Bug 1343037 part 15. Implement nsTextEditorState::GetSelectionDirection. r=ehsan
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 Mar 2017 14:44:06 -0500
changeset 397589 6628ee6c224890bb4d4f411ab00d9336544476e5
parent 397588 2ed58ad7b2d59e3e100858764c884f92b004e3c6
child 397590 b7c1dd9a7a13f2d7b7095ac3d963393ecfbf4fa0
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
@@ -6514,47 +6514,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) {