setSelectionRange shouldn't directly instantiate VisibleSelection
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Feb 2014 22:00:21 +0000 (22:00 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Feb 2014 22:00:21 +0000 (22:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128881

Reviewed by Andreas Kling.

Added a new version of moveTo for setSelectionRange.

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::moveTo): Added.
* editing/FrameSelection.h:
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::setSelectionRange): Use the newly added FrameSelection::moveTo
instead of manually instantiating VisibleSelection here.

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

Source/WebCore/ChangeLog
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/FrameSelection.h
Source/WebCore/html/HTMLTextFormControlElement.cpp

index b9ddac87f073173aa4e11c0a042e9daa640999b0..ec8160faea38b40ee1d1ab5519eab6cd42f31213 100644 (file)
@@ -1,3 +1,19 @@
+2014-02-16  Ryosuke Niwa  <rniwa@webkit.org>
+
+        setSelectionRange shouldn't directly instantiate VisibleSelection
+        https://bugs.webkit.org/show_bug.cgi?id=128881
+
+        Reviewed by Andreas Kling.
+
+        Added a new version of moveTo for setSelectionRange.
+
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::moveTo): Added.
+        * editing/FrameSelection.h:
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::setSelectionRange): Use the newly added FrameSelection::moveTo
+        instead of manually instantiating VisibleSelection here.
+
 2014-02-16  Dan Bernstein  <mitz@apple.com>
 
         Stop using PLATFORM(MAC) in Source except where it means “OS X but not iOS”
index 6e4b631df639d5df3447ae4eb27d23d0847b0b4f..3f0a97787e2be9c9ea68fbd245fb83eaa9e58af7 100644 (file)
@@ -164,6 +164,12 @@ void FrameSelection::moveTo(const Position &base, const Position &extent, EAffin
     setSelection(VisibleSelection(base, extent, affinity, selectionHasDirection), defaultSetSelectionOptions(userTriggered));
 }
 
+void FrameSelection::moveTo(const Position& base, const Position& extent, bool selectionHasDirection, bool shouldSetFocus)
+{
+    setSelection(VisibleSelection(base, extent, DOWNSTREAM, selectionHasDirection),
+        defaultSetSelectionOptions() | (shouldSetFocus ? 0 : DoNotSetFocus));
+}
+
 void DragCaretController::setCaretPosition(const VisiblePosition& position)
 {
     if (Node* node = m_position.deepEquivalent().deprecatedNode())
index d84b70226820bfb85bfc0360212f268fe3baf614..a315edb32d5f8fa10facf661b4d231fcd7883bb8 100644 (file)
@@ -140,6 +140,7 @@ public:
     void moveTo(const VisiblePosition&, const VisiblePosition&, EUserTriggered = NotUserTriggered);
     void moveTo(const Position&, EAffinity, EUserTriggered = NotUserTriggered);
     void moveTo(const Position&, const Position&, EAffinity, EUserTriggered = NotUserTriggered);
+    void moveTo(const Position&, const Position&, bool selectionHasDirection, bool shouldSetFocus);
 
     const VisibleSelection& selection() const { return m_selection; }
     void setSelection(const VisibleSelection&, SetSelectionOptions = defaultSetSelectionOptions(), CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity);
index 6fdac933d21d984f69c98db12767c2d3ca0c8c65..fe53c3ae087363a9ba5305623498cd995e7f9354 100644 (file)
@@ -306,21 +306,16 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField
     Position endPosition;
     if (start == end)
         endPosition = startPosition;
-    else
-        endPosition = positionForIndex(innerText, end);
-
-    VisibleSelection newSelection;
-    if (direction == SelectionHasBackwardDirection)
-        newSelection = VisibleSelection(endPosition, startPosition);
-    else
-        newSelection = VisibleSelection(startPosition, endPosition);
-    newSelection.setIsDirectional(direction != SelectionHasNoDirection);
+    else {
+        if (direction == SelectionHasBackwardDirection) {
+            endPosition = startPosition;
+            startPosition = positionForIndex(innerText, end);
+        } else
+            endPosition = positionForIndex(innerText, end);
+    }
 
-    FrameSelection::SetSelectionOptions options = FrameSelection::defaultSetSelectionOptions();
-    if (hasFocus)
-        options |= FrameSelection::DoNotSetFocus;
     if (Frame* frame = document().frame())
-        frame->selection().setSelection(newSelection, options);
+        frame->selection().moveTo(startPosition, endPosition, direction != SelectionHasNoDirection, !hasFocus);
 }
 
 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& position) const