Title: [281240] trunk/Source/WebCore
Revision
281240
Author
[email protected]
Date
2021-08-19 09:05:09 -0700 (Thu, 19 Aug 2021)

Log Message

Move MarkedTextStyle into StyledMarkedText scope
https://bugs.webkit.org/show_bug.cgi?id=228956

Reviewed by Alan Bujtas.

As StyledMarkedText::Style.
Also other cleanups and a file rename to match the type.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* rendering/LegacyInlineTextBox.cpp:
(WebCore::LegacyInlineTextBox::paint):
* rendering/StyledMarkedText.cpp: Renamed from Source/WebCore/rendering/MarkedTextStyle.cpp.
(WebCore::resolveStyleForMarkedText):
(WebCore::computeStyleForUnmarkedMarkedText):
(WebCore::StyledMarkedText::subdivideAndResolve):
(WebCore::coalesceAdjacent):
(WebCore::StyledMarkedText::coalesceAdjacentWithEqualBackground):
(WebCore::StyledMarkedText::coalesceAdjacentWithEqualForeground):
(WebCore::StyledMarkedText::coalesceAdjacentWithEqualDecorations):
* rendering/StyledMarkedText.h: Renamed from Source/WebCore/rendering/MarkedTextStyle.h.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281239 => 281240)


--- trunk/Source/WebCore/ChangeLog	2021-08-19 15:51:31 UTC (rev 281239)
+++ trunk/Source/WebCore/ChangeLog	2021-08-19 16:05:09 UTC (rev 281240)
@@ -1,3 +1,27 @@
+2021-08-19  Antti Koivisto  <[email protected]>
+
+        Move MarkedTextStyle into StyledMarkedText scope
+        https://bugs.webkit.org/show_bug.cgi?id=228956
+
+        Reviewed by Alan Bujtas.
+
+        As StyledMarkedText::Style.
+        Also other cleanups and a file rename to match the type.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/LegacyInlineTextBox.cpp:
+        (WebCore::LegacyInlineTextBox::paint):
+        * rendering/StyledMarkedText.cpp: Renamed from Source/WebCore/rendering/MarkedTextStyle.cpp.
+        (WebCore::resolveStyleForMarkedText):
+        (WebCore::computeStyleForUnmarkedMarkedText):
+        (WebCore::StyledMarkedText::subdivideAndResolve):
+        (WebCore::coalesceAdjacent):
+        (WebCore::StyledMarkedText::coalesceAdjacentWithEqualBackground):
+        (WebCore::StyledMarkedText::coalesceAdjacentWithEqualForeground):
+        (WebCore::StyledMarkedText::coalesceAdjacentWithEqualDecorations):
+        * rendering/StyledMarkedText.h: Renamed from Source/WebCore/rendering/MarkedTextStyle.h.
+
 2021-08-19  Simon Fraser  <[email protected]>
 
         Use an OptionSet<MapCoordinatesMode> in place of MapCoordinatesFlags

Modified: trunk/Source/WebCore/Sources.txt (281239 => 281240)


--- trunk/Source/WebCore/Sources.txt	2021-08-19 15:51:31 UTC (rev 281239)
+++ trunk/Source/WebCore/Sources.txt	2021-08-19 16:05:09 UTC (rev 281240)
@@ -2176,7 +2176,6 @@
 rendering/LegacyRootInlineBox.cpp
 rendering/LegacyInlineTextBox.cpp
 rendering/MarkedText.cpp
-rendering/MarkedTextStyle.cpp
 rendering/OrderIterator.cpp
 rendering/PointerEventsHitRules.cpp
 rendering/RenderAttachment.cpp
@@ -2264,6 +2263,7 @@
 rendering/RenderWidget.cpp
 rendering/ScrollAlignment.cpp
 rendering/SelectionRangeData.cpp
+rendering/StyledMarkedText.cpp
 rendering/TableLayout.cpp
 rendering/TextDecorationPainter.cpp
 rendering/TextPaintStyle.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (281239 => 281240)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-08-19 15:51:31 UTC (rev 281239)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-08-19 16:05:09 UTC (rev 281240)
