Skip to content

Commit

Permalink
Backed out changeset 63fbc22d2223 (bug 1792741) for causing assertion…
Browse files Browse the repository at this point in the history
… failures on nsCSSFrameConstructor.cpp. CLOSED TREE
  • Loading branch information
ncsoregi committed Oct 1, 2022
1 parent 39da87d commit 462f519
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 41 deletions.
44 changes: 26 additions & 18 deletions layout/base/nsCSSFrameConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ static FrameCtorDebugFlags gFlags[] = {

//------------------------------------------------------------------

nsContainerFrame* NS_NewDocElementBoxFrame(PresShell* aPresShell,
ComputedStyle* aStyle);

nsIFrame* NS_NewLeafBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle);

nsIFrame* NS_NewRangeFrame(PresShell* aPresShell, ComputedStyle* aStyle);
Expand Down Expand Up @@ -2417,7 +2420,14 @@ nsIFrame* nsCSSFrameConstructor::ConstructDocElementFrame(

nsFrameConstructorSaveState absoluteSaveState;

if (aDocElement->IsSVGElement()) {
// 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(nsGkAtoms::svg)) {
return nullptr;
}
Expand All @@ -2437,17 +2447,11 @@ nsIFrame* nsCSSFrameConstructor::ConstructDocElementFrame(
} else if (display->mDisplay == StyleDisplay::Flex ||
display->mDisplay == StyleDisplay::WebkitBox ||
display->mDisplay == StyleDisplay::Grid ||
display->mDisplay == StyleDisplay::MozBox) {
auto func = [&] {
if (display->mDisplay == StyleDisplay::Grid) {
return NS_NewGridContainerFrame;
}
if (display->mDisplay == StyleDisplay::MozBox &&
!computedStyle->StyleVisibility()->EmulateMozBoxWithFlex()) {
return NS_NewBoxFrame;
}
return NS_NewFlexContainerFrame;
}();
(display->mDisplay == StyleDisplay::MozBox &&
computedStyle->StyleVisibility()->EmulateMozBoxWithFlex())) {
auto func = display->mDisplay == StyleDisplay::Grid
? NS_NewGridContainerFrame
: NS_NewFlexContainerFrame;
contentFrame = func(mPresShell, computedStyle);
InitAndRestoreFrame(
state, aDocElement,
Expand Down Expand Up @@ -2598,14 +2602,19 @@ void nsCSSFrameConstructor::SetUpDocElementContainingBlock(
/*
how the root frame hierarchy should look

Galley presentation, with scrolling:
Galley presentation, non-XUL, with scrolling:

ViewportFrame [fixed-cb]
nsHTMLScrollFrame (if needed)
nsHTMLScrollFrame
nsCanvasFrame [abs-cb]
root element frame (nsBlockFrame, SVGOuterSVGFrame,
nsTableWrapperFrame, nsPlaceholderFrame,
nsBoxFrame)
nsTableWrapperFrame, nsPlaceholderFrame)

Galley presentation, XUL

ViewportFrame [fixed-cb]
nsCanvasFrame [abs-cb]
root element frame (nsDocElementBoxFrame)

Print presentation, non-XUL

Expand Down Expand Up @@ -4463,8 +4472,7 @@ nsCSSFrameConstructor::FindDisplayData(const nsStyleDisplay& aDisplay,
if (aMozBoxLayout == StyleMozBoxLayout::Legacy ||
aElement.IsXULElement(nsGkAtoms::scrollcorner)) {
static constexpr FrameConstructionData data =
SCROLLABLE_ABSPOS_CONTAINER_XUL_FCDATA(
ToCreationFunc(NS_NewBoxFrame));
SCROLLABLE_ABSPOS_CONTAINER_XUL_FCDATA(NS_NewBoxFrame);
return &data;
}
[[fallthrough]];
Expand Down
1 change: 1 addition & 0 deletions layout/generic/FrameClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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),
Expand Down
2 changes: 1 addition & 1 deletion layout/generic/nsContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,

nsSize minSize(0, 0);
nsSize maxSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
if (rootFrame->IsXULBoxFrame()) {
if (rootElement->IsXULElement()) {
nsBoxLayoutState aState(aPresContext, aRC);
minSize = rootFrame->GetXULMinSize(aState);
maxSize = rootFrame->GetXULMaxSize(aState);
Expand Down
8 changes: 5 additions & 3 deletions layout/generic/nsFrameStateBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,11 @@ 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_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_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 bits that apply to flex container frames ====================

Expand Down
2 changes: 1 addition & 1 deletion layout/generic/nsGfxScrollFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ NS_IMPL_FRAMEARENA_HELPERS(nsXULScrollFrame)

nsXULScrollFrame::nsXULScrollFrame(ComputedStyle* aStyle,
nsPresContext* aPresContext, bool aIsRoot)
: nsBoxFrame(aStyle, aPresContext, kClassID),
: nsBoxFrame(aStyle, aPresContext, kClassID, aIsRoot),
mHelper(ALLOW_THIS_IN_INITIALIZER_LIST(this), aIsRoot) {
SetXULLayoutManager(nullptr);
}
Expand Down
10 changes: 5 additions & 5 deletions layout/painting/nsDisplayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
// 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.

if (IsPartialUpdate()) {
if (aItem->Frame()->Style()->IsRootElementStyle()) {
if (aItem->Frame()->IsDocElementBoxFrame()) {
#ifdef DEBUG
if (mHasGlassItemDuringPartial) {
NS_WARNING("Multiple glass backgrounds found?");
Expand All @@ -856,7 +856,7 @@ void nsDisplayListBuilder::SetGlassDisplayItem(nsDisplayItem* aItem) {
return;
}

if (aItem->Frame()->Style()->IsRootElementStyle()) {
if (aItem->Frame()->IsDocElementBoxFrame()) {
#ifdef DEBUG
if (mGlassDisplayItem) {
NS_WARNING("Multiple glass backgrounds found?");
Expand Down
1 change: 1 addition & 0 deletions layout/xul/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ UNIFIED_SOURCES += [
"nsBoxFrame.cpp",
"nsBoxLayout.cpp",
"nsBoxLayoutState.cpp",
"nsDocElementBoxFrame.cpp",
"nsImageBoxFrame.cpp",
"nsLeafBoxFrame.cpp",
"nsMenuBarFrame.cpp",
Expand Down
27 changes: 20 additions & 7 deletions layout/xul/nsBoxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::gfx;

nsContainerFrame* NS_NewBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
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) {
return new (aPresShell) nsBoxFrame(aStyle, aPresShell->GetPresContext());
}

Expand All @@ -100,16 +107,22 @@ NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
#endif

nsBoxFrame::nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
ClassID aID)
ClassID aID, bool aIsRoot, nsBoxLayout* aLayoutManager)
: 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;

// Use the static sprocket layout
nsCOMPtr<nsBoxLayout> layout;
NS_NewSprocketLayout(layout);
// if no layout manager specified us the static sprocket layout
nsCOMPtr<nsBoxLayout> layout = aLayoutManager;

if (layout == nullptr) {
NS_NewSprocketLayout(layout);
}

SetXULLayoutManager(layout);
}

Expand Down Expand Up @@ -525,7 +538,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 (!Style()->IsRootElementStyle()) {
if (!(mState & NS_STATE_IS_ROOT)) {
ascent = GetXULBoxAscent(state);
}

Expand Down Expand Up @@ -694,7 +707,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 (!Style()->IsRootElementStyle()) {
if (!(mState & NS_STATE_IS_ROOT)) {
ascent = GetXULBoxAscent(aState);
}
desiredSize.SetBlockStartAscent(ascent);
Expand Down
19 changes: 13 additions & 6 deletions layout/xul/nsBoxFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ class DrawTarget;
} // namespace gfx
} // namespace mozilla

nsContainerFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
mozilla::ComputedStyle* aStyle);
nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
mozilla::ComputedStyle* aStyle, bool aIsRoot,
nsBoxLayout* aLayoutManager);
nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
mozilla::ComputedStyle* aStyle);

class nsBoxFrame : public nsContainerFrame {
protected:
Expand All @@ -42,8 +45,11 @@ class nsBoxFrame : public nsContainerFrame {
NS_DECL_QUERYFRAME
#endif

friend nsContainerFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
ComputedStyle* aStyle);
friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
ComputedStyle* aStyle, bool aIsRoot,
nsBoxLayout* aLayoutManager);
friend nsIFrame* 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
Expand Down Expand Up @@ -144,10 +150,11 @@ class nsBoxFrame : public nsContainerFrame {

private:
explicit nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
: nsBoxFrame(aStyle, aPresContext, kClassID) {}
: nsBoxFrame(aStyle, aPresContext, kClassID, false, nullptr) {}

protected:
nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID);
nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID,
bool aIsRoot = false, nsBoxLayout* aLayoutManager = nullptr);
virtual ~nsBoxFrame();

virtual bool GetInitialEqualSize(bool& aEqualSize);
Expand Down
61 changes: 61 additions & 0 deletions layout/xul/nsDocElementBoxFrame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* -*- 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

0 comments on commit 462f519

Please sign in to comment.