Cleanup: Remove AlternativeTextInfo and use Variant to represent alternative text...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jul 2017 16:31:46 +0000 (16:31 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jul 2017 16:31:46 +0000 (16:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174604

Reviewed by Darin Adler.

Remove struct AlternativeTextInfo and represent the alternative text info as instance variables
using Variant to hold either an autocorrection replacement string or the alternative dictation
context.

Not functionality changed. So, no new tests.

* editing/AlternativeTextController.cpp: Remove header Event.h as it is ultimately included by TextEvent.h.
(WebCore::AlternativeTextController::show): Update code as needed.
(WebCore::AlternativeTextController::timerFired): Ditto.
(WebCore::AlternativeTextController::alternativeTextClient): Substitute nullptr for 0.
(WebCore::AlternativeTextController::respondToMarkerAtEndOfWord): Update code as needed.
(WebCore::AutocorrectionAlternativeDetails::create): Deleted.
(WebCore::AutocorrectionAlternativeDetails::replacementString): Deleted.
(WebCore::AutocorrectionAlternativeDetails::AutocorrectionAlternativeDetails): Deleted.
(WebCore::DictationAlternativeDetails::create): Deleted.
(WebCore::DictationAlternativeDetails::dictationContext): Deleted.
(WebCore::DictationAlternativeDetails::DictationAlternativeDetails): Deleted.
* editing/AlternativeTextController.h: Remove header Range.h and forward declare Range. Include header
Position.h and wtf/Variant.h. Sort forward declarations.
(WebCore::AlternativeTextDetails::~AlternativeTextDetails): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/AlternativeTextController.h

index df70830..47d8e4a 100644 (file)
@@ -1,3 +1,31 @@
+2017-07-17  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: Remove AlternativeTextInfo and use Variant to represent alternative text info details
+        https://bugs.webkit.org/show_bug.cgi?id=174604
+
+        Reviewed by Darin Adler.
+
+        Remove struct AlternativeTextInfo and represent the alternative text info as instance variables
+        using Variant to hold either an autocorrection replacement string or the alternative dictation
+        context.
+
+        Not functionality changed. So, no new tests.
+
+        * editing/AlternativeTextController.cpp: Remove header Event.h as it is ultimately included by TextEvent.h.
+        (WebCore::AlternativeTextController::show): Update code as needed.
+        (WebCore::AlternativeTextController::timerFired): Ditto.
+        (WebCore::AlternativeTextController::alternativeTextClient): Substitute nullptr for 0.
+        (WebCore::AlternativeTextController::respondToMarkerAtEndOfWord): Update code as needed.
+        (WebCore::AutocorrectionAlternativeDetails::create): Deleted.
+        (WebCore::AutocorrectionAlternativeDetails::replacementString): Deleted.
+        (WebCore::AutocorrectionAlternativeDetails::AutocorrectionAlternativeDetails): Deleted.
+        (WebCore::DictationAlternativeDetails::create): Deleted.
+        (WebCore::DictationAlternativeDetails::dictationContext): Deleted.
+        (WebCore::DictationAlternativeDetails::DictationAlternativeDetails): Deleted.
+        * editing/AlternativeTextController.h: Remove header Range.h and forward declare Range. Include header
+        Position.h and wtf/Variant.h. Sort forward declarations.
+        (WebCore::AlternativeTextDetails::~AlternativeTextDetails): Deleted.
+
 2017-07-18  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Async image decoding for large images should be disabled after the first time a tile is painted
index 821eb85..2d126c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,6 @@
 #include "Editing.h"
 #include "Editor.h"
 #include "Element.h"
-#include "Event.h"
 #include "FloatQuad.h"
 #include "Frame.h"
 #include "FrameView.h"
 
 namespace WebCore {
 
-class AutocorrectionAlternativeDetails : public AlternativeTextDetails {
-public:
-    static Ref<AutocorrectionAlternativeDetails> create(const String& replacementString)
-    {
-        return adoptRef(*new AutocorrectionAlternativeDetails(replacementString));
-    }
-    
-    const String& replacementString() const { return m_replacementString; }
-private:
-    AutocorrectionAlternativeDetails(const String& replacementString)
-    : m_replacementString(replacementString)
-    { }
-    
-    String m_replacementString;
-};
-
-class DictationAlternativeDetails : public AlternativeTextDetails {
-public:
-    static Ref<DictationAlternativeDetails> create(uint64_t dictationContext)
-    {
-        return adoptRef(*new DictationAlternativeDetails(dictationContext));
-    }
-
-    uint64_t dictationContext() const { return m_dictationContext; }
-
-private:
-    DictationAlternativeDetails(uint64_t dictationContext)
-    : m_dictationContext(dictationContext)
-    { }
-
-    uint64_t m_dictationContext;
-};
-
 #if USE(AUTOCORRECTION_PANEL)
 
 static inline OptionSet<DocumentMarker::MarkerType> markerTypesForAutocorrection()
@@ -186,10 +152,10 @@ void AlternativeTextController::show(Range& rangeToReplace, const String& replac
         return;
     m_alternativeTextInfo.originalText = plainText(&rangeToReplace);
     m_alternativeTextInfo.rangeWithAlternative = &rangeToReplace;
-    m_alternativeTextInfo.details = AutocorrectionAlternativeDetails::create(replacement);
+    m_alternativeTextInfo.details = replacement;
     m_alternativeTextInfo.isActive = true;
     if (AlternativeTextClient* client = alternativeTextClient())
-        client->showCorrectionAlternative(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, replacement, Vector<String>());
+        client->showCorrectionAlternative(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, replacement, { });
 }
 
 void AlternativeTextController::handleCancelOperation()
@@ -321,15 +287,17 @@ void AlternativeTextController::timerFired()
     }
         break;
     case AlternativeTextTypeReversion: {
-        auto* details = static_cast<const AutocorrectionAlternativeDetails*>(m_alternativeTextInfo.details.get());
-        if (!m_alternativeTextInfo.rangeWithAlternative || !details || details->replacementString().isEmpty())
+        if (!m_alternativeTextInfo.rangeWithAlternative)
+            break;
+        String replacementString = WTF::get<AutocorrectionReplacement>(m_alternativeTextInfo.details);
+        if (replacementString.isEmpty())
             break;
         m_alternativeTextInfo.isActive = true;
         m_alternativeTextInfo.originalText = plainText(m_alternativeTextInfo.rangeWithAlternative.get());
         FloatRect boundingBox = rootViewRectForRange(m_alternativeTextInfo.rangeWithAlternative.get());
         if (!boundingBox.isEmpty()) {
             if (AlternativeTextClient* client = alternativeTextClient())
-                client->showCorrectionAlternative(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, details->replacementString(), Vector<String>());
+                client->showCorrectionAlternative(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, replacementString, { });
         }
     }
         break;
@@ -356,15 +324,16 @@ void AlternativeTextController::timerFired()
     case AlternativeTextTypeDictationAlternatives:
     {
 #if USE(DICTATION_ALTERNATIVES)
-        const Range* rangeWithAlternative = m_alternativeTextInfo.rangeWithAlternative.get();
-        const DictationAlternativeDetails* details = static_cast<const DictationAlternativeDetails*>(m_alternativeTextInfo.details.get());
-        if (!rangeWithAlternative || !details || !details->dictationContext())
+        if (!m_alternativeTextInfo.rangeWithAlternative)
+            return;
+        uint64_t dictationContext = WTF::get<AlternativeDictationContext>(m_alternativeTextInfo.details);
+        if (!dictationContext)
             return;
-        FloatRect boundingBox = rootViewRectForRange(rangeWithAlternative);
+        FloatRect boundingBox = rootViewRectForRange(m_alternativeTextInfo.rangeWithAlternative.get());
         m_alternativeTextInfo.isActive = true;
         if (!boundingBox.isEmpty()) {
             if (AlternativeTextClient* client = alternativeTextClient())
-                client->showDictationAlternativeUI(boundingBox, details->dictationContext());
+                client->showDictationAlternativeUI(boundingBox, dictationContext);
         }
 #endif
     }
@@ -482,7 +451,7 @@ void AlternativeTextController::respondToUnappliedEditing(EditCommandComposition
 
 AlternativeTextClient* AlternativeTextController::alternativeTextClient()
 {
-    return m_frame.page() ? m_frame.page()->alternativeTextClient() : 0;
+    return m_frame.page() ? m_frame.page()->alternativeTextClient() : nullptr;
 }
 
 EditorClient* AlternativeTextController::editorClient()
@@ -614,12 +583,12 @@ bool AlternativeTextController::respondToMarkerAtEndOfWord(const DocumentMarker&
     switch (marker.type()) {
     case DocumentMarker::Spelling:
         m_alternativeTextInfo.rangeWithAlternative = wordRange;
-        m_alternativeTextInfo.details = AutocorrectionAlternativeDetails::create(emptyString());
+        m_alternativeTextInfo.details = emptyString();
         startAlternativeTextUITimer(AlternativeTextTypeSpellingSuggestions);
         break;
     case DocumentMarker::Replacement:
         m_alternativeTextInfo.rangeWithAlternative = wordRange;
-        m_alternativeTextInfo.details = AutocorrectionAlternativeDetails::create(marker.description());
+        m_alternativeTextInfo.details = marker.description();
         startAlternativeTextUITimer(AlternativeTextTypeReversion);
         break;
     case DocumentMarker::DictationAlternatives: {
@@ -629,7 +598,7 @@ bool AlternativeTextController::respondToMarkerAtEndOfWord(const DocumentMarker&
         if (currentWord != markerData.originalText)
             return false;
         m_alternativeTextInfo.rangeWithAlternative = wordRange;
-        m_alternativeTextInfo.details = DictationAlternativeDetails::create(markerData.context);
+        m_alternativeTextInfo.details = markerData.context;
         startAlternativeTextUITimer(AlternativeTextTypeDictationAlternatives);
     }
         break;
index 43dbe68..173c909 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #include "AlternativeTextClient.h"
 #include "DocumentMarker.h"
-#include "Range.h"
+#include "Position.h"
 #include "Timer.h"
 #include <wtf/Noncopyable.h>
+#include <wtf/Variant.h>
 
 namespace WebCore {
 
 class CompositeEditCommand;
-class EditorClient;
 class EditCommand;
 class EditCommandComposition;
+class EditorClient;
 class Event;
 class Frame;
+class Range;
 class TextCheckerClient;
 class VisibleSelection;
 
 struct DictationAlternative;
 struct TextCheckingResult;
 
-class AlternativeTextDetails : public RefCounted<AlternativeTextDetails> {
-public:
-    virtual ~AlternativeTextDetails() { }
-};
-
-struct AlternativeTextInfo {
-    RefPtr<Range> rangeWithAlternative;
-    bool isActive;
-    AlternativeTextType type;
-    String originalText;
-    RefPtr<AlternativeTextDetails> details;
-};
-
 #if USE(AUTOCORRECTION_PANEL)
 // These backslashes are for making style checker happy.
 #define UNLESS_ENABLED(functionBody) \
@@ -114,6 +103,17 @@ public:
 
 private:
 #if USE(AUTOCORRECTION_PANEL)
+    using AutocorrectionReplacement = String;
+    using AlternativeDictationContext = uint64_t;
+
+    struct AlternativeTextInfo {
+        RefPtr<Range> rangeWithAlternative;
+        bool isActive;
+        AlternativeTextType type;
+        String originalText;
+        Variant<AutocorrectionReplacement, AlternativeDictationContext> details;
+    };
+
     String dismissSoon(ReasonForDismissingAlternativeText);
     void applyAlternativeTextToRange(const Range&, const String& alternative, AlternativeTextType, OptionSet<DocumentMarker::MarkerType>);
     void timerFired();
@@ -131,8 +131,12 @@ private:
     void markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand*);
 
     Timer m_timer;
-    AlternativeTextInfo m_alternativeTextInfo;
+    RefPtr<Range> m_rangeWithAlternative;
+    bool m_isActive;
     bool m_isDismissedByEditing;
+    AlternativeTextType m_type;
+    String m_originalText;
+    Variant<AutocorrectionReplacement, AlternativeDictationContext> m_details;
 
     String m_originalStringForLastDeletedAutocorrection;
     Position m_positionForLastDeletedAutocorrection;