@@ -5200,7 +5200,7 @@
 		E43A023B17EB370A004CDD25 /* RenderElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A023A17EB370A004CDD25 /* RenderElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E43AF8E71AC5B7EC00CA717E /* CacheValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E440AA961C68420800A265CC /* ElementAndTextDescendantIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E440AA951C68420800A265CC /* ElementAndTextDescendantIterator.h */; };
-		E440FD5325A4AFDF00F7C849 /* MarkedTextStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = E440FD5125A4AFDF00F7C849 /* MarkedTextStyle.h */; };
+		E440FD5325A4AFDF00F7C849 /* StyledMarkedText.h in Headers */ = {isa = PBXBuildFile; fileRef = E440FD5125A4AFDF00F7C849 /* StyledMarkedText.h */; };
 		E44613A20CD6331000FADA75 /* HTMLAudioElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613900CD6331000FADA75 /* HTMLAudioElement.h */; };
 		E44613A50CD6331000FADA75 /* HTMLMediaElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613930CD6331000FADA75 /* HTMLMediaElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E44613A80CD6331000FADA75 /* HTMLSourceElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613960CD6331000FADA75 /* HTMLSourceElement.h */; };
@@ -16198,8 +16198,8 @@
 		E43AF8E41AC5B7DD00CA717E /* CacheValidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheValidation.cpp; sourceTree = "<group>"; };
 		E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheValidation.h; sourceTree = "<group>"; };
 		E440AA951C68420800A265CC /* ElementAndTextDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAndTextDescendantIterator.h; sourceTree = "<group>"; };
-		E440FD5125A4AFDF00F7C849 /* MarkedTextStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkedTextStyle.h; sourceTree = "<group>"; };
-		E440FD5425A4AFEE00F7C849 /* MarkedTextStyle.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MarkedTextStyle.cpp; sourceTree = "<group>"; };
+		E440FD5125A4AFDF00F7C849 /* StyledMarkedText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyledMarkedText.h; sourceTree = "<group>"; };
+		E440FD5425A4AFEE00F7C849 /* StyledMarkedText.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StyledMarkedText.cpp; sourceTree = "<group>"; };
 		E4451077202C7E0100657D33 /* CompiledSelector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompiledSelector.h; sourceTree = "<group>"; };
 		E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; };
 		E44613900CD6331000FADA75 /* HTMLAudioElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLAudioElement.h; sourceTree = "<group>"; };
@@ -29489,8 +29489,6 @@
 				9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */,
 				CE1866421F72E5B400A0CAB6 /* MarkedText.cpp */,
 				CE1866431F72E5B400A0CAB6 /* MarkedText.h */,
-				E440FD5425A4AFEE00F7C849 /* MarkedTextStyle.cpp */,
-				E440FD5125A4AFDF00F7C849 /* MarkedTextStyle.h */,
 				CDE7FC42181904B1002BBB77 /* OrderIterator.cpp */,
 				CDE7FC43181904B1002BBB77 /* OrderIterator.h */,
 				3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */,
@@ -29684,6 +29682,8 @@
 				5D925B660F64D4DD00B847F0 /* ScrollAlignment.h */,
 				44B38BF925369A8800A4458D /* SelectionRangeData.cpp */,
 				44B38BF42536901A00A4458D /* SelectionRangeData.h */,
+				E440FD5425A4AFEE00F7C849 /* StyledMarkedText.cpp */,
+				E440FD5125A4AFDF00F7C849 /* StyledMarkedText.h */,
 				E31CD750229F749500FBDA19 /* TableLayout.cpp */,
 				A8CFF04C0A154F09000A4234 /* TableLayout.h */,
 				0F54DCE31881051D003EEDBB /* TextAutoSizing.cpp */,
@@ -33522,7 +33522,7 @@
 				7AE6C93C1BE0C60100E19E03 /* MainThreadSharedTimer.h in Headers */,
 				E451C6322394031A00993190 /* MarginTypes.h in Headers */,
 				CE1866451F72E5B400A0CAB6 /* MarkedText.h in Headers */,
