Changeset 271350 in webkit


Ignore:
Timestamp:
Jan 10, 2021 10:09:09 AM (3 years ago)
Author:
Antti Koivisto
Message:

[LFC][Integration] Factor marked text style collection code out of InlineTextBox
https://bugs.webkit.org/show_bug.cgi?id=220249

Reviewed by Zalan Bujtas.

Source/WebCore:

This makes it possible to use the code from LFC painting.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paint):
(WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): Deleted.
(WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): Deleted.
(WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): Deleted.
(WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): Deleted.
(WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): Deleted.
(WebCore::InlineTextBox::resolveStyleForMarkedText): Deleted.
(WebCore::InlineTextBox::subdivideAndResolveStyle): Deleted.
(WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): Deleted.

  • rendering/InlineTextBox.h:
  • rendering/MarkedTextStyle.cpp: Added.

(WebCore::resolveStyleForMarkedText):
(WebCore::computeStyleForUnmarkedMarkedText):
(WebCore::subdivideAndResolveStyle):
(WebCore::coalesceAdjacentMarkedTexts):

  • rendering/MarkedTextStyle.h: Added.

(WebCore::MarkedTextStyle::areBackgroundMarkedTextStylesEqual):
(WebCore::MarkedTextStyle::areForegroundMarkedTextStylesEqual):
(WebCore::MarkedTextStyle::areDecorationMarkedTextStylesEqual):
(WebCore::StyledMarkedText::StyledMarkedText):

LayoutTests:

Mark http/wpt/css/css-highlight-api/highlight-text-cascade.html failing.

