Commit d8bcaf96 authored by Oriol Brufau's avatar Oriol Brufau Committed by Commit Bot

[css-pseudo] Use list item computed style when resolving marker margins

The list-style-type and list-style-image properties can affect the kind
of list marker that we have, including its margin. However, what matters
are the values on the originating list item, not on the ::marker itself.

Right now the difference doesn't matter, since ::marker doesn't accept
these properties, and thus must be inherited. But in the future we might
remove the restrictions and accept arbitrary properties in ::marker.

This patch uses the proper ComputedStyle when resolving margins.

Bug: 457718
Change-Id: I41aafb4b0b5778f637af6d74c0f50146a3698be8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2263834Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#784433}
parent a715453a
...@@ -239,8 +239,7 @@ static void AdjustStyleForMarker(ComputedStyle& style, ...@@ -239,8 +239,7 @@ static void AdjustStyleForMarker(ComputedStyle& style,
!parent_style.IsInsideListElement()); !parent_style.IsInsideListElement());
if (is_inside) { if (is_inside) {
auto margins = ListMarker::InlineMarginsForInside( auto margins = ListMarker::InlineMarginsForInside(style, parent_style);
style, parent_style.GeneratesMarkerImage());
style.SetMarginStart(Length::Fixed(margins.first)); style.SetMarginStart(Length::Fixed(margins.first));
style.SetMarginEnd(Length::Fixed(margins.second)); style.SetMarginEnd(Length::Fixed(margins.second));
} else { } else {
......
...@@ -260,12 +260,13 @@ void LayoutListMarker::UpdateMargins(LayoutUnit marker_inline_size) { ...@@ -260,12 +260,13 @@ void LayoutListMarker::UpdateMargins(LayoutUnit marker_inline_size) {
LayoutUnit margin_start; LayoutUnit margin_start;
LayoutUnit margin_end; LayoutUnit margin_end;
const ComputedStyle& style = StyleRef(); const ComputedStyle& style = StyleRef();
const ComputedStyle& list_item_style = ListItem()->StyleRef();
if (IsInside()) { if (IsInside()) {
std::tie(margin_start, margin_end) = std::tie(margin_start, margin_end) =
ListMarker::InlineMarginsForInside(style, IsImage()); ListMarker::InlineMarginsForInside(style, list_item_style);
} else { } else {
std::tie(margin_start, margin_end) = ListMarker::InlineMarginsForOutside( std::tie(margin_start, margin_end) = ListMarker::InlineMarginsForOutside(
style, IsImage(), marker_inline_size); style, list_item_style, marker_inline_size);
} }
SetMarginStart(margin_start); SetMarginStart(margin_start);
......
...@@ -274,16 +274,16 @@ LayoutUnit ListMarker::WidthOfSymbol(const ComputedStyle& style) { ...@@ -274,16 +274,16 @@ LayoutUnit ListMarker::WidthOfSymbol(const ComputedStyle& style) {
} }
std::pair<LayoutUnit, LayoutUnit> ListMarker::InlineMarginsForInside( std::pair<LayoutUnit, LayoutUnit> ListMarker::InlineMarginsForInside(
const ComputedStyle& style, const ComputedStyle& marker_style,
bool is_image) { const ComputedStyle& list_item_style) {
if (!style.ContentBehavesAsNormal()) if (!marker_style.ContentBehavesAsNormal())
return {}; return {};
if (is_image) if (list_item_style.GeneratesMarkerImage())
return {LayoutUnit(), LayoutUnit(kCMarkerPaddingPx)}; return {LayoutUnit(), LayoutUnit(kCMarkerPaddingPx)};
switch (GetListStyleCategory(style.ListStyleType())) { switch (GetListStyleCategory(list_item_style.ListStyleType())) {
case ListStyleCategory::kSymbol: case ListStyleCategory::kSymbol:
return {LayoutUnit(-1), return {LayoutUnit(-1),
LayoutUnit(kCUAMarkerMarginEm * style.ComputedFontSize())}; LayoutUnit(kCUAMarkerMarginEm * marker_style.ComputedFontSize())};
default: default:
break; break;
} }
...@@ -291,22 +291,22 @@ std::pair<LayoutUnit, LayoutUnit> ListMarker::InlineMarginsForInside( ...@@ -291,22 +291,22 @@ std::pair<LayoutUnit, LayoutUnit> ListMarker::InlineMarginsForInside(
} }
std::pair<LayoutUnit, LayoutUnit> ListMarker::InlineMarginsForOutside( std::pair<LayoutUnit, LayoutUnit> ListMarker::InlineMarginsForOutside(
const ComputedStyle& style, const ComputedStyle& marker_style,
bool is_image, const ComputedStyle& list_item_style,
LayoutUnit marker_inline_size) { LayoutUnit marker_inline_size) {
LayoutUnit margin_start; LayoutUnit margin_start;
LayoutUnit margin_end; LayoutUnit margin_end;
if (!style.ContentBehavesAsNormal()) { if (!marker_style.ContentBehavesAsNormal()) {
margin_start = -marker_inline_size; margin_start = -marker_inline_size;
} else if (is_image) { } else if (list_item_style.GeneratesMarkerImage()) {
margin_start = -marker_inline_size - kCMarkerPaddingPx; margin_start = -marker_inline_size - kCMarkerPaddingPx;
margin_end = LayoutUnit(kCMarkerPaddingPx); margin_end = LayoutUnit(kCMarkerPaddingPx);
} else { } else {
switch (GetListStyleCategory(style.ListStyleType())) { switch (GetListStyleCategory(list_item_style.ListStyleType())) {
case ListStyleCategory::kNone: case ListStyleCategory::kNone:
break; break;
case ListStyleCategory::kSymbol: { case ListStyleCategory::kSymbol: {
const SimpleFontData* font_data = style.GetFont().PrimaryFont(); const SimpleFontData* font_data = marker_style.GetFont().PrimaryFont();
DCHECK(font_data); DCHECK(font_data);
if (!font_data) if (!font_data)
return {}; return {};
......
...@@ -50,11 +50,11 @@ class CORE_EXPORT ListMarker { ...@@ -50,11 +50,11 @@ class CORE_EXPORT ListMarker {
// Compute inline margins for 'list-style-position: inside' and 'outside'. // Compute inline margins for 'list-style-position: inside' and 'outside'.
static std::pair<LayoutUnit, LayoutUnit> InlineMarginsForInside( static std::pair<LayoutUnit, LayoutUnit> InlineMarginsForInside(
const ComputedStyle&, const ComputedStyle& marker_style,
bool is_image); const ComputedStyle& list_item_style);
static std::pair<LayoutUnit, LayoutUnit> InlineMarginsForOutside( static std::pair<LayoutUnit, LayoutUnit> InlineMarginsForOutside(
const ComputedStyle&, const ComputedStyle& marker_style,
bool is_image, const ComputedStyle& list_item_style,
LayoutUnit marker_inline_size); LayoutUnit marker_inline_size);
static LayoutRect RelativeSymbolMarkerRect(const ComputedStyle&, LayoutUnit); static LayoutRect RelativeSymbolMarkerRect(const ComputedStyle&, LayoutUnit);
......
...@@ -22,12 +22,6 @@ NGUnpositionedListMarker::NGUnpositionedListMarker(const NGBlockNode& node) ...@@ -22,12 +22,6 @@ NGUnpositionedListMarker::NGUnpositionedListMarker(const NGBlockNode& node)
: NGUnpositionedListMarker( : NGUnpositionedListMarker(
ToLayoutNGOutsideListMarker(node.GetLayoutBox())) {} ToLayoutNGOutsideListMarker(node.GetLayoutBox())) {}
// Returns true if this is an image marker.
bool NGUnpositionedListMarker::IsImage() const {
DCHECK(marker_layout_object_);
return marker_layout_object_->Marker().IsMarkerImage(*marker_layout_object_);
}
// Compute the inline offset of the marker, relative to the list item. // Compute the inline offset of the marker, relative to the list item.
// The marker is relative to the border box of the list item and has nothing // The marker is relative to the border box of the list item and has nothing
// to do with the content offset. // to do with the content offset.
...@@ -35,8 +29,11 @@ bool NGUnpositionedListMarker::IsImage() const { ...@@ -35,8 +29,11 @@ bool NGUnpositionedListMarker::IsImage() const {
LayoutUnit NGUnpositionedListMarker::InlineOffset( LayoutUnit NGUnpositionedListMarker::InlineOffset(
const LayoutUnit marker_inline_size) const { const LayoutUnit marker_inline_size) const {
DCHECK(marker_layout_object_); DCHECK(marker_layout_object_);
LayoutObject* list_item =
marker_layout_object_->Marker().ListItem(*marker_layout_object_);
auto margins = ListMarker::InlineMarginsForOutside( auto margins = ListMarker::InlineMarginsForOutside(
marker_layout_object_->StyleRef(), IsImage(), marker_inline_size); marker_layout_object_->StyleRef(), list_item->StyleRef(),
marker_inline_size);
return margins.first; return margins.first;
} }
......
...@@ -99,8 +99,6 @@ class CORE_EXPORT NGUnpositionedListMarker final { ...@@ -99,8 +99,6 @@ class CORE_EXPORT NGUnpositionedListMarker final {
#endif #endif
private: private:
bool IsImage() const;
LayoutUnit ComputeIntrudedFloatOffset(const NGConstraintSpace&, LayoutUnit ComputeIntrudedFloatOffset(const NGConstraintSpace&,
const NGBoxFragmentBuilder*, const NGBoxFragmentBuilder*,
const NGBoxStrut&, const NGBoxStrut&,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment