[text-box-trim] Correct detection of intervening border/padding.
Replace what crrev.com/c/5905670 did. The detection code is now in BlockLayoutAlgorithm(). Border / padding at the container that establishes box trimming shouldn't be considered to be intervening. Only check border/padding on descendants. Bug: 40254880 Change-Id: I45b7c28f5dd37df20eb90c377759642fd3b76ed1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5960337 Reviewed-by: Koji Ishii <kojii@chromium.org> Commit-Queue: Morten Stenshorne <mstensho@chromium.org> Cr-Commit-Position: refs/heads/main@{#1374580}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e105b59875
commit
dcee011cb7
third_party/blink
renderer
core
web_tests
external
wpt
css
css-inline
@ -331,6 +331,16 @@ BlockLayoutAlgorithm::BlockLayoutAlgorithm(const LayoutAlgorithmParams& params)
|
||||
}
|
||||
}
|
||||
|
||||
// Disable text box trimming if there's intervening border / padding.
|
||||
if (should_text_box_trim_node_start_ &&
|
||||
BorderPadding().block_start != LayoutUnit()) {
|
||||
should_text_box_trim_node_start_ = false;
|
||||
}
|
||||
if (should_text_box_trim_node_end_ &&
|
||||
BorderPadding().block_end != LayoutUnit()) {
|
||||
should_text_box_trim_node_end_ = false;
|
||||
}
|
||||
|
||||
// Initialize `text-box-trim` flags from the `ComputedStyle`.
|
||||
const ComputedStyle& style = Node().Style();
|
||||
if (style.TextBoxTrim() != ETextBoxTrim::kNone) [[unlikely]] {
|
||||
|
@ -33,9 +33,6 @@ class CORE_EXPORT InlineChildLayoutContext {
|
||||
~InlineChildLayoutContext();
|
||||
|
||||
FragmentItemsBuilder* ItemsBuilder() { return &items_builder_; }
|
||||
const BoxFragmentBuilder* ContainerBuilder() const {
|
||||
return container_builder_;
|
||||
}
|
||||
|
||||
ScoreLineBreakContext* GetScoreLineBreakContext() const {
|
||||
return score_line_break_context_;
|
||||
|
@ -264,16 +264,6 @@ InlineLayoutAlgorithm::InlineLayoutAlgorithm(
|
||||
// header.
|
||||
InlineLayoutAlgorithm::~InlineLayoutAlgorithm() = default;
|
||||
|
||||
bool InlineLayoutAlgorithm::HasContainerBorderPaddingAtBlockStart() const {
|
||||
return context_->ContainerBuilder()->BorderPadding().block_start !=
|
||||
LayoutUnit();
|
||||
}
|
||||
|
||||
bool InlineLayoutAlgorithm::HasContainerBorderPaddingAtBlockEnd() const {
|
||||
return context_->ContainerBuilder()->BorderPadding().block_end !=
|
||||
LayoutUnit();
|
||||
}
|
||||
|
||||
// Prepare InlineLayoutStateStack for a new line.
|
||||
void InlineLayoutAlgorithm::PrepareBoxStates(
|
||||
const LineInfo& line_info,
|
||||
@ -641,49 +631,41 @@ void InlineLayoutAlgorithm::ApplyTextBoxTrim(LineInfo& line_info,
|
||||
should_apply_over, should_apply_under, intrinsic_metrics);
|
||||
|
||||
if (should_apply_start) {
|
||||
// If there is intervening non-zero padding or borders, there is no effect.
|
||||
if (!HasContainerBorderPaddingAtBlockStart()) {
|
||||
// Apply `text-box-trim: start` if this is the first formatted line.
|
||||
LayoutUnit offset_for_trimming_box;
|
||||
if (is_flipped_line) [[unlikely]] {
|
||||
offset_for_trimming_box =
|
||||
intrinsic_metrics.descent - line_box_metrics.descent;
|
||||
} else {
|
||||
offset_for_trimming_box =
|
||||
intrinsic_metrics.ascent - line_box_metrics.ascent;
|
||||
}
|
||||
container_builder_.SetLineBoxBfcBlockOffset(
|
||||
container_builder_.LineBoxBfcBlockOffset()
|
||||
? offset_for_trimming_box +
|
||||
container_builder_.LineBoxBfcBlockOffset().value()
|
||||
: offset_for_trimming_box);
|
||||
|
||||
// Cancel adjusting the block start for the initial letters and Ruby
|
||||
// annotation. The use of the `text-box-trim` accepts the risk of
|
||||
// collisions for the finer control of the alignment of the body text in
|
||||
// the block direction.
|
||||
line_info.SetAnnotationBlockStartAdjustment(LayoutUnit());
|
||||
line_info.SetInitialLetterBlockStartAdjustment(LayoutUnit());
|
||||
// Apply `text-box-trim: start` if this is the first formatted line.
|
||||
LayoutUnit offset_for_trimming_box;
|
||||
if (is_flipped_line) [[unlikely]] {
|
||||
offset_for_trimming_box =
|
||||
intrinsic_metrics.descent - line_box_metrics.descent;
|
||||
} else {
|
||||
offset_for_trimming_box =
|
||||
intrinsic_metrics.ascent - line_box_metrics.ascent;
|
||||
}
|
||||
container_builder_.SetLineBoxBfcBlockOffset(
|
||||
container_builder_.LineBoxBfcBlockOffset()
|
||||
? offset_for_trimming_box +
|
||||
container_builder_.LineBoxBfcBlockOffset().value()
|
||||
: offset_for_trimming_box);
|
||||
|
||||
// Cancel adjusting the block start for the initial letters and Ruby
|
||||
// annotation. The use of the `text-box-trim` accepts the risk of collisions
|
||||
// for the finer control of the alignment of the body text in the block
|
||||
// direction.
|
||||
line_info.SetAnnotationBlockStartAdjustment(LayoutUnit());
|
||||
line_info.SetInitialLetterBlockStartAdjustment(LayoutUnit());
|
||||
}
|
||||
|
||||
if (should_apply_end) {
|
||||
container_builder_.SetIsBlockEndTrimmableLine();
|
||||
// If there is intervening non-zero padding or borders, there is no effect,
|
||||
// but this is where trimming should have been applied, so we need to report
|
||||
// it as trimmable nevertheless.
|
||||
if (!HasContainerBorderPaddingAtBlockEnd()) [[unlikely]] {
|
||||
// Ask the block layout algorithm to trim the end of the line box.
|
||||
LayoutUnit block_end_to_be_trimmed;
|
||||
if (is_flipped_line) [[unlikely]] {
|
||||
block_end_to_be_trimmed =
|
||||
line_box_metrics.ascent - intrinsic_metrics.ascent;
|
||||
} else {
|
||||
block_end_to_be_trimmed =
|
||||
line_box_metrics.descent - intrinsic_metrics.descent;
|
||||
}
|
||||
container_builder_.SetTrimBlockEndBy(block_end_to_be_trimmed);
|
||||
// Ask the block layout algorithm to trim the end of the line box.
|
||||
LayoutUnit block_end_to_be_trimmed;
|
||||
if (is_flipped_line) [[unlikely]] {
|
||||
block_end_to_be_trimmed =
|
||||
line_box_metrics.ascent - intrinsic_metrics.ascent;
|
||||
} else {
|
||||
block_end_to_be_trimmed =
|
||||
line_box_metrics.descent - intrinsic_metrics.descent;
|
||||
}
|
||||
container_builder_.SetTrimBlockEndBy(block_end_to_be_trimmed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,9 +72,6 @@ class CORE_EXPORT InlineLayoutAlgorithm final
|
||||
private:
|
||||
friend class LineWidthsTest;
|
||||
|
||||
bool HasContainerBorderPaddingAtBlockStart() const;
|
||||
bool HasContainerBorderPaddingAtBlockEnd() const;
|
||||
|
||||
void PositionLeadingFloats(ExclusionSpace&, LeadingFloats&);
|
||||
PositionedFloat PositionFloat(LayoutUnit origin_block_bfc_offset,
|
||||
LayoutObject* floating_object,
|
||||
|
12
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-001.html
vendored
Normal file
12
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-001.html
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<title>Border/padding on the trim-establishing container itself isn't considered to be "intervening"</title>
|
||||
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
|
||||
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#text-box-trim">
|
||||
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
|
||||
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css">
|
||||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
|
||||
<div style="position:absolute; margin-top:30px; width:100px; height:40px; background:green;"></div>
|
||||
<div style="text-box-trim:trim-both; border:10px solid green; width:80px; font:20px/60px Ahem; color:green; background:red;">
|
||||
xxxx<br>
|
||||
xxxx<br>
|
||||
</div>
|
14
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-002.html
vendored
Normal file
14
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-002.html
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<title>Border/padding on the trim-establishing container itself isn't considered to be "intervening"</title>
|
||||
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
|
||||
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#text-box-trim">
|
||||
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
|
||||
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css">
|
||||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
|
||||
<div style="position:absolute; margin-top:30px; width:100px; height:40px; background:green;"></div>
|
||||
<div style="text-box-trim:trim-both; width:100px; font:20px/60px Ahem; color:green; background:red;">
|
||||
<div style="text-box-trim:trim-both; border:10px solid green;">
|
||||
xxxx<br>
|
||||
xxxx<br>
|
||||
</div>
|
||||
</div>
|
15
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-003.html
vendored
Normal file
15
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-003.html
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<title>Border/padding on the trim-establishing container itself isn't considered to be "intervening"</title>
|
||||
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
|
||||
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#text-box-trim">
|
||||
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
|
||||
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css">
|
||||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
|
||||
<div style="position:absolute; margin-top:35px; width:100px; height:20px; background:green;"></div>
|
||||
<div style="position:absolute; margin-top:75px; width:100px; height:10px; background:green;"></div>
|
||||
<div style="text-box-trim:trim-both; width:100px; font:20px/40px Ahem; color:green; background:red;">
|
||||
<div style="text-box-trim:trim-start; border:10px solid green; border-block-width:15px;">
|
||||
xxxx<br>
|
||||
xxxx<br>
|
||||
</div>
|
||||
</div>
|
15
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-004.html
vendored
Normal file
15
third_party/blink/web_tests/external/wpt/css/css-inline/text-box-trim/border-padding-004.html
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<title>Border/padding on the trim-establishing container itself isn't considered to be "intervening"</title>
|
||||
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
|
||||
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#text-box-trim">
|
||||
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
|
||||
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css">
|
||||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
|
||||
<div style="position:absolute; margin-top:15px; width:100px; height:10px; background:green;"></div>
|
||||
<div style="position:absolute; margin-top:45px; width:100px; height:20px; background:green;"></div>
|
||||
<div style="text-box-trim:trim-both; width:100px; font:20px/40px Ahem; color:green; background:red;">
|
||||
<div style="text-box-trim:trim-end; border:10px solid green; border-block-width:15px;">
|
||||
xxxx<br>
|
||||
xxxx<br>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user