Cleanup: Use OptionSet to represent marker types
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jul 2017 02:43:07 +0000 (02:43 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jul 2017 02:43:07 +0000 (02:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174594

Reviewed by Darin Adler.

Remove class DocumentMarker::MarkerTypes that duplicates most of functionality of OptionSet
and use OptionSet directly to represent a set of marker types.

No functionality changed. So, no new tests.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::updateLayout):
* dom/DocumentMarker.h:
(WebCore::DocumentMarker::MarkerTypes::MarkerTypes): Deleted.
(WebCore::DocumentMarker::MarkerTypes::contains): Deleted.
(WebCore::DocumentMarker::MarkerTypes::intersects): Deleted.
(WebCore::DocumentMarker::MarkerTypes::operator==): Deleted.
(WebCore::DocumentMarker::MarkerTypes::add): Deleted.
(WebCore::DocumentMarker::MarkerTypes::remove): Deleted.
(WebCore::DocumentMarker::AllMarkers::AllMarkers): Deleted.
* dom/DocumentMarkerController.cpp:
(WebCore::DocumentMarkerController::possiblyHasMarkers):
(WebCore::DocumentMarkerController::detach):
(WebCore::DocumentMarkerController::removeMarkers):
(WebCore::DocumentMarkerController::addMarker):
(WebCore::DocumentMarkerController::copyMarkers):
(WebCore::DocumentMarkerController::markersFor):
(WebCore::DocumentMarkerController::markersInRange):
(WebCore::DocumentMarkerController::removeMarkersFromList):
(WebCore::DocumentMarkerController::repaintMarkers):
(WebCore::DocumentMarkerController::shiftMarkers):
(DocumentMarkerController::setMarkersActive):
(DocumentMarkerController::hasMarkers):
(DocumentMarkerController::clearDescriptionOnMarkersIntersectingRange):
Update code as needed.

* dom/DocumentMarkerController.h:
(WebCore::DocumentMarkerController::hasMarkers):
Update code as needed.

* editing/AlternativeTextController.cpp:
(WebCore::markerTypesForAutocorrection):
(WebCore::markerTypesForReplacement):
(WebCore::markerTypesForAppliedDictationAlternative):
Marked as inline and returns an OptionSet<DocumentMarker::MarkerType>. It is unnecessary to use NeverDestroyed
in these functions as constructing an OptionSet and copying/moving it is very efficient. Such operations are
effectively equivalent to an integral assignment and copy of an integral value, respectively.

(WebCore::AlternativeTextController::applyAlternativeTextToRange):
(WebCore::AlternativeTextController::respondToUnappliedSpellCorrection):
(WebCore::AlternativeTextController::markCorrection):
Update code as needed.

* editing/AlternativeTextController.h: While I am here, remove some unnecessary #includes and group
forward declarations of structs.
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers): Update code as needed.
* editing/Editor.cpp:
(WebCore::Editor::updateMarkersForWordsAffectedByEditing): Ditto.
* editing/SpellChecker.cpp:
(WebCore::SpellChecker::didCheckSucceed): Ditto.
* page/ios/FrameIOS.mm:
(WebCore::Frame::interpretationsForCurrentRoot): Ditto.
* testing/Internals.cpp:
(WebCore::markerTypesFrom): Ditto.
(WebCore::Internals::markerCountForNode): Ditto.
(WebCore::Internals::markerAt): Ditto.

Source/WebKitLegacy/ios:

* WebCoreSupport/WebVisiblePosition.mm:
(-[WebVisiblePosition enclosingRangeWithDictationPhraseAlternatives:]): Update code as needed.
(-[WebVisiblePosition enclosingRangeWithCorrectionIndicator]): Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@219597 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/DocumentMarker.h
Source/WebCore/dom/DocumentMarkerController.cpp
Source/WebCore/dom/DocumentMarkerController.h
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/AlternativeTextController.h
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/SpellChecker.cpp
Source/WebCore/page/ios/FrameIOS.mm
Source/WebCore/testing/Internals.cpp
Source/WebKitLegacy/ios/ChangeLog
Source/WebKitLegacy/ios/WebCoreSupport/WebVisiblePosition.mm

