Bug 1391978 - Part 3. Replace nsISelection::GetIsCollapsed with Selection::IsCollapsed. r?masayuki
MozReview-Commit-ID: AYCX9V8smzm
--- a/editor/composer/nsComposerCommandsUpdater.cpp
+++ b/editor/composer/nsComposerCommandsUpdater.cpp
@@ -1,15 +1,16 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/mozalloc.h" // for operator new
+#include "mozilla/dom/Selection.h"
#include "nsAString.h"
#include "nsComponentManagerUtils.h" // for do_CreateInstance
#include "nsComposerCommandsUpdater.h"
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
#include "nsError.h" // for NS_OK, NS_ERROR_FAILURE, etc
#include "nsICommandManager.h" // for nsICommandManager
#include "nsID.h" // for NS_GET_IID, etc
#include "nsIDOMWindow.h" // for nsIDOMWindow
@@ -336,19 +337,17 @@ nsComposerCommandsUpdater::SelectionIsCo
nsCOMPtr<nsPIDOMWindowOuter> domWindow = do_QueryReferent(mDOMWindow);
NS_ENSURE_TRUE(domWindow, true);
nsCOMPtr<nsISelection> domSelection = domWindow->GetSelection();
if (NS_WARN_IF(!domSelection)) {
return false;
}
- bool selectionCollapsed = false;
- domSelection->GetIsCollapsed(&selectionCollapsed);
- return selectionCollapsed;
+ return domSelection->AsSelection()->IsCollapsed();
}
already_AddRefed<nsPICommandUpdater>
nsComposerCommandsUpdater::GetCommandUpdater()
{
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
NS_ENSURE_TRUE(docShell, nullptr);
nsCOMPtr<nsICommandManager> manager = docShell->GetCommandManager();
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -417,20 +417,17 @@ TextEditRules::WillInsertBreak(Selection
if (didTruncate) {
*aCancel = true;
return NS_OK;
}
*aCancel = false;
// if the selection isn't collapsed, delete it.
- bool bCollapsed;
- rv = aSelection->GetIsCollapsed(&bCollapsed);
- NS_ENSURE_SUCCESS(rv, rv);
- if (!bCollapsed) {
+ if (!aSelection->IsCollapsed()) {
NS_ENSURE_STATE(mTextEditor);
rv = mTextEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
NS_ENSURE_SUCCESS(rv, rv);
}
WillInsert(*aSelection, aCancel);
// initialize out param
// we want to ignore result of WillInsert()
@@ -662,20 +659,17 @@ TextEditRules::WillInsertText(EditAction
if (IsPasswordEditor()) {
NS_ENSURE_STATE(mTextEditor);
nsContentUtils::GetSelectionInTextControl(aSelection,
mTextEditor->GetRoot(),
start, end);
}
// if the selection isn't collapsed, delete it.
- bool bCollapsed;
- rv = aSelection->GetIsCollapsed(&bCollapsed);
- NS_ENSURE_SUCCESS(rv, rv);
- if (!bCollapsed) {
+ if (!aSelection->IsCollapsed()) {
NS_ENSURE_STATE(mTextEditor);
rv = mTextEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
NS_ENSURE_SUCCESS(rv, rv);
}
WillInsert(*aSelection, aCancel);
// initialize out param
// we want to ignore result of WillInsert()
@@ -1022,21 +1016,17 @@ TextEditRules::WillDeleteSelection(Selec
nsCOMPtr<nsIDOMNode> startNode;
int32_t startOffset;
nsresult rv =
EditorBase::GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode),
&startOffset);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
- bool bCollapsed;
- rv = aSelection->GetIsCollapsed(&bCollapsed);
- NS_ENSURE_SUCCESS(rv, rv);
-
- if (!bCollapsed) {
+ if (!aSelection->IsCollapsed()) {
return NS_OK;
}
// Test for distance between caret and text that will be deleted
rv = CheckBidiLevelForDeletion(aSelection, startNode, startOffset,
aCollapsedAction, aCancel);
NS_ENSURE_SUCCESS(rv, rv);
if (*aCancel) {
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -490,46 +490,41 @@ nsTextServicesDocument::LastSelectedBloc
*aSelStatus = nsITextServicesDocument::eBlockNotFound;
*aSelOffset = *aSelLength = -1;
if (!mSelCon || !mIterator) {
UNLOCK_DOC(this);
return NS_ERROR_FAILURE;
}
- nsCOMPtr<nsISelection> domSelection;
- nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
- getter_AddRefs(domSelection));
- if (NS_FAILED(rv)) {
+ RefPtr<Selection> selection =
+ mSelCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
+ if (NS_WARN_IF(!selection)) {
UNLOCK_DOC(this);
- return rv;
+ return NS_ERROR_FAILURE;
}
- RefPtr<Selection> selection = domSelection->AsSelection();
-
- bool isCollapsed = selection->IsCollapsed();
-
nsCOMPtr<nsIContentIterator> iter;
RefPtr<nsRange> range;
nsCOMPtr<nsIDOMNode> parent;
- if (isCollapsed) {
+ if (selection->IsCollapsed()) {
// We have a caret. Check if the caret is in a text node.
// If it is, make the text node's block the current block.
// If the caret isn't in a text node, search forwards in
// the document, till we find a text node.
range = selection->GetRangeAt(0);
if (!range) {
UNLOCK_DOC(this);
return NS_ERROR_FAILURE;
}
- rv = range->GetStartContainer(getter_AddRefs(parent));
+ nsresult rv = range->GetStartContainer(getter_AddRefs(parent));
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
if (!parent) {
UNLOCK_DOC(this);
@@ -600,16 +595,17 @@ nsTextServicesDocument::LastSelectedBloc
parent, static_cast<int32_t>(offset), false,
getter_AddRefs(range));
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
+ bool isCollapsed;
rv = range->GetCollapsed(&isCollapsed);
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
if (isCollapsed) {
@@ -709,17 +705,17 @@ nsTextServicesDocument::LastSelectedBloc
if (!range) {
UNLOCK_DOC(this);
return NS_OK; // XXX Really?
}
// Create an iterator for the range.
- rv = CreateContentIterator(range, getter_AddRefs(iter));
+ nsresult rv = CreateContentIterator(range, getter_AddRefs(iter));
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
iter->Last();
@@ -775,17 +771,17 @@ nsTextServicesDocument::LastSelectedBloc
range = selection->GetRangeAt(rangeCount - 1);
if (!range) {
UNLOCK_DOC(this);
return NS_ERROR_FAILURE;
}
- rv = range->GetEndContainer(getter_AddRefs(parent));
+ nsresult rv = range->GetEndContainer(getter_AddRefs(parent));
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
if (!parent) {
UNLOCK_DOC(this);
@@ -803,16 +799,17 @@ nsTextServicesDocument::LastSelectedBloc
rv = CreateDocumentContentRootToNodeOffsetRange(
parent, static_cast<int32_t>(offset), false, getter_AddRefs(range));
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
+ bool isCollapsed;
rv = range->GetCollapsed(&isCollapsed);
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
if (isCollapsed) {
@@ -2290,36 +2287,27 @@ nsTextServicesDocument::GetSelection(nsI
*aSelLength = -1;
NS_ENSURE_TRUE(mDOMDocument && mSelCon, NS_ERROR_FAILURE);
if (mIteratorStatus == nsTextServicesDocument::eIsDone) {
return NS_OK;
}
- nsCOMPtr<nsISelection> selection;
- bool isCollapsed;
-
- nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
- getter_AddRefs(selection));
-
- NS_ENSURE_SUCCESS(rv, rv);
-
+ RefPtr<Selection> selection =
+ mSelCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
- rv = selection->GetIsCollapsed(&isCollapsed);
-
- NS_ENSURE_SUCCESS(rv, rv);
-
// XXX: If we expose this method publicly, we need to
// add LOCK_DOC/UNLOCK_DOC calls!
// LOCK_DOC(this);
- if (isCollapsed) {
+ nsresult rv;
+ if (selection->IsCollapsed()) {
rv = GetCollapsedSelection(aSelStatus, aSelOffset, aSelLength);
} else {
rv = GetUncollapsedSelection(aSelStatus, aSelOffset, aSelLength);
}
// UNLOCK_DOC(this);
// XXX The result of GetCollapsedSelection() or GetUncollapsedSelection().