This test requires CSS4 highlight pseudo element inheritance (https://bugs.webkit.org/show_bug.cgi?id=220325)
which we (or anyone else) don't support.

It was passing by accident because the code was getting '::highlight' pseudo element style from a wrong element
(containing block instead of inline element) in certain cases. Renderer was found via InlineBox parent() which doesn't
match render tree parent in case inline culling optimization is active. The correct way is to use render tree parent.

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r271348 r271350  
     12021-01-10  Antti Koivisto  <antti@apple.com>
     2
     3        [LFC][Integration] Factor marked text style collection code out of InlineTextBox
     4        https://bugs.webkit.org/show_bug.cgi?id=220249
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * TestExpectations:
     9
     10        Mark http/wpt/css/css-highlight-api/highlight-text-cascade.html failing.
     11
     12        This test requires CSS4 highlight pseudo element inheritance (https://bugs.webkit.org/show_bug.cgi?id=220325)
     13        which we (or anyone else) don't support.
     14
     15        It was passing by accident because the code was getting '::highlight' pseudo element style from a wrong element
     16        (containing block instead of inline element) in certain cases. Renderer was found via InlineBox parent() which doesn't
     17        match render tree parent in case inline culling optimization is active. The correct way is to use render tree parent.
     18
    1192021-01-09  Zalan Bujtas  <zalan@apple.com>
    220
  • trunk/LayoutTests/TestExpectations

    r271293 r271350  
    45954595webkit.org/b/217931 imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/moving-between-documents/move-back-iframe-success-external-module.html [ Pass Failure ]
    45964596webkit.org/b/217931 imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/moving-between-documents/move-back-iframe-success-inline-classic.html [ Pass Failure ]
     4597
     4598webkit.org/b/220325 http/wpt/css/css-highlight-api/highlight-text-cascade.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r271349 r271350  
     12021-01-10  Antti Koivisto  <antti@apple.com>
     2
     3        [LFC][Integration] Factor marked text style collection code out of InlineTextBox
     4        https://bugs.webkit.org/show_bug.cgi?id=220249
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        This makes it possible to use the code from LFC painting.
     9
     10        * Sources.txt:
     11        * WebCore.xcodeproj/project.pbxproj:
     12        * rendering/InlineTextBox.cpp:
     13        (WebCore::InlineTextBox::paint):
     14        (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): Deleted.
     15        (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): Deleted.
     16        (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): Deleted.
     17        (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): Deleted.
     18        (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): Deleted.
     19        (WebCore::InlineTextBox::resolveStyleForMarkedText): Deleted.
     20        (WebCore::InlineTextBox::subdivideAndResolveStyle): Deleted.
     21        (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): Deleted.
     22        * rendering/InlineTextBox.h:
     23        * rendering/MarkedTextStyle.cpp: Added.
     24        (WebCore::resolveStyleForMarkedText):
     25        (WebCore::computeStyleForUnmarkedMarkedText):
     26        (WebCore::subdivideAndResolveStyle):
     27        (WebCore::coalesceAdjacentMarkedTexts):
     28        * rendering/MarkedTextStyle.h: Added.
     29        (WebCore::MarkedTextStyle::areBackgroundMarkedTextStylesEqual):
     30        (WebCore::MarkedTextStyle::areForegroundMarkedTextStylesEqual):
     31        (WebCore::MarkedTextStyle::areDecorationMarkedTextStylesEqual):
     32        (WebCore::StyledMarkedText::StyledMarkedText):
     33
    1342021-01-10  Antti Koivisto  <antti@apple.com>
    235
  • trunk/Source/WebCore/Sources.txt

    r271137 r271350  
    21962196rendering/LayoutRepainter.cpp
    21972197rendering/MarkedText.cpp
     2198rendering/MarkedTextStyle.cpp
    21982199rendering/OrderIterator.cpp
    21992200rendering/PointerEventsHitRules.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r271270 r271350  
    50915091                E43AF8E71AC5B7EC00CA717E /* CacheValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */; settings = {ATTRIBUTES = (Private, ); }; };
    50925092                E440AA961C68420800A265CC /* ElementAndTextDescendantIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E440AA951C68420800A265CC /* ElementAndTextDescendantIterator.h */; };
     5093                E440FD5325A4AFDF00F7C849 /* MarkedTextStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = E440FD5125A4AFDF00F7C849 /* MarkedTextStyle.h */; };
    50935094                E44613A20CD6331000FADA75 /* HTMLAudioElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613900CD6331000FADA75 /* HTMLAudioElement.h */; };
    50945095                E44613A50CD6331000FADA75 /* HTMLMediaElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613930CD6331000FADA75 /* HTMLMediaElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1623316234                E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheValidation.h; sourceTree = "<group>"; };
    1623416235                E440AA951C68420800A265CC /* ElementAndTextDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAndTextDescendantIterator.h; sourceTree = "<group>"; };
     16236                E440FD5125A4AFDF00F7C849 /* MarkedTextStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkedTextStyle.h; sourceTree = "<group>"; };
     16237                E440FD5425A4AFEE00F7C849 /* MarkedTextStyle.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MarkedTextStyle.cpp; sourceTree = "<group>"; };
    1623516238                E4451077202C7E0100657D33 /* CompiledSelector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompiledSelector.h; sourceTree = "<group>"; };
    1623616239                E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; };
     
    2964829651                                CE1866421F72E5B400A0CAB6 /* MarkedText.cpp */,
    2964929652                                CE1866431F72E5B400A0CAB6 /* MarkedText.h */,
     29653                                E440FD5425A4AFEE00F7C849 /* MarkedTextStyle.cpp */,
     29654                                E440FD5125A4AFDF00F7C849 /* MarkedTextStyle.h */,
    2965029655                                CDE7FC42181904B1002BBB77 /* OrderIterator.cpp */,
    2965129656                                CDE7FC43181904B1002BBB77 /* OrderIterator.h */,
     
    3304233047                                CDF756A3215C29E900EFCB50 /* JSMediaKeyEncryptionScheme.h in Headers */,
    3304333048                                2D9BF7281DBFDB0D007A7D99 /* JSMediaKeyMessageEvent.h in Headers */,
     33049                                E440FD5325A4AFDF00F7C849 /* MarkedTextStyle.h in Headers */,
    3304433050                                2D9BF7291DBFDB10007A7D99 /* JSMediaKeys.h in Headers */,
    3304533051                                2D9BF72A1DBFDB13007A7D99 /* JSMediaKeySession.h in Headers */,
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r270585 r271350  
    4141#include "ImageBuffer.h"
    4242#include "InlineTextBoxStyle.h"
    43 #include "MarkedText.h"
     43#include "MarkedTextStyle.h"
    4444#include "Page.h"
    4545#include "PaintInfo.h"
     
    434434}
    435435
    436 struct InlineTextBox::MarkedTextStyle {
    437     static bool areBackgroundMarkedTextStylesEqual(const MarkedTextStyle& a, const MarkedTextStyle& b)
    438     {
    439         return a.backgroundColor == b.backgroundColor;
    440     }
    441     static bool areForegroundMarkedTextStylesEqual(const MarkedTextStyle& a, const MarkedTextStyle& b)
    442     {
    443         return a.textStyles == b.textStyles && a.textShadow == b.textShadow && a.alpha == b.alpha;
    444     }
    445     static bool areDecorationMarkedTextStylesEqual(const MarkedTextStyle& a, const MarkedTextStyle& b)
    446     {
    447         return a.textDecorationStyles == b.textDecorationStyles && a.textShadow == b.textShadow && a.alpha == b.alpha;
    448     }
    449 
    450     Color backgroundColor;
    451     TextPaintStyle textStyles;
    452     TextDecorationPainter::Styles textDecorationStyles;
    453     Optional<ShadowData> textShadow;
    454     float alpha;
    455 };
    456 
    457 struct InlineTextBox::StyledMarkedText : MarkedText {
    458     StyledMarkedText(const MarkedText& marker)
    459         : MarkedText { marker }
    460     {
    461     }
    462 
    463     MarkedTextStyle style;
    464 };
    465 
    466436static MarkedText createMarkedTextFromSelectionInBox(const InlineTextBox& box)
    467437{
     
    545515    bool useCustomUnderlines = containsComposition && renderer().frame().editor().compositionUsesCustomUnderlines();
    546516
    547     MarkedTextStyle unmarkedStyle = computeStyleForUnmarkedMarkedText(paintInfo);
    548 
    549517    // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
    550518    // and composition underlines.
     
    564532        }
    565533#endif
    566         auto styledMarkedTexts = subdivideAndResolveStyle(markedTexts, unmarkedStyle, paintInfo);
     534        auto styledMarkedTexts = subdivideAndResolveStyle(markedTexts, renderer(), isFirstLine(), paintInfo);
    567535
    568536        // Coalesce styles of adjacent marked texts to minimize the number of drawing commands.
     
    612580    }
    613581
    614     auto styledMarkedTexts = subdivideAndResolveStyle(markedTexts, unmarkedStyle, paintInfo);
     582    auto styledMarkedTexts = subdivideAndResolveStyle(markedTexts, renderer(), isFirstLine(), paintInfo);
    615583
    616584    // ... now remove the selection marked text if we are excluding selection.
     
    795763    bounds.moveBy(boxOrigin);
    796764    context.drawDotsForDocumentMarker(bounds, lineStyleForMarkedTextType());
    797 }
    798 
    799 auto InlineTextBox::computeStyleForUnmarkedMarkedText(const PaintInfo& paintInfo) const -> MarkedTextStyle
    800 {
    801     auto& lineStyle = this->lineStyle();
    802 
    803     MarkedTextStyle style;
    804     style.textDecorationStyles = TextDecorationPainter::stylesForRenderer(renderer(), lineStyle.textDecorationsInEffect(), isFirstLine());
    805     style.textStyles = computeTextPaintStyle(renderer().frame(), lineStyle, paintInfo);
    806     style.textShadow = ShadowData::clone(paintInfo.forceTextColor() ? nullptr : lineStyle.textShadow());
    807     style.alpha = 1;
    808     return style;
    809 }
    810 
    811 auto InlineTextBox::resolveStyleForMarkedText(const MarkedText& markedText, const MarkedTextStyle& baseStyle, const PaintInfo& paintInfo) -> StyledMarkedText
    812 {
    813     MarkedTextStyle style = baseStyle;
    814     switch (markedText.type) {
    815     case MarkedText::Correction:
    816     case MarkedText::DictationAlternatives:
    817 #if PLATFORM(IOS_FAMILY)
    818     // FIXME: See <rdar://problem/8933352>. Also, remove the PLATFORM(IOS_FAMILY)-guard.
    819     case MarkedText::DictationPhraseWithAlternatives:
    820 #endif
    821     case MarkedText::GrammarError:
    822     case MarkedText::SpellingError:
    823     case MarkedText::Unmarked:
    824         break;
    825     case MarkedText::Highlight:
    826         if (auto renderStyle = parent()->renderer().getUncachedPseudoStyle({ PseudoId::Highlight, markedText.highlightName }, &parent()->renderer().style())) {
    827             style.backgroundColor = renderStyle->backgroundColor();
    828             style.textStyles.fillColor = renderStyle->computedStrokeColor();
    829             style.textStyles.strokeColor = renderStyle->computedStrokeColor();
    830            
    831             auto color = TextDecorationPainter::decorationColor(*renderStyle.get());
    832             auto decorationStyle = renderStyle->textDecorationStyle();
    833             auto decorations = renderStyle->textDecorationsInEffect();
    834 
    835             if (decorations.contains(TextDecoration::Underline)) {
    836                 style.textDecorationStyles.underlineColor = color;
    837                 style.textDecorationStyles.underlineStyle = decorationStyle;
    838             }
    839             if (decorations.contains(TextDecoration::Overline)) {
    840                 style.textDecorationStyles.overlineColor = color;
    841                 style.textDecorationStyles.overlineStyle = decorationStyle;
    842             }
    843             if (decorations.contains(TextDecoration::LineThrough)) {
    844                 style.textDecorationStyles.linethroughColor = color;
    845                 style.textDecorationStyles.linethroughStyle = decorationStyle;
    846             }
    847         }
    848         break;
    849 #if ENABLE(APP_HIGHLIGHTS)
    850     case MarkedText::AppHighlight: {
    851         OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
    852         style.backgroundColor = renderer().theme().appHighlightColor(styleColorOptions);
    853         break;
    854     }
    855 #endif
    856     case MarkedText::DraggedContent:
    857         style.alpha = 0.25;
    858         break;
    859     case MarkedText::Selection: {
    860         style.textStyles = computeTextSelectionPaintStyle(style.textStyles, renderer(), lineStyle(), paintInfo, style.textShadow);
    861 
    862         Color selectionBackgroundColor = renderer().selectionBackgroundColor();
    863         style.backgroundColor = selectionBackgroundColor;
    864         if (selectionBackgroundColor.isValid() && selectionBackgroundColor.isVisible() && style.textStyles.fillColor == selectionBackgroundColor)
    865             style.backgroundColor = selectionBackgroundColor.invertedColorWithAlpha(1.0);
    866         break;
    867     }
    868     case MarkedText::TextMatch: {
    869         // Text matches always use the light system appearance.
    870         OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
    871 #if PLATFORM(MAC)
    872         style.textStyles.fillColor = renderer().theme().systemColor(CSSValueAppleSystemLabel, styleColorOptions);
    873 #endif
    874         style.backgroundColor = renderer().theme().textSearchHighlightColor(styleColorOptions);
    875         break;
    876     }
    877     }
    878     StyledMarkedText styledMarkedText = markedText;
    879     styledMarkedText.style = WTFMove(style);
    880     return styledMarkedText;
    881 }
    882 
    883 auto InlineTextBox::subdivideAndResolveStyle(const Vector<MarkedText>& textsToSubdivide, const MarkedTextStyle& baseStyle, const PaintInfo& paintInfo) -> Vector<StyledMarkedText>
    884 {
    885     if (textsToSubdivide.isEmpty())
    886         return { };
    887 
    888     auto markedTexts = subdivide(textsToSubdivide);
    889     ASSERT(!markedTexts.isEmpty());
    890     if (UNLIKELY(markedTexts.isEmpty()))
    891         return { };
    892 
    893     // Compute frontmost overlapping styled marked texts.
    894     Vector<StyledMarkedText> frontmostMarkedTexts;
    895     frontmostMarkedTexts.reserveInitialCapacity(markedTexts.size());
    896     frontmostMarkedTexts.uncheckedAppend(resolveStyleForMarkedText(markedTexts[0], baseStyle, paintInfo));
    897     for (auto it = markedTexts.begin() + 1, end = markedTexts.end(); it != end; ++it) {
    898         StyledMarkedText& previousStyledMarkedText = frontmostMarkedTexts.last();
    899         if (previousStyledMarkedText.startOffset == it->startOffset && previousStyledMarkedText.endOffset == it->endOffset) {
    900             // Marked texts completely cover each other.
    901             previousStyledMarkedText = resolveStyleForMarkedText(*it, previousStyledMarkedText.style, paintInfo);
    902             continue;
    903         }
    904         frontmostMarkedTexts.uncheckedAppend(resolveStyleForMarkedText(*it, baseStyle, paintInfo));
    905     }
    906 
    907     return frontmostMarkedTexts;
    908 }
    909 
    910 auto InlineTextBox::coalesceAdjacentMarkedTexts(const Vector<StyledMarkedText>& textsToCoalesce, MarkedTextStylesEqualityFunction areMarkedTextStylesEqual) -> Vector<StyledMarkedText>
    911 {
    912     if (textsToCoalesce.isEmpty())
    913         return { };
    914 
    915     auto areAdjacentMarkedTextsWithSameStyle = [&] (const StyledMarkedText& a, const StyledMarkedText& b) {
    916         return a.endOffset == b.startOffset && areMarkedTextStylesEqual(a.style, b.style);
    917     };
    918 
    919     Vector<StyledMarkedText> styledMarkedTexts;
    920     styledMarkedTexts.reserveInitialCapacity(textsToCoalesce.size());
    921     styledMarkedTexts.uncheckedAppend(textsToCoalesce[0]);
    922     for (auto it = textsToCoalesce.begin() + 1, end = textsToCoalesce.end(); it != end; ++it) {
    923         StyledMarkedText& previousStyledMarkedText = styledMarkedTexts.last();
    924         if (areAdjacentMarkedTextsWithSameStyle(previousStyledMarkedText, *it)) {
    925             previousStyledMarkedText.endOffset = it->endOffset;
    926             continue;
    927         }
    928         styledMarkedTexts.uncheckedAppend(*it);
    929     }
    930 
    931     return styledMarkedTexts;
    932765}
    933766
  • trunk/Source/WebCore/rendering/InlineTextBox.h

    r269726 r271350  
    3434struct CompositionUnderline;
    3535struct MarkedText;
     36struct StyledMarkedText;
    3637struct TextPaintStyle;
    3738
     
    165166
    166167private:
    167     struct MarkedTextStyle;
    168     struct StyledMarkedText;
    169 
    170168    enum class TextPaintPhase { Background, Foreground, Decoration };
    171169
     
    173171    Vector<MarkedText> collectMarkedTextsForDocumentMarkers(TextPaintPhase) const;
    174172    Vector<MarkedText> collectMarkedTextsForHighlights(TextPaintPhase) const;
    175 
    176     MarkedTextStyle computeStyleForUnmarkedMarkedText(const PaintInfo&) const;
    177     StyledMarkedText resolveStyleForMarkedText(const MarkedText&, const MarkedTextStyle& baseStyle, const PaintInfo&);
    178     Vector<StyledMarkedText> subdivideAndResolveStyle(const Vector<MarkedText>&, const MarkedTextStyle& baseStyle, const PaintInfo&);
    179 
    180     using MarkedTextStylesEqualityFunction = bool (*)(const MarkedTextStyle&, const MarkedTextStyle&);
    181     Vector<StyledMarkedText> coalesceAdjacentMarkedTexts(const Vector<StyledMarkedText>&, MarkedTextStylesEqualityFunction);
    182173
    183174    FloatPoint textOriginFromBoxRect(const FloatRect&) const;
Note: See TracChangeset for help on using the changeset viewer.