index be74c23..3e78690 100644 (file)
@@ -1,3 +1,73 @@
+2017-07-17  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: Use OptionSet to represent marker types
+        https://bugs.webkit.org/show_bug.cgi?id=174594
+
+        Reviewed by Darin Adler.
+
+        Remove class DocumentMarker::MarkerTypes that duplicates most of functionality of OptionSet
+        and use OptionSet directly to represent a set of marker types.
+
+        No functionality changed. So, no new tests.
+
+        * dom/Document.cpp:
+        (WebCore::Document::updateLayout):
+        * dom/DocumentMarker.h:
+        (WebCore::DocumentMarker::MarkerTypes::MarkerTypes): Deleted.
+        (WebCore::DocumentMarker::MarkerTypes::contains): Deleted.
+        (WebCore::DocumentMarker::MarkerTypes::intersects): Deleted.
+        (WebCore::DocumentMarker::MarkerTypes::operator==): Deleted.
+        (WebCore::DocumentMarker::MarkerTypes::add): Deleted.
+        (WebCore::DocumentMarker::MarkerTypes::remove): Deleted.
+        (WebCore::DocumentMarker::AllMarkers::AllMarkers): Deleted.
+        * dom/DocumentMarkerController.cpp:
+        (WebCore::DocumentMarkerController::possiblyHasMarkers):
+        (WebCore::DocumentMarkerController::detach):
+        (WebCore::DocumentMarkerController::removeMarkers):
+        (WebCore::DocumentMarkerController::addMarker):
+        (WebCore::DocumentMarkerController::copyMarkers):
+        (WebCore::DocumentMarkerController::markersFor):
+        (WebCore::DocumentMarkerController::markersInRange):
+        (WebCore::DocumentMarkerController::removeMarkersFromList):
+        (WebCore::DocumentMarkerController::repaintMarkers):
+        (WebCore::DocumentMarkerController::shiftMarkers):
+        (DocumentMarkerController::setMarkersActive):
+        (DocumentMarkerController::hasMarkers):
+        (DocumentMarkerController::clearDescriptionOnMarkersIntersectingRange):
+        Update code as needed.
+
+        * dom/DocumentMarkerController.h:
+        (WebCore::DocumentMarkerController::hasMarkers):
+        Update code as needed.
+
+        * editing/AlternativeTextController.cpp:
+        (WebCore::markerTypesForAutocorrection):
+        (WebCore::markerTypesForReplacement):
+        (WebCore::markerTypesForAppliedDictationAlternative):
+        Marked as inline and returns an OptionSet<DocumentMarker::MarkerType>. It is unnecessary to use NeverDestroyed
+        in these functions as constructing an OptionSet and copying/moving it is very efficient. Such operations are
+        effectively equivalent to an integral assignment and copy of an integral value, respectively.
+
+        (WebCore::AlternativeTextController::applyAlternativeTextToRange):
+        (WebCore::AlternativeTextController::respondToUnappliedSpellCorrection):
+        (WebCore::AlternativeTextController::markCorrection):
+        Update code as needed.
+
+        * editing/AlternativeTextController.h: While I am here, remove some unnecessary #includes and group
+        forward declarations of structs.
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers): Update code as needed.
+        * editing/Editor.cpp:
+        (WebCore::Editor::updateMarkersForWordsAffectedByEditing): Ditto.
+        * editing/SpellChecker.cpp:
+        (WebCore::SpellChecker::didCheckSucceed): Ditto.
+        * page/ios/FrameIOS.mm:
+        (WebCore::Frame::interpretationsForCurrentRoot): Ditto.
+        * testing/Internals.cpp:
+        (WebCore::markerTypesFrom): Ditto.
+        (WebCore::Internals::markerCountForNode): Ditto.
+        (WebCore::Internals::markerAt): Ditto.
+
 2017-07-17  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: overlay page highlight doesn't disappear when a page is constantly updating
index 01ea049..3ef6319 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -23,6 +23,7 @@
 #include "Node.h"
 
 #include <wtf/Forward.h>
+#include <wtf/OptionSet.h>
 #include <wtf/Variant.h>
 #include <wtf/text/WTFString.h>
 
@@ -81,49 +82,7 @@ public:
         DraggedContent = 1 << 14
     };
 
-    class MarkerTypes {
-    public:
-        // This constructor is left implicit to allow conversion from result of a bit-wise or of enumeration values.
-        MarkerTypes(unsigned mask) : m_mask(mask) { }
-
-        bool contains(MarkerType type) const { return m_mask & type; }
-        bool intersects(MarkerTypes types) const { return m_mask & types.m_mask; }
-        bool operator==(MarkerTypes other) const { return m_mask == other.m_mask; }
-
-        void add(MarkerTypes types) { m_mask |= types.m_mask; }
-        void remove(MarkerTypes types) { m_mask &= ~types.m_mask; }
-
-    private:
-        unsigned m_mask;
-    };
-
-    class AllMarkers : public MarkerTypes {
-    public:
-        AllMarkers()
-            : MarkerTypes(0
-                | AcceptedCandidate
-                | Autocorrected
-                | CorrectionIndicator
-                | DeletedAutocorrection
-                | DictationAlternatives
-                | Grammar
-                | RejectedCorrection
-                | Replacement
-                | SpellCheckingExemption
-                | Spelling
-                | TextMatch
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-                | TelephoneNumber
-#endif
-#if PLATFORM(IOS)
-                | DictationPhraseWithAlternatives
-                | DictationResult
-#endif
-                | DraggedContent
-            )
-        {
-        }
-    };
+    static OptionSet<MarkerType> allMarkers();
 
     using IsActiveMatchData = bool;
     using DescriptionData = String;
