Title: [256451] trunk
Revision
256451
Author
[email protected]
Date
2020-02-12 10:40:24 -0800 (Wed, 12 Feb 2020)

Log Message

Fix highlight text decorations to work with all decoration types and colors
https://bugs.webkit.org/show_bug.cgi?id=207601

Reviewed by Dean Jackson.

Source/WebCore:

MarkedText styles were incorrectly setting styles, and colors were being
calculated incorrectly.

Extended http/wpt/css/css-highlight-api/highlight-text-decorations.html.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::resolveStyleForMarkedText):
Correctly pass information about text decorations to MarkedTexts styles.

* rendering/TextDecorationPainter.cpp:
(WebCore::collectStylesForRenderer):
(WebCore::TextDecorationPainter::decorationColor):
(WebCore::decorationColor): Deleted.
Expose decorationColor calculator for use in InlineTextBox.
* rendering/TextDecorationPainter.h:

LayoutTests:

* http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html:
* http/wpt/css/css-highlight-api/highlight-text-decorations.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (256450 => 256451)


--- trunk/LayoutTests/ChangeLog	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/LayoutTests/ChangeLog	2020-02-12 18:40:24 UTC (rev 256451)
@@ -1,3 +1,13 @@
+2020-02-12  Megan Gardner  <[email protected]>
+
+        Fix highlight text decorations to work with all decoration types and colors
+        https://bugs.webkit.org/show_bug.cgi?id=207601
+
+        Reviewed by Dean Jackson.
+
+        * http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html:
+        * http/wpt/css/css-highlight-api/highlight-text-decorations.html:
+
 2020-02-12  Per Arne Vollan  <[email protected]>
 
         [iOS] Deny mach lookup access to view service in the WebContent process

Modified: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html (256450 => 256451)


--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html	2020-02-12 18:40:24 UTC (rev 256451)
@@ -7,12 +7,24 @@
         }
         .style1 {
             text-decoration: underline;
+            text-decoration-color: red;
+            color: blue;
         }
+        .style2 {
+            text-decoration: line-through;
+            text-decoration-color: violet;
+            text-decoration-style: double;
+        }
+        .style3 {
+            text-decoration: overline;
+            text-decoration-color: orange;
+            text-decoration-style: dotted;
+        }
         /* FIXME: There is a discrepency for how the underlines are displayed at the end of the line, leading to a pixel different in this text. Find a real fix, but in the meantime, obscure the offending pixel <rdar://problem/59327965> https://bugs.webkit.org/show_bug.cgi?id=207512*/
         .obscurer1 {
           position: absolute;
-          top: 35px;
-          left: 100px;
+          top: 25px;
+          left: 95px;
           width: 10px;
           height: 10px;
           background: grey;
@@ -28,7 +40,7 @@
     </style>
 </head>
 <body>
-    O<span class="style1">n</span>e t<span class="style1">w</span>o th<span class="style1">ree</span>
+    O<span class="style1">n</span>e t<span class="style2">w</span>o th<span class="style3">ree</span>
     <div class='obscurer1'></div>
     <div class='obscurer2'></div>
 </body>

Modified: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations.html (256450 => 256451)


--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations.html	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations.html	2020-02-12 18:40:24 UTC (rev 256451)
@@ -12,12 +12,24 @@
         }
         ::highlight(example-highlight1) {
             text-decoration: underline;
+            text-decoration-color: red;
+            color: blue;
         }
+        ::highlight(example-highlight2) {
+            text-decoration: line-through;
+            text-decoration-color: violet;
+            text-decoration-style: double;
+        }
+        ::highlight(example-highlight3) {
+            text-decoration: overline;
+            text-decoration-color: orange;
+            text-decoration-style: dotted;
+        }
         /* FIXME: There is a discrepency for how the underlines are displayed at the end of the line, leading to a pixel different in this text. Find a real fix, but in the meantime, obscure the offending pixel https://bugs.webkit.org/show_bug.cgi?id=207512 <rdar://problem/59327965> */
         .obscurer1 {
           position: absolute;
-          top: 35px;
-          left: 100px;
+          top: 25px;
+          left: 95px;
           width: 10px;
           height: 10px;
           background: grey;
@@ -36,13 +48,16 @@
     <span id="text1">One two three</span>
     <div class='obscurer1'></div>
     <div class='obscurer2'></div>
+
     <script>
         let textElement = document.getElementById('text1');
         let highlightRangeGroup1 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 1, endContainer: textElement.childNodes[0], endOffset: 2}));
-        highlightRangeGroup1.add(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 5, endContainer: textElement.childNodes[0], endOffset: 6}));
-        highlightRangeGroup1.add(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 10, endContainer: textElement.childNodes[0], endOffset: 13}));
+        let highlightRangeGroup2 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 5, endContainer: textElement.childNodes[0], endOffset: 6}));
+        let highlightRangeGroup3 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 10, endContainer: textElement.childNodes[0], endOffset: 13}));
 
         CSS.highlights.set("example-highlight1", highlightRangeGroup1);
+        CSS.highlights.set("example-highlight2", highlightRangeGroup2);
+        CSS.highlights.set("example-highlight3", highlightRangeGroup3);
     </script>
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (256450 => 256451)


