Split UserTriggered into FireSelectEvent and RevealSelection for selection options
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 21:40:32 +0000 (21:40 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 21:40:32 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128441

Reviewed by Darin Adler.

Split UserTriggered by FireSelectEvent and RevealSelection for selection options.

Also added defaultSetSelectionOptions() to abstract away the default options.

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::respondToUnappliedSpellCorrection):
* editing/Editor.cpp:
(WebCore::Editor::unappliedEditing):
(WebCore::Editor::reappliedEditing):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::moveTo):
(WebCore::FrameSelection::setSelectionByMouseIfDifferent): UserTriggered | DoNotRevealSelection
is replaced by FireSelectEvent.
(WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance): Check options & FireSelectEvent
instead of options & UserTriggered.
(WebCore::FrameSelection::setSelection): Check options & RevealSelection instead of
options & UserTriggered && !(options & DoNotRevealSelection).
(WebCore::FrameSelection::prepareForDestruction):
(WebCore::FrameSelection::setBase):
(WebCore::FrameSelection::setExtent):
(WebCore::FrameSelection::selectAll):
(WebCore::FrameSelection::wordSelectionContainingCaretSelection):
* editing/FrameSelection.h:
(WebCore::FrameSelection::defaultSetSelectionOptions): Added.
* editing/SpellingCorrectionCommand.cpp:
(WebCore::SpellingCorrectionCommand::doApply):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::selectionChanged): Renamed the argument.
* html/HTMLTextFormControlElement.h:

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

Source/WebCore/ChangeLog
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/FrameSelection.h
Source/WebCore/editing/SpellingCorrectionCommand.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.h

index 7e44e0400d0e035dc36c0a1c49dc3696f05a1e44..f7ac2b31f2afedc3019b926032bb505ea12216ea 100644 (file)
@@ -1,3 +1,40 @@
+2014-02-08  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Split UserTriggered into FireSelectEvent and RevealSelection for selection options
+        https://bugs.webkit.org/show_bug.cgi?id=128441
+
+        Reviewed by Darin Adler.
+
+        Split UserTriggered by FireSelectEvent and RevealSelection for selection options.
+
+        Also added defaultSetSelectionOptions() to abstract away the default options.
+
+        * editing/AlternativeTextController.cpp:
+        (WebCore::AlternativeTextController::respondToUnappliedSpellCorrection):
+        * editing/Editor.cpp:
+        (WebCore::Editor::unappliedEditing):
+        (WebCore::Editor::reappliedEditing):
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::moveTo):
+        (WebCore::FrameSelection::setSelectionByMouseIfDifferent): UserTriggered | DoNotRevealSelection
+        is replaced by FireSelectEvent.
+        (WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance): Check options & FireSelectEvent
+        instead of options & UserTriggered.
+        (WebCore::FrameSelection::setSelection): Check options & RevealSelection instead of
+        options & UserTriggered && !(options & DoNotRevealSelection).
+        (WebCore::FrameSelection::prepareForDestruction):
+        (WebCore::FrameSelection::setBase):
+        (WebCore::FrameSelection::setExtent):
+        (WebCore::FrameSelection::selectAll):
+        (WebCore::FrameSelection::wordSelectionContainingCaretSelection):
+        * editing/FrameSelection.h:
+        (WebCore::FrameSelection::defaultSetSelectionOptions): Added.
+        * editing/SpellingCorrectionCommand.cpp:
+        (WebCore::SpellingCorrectionCommand::doApply):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::selectionChanged): Renamed the argument.
+        * html/HTMLTextFormControlElement.h:
+
 2014-02-08  Zan Dobersek  <zdobersek@igalia.com>
 
         Move TreeScope, IdTargetObserverRegistry to std::unique_ptr
index 31ca46ff245c777c4968eab55fac37b64d5eea3f..4ad3dc8ae4d9a6a008a2bf375ce1aa47f70cb727 100644 (file)
@@ -314,7 +314,7 @@ void AlternativeTextController::respondToUnappliedSpellCorrection(const VisibleS
     if (AlternativeTextClient* client = alternativeTextClient())
         client->recordAutocorrectionResponse(AutocorrectionReverted, corrected, correction);
     m_frame.document()->updateLayout();
-    m_frame.selection().setSelection(selectionOfCorrected, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::SpellCorrectionTriggered);
+    m_frame.selection().setSelection(selectionOfCorrected, FrameSelection::defaultSetSelectionOptions() | FrameSelection::SpellCorrectionTriggered);
     RefPtr<Range> range = Range::create(*m_frame.document(), m_frame.selection().selection().start(), m_frame.selection().selection().end());
 
     DocumentMarkerController& markers = m_frame.document()->markers();
index fb7709834215b5cd30fa136fb640beb4ba6bf45f..1ca4f8984f011e52fee4d44acc5e6e6311572159 100644 (file)
@@ -1102,7 +1102,7 @@ void Editor::unappliedEditing(PassRefPtr<EditCommandComposition> cmd)
     document().updateLayout();
 
     VisibleSelection newSelection(cmd->startingSelection());
-    changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);
+    changeSelectionAfterCommand(newSelection, FrameSelection::defaultSetSelectionOptions());
     dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd->endingRootEditableElement());
 
     m_alternativeTextController->respondToUnappliedEditing(cmd.get());
