Bug 1343037 part 15. Implement nsTextEditorState::GetSelectionDirection. r=ehsan
☠☠ backed out by f584babc1167 ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 Mar 2017 14:44:06 -0500
changeset 397300 67d29abbbd53a60e0340ec751ced61a397684229
parent 397299 a6833ad9712f8c132d06ed84979405bb7878f884
child 397301 1d0da4f3c82bcc6a0eeda2c67bbc514d40608821
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1343037
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1343037 part 15. Implement nsTextEditorState::GetSelectionDirection. r=ehsan MozReview-Commit-ID: 1bLLYhjmlff
dom/html/HTMLInputElement.cpp
dom/html/HTMLTextAreaElement.cpp
dom/html/nsTextEditorState.cpp
dom/html/nsTextEditorState.h
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -6492,47 +6492,27 @@ HTMLInputElement::GetSelectionRange(int3
     // Not a text control.
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
 
   state->GetSelectionRange(aSelectionStart, aSelectionEnd, aRv);
 }
 
-static void
-DirectionToName(nsITextControlFrame::SelectionDirection dir, nsAString& aDirection)
-{
-  if (dir == nsITextControlFrame::eNone) {
-    aDirection.AssignLiteral("none");
-  } else if (dir == nsITextControlFrame::eForward) {
-    aDirection.AssignLiteral("forward");
-  } else if (dir == nsITextControlFrame::eBackward) {
-    aDirection.AssignLiteral("backward");
-  } else {
-    NS_NOTREACHED("Invalid SelectionDirection value");
-  }
-}
-
 void
 HTMLInputElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& aRv)
 {
   if (!SupportsTextSelection()) {
     aDirection.SetIsVoid(true);
     return;
   }
 
   nsTextEditorState* state = GetEditorState();
   MOZ_ASSERT(state, "SupportsTextSelection came back true!");
-  nsITextControlFrame::SelectionDirection dir =
-    state->GetSelectionDirection(aRv);
-  if (aRv.Failed()) {
-    return;
-  }
-  
-  DirectionToName(dir, aDirection);
+  state->GetSelectionDirectionString(aDirection, aRv);
 }
 
 void
 HTMLInputElement::SetSelectionDirection(const nsAString& aDirection, ErrorResult& aRv)
 {
   if (!SupportsTextSelection()) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
--- a/dom/html/HTMLTextAreaElement.cpp
+++ b/dom/html/HTMLTextAreaElement.cpp
@@ -731,39 +731,20 @@ HTMLTextAreaElement::SetSelectionEnd(con
 void
 HTMLTextAreaElement::GetSelectionRange(int32_t* aSelectionStart,
                                        int32_t* aSelectionEnd,
                                        ErrorResult& aRv)
 {
   return mState.GetSelectionRange(aSelectionStart, aSelectionEnd, aRv);
 }
 
-static void
-DirectionToName(nsITextControlFrame::SelectionDirection dir, nsAString& aDirection)
-{
-  if (dir == nsITextControlFrame::eNone) {
-    aDirection.AssignLiteral("none");
-  } else if (dir == nsITextControlFrame::eForward) {
-    aDirection.AssignLiteral("forward");
-  } else if (dir == nsITextControlFrame::eBackward) {
-    aDirection.AssignLiteral("backward");
-  } else {
-    NS_NOTREACHED("Invalid SelectionDirection value");
-  }
-}
-
 void
 HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& aError)
 {
-  nsITextControlFrame::SelectionDirection dir =
-    mState.GetSelectionDirection(aError);
-  if (aError.Failed()) {
-    return;
-  }
-  DirectionToName(dir, aDirection);
+  mState.GetSelectionDirectionString(aDirection, aError);
 }
 
 void
 HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection,
                                            ErrorResult& aError)
 {
   mState.SetSelectionDirection(aDirection, aError);
 }
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -1757,16 +1757,42 @@ nsTextEditorState::SetSelectionEnd(const
   nsITextControlFrame::SelectionDirection dir = GetSelectionDirection(aRv);
   if (aRv.Failed()) {
     return;
   }
 
   SetSelectionRange(start, end, dir, aRv);
 }
 
+static void
+DirectionToName(nsITextControlFrame::SelectionDirection dir, nsAString& aDirection)
+{
+  if (dir == nsITextControlFrame::eNone) {
+    NS_WARNING("We don't actually support this... how did we get it?");
+    aDirection.AssignLiteral("none");
+  } else if (dir == nsITextControlFrame::eForward) {
+    aDirection.AssignLiteral("forward");
+  } else if (dir == nsITextControlFrame::eBackward) {
+    aDirection.AssignLiteral("backward");
+  } else {
+    NS_NOTREACHED("Invalid SelectionDirection value");
+  }
+}
+
+void
+nsTextEditorState::GetSelectionDirectionString(nsAString& aDirection,
+                                               ErrorResult& aRv)
+{
+  nsITextControlFrame::SelectionDirection dir = GetSelectionDirection(aRv);
+  if (aRv.Failed()) {
+    return;
+  }
+  DirectionToName(dir, aDirection);
+}
+
 static nsITextControlFrame::SelectionDirection
 DirectionStringToSelectionDirection(const nsAString& aDirection)
 {
   if (aDirection.EqualsLiteral("backward")) {
     return nsITextControlFrame::eBackward;
   }
 
   // We don't support directionless selections.
--- a/dom/html/nsTextEditorState.h
+++ b/dom/html/nsTextEditorState.h
@@ -305,16 +305,22 @@ public:
                          mozilla::ErrorResult& aRv);
 
   // Set the selection end.  This basically implements the
   // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectionend
   // setter.
   void SetSelectionEnd(const mozilla::dom::Nullable<uint32_t>& aEnd,
                        mozilla::ErrorResult& aRv);
 
+  // Get the selection direction as a string.  This implements the
+  // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectiondirection
+  // getter.
+  void GetSelectionDirectionString(nsAString& aDirection,
+                                   mozilla::ErrorResult& aRv);
+
   // Set the selection direction.  This basically implements the
   // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectiondirection
   // setter.
   void SetSelectionDirection(const nsAString& aDirection,
                              mozilla::ErrorResult& aRv);
 
   void UpdateEditableState(bool aNotify) {
     if (mRootNode) {