Skip to content

Commit 5217f39

Browse files
dandclarkChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Highlight API: Ignore CSS contain when painting
Per the CSSWG resolution [1], ignore CSS contain boundaries when painting. Update tests, and remove some tests that are no longer interesting now that StaticRange painting no longer needs to take contain boundaries into account. [1] w3c/csswg-drafts#4598 Bug: 1164461 Change-Id: Iad9249867ea704f924827db810816935069363c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3437210 Reviewed-by: Rune Lillesveen Reviewed-by: Fernando Fiori Commit-Queue: Dan Clark Cr-Commit-Position: refs/heads/main@{#967368}
1 parent 47e7633 commit 5217f39

10 files changed

+29
-163
lines changed

third_party/blink/renderer/core/dom/static_range.cc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,6 @@ StaticRange* StaticRange::Create(Document& document,
5757
static_range_init->endOffset());
5858
}
5959

60-
namespace {
61-
62-
// Returns the lowest ancestor of |node| in the tree that has a containment set.
63-
Node* GetLowestContainAncestor(const Node* node) {
64-
for (Node& ancestor : NodeTraversal::InclusiveAncestorsOf(*node)) {
65-
if (LayoutObject* node_layout_object = ancestor.GetLayoutObject()) {
66-
if (node_layout_object->ShouldApplyAnyContainment()) {
67-
return &ancestor;
68-
}
69-
}
70-
}
71-
return nullptr;
72-
}
73-
74-
} // namespace
75-
76-
// Returns true if the range crosses any css-contain subtree boundary.
77-
bool StaticRange::CrossesContainBoundary() const {
78-
if (style_version_for_crosses_contain_boundary_ ==
79-
owner_document_->StyleVersion())
80-
return crosses_contain_boundary_;
81-
style_version_for_crosses_contain_boundary_ = owner_document_->StyleVersion();
82-
83-
crosses_contain_boundary_ = GetLowestContainAncestor(start_container_) !=
84-
GetLowestContainAncestor(end_container_);
85-
return crosses_contain_boundary_;
86-
}
87-
8860
bool StaticRange::IsValid() const {
8961
if (dom_tree_version_for_is_valid_ == owner_document_->DomTreeVersion())
9062
return is_valid_;

third_party/blink/renderer/core/dom/static_range.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class CORE_EXPORT StaticRange final : public AbstractRange {
5151
Range* toRange(ExceptionState& = ASSERT_NO_EXCEPTION) const;
5252

5353
bool IsValid() const;
54-
bool CrossesContainBoundary() const;
5554
bool IsStaticRange() const override { return true; }
5655
Document& OwnerDocument() const override { return *owner_document_.Get(); }
5756

@@ -64,10 +63,7 @@ class CORE_EXPORT StaticRange final : public AbstractRange {
6463
Member end_container_;
6564
unsigned end_offset_ = 0;
6665
mutable bool is_valid_ = false;
67-
mutable bool crosses_contain_boundary_ = false;
6866
mutable uint64_t dom_tree_version_for_is_valid_ = 0;
69-
mutable uint64_t style_version_for_crosses_contain_boundary_ =
70-
static_cast<uint64_t>(-1);
7167
};
7268

7369
using StaticRangeVector = HeapVector>;

third_party/blink/renderer/core/highlight/highlight_registry.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ void HighlightRegistry::ValidateHighlightMarkers() {
6969
if (abstract_range->OwnerDocument() == document &&
7070
!abstract_range->collapsed()) {
7171
auto* static_range = DynamicTo(*abstract_range);
72-
if (static_range && (!static_range->IsValid() ||
73-
static_range->CrossesContainBoundary()))
72+
if (static_range && !static_range->IsValid())
7473
continue;
7574

7675
EphemeralRange eph_range(abstract_range);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
>
2+
<meta charset="UTF-8">
3+
<title>CSS Highlight API Test: Range across contain boundary is paintedtitle>
4+
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
5+
<link rel="match" href="custom-highlight-painting-001-ref.html">
6+
<meta name="assert" value="Highlight should be painted even though a Range that crosses a css-contain boundary is a part of it">
7+
<style>
8+
::highlight(example-highlight) {
9+
background-color: yellow;
10+
color: blue;
11+
}
12+
#target {
13+
contain: paint;
14+
}
15+
style>
16+
<body><span>One span><span id="target"><span>two span><span>three…span>span>
17+
<script>
18+
let r = new Range();
19+
r.setStart(document.body, 0);
20+
r.setEnd(document.querySelector("#target"), 1);
21+
CSS.highlights.set("example-highlight", new Highlight(r));
22+
script>
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
>
22
<meta charset="UTF-8">
3-
<title>CSS Highlight API Test: title>
3+
<title>CSS Highlight API Test: Invalid StaticRanges are not paintedtitle>
44
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
55
<link rel="match" href="custom-highlight-painting-staticrange-001-ref.html">
6-
<meta name="assert" value="StaticRanges that are invalid, collapsed or that cross only one boundary of a css-contain node should not be painted when they're in a Highlight">
6+
<meta name="assert" value="StaticRanges that are invalid or collapsed should not be painted when they're in a Highlight">
77
<style>
88
::highlight(example-highlight) {
99
background-color: yellow;
1010
color: blue;
1111
}
12-
#second {
13-
contain: style;
14-
}
1512
style>
1613
<body><span id="first">One span><span id="second">two span><span id="third">three…span>
1714
<script>
@@ -21,7 +18,5 @@
2118
h.add(new StaticRange({startContainer: document.body, startOffset: 1, endContainer: document.body, endOffset: 100}));
2219
h.add(new StaticRange({startContainer: document, startOffset: 0, endContainer: document, endOffset: 1}));
2320
h.add(new StaticRange({startContainer: document.querySelector("#third").firstChild, startOffset: 1, endContainer: document.querySelector("#first").firstChild, endOffset: 2}));
24-
h.add(new StaticRange({startContainer: document.querySelector("#first").firstChild, startOffset: 1, endContainer: document.querySelector("#second").firstChild, endOffset: 2}));
25-
h.add(new StaticRange({startContainer: document.querySelector("#second").firstChild, startOffset: 1, endContainer: document.querySelector("#third").firstChild, endOffset: 2}));
2621
CSS.highlights.set("example-highlight", h);
2722
script>
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
>
22
<meta charset="UTF-8">
3-
<title>CSS Highlight API Test: title>
3+
<title>CSS Highlight API Test: StaticRange across contain boundary is paintedtitle>
44
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
55
<link rel="match" href="custom-highlight-painting-001-ref.html">
6-
<meta name="assert" value="StaticRanges crossing both boundaries of a css-contain (i.e. containing it entirely) should be painted">
6+
<meta name="assert" value="A StaticRange crossing a contain boundary should be painted">
77
<style>
88
::highlight(example-highlight) {
99
background-color: yellow;
1010
color: blue;
1111
}
1212
#contained {
13-
contain: style;
13+
contain: paint;
1414
}
1515
style>
1616
<body><span>One <span id="contained">two span>three…span>
1717
<script>
1818
let h = new Highlight();
19-
h.add(new StaticRange({startContainer: document.body.firstChild.childNodes[0], startOffset: 0, endContainer: document.body.firstChild.childNodes[2], endOffset: 0}));
19+
h.add(new StaticRange({startContainer: document.body.firstChild.childNodes[0], startOffset: 0, endContainer: document.body.firstChild.childNodes[1], endOffset: 1}));
2020
CSS.highlights.set("example-highlight", h);
2121
script>

third_party/blink/web_tests/external/wpt/css/css-highlight-api/painting/custom-highlight-painting-staticrange-004.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

third_party/blink/web_tests/external/wpt/css/css-highlight-api/painting/custom-highlight-painting-staticrange-005.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

third_party/blink/web_tests/external/wpt/css/css-highlight-api/painting/custom-highlight-painting-staticrange-006.html

Lines changed: 0 additions & 29 deletions
This file was deleted.

third_party/blink/web_tests/external/wpt/css/css-highlight-api/painting/custom-highlight-painting-staticrange-007.html

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)