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
This commit is contained in:
Emilio Cobos Álvarez 2022-10-01 02:35:31 +00:00
Родитель 462f51927a
Коммит 048e9bb783
10 изменённых файлов: 43 добавлений и 134 удалений

Просмотреть файл

@ -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]];

Просмотреть файл

@ -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),

Просмотреть файл

@ -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);

Просмотреть файл

@ -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 ====================

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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?");

Просмотреть файл

@ -23,7 +23,6 @@ UNIFIED_SOURCES += [
"nsBoxFrame.cpp",
"nsBoxLayout.cpp",
"nsBoxLayoutState.cpp",
"nsDocElementBoxFrame.cpp",
"nsImageBoxFrame.cpp",
"nsLeafBoxFrame.cpp",
"nsMenuBarFrame.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<nsBoxLayout> layout = aLayoutManager;
if (layout == nullptr) {
NS_NewSprocketLayout(layout);
}
// Use the static sprocket layout
nsCOMPtr<nsBoxLayout> 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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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