2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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 "nsBoxFrame.h"
|
2018-07-18 13:23:32 +03:00
|
|
|
#include "nsDisplayList.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsStackLayout.h"
|
2018-06-27 03:29:55 +03:00
|
|
|
#include "nsIPopupContainer.h"
|
2001-12-05 01:32:49 +03:00
|
|
|
#include "nsIContent.h"
|
2006-08-08 14:40:11 +04:00
|
|
|
#include "nsFrameManager.h"
|
2020-10-01 00:05:34 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2020-10-04 00:07:34 +03:00
|
|
|
#include "mozilla/DisplayPortUtils.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/PresShell.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
|
|
|
|
|
2006-08-08 14:40:11 +04:00
|
|
|
// static
|
2019-04-16 10:25:10 +03:00
|
|
|
nsIPopupContainer* nsIPopupContainer::GetPopupContainer(PresShell* aPresShell) {
|
|
|
|
if (!aPresShell) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-08-08 14:40:11 +04:00
|
|
|
}
|
2019-04-16 10:25:10 +03:00
|
|
|
nsIFrame* rootFrame = aPresShell->GetRootFrame();
|
2006-08-08 14:40:11 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-06-27 03:29:55 +03:00
|
|
|
nsIPopupContainer* rootBox = do_QueryFrame(rootFrame);
|
2018-06-05 04:02:32 +03:00
|
|
|
|
|
|
|
// If the rootBox was not found yet this may be a top level non-XUL document.
|
|
|
|
if (rootFrame && !rootBox) {
|
|
|
|
// In a non-XUL document the rootFrame here will be a nsHTMLScrollFrame,
|
|
|
|
// get the nsCanvasFrame (which is the popup container) from it.
|
|
|
|
rootFrame = rootFrame->GetContentInsertionFrame();
|
|
|
|
rootBox = do_QueryFrame(rootFrame);
|
|
|
|
}
|
|
|
|
|
2006-08-08 14:40:11 +04:00
|
|
|
return rootBox;
|
|
|
|
}
|
|
|
|
|
2018-06-27 03:29:55 +03:00
|
|
|
class nsRootBoxFrame final : public nsBoxFrame, public nsIPopupContainer {
|
2000-03-31 11:02:06 +04:00
|
|
|
public:
|
2019-04-16 10:24:49 +03:00
|
|
|
friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsRootBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
|
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;
|
2019-11-29 23:39:36 +03:00
|
|
|
virtual dom::Element* GetDefaultTooltip() override;
|
|
|
|
virtual void SetDefaultTooltip(dom::Element* aTooltip) 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, nsIFrame* aPrevFrame,
|
2019-07-18 02:34:45 +03:00
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext, 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:
|
2019-11-29 23:39:36 +03:00
|
|
|
dom::Element* mDefaultTooltip;
|
2000-03-31 11:02:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsContainerFrame* NS_NewRootBoxFrame(PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell) nsRootBoxFrame(aStyle, aPresShell->GetPresContext());
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRootBoxFrame)
|
|
|
|
|
2019-02-05 19:45:54 +03:00
|
|
|
nsRootBoxFrame::nsRootBoxFrame(ComputedStyle* aStyle,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
: nsBoxFrame(aStyle, aPresContext, kClassID, true),
|
2017-04-22 22:07:03 +03:00
|
|
|
mPopupSetFrame(nullptr),
|
|
|
|
mDefaultTooltip(nullptr) {
|
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
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsRootBoxFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
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
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsRootBoxFrame::InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
2019-07-18 02:34:45 +03:00
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
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
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsRootBoxFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void 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) {
|
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
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void 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 =
|
2017-10-04 04:28:38 +03:00
|
|
|
aBuilder->GetVisibleRect().Intersect(nsRect(nsPoint(0, 0), GetSize()));
|
2020-10-04 00:07:34 +03:00
|
|
|
DisplayPortUtils::SetDisplayPortBase(mContent, displayPortBase);
|
2015-04-29 14:22:27 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
nsresult 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) {
|
2020-07-07 01:29:42 +03:00
|
|
|
nsIFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-03 02:53:56 +03:00
|
|
|
nsPopupSetFrame* nsRootBoxFrame::GetPopupSetFrame() { return mPopupSetFrame; }
|
2001-08-18 05:04:47 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void nsRootBoxFrame::SetPopupSetFrame(nsPopupSetFrame* aPopupSet) {
|
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.
|
2018-06-05 04:02:32 +03:00
|
|
|
MOZ_ASSERT(!aPopupSet || !mPopupSetFrame,
|
|
|
|
"Popup set is already defined! Only 1 allowed.");
|
|
|
|
mPopupSetFrame = aPopupSet;
|
2001-08-18 05:04:47 +04:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:39:36 +03:00
|
|
|
dom::Element* nsRootBoxFrame::GetDefaultTooltip() { return mDefaultTooltip; }
|
2001-12-05 01:32:49 +03:00
|
|
|
|
2019-11-29 23:39:36 +03:00
|
|
|
void nsRootBoxFrame::SetDefaultTooltip(dom::Element* aTooltip) {
|
2001-12-05 01:32:49 +03:00
|
|
|
mDefaultTooltip = aTooltip;
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsRootBoxFrame)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIPopupContainer)
|
2009-01-12 22:20:59 +03:00
|
|
|
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
|
2005-11-03 02:53:56 +03:00
|
|
|
nsresult nsRootBoxFrame::GetFrameName(nsAString& aResult) const {
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(u"RootBox"_ns, aResult);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
#endif
|