Skip to content

Commit

Permalink
Bug 1844195 - Avoid duplicating rust and C++ display definitions. r=l…
Browse files Browse the repository at this point in the history
…ayout-reviewers,jfkthame

We need to inline Self::new() so cbindgen generates the constants, which
is kinda lame, but seems better than duplicating the values and type
definitions.

Differential Revision: https://phabricator.services.mozilla.com/D183921
  • Loading branch information
emilio committed Jul 25, 2023
1 parent 1a258a9 commit c70814a
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 249 deletions.
6 changes: 3 additions & 3 deletions dom/base/nsRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3185,13 +3185,13 @@ void nsRange::GetInnerTextNoFlush(DOMString& aValue, ErrorResult& aError,
if (currentNode->IsHTMLElement(nsGkAtoms::br)) {
result.Append('\n');
}
switch (f->StyleDisplay()->mDisplay) {
case StyleDisplay::TableCell:
switch (f->StyleDisplay()->DisplayInside()) {
case StyleDisplayInside::TableCell:
if (!IsLastCellOfRow(f)) {
result.Append('\t');
}
break;
case StyleDisplay::TableRow:
case StyleDisplayInside::TableRow:
if (!IsLastRowOfRowGroup(f) ||
!IsLastNonemptyRowGroupOfTable(f->GetParent())) {
result.Append('\n');
Expand Down
2 changes: 1 addition & 1 deletion dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ void nsGenericHTMLElement::MapCommonAttributesInto(
MapCommonAttributesIntoExceptHidden(aBuilder);
if (!aBuilder.PropertyIsSet(eCSSProperty_display)) {
if (aBuilder.GetAttr(nsGkAtoms::hidden)) {
aBuilder.SetKeywordValue(eCSSProperty_display, StyleDisplay::None);
aBuilder.SetKeywordValue(eCSSProperty_display, StyleDisplay::None._0);
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions layout/base/nsCSSFrameConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5277,7 +5277,7 @@ nsCSSFrameConstructor::FindElementData(const Element& aElement,
bool isRootElement = false;
uint16_t rawDisplayValue =
Servo_ComputedValues_BlockifiedDisplay(&aStyle, isRootElement);
display.mDisplay = StyleDisplay(rawDisplayValue);
display.mDisplay = StyleDisplay{rawDisplayValue};
return FindDisplayData(display, aElement);
}

Expand Down Expand Up @@ -8808,8 +8808,7 @@ void nsCSSFrameConstructor::CreateNeededAnonFlexOrGridItems(
/* static */ nsCSSFrameConstructor::RubyWhitespaceType
nsCSSFrameConstructor::ComputeRubyWhitespaceType(StyleDisplay aPrevDisplay,
StyleDisplay aNextDisplay) {
MOZ_ASSERT(nsStyleDisplay::IsRubyDisplayType(aPrevDisplay) &&
nsStyleDisplay::IsRubyDisplayType(aNextDisplay));
MOZ_ASSERT(aPrevDisplay.IsRuby() && aNextDisplay.IsRuby());
if (aPrevDisplay == aNextDisplay &&
(aPrevDisplay == StyleDisplay::RubyBase ||
aPrevDisplay == StyleDisplay::RubyText)) {
Expand Down Expand Up @@ -9254,10 +9253,9 @@ void nsCSSFrameConstructor::WrapItemsInPseudoParent(
pseudoType);
}

FrameConstructionItem* newItem = new (this)
FrameConstructionItem(&pseudoData.mFCData,
// Use the content of our parent frame
aParentContent, wrapperStyle.forget(), true);
// Use the content of our parent frame
auto* newItem = new (this) FrameConstructionItem(
&pseudoData.mFCData, aParentContent, wrapperStyle.forget(), true);

const nsStyleDisplay* disp = newItem->mComputedStyle->StyleDisplay();
// Here we're cheating a tad... technically, table-internal items should be
Expand Down
3 changes: 1 addition & 2 deletions layout/generic/nsBlockFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,7 @@ static bool IsLineClampRoot(const nsBlockFrame* aFrame) {
}
return aFrame->StyleDisplay()->mOriginalDisplay;
}();
return nsStyleDisplay::DisplayInside(origDisplay) ==
StyleDisplayInside::WebkitBox;
return origDisplay.Inside() == StyleDisplayInside::WebkitBox;
}

bool nsBlockFrame::IsInLineClampContext() const {
Expand Down
34 changes: 16 additions & 18 deletions layout/generic/nsIFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,18 @@ static bool IsFontSizeInflationContainer(nsIFrame* aFrame,

LayoutFrameType frameType = aFrame->Type();
bool isInline =
(nsStyleDisplay::IsInlineFlow(aFrame->GetDisplay()) ||
RubyUtils::IsRubyBox(frameType) ||
(aStyleDisplay->IsFloatingStyle() &&
frameType == LayoutFrameType::Letter) ||
// Given multiple frames for the same node, only the
// outer one should be considered a container.
// (Important, e.g., for nsSelectsAreaFrame.)
(aFrame->GetParent()->GetContent() == content) ||
(content &&
// Form controls shouldn't become inflation containers.
(content->IsAnyOfHTMLElements(
nsGkAtoms::option, nsGkAtoms::optgroup, nsGkAtoms::select,
nsGkAtoms::input, nsGkAtoms::button, nsGkAtoms::textarea))));
aFrame->GetDisplay().IsInlineFlow() || RubyUtils::IsRubyBox(frameType) ||
(aStyleDisplay->IsFloatingStyle() &&
frameType == LayoutFrameType::Letter) ||
// Given multiple frames for the same node, only the
// outer one should be considered a container.
// (Important, e.g., for nsSelectsAreaFrame.)
(aFrame->GetParent()->GetContent() == content) ||
(content &&
// Form controls shouldn't become inflation containers.
(content->IsAnyOfHTMLElements(nsGkAtoms::option, nsGkAtoms::optgroup,
nsGkAtoms::select, nsGkAtoms::input,
nsGkAtoms::button, nsGkAtoms::textarea)));
NS_ASSERTION(!aFrame->IsFrameOfType(nsIFrame::eLineParticipant) || isInline ||
// br frames and mathml frames report being line
// participants even when their position or display is
Expand Down Expand Up @@ -2417,10 +2416,9 @@ static inline bool IsIntrinsicKeyword(const SizeOrMaxSize& aSize) {
}

bool nsIFrame::CanBeDynamicReflowRoot() const {
auto& display = *StyleDisplay();
if (IsFrameOfType(nsIFrame::eLineParticipant) ||
nsStyleDisplay::IsRubyDisplayType(display.mDisplay) ||
display.DisplayOutside() == StyleDisplayOutside::InternalTable ||
const auto& display = *StyleDisplay();
if (IsFrameOfType(nsIFrame::eLineParticipant) || display.mDisplay.IsRuby() ||
display.IsInnerTableStyle() ||
display.DisplayInside() == StyleDisplayInside::Table) {
// We have a display type where 'width' and 'height' don't actually set the
// width or height (i.e., the size depends on content).
Expand Down Expand Up @@ -2457,7 +2455,7 @@ bool nsIFrame::CanBeDynamicReflowRoot() const {
//
// FIXME: For display:block, we should probably optimize inline-size: auto.
// FIXME: Other flex and grid cases?
auto& pos = *StylePosition();
const auto& pos = *StylePosition();
const auto& width = pos.mWidth;
const auto& height = pos.mHeight;
if (!width.IsLengthPercentage() || width.HasPercent() ||
Expand Down
6 changes: 3 additions & 3 deletions layout/generic/nsTextFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4735,10 +4735,10 @@ void nsTextFrame::GetTextDecorations(
// If we're on a ruby frame other than ruby text container, we
// should continue.
mozilla::StyleDisplay display = f->GetDisplay();
if (!nsStyleDisplay::IsInlineFlow(display) &&
(!nsStyleDisplay::IsRubyDisplayType(display) ||
if (!display.IsInlineFlow() &&
(!display.IsRuby() ||
display == mozilla::StyleDisplay::RubyTextContainer) &&
nsStyleDisplay::IsDisplayTypeInlineOutside(display)) {
display.IsInlineOutside()) {
break;
}

Expand Down
39 changes: 39 additions & 0 deletions layout/style/ServoStyleConstsInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,45 @@ inline StyleViewTimelineInset::StyleGenericViewTimelineInset()
: start(LengthPercentageOrAuto::Auto()),
end(LengthPercentageOrAuto::Auto()) {}

inline StyleDisplayOutside StyleDisplay::Outside() const {
return StyleDisplayOutside((_0 & OUTSIDE_MASK) >> OUTSIDE_SHIFT);
}

inline StyleDisplayInside StyleDisplay::Inside() const {
return StyleDisplayInside(_0 & INSIDE_MASK);
}

inline bool StyleDisplay::IsListItem() const { return _0 & LIST_ITEM_MASK; }

inline bool StyleDisplay::IsInternalTable() const {
return Outside() == StyleDisplayOutside::InternalTable;
}

inline bool StyleDisplay::IsInternalTableExceptCell() const {
return IsInternalTable() && *this != TableCell;
}

inline bool StyleDisplay::IsInternalRuby() const {
return Outside() == StyleDisplayOutside::InternalRuby;
}

inline bool StyleDisplay::IsRuby() const {
return Inside() == StyleDisplayInside::Ruby || IsInternalRuby();
}

inline bool StyleDisplay::IsInlineFlow() const {
return Outside() == StyleDisplayOutside::Inline &&
Inside() == StyleDisplayInside::Flow;
}

inline bool StyleDisplay::IsInlineInside() const {
return IsInlineFlow() || IsRuby();
}

inline bool StyleDisplay::IsInlineOutside() const {
return Outside() == StyleDisplayOutside::Inline || IsInternalRuby();
}

} // namespace mozilla

#endif
72 changes: 0 additions & 72 deletions layout/style/nsStyleConsts.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,78 +20,6 @@

namespace mozilla {

static constexpr uint16_t STYLE_DISPLAY_LIST_ITEM_BIT = 0x8000;
static constexpr uint8_t STYLE_DISPLAY_OUTSIDE_BITS = 7;
static constexpr uint8_t STYLE_DISPLAY_INSIDE_BITS = 8;

// The `display` longhand.
uint16_t constexpr StyleDisplayFrom(StyleDisplayOutside aOuter,
StyleDisplayInside aInner) {
return uint16_t(uint16_t(aOuter) << STYLE_DISPLAY_INSIDE_BITS) |
uint16_t(aInner);
}

enum class StyleDisplay : uint16_t {
// These MUST be in sync with the Rust enum values in
// servo/components/style/values/specified/box.rs
/// https://drafts.csswg.org/css-display/#the-display-properties
None = StyleDisplayFrom(StyleDisplayOutside::None, StyleDisplayInside::None),
Contents =
StyleDisplayFrom(StyleDisplayOutside::None, StyleDisplayInside::Contents),
Inline =
StyleDisplayFrom(StyleDisplayOutside::Inline, StyleDisplayInside::Flow),
Block =
StyleDisplayFrom(StyleDisplayOutside::Block, StyleDisplayInside::Flow),
FlowRoot = StyleDisplayFrom(StyleDisplayOutside::Block,
StyleDisplayInside::FlowRoot),
Flex = StyleDisplayFrom(StyleDisplayOutside::Block, StyleDisplayInside::Flex),
Grid = StyleDisplayFrom(StyleDisplayOutside::Block, StyleDisplayInside::Grid),
Table =
StyleDisplayFrom(StyleDisplayOutside::Block, StyleDisplayInside::Table),
InlineTable =
StyleDisplayFrom(StyleDisplayOutside::Inline, StyleDisplayInside::Table),
TableCaption = StyleDisplayFrom(StyleDisplayOutside::TableCaption,
StyleDisplayInside::Flow),
Ruby =
StyleDisplayFrom(StyleDisplayOutside::Inline, StyleDisplayInside::Ruby),
WebkitBox = StyleDisplayFrom(StyleDisplayOutside::Block,
StyleDisplayInside::WebkitBox),
WebkitInlineBox = StyleDisplayFrom(StyleDisplayOutside::Inline,
StyleDisplayInside::WebkitBox),
ListItem = Block | STYLE_DISPLAY_LIST_ITEM_BIT,

/// Internal table boxes.
TableRowGroup = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableRowGroup),
TableHeaderGroup = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableHeaderGroup),
TableFooterGroup = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableFooterGroup),
TableColumn = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableColumn),
TableColumnGroup = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableColumnGroup),
TableRow = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableRow),
TableCell = StyleDisplayFrom(StyleDisplayOutside::InternalTable,
StyleDisplayInside::TableCell),

/// Internal ruby boxes.
RubyBase = StyleDisplayFrom(StyleDisplayOutside::InternalRuby,
StyleDisplayInside::RubyBase),
RubyBaseContainer = StyleDisplayFrom(StyleDisplayOutside::InternalRuby,
StyleDisplayInside::RubyBaseContainer),
RubyText = StyleDisplayFrom(StyleDisplayOutside::InternalRuby,
StyleDisplayInside::RubyText),
RubyTextContainer = StyleDisplayFrom(StyleDisplayOutside::InternalRuby,
StyleDisplayInside::RubyTextContainer),
};
// The order of the StyleDisplay values isn't meaningful.
bool operator<(const StyleDisplay&, const StyleDisplay&) = delete;
bool operator<=(const StyleDisplay&, const StyleDisplay&) = delete;
bool operator>(const StyleDisplay&, const StyleDisplay&) = delete;
bool operator>=(const StyleDisplay&, const StyleDisplay&) = delete;

// box-align
enum class StyleBoxAlign : uint8_t {
Stretch,
Expand Down
86 changes: 11 additions & 75 deletions layout/style/nsStyleStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -1456,81 +1456,31 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
}
}

static mozilla::StyleDisplayOutside DisplayOutside(
mozilla::StyleDisplay aDisplay) {
return mozilla::StyleDisplayOutside(
(uint16_t(aDisplay) >> mozilla::STYLE_DISPLAY_INSIDE_BITS) &
uint16_t(((1 << mozilla::STYLE_DISPLAY_OUTSIDE_BITS) - 1)));
}
mozilla::StyleDisplayOutside DisplayOutside() const {
return DisplayOutside(mDisplay);
}

static mozilla::StyleDisplayInside DisplayInside(
mozilla::StyleDisplay aDisplay) {
return mozilla::StyleDisplayInside(
uint16_t(aDisplay) &
uint16_t(((1 << mozilla::STYLE_DISPLAY_INSIDE_BITS) - 1)));
return mDisplay.Outside();
}
mozilla::StyleDisplayInside DisplayInside() const {
return DisplayInside(mDisplay);
return mDisplay.Inside();
}
bool IsListItem() const { return mDisplay.IsListItem(); }
bool IsInlineFlow() const { return mDisplay.IsInlineFlow(); }

static bool IsListItem(mozilla::StyleDisplay aDisplay) {
return !!(uint16_t(aDisplay) & mozilla::STYLE_DISPLAY_LIST_ITEM_BIT);
}
bool IsListItem() const { return IsListItem(mDisplay); }

// Whether display is `inline` or `inline list-item`.
static bool IsInlineFlow(mozilla::StyleDisplay aDisplay) {
return DisplayOutside(aDisplay) == mozilla::StyleDisplayOutside::Inline &&
DisplayInside(aDisplay) == mozilla::StyleDisplayInside::Flow;
}

bool IsInlineFlow() const { return IsInlineFlow(mDisplay); }

bool IsInlineInsideStyle() const {
auto inside = DisplayInside();
return IsInlineFlow() || inside == mozilla::StyleDisplayInside::Ruby ||
inside == mozilla::StyleDisplayInside::RubyBase ||
inside == mozilla::StyleDisplayInside::RubyBaseContainer ||
inside == mozilla::StyleDisplayInside::RubyText ||
inside == mozilla::StyleDisplayInside::RubyTextContainer;
}
bool IsInlineInsideStyle() const { return mDisplay.IsInlineInside(); }

bool IsBlockOutsideStyle() const {
return DisplayOutside() == mozilla::StyleDisplayOutside::Block;
}

static bool IsDisplayTypeInlineOutside(mozilla::StyleDisplay aDisplay) {
auto outside = DisplayOutside(aDisplay);
if (outside == mozilla::StyleDisplayOutside::Inline) {
return true;
}
// just an optimization for the common case:
if (outside == mozilla::StyleDisplayOutside::Block) {
return false;
}
return mozilla::StyleDisplay::RubyBase == aDisplay ||
mozilla::StyleDisplay::RubyBaseContainer == aDisplay ||
mozilla::StyleDisplay::RubyText == aDisplay ||
mozilla::StyleDisplay::RubyTextContainer == aDisplay;
}

bool IsInlineOutsideStyle() const {
return IsDisplayTypeInlineOutside(mDisplay);
}
bool IsInlineOutsideStyle() const { return mDisplay.IsInlineOutside(); }

bool IsOriginalDisplayInlineOutside() const {
return IsDisplayTypeInlineOutside(mOriginalDisplay);
return mOriginalDisplay.IsInlineOutside();
}

bool IsInnerTableStyle() const {
return DisplayOutside() == mozilla::StyleDisplayOutside::InternalTable;
}
bool IsInnerTableStyle() const { return mDisplay.IsInternalTable(); }

bool IsInternalTableStyleExceptCell() const {
return IsInnerTableStyle() && mozilla::StyleDisplay::TableCell != mDisplay;
return mDisplay.IsInternalTableExceptCell();
}

bool IsFloatingStyle() const { return mozilla::StyleFloat::None != mFloat; }
Expand Down Expand Up @@ -1560,23 +1510,9 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
mozilla::StylePositionProperty::Fixed == mPosition;
}

static bool IsRubyDisplayType(mozilla::StyleDisplay aDisplay) {
return DisplayInside(aDisplay) == mozilla::StyleDisplayInside::Ruby ||
IsInternalRubyDisplayType(aDisplay);
}

static bool IsInternalRubyDisplayType(mozilla::StyleDisplay aDisplay) {
return mozilla::StyleDisplay::RubyBase == aDisplay ||
mozilla::StyleDisplay::RubyBaseContainer == aDisplay ||
mozilla::StyleDisplay::RubyText == aDisplay ||
mozilla::StyleDisplay::RubyTextContainer == aDisplay;
}
bool IsRubyDisplayType() const { return mDisplay.IsRuby(); }

bool IsRubyDisplayType() const { return IsRubyDisplayType(mDisplay); }

bool IsInternalRubyDisplayType() const {
return IsInternalRubyDisplayType(mDisplay);
}
bool IsInternalRubyDisplayType() const { return mDisplay.IsInternalRuby(); }

bool IsOutOfFlowStyle() const {
return (IsAbsolutelyPositionedStyle() || IsFloatingStyle());
Expand Down
8 changes: 4 additions & 4 deletions layout/tables/nsCellMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,14 +2162,14 @@ void nsCellMap::Dump(bool aIsBorderCollapse) const {
printf("\n ***** START GROUP CELL MAP DUMP ***** %p\n", (void*)this);
nsTableRowGroupFrame* rg = GetRowGroup();
const nsStyleDisplay* display = rg->StyleDisplay();
switch (display->mDisplay) {
case StyleDisplay::TableHeaderGroup:
switch (display->DisplayInside()) {
case StyleDisplayInside::TableHeaderGroup:
printf(" thead ");
break;
case StyleDisplay::TableFooterGroup:
case StyleDisplayInside::TableFooterGroup:
printf(" tfoot ");
break;
case StyleDisplay::TableRowGroup:
case StyleDisplayInside::TableRowGroup:
printf(" tbody ");
break;
default:
Expand Down
Loading

0 comments on commit c70814a

Please sign in to comment.