Changeset 256451 in webkit


Ignore:
Timestamp:
Feb 12, 2020 10:40:24 AM (4 years ago)
Author:
Megan Gardner
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:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r256450 r256451  
     12020-02-12  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Fix highlight text decorations to work with all decoration types and colors
     4        https://bugs.webkit.org/show_bug.cgi?id=207601
     5
     6        Reviewed by Dean Jackson.
     7
     8        * http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html:
     9        * http/wpt/css/css-highlight-api/highlight-text-decorations.html:
     10
    1112020-02-12  Per Arne Vollan  <pvollan@apple.com>
    212
  • trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html

    r256360 r256451  
    88        .style1 {
    99            text-decoration: underline;
     10            text-decoration-color: red;
     11            color: blue;
     12        }
     13        .style2 {
     14            text-decoration: line-through;
     15            text-decoration-color: violet;
     16            text-decoration-style: double;
     17        }
     18        .style3 {
     19            text-decoration: overline;
     20            text-decoration-color: orange;
     21            text-decoration-style: dotted;
    1022        }
    1123        /* 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*/
    1224        .obscurer1 {
    1325          position: absolute;
    14           top: 35px;
    15           left: 100px;
     26          top: 25px;
     27          left: 95px;
    1628          width: 10px;
    1729          height: 10px;
     
    2941</head>
    3042<body>
    31     O<span class="style1">n</span>e t<span class="style1">w</span>o th<span class="style1">ree</span>
     43    O<span class="style1">n</span>e t<span class="style2">w</span>o th<span class="style3">ree</span>
    3244    <div class='obscurer1'></div>
    3345    <div class='obscurer2'></div>
  • trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations.html

    r256360 r256451  
    1313        ::highlight(example-highlight1) {
    1414            text-decoration: underline;
     15            text-decoration-color: red;
     16            color: blue;
     17        }
     18        ::highlight(example-highlight2) {
     19            text-decoration: line-through;
     20            text-decoration-color: violet;
     21            text-decoration-style: double;
     22        }
     23        ::highlight(example-highlight3) {
     24            text-decoration: overline;
     25            text-decoration-color: orange;
     26            text-decoration-style: dotted;
    1527        }
    1628        /* 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> */
    1729        .obscurer1 {
    1830          position: absolute;
    19           top: 35px;
    20           left: 100px;
     31          top: 25px;
     32          left: 95px;
    2133          width: 10px;
    2234          height: 10px;
     
    3749    <div class='obscurer1'></div>
    3850    <div class='obscurer2'></div>
     51
    3952    <script>
    4053        let textElement = document.getElementById('text1');
    4154        let highlightRangeGroup1 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 1, endContainer: textElement.childNodes[0], endOffset: 2}));
    42         highlightRangeGroup1.add(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 5, endContainer: textElement.childNodes[0], endOffset: 6}));
    43         highlightRangeGroup1.add(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 10, endContainer: textElement.childNodes[0], endOffset: 13}));
     55        let highlightRangeGroup2 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 5, endContainer: textElement.childNodes[0], endOffset: 6}));
     56        let highlightRangeGroup3 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 10, endContainer: textElement.childNodes[0], endOffset: 13}));
    4457
    4558        CSS.highlights.set("example-highlight1", highlightRangeGroup1);
     59        CSS.highlights.set("example-highlight2", highlightRangeGroup2);
     60        CSS.highlights.set("example-highlight3", highlightRangeGroup3);
    4661    </script>
    4762</body>
  • trunk/Source/WebCore/ChangeLog

    r256447 r256451  
     12020-02-12  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Fix highlight text decorations to work with all decoration types and colors
     4        https://bugs.webkit.org/show_bug.cgi?id=207601
     5
     6        Reviewed by Dean Jackson.
     7
     8        MarkedText styles were incorrectly setting styles, and colors were being
     9        calculated incorrectly.
     10
     11        Extended http/wpt/css/css-highlight-api/highlight-text-decorations.html.
     12
     13        * rendering/InlineTextBox.cpp:
     14        (WebCore::InlineTextBox::resolveStyleForMarkedText):
     15        Correctly pass information about text decorations to MarkedTexts styles.
     16       
     17        * rendering/TextDecorationPainter.cpp:
     18        (WebCore::collectStylesForRenderer):
     19        (WebCore::TextDecorationPainter::decorationColor):
     20        (WebCore::decorationColor): Deleted.
     21        Expose decorationColor calculator for use in InlineTextBox.
     22        * rendering/TextDecorationPainter.h:
     23
    1242020-02-12  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r256360 r256451  
    827827            style.textStyles.strokeColor = renderStyle->computedStrokeColor();
    828828           
    829             auto color = renderStyle->visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);
     829            auto color = TextDecorationPainter::decorationColor(*renderStyle.get());
    830830            auto decorationStyle = renderStyle->textDecorationStyle();
    831831            auto decorations = renderStyle->textDecorationsInEffect();
    832832
    833             if (decorations.containsAny({ TextDecoration::Underline, TextDecoration::Overline, TextDecoration::LineThrough })) {
     833            if (decorations.contains(TextDecoration::Underline)) {
    834834                style.textDecorationStyles.underlineColor = color;
    835835                style.textDecorationStyles.underlineStyle = decorationStyle;
     836            }
     837            if (decorations.contains(TextDecoration::Overline)) {
     838                style.textDecorationStyles.overlineColor = color;
     839                style.textDecorationStyles.overlineStyle = decorationStyle;
     840            }
     841            if (decorations.contains(TextDecoration::LineThrough)) {
     842                style.textDecorationStyles.linethroughColor = color;
     843                style.textDecorationStyles.linethroughStyle = decorationStyle;
    836844            }
    837845        }
  • trunk/Source/WebCore/rendering/TextDecorationPainter.cpp

    r256360 r256451  
    317317}
    318318
    319 static Color decorationColor(const RenderStyle& style)
     319static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, OptionSet<TextDecoration> remainingDecorations, bool firstLineStyle, PseudoId pseudoId)
     320{
     321    auto extractDecorations = [&] (const RenderStyle& style, OptionSet<TextDecoration> decorations) {
     322        auto color = TextDecorationPainter::decorationColor(style);
     323        auto decorationStyle = style.textDecorationStyle();
     324
     325        if (decorations.contains(TextDecoration::Underline)) {
     326            remainingDecorations.remove(TextDecoration::Underline);
     327            result.underlineColor = color;
     328            result.underlineStyle = decorationStyle;
     329        }
     330        if (decorations.contains(TextDecoration::Overline)) {
     331            remainingDecorations.remove(TextDecoration::Overline);
     332            result.overlineColor = color;
     333            result.overlineStyle = decorationStyle;
     334        }
     335        if (decorations.contains(TextDecoration::LineThrough)) {
     336            remainingDecorations.remove(TextDecoration::LineThrough);
     337            result.linethroughColor = color;
     338            result.linethroughStyle = decorationStyle;
     339        }
     340
     341    };
     342
     343    auto styleForRenderer = [&] (const RenderObject& renderer) -> const RenderStyle& {
     344        if (pseudoId != PseudoId::None && renderer.style().hasPseudoStyle(pseudoId)) {
     345            if (is<RenderText>(renderer))
     346                return *downcast<RenderText>(renderer).getCachedPseudoStyle(pseudoId);
     347            return *downcast<RenderElement>(renderer).getCachedPseudoStyle(pseudoId);
     348        }
     349        return firstLineStyle ? renderer.firstLineStyle() : renderer.style();
     350    };
     351
     352    auto* current = &renderer;
     353    do {
     354        const auto& style = styleForRenderer(*current);
     355        extractDecorations(style, style.textDecoration());
     356
     357        if (current->isRubyText())
     358            return;
     359
     360        current = current->parent();
     361        if (current && current->isAnonymousBlock() && downcast<RenderBlock>(*current).continuation())
     362            current = downcast<RenderBlock>(*current).continuation();
     363
     364        if (remainingDecorations.isEmpty())
     365            break;
     366
     367    } while (current && !is<HTMLAnchorElement>(current->node()) && !is<HTMLFontElement>(current->node()));
     368
     369    // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
     370    if (!remainingDecorations.isEmpty() && current)
     371        extractDecorations(styleForRenderer(*current), remainingDecorations);
     372}
     373
     374Color TextDecorationPainter::decorationColor(const RenderStyle& style)
    320375{
    321376    // Check for text decoration color first.
    322     Color result = style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor);
     377    auto result = style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor);
    323378    if (result.isValid())
    324379        return result;
     
    331386   
    332387    return style.visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);
    333 }
    334 
    335 static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, OptionSet<TextDecoration> remainingDecorations, bool firstLineStyle, PseudoId pseudoId)
    336 {
    337     auto extractDecorations = [&] (const RenderStyle& style, OptionSet<TextDecoration> decorations) {
    338         auto color = decorationColor(style);
    339         auto decorationStyle = style.textDecorationStyle();
    340 
    341         if (decorations.contains(TextDecoration::Underline)) {
    342             remainingDecorations.remove(TextDecoration::Underline);
    343             result.underlineColor = color;
    344             result.underlineStyle = decorationStyle;
    345         }
    346         if (decorations.contains(TextDecoration::Overline)) {
    347             remainingDecorations.remove(TextDecoration::Overline);
    348             result.overlineColor = color;
    349             result.overlineStyle = decorationStyle;
    350         }
    351         if (decorations.contains(TextDecoration::LineThrough)) {
    352             remainingDecorations.remove(TextDecoration::LineThrough);
    353             result.linethroughColor = color;
    354             result.linethroughStyle = decorationStyle;
    355         }
    356 
    357     };
    358 
    359     auto styleForRenderer = [&] (const RenderObject& renderer) -> const RenderStyle& {
    360         if (pseudoId != PseudoId::None && renderer.style().hasPseudoStyle(pseudoId)) {
    361             if (is<RenderText>(renderer))
    362                 return *downcast<RenderText>(renderer).getCachedPseudoStyle(pseudoId);
    363             return *downcast<RenderElement>(renderer).getCachedPseudoStyle(pseudoId);
    364         }
    365         return firstLineStyle ? renderer.firstLineStyle() : renderer.style();
    366     };
    367 
    368     auto* current = &renderer;
    369     do {
    370         const auto& style = styleForRenderer(*current);
    371         extractDecorations(style, style.textDecoration());
    372 
    373         if (current->isRubyText())
    374             return;
    375 
    376         current = current->parent();
    377         if (current && current->isAnonymousBlock() && downcast<RenderBlock>(*current).continuation())
    378             current = downcast<RenderBlock>(*current).continuation();
    379 
    380         if (remainingDecorations.isEmpty())
    381             break;
    382 
    383     } while (current && !is<HTMLAnchorElement>(current->node()) && !is<HTMLFontElement>(current->node()));
    384 
    385     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
    386     if (!remainingDecorations.isEmpty() && current)
    387         extractDecorations(styleForRenderer(*current), remainingDecorations);
    388388}
    389389
  • trunk/Source/WebCore/rendering/TextDecorationPainter.h

    r256360 r256451  
    6565        TextDecorationStyle linethroughStyle;
    6666    };
     67    static Color decorationColor(const RenderStyle&);
    6768    static OptionSet<TextDecoration> textDecorationsInEffectForStyle(const Styles&);
    6869    static Styles stylesForRenderer(const RenderObject&, OptionSet<TextDecoration> requestedDecorations, bool firstLineStyle = false, PseudoId = PseudoId::None);
Note: See TracChangeset for help on using the changeset viewer.