Skip to content

Commit

Permalink
Bug 1874823 - Make nsBlockFrame::Init set NS_BLOCK_STATIC_BFC by chec…
Browse files Browse the repository at this point in the history
…king classes. r=layout-reviewers,AlaskanEmily

The following classes deriving from nsBlockFrame always set
NS_BLOCK_STATIC_BFC in their constructors or initializers:

- nsComboboxControlFrame
- nsFileControlFrame
- nsSelectsAreaFrame
- ColumnSetWrapperFrame
- nsMathMLmathBlockFrame

Do that in nsBlockFrame::Init instead. Behavior is unchanged.

Differential Revision: https://phabricator.services.mozilla.com/D199097
  • Loading branch information
fred-wang committed Jan 24, 2024
1 parent be776b9 commit f14fe86
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 25 deletions.
5 changes: 0 additions & 5 deletions layout/forms/nsComboboxControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ nsComboboxControlFrame* NS_NewComboboxControlFrame(PresShell* aPresShell,
ComputedStyle* aStyle) {
nsComboboxControlFrame* it = new (aPresShell)
nsComboboxControlFrame(aStyle, aPresShell->GetPresContext());

if (it) {
it->AddStateBits(NS_BLOCK_STATIC_BFC);
}

return it;
}

Expand Down
4 changes: 1 addition & 3 deletions layout/forms/nsFileControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ NS_IMPL_FRAMEARENA_HELPERS(nsFileControlFrame)

nsFileControlFrame::nsFileControlFrame(ComputedStyle* aStyle,
nsPresContext* aPresContext)
: nsBlockFrame(aStyle, aPresContext, kClassID) {
AddStateBits(NS_BLOCK_STATIC_BFC);
}
: nsBlockFrame(aStyle, aPresContext, kClassID) {}

void nsFileControlFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
nsIFrame* aPrevInFlow) {
Expand Down
9 changes: 4 additions & 5 deletions layout/forms/nsSelectsAreaFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ nsContainerFrame* NS_NewSelectsAreaFrame(PresShell* aShell,
ComputedStyle* aStyle) {
nsSelectsAreaFrame* it =
new (aShell) nsSelectsAreaFrame(aStyle, aShell->GetPresContext());

// We need NS_BLOCK_STATIC_BFC to ensure that the options inside the select
// aren't expanded by right floats outside the select.
it->AddStateBits(NS_BLOCK_STATIC_BFC);

return it;
}

NS_IMPL_FRAMEARENA_HELPERS(nsSelectsAreaFrame)

NS_QUERYFRAME_HEAD(nsSelectsAreaFrame)
NS_QUERYFRAME_ENTRY(nsSelectsAreaFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)

static nsListControlFrame* GetEnclosingListFrame(nsIFrame* aSelectsAreaFrame) {
nsIFrame* frame = aSelectsAreaFrame->GetParent();
while (frame) {
Expand Down
1 change: 1 addition & 0 deletions layout/forms/nsSelectsAreaFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PresShell;

class nsSelectsAreaFrame final : public nsBlockFrame {
public:
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS(nsSelectsAreaFrame)

friend nsContainerFrame* NS_NewSelectsAreaFrame(mozilla::PresShell* aShell,
Expand Down
6 changes: 1 addition & 5 deletions layout/generic/ColumnSetWrapperFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ nsBlockFrame* NS_NewColumnSetWrapperFrame(PresShell* aPresShell,
nsFrameState aStateFlags) {
ColumnSetWrapperFrame* frame = new (aPresShell)
ColumnSetWrapperFrame(aStyle, aPresShell->GetPresContext());

// CSS Multi-column level 1 section 2: A multi-column container
// establishes a new block formatting context, as per CSS 2.1 section
// 9.4.1.
frame->AddStateBits(aStateFlags | NS_BLOCK_STATIC_BFC);
frame->AddStateBits(aStateFlags);
return frame;
}

Expand Down
28 changes: 27 additions & 1 deletion layout/generic/nsBlockFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
#include "mozilla/ServoStyleSet.h"
#include "mozilla/Telemetry.h"
#include "nsFlexContainerFrame.h"
#include "nsFileControlFrame.h"
#include "nsMathMLContainerFrame.h"
#include "nsSelectsAreaFrame.h"

#include "nsBidiPresUtils.h"

Expand Down Expand Up @@ -7746,6 +7749,26 @@ void nsBlockFrame::ChildIsDirty(nsIFrame* aChild) {
nsContainerFrame::ChildIsDirty(aChild);
}

static bool AlwaysEstablishesBFC(const nsBlockFrame* aFrame) {
switch (aFrame->Type()) {
case LayoutFrameType::ColumnSetWrapper:
// CSS Multi-column level 1 section 2: A multi-column container
// establishes a new block formatting context, as per CSS 2.1 section
// 9.4.1.
case LayoutFrameType::ComboboxControl:
return true;
case LayoutFrameType::Block:
return static_cast<const nsFileControlFrame*>(do_QueryFrame(aFrame)) ||
// Ensure that the options inside the select aren't expanded by
// right floats outside the select.
static_cast<const nsSelectsAreaFrame*>(do_QueryFrame(aFrame)) ||
// See bug 1373767 and bug 353894.
static_cast<const nsMathMLmathBlockFrame*>(do_QueryFrame(aFrame));
default:
return false;
}
}

void nsBlockFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
nsIFrame* aPrevInFlow) {
// These are all the block specific frame bits, they are copied from
Expand Down Expand Up @@ -7788,13 +7811,16 @@ void nsBlockFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
// then it should also establish a formatting context.
//
// Per spec, a column-span always establishes a new block formatting context.
//
// Other more specific frame types also always establish a BFC.
//
if (StyleDisplay()->mDisplay == mozilla::StyleDisplay::FlowRoot ||
(GetParent() &&
(GetWritingMode().GetBlockDir() !=
GetParent()->GetWritingMode().GetBlockDir() ||
GetWritingMode().IsVerticalSideways() !=
GetParent()->GetWritingMode().IsVerticalSideways())) ||
IsColumnSpan()) {
IsColumnSpan() || AlwaysEstablishesBFC(this)) {
AddStateBits(NS_BLOCK_STATIC_BFC);
}

Expand Down
7 changes: 6 additions & 1 deletion layout/mathml/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ UNIFIED_SOURCES += [
"nsMathMLTokenFrame.cpp",
]

EXPORTS += ["nsIMathMLFrame.h", "nsMathMLOperators.h"]
EXPORTS += [
"nsIMathMLFrame.h",
"nsMathMLContainerFrame.h",
"nsMathMLFrame.h",
"nsMathMLOperators.h",
]

include("/ipc/chromium/chromium-config.mozbuild")

Expand Down
1 change: 0 additions & 1 deletion layout/mathml/nsMathMLContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,6 @@ nsContainerFrame* NS_NewMathMLmathBlockFrame(PresShell* aPresShell,
ComputedStyle* aStyle) {
auto newFrame = new (aPresShell)
nsMathMLmathBlockFrame(aStyle, aPresShell->GetPresContext());
newFrame->AddStateBits(NS_BLOCK_STATIC_BFC);
return newFrame;
}

Expand Down
4 changes: 0 additions & 4 deletions layout/mathml/nsMathMLContainerFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,6 @@ class nsMathMLmathBlockFrame final : public nsBlockFrame {
explicit nsMathMLmathBlockFrame(ComputedStyle* aStyle,
nsPresContext* aPresContext)
: nsBlockFrame(aStyle, aPresContext, kClassID) {
// We should always have a float manager. Not that things can really try
// to float out of us anyway, but we need one for line layout.
// Bug 1301881: Do we still need to set NS_BLOCK_STATIC_BFC?
// AddStateBits(NS_BLOCK_STATIC_BFC);
}
virtual ~nsMathMLmathBlockFrame() = default;
};
Expand Down

0 comments on commit f14fe86

Please sign in to comment.