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
--- 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.
*/