@@ -1118,7 +1118,7 @@ void Editor::reappliedEditing(PassRefPtr<EditCommandComposition> cmd)
     document().updateLayout();
 
     VisibleSelection newSelection(cmd->endingSelection());
-    changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);
+    changeSelectionAfterCommand(newSelection, FrameSelection::defaultSetSelectionOptions());
     dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd->endingRootEditableElement());
 
     m_lastEditCommand = 0;
index b28e7c55e117c604144e733a1bf482a508f1a14b..574cb2dc7db877fcd0403844449ccfa9ca16ba07 100644 (file)
@@ -135,35 +135,31 @@ Element* FrameSelection::rootEditableElementOrDocumentElement() const
 
 void FrameSelection::moveTo(const VisiblePosition &pos, EUserTriggered userTriggered, CursorAlignOnScroll align)
 {
-    SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
-    setSelection(VisibleSelection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity(), m_selection.isDirectional()), options, align);
+    setSelection(VisibleSelection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity(), m_selection.isDirectional()),
+        defaultSetSelectionOptions(userTriggered), align);
 }
 
 void FrameSelection::moveTo(const VisiblePosition &base, const VisiblePosition &extent, EUserTriggered userTriggered)
 {
     const bool selectionHasDirection = true;
-    SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
-    setSelection(VisibleSelection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity(), selectionHasDirection), options);
+    setSelection(VisibleSelection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity(), selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
 void FrameSelection::moveTo(const Position &pos, EAffinity affinity, EUserTriggered userTriggered)
 {
-    SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
-    setSelection(VisibleSelection(pos, affinity, m_selection.isDirectional()), options);
+    setSelection(VisibleSelection(pos, affinity, m_selection.isDirectional()), defaultSetSelectionOptions(userTriggered));
 }
 
 void FrameSelection::moveTo(const Range *r, EAffinity affinity, EUserTriggered userTriggered)
 {
-    SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
     VisibleSelection selection = r ? VisibleSelection(r->startPosition(), r->endPosition(), affinity) : VisibleSelection(Position(), Position(), affinity);
-    setSelection(selection, options);
+    setSelection(selection, defaultSetSelectionOptions(userTriggered));
 }
 
 void FrameSelection::moveTo(const Position &base, const Position &extent, EAffinity affinity, EUserTriggered userTriggered)
 {
     const bool selectionHasDirection = true;
-    SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
-    setSelection(VisibleSelection(base, extent, affinity, selectionHasDirection), options);
+    setSelection(VisibleSelection(base, extent, affinity, selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
 void DragCaretController::setCaretPosition(const VisiblePosition& position)
@@ -247,10 +243,10 @@ void FrameSelection::setSelectionByMouseIfDifferent(const VisibleSelection& pass
     if (m_selection == newSelection || !shouldChangeSelection(newSelection))
         return;
 
-    setSelection(newSelection, UserTriggered | DoNotRevealSelection | CloseTyping | ClearTypingStyle, AlignCursorOnScrollIfNeeded, granularity);
+    setSelection(newSelection, defaultSetSelectionOptions() | FireSelectEvent, AlignCursorOnScrollIfNeeded, granularity);
 }
 
-bool FrameSelection::setSelectionWithoutUpdatingAppearance(const VisibleSelection& newSelectionPossiblyWithoutDirection, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granularity, EUserTriggered userTriggered)
+bool FrameSelection::setSelectionWithoutUpdatingAppearance(const VisibleSelection& newSelectionPossiblyWithoutDirection, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granularity)
 {
     bool closeTyping = options & CloseTyping;
     bool shouldClearTypingStyle = options & ClearTypingStyle;
@@ -297,7 +293,7 @@ bool FrameSelection::setSelectionWithoutUpdatingAppearance(const VisibleSelectio
 
     // Selection offsets should increase when LF is inserted before the caret in InsertLineBreakCommand. See <https://webkit.org/b/56061>.
     if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(newSelection.start()))
-        textControl->selectionChanged(userTriggered == UserTriggered);
+        textControl->selectionChanged(options & FireSelectEvent);
 
     if (oldSelection == newSelection)
         return false;
@@ -319,8 +315,7 @@ bool FrameSelection::setSelectionWithoutUpdatingAppearance(const VisibleSelectio
 
 void FrameSelection::setSelection(const VisibleSelection& selection, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granularity)
 {
-    EUserTriggered userTriggered = selectionOptionsToUserTriggered(options);
-    if (!setSelectionWithoutUpdatingAppearance(selection, options, align, granularity, userTriggered))
+    if (!setSelectionWithoutUpdatingAppearance(selection, options, align, granularity))
         return;
 
 #if ENABLE(TEXT_CARET)
@@ -330,7 +325,7 @@ void FrameSelection::setSelection(const VisibleSelection& selection, SetSelectio
 #endif
     updateAppearance();
 
-    if (userTriggered == UserTriggered && !(options & DoNotRevealSelection)) {
+    if (options & RevealSelection) {
         ScrollAlignment alignment;
 
         if (m_frame->editor().behavior().shouldCenterAlignWhenSelectionIsRevealed())
@@ -1243,8 +1238,7 @@ void FrameSelection::prepareForDestruction()
     if (view)
         view->clearSelection();
 
-    setSelectionWithoutUpdatingAppearance(VisibleSelection(), CloseTyping | ClearTypingStyle,
-        AlignCursorOnScrollIfNeeded, CharacterGranularity, NotUserTriggered);
+    setSelectionWithoutUpdatingAppearance(VisibleSelection(), defaultSetSelectionOptions(), AlignCursorOnScrollIfNeeded, CharacterGranularity);
     m_previousCaretNode.clear();
 }
 
@@ -1267,25 +1261,25 @@ void FrameSelection::setEnd(const VisiblePosition &pos, EUserTriggered trigger)
 void FrameSelection::setBase(const VisiblePosition &pos, EUserTriggered userTriggered)
 {
     const bool selectionHasDirection = true;
-    setSelection(VisibleSelection(pos.deepEquivalent(), m_selection.extent(), pos.affinity(), selectionHasDirection), CloseTyping | ClearTypingStyle | userTriggered);
+    setSelection(VisibleSelection(pos.deepEquivalent(), m_selection.extent(), pos.affinity(), selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
 void FrameSelection::setExtent(const VisiblePosition &pos, EUserTriggered userTriggered)
 {
     const bool selectionHasDirection = true;
-    setSelection(VisibleSelection(m_selection.base(), pos.deepEquivalent(), pos.affinity(), selectionHasDirection), CloseTyping | ClearTypingStyle | userTriggered);
+    setSelection(VisibleSelection(m_selection.base(), pos.deepEquivalent(), pos.affinity(), selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
 void FrameSelection::setBase(const Position &pos, EAffinity affinity, EUserTriggered userTriggered)
 {
     const bool selectionHasDirection = true;
-    setSelection(VisibleSelection(pos, m_selection.extent(), affinity, selectionHasDirection), CloseTyping | ClearTypingStyle | userTriggered);
+    setSelection(VisibleSelection(pos, m_selection.extent(), affinity, selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
 void FrameSelection::setExtent(const Position &pos, EAffinity affinity, EUserTriggered userTriggered)
 {
     const bool selectionHasDirection = true;
-    setSelection(VisibleSelection(m_selection.base(), pos, affinity, selectionHasDirection), CloseTyping | ClearTypingStyle | userTriggered);
+    setSelection(VisibleSelection(m_selection.base(), pos, affinity, selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
 void CaretBase::clearCaretRect()
@@ -1706,7 +1700,7 @@ void FrameSelection::selectAll()
     VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode(root.get()));
 
     if (shouldChangeSelection(newSelection))
-        setSelection(newSelection, UserTriggered | CloseTyping | ClearTypingStyle | DoNotRevealSelection);
+        setSelection(newSelection, defaultSetSelectionOptions() | FireSelectEvent);
 }
 
 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool closeTyping)
@@ -2422,7 +2416,7 @@ VisibleSelection FrameSelection::wordSelectionContainingCaretSelection(const Vis
 
     VisibleSelection newSelection = frameSelection.selection();
     newSelection.expandUsingGranularity(WordGranularity);
-    frameSelection.setSelection(newSelection, CloseTyping | ClearTypingStyle, AlignCursorOnScrollIfNeeded, frameSelection.granularity());
+    frameSelection.setSelection(newSelection, defaultSetSelectionOptions(), AlignCursorOnScrollIfNeeded, frameSelection.granularity());
 
     Position startPos(frameSelection.selection().start());
     Position endPos(frameSelection.selection().end());
index f0417a89414847634145252f5c2380c63c1c120d..16abf5e38066acd3a8609c678105f77306e33bc1 100644 (file)
@@ -118,18 +118,18 @@ public:
     enum CursorAlignOnScroll { AlignCursorOnScrollIfNeeded,
                                AlignCursorOnScrollAlways };
     enum SetSelectionOption {
-        // 1 << 0 is reserved for EUserTriggered
+        FireSelectEvent = 1 << 0,
         CloseTyping = 1 << 1,
         ClearTypingStyle = 1 << 2,
         SpellCorrectionTriggered = 1 << 3,
         DoNotSetFocus = 1 << 4,
         DictationTriggered = 1 << 5,
-        DoNotRevealSelection = 1 << 6,
+        RevealSelection = 1 << 6,
     };
     typedef unsigned SetSelectionOptions; // Union of values in SetSelectionOption and EUserTriggered
-    static inline EUserTriggered selectionOptionsToUserTriggered(SetSelectionOptions options)
+    static inline SetSelectionOptions defaultSetSelectionOptions(EUserTriggered userTriggered = NotUserTriggered)
     {
-        return static_cast<EUserTriggered>(options & UserTriggered);
+        return CloseTyping | ClearTypingStyle | (userTriggered ? (RevealSelection | FireSelectEvent) : 0);
     }
 
     explicit FrameSelection(Frame* = 0);
@@ -143,7 +143,7 @@ public:
     void moveTo(const Position&, const Position&, EAffinity, EUserTriggered = NotUserTriggered);
 
     const VisibleSelection& selection() const { return m_selection; }
-    void setSelection(const VisibleSelection&, SetSelectionOptions = CloseTyping | ClearTypingStyle, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity);
+    void setSelection(const VisibleSelection&, SetSelectionOptions = defaultSetSelectionOptions(), CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity);
     bool setSelectedRange(Range*, EAffinity, bool closeTyping);
     void selectAll();
     void clear();
@@ -279,7 +279,7 @@ public:
 private:
     enum EPositionType { START, END, BASE, EXTENT };
 
-    bool setSelectionWithoutUpdatingAppearance(const VisibleSelection&, SetSelectionOptions, CursorAlignOnScroll, TextGranularity, EUserTriggered);
+    bool setSelectionWithoutUpdatingAppearance(const VisibleSelection&, SetSelectionOptions, CursorAlignOnScroll, TextGranularity);
 
     void respondToNodeModification(Node*, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
     TextDirection directionOfEnclosingBlock();
index c0ba961bd4a4c3cdfcb28f3bed2dfc5aba206d98..943e48357c52e9e96c9a001bff0e70c67a263e15 100644 (file)
@@ -104,7 +104,7 @@ void SpellingCorrectionCommand::doApply()
     if (!fragment)
         return;
 
-    applyCommandToComposite(SetSelectionCommand::create(m_selectionToBeCorrected, FrameSelection::SpellCorrectionTriggered | FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle));
+    applyCommandToComposite(SetSelectionCommand::create(m_selectionToBeCorrected, FrameSelection::defaultSetSelectionOptions() | FrameSelection::SpellCorrectionTriggered));
 #if USE(AUTOCORRECTION_PANEL)
     applyCommandToComposite(SpellingCorrectionRecordUndoCommand::create(document(), m_corrected, m_correction));
 #endif
index 3c20d0e7472e60a43c39bead43114116ac3f9ba3..06b52268422fe799326dfc8091a29c087a490779 100644 (file)
@@ -475,7 +475,7 @@ void HTMLTextFormControlElement::restoreCachedSelection()
     setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSelectionDirection);
 }
 
-void HTMLTextFormControlElement::selectionChanged(bool userTriggered)
+void HTMLTextFormControlElement::selectionChanged(bool shouldFireSelectEvent)
 {
     if (!isTextFormControl())
         return;
@@ -483,9 +483,12 @@ void HTMLTextFormControlElement::selectionChanged(bool userTriggered)
     // FIXME: Don't re-compute selection start and end if this function was called inside setSelectionRange.
     // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus
     cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection());
+    
+    if (!shouldFireSelectEvent)
+        return;
 
     if (Frame* frame = document().frame()) {
-        if (frame->selection().isRange() && userTriggered)
+        if (frame->selection().isRange())
             dispatchEvent(Event::create(eventNames().selectEvent, true, false));
     }
 }
index 976670ad54fe7b4763ebe17eb3386649a39a2143..327cc1a411f3b855487287c3e898b0e264c2436b 100644 (file)
@@ -78,7 +78,7 @@ public:
 
     virtual TextControlInnerTextElement* innerTextElement() const = 0;
 
-    void selectionChanged(bool userTriggered);
+    void selectionChanged(bool shouldFireSelectEvent);
     bool lastChangeWasUserEdit() const;
     void setInnerTextValue(const String&);
     String innerTextValue() const;