Bug 1342197 part 2. Use nsITextControlElement::GetRootEditorNode to get the root editor node in nsTextControlFrame::GetSelectionRange. r=ehsan
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 28 Feb 2017 12:41:37 -0500
changeset 374274 c52653ed3dd7643c6ffa2133861a2fa96790bcbb
parent 374273 2e7d6509b02a5aa39870f8a4a898628c4375e231
child 374275 31bc78fa4886aaa8f4d8d1e373a9e2e8f36462f5
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1342197
milestone54.0a1
Bug 1342197 part 2. Use nsITextControlElement::GetRootEditorNode to get the root editor node in nsTextControlFrame::GetSelectionRange. r=ehsan MozReview-Commit-ID: 7ncJVNVGF78
layout/forms/nsTextControlFrame.cpp
layout/forms/nsTextControlFrame.h
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -798,25 +798,16 @@ nsTextControlFrame::ScrollSelectionIntoV
     return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
                                            nsISelectionController::SELECTION_FOCUS_REGION,
                                            nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY);
   }
 
   return NS_ERROR_FAILURE;
 }
 
-mozilla::dom::Element*
-nsTextControlFrame::GetRootNodeAndInitializeEditor()
-{
-  nsCOMPtr<nsIDOMElement> root;
-  GetRootNodeAndInitializeEditor(getter_AddRefs(root));
-  nsCOMPtr<mozilla::dom::Element> rootElem = do_QueryInterface(root);
-  return rootElem;
-}
-
 nsresult
 nsTextControlFrame::GetRootNodeAndInitializeEditor(nsIDOMElement **aRootElement)
 {
   NS_ENSURE_ARG_POINTER(aRootElement);
 
   nsCOMPtr<nsIEditor> editor;
   GetEditor(getter_AddRefs(editor));
   if (!editor)
@@ -1057,17 +1048,17 @@ nsTextControlFrame::GetSelectionRange(in
       NS_NOTREACHED("Invalid nsDirection enum value");
     }
   }
 
   if (!aSelectionStart || !aSelectionEnd) {
     return NS_OK;
   }
 
-  mozilla::dom::Element* root = GetRootNodeAndInitializeEditor();
+  mozilla::dom::Element* root = txtCtrl->GetRootEditorNode();
   NS_ENSURE_STATE(root);
   nsContentUtils::GetSelectionInTextControl(sel, root,
                                             *aSelectionStart, *aSelectionEnd);
 
   return NS_OK;
 }
 
 /////END INTERFACE IMPLEMENTATIONS
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -316,19 +316,23 @@ private:
   nsresult SetSelectionInternal(nsIDOMNode *aStartNode, int32_t aStartOffset,
                                 nsIDOMNode *aEndNode, int32_t aEndOffset,
                                 SelectionDirection aDirection = eNone);
   nsresult SelectAllOrCollapseToEndOfText(bool aSelect);
   nsresult SetSelectionEndPoints(int32_t aSelStart, int32_t aSelEnd,
                                  SelectionDirection aDirection = eNone);
 
   /**
-   * Return the root DOM element, and implicitly initialize the editor if needed.
+   * Return the root DOM element, and implicitly initialize the editor if
+   * needed.
+   *
+   * XXXbz This function is slow.  Very slow.  Consider using
+   * EnsureEditorInitialized() if you need that, and
+   * nsITextControlElement::GetRootEditorNode on our content if you need that.
    */
-  mozilla::dom::Element* GetRootNodeAndInitializeEditor();
   nsresult GetRootNodeAndInitializeEditor(nsIDOMElement **aRootElement);
 
   void FinishedInitializer() {
     Properties().Delete(TextControlInitializer());
   }
 
 private:
   // Our first baseline, or NS_INTRINSIC_WIDTH_UNKNOWN if we have a pending