Bug 1371170 - Add non-virtual EditorBase::GetSelectionController. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 08 Jun 2017 13:58:09 +0900
changeset 411033 41ba10aad446166d6c4263432150d9184e6d1ee7
parent 411032 3e11df0da1c8bcbc3ea210d6ef2784795ea65ca7
child 411034 f223e1fd2044a026c740434df95f37a7f7accf48
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1371170
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 1371170 - Add non-virtual EditorBase::GetSelectionController. r=masayuki GetSelectionController is virtual method, but we should have non-virtual version of GetSelectionController that return value is nsISelectionController since we have a lot of call of GetSelection(). MozReview-Commit-ID: 41JFqTyIh0b
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -612,28 +612,35 @@ EditorBase::SetContentsMIMEType(const ch
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::GetSelectionController(nsISelectionController** aSel)
 {
   NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
   *aSel = nullptr; // init out param
+  nsCOMPtr<nsISelectionController> selCon = GetSelectionController();
+  if (NS_WARN_IF(!selCon)) {
+    return NS_ERROR_NOT_INITIALIZED;
+  }
+  selCon.forget(aSel);
+  return NS_OK;
+}
+
+already_AddRefed<nsISelectionController>
+EditorBase::GetSelectionController()
+{
   nsCOMPtr<nsISelectionController> selCon;
   if (mSelConWeak) {
     selCon = do_QueryReferent(mSelConWeak);
   } else {
     nsCOMPtr<nsIPresShell> presShell = GetPresShell();
     selCon = do_QueryInterface(presShell);
   }
-  if (!selCon) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-  NS_ADDREF(*aSel = selCon);
-  return NS_OK;
+  return selCon.forget();
 }
 
 NS_IMETHODIMP
 EditorBase::DeleteSelection(EDirection aAction,
                             EStripWrappers aStripWrappers)
 {
   MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
   return DeleteSelectionImpl(aAction, aStripWrappers);
@@ -646,18 +653,17 @@ EditorBase::GetSelection(nsISelection** 
 }
 
 nsresult
 EditorBase::GetSelection(SelectionType aSelectionType,
                          nsISelection** aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   *aSelection = nullptr;
-  nsCOMPtr<nsISelectionController> selcon;
-  GetSelectionController(getter_AddRefs(selcon));
+  nsCOMPtr<nsISelectionController> selcon = GetSelectionController();
   if (!selcon) {
     return NS_ERROR_NOT_INITIALIZED;
   }
   return selcon->GetSelection(ToRawSelectionType(aSelectionType), aSelection);
 }
 
 Selection*
 EditorBase::GetSelection(SelectionType aSelectionType)
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -488,16 +488,17 @@ protected:
    * the event comes to the editor.
    *
    * @return            true if there is a composition.  Otherwise, for example,
    *                    a composition event handler in web contents moved focus
    *                    for committing the composition, returns false.
    */
   bool EnsureComposition(WidgetCompositionEvent* aCompositionEvent);
 
+  already_AddRefed<nsISelectionController> GetSelectionController();
   nsresult GetSelection(SelectionType aSelectionType,
                         nsISelection** aSelection);
 
 public:
   /**
    * All editor operations which alter the doc should be prefaced
    * with a call to StartOperation, naming the action and direction.
    */