haikuwebkit/Source/WebCore/rendering/MarkedText.cpp

265 lines
12 KiB
C++
Raw Permalink Normal View History

Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
/*
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
* Copyright (C) 2017-2021 Apple Inc. All rights reserved.
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
*
* 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"
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
#include "MarkedText.h"
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
#include "Document.h"
#include "DocumentMarkerController.h"
#include "Editor.h"
#include "ElementRuleCollector.h"
Non-unified build fixes, early May 2021 edition https://bugs.webkit.org/show_bug.cgi?id=226763 Unreviewed non-unified build fixes. Source/JavaScriptCore: * bytecode/InlineAccess.h: Add missing forward declaration for the CodeBlock type. * jit/JITInlineCacheGenerator.cpp: Add missing CCallHelpers.h header. * runtime/Intrinsic.h: Add missing <optional> header. * yarr/YarrUnicodeProperties.h: Ditto. Source/WebCore: * css/calc/CSSCalcValue.cpp: Add missing CSSCalcSymbolTable.h header. * layout/formattingContexts/inline/text/TextUtil.h: Add missing forward declaration for InlineTextBox class. * loader/MixedContentChecker.h: Add missing <optional> header. * page/FrameSnapshotting.cpp: Remove unneeded inclusion of DestinationColorSpace.h and wtf/OptionSet.h headers. * page/FrameSnapshotting.h: Add mission DestinationColorSpace.h and wtf/OptionSet.h headers, remove now unneeded wtf/Forward.h heeder and forward declaration for the DestinationColorSpace class. * platform/DateComponents.h: Add missing <optional> header, remove unneeded <limits> header. * platform/Theme.h: Add missin <optional> header. * platform/graphics/HEVCUtilities.h: Ditto. * rendering/HighlightData.h: Add missing forward declaration for the RenderText class. * rendering/MarkedText.cpp: Add missing HighlightData.h header. * rendering/RenderLineBoxList.cpp: Add missing inclusion of the LegacyInlineElementBox.h header. * style/StyleAdjuster.cpp: Add missing ShadowRoot.h header. * svg/SVGToOTFFontConversion.h: Add missing <optional> header. * workers/service/ServiceWorkerClientQueryOptions.h: Ditto. Source/WebKit: * Shared/WebPageNetworkParameters.cpp: Add missing inclusion of the ArgumentCoders.h header. Canonical link: https://commits.webkit.org/238670@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278698 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-10 08:36:18 +00:00
#include "HighlightData.h"
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
#include "HighlightRegister.h"
#include "RenderBoxModelObject.h"
#include "RenderText.h"
#include "RenderedDocumentMarker.h"
#include "RuntimeEnabledFeatures.h"
#include "TextBoxSelectableRange.h"
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
#include <algorithm>
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
#include <wtf/HashSet.h>
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
namespace WebCore {
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
Vector<MarkedText> MarkedText::subdivide(const Vector<MarkedText>& markedTexts, OverlapStrategy overlapStrategy)
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
{
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
if (markedTexts.isEmpty())
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
return { };
struct Offset {
enum Kind { Begin, End };
Kind kind;
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
unsigned value; // Copy of markedText.startOffset/endOffset to avoid the need to branch based on kind.
const MarkedText* markedText;
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
};
// 1. Build table of all offsets.
Vector<Offset> offsets;
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
ASSERT(markedTexts.size() < std::numeric_limits<unsigned>::max() / 2);
unsigned numberOfMarkedTexts = markedTexts.size();
unsigned numberOfOffsets = 2 * numberOfMarkedTexts;
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
offsets.reserveInitialCapacity(numberOfOffsets);
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
for (auto& markedText : markedTexts) {
offsets.uncheckedAppend({ Offset::Begin, markedText.startOffset, &markedText });
offsets.uncheckedAppend({ Offset::End, markedText.endOffset, &markedText });
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
}
// 2. Sort offsets such that begin offsets are in paint order and end offsets are in reverse paint order.
std::sort(offsets.begin(), offsets.end(), [] (const Offset& a, const Offset& b) {
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
return a.value < b.value || (a.value == b.value && a.kind == b.kind && a.kind == Offset::Begin && a.markedText->type < b.markedText->type)
|| (a.value == b.value && a.kind == b.kind && a.kind == Offset::End && a.markedText->type > b.markedText->type);
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
});
// 3. Compute intersection.
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
Vector<MarkedText> result;
result.reserveInitialCapacity(numberOfMarkedTexts);
HashSet<const MarkedText*> processedMarkedTexts;
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
unsigned offsetSoFar = offsets[0].value;
for (unsigned i = 1; i < numberOfOffsets; ++i) {
if (offsets[i].value > offsets[i - 1].value) {
REGRESSION (r226138): Selecting a line that ends with zero-width joiner (ZWJ) may cause text transformation https://bugs.webkit.org/show_bug.cgi?id=181993 <rdar://problem/36421080> Reviewed by David Hyatt. Source/WebCore: Re-implement paint optimization that was inadvertently removed in r226138. This optimization works around an issue where selecting the last printable character in a line that is followed followed by a zero-width joiner transforms the selected character. We need to fix <https://bugs.webkit.org/show_bug.cgi?id=181964> to improve the interaction of selection and zero-width joiner characters. For now, re-implement a paint optimization to perform a single paint operation when the style of the non-selected text is identical to the style of the selected text. Test: fast/text/mac/select-character-before-zero-width-joiner.html * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Add helper functions to determine when marker styles are identical. We make use of these equality functions to coalesce adjacent subranges that have the same visual style and hence reduce the number of drawing commands to paint all the subranges in a line. (WebCore::InlineTextBox::paint): Coalesce subranges before painting. (WebCore::InlineTextBox::subdivideAndResolveStyle): Split out the logic to coalesce subranges with the same style into its own function InlineTextBox::coalesceAdjacentSubranges() and kept this function focused on subdivision and style resolution. Manually compute the frontmost subranges so that we can resolve style for each subrange with respect to the correct base style. Formerly we always resolved style with respect the specified base style. Now we resolve style with respect the previous frontmost subrange to ensure styles cascade as expected. This change causes no visual difference now. Once we implement <https://bugs.webkit.org/show_bug.cgi?id=175784> we will be able to test this change with respect to selection of ::spelling-error/::grammar-error pseudo elements. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Extracted logic from InlineTextBox::subdivideAndResolveStyle(). (WebCore::InlineTextBox::MarkerSubrangeStyle::operator== const): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::operator!= const): Deleted. Comparing MarkerSubrangeStyle objects should be performed using the appropriate are*MarkerSubrangeStylesEqual() non-member function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: (WebCore::subdivide): Remove overlap strategy FrontmostWithLongestEffectiveRange as this strategy is now implemented by InlineTextBox::subdivideAndResolveStyle() and InlineTextBox::coalesceAdjacentSubranges() that compute the set of frontmost subranges and coalesces adjacent subranges with the same style into the longest effective subrange, respectively. Unlike WebCore::subdivide(), InlineTextBox knows what the base style should be for the subranges and can more aggressively coalesce adjacent subranges of different types that have the same visual style. * rendering/MarkerSubrange.h: Tools: Remove unit test for overlap strategy FrontmostWithLongestEffectiveRange as we no longer support this strategy. * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: LayoutTests: Add a Mac-specific test to ensure that selecting the last visible character on a line that ends with a zero-width joiner (ZWJ) does not cause a text transformation of the selected character. We need to fix <https://bugs.webkit.org/show_bug.cgi?id=181964> for this test to pass on Mac. * TestExpectations: Skip the test directory on non-Mac platforms. * fast/text/mac/select-character-before-zero-width-joiner-expected.html: Added. * fast/text/mac/select-character-before-zero-width-joiner.html: Added. * platform/mac/TestExpectations: Mark the test directory as PASS on Mac so that we run all containing tests. Mark the test as ImageOnlyFailure until we fix <https://bugs.webkit.org/show_bug.cgi?id=181964>. Canonical link: https://commits.webkit.org/197885@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227533 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-01-24 19:17:30 +00:00
if (overlapStrategy == OverlapStrategy::Frontmost) {
Remove WTF::Optional synonym for std::optional, using that class template directly instead https://bugs.webkit.org/show_bug.cgi?id=226433 Reviewed by Chris Dumez. Source/JavaScriptCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): Use auto instead of Optional<>. Also use * instead of value() and nest the definition of the local inside an if statement in the case where it's an optional. * inspector/scripts/tests/expected/*: Regenerated these results. Source/WebCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebCore/PAL: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebDriver: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKit: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * Scripts/webkit/tests: Regenerated expected results, by running the command "python Scripts/webkit/messages_unittest.py -r". (How am I supposed to know to do that?) Source/WebKitLegacy/ios: * WebCoreSupport/WebChromeClientIOS.h: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/mac: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/win: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WTF: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * wtf/Optional.h: Remove WTF::Optional. Tools: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Canonical link: https://commits.webkit.org/238290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-30 16:11:40 +00:00
std::optional<unsigned> frontmost;
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
for (unsigned j = 0; j < i; ++j) {
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
if (!processedMarkedTexts.contains(offsets[j].markedText) && (!frontmost || offsets[j].markedText->type > offsets[*frontmost].markedText->type))
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
frontmost = j;
}
REGRESSION (r226138): Selecting a line that ends with zero-width joiner (ZWJ) may cause text transformation https://bugs.webkit.org/show_bug.cgi?id=181993 <rdar://problem/36421080> Reviewed by David Hyatt. Source/WebCore: Re-implement paint optimization that was inadvertently removed in r226138. This optimization works around an issue where selecting the last printable character in a line that is followed followed by a zero-width joiner transforms the selected character. We need to fix <https://bugs.webkit.org/show_bug.cgi?id=181964> to improve the interaction of selection and zero-width joiner characters. For now, re-implement a paint optimization to perform a single paint operation when the style of the non-selected text is identical to the style of the selected text. Test: fast/text/mac/select-character-before-zero-width-joiner.html * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Add helper functions to determine when marker styles are identical. We make use of these equality functions to coalesce adjacent subranges that have the same visual style and hence reduce the number of drawing commands to paint all the subranges in a line. (WebCore::InlineTextBox::paint): Coalesce subranges before painting. (WebCore::InlineTextBox::subdivideAndResolveStyle): Split out the logic to coalesce subranges with the same style into its own function InlineTextBox::coalesceAdjacentSubranges() and kept this function focused on subdivision and style resolution. Manually compute the frontmost subranges so that we can resolve style for each subrange with respect to the correct base style. Formerly we always resolved style with respect the specified base style. Now we resolve style with respect the previous frontmost subrange to ensure styles cascade as expected. This change causes no visual difference now. Once we implement <https://bugs.webkit.org/show_bug.cgi?id=175784> we will be able to test this change with respect to selection of ::spelling-error/::grammar-error pseudo elements. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Extracted logic from InlineTextBox::subdivideAndResolveStyle(). (WebCore::InlineTextBox::MarkerSubrangeStyle::operator== const): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::operator!= const): Deleted. Comparing MarkerSubrangeStyle objects should be performed using the appropriate are*MarkerSubrangeStylesEqual() non-member function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: (WebCore::subdivide): Remove overlap strategy FrontmostWithLongestEffectiveRange as this strategy is now implemented by InlineTextBox::subdivideAndResolveStyle() and InlineTextBox::coalesceAdjacentSubranges() that compute the set of frontmost subranges and coalesces adjacent subranges with the same style into the longest effective subrange, respectively. Unlike WebCore::subdivide(), InlineTextBox knows what the base style should be for the subranges and can more aggressively coalesce adjacent subranges of different types that have the same visual style. * rendering/MarkerSubrange.h: Tools: Remove unit test for overlap strategy FrontmostWithLongestEffectiveRange as we no longer support this strategy. * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: LayoutTests: Add a Mac-specific test to ensure that selecting the last visible character on a line that ends with a zero-width joiner (ZWJ) does not cause a text transformation of the selected character. We need to fix <https://bugs.webkit.org/show_bug.cgi?id=181964> for this test to pass on Mac. * TestExpectations: Skip the test directory on non-Mac platforms. * fast/text/mac/select-character-before-zero-width-joiner-expected.html: Added. * fast/text/mac/select-character-before-zero-width-joiner.html: Added. * platform/mac/TestExpectations: Mark the test directory as PASS on Mac so that we run all containing tests. Mark the test as ImageOnlyFailure until we fix <https://bugs.webkit.org/show_bug.cgi?id=181964>. Canonical link: https://commits.webkit.org/197885@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227533 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-01-24 19:17:30 +00:00
if (frontmost)
Paint highlights specified in CSS Highlight API https://bugs.webkit.org/show_bug.cgi?id=205318 Reviewed by Ryosuke Niwa. LayoutTests/imported/w3c: * web-platform-tests/css/css-highlight-api/highlight-text-across-elements-expected.html: Added. * web-platform-tests/css/css-highlight-api/highlight-text-across-elements.html: Added. * web-platform-tests/css/css-highlight-api/highlight-text-expected.html: Added. * web-platform-tests/css/css-highlight-api/highlight-text.html: Added. Source/WebCore: Render highlights when present, similar to the way we render selection. Tests: imported/w3c/web-platform-tests/css/css-highlight-api/highlight-text-across-elements.html imported/w3c/web-platform-tests/css/css-highlight-api/highlight-text.html * Modules/highlight/HighlightMap.h: (WebCore::HighlightMap::map const): Add a getter for the internal HashMap. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::selectionState): (WebCore::InlineTextBox::verifySelectionState const): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::clampedStartEndForState const): (WebCore::InlineTextBox::selectionStartEnd const): (WebCore::InlineTextBox::highlightStartEnd const): (WebCore::InlineTextBox::resolveStyleForMarkedText): Use the highlight name from the HighlightRangeGroup to obtain the style from the renderer. (WebCore::InlineTextBox::collectMarkedTextsForHighlights const): Render the highlights when painting text. Determine if a highlight is present in the current RenderObject, and add additional MarkedText to be rendered when painting * rendering/InlineTextBox.h: * rendering/MarkedText.cpp: (WebCore::subdivide): * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): Expand MarkedText to take a style name. * rendering/SelectionRangeData.cpp: (WebCore::SelectionRangeData::setContext): (WebCore::SelectionRangeData::selectionStateForRenderer): (WebCore::SelectionRangeData::set): * rendering/SelectionRangeData.h: Leverage SelectionRangeData for highlights. Tools: Expand MarkedText to take a style name. * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (WebCore::operator<<): Canonical link: https://commits.webkit.org/218737@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253857 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-21 01:33:10 +00:00
result.append({ offsetSoFar, offsets[i].value, offsets[*frontmost].markedText->type, offsets[*frontmost].markedText->marker, offsets[*frontmost].markedText->highlightName });
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
} else {
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
// The appended marked texts may not be in paint order. We will fix this up at the end of this function.
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
for (unsigned j = 0; j < i; ++j) {
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
if (!processedMarkedTexts.contains(offsets[j].markedText))
Paint highlights specified in CSS Highlight API https://bugs.webkit.org/show_bug.cgi?id=205318 Reviewed by Ryosuke Niwa. LayoutTests/imported/w3c: * web-platform-tests/css/css-highlight-api/highlight-text-across-elements-expected.html: Added. * web-platform-tests/css/css-highlight-api/highlight-text-across-elements.html: Added. * web-platform-tests/css/css-highlight-api/highlight-text-expected.html: Added. * web-platform-tests/css/css-highlight-api/highlight-text.html: Added. Source/WebCore: Render highlights when present, similar to the way we render selection. Tests: imported/w3c/web-platform-tests/css/css-highlight-api/highlight-text-across-elements.html imported/w3c/web-platform-tests/css/css-highlight-api/highlight-text.html * Modules/highlight/HighlightMap.h: (WebCore::HighlightMap::map const): Add a getter for the internal HashMap. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::selectionState): (WebCore::InlineTextBox::verifySelectionState const): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::clampedStartEndForState const): (WebCore::InlineTextBox::selectionStartEnd const): (WebCore::InlineTextBox::highlightStartEnd const): (WebCore::InlineTextBox::resolveStyleForMarkedText): Use the highlight name from the HighlightRangeGroup to obtain the style from the renderer. (WebCore::InlineTextBox::collectMarkedTextsForHighlights const): Render the highlights when painting text. Determine if a highlight is present in the current RenderObject, and add additional MarkedText to be rendered when painting * rendering/InlineTextBox.h: * rendering/MarkedText.cpp: (WebCore::subdivide): * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): Expand MarkedText to take a style name. * rendering/SelectionRangeData.cpp: (WebCore::SelectionRangeData::setContext): (WebCore::SelectionRangeData::selectionStateForRenderer): (WebCore::SelectionRangeData::set): * rendering/SelectionRangeData.h: Leverage SelectionRangeData for highlights. Tools: Expand MarkedText to take a style name. * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (WebCore::operator<<): Canonical link: https://commits.webkit.org/218737@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253857 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-21 01:33:10 +00:00
result.append({ offsetSoFar, offsets[i].value, offsets[j].markedText->type, offsets[j].markedText->marker, offsets[j].markedText->highlightName });
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
}
}
offsetSoFar = offsets[i].value;
}
if (offsets[i].kind == Offset::End)
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
processedMarkedTexts.add(offsets[i].markedText);
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
}
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
// Fix up; sort the marked texts so that they are in paint order.
if (overlapStrategy == OverlapStrategy::None)
Standardize terminology for marked text https://bugs.webkit.org/show_bug.cgi?id=180999 Reviewed by Zalan Bujtas. The name MarkerSubrange is a misnomer for a data structure that associates a text subrange with a type and optional document marker. In particular, a MarkerSubrange may not always correspond to a document marker. For instance, selected text is represented using a MarkerSubrange that does not have a corresponding document marker. Let's standardize on the phrase "marked text" as the canonical way to describe these tagged text subranges. Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::localSelectionRect const): (WebCore::InlineTextBox::MarkedTextStyle::areBackgroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areForegroundMarkedTextStylesEqual): (WebCore::InlineTextBox::MarkedTextStyle::areDecorationMarkedTextStylesEqual): (WebCore::InlineTextBox::StyledMarkedText::StyledMarkedText): (WebCore::createMarkedTextFromSelectionInBox): (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintPlatformDocumentMarkers): (WebCore::InlineTextBox::paintPlatformDocumentMarker): (WebCore::InlineTextBox::computeStyleForUnmarkedMarkedText const): (WebCore::InlineTextBox::resolveStyleForMarkedText): (WebCore::InlineTextBox::subdivideAndResolveStyle): (WebCore::InlineTextBox::coalesceAdjacentMarkedTexts): (WebCore::InlineTextBox::collectMarkedTextsForDraggedContent): (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkedTextBackground): (WebCore::InlineTextBox::paintMarkedTextForeground): (WebCore::InlineTextBox::paintMarkedTextDecoration): (WebCore::InlineTextBox::paintCompositionBackground): (WebCore::InlineTextBox::MarkerSubrangeStyle::areBackgroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areForegroundMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::MarkerSubrangeStyle::areDecorationMarkerSubrangeStylesEqual): Deleted. (WebCore::InlineTextBox::StyledMarkerSubrange::StyledMarkerSubrange): Deleted. (WebCore::createMarkerSubrangeFromSelectionInBox): Deleted. (WebCore::InlineTextBox::computeStyleForUnmarkedMarkerSubrange const): Deleted. (WebCore::InlineTextBox::resolveStyleForSubrange): Deleted. (WebCore::InlineTextBox::coalesceAdjacentSubranges): Deleted. (WebCore::InlineTextBox::collectSubrangesForDraggedContent): Deleted. (WebCore::InlineTextBox::collectSubrangesForDocumentMarkers): Deleted. (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. (WebCore::InlineTextBox::paintTextSubrangeBackground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeForeground): Deleted. (WebCore::InlineTextBox::paintTextSubrangeDecoration): Deleted. * rendering/InlineTextBox.h: (WebCore::InlineTextBox::paintMarkedTexts): (WebCore::InlineTextBox::paintMarkerSubranges): Deleted. * rendering/MarkedText.cpp: Renamed from Source/WebCore/rendering/MarkerSubrange.cpp. (WebCore::subdivide): * rendering/MarkedText.h: Renamed from Source/WebCore/rendering/MarkerSubrange.h. (WebCore::MarkedText::MarkedText): (WebCore::MarkedText::isEmpty const): (WebCore::MarkedText::operator!= const): (WebCore::MarkedText::operator== const): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: Added. (WebCore::operator<<): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Removed. Canonical link: https://commits.webkit.org/198884@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-27 22:35:47 +00:00
std::sort(result.begin(), result.end(), [] (const MarkedText& a, const MarkedText& b) { return a.startOffset < b.startOffset || (a.startOffset == b.startOffset && a.type < b.type); });
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
return result;
}
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
Vector<MarkedText> MarkedText::collectForHighlights(RenderText& renderer, RenderBoxModelObject& parentRenderer, const TextBoxSelectableRange& selectableRange, PaintPhase phase)
{
Vector<MarkedText> markedTexts;
HighlightData highlightData;
if (RuntimeEnabledFeatures::sharedFeatures().highlightAPIEnabled()) {
auto& parentStyle = parentRenderer.style();
if (auto highlightRegister = renderer.document().highlightRegisterIfExists()) {
for (auto& highlight : highlightRegister->map()) {
auto renderStyle = parentRenderer.getUncachedPseudoStyle({ PseudoId::Highlight, highlight.key }, &parentStyle);
if (!renderStyle)
continue;
if (renderStyle->textDecorationsInEffect().isEmpty() && phase == PaintPhase::Decoration)
continue;
for (auto& rangeData : highlight.value->rangesData()) {
if (!highlightData.setRenderRange(rangeData))
continue;
auto [highlightStart, highlightEnd] = highlightData.rangeForTextBox(renderer, selectableRange);
if (highlightStart < highlightEnd)
markedTexts.append({ highlightStart, highlightEnd, MarkedText::Highlight, nullptr, highlight.key });
}
}
}
}
#if ENABLE(APP_HIGHLIGHTS)
if (auto appHighlightRegister = renderer.document().appHighlightRegisterIfExists()) {
if (appHighlightRegister->highlightsVisibility() == HighlightVisibility::Visible) {
for (auto& highlight : appHighlightRegister->map()) {
for (auto& rangeData : highlight.value->rangesData()) {
if (!highlightData.setRenderRange(rangeData))
continue;
auto [highlightStart, highlightEnd] = highlightData.rangeForTextBox(renderer, selectableRange);
if (highlightStart < highlightEnd)
markedTexts.append({ highlightStart, highlightEnd, MarkedText::AppHighlight });
}
}
}
}
#endif
return markedTexts;
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
}
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
Vector<MarkedText> MarkedText::collectForDocumentMarkers(RenderText& renderer, const TextBoxSelectableRange& selectableRange, PaintPhase phase)
{
if (!renderer.textNode())
return { };
Vector<RenderedDocumentMarker*> markers = renderer.document().markers().markersFor(*renderer.textNode());
auto markedTextTypeForMarkerType = [] (DocumentMarker::MarkerType type) {
switch (type) {
case DocumentMarker::Spelling:
return MarkedText::SpellingError;
case DocumentMarker::Grammar:
return MarkedText::GrammarError;
case DocumentMarker::CorrectionIndicator:
return MarkedText::Correction;
case DocumentMarker::TextMatch:
return MarkedText::TextMatch;
case DocumentMarker::DictationAlternatives:
return MarkedText::DictationAlternatives;
#if PLATFORM(IOS_FAMILY)
case DocumentMarker::DictationPhraseWithAlternatives:
return MarkedText::DictationPhraseWithAlternatives;
#endif
default:
return MarkedText::Unmarked;
}
};
Vector<MarkedText> markedTexts;
markedTexts.reserveInitialCapacity(markers.size());
Spelling and grammar dots should not overlap https://bugs.webkit.org/show_bug.cgi?id=177265 <rdar://problem/34556424> Reviewed by David Hyatt. Source/WebCore: A line may contain both spelling and grammar errors such that these errors overlap. For example, "to mooof or not to mooof.". It is more pleasing aesthetically to paint spelling and grammar dots such that they do not overlap. This also matches AppKit's behavior. A side benefit of this change is that it adds support infrastructure towards implementing the CSS Pseudo-Elements Module Level 4 pseudo elements ::spelling-error and ::grammar-error (see <https://bugs.webkit.org/show_bug.cgi?id=175784>). It will also make it straightforward to add ::inactive-selection and allow us to make ::selection conform to CSS Pseudo-Elements Module Level 4. * CMakeLists.txt: Add file MarkerSubrange.cpp. * WebCore.xcodeproj/project.pbxproj: Add files MarkerSubrange.{cpp, h}. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paintDocumentMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker&. (WebCore::InlineTextBox::paintTextMatchMarker): Modified to take a const MarkerSubrange& instead of a RenderedDocumentMarker& and take a boolean as to whether the text match is active. (WebCore::InlineTextBox::paintDocumentMarkers): Collect the subranges that need to be painted, subdivide them preserving only the frontmost subrange when two or more subranges overlap and paint the resulting subranges. (WebCore::lineStyleForMarkerType): Deleted; converted to a lambda function inlined in paintDocumentMarker() as this is the only place we made use of this function. * rendering/InlineTextBox.h: * rendering/MarkerSubrange.cpp: Added. (WebCore::subdivide): Subdivides the specified list of subranges and returns a list of non-overlapping subranges in paint order. The implementation of subdivide() is derived from an algorithm that Said Abou-Hallawa came up with. * rendering/MarkerSubrange.h: Added. (WebCore::MarkerSubrange::MarkerSubrange): Tools: Add unit tests for the subdivision algorithm. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/MarkerSubrange.cpp: Added. (WebCore::operator<<): (WebCore::operator==): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-20 23:13:27 +00:00
Factor MarkedText collection out of LegacyInlineTextBox https://bugs.webkit.org/show_bug.cgi?id=226731 Reviewed by Sam Weinig. Source/WebCore: Move more code out from the legacy inline classes. * rendering/LegacyInlineTextBox.cpp: (WebCore::LegacyInlineTextBox::paint): (WebCore::LegacyInlineTextBox::hasMarkers const): (WebCore::LegacyInlineTextBox::paintPlatformDocumentMarkers): (WebCore::LegacyInlineTextBox::calculateUnionOfAllDocumentMarkerBounds const): (WebCore::LegacyInlineTextBox::paintMarkedTexts): (WebCore::LegacyInlineTextBox::highlightStartEnd const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDraggedContent): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForDocumentMarkers const): Deleted. (WebCore::LegacyInlineTextBox::collectMarkedTextsForHighlights const): Deleted. * rendering/LegacyInlineTextBox.h: (WebCore::LegacyInlineTextBox::paintMarkedTexts): * rendering/MarkedText.cpp: (WebCore::MarkedText::subdivide): (WebCore::MarkedText::collectForHighlights): (WebCore::MarkedText::collectForDocumentMarkers): (WebCore::MarkedText::collectForDraggedContent): (WebCore::subdivide): Deleted. * rendering/MarkedText.h: (WebCore::MarkedText::operator== const): * rendering/MarkedTextStyle.cpp: (WebCore::subdivideAndResolveStyle): Tools: * TestWebKitAPI/Tests/WebCore/MarkedText.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 18:02:20 +00:00
// Give any document markers that touch this run a chance to draw before the text has been drawn.
// Note end() points at the last char, not one past it like endOffset and ranges do.
for (auto* marker : markers) {
// Collect either the background markers or the foreground markers, but not both
switch (marker->type()) {
case DocumentMarker::Grammar:
case DocumentMarker::Spelling:
case DocumentMarker::CorrectionIndicator:
case DocumentMarker::Replacement:
case DocumentMarker::DictationAlternatives:
#if PLATFORM(IOS_FAMILY)
// FIXME: Remove the PLATFORM(IOS_FAMILY)-guard.
case DocumentMarker::DictationPhraseWithAlternatives:
#endif
if (phase != MarkedText::PaintPhase::Decoration)
continue;
break;
case DocumentMarker::TextMatch:
if (!renderer.frame().editor().markedTextMatchesAreHighlighted())
continue;
if (phase == MarkedText::PaintPhase::Decoration)
continue;
break;
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
case DocumentMarker::TelephoneNumber:
if (!renderer.frame().editor().markedTextMatchesAreHighlighted())
continue;
if (phase != MarkedText::PaintPhase::Background)
continue;
break;
#endif
default:
continue;
}
if (marker->endOffset() <= selectableRange.start) {
// Marker is completely before this run. This might be a marker that sits before the
// first run we draw, or markers that were within runs we skipped due to truncation.
continue;
}
if (marker->startOffset() >= selectableRange.start + selectableRange.length) {
// Marker is completely after this run, bail. A later run will paint it.
break;
}
// Marker intersects this run. Collect it.
switch (marker->type()) {
case DocumentMarker::Spelling:
case DocumentMarker::CorrectionIndicator:
case DocumentMarker::DictationAlternatives:
case DocumentMarker::Grammar:
#if PLATFORM(IOS_FAMILY)
// FIXME: See <rdar://problem/8933352>. Also, remove the PLATFORM(IOS_FAMILY)-guard.
case DocumentMarker::DictationPhraseWithAlternatives:
#endif
case DocumentMarker::TextMatch: {
auto [clampedStart, clampedEnd] = selectableRange.clamp(marker->startOffset(), marker->endOffset());
markedTexts.uncheckedAppend({ clampedStart, clampedEnd, markedTextTypeForMarkerType(marker->type()), marker });
break;
}
case DocumentMarker::Replacement:
break;
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
case DocumentMarker::TelephoneNumber:
break;
#endif
default:
ASSERT_NOT_REACHED();
}
}
return markedTexts;
}
Vector<MarkedText> MarkedText::collectForDraggedContent(RenderText& renderer, const TextBoxSelectableRange& selectableRange)
{
auto draggedContentRanges = renderer.draggedContentRangesBetweenOffsets(selectableRange.start, selectableRange.start + selectableRange.length);
return draggedContentRanges.map([&](const auto& range) -> MarkedText {
return { selectableRange.clamp(range.first), selectableRange.clamp(range.second), MarkedText::DraggedContent };
});
}
}