2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-02-12 19:17:33 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsStackLayout.h"
|
2001-08-18 01:04:47 +00:00
|
|
|
#include "nsIRootBox.h"
|
2001-12-04 22:32:49 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsXULTooltipListener.h"
|
2006-08-08 10:40:11 +00:00
|
|
|
#include "nsFrameManager.h"
|
2013-09-25 11:21:22 +00:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// Interface IDs
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
//#define DEBUG_REFLOW
|
|
|
|
|
2006-08-08 10:40:11 +00:00
|
|
|
// static
|
|
|
|
nsIRootBox*
|
|
|
|
nsIRootBox::GetRootBox(nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
if (!aShell) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-08-08 10:40:11 +00:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = aShell->FrameManager()->GetRootFrame();
|
|
|
|
if (!rootFrame) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-08-08 10:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rootFrame) {
|
2011-08-24 20:54:30 +00:00
|
|
|
rootFrame = rootFrame->GetFirstPrincipalChild();
|
2006-08-08 10:40:11 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIRootBox* rootBox = do_QueryFrame(rootFrame);
|
2006-08-08 10:40:11 +00:00
|
|
|
return rootBox;
|
|
|
|
}
|
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
class nsRootBoxFrame : public nsBoxFrame, public nsIRootBox {
|
2000-03-31 07:02:06 +00:00
|
|
|
public:
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext *aContext);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual nsPopupSetFrame* GetPopupSetFrame() MOZ_OVERRIDE;
|
|
|
|
virtual void SetPopupSetFrame(nsPopupSetFrame* aPopupSet) MOZ_OVERRIDE;
|
|
|
|
virtual nsIContent* GetDefaultTooltip() MOZ_OVERRIDE;
|
|
|
|
virtual void SetDefaultTooltip(nsIContent* aTooltip) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult AddTooltipSupport(nsIContent* aNode) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult RemoveTooltipSupport(nsIContent* aNode) MOZ_OVERRIDE;
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2014-05-28 19:36:58 +00:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void InsertFrames(ChildListID aListID,
|
2014-05-28 19:36:58 +00:00
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void RemoveFrame(ChildListID aListID,
|
2014-05-28 19:36:58 +00:00
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2014-05-13 00:47:52 +00:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2014-02-24 14:41:56 +00:00
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 08:36:33 +00:00
|
|
|
WidgetGUIEvent* aEvent,
|
2014-02-24 14:41:56 +00:00
|
|
|
nsEventStatus* aEventStatus) MOZ_OVERRIDE;
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2001-05-25 15:00:51 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
2006-12-26 17:47:52 +00:00
|
|
|
* @see nsGkAtoms::rootFrame
|
2000-03-31 07:02:06 +00:00
|
|
|
*/
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2007-02-24 18:33:33 +00:00
|
|
|
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
|
2007-02-24 18:33:33 +00:00
|
|
|
{
|
|
|
|
// Override bogus IsFrameOfType in nsBoxFrame.
|
|
|
|
if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-02-24 18:33:33 +00:00
|
|
|
return nsBoxFrame::IsFrameOfType(aFlags);
|
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
|
2000-03-31 07:02:06 +00:00
|
|
|
#endif
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsPopupSetFrame* mPopupSetFrame;
|
2001-12-04 22:32:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIContent* mDefaultTooltip;
|
2000-03-31 07:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2014-05-24 22:20:40 +00:00
|
|
|
nsContainerFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsRootBoxFrame (aPresShell, aContext);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRootBoxFrame)
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
2011-10-17 14:59:28 +00:00
|
|
|
nsBoxFrame(aShell, aContext, true)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mPopupSetFrame = nullptr;
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2011-07-11 14:05:10 +00:00
|
|
|
nsCOMPtr<nsBoxLayout> layout;
|
2000-04-05 00:19:00 +00:00
|
|
|
NS_NewStackLayout(aShell, layout);
|
|
|
|
SetLayoutManager(layout);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsRootBoxFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 17:23:32 +00:00
|
|
|
nsFrameList& aFrameList)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2014-05-28 19:36:58 +00:00
|
|
|
MOZ_ASSERT(aListID == kPrincipalList, "unexpected child list ID");
|
|
|
|
MOZ_ASSERT(mFrames.IsEmpty(), "already have a child frame");
|
|
|
|
nsBoxFrame::AppendFrames(aListID, aFrameList);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsRootBoxFrame::InsertFrames(ChildListID aListID,
|
2005-02-07 01:58:25 +00:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 17:23:32 +00:00
|
|
|
nsFrameList& aFrameList)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
|
|
|
// Because we only support a single child frame inserting is the same
|
2011-08-24 20:54:30 +00:00
|
|
|
// as appending.
|
2014-05-28 19:36:58 +00:00
|
|
|
MOZ_ASSERT(!aPrevFrame, "unexpected previous sibling frame");
|
|
|
|
AppendFrames(aListID, aFrameList);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsRootBoxFrame::RemoveFrame(ChildListID aListID,
|
2005-02-07 01:58:25 +00:00
|
|
|
nsIFrame* aOldFrame)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2011-08-24 20:54:30 +00:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
|
2014-05-28 19:36:58 +00:00
|
|
|
if (aOldFrame == mFrames.FirstChild()) {
|
|
|
|
nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2000-03-31 07:02:06 +00:00
|
|
|
} else {
|
2014-05-28 19:36:58 +00:00
|
|
|
MOZ_CRASH("unknown aOldFrame");
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
#ifdef DEBUG_REFLOW
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t gReflows = 0;
|
2000-05-15 04:12:31 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-13 00:47:52 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsRootBoxFrame::Reflow(nsPresContext* aPresContext,
|
2002-05-28 22:50:43 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame");
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_REFLOW
|
|
|
|
gReflows++;
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("----Reflow %d----\n", gReflows);
|
2000-05-15 04:12:31 +00:00
|
|
|
#endif
|
2000-03-31 07:02:06 +00:00
|
|
|
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRootBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// root boxes don't need a debug border/outline or a selection overlay...
|
|
|
|
// They *may* have a background propagated to them, so force creation
|
|
|
|
// of a background display list element.
|
2013-02-14 11:08:08 +00:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists, true);
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2013-02-14 11:08:08 +00:00
|
|
|
BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2013-10-02 03:46:03 +00:00
|
|
|
nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2000-03-31 07:02:06 +00:00
|
|
|
nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// REVIEW: The override here was doing nothing since nsBoxFrame is our
|
|
|
|
// parent class
|
2003-10-31 20:19:18 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsRootBoxFrame::GetType() const
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::rootFrame;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsPopupSetFrame*
|
2005-11-02 23:53:56 +00:00
|
|
|
nsRootBoxFrame::GetPopupSetFrame()
|
2001-08-18 01:04:47 +00:00
|
|
|
{
|
2005-11-02 23:53:56 +00:00
|
|
|
return mPopupSetFrame;
|
2001-08-18 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 23:53:56 +00:00
|
|
|
void
|
2007-07-04 15:49:38 +00:00
|
|
|
nsRootBoxFrame::SetPopupSetFrame(nsPopupSetFrame* aPopupSet)
|
2001-08-18 01:04:47 +00:00
|
|
|
{
|
2002-08-19 18:29:29 +00:00
|
|
|
// Under normal conditions this should only be called once. However,
|
|
|
|
// if something triggers ReconstructDocElementHierarchy, we will
|
|
|
|
// destroy this frame's child (the nsDocElementBoxFrame), but not this
|
|
|
|
// frame. This will cause the popupset to remove itself by calling
|
2012-07-30 14:20:58 +00:00
|
|
|
// |SetPopupSetFrame(nullptr)|, and then we'll be able to accept a new
|
2002-08-19 18:29:29 +00:00
|
|
|
// popupset. Since the anonymous content is associated with the
|
|
|
|
// nsDocElementBoxFrame, we'll get a new popupset when the new doc
|
|
|
|
// element box frame is created.
|
|
|
|
if (!mPopupSetFrame || !aPopupSet) {
|
2002-07-19 21:58:09 +00:00
|
|
|
mPopupSetFrame = aPopupSet;
|
2002-08-19 18:29:29 +00:00
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("Popup set is already defined! Only 1 allowed.");
|
|
|
|
}
|
2001-08-18 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 23:53:56 +00:00
|
|
|
nsIContent*
|
|
|
|
nsRootBoxFrame::GetDefaultTooltip()
|
2001-12-04 22:32:49 +00:00
|
|
|
{
|
2005-11-02 23:53:56 +00:00
|
|
|
return mDefaultTooltip;
|
2001-12-04 22:32:49 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 23:53:56 +00:00
|
|
|
void
|
2001-12-04 22:32:49 +00:00
|
|
|
nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
|
|
|
|
{
|
|
|
|
mDefaultTooltip = aTooltip;
|
|
|
|
}
|
|
|
|
|
2005-11-02 23:53:56 +00:00
|
|
|
nsresult
|
2001-12-04 22:32:49 +00:00
|
|
|
nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
2006-08-16 08:44:45 +00:00
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2007-04-12 20:59:01 +00:00
|
|
|
nsXULTooltipListener *listener = nsXULTooltipListener::GetInstance();
|
2003-12-21 04:04:05 +00:00
|
|
|
if (!listener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-04-12 20:59:01 +00:00
|
|
|
return listener->AddTooltipSupport(aNode);
|
2001-12-04 22:32:49 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 23:53:56 +00:00
|
|
|
nsresult
|
2001-12-04 22:32:49 +00:00
|
|
|
nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
// XXjh yuck, I'll have to implement a way to get at
|
|
|
|
// the tooltip listener for a given node to make
|
|
|
|
// this work. Not crucial, we aren't removing
|
|
|
|
// tooltips from any nodes in the app just yet.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsRootBoxFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIRootBox)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2005-11-02 23:53:56 +00:00
|
|
|
nsRootBoxFrame::GetFrameName(nsAString& aResult) const
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2001-11-14 01:33:42 +00:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
#endif
|