-				E440FD5325A4AFDF00F7C849 /* MarkedTextStyle.h in Headers */,
+				E440FD5325A4AFDF00F7C849 /* StyledMarkedText.h in Headers */,
 				93309DF8099E64920056E581 /* markup.h in Headers */,
 				9728C3141268E4390041E89B /* MarkupAccumulator.h in Headers */,
 				00C60E3F13D76D7E0092A275 /* MarkupTokenizerInlines.h in Headers */,

Modified: trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp (281239 => 281240)


--- trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp	2021-08-19 15:51:31 UTC (rev 281239)
+++ trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp	2021-08-19 16:05:09 UTC (rev 281240)
@@ -40,7 +40,6 @@
 #include "ImageBuffer.h"
 #include "InlineTextBoxStyle.h"
 #include "LegacyEllipsisBox.h"
-#include "MarkedTextStyle.h"
 #include "Page.h"
 #include "PaintInfo.h"
 #include "RenderBlock.h"
@@ -53,6 +52,7 @@
 #include "RenderedDocumentMarker.h"
 #include "RuntimeEnabledFeatures.h"
 #include "Settings.h"
+#include "StyledMarkedText.h"
 #include "Text.h"
 #include "TextBoxSelectableRange.h"
 #include "TextDecorationPainter.h"
@@ -504,10 +504,10 @@
                 markedTexts.append(WTFMove(selectionMarkedText));
         }
 #endif
-        auto styledMarkedTexts = subdivideAndResolveStyle(markedTexts, renderer(), isFirstLine(), paintInfo);
+        auto styledMarkedTexts = StyledMarkedText::subdivideAndResolve(markedTexts, renderer(), isFirstLine(), paintInfo);
 
         // Coalesce styles of adjacent marked texts to minimize the number of drawing commands.
-        auto coalescedStyledMarkedTexts = coalesceAdjacentMarkedTexts(styledMarkedTexts, &MarkedTextStyle::areBackgroundMarkedTextStylesEqual);
+        auto coalescedStyledMarkedTexts = StyledMarkedText::coalesceAdjacentWithEqualBackground(styledMarkedTexts);
 
         paintMarkedTexts(paintInfo, MarkedText::PaintPhase::Background, boxRect, coalescedStyledMarkedTexts);
     }
@@ -553,7 +553,7 @@
             markedTexts.append(WTFMove(selectionMarkedText));
     }
 
-    auto styledMarkedTexts = subdivideAndResolveStyle(markedTexts, renderer(), isFirstLine(), paintInfo);
+    auto styledMarkedTexts = StyledMarkedText::subdivideAndResolve(markedTexts, renderer(), isFirstLine(), paintInfo);
 
     // ... now remove the selection marked text if we are excluding selection.
     if (!isPrinting && paintInfo.paintBehavior.contains(PaintBehavior::ExcludeSelection)) {
@@ -563,7 +563,7 @@
     }
 
     // Coalesce styles of adjacent marked texts to minimize the number of drawing commands.
-    auto coalescedStyledMarkedTexts = coalesceAdjacentMarkedTexts(styledMarkedTexts, &MarkedTextStyle::areForegroundMarkedTextStylesEqual);
+    auto coalescedStyledMarkedTexts = StyledMarkedText::coalesceAdjacentWithEqualForeground(styledMarkedTexts);
 
     paintMarkedTexts(paintInfo, MarkedText::PaintPhase::Foreground, boxRect, coalescedStyledMarkedTexts);
 
@@ -602,7 +602,7 @@
         }
 
         // Coalesce styles of adjacent marked texts to minimize the number of drawing commands.
-        auto coalescedStyledMarkedTexts = coalesceAdjacentMarkedTexts(styledMarkedTexts, &MarkedTextStyle::areDecorationMarkedTextStylesEqual);
+        auto coalescedStyledMarkedTexts = StyledMarkedText::coalesceAdjacentWithEqualDecorations(styledMarkedTexts);
 
         paintMarkedTexts(paintInfo, MarkedText::PaintPhase::Decoration, boxRect, coalescedStyledMarkedTexts, textDecorationSelectionClipOutRect);
     }

