Bug 1343275 part 1. Get selection faster in some nsTextEditorState methods. r=ehsan
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 Mar 2017 14:44:10 -0500
changeset 397594 5df501fbf40d16cc5a23384e189e7ae12e746ea5
parent 397593 d737e4692b288509f9f95eb98f14402c58247df3
child 397595 5b1392f47637e9c1366c5deb908a3b67f37d6dd7
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
bugs1343275
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 1343275 part 1. Get selection faster in some nsTextEditorState methods. r=ehsan MozReview-Commit-ID: 2v0r3jtua1O
dom/html/nsTextEditorState.cpp
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -219,16 +219,18 @@ public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTextInputSelectionImpl, nsISelectionController)
 
   nsTextInputSelectionImpl(nsFrameSelection *aSel, nsIPresShell *aShell, nsIContent *aLimiter);
 
   void SetScrollableFrame(nsIScrollableFrame *aScrollableFrame);
   nsFrameSelection* GetConstFrameSelection()
     { return mFrameSelection; }
+  // Will return null if !mFrameSelection.
+  Selection* GetSelection(SelectionType aSelectionType);
 
   //NSISELECTIONCONTROLLER INTERFACES
   NS_IMETHOD SetDisplaySelection(int16_t toggle) override;
   NS_IMETHOD GetDisplaySelection(int16_t* _retval) override;
   NS_IMETHOD SetSelectionFlags(int16_t aInEnable) override;
   NS_IMETHOD GetSelectionFlags(int16_t *aOutEnable) override;
   NS_IMETHOD GetSelection(RawSelectionType aRawSelectionType,
                           nsISelection** aSelection) override;
@@ -301,16 +303,26 @@ nsTextInputSelectionImpl::SetScrollableF
 {
   mScrollFrame = aScrollableFrame;
   if (!mScrollFrame && mFrameSelection) {
     mFrameSelection->DisconnectFromPresShell();
     mFrameSelection = nullptr;
   }
 }
 
+Selection*
+nsTextInputSelectionImpl::GetSelection(SelectionType aSelectionType)
+{
+  if (!mFrameSelection) {
+    return nullptr;
+  }
+
+  return mFrameSelection->GetSelection(aSelectionType);
+}
+
 NS_IMETHODIMP
 nsTextInputSelectionImpl::SetDisplaySelection(int16_t aToggle)
 {
   if (!mFrameSelection)
     return NS_ERROR_NULL_POINTER;
   
   mFrameSelection->SetDisplaySelection(aToggle);
   return NS_OK;
@@ -1579,31 +1591,22 @@ nsTextEditorState::GetSelectionRange(int
   // GetSelectionController() if we haven't initialized our editor yet.
   if (IsSelectionCached()) {
     const SelectionProperties& props = GetSelectionProperties();
     *aSelectionStart = props.GetStart();
     *aSelectionEnd = props.GetEnd();
     return;
   }
 
-  nsISelectionController* selCon = GetSelectionController();
-
-  nsCOMPtr<nsISelection> selection;
-  nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                                     getter_AddRefs(selection));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    aRv.Throw(rv);
-    return;
-  }
-  if (NS_WARN_IF(!selection)) {
+  Selection* sel = mSelCon->GetSelection(SelectionType::eNormal);
+  if (NS_WARN_IF(!sel)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
-  dom::Selection* sel = selection->AsSelection();
   mozilla::dom::Element* root = GetRootNode();
   if (NS_WARN_IF(!root)) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
   nsContentUtils::GetSelectionInTextControl(sel, root,
                                             *aSelectionStart, *aSelectionEnd);
 }
@@ -1616,31 +1619,22 @@ nsTextEditorState::GetSelectionDirection
              "controller?");
 
   // Note that we may have both IsSelectionCached() _and_
   // GetSelectionController() if we haven't initialized our editor yet.
   if (IsSelectionCached()) {
     return GetSelectionProperties().GetDirection();
   }
 
-  nsISelectionController* selCon = GetSelectionController();
-
-  nsCOMPtr<nsISelection> selection;
-  nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                                     getter_AddRefs(selection));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    aRv.Throw(rv);
-    return nsITextControlFrame::eForward; // Doesn't really matter
-  }
-  if (NS_WARN_IF(!selection)) {
+  Selection* sel = mSelCon->GetSelection(SelectionType::eNormal);
+  if (NS_WARN_IF(!sel)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nsITextControlFrame::eForward; // Doesn't really matter
   }
 
-  dom::Selection* sel = selection->AsSelection();
   nsDirection direction = sel->GetSelectionDirection();
   if (direction == eDirNext) {
     return nsITextControlFrame::eForward;
   }
 
   MOZ_ASSERT(direction == eDirPrevious);
   return nsITextControlFrame::eBackward;
 }