--- trunk/Source/WebCore/ChangeLog	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/Source/WebCore/ChangeLog	2020-02-12 18:40:24 UTC (rev 256451)
@@ -1,3 +1,26 @@
+2020-02-12  Megan Gardner  <[email protected]>
+
+        Fix highlight text decorations to work with all decoration types and colors
+        https://bugs.webkit.org/show_bug.cgi?id=207601
+
+        Reviewed by Dean Jackson.
+
+        MarkedText styles were incorrectly setting styles, and colors were being 
+        calculated incorrectly.
+
+        Extended http/wpt/css/css-highlight-api/highlight-text-decorations.html.
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::resolveStyleForMarkedText):
+        Correctly pass information about text decorations to MarkedTexts styles.
+        
+        * rendering/TextDecorationPainter.cpp:
+        (WebCore::collectStylesForRenderer):
+        (WebCore::TextDecorationPainter::decorationColor):
+        (WebCore::decorationColor): Deleted.
+        Expose decorationColor calculator for use in InlineTextBox. 
+        * rendering/TextDecorationPainter.h:
+
 2020-02-12  Chris Dumez  <[email protected]>
 
         RELEASE_ASSERT() under WebSWClientConnection::didResolveRegistrationPromise()

Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (256450 => 256451)


--- trunk/Source/WebCore/rendering/InlineTextBox.cpp	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp	2020-02-12 18:40:24 UTC (rev 256451)
@@ -826,14 +826,22 @@
             style.textStyles.fillColor = renderStyle->computedStrokeColor();
             style.textStyles.strokeColor = renderStyle->computedStrokeColor();
             
-            auto color = renderStyle->visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);
+            auto color = TextDecorationPainter::decorationColor(*renderStyle.get());
             auto decorationStyle = renderStyle->textDecorationStyle();
             auto decorations = renderStyle->textDecorationsInEffect();
 
-            if (decorations.containsAny({ TextDecoration::Underline, TextDecoration::Overline, TextDecoration::LineThrough })) {
+            if (decorations.contains(TextDecoration::Underline)) {
                 style.textDecorationStyles.underlineColor = color;
                 style.textDecorationStyles.underlineStyle = decorationStyle;
             }
+            if (decorations.contains(TextDecoration::Overline)) {
+                style.textDecorationStyles.overlineColor = color;
+                style.textDecorationStyles.overlineStyle = decorationStyle;
+            }
+            if (decorations.contains(TextDecoration::LineThrough)) {
+                style.textDecorationStyles.linethroughColor = color;
+                style.textDecorationStyles.linethroughStyle = decorationStyle;
+            }
         }
         break;
     case MarkedText::DraggedContent:

Modified: trunk/Source/WebCore/rendering/TextDecorationPainter.cpp (256450 => 256451)


--- trunk/Source/WebCore/rendering/TextDecorationPainter.cpp	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/Source/WebCore/rendering/TextDecorationPainter.cpp	2020-02-12 18:40:24 UTC (rev 256451)
@@ -316,26 +316,10 @@
         m_context.clearShadow();
 }
 
-static Color decorationColor(const RenderStyle& style)
-{
-    // Check for text decoration color first.
-    Color result = style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor);
-    if (result.isValid())
-        return result;
-    if (style.hasPositiveStrokeWidth()) {
-        // Prefer stroke color if possible but not if it's fully transparent.
-        result = style.computedStrokeColor();
-        if (result.isVisible())
-            return result;
-    }
-    
-    return style.visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);
-}
-
 static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, OptionSet<TextDecoration> remainingDecorations, bool firstLineStyle, PseudoId pseudoId)
 {
     auto extractDecorations = [&] (const RenderStyle& style, OptionSet<TextDecoration> decorations) {
-        auto color = decorationColor(style);
+        auto color = TextDecorationPainter::decorationColor(style);
         auto decorationStyle = style.textDecorationStyle();
 
         if (decorations.contains(TextDecoration::Underline)) {
@@ -387,6 +371,22 @@
         extractDecorations(styleForRenderer(*current), remainingDecorations);
 }
 
+Color TextDecorationPainter::decorationColor(const RenderStyle& style)
+{
+    // Check for text decoration color first.
+    auto result = style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor);
+    if (result.isValid())
+        return result;
+    if (style.hasPositiveStrokeWidth()) {
+        // Prefer stroke color if possible but not if it's fully transparent.
+        result = style.computedStrokeColor();
+        if (result.isVisible())
+            return result;
+    }
+    
+    return style.visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);
+}
+
 OptionSet<TextDecoration> TextDecorationPainter::textDecorationsInEffectForStyle(const TextDecorationPainter::Styles& style)
 {
     OptionSet<TextDecoration> decorations;

Modified: trunk/Source/WebCore/rendering/TextDecorationPainter.h (256450 => 256451)


--- trunk/Source/WebCore/rendering/TextDecorationPainter.h	2020-02-12 18:40:04 UTC (rev 256450)
+++ trunk/Source/WebCore/rendering/TextDecorationPainter.h	2020-02-12 18:40:24 UTC (rev 256451)
@@ -64,6 +64,7 @@
         TextDecorationStyle overlineStyle;
         TextDecorationStyle linethroughStyle;
     };
+    static Color decorationColor(const RenderStyle&);
     static OptionSet<TextDecoration> textDecorationsInEffectForStyle(const Styles&);
     static Styles stylesForRenderer(const RenderObject&, OptionSet<TextDecoration> requestedDecorations, bool firstLineStyle = false, PseudoId = PseudoId::None);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to