Deleted: trunk/Source/WebCore/rendering/MarkedTextStyle.cpp (281239 => 281240)


--- trunk/Source/WebCore/rendering/MarkedTextStyle.cpp	2021-08-19 15:51:31 UTC (rev 281239)
+++ trunk/Source/WebCore/rendering/MarkedTextStyle.cpp	2021-08-19 16:05:09 UTC (rev 281240)
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "MarkedTextStyle.h"
-
-#include "ElementRuleCollector.h"
-#include "RenderElement.h"
-#include "RenderText.h"
-#include "RenderTheme.h"
-
-namespace WebCore {
-
-static StyledMarkedText resolveStyleForMarkedText(const MarkedText& markedText, const MarkedTextStyle& baseStyle, const RenderText& renderer, const RenderStyle& lineStyle, const PaintInfo& paintInfo)
-{
-    MarkedTextStyle style = baseStyle;
-    switch (markedText.type) {
-    case MarkedText::Correction:
-    case MarkedText::DictationAlternatives:
-#if PLATFORM(IOS_FAMILY)
-    // FIXME: See <rdar://problem/8933352>. Also, remove the PLATFORM(IOS_FAMILY)-guard.
-    case MarkedText::DictationPhraseWithAlternatives:
-#endif
-    case MarkedText::GrammarError:
-    case MarkedText::SpellingError:
-    case MarkedText::Unmarked:
-        break;
-    case MarkedText::Highlight:
-        if (auto renderStyle = renderer.parent()->getUncachedPseudoStyle({ PseudoId::Highlight, markedText.highlightName }, &renderer.style())) {
-            style.backgroundColor = renderStyle->backgroundColor();
-            style.textStyles.fillColor = renderStyle->computedStrokeColor();
-            style.textStyles.strokeColor = renderStyle->computedStrokeColor();
-
-            auto color = TextDecorationPainter::decorationColor(*renderStyle.get());
-            auto decorationStyle = renderStyle->textDecorationStyle();
-            auto decorations = renderStyle->textDecorationsInEffect();
-
-            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;
-#if ENABLE(APP_HIGHLIGHTS)
-    case MarkedText::AppHighlight: {
-        OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
-        style.backgroundColor = renderer.theme().appHighlightColor(styleColorOptions);
-        break;
-    }
-#endif
-    case MarkedText::DraggedContent:
-        style.alpha = 0.25;
-        break;
-    case MarkedText::Selection: {
-        style.textStyles = computeTextSelectionPaintStyle(style.textStyles, renderer, lineStyle, paintInfo, style.textShadow);
-
-        Color selectionBackgroundColor = renderer.selectionBackgroundColor();
-        style.backgroundColor = selectionBackgroundColor;
-        if (selectionBackgroundColor.isValid() && selectionBackgroundColor.isVisible() && style.textStyles.fillColor == selectionBackgroundColor)
-            style.backgroundColor = selectionBackgroundColor.invertedColorWithAlpha(1.0);
-        break;
-    }
-    case MarkedText::TextMatch: {
-        // Text matches always use the light system appearance.
-        OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
-#if PLATFORM(MAC)
-        style.textStyles.fillColor = renderer.theme().systemColor(CSSValueAppleSystemLabel, styleColorOptions);
-#endif
-        style.backgroundColor = renderer.theme().textSearchHighlightColor(styleColorOptions);
-        break;
-    }
-    }
-    StyledMarkedText styledMarkedText = markedText;
-    styledMarkedText.style = WTFMove(style);
-    return styledMarkedText;
-}
-
-static MarkedTextStyle computeStyleForUnmarkedMarkedText(const RenderText& renderer, const RenderStyle& lineStyle, bool isFirstLine, const PaintInfo& paintInfo)
-{
-    MarkedTextStyle style;
-    style.textDecorationStyles = TextDecorationPainter::stylesForRenderer(renderer, lineStyle.textDecorationsInEffect(), isFirstLine);
-    style.textStyles = computeTextPaintStyle(renderer.frame(), lineStyle, paintInfo);
-    style.textShadow = ShadowData::clone(paintInfo.forceTextColor() ? nullptr : lineStyle.textShadow());
-    style.alpha = 1;
-    return style;
-}
-
-Vector<StyledMarkedText> subdivideAndResolveStyle(const Vector<MarkedText>& textsToSubdivide, const RenderText& renderer, bool isFirstLine, const PaintInfo& paintInfo)
-{
-    if (textsToSubdivide.isEmpty())
-        return { };
-
-    Vector<StyledMarkedText> frontmostMarkedTexts;
-
-    auto& lineStyle = isFirstLine ? renderer.firstLineStyle() : renderer.style();
-    auto baseStyle = computeStyleForUnmarkedMarkedText(renderer, lineStyle, isFirstLine, paintInfo);
-
-    if (textsToSubdivide.size() == 1 && textsToSubdivide[0].type == MarkedText::Unmarked) {
-        StyledMarkedText styledMarkedText = textsToSubdivide[0];
-        styledMarkedText.style = WTFMove(baseStyle);
-        return { styledMarkedText };
-    }
-
-    auto markedTexts = MarkedText::subdivide(textsToSubdivide);
-    ASSERT(!markedTexts.isEmpty());
-    if (UNLIKELY(markedTexts.isEmpty()))
-        return { };
-
-    // Compute frontmost overlapping styled marked texts.
-    frontmostMarkedTexts.reserveInitialCapacity(markedTexts.size());
-    frontmostMarkedTexts.uncheckedAppend(resolveStyleForMarkedText(markedTexts[0], baseStyle, renderer, lineStyle, paintInfo));
-    for (auto it = markedTexts.begin() + 1, end = markedTexts.end(); it != end; ++it) {
-        StyledMarkedText& previousStyledMarkedText = frontmostMarkedTexts.last();
-        if (previousStyledMarkedText.startOffset == it->startOffset && previousStyledMarkedText.endOffset == it->endOffset) {
-            // Marked texts completely cover each other.
-            previousStyledMarkedText = resolveStyleForMarkedText(*it, previousStyledMarkedText.style, renderer, lineStyle, paintInfo);
-            continue;
-        }
-        frontmostMarkedTexts.uncheckedAppend(resolveStyleForMarkedText(*it, baseStyle, renderer, lineStyle, paintInfo));
-    }
-
-    return frontmostMarkedTexts;
-}
-
-Vector<StyledMarkedText> coalesceAdjacentMarkedTexts(const Vector<StyledMarkedText>& textsToCoalesce, MarkedTextStylesEqualityFunction areMarkedTextStylesEqual)
-{
-    if (textsToCoalesce.size() <= 1)
-        return textsToCoalesce;
-
-    auto areAdjacentMarkedTextsWithSameStyle = [&] (const StyledMarkedText& a, const StyledMarkedText& b) {
-        return a.endOffset == b.startOffset && areMarkedTextStylesEqual(a.style, b.style);
-    };
-
-    Vector<StyledMarkedText> styledMarkedTexts;
-    styledMarkedTexts.reserveInitialCapacity(textsToCoalesce.size());
-    styledMarkedTexts.uncheckedAppend(textsToCoalesce[0]);
-    for (auto it = textsToCoalesce.begin() + 1, end = textsToCoalesce.end(); it != end; ++it) {
-        StyledMarkedText& previousStyledMarkedText = styledMarkedTexts.last();
-        if (areAdjacentMarkedTextsWithSameStyle(previousStyledMarkedText, *it)) {
-            previousStyledMarkedText.endOffset = it->endOffset;
-            continue;
-        }
-        styledMarkedTexts.uncheckedAppend(*it);
-    }
-
-    return styledMarkedTexts;
-}
-
-}

Deleted: trunk/Source/WebCore/rendering/MarkedTextStyle.h (281239 => 281240)


--- trunk/Source/WebCore/rendering/MarkedTextStyle.h	2021-08-19 15:51:31 UTC (rev 281239)
+++ trunk/Source/WebCore/rendering/MarkedTextStyle.h	2021-08-19 16:05:09 UTC (rev 281240)
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "MarkedText.h"
-#include "ShadowData.h"
-#include "TextDecorationPainter.h"
-#include "TextPaintStyle.h"
-
-namespace WebCore {
-
-class RenderText;
-class RenderedDocumentMarker;
-
-struct MarkedTextStyle {
-    static bool areBackgroundMarkedTextStylesEqual(const MarkedTextStyle& a, const MarkedTextStyle& b)
-    {
-        return a.backgroundColor == b.backgroundColor;
-    }
-    static bool areForegroundMarkedTextStylesEqual(const MarkedTextStyle& a, const MarkedTextStyle& b)
-    {
-        return a.textStyles == b.textStyles && a.textShadow == b.textShadow && a.alpha == b.alpha;
-    }
-    static bool areDecorationMarkedTextStylesEqual(const MarkedTextStyle& a, const MarkedTextStyle& b)
-    {
-        return a.textDecorationStyles == b.textDecorationStyles && a.textShadow == b.textShadow && a.alpha == b.alpha;
-    }
-
-    Color backgroundColor;
-    TextPaintStyle textStyles;
-    TextDecorationPainter::Styles textDecorationStyles;
-    std::optional<ShadowData> textShadow;
-    float alpha;
-};
-
-struct StyledMarkedText : MarkedText {
-    StyledMarkedText(const MarkedText& marker)
-        : MarkedText { marker }
-    {
-    }
-
-    MarkedTextStyle style;
-};
-
-Vector<StyledMarkedText> subdivideAndResolveStyle(const Vector<MarkedText>&, const RenderText&, bool isFirstLine, const PaintInfo&);
-
-using MarkedTextStylesEqualityFunction = bool (*)(const MarkedTextStyle&, const MarkedTextStyle&);
-Vector<StyledMarkedText> coalesceAdjacentMarkedTexts(const Vector<StyledMarkedText>&, MarkedTextStylesEqualityFunction);
-
-}

Copied: trunk/Source/WebCore/rendering/StyledMarkedText.cpp (from rev 281239, trunk/Source/WebCore/rendering/MarkedTextStyle.cpp) (0 => 281240)


--- trunk/Source/WebCore/rendering/StyledMarkedText.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/StyledMarkedText.cpp	2021-08-19 16:05:09 UTC (rev 281240)
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "StyledMarkedText.h"
+
+#include "ElementRuleCollector.h"
+#include "RenderElement.h"
+#include "RenderText.h"
+#include "RenderTheme.h"
+
+namespace WebCore {
+
+static StyledMarkedText resolveStyleForMarkedText(const MarkedText& markedText, const StyledMarkedText::Style& baseStyle, const RenderText& renderer, const RenderStyle& lineStyle, const PaintInfo& paintInfo)
+{
+    auto style = baseStyle;
+    switch (markedText.type) {
+    case MarkedText::Correction:
+    case MarkedText::DictationAlternatives:
+#if PLATFORM(IOS_FAMILY)
+    // FIXME: See <rdar://problem/8933352>. Also, remove the PLATFORM(IOS_FAMILY)-guard.
+    case MarkedText::DictationPhraseWithAlternatives:
+#endif
+    case MarkedText::GrammarError:
+    case MarkedText::SpellingError:
+    case MarkedText::Unmarked:
+        break;
+    case MarkedText::Highlight:
+        if (auto renderStyle = renderer.parent()->getUncachedPseudoStyle({ PseudoId::Highlight, markedText.highlightName }, &renderer.style())) {
+            style.backgroundColor = renderStyle->backgroundColor();
+            style.textStyles.fillColor = renderStyle->computedStrokeColor();
+            style.textStyles.strokeColor = renderStyle->computedStrokeColor();
+
+            auto color = TextDecorationPainter::decorationColor(*renderStyle.get());
+            auto decorationStyle = renderStyle->textDecorationStyle();
+            auto decorations = renderStyle->textDecorationsInEffect();
+
+            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;
+#if ENABLE(APP_HIGHLIGHTS)
+    case MarkedText::AppHighlight: {
+        OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
+        style.backgroundColor = renderer.theme().appHighlightColor(styleColorOptions);
+        break;
+    }
+#endif
+    case MarkedText::DraggedContent:
+        style.alpha = 0.25;
+        break;
+    case MarkedText::Selection: {
+        style.textStyles = computeTextSelectionPaintStyle(style.textStyles, renderer, lineStyle, paintInfo, style.textShadow);
+
+        Color selectionBackgroundColor = renderer.selectionBackgroundColor();
+        style.backgroundColor = selectionBackgroundColor;
+        if (selectionBackgroundColor.isValid() && selectionBackgroundColor.isVisible() && style.textStyles.fillColor == selectionBackgroundColor)
+            style.backgroundColor = selectionBackgroundColor.invertedColorWithAlpha(1.0);
+        break;
+    }
+    case MarkedText::TextMatch: {
+        // Text matches always use the light system appearance.
+        OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
+#if PLATFORM(MAC)
+        style.textStyles.fillColor = renderer.theme().systemColor(CSSValueAppleSystemLabel, styleColorOptions);
+#endif
+        style.backgroundColor = renderer.theme().textSearchHighlightColor(styleColorOptions);
+        break;
+    }
+    }
+    StyledMarkedText styledMarkedText = markedText;
+    styledMarkedText.style = WTFMove(style);
+    return styledMarkedText;
+}
+
+static StyledMarkedText::Style computeStyleForUnmarkedMarkedText(const RenderText& renderer, const RenderStyle& lineStyle, bool isFirstLine, const PaintInfo& paintInfo)
+{
+    StyledMarkedText::Style style;
+    style.textDecorationStyles = TextDecorationPainter::stylesForRenderer(renderer, lineStyle.textDecorationsInEffect(), isFirstLine);
+    style.textStyles = computeTextPaintStyle(renderer.frame(), lineStyle, paintInfo);
+    style.textShadow = ShadowData::clone(paintInfo.forceTextColor() ? nullptr : lineStyle.textShadow());
+    style.alpha = 1;
+    return style;
+}
+
+Vector<StyledMarkedText> StyledMarkedText::subdivideAndResolve(const Vector<MarkedText>& textsToSubdivide, const RenderText& renderer, bool isFirstLine, const PaintInfo& paintInfo)
+{
+    if (textsToSubdivide.isEmpty())
+        return { };
+
+    Vector<StyledMarkedText> frontmostMarkedTexts;
+
+    auto& lineStyle = isFirstLine ? renderer.firstLineStyle() : renderer.style();
+    auto baseStyle = computeStyleForUnmarkedMarkedText(renderer, lineStyle, isFirstLine, paintInfo);
+
+    if (textsToSubdivide.size() == 1 && textsToSubdivide[0].type == MarkedText::Unmarked) {
+        StyledMarkedText styledMarkedText = textsToSubdivide[0];
+        styledMarkedText.style = WTFMove(baseStyle);
+        return { styledMarkedText };
+    }
+
+    auto markedTexts = MarkedText::subdivide(textsToSubdivide);
+    ASSERT(!markedTexts.isEmpty());
+    if (UNLIKELY(markedTexts.isEmpty()))
+        return { };
+
+    // Compute frontmost overlapping styled marked texts.
+    frontmostMarkedTexts.reserveInitialCapacity(markedTexts.size());
+    frontmostMarkedTexts.uncheckedAppend(resolveStyleForMarkedText(markedTexts[0], baseStyle, renderer, lineStyle, paintInfo));
+    for (auto it = markedTexts.begin() + 1, end = markedTexts.end(); it != end; ++it) {
+        StyledMarkedText& previousStyledMarkedText = frontmostMarkedTexts.last();
+        if (previousStyledMarkedText.startOffset == it->startOffset && previousStyledMarkedText.endOffset == it->endOffset) {
+            // Marked texts completely cover each other.
+            previousStyledMarkedText = resolveStyleForMarkedText(*it, previousStyledMarkedText.style, renderer, lineStyle, paintInfo);
+            continue;
+        }
+        frontmostMarkedTexts.uncheckedAppend(resolveStyleForMarkedText(*it, baseStyle, renderer, lineStyle, paintInfo));
+    }
+
+    return frontmostMarkedTexts;
+}
+
+template<typename EqualityFunction>
+static Vector<StyledMarkedText> coalesceAdjacent(const Vector<StyledMarkedText>& textsToCoalesce, EqualityFunction&& equalityFunction)
+{
+    if (textsToCoalesce.size() <= 1)
+        return textsToCoalesce;
+
+    auto areAdjacentMarkedTextsWithSameStyle = [&] (const StyledMarkedText& a, const StyledMarkedText& b) {
+        return a.endOffset == b.startOffset && equalityFunction(a.style, b.style);
+    };
+
+    Vector<StyledMarkedText> styledMarkedTexts;
+    styledMarkedTexts.reserveInitialCapacity(textsToCoalesce.size());
+    styledMarkedTexts.uncheckedAppend(textsToCoalesce[0]);
+    for (auto it = textsToCoalesce.begin() + 1, end = textsToCoalesce.end(); it != end; ++it) {
+        StyledMarkedText& previousStyledMarkedText = styledMarkedTexts.last();
+        if (areAdjacentMarkedTextsWithSameStyle(previousStyledMarkedText, *it)) {
+            previousStyledMarkedText.endOffset = it->endOffset;
+            continue;
+        }
+        styledMarkedTexts.uncheckedAppend(*it);
+    }
+
+    return styledMarkedTexts;
+}
+
+Vector<StyledMarkedText> StyledMarkedText::coalesceAdjacentWithEqualBackground(const Vector<StyledMarkedText>& markedTexts)
+{
+    return coalesceAdjacent(markedTexts, [&](auto& a, auto& b) {
+        return a.backgroundColor == b.backgroundColor;
+    });
+}
+
+Vector<StyledMarkedText> StyledMarkedText::coalesceAdjacentWithEqualForeground(const Vector<StyledMarkedText>& markedTexts)
+{
+    return coalesceAdjacent(markedTexts, [&](auto& a, auto& b) {
+        return a.textStyles == b.textStyles && a.textShadow == b.textShadow && a.alpha == b.alpha;
+    });
+}
+
+Vector<StyledMarkedText> StyledMarkedText::coalesceAdjacentWithEqualDecorations(const Vector<StyledMarkedText>& markedTexts)
+{
+    return coalesceAdjacent(markedTexts, [&](auto& a, auto& b) {
+        return a.textDecorationStyles == b.textDecorationStyles && a.textShadow == b.textShadow && a.alpha == b.alpha;
+    });
+}
+
+}

Copied: trunk/Source/WebCore/rendering/StyledMarkedText.h (from rev 281239, trunk/Source/WebCore/rendering/MarkedTextStyle.h) (0 => 281240)


--- trunk/Source/WebCore/rendering/StyledMarkedText.h	                        (rev 0)
+++ trunk/Source/WebCore/rendering/StyledMarkedText.h	2021-08-19 16:05:09 UTC (rev 281240)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "MarkedText.h"
+#include "ShadowData.h"
+#include "TextDecorationPainter.h"
+#include "TextPaintStyle.h"
+
+namespace WebCore {
+
+class RenderText;
+class RenderedDocumentMarker;
+
+struct StyledMarkedText : MarkedText {
+    StyledMarkedText(const MarkedText& marker)
+        : MarkedText { marker }
+    {
+    }
+
+    struct Style {
+        Color backgroundColor;
+        TextPaintStyle textStyles;
+        TextDecorationPainter::Styles textDecorationStyles;
+        std::optional<ShadowData> textShadow;
+        float alpha;
+    };
+
+    Style style;
+
+    static Vector<StyledMarkedText> subdivideAndResolve(const Vector<MarkedText>&, const RenderText&, bool isFirstLine, const PaintInfo&);
+    static Vector<StyledMarkedText> coalesceAdjacentWithEqualBackground(const Vector<StyledMarkedText>&);
+    static Vector<StyledMarkedText> coalesceAdjacentWithEqualForeground(const Vector<StyledMarkedText>&);
+    static Vector<StyledMarkedText> coalesceAdjacentWithEqualDecorations(const Vector<StyledMarkedText>&);
+};
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to