Title: [267863] trunk
Revision
267863
Author
[email protected]
Date
2020-10-01 18:10:08 -0700 (Thu, 01 Oct 2020)

Log Message

Repaint as needed when adding and removing highlights
https://bugs.webkit.org/show_bug.cgi?id=217116
Source/WebCore:

<rdar://problem/59076190>

Reviewed by Simon Fraser.

When adding and removing psudo highlights, make sure that the
right areas are repainted.

Test: http/wpt/css/css-highlight-api/highlight-text-repaint.html

* Modules/highlight/HighlightRangeGroup.cpp:
(WebCore::repaintRange):
(WebCore::HighlightRangeGroup::removeFromSetLike):
(WebCore::HighlightRangeGroup::clearFromSetLike):
(WebCore::HighlightRangeGroup::addToSetLike):

LayoutTests:

Reviewed by Simon Fraser.

* http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt: Added.
* http/wpt/css/css-highlight-api/highlight-text-repaint.html: Added.
* http/wpt/css/css-highlight-api/highlight-text-replace-expected.html: Removed.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (267862 => 267863)


--- trunk/LayoutTests/ChangeLog	2020-10-02 00:18:50 UTC (rev 267862)
+++ trunk/LayoutTests/ChangeLog	2020-10-02 01:10:08 UTC (rev 267863)
@@ -1,3 +1,14 @@
+2020-10-01  Megan Gardner  <[email protected]>
+
+        Repaint as needed when adding and removing highlights
+        https://bugs.webkit.org/show_bug.cgi?id=217116
+
+        Reviewed by Simon Fraser.
+
+        * http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt: Added.
+        * http/wpt/css/css-highlight-api/highlight-text-repaint.html: Added.
+        * http/wpt/css/css-highlight-api/highlight-text-replace-expected.html: Removed.
+
 2020-10-01  Karl Rackler  <[email protected]>
 
         REGRESSION (r267814): [ Mojave+ release wk2 ] inspector/console/queryHolders.html is a flaky failure

Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt (0 => 267863)


--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt	2020-10-02 01:10:08 UTC (rev 267863)
@@ -0,0 +1,8 @@
+One two three
+(repaint rects
+  (rect 8 8 784 20)
+  (rect 8 8 784 20)
+  (rect 8 8 784 20)
+  (rect 8 8 784 20)
+)
+

Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-repaint.html (0 => 267863)


--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-repaint.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-repaint.html	2020-10-02 01:10:08 UTC (rev 267863)
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Multiple custom highlight pseudo elements.</title>
+    <link rel="help" href=""
+    <link rel="match" href=""
+    <meta name="assert" content="Highlight Ranges should be able to be added and removed from the HighlightRangeGroup.">
+    <style>
+        ::highlight(example-highlight) {
+            background-color: blue;
+            color:red;
+        }
+        #text1
+        {
+            font: 20px Ahem;
+        }
+    </style>
+</head>
+<body>
+    <span id="text1">One two three</span>
+    <pre id="repaintRects"></pre>
+
+    <script>
+        function repaintTest()
+        {
+            if (!window.testRunner) {
+                alert('This test requires testRunner to run!');
+                return;
+            }
+
+            if (!window.internals) {
+                 alert('This test requires window.interals to run!');
+                 return;
+            }
+            window.internals.startTrackingRepaints();
+            window.testRunner.dumpAsText(false);
+
+            let textElement = document.getElementById('text1');
+
+            let range1 = new StaticRange({startContainer: textElement.childNodes[0], startOffset: 1, endContainer: textElement.childNodes[0], endOffset: 2})
+            let range2 = new StaticRange({startContainer: textElement.childNodes[0], startOffset: 3, endContainer: textElement.childNodes[0], endOffset: 4});
+            let range3 = new StaticRange({startContainer: textElement.childNodes[0], startOffset: 8, endContainer: textElement.childNodes[0], endOffset: 12});
+
+            let highlightRangeGroup1 = new HighlightRangeGroup(range1);
+            CSS.highlights.set("example-highlight", highlightRangeGroup1);
+
+            highlightRangeGroup1.add(range2);
+            highlightRangeGroup1.delete(range1);
+            highlightRangeGroup1.add(range3);
+
+            var repaintRects = window.internals.repaintRectsAsText();
+            window.internals.stopTrackingRepaints();
+
+            var pre = document.getElementById('repaintRects');
+            pre.innerHTML = repaintRects;
+        }
+        window.addEventListener('load', repaintTest, false);
+    </script>
+</body>
+</html>

