2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 22:17:33 +03:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsStackLayout.h"
|
2001-08-18 05:04:47 +04:00
|
|
|
#include "nsIRootBox.h"
|
2001-12-05 01:32:49 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsXULTooltipListener.h"
|
2006-08-08 14:40:11 +04:00
|
|
|
#include "nsFrameManager.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// Interface IDs
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
//#define DEBUG_REFLOW
|
|
|
|
|
2006-08-08 14:40:11 +04:00
|
|
|
// static
|
|
|
|
nsIRootBox*
|
|
|
|
nsIRootBox::GetRootBox(nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
if (!aShell) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-08-08 14:40:11 +04:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = aShell->FrameManager()->GetRootFrame();
|
|
|
|
if (!rootFrame) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-08-08 14:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rootFrame) {
|
2016-01-29 17:42:14 +03:00
|
|
|
rootFrame = rootFrame->PrincipalChildList().FirstChild();
|
2006-08-08 14:40:11 +04:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIRootBox* rootBox = do_QueryFrame(rootFrame);
|
2006-08-08 14:40:11 +04:00
|
|
|
return rootBox;
|
|
|
|
}
|
|
|
|
|
2017-05-02 04:50:16 +03:00
|
|
|
class nsRootBoxFrame final : public nsBoxFrame, public nsIRootBox
|
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
public:
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2015-01-06 13:07:04 +03:00
|
|
|
explicit nsRootBoxFrame(nsStyleContext* aContext);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsRootBoxFrame)
|
2001-08-18 05:04:47 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsPopupSetFrame* GetPopupSetFrame() override;
|
|
|
|
virtual void SetPopupSetFrame(nsPopupSetFrame* aPopupSet) override;
|
|
|
|
virtual nsIContent* GetDefaultTooltip() override;
|
|
|
|
virtual void SetDefaultTooltip(nsIContent* aTooltip) override;
|
|
|
|
virtual nsresult AddTooltipSupport(nsIContent* aNode) override;
|
|
|
|
virtual nsresult RemoveTooltipSupport(nsIContent* aNode) override;
|
2001-08-18 05:04:47 +04:00
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void InsertFrames(ChildListID aListID,
|
2014-05-28 23:36:58 +04:00
|
|
|
nsIFrame* aPrevFrame,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void RemoveFrame(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aOldFrame) override;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsReflowStatus& aStatus) override;
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 12:36:33 +04:00
|
|
|
WidgetGUIEvent* aEvent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsEventStatus* aEventStatus) override;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2001-05-25 19:00:51 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override
|
2007-02-24 21:33:33 +03:00
|
|
|
{
|
|
|
|
// Override bogus IsFrameOfType in nsBoxFrame.
|
|
|
|
if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-02-24 21:33:33 +03:00
|
|
|
return nsBoxFrame::IsFrameOfType(aFlags);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override;
|
2000-03-31 11:02:06 +04:00
|
|
|
#endif
|
2001-08-18 05:04:47 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsPopupSetFrame* mPopupSetFrame;
|
2001-12-05 01:32:49 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIContent* mDefaultTooltip;
|
2000-03-31 11:02:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
nsContainerFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsRootBoxFrame(aContext);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRootBoxFrame)
|
|
|
|
|
2017-04-22 22:07:03 +03:00
|
|
|
nsRootBoxFrame::nsRootBoxFrame(nsStyleContext* aContext)
|
2017-05-26 13:11:11 +03:00
|
|
|
: nsBoxFrame(aContext, kClassID, true)
|
2017-04-22 22:07:03 +03:00
|
|
|
, mPopupSetFrame(nullptr)
|
|
|
|
, mDefaultTooltip(nullptr)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-07-11 18:05:10 +04:00
|
|
|
nsCOMPtr<nsBoxLayout> layout;
|
2015-12-08 02:27:01 +03:00
|
|
|
NS_NewStackLayout(layout);
|
2016-04-21 07:28:33 +03:00
|
|
|
SetXULLayoutManager(layout);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2011-08-25 00:54:30 +04:00
|
|
|
nsRootBoxFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2014-05-28 23:36:58 +04: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 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2011-08-25 00:54:30 +04:00
|
|
|
nsRootBoxFrame::InsertFrames(ChildListID aListID,
|
2005-02-07 04:58:25 +03:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
// Because we only support a single child frame inserting is the same
|
2011-08-25 00:54:30 +04:00
|
|
|
// as appending.
|
2014-05-28 23:36:58 +04:00
|
|
|
MOZ_ASSERT(!aPrevFrame, "unexpected previous sibling frame");
|
|
|
|
AppendFrames(aListID, aFrameList);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2011-08-25 00:54:30 +04:00
|
|
|
nsRootBoxFrame::RemoveFrame(ChildListID aListID,
|
2005-02-07 04:58:25 +03:00
|
|
|
nsIFrame* aOldFrame)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
|
2014-05-28 23:36:58 +04:00
|
|
|
if (aOldFrame == mFrames.FirstChild()) {
|
|
|
|
nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
2014-05-28 23:36:58 +04:00
|
|
|
MOZ_CRASH("unknown aOldFrame");
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
#ifdef DEBUG_REFLOW
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t gReflows = 0;
|
2000-05-15 08:12:31 +04:00
|
|
|
#endif
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2011-08-25 00:54:30 +04:00
|
|
|
nsRootBoxFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2002-05-29 02:50:43 +04:00
|
|
|
nsReflowStatus& aStatus)
|
2000-03-31 11:02:06 +04: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 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame");
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
2000-05-15 08:12:31 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_REFLOW
|
|
|
|
gReflows++;
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("----Reflow %d----\n", gReflows);
|
2000-05-15 08:12:31 +04:00
|
|
|
#endif
|
2016-07-21 13:36:39 +03:00
|
|
|
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRootBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2015-04-29 14:22:27 +03:00
|
|
|
if (mContent && mContent->GetProperty(nsGkAtoms::DisplayPortMargins)) {
|
|
|
|
// The XUL document's root element may have displayport margins set in
|
|
|
|
// ChromeProcessController::InitializeRoot, and we should to supply the
|
|
|
|
// base rect.
|
2017-08-07 05:23:35 +03:00
|
|
|
nsRect displayPortBase =
|
|
|
|
aBuilder->GetDirtyRect().Intersect(nsRect(nsPoint(0, 0), GetSize()));
|
2015-04-29 14:22:27 +03:00
|
|
|
nsLayoutUtils::SetDisplayPortBase(mContent, displayPortBase);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// 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 15:08:08 +04:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists, true);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListForChildren(aBuilder, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2013-10-02 07:46:03 +04:00
|
|
|
nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-29 02:58:30 +03:00
|
|
|
if (aEvent->mMessage == eMouseUp) {
|
2000-03-31 11:02:06 +04:00
|
|
|
nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsPopupSetFrame*
|
2005-11-03 02:53:56 +03:00
|
|
|
nsRootBoxFrame::GetPopupSetFrame()
|
2001-08-18 05:04:47 +04:00
|
|
|
{
|
2005-11-03 02:53:56 +03:00
|
|
|
return mPopupSetFrame;
|
2001-08-18 05:04:47 +04:00
|
|
|
}
|
|
|
|
|
2005-11-03 02:53:56 +03:00
|
|
|
void
|
2007-07-04 19:49:38 +04:00
|
|
|
nsRootBoxFrame::SetPopupSetFrame(nsPopupSetFrame* aPopupSet)
|
2001-08-18 05:04:47 +04:00
|
|
|
{
|
2002-08-19 22:29:29 +04: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 18:20:58 +04:00
|
|
|
// |SetPopupSetFrame(nullptr)|, and then we'll be able to accept a new
|
2002-08-19 22:29:29 +04: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-20 01:58:09 +04:00
|
|
|
mPopupSetFrame = aPopupSet;
|
2002-08-19 22:29:29 +04:00
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("Popup set is already defined! Only 1 allowed.");
|
|
|
|
}
|
2001-08-18 05:04:47 +04:00
|
|
|
}
|
|
|
|
|
2005-11-03 02:53:56 +03:00
|
|
|
nsIContent*
|
|
|
|
nsRootBoxFrame::GetDefaultTooltip()
|
2001-12-05 01:32:49 +03:00
|
|
|
{
|
2005-11-03 02:53:56 +03:00
|
|
|
return mDefaultTooltip;
|
2001-12-05 01:32:49 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 02:53:56 +03:00
|
|
|
void
|
2001-12-05 01:32:49 +03:00
|
|
|
nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
|
|
|
|
{
|
|
|
|
mDefaultTooltip = aTooltip;
|
|
|
|
}
|
|
|
|
|
2005-11-03 02:53:56 +03:00
|
|
|
nsresult
|
2001-12-05 01:32:49 +03:00
|
|
|
nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
2006-08-16 12:44:45 +04:00
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2007-04-13 00:59:01 +04:00
|
|
|
nsXULTooltipListener *listener = nsXULTooltipListener::GetInstance();
|
2003-12-21 07:04:05 +03:00
|
|
|
if (!listener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-04-13 00:59:01 +04:00
|
|
|
return listener->AddTooltipSupport(aNode);
|
2001-12-05 01:32:49 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 02:53:56 +03:00
|
|
|
nsresult
|
2001-12-05 01:32:49 +03:00
|
|
|
nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
// XXjh yuck, I'll have to implement a way to get at
|
2017-07-06 15:00:35 +03:00
|
|
|
// the tooltip listener for a given node to make
|
|
|
|
// this work. Not crucial, we aren't removing
|
2001-12-05 01:32:49 +03:00
|
|
|
// tooltips from any nodes in the app just yet.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsRootBoxFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIRootBox)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
2001-08-18 05:04:47 +04:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2005-11-03 02:53:56 +03:00
|
|
|
nsRootBoxFrame::GetFrameName(nsAString& aResult) const
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
#endif
|