From 048e9bb783f1c0f0a1baf211e3e52215270fd173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 1 Oct 2022 02:35:31 +0000 Subject: [PATCH] Bug 1792741 - Remove nsDocElementBoxFrame. r=TYLin After bug 1665476, it's pretty much a regular XUL box with a couple special-cases that we can use IsRootElementStyle for. Do that, and allow using nsFlexContainerFrame when using flexbox emulation. Differential Revision: https://phabricator.services.mozilla.com/D158288 --- layout/base/nsCSSFrameConstructor.cpp | 46 +++++++++----------- layout/generic/FrameClasses.py | 1 - layout/generic/nsContainerFrame.cpp | 2 +- layout/generic/nsFrameStateBits.h | 8 ++-- layout/generic/nsGfxScrollFrame.cpp | 2 +- layout/painting/nsDisplayList.cpp | 10 ++--- layout/xul/moz.build | 1 - layout/xul/nsBoxFrame.cpp | 27 +++--------- layout/xul/nsBoxFrame.h | 19 +++------ layout/xul/nsDocElementBoxFrame.cpp | 61 --------------------------- 10 files changed, 43 insertions(+), 134 deletions(-) delete mode 100644 layout/xul/nsDocElementBoxFrame.cpp diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 227538c72716..2c13fcc35d17 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -209,9 +209,6 @@ static FrameCtorDebugFlags gFlags[] = { //------------------------------------------------------------------ -nsContainerFrame* NS_NewDocElementBoxFrame(PresShell* aPresShell, - ComputedStyle* aStyle); - nsIFrame* NS_NewLeafBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle); nsIFrame* NS_NewRangeFrame(PresShell* aPresShell, ComputedStyle* aStyle); @@ -2420,14 +2417,7 @@ nsIFrame* nsCSSFrameConstructor::ConstructDocElementFrame( nsFrameConstructorSaveState absoluteSaveState; - // Check whether we need to build a XUL box or SVG root frame - if (aDocElement->IsXULElement()) { - contentFrame = NS_NewDocElementBoxFrame(mPresShell, computedStyle); - InitAndRestoreFrame(state, aDocElement, mDocElementContainingBlock, - contentFrame); - frameList = {contentFrame, contentFrame}; - processChildren = true; - } else if (aDocElement->IsSVGElement()) { + if (aDocElement->IsSVGElement()) { if (!aDocElement->IsSVGElement(nsGkAtoms::svg)) { return nullptr; } @@ -2447,11 +2437,19 @@ nsIFrame* nsCSSFrameConstructor::ConstructDocElementFrame( } else if (display->mDisplay == StyleDisplay::Flex || display->mDisplay == StyleDisplay::WebkitBox || display->mDisplay == StyleDisplay::Grid || - (display->mDisplay == StyleDisplay::MozBox && - computedStyle->StyleVisibility()->EmulateMozBoxWithFlex())) { - auto func = display->mDisplay == StyleDisplay::Grid - ? NS_NewGridContainerFrame - : NS_NewFlexContainerFrame; + display->mDisplay == StyleDisplay::MozBox || + display->mDisplay == StyleDisplay::MozPopup) { + auto func = [&] { + if (display->mDisplay == StyleDisplay::Grid) { + return NS_NewGridContainerFrame; + } + if ((display->mDisplay == StyleDisplay::MozBox || + display->mDisplay == StyleDisplay::MozPopup) && + !computedStyle->StyleVisibility()->EmulateMozBoxWithFlex()) { + return NS_NewBoxFrame; + } + return NS_NewFlexContainerFrame; + }(); contentFrame = func(mPresShell, computedStyle); InitAndRestoreFrame( state, aDocElement, @@ -2602,19 +2600,14 @@ void nsCSSFrameConstructor::SetUpDocElementContainingBlock( /* how the root frame hierarchy should look - Galley presentation, non-XUL, with scrolling: + Galley presentation, with scrolling: ViewportFrame [fixed-cb] - nsHTMLScrollFrame + nsHTMLScrollFrame (if needed) nsCanvasFrame [abs-cb] root element frame (nsBlockFrame, SVGOuterSVGFrame, - nsTableWrapperFrame, nsPlaceholderFrame) - - Galley presentation, XUL - - ViewportFrame [fixed-cb] - nsCanvasFrame [abs-cb] - root element frame (nsDocElementBoxFrame) + nsTableWrapperFrame, nsPlaceholderFrame, + nsBoxFrame) Print presentation, non-XUL @@ -4472,7 +4465,8 @@ nsCSSFrameConstructor::FindDisplayData(const nsStyleDisplay& aDisplay, if (aMozBoxLayout == StyleMozBoxLayout::Legacy || aElement.IsXULElement(nsGkAtoms::scrollcorner)) { static constexpr FrameConstructionData data = - SCROLLABLE_ABSPOS_CONTAINER_XUL_FCDATA(NS_NewBoxFrame); + SCROLLABLE_ABSPOS_CONTAINER_XUL_FCDATA( + ToCreationFunc(NS_NewBoxFrame)); return &data; } [[fallthrough]]; diff --git a/layout/generic/FrameClasses.py b/layout/generic/FrameClasses.py index 66e59d7fde19..2cf28b221c8f 100644 --- a/layout/generic/FrameClasses.py +++ b/layout/generic/FrameClasses.py @@ -22,7 +22,6 @@ FRAME_CLASSES = [ Frame("nsComboboxDisplayFrame", "ComboboxDisplay", NOT_LEAF), Frame("nsContinuingTextFrame", "Text", LEAF), Frame("nsDateTimeControlFrame", "DateTimeControl", NOT_LEAF), - Frame("nsDocElementBoxFrame", "DocElementBox", NOT_LEAF), Frame("nsFieldSetFrame", "FieldSet", NOT_LEAF), Frame("nsFileControlFrame", "Block", LEAF), Frame("nsFirstLetterFrame", "Letter", NOT_LEAF), diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp index b1d560877ab2..89128d7d6ca7 100644 --- a/layout/generic/nsContainerFrame.cpp +++ b/layout/generic/nsContainerFrame.cpp @@ -810,7 +810,7 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext, nsSize minSize(0, 0); nsSize maxSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE); - if (rootElement->IsXULElement()) { + if (rootFrame->IsXULBoxFrame()) { nsBoxLayoutState aState(aPresContext, aRC); minSize = rootFrame->GetXULMinSize(aState); maxSize = rootFrame->GetXULMaxSize(aState); diff --git a/layout/generic/nsFrameStateBits.h b/layout/generic/nsFrameStateBits.h index f5e596cdb0d7..baa1d5387ea1 100644 --- a/layout/generic/nsFrameStateBits.h +++ b/layout/generic/nsFrameStateBits.h @@ -320,11 +320,9 @@ FRAME_STATE_GROUP(Box, nsBoxFrame) FRAME_STATE_BIT(Box, 20, NS_STATE_BOX_CHILD_RESERVED) FRAME_STATE_BIT(Box, 22, NS_STATE_IS_HORIZONTAL) FRAME_STATE_BIT(Box, 23, NS_STATE_AUTO_STRETCH) -FRAME_STATE_BIT(Box, 24, NS_STATE_IS_ROOT) -/* Bits 25, 26, and 27 were used for xul debug flags but are now unused */ -FRAME_STATE_BIT(Box, 28, NS_STATE_MENU_HAS_POPUP_LIST) -FRAME_STATE_BIT(Box, 29, NS_STATE_EQUAL_SIZE) -FRAME_STATE_BIT(Box, 30, NS_STATE_IS_DIRECTION_NORMAL) +FRAME_STATE_BIT(Box, 24, NS_STATE_MENU_HAS_POPUP_LIST) +FRAME_STATE_BIT(Box, 25, NS_STATE_EQUAL_SIZE) +FRAME_STATE_BIT(Box, 26, NS_STATE_IS_DIRECTION_NORMAL) // == Frame state bits that apply to flex container frames ==================== diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index cd9a43b9ea5e..dc3450be41e1 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1576,7 +1576,7 @@ NS_IMPL_FRAMEARENA_HELPERS(nsXULScrollFrame) nsXULScrollFrame::nsXULScrollFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, bool aIsRoot) - : nsBoxFrame(aStyle, aPresContext, kClassID, aIsRoot), + : nsBoxFrame(aStyle, aPresContext, kClassID), mHelper(ALLOW_THIS_IN_INITIALIZER_LIST(this), aIsRoot) { SetXULLayoutManager(nullptr); } diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 473602ebeda2..45131de7ca4d 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -837,12 +837,12 @@ void nsDisplayListBuilder::MarkFrameForDisplayIfVisible( void nsDisplayListBuilder::SetGlassDisplayItem(nsDisplayItem* aItem) { // Web pages or extensions could trigger the "Multiple glass backgrounds // found?" warning by using -moz-appearance:win-borderless-glass etc on their - // own elements (as long as they are DocElementBoxFrames, which is rare as - // each xul doc only gets one near the root). We only care about first one, - // since that will be the background of the root window. + // own elements (as long as they are root frames, which is rare as each doc + // only gets one near the root). We only care about the first one, since that + // will be the background of the root window. if (IsPartialUpdate()) { - if (aItem->Frame()->IsDocElementBoxFrame()) { + if (aItem->Frame()->Style()->IsRootElementStyle()) { #ifdef DEBUG if (mHasGlassItemDuringPartial) { NS_WARNING("Multiple glass backgrounds found?"); @@ -856,7 +856,7 @@ void nsDisplayListBuilder::SetGlassDisplayItem(nsDisplayItem* aItem) { return; } - if (aItem->Frame()->IsDocElementBoxFrame()) { + if (aItem->Frame()->Style()->IsRootElementStyle()) { #ifdef DEBUG if (mGlassDisplayItem) { NS_WARNING("Multiple glass backgrounds found?"); diff --git a/layout/xul/moz.build b/layout/xul/moz.build index fba7a671e19e..358e81bf8840 100644 --- a/layout/xul/moz.build +++ b/layout/xul/moz.build @@ -23,7 +23,6 @@ UNIFIED_SOURCES += [ "nsBoxFrame.cpp", "nsBoxLayout.cpp", "nsBoxLayoutState.cpp", - "nsDocElementBoxFrame.cpp", "nsImageBoxFrame.cpp", "nsLeafBoxFrame.cpp", "nsMenuBarFrame.cpp", diff --git a/layout/xul/nsBoxFrame.cpp b/layout/xul/nsBoxFrame.cpp index 878c5ddfc846..886331384437 100644 --- a/layout/xul/nsBoxFrame.cpp +++ b/layout/xul/nsBoxFrame.cpp @@ -87,14 +87,7 @@ using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::gfx; -nsIFrame* NS_NewBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle, - bool aIsRoot, nsBoxLayout* aLayoutManager) { - return new (aPresShell) - nsBoxFrame(aStyle, aPresShell->GetPresContext(), nsBoxFrame::kClassID, - aIsRoot, aLayoutManager); -} - -nsIFrame* NS_NewBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle) { +nsContainerFrame* NS_NewBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle) { return new (aPresShell) nsBoxFrame(aStyle, aPresShell->GetPresContext()); } @@ -107,22 +100,16 @@ NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame) #endif nsBoxFrame::nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, - ClassID aID, bool aIsRoot, nsBoxLayout* aLayoutManager) + ClassID aID) : nsContainerFrame(aStyle, aPresContext, aID), mAscent(0) { AddStateBits(NS_STATE_IS_HORIZONTAL | NS_STATE_AUTO_STRETCH); - if (aIsRoot) AddStateBits(NS_STATE_IS_ROOT); - mValign = vAlign_Top; mHalign = hAlign_Left; - // if no layout manager specified us the static sprocket layout - nsCOMPtr layout = aLayoutManager; - - if (layout == nullptr) { - NS_NewSprocketLayout(layout); - } - + // Use the static sprocket layout + nsCOMPtr layout; + NS_NewSprocketLayout(layout); SetXULLayoutManager(layout); } @@ -538,7 +525,7 @@ void nsBoxFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, // getting the ascent could be a lot of work. Don't get it if // we are the root. The viewport doesn't care about it. - if (!(mState & NS_STATE_IS_ROOT)) { + if (!Style()->IsRootElementStyle()) { ascent = GetXULBoxAscent(state); } @@ -707,7 +694,7 @@ nsBoxFrame::DoXULLayout(nsBoxLayoutState& aState) { // getting the ascent could be a lot of work. Don't get it if // we are the root. The viewport doesn't care about it. - if (!(mState & NS_STATE_IS_ROOT)) { + if (!Style()->IsRootElementStyle()) { ascent = GetXULBoxAscent(aState); } desiredSize.SetBlockStartAscent(ascent); diff --git a/layout/xul/nsBoxFrame.h b/layout/xul/nsBoxFrame.h index 761eea08a5ac..17c01588e757 100644 --- a/layout/xul/nsBoxFrame.h +++ b/layout/xul/nsBoxFrame.h @@ -29,11 +29,8 @@ class DrawTarget; } // namespace gfx } // namespace mozilla -nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, - mozilla::ComputedStyle* aStyle, bool aIsRoot, - nsBoxLayout* aLayoutManager); -nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, - mozilla::ComputedStyle* aStyle); +nsContainerFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, + mozilla::ComputedStyle* aStyle); class nsBoxFrame : public nsContainerFrame { protected: @@ -45,11 +42,8 @@ class nsBoxFrame : public nsContainerFrame { NS_DECL_QUERYFRAME #endif - friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, - ComputedStyle* aStyle, bool aIsRoot, - nsBoxLayout* aLayoutManager); - friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, - ComputedStyle* aStyle); + friend nsContainerFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, + ComputedStyle* aStyle); // gets the rect inside our border and debug border. If you wish to paint // inside a box call this method to get the rect so you don't draw on the @@ -150,11 +144,10 @@ class nsBoxFrame : public nsContainerFrame { private: explicit nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext) - : nsBoxFrame(aStyle, aPresContext, kClassID, false, nullptr) {} + : nsBoxFrame(aStyle, aPresContext, kClassID) {} protected: - nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID, - bool aIsRoot = false, nsBoxLayout* aLayoutManager = nullptr); + nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID); virtual ~nsBoxFrame(); virtual bool GetInitialEqualSize(bool& aEqualSize); diff --git a/layout/xul/nsDocElementBoxFrame.cpp b/layout/xul/nsDocElementBoxFrame.cpp deleted file mode 100644 index 6e763491b490..000000000000 --- a/layout/xul/nsDocElementBoxFrame.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ -#include "mozilla/PresShell.h" -#include "mozilla/dom/Document.h" -#include "mozilla/dom/Element.h" -#include "mozilla/dom/FromParser.h" -#include "mozilla/dom/NodeInfo.h" -#include "nsHTMLParts.h" -#include "nsContainerFrame.h" -#include "nsCSSRendering.h" -#include "nsPageFrame.h" -#include "nsStyleConsts.h" -#include "nsGkAtoms.h" -#include "nsBoxFrame.h" -#include "nsNodeInfoManager.h" -#include "nsContentCreatorFunctions.h" - -using namespace mozilla; -using namespace mozilla::dom; - -class nsDocElementBoxFrame final : public nsBoxFrame { - public: - friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell, - ComputedStyle* aStyle); - - explicit nsDocElementBoxFrame(ComputedStyle* aStyle, - nsPresContext* aPresContext) - : nsBoxFrame(aStyle, aPresContext, kClassID, true) {} - - NS_DECL_FRAMEARENA_HELPERS(nsDocElementBoxFrame) - - bool IsFrameOfType(uint32_t aFlags) const override { - // Override nsBoxFrame. - if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced)) - return false; - return nsBoxFrame::IsFrameOfType(aFlags); - } - -#ifdef DEBUG_FRAME_DUMP - nsresult GetFrameName(nsAString& aResult) const override; -#endif -}; - -//---------------------------------------------------------------------- - -nsContainerFrame* NS_NewDocElementBoxFrame(PresShell* aPresShell, - ComputedStyle* aStyle) { - return new (aPresShell) - nsDocElementBoxFrame(aStyle, aPresShell->GetPresContext()); -} - -NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame) - -#ifdef DEBUG_FRAME_DUMP -nsresult nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const { - return MakeFrameName(u"DocElementBox"_ns, aResult); -} -#endif