Bug 1371170 - Add non-virtual EditorBase::GetSelectionController. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 08 Jun 2017 13:58:09 +0900
changeset 590837 87f840ec3c74f72773868e1c1c7f338c48d324ee
parent 590795 7efda263a842e60cd0cc00b3c4a7058c65590702
child 632319 c1dd2418681b967524543a8cdaad959269ada622
push id62843
push userbmo:m_kato@ga2.so-net.ne.jp
push dateThu, 08 Jun 2017 05:12:05 +0000
reviewersmasayuki
bugs1371170
milestone55.0a1
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.
    */