@@ -181,6 +140,32 @@ private:
     Data m_data;
 };
 
+inline auto DocumentMarker::allMarkers() -> OptionSet<MarkerType>
+{
+    OptionSet<MarkerType> markers {
+        AcceptedCandidate,
+        Autocorrected,
+        CorrectionIndicator,
+        DeletedAutocorrection,
+        DictationAlternatives,
+        DraggedContent,
+        Grammar,
+        RejectedCorrection,
+        Replacement,
+        SpellCheckingExemption,
+        Spelling,
+        TextMatch,
+#if ENABLE(TELEPHONE_NUMBER_DETECTION)
+        TelephoneNumber,
+#endif
+#if PLATFORM(IOS)
+        DictationPhraseWithAlternatives,
+        DictationResult,
+#endif
+    };
+    return markers;
+}
+
 inline DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, bool isActiveMatch)
     : m_type(TextMatch)
     , m_startOffset(startOffset)
index 165a1d2..914c45b 100644 (file)
@@ -42,9 +42,9 @@
 
 namespace WebCore {
 
-inline bool DocumentMarkerController::possiblyHasMarkers(DocumentMarker::MarkerTypes types)
+inline bool DocumentMarkerController::possiblyHasMarkers(OptionSet<DocumentMarker::MarkerType> types)
 {
-    return m_possiblyExistingMarkerTypes.intersects(types);
+    return m_possiblyExistingMarkerTypes.contains(types);
 }
 
 DocumentMarkerController::DocumentMarkerController(Document& document)
@@ -59,7 +59,7 @@ DocumentMarkerController::~DocumentMarkerController()
 void DocumentMarkerController::detach()
 {
     m_markers.clear();
-    m_possiblyExistingMarkerTypes = 0;
+    m_possiblyExistingMarkerTypes = { };
 }
 
 void DocumentMarkerController::addMarker(Range* range, DocumentMarker::MarkerType type, const String& description)
@@ -144,7 +144,7 @@ void DocumentMarkerController::addDraggedContentMarker(RefPtr<Range> range)
     }
 }
 