Added: trunk/LayoutTests/platform/ios/http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt (0 => 267863)


--- trunk/LayoutTests/platform/ios/http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios/http/wpt/css/css-highlight-api/highlight-text-repaint-expected.txt	2020-10-02 01:10:08 UTC (rev 267863)
@@ -0,0 +1,8 @@
+One two three
+(repaint rects
+  (rect 8 8 784 21)
+  (rect 8 8 784 21)
+  (rect 8 8 784 21)
+  (rect 8 8 784 21)
+)
+

Modified: trunk/Source/WebCore/ChangeLog (267862 => 267863)


--- trunk/Source/WebCore/ChangeLog	2020-10-02 00:18:50 UTC (rev 267862)
+++ trunk/Source/WebCore/ChangeLog	2020-10-02 01:10:08 UTC (rev 267863)
@@ -1,3 +1,22 @@
+2020-10-01  Megan Gardner  <[email protected]>
+
+        Repaint as needed when adding and removing highlights
+        https://bugs.webkit.org/show_bug.cgi?id=217116
+        <rdar://problem/59076190>
+
+        Reviewed by Simon Fraser.
+
+        When adding and removing psudo highlights, make sure that the
+        right areas are repainted.
+
+        Test: http/wpt/css/css-highlight-api/highlight-text-repaint.html
+
+        * Modules/highlight/HighlightRangeGroup.cpp:
+        (WebCore::repaintRange):
+        (WebCore::HighlightRangeGroup::removeFromSetLike):
+        (WebCore::HighlightRangeGroup::clearFromSetLike):
+        (WebCore::HighlightRangeGroup::addToSetLike):
+
 2020-10-01  Chris Dumez  <[email protected]>
 
         Add basic infrastructure for AudioWorklet

Modified: trunk/Source/WebCore/Modules/highlight/HighlightRangeGroup.cpp (267862 => 267863)


--- trunk/Source/WebCore/Modules/highlight/HighlightRangeGroup.cpp	2020-10-02 00:18:50 UTC (rev 267862)
+++ trunk/Source/WebCore/Modules/highlight/HighlightRangeGroup.cpp	2020-10-02 01:10:08 UTC (rev 267863)
@@ -29,7 +29,9 @@
 #include "IDLTypes.h"
 #include "JSDOMSetLike.h"
 #include "JSStaticRange.h"
+#include "NodeTraversal.h"
 #include "PropertySetCSSStyleDeclaration.h"
+#include "RenderObject.h"
 #include "StaticRange.h"
 #include "StyleProperties.h"
 #include <wtf/Ref.h>
@@ -53,9 +55,33 @@
         set.add<IDLInterface<StaticRange>>(rangeData->range);
 }
 
+static void repaintRange(const StaticRange& range)
+{
+    auto* startNode = &range.startContainer();
+    auto* endNode = &range.endContainer();
+    auto ordering = documentOrder(*startNode, *endNode);
+    if (is_eq(ordering)) {
+        if (auto renderer = startNode->renderer())
+            renderer->repaint();
+        return;
+    }
+    if (is_gt(ordering)) {
+        startNode = &range.endContainer();
+        endNode = &range.startContainer();
+    }
+
+    auto node = startNode;
+    while (node != endNode) {
+        if (auto renderer = node->renderer())
+            renderer->repaint();
+        node = NodeTraversal::next(*node);
+    }
+}
+
 bool HighlightRangeGroup::removeFromSetLike(const StaticRange& range)
 {
     return m_rangesData.removeFirstMatching([&range](const Ref<HighlightRangeData>& current) {
+        repaintRange(range);
         return current.get().range.get() == range;
     });
 }
@@ -62,6 +88,9 @@
 
 void HighlightRangeGroup::clearFromSetLike()
 {
+    for (auto& data : m_rangesData)
+        repaintRange(data->range);
+
     m_rangesData.clear();
 }
 
@@ -69,6 +98,7 @@
 {
     if (notFound != m_rangesData.findMatching([&range](const Ref<HighlightRangeData>& current) { return current.get().range.get() == range; }))
         return false;
+    repaintRange(range);
     m_rangesData.append(HighlightRangeData::create(range));
     
     return true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to