-void DocumentMarkerController::removeMarkers(Range* range, DocumentMarker::MarkerTypes markerTypes, RemovePartiallyOverlappingMarkerOrNot shouldRemovePartiallyOverlappingMarker)
+void DocumentMarkerController::removeMarkers(Range* range, OptionSet<DocumentMarker::MarkerType> markerTypes, RemovePartiallyOverlappingMarkerOrNot shouldRemovePartiallyOverlappingMarker)
 {
     for (TextIterator markedText(range); !markedText.atEnd(); markedText.advance()) {
         if (!possiblyHasMarkers(markerTypes))
@@ -333,7 +333,7 @@ void DocumentMarkerController::addMarker(Node* node, const DocumentMarker& newMa
             downcast<RenderBlockFlow>(*renderer).ensureLineBoxes();
     }
 
-    m_possiblyExistingMarkerTypes.add(newMarker.type());
+    m_possiblyExistingMarkerTypes |= newMarker.type();
 
     std::unique_ptr<MarkerList>& list = m_markers.add(node, nullptr).iterator->value;
 
@@ -403,7 +403,7 @@ void DocumentMarkerController::copyMarkers(Node* srcNode, unsigned startOffset,
     if (length <= 0)
         return;
 
-    if (!possiblyHasMarkers(DocumentMarker::AllMarkers()))
+    if (!possiblyHasMarkers(DocumentMarker::allMarkers()))
         return;
     ASSERT(!m_markers.isEmpty());
 
@@ -437,7 +437,7 @@ void DocumentMarkerController::copyMarkers(Node* srcNode, unsigned startOffset,
         dstNode->renderer()->repaint();
 }
 
-void DocumentMarkerController::removeMarkers(Node* node, unsigned startOffset, int length, DocumentMarker::MarkerTypes markerTypes, RemovePartiallyOverlappingMarkerOrNot shouldRemovePartiallyOverlappingMarker)
+void DocumentMarkerController::removeMarkers(Node* node, unsigned startOffset, int length, OptionSet<DocumentMarker::MarkerType> markerTypes, RemovePartiallyOverlappingMarkerOrNot shouldRemovePartiallyOverlappingMarker)
 {
     if (length <= 0)
         return;
@@ -495,7 +495,7 @@ void DocumentMarkerController::removeMarkers(Node* node, unsigned startOffset, i
     if (list->isEmpty()) {
         m_markers.remove(node);
         if (m_markers.isEmpty())
-            m_possiblyExistingMarkerTypes = 0;
+            m_possiblyExistingMarkerTypes = { };
     }
 
     if (docDirty && node->renderer())
@@ -523,7 +523,7 @@ DocumentMarker* DocumentMarkerController::markerContainingPoint(const LayoutPoin
     return nullptr;
 }
 
-Vector<RenderedDocumentMarker*> DocumentMarkerController::markersFor(Node* node, DocumentMarker::MarkerTypes markerTypes)
+Vector<RenderedDocumentMarker*> DocumentMarkerController::markersFor(Node* node, OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return { };
@@ -541,7 +541,7 @@ Vector<RenderedDocumentMarker*> DocumentMarkerController::markersFor(Node* node,
     return result;
 }
 
-Vector<RenderedDocumentMarker*> DocumentMarkerController::markersInRange(Range& range, DocumentMarker::MarkerTypes markerTypes)
+Vector<RenderedDocumentMarker*> DocumentMarkerController::markersInRange(Range& range, OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return Vector<RenderedDocumentMarker*>();
@@ -566,7 +566,7 @@ Vector<RenderedDocumentMarker*> DocumentMarkerController::markersInRange(Range&
     return foundMarkers;
 }
 
-void DocumentMarkerController::removeMarkers(Node* node, DocumentMarker::MarkerTypes markerTypes)
+void DocumentMarkerController::removeMarkers(Node* node, OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return;
@@ -577,7 +577,7 @@ void DocumentMarkerController::removeMarkers(Node* node, DocumentMarker::MarkerT
         removeMarkersFromList(iterator, markerTypes);
 }
 
-void DocumentMarkerController::removeMarkers(DocumentMarker::MarkerTypes markerTypes)
+void DocumentMarkerController::removeMarkers(OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return;
@@ -591,15 +591,15 @@ void DocumentMarkerController::removeMarkers(DocumentMarker::MarkerTypes markerT
             removeMarkersFromList(iterator, markerTypes);
     }
 
-    m_possiblyExistingMarkerTypes.remove(markerTypes);
+    m_possiblyExistingMarkerTypes -= markerTypes;
 }
 
-void DocumentMarkerController::removeMarkersFromList(MarkerMap::iterator iterator, DocumentMarker::MarkerTypes markerTypes)
+void DocumentMarkerController::removeMarkersFromList(MarkerMap::iterator iterator, OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     bool needsRepainting = false;
     bool listCanBeRemoved;
 
-    if (markerTypes == DocumentMarker::AllMarkers()) {
+    if (markerTypes == DocumentMarker::allMarkers()) {
         needsRepainting = true;
         listCanBeRemoved = true;
     } else {
@@ -631,11 +631,11 @@ void DocumentMarkerController::removeMarkersFromList(MarkerMap::iterator iterato
     if (listCanBeRemoved) {
         m_markers.remove(iterator);
         if (m_markers.isEmpty())
-            m_possiblyExistingMarkerTypes = 0;
+            m_possiblyExistingMarkerTypes = { };
     }
 }
 
-void DocumentMarkerController::repaintMarkers(DocumentMarker::MarkerTypes markerTypes)
+void DocumentMarkerController::repaintMarkers(OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return;
@@ -665,7 +665,7 @@ void DocumentMarkerController::repaintMarkers(DocumentMarker::MarkerTypes marker
 
 void DocumentMarkerController::shiftMarkers(Node* node, unsigned startOffset, int delta)
 {
-    if (!possiblyHasMarkers(DocumentMarker::AllMarkers()))
+    if (!possiblyHasMarkers(DocumentMarker::allMarkers()))
         return;
     ASSERT(!m_markers.isEmpty());
 
@@ -716,7 +716,7 @@ void DocumentMarkerController::shiftMarkers(Node* node, unsigned startOffset, in
 
 void DocumentMarkerController::setMarkersActive(Range* range, bool active)
 {
-    if (!possiblyHasMarkers(DocumentMarker::AllMarkers()))
+    if (!possiblyHasMarkers(DocumentMarker::allMarkers()))
         return;
     ASSERT(!m_markers.isEmpty());
 
@@ -756,7 +756,7 @@ void DocumentMarkerController::setMarkersActive(Node* node, unsigned startOffset
         node->renderer()->repaint();
 }
 
-bool DocumentMarkerController::hasMarkers(Range& range, DocumentMarker::MarkerTypes markerTypes)
+bool DocumentMarkerController::hasMarkers(Range& range, OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return false;
@@ -780,7 +780,7 @@ bool DocumentMarkerController::hasMarkers(Range& range, DocumentMarker::MarkerTy
     return false;
 }
 
-void DocumentMarkerController::clearDescriptionOnMarkersIntersectingRange(Range& range, DocumentMarker::MarkerTypes markerTypes)
+void DocumentMarkerController::clearDescriptionOnMarkersIntersectingRange(Range& range, OptionSet<DocumentMarker::MarkerType> markerTypes)
 {
     if (!possiblyHasMarkers(markerTypes))
         return;
index 8deb417..9007a18 100644 (file)
@@ -63,28 +63,28 @@ public:
     void copyMarkers(Node* srcNode, unsigned startOffset, int length, Node* dstNode, int delta);
     bool hasMarkers() const
     {
-        ASSERT(m_markers.isEmpty() == !m_possiblyExistingMarkerTypes.intersects(DocumentMarker::AllMarkers()));
+        ASSERT(m_markers.isEmpty() == !m_possiblyExistingMarkerTypes.contains(DocumentMarker::allMarkers()));
         return !m_markers.isEmpty();
     }
-    bool hasMarkers(Range&, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
+    bool hasMarkers(Range&, OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers());
 
     // When a marker partially overlaps with range, if removePartiallyOverlappingMarkers is true, we completely
     // remove the marker. If the argument is false, we will adjust the span of the marker so that it retains
     // the portion that is outside of the range.
     enum RemovePartiallyOverlappingMarkerOrNot { DoNotRemovePartiallyOverlappingMarker, RemovePartiallyOverlappingMarker };
-    void removeMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker);
-    void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(),  RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker);
+    void removeMarkers(Range*, OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker);
+    void removeMarkers(Node*, unsigned startOffset, int length, OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers(),  RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker);
 
-    WEBCORE_EXPORT void removeMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
-    void removeMarkers(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
-    void repaintMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
+    WEBCORE_EXPORT void removeMarkers(OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers());
+    void removeMarkers(Node*, OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers());
+    void repaintMarkers(OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers());
     void shiftMarkers(Node*, unsigned startOffset, int delta);
     void setMarkersActive(Range*, bool);
     void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
 
-    WEBCORE_EXPORT Vector<RenderedDocumentMarker*> markersFor(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
-    WEBCORE_EXPORT Vector<RenderedDocumentMarker*> markersInRange(Range&, DocumentMarker::MarkerTypes);
-    void clearDescriptionOnMarkersIntersectingRange(Range&, DocumentMarker::MarkerTypes);
+    WEBCORE_EXPORT Vector<RenderedDocumentMarker*> markersFor(Node*, OptionSet<DocumentMarker::MarkerType> = DocumentMarker::allMarkers());
+    WEBCORE_EXPORT Vector<RenderedDocumentMarker*> markersInRange(Range&, OptionSet<DocumentMarker::MarkerType>);
+    void clearDescriptionOnMarkersIntersectingRange(Range&, OptionSet<DocumentMarker::MarkerType>);
 
     WEBCORE_EXPORT void updateRectsForInvalidatedMarkersOfType(DocumentMarker::MarkerType);
 
@@ -103,12 +103,12 @@ private:
 
     typedef Vector<RenderedDocumentMarker> MarkerList;
     typedef HashMap<RefPtr<Node>, std::unique_ptr<MarkerList>> MarkerMap;
-    bool possiblyHasMarkers(DocumentMarker::MarkerTypes);
-    void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
+    bool possiblyHasMarkers(OptionSet<DocumentMarker::MarkerType>);
+    void removeMarkersFromList(MarkerMap::iterator, OptionSet<DocumentMarker::MarkerType>);
 
     MarkerMap m_markers;
     // Provide a quick way to determine whether a particular marker type is absent without going through the map.
-    DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes { 0 };
+    OptionSet<DocumentMarker::MarkerType> m_possiblyExistingMarkerTypes;
     Document& m_document;
 };
 
index f8f2416..821eb85 100644 (file)
@@ -45,7 +45,6 @@
 #include "TextIterator.h"
 #include "VisibleUnits.h"
 #include "markup.h"
-#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
@@ -84,32 +83,19 @@ private:
 
 #if USE(AUTOCORRECTION_PANEL)
 
-static const Vector<DocumentMarker::MarkerType>& markerTypesForAutocorrection()
+static inline OptionSet<DocumentMarker::MarkerType> markerTypesForAutocorrection()
 {
-    static const auto markerTypesForAutoCorrection = makeNeverDestroyed(Vector<DocumentMarker::MarkerType> {
-        DocumentMarker::Autocorrected,
-        DocumentMarker::CorrectionIndicator,
-        DocumentMarker::Replacement,
-        DocumentMarker::SpellCheckingExemption,
-    });
-    return markerTypesForAutoCorrection;
+    return { DocumentMarker::Autocorrected, DocumentMarker::CorrectionIndicator, DocumentMarker::Replacement, DocumentMarker::SpellCheckingExemption };
 }
 
-static const Vector<DocumentMarker::MarkerType>& markerTypesForReplacement()
+static inline OptionSet<DocumentMarker::MarkerType> markerTypesForReplacement()
 {
-    static const auto markerTypesForReplacement = makeNeverDestroyed(Vector<DocumentMarker::MarkerType> {
-        DocumentMarker::Replacement,
-        DocumentMarker::SpellCheckingExemption,
-    });
-    return markerTypesForReplacement;
+    return { DocumentMarker::Replacement, DocumentMarker::SpellCheckingExemption };
 }
 
-static const Vector<DocumentMarker::MarkerType>& markerTypesForAppliedDictationAlternative()
+static inline OptionSet<DocumentMarker::MarkerType> markerTypesForAppliedDictationAlternative()
 {
-    static const auto markerTypesForAppliedDictationAlternative = makeNeverDestroyed(Vector<DocumentMarker::MarkerType> {
-        DocumentMarker::SpellCheckingExemption,
-    });
-    return markerTypesForAppliedDictationAlternative;
+    return DocumentMarker::SpellCheckingExemption;
 }
 
 static bool markersHaveIdenticalDescription(const Vector<RenderedDocumentMarker*>& markers)
@@ -235,7 +221,7 @@ String AlternativeTextController::dismissSoon(ReasonForDismissingAlternativeText
     return String();
 }
 
-void AlternativeTextController::applyAlternativeTextToRange(const Range& range, const String& alternative, AlternativeTextType alternativeType, const Vector<DocumentMarker::MarkerType>& markerTypesToAdd)
+void AlternativeTextController::applyAlternativeTextToRange(const Range& range, const String& alternative, AlternativeTextType alternativeType, OptionSet<DocumentMarker::MarkerType> markerTypesToAdd)
 {
     auto paragraphRangeContainingCorrection = range.cloneRange();
 
@@ -281,7 +267,7 @@ void AlternativeTextController::applyAlternativeTextToRange(const Range& range,
 
     DocumentMarkerController& markers = replacementRange->startContainer().document().markers();
 
-    for (auto& markerType : markerTypesToAdd)
+    for (auto markerType : markerTypesToAdd)
         markers.addMarker(replacementRange.get(), markerType, markerDescriptionForAppliedAlternativeText(alternativeType, markerType));
 }
 
@@ -317,7 +303,7 @@ void AlternativeTextController::respondToUnappliedSpellCorrection(const VisibleS
     RefPtr<Range> range = Range::create(*m_frame.document(), m_frame.selection().selection().start(), m_frame.selection().selection().end());
 
     DocumentMarkerController& markers = m_frame.document()->markers();
-    markers.removeMarkers(range.get(), DocumentMarker::Spelling | DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker);
+    markers.removeMarkers(range.get(), OptionSet<DocumentMarker::MarkerType> { DocumentMarker::Spelling, DocumentMarker::Autocorrected }, DocumentMarkerController::RemovePartiallyOverlappingMarker);
     markers.addMarker(range.get(), DocumentMarker::Replacement);
     markers.addMarker(range.get(), DocumentMarker::SpellCheckingExemption);
 }
@@ -526,7 +512,7 @@ void AlternativeTextController::markReversed(Range& changedRange)
 void AlternativeTextController::markCorrection(Range& replacedRange, const String& replacedString)
 {
     DocumentMarkerController& markers = replacedRange.startContainer().document().markers();
-    for (auto& markerType : markerTypesForAutocorrection()) {
+    for (auto markerType : markerTypesForAutocorrection()) {
         if (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected)
             markers.addMarker(&replacedRange, markerType, replacedString);
         else
index 5f665a8..43dbe68 100644 (file)
 
 #include "AlternativeTextClient.h"
 #include "DocumentMarker.h"
-#include "FrameSelection.h"
 #include "Range.h"
-#include "TextChecking.h"
 #include "Timer.h"
-#include "VisibleSelection.h"
 #include <wtf/Noncopyable.h>
 
 namespace WebCore {
@@ -43,7 +40,10 @@ class EditCommandComposition;
 class Event;
 class Frame;
 class TextCheckerClient;
+class VisibleSelection;
+
 struct DictationAlternative;
+struct TextCheckingResult;
 
 class AlternativeTextDetails : public RefCounted<AlternativeTextDetails> {
 public:
@@ -58,8 +58,6 @@ struct AlternativeTextInfo {
     RefPtr<AlternativeTextDetails> details;
 };
 
-struct TextCheckingResult;
-
 #if USE(AUTOCORRECTION_PANEL)
 // These backslashes are for making style checker happy.
 #define UNLESS_ENABLED(functionBody) \
@@ -117,7 +115,7 @@ public:
 private:
 #if USE(AUTOCORRECTION_PANEL)
     String dismissSoon(ReasonForDismissingAlternativeText);
-    void applyAlternativeTextToRange(const Range&, const String& alternative, AlternativeTextType, const Vector<DocumentMarker::MarkerType>&);
+    void applyAlternativeTextToRange(const Range&, const String& alternative, AlternativeTextType, OptionSet<DocumentMarker::MarkerType>);
     void timerFired();
     void recordSpellcheckerResponseForModifiedCorrection(Range& rangeOfCorrection, const String& corrected, const String& correction);
     String markerDescriptionForAppliedAlternativeText(AlternativeTextType, DocumentMarker::MarkerType);
index 87df516..68574c4 100644 (file)
@@ -766,7 +766,7 @@ void CompositeEditCommand::replaceTextInNodePreservingMarkers(Text& node, unsign
 {
     Ref<Text> protectedNode(node);
     DocumentMarkerController& markerController = document().markers();
-    auto markers = copyMarkers(markerController.markersInRange(Range::create(document(), &node, offset, &node, offset + count), DocumentMarker::AllMarkers()));
+    auto markers = copyMarkers(markerController.markersInRange(Range::create(document(), &node, offset, &node, offset + count), DocumentMarker::allMarkers()));
     replaceTextInNode(node, offset, count, replacementText);
     RefPtr<Range> newRange = Range::create(document(), &node, offset, &node, offset + replacementText.length());
     for (const auto& marker : markers)
index 4f290e2..9ab1372 100644 (file)
@@ -2782,11 +2782,16 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA
     for (auto* marker : markers)
         m_alternativeTextController->removeDictationAlternativesForMarker(*marker);
 
-#if PLATFORM(IOS)
-    document().markers().removeMarkers(wordRange.ptr(), DocumentMarker::Spelling | DocumentMarker::CorrectionIndicator | DocumentMarker::SpellCheckingExemption | DocumentMarker::DictationAlternatives | DocumentMarker::DictationPhraseWithAlternatives, DocumentMarkerController::RemovePartiallyOverlappingMarker);
-#else
-    document().markers().removeMarkers(wordRange.ptr(), DocumentMarker::Spelling | DocumentMarker::Grammar | DocumentMarker::CorrectionIndicator | DocumentMarker::SpellCheckingExemption | DocumentMarker::DictationAlternatives, DocumentMarkerController::RemovePartiallyOverlappingMarker);
+    OptionSet<DocumentMarker::MarkerType> markerTypesToRemove {
+        DocumentMarker::CorrectionIndicator,
+        DocumentMarker::DictationAlternatives,
+        DocumentMarker::SpellCheckingExemption,
+        DocumentMarker::Spelling,
+#if !PLATFORM(IOS)
+        DocumentMarker::Grammar,
 #endif
+    };
+    document().markers().removeMarkers(wordRange.ptr(), markerTypesToRemove, DocumentMarkerController::RemovePartiallyOverlappingMarker);
     document().markers().clearDescriptionOnMarkersIntersectingRange(wordRange, DocumentMarker::Replacement);
 }
 
index 8f3f5eb..a294bb3 100644 (file)
@@ -217,13 +217,13 @@ void SpellChecker::didCheckSucceed(int sequence, const Vector<TextCheckingResult
 {
     TextCheckingRequestData requestData = m_processingRequest->data();
     if (requestData.sequence() == sequence) {
-        unsigned markers = 0;
+        OptionSet<DocumentMarker::MarkerType> markerTypes;
         if (requestData.mask() & TextCheckingTypeSpelling)
-            markers |= DocumentMarker::Spelling;
+            markerTypes |= DocumentMarker::Spelling;
         if (requestData.mask() & TextCheckingTypeGrammar)
-            markers |= DocumentMarker::Grammar;
-        if (markers)
-            m_frame.document()->markers().removeMarkers(&m_processingRequest->checkingRange(), markers);
+            markerTypes |= DocumentMarker::Grammar;
+        if (!markerTypes.isEmpty())
+            m_frame.document()->markers().removeMarkers(&m_processingRequest->checkingRange(), markerTypes);
     }
     didCheck(sequence, results);
 }
index e9d3659..b66387b 100644 (file)
@@ -652,7 +652,7 @@ NSArray *Frame::interpretationsForCurrentRoot() const
 
     Node* pastLastNode = rangeOfRootContents->pastLastNode();
     for (Node* node = rangeOfRootContents->firstNode(); node != pastLastNode; node = NodeTraversal::next(*node)) {
-        for (auto* marker : document()->markers().markersFor(node, DocumentMarker::MarkerTypes(DocumentMarker::DictationPhraseWithAlternatives))) {
+        for (auto* marker : document()->markers().markersFor(node, DocumentMarker::DictationPhraseWithAlternatives)) {
             // First, add text that precede the marker.
             if (precedingTextStartPosition != createLegacyEditingPosition(node, marker->startOffset())) {
                 RefPtr<Range> precedingTextRange = Range::create(*document(), precedingTextStartPosition, createLegacyEditingPosition(node, marker->startOffset()));
index 4fb91cc..31c8fab 100644 (file)
@@ -361,12 +361,12 @@ static bool markerTypeFrom(const String& markerType, DocumentMarker::MarkerType&
     return true;
 }
 
-static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
+static bool markerTypesFrom(const String& markerType, OptionSet<DocumentMarker::MarkerType>& result)
 {
     DocumentMarker::MarkerType singularResult;
 
     if (markerType.isEmpty() || equalLettersIgnoringASCIICase(markerType, "all"))
-        result = DocumentMarker::AllMarkers();
+        result = DocumentMarker::allMarkers();
     else if (markerTypeFrom(markerType, singularResult))
         result = singularResult;
     else
@@ -1391,7 +1391,7 @@ ExceptionOr<String> Internals::inspectorHighlightObject()
 
 ExceptionOr<unsigned> Internals::markerCountForNode(Node& node, const String& markerType)
 {
-    DocumentMarker::MarkerTypes markerTypes = 0;
+    OptionSet<DocumentMarker::MarkerType> markerTypes;
     if (!markerTypesFrom(markerType, markerTypes))
         return Exception { SYNTAX_ERR };
 
@@ -1403,7 +1403,7 @@ ExceptionOr<RenderedDocumentMarker*> Internals::markerAt(Node& node, const Strin
 {
     node.document().updateLayoutIgnorePendingStylesheets();
 
-    DocumentMarker::MarkerTypes markerTypes = 0;
+    OptionSet<DocumentMarker::MarkerType> markerTypes;
     if (!markerTypesFrom(markerType, markerTypes))
         return Exception { SYNTAX_ERR };
 
index 9eb3940..e643226 100644 (file)
@@ -1,3 +1,19 @@
+2017-07-17  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: Use OptionSet to represent marker types
+        https://bugs.webkit.org/show_bug.cgi?id=174594
+
+        Reviewed by Darin Adler.
+
+        Remove class DocumentMarker::MarkerTypes that duplicates most of functionality of OptionSet
+        and use OptionSet directly to represent a set of marker types.
+
+        No functionality changed. So, no new tests.
+
+        * WebCoreSupport/WebVisiblePosition.mm:
+        (-[WebVisiblePosition enclosingRangeWithDictationPhraseAlternatives:]): Update code as needed.
+        (-[WebVisiblePosition enclosingRangeWithCorrectionIndicator]): Ditto.
+
 2017-07-12  Daniel Bates  <dabates@apple.com>
 
         Rename NavigationInitiatedByMainFrame to InitiatedByMainFrame
index 75ce3b7..38163cd 100644 (file)
@@ -423,7 +423,7 @@ static inline SelectionDirection toSelectionDirection(WebTextAdjustmentDirection
     Node* node = p.deepEquivalent().anchorNode();
     Document& document = node->document();
     
-    const auto& markers = document.markers().markersFor(node, DocumentMarker::MarkerTypes(DocumentMarker::DictationPhraseWithAlternatives));
+    const auto& markers = document.markers().markersFor(node, DocumentMarker::DictationPhraseWithAlternatives);
     if (markers.isEmpty())
         return nil;
         
@@ -457,7 +457,7 @@ static inline SelectionDirection toSelectionDirection(WebTextAdjustmentDirection
     Node* node = p.deepEquivalent().anchorNode();
     Document& document = node->document();
     
-    const auto& markers = document.markers().markersFor(node, DocumentMarker::MarkerTypes(DocumentMarker::Spelling));
+    const auto& markers = document.markers().markersFor(node, DocumentMarker::Spelling);
     if (markers.isEmpty())
         return nil;