Bug 1447890 part 5. Remove nsISelection::RemoveAllRanges. r=mystor
MozReview-Commit-ID: EeMje9KW6An
This commit is contained in:
@@ -273,7 +273,7 @@ nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
||||
selCon->GetDOMSelection(nsISelectionController::SELECTION_ACCESSIBILITY);
|
||||
|
||||
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryObject(selection));
|
||||
selection->RemoveAllRanges();
|
||||
selection->RemoveAllRanges(IgnoreErrors());
|
||||
selection->AddRange(*aRange, IgnoreErrors());
|
||||
|
||||
privSel->ScrollIntoViewInternal(
|
||||
|
||||
@@ -778,7 +778,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Selection)
|
||||
// in JS!).
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSelectionListeners)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedRange)
|
||||
tmp->RemoveAllRanges();
|
||||
tmp->RemoveAllRanges(IgnoreErrors());
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameSelection)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
@@ -2225,16 +2225,6 @@ Selection::DoAutoScroll(nsIFrame* aFrame, nsPoint aPoint)
|
||||
}
|
||||
|
||||
|
||||
/** RemoveAllRanges zeroes the selection
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
Selection::RemoveAllRanges()
|
||||
{
|
||||
ErrorResult result;
|
||||
RemoveAllRanges(result);
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
void
|
||||
Selection::RemoveAllRanges(ErrorResult& aRv)
|
||||
{
|
||||
@@ -4025,7 +4015,6 @@ Selection::SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
||||
return;
|
||||
}
|
||||
|
||||
// Use non-virtual method instead of nsISelection::RemoveAllRanges().
|
||||
RemoveAllRanges(aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
|
||||
@@ -2439,7 +2439,7 @@ nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell, nsIContent* aContent)
|
||||
if (domSelection) {
|
||||
// First clear the selection. This way, if there is no currently focused
|
||||
// content, the selection will just be cleared.
|
||||
domSelection->RemoveAllRanges();
|
||||
domSelection->RemoveAllRanges(IgnoreErrors());
|
||||
if (aContent) {
|
||||
ErrorResult rv;
|
||||
RefPtr<nsRange> newRange = doc->CreateRange(rv);
|
||||
|
||||
@@ -102,11 +102,6 @@ interface nsISelection : nsISupports
|
||||
*/
|
||||
void selectAllChildren(in nsIDOMNode parentNode);
|
||||
|
||||
/**
|
||||
* Removes all ranges from the current selection.
|
||||
*/
|
||||
void removeAllRanges();
|
||||
|
||||
/**
|
||||
* Deletes this selection from document the nodes belong to.
|
||||
*/
|
||||
|
||||
@@ -103,6 +103,7 @@
|
||||
#include "nsIImageDocument.h"
|
||||
#include "mozilla/dom/HTMLBodyElement.h"
|
||||
#include "mozilla/dom/HTMLDocumentBinding.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "nsCharsetSource.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
@@ -2548,12 +2549,11 @@ nsHTMLDocument::EditingStateChanged()
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelection> spellCheckSelection;
|
||||
rv = selectionController->GetSelection(
|
||||
nsISelectionController::SELECTION_SPELLCHECK,
|
||||
getter_AddRefs(spellCheckSelection));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
spellCheckSelection->RemoveAllRanges();
|
||||
RefPtr<Selection> spellCheckSelection =
|
||||
selectionController->GetDOMSelection(
|
||||
nsISelectionController::SELECTION_SPELLCHECK);
|
||||
if (spellCheckSelection) {
|
||||
spellCheckSelection->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
}
|
||||
htmlEditor->SyncRealTimeSpell();
|
||||
|
||||
@@ -37,6 +37,9 @@ interface Selection {
|
||||
*/
|
||||
[Throws]
|
||||
void removeRange(Range range);
|
||||
/**
|
||||
* Removes all ranges from the current selection.
|
||||
*/
|
||||
[Throws]
|
||||
void removeAllRanges();
|
||||
[Throws, BinaryName="RemoveAllRanges"]
|
||||
|
||||
@@ -245,14 +245,11 @@ CompositionTransaction::SetIMESelection(EditorBase& aEditorBase,
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
for (uint32_t i = 0; i < ArrayLength(kIMESelections); ++i) {
|
||||
nsCOMPtr<nsISelection> selectionOfIME;
|
||||
if (NS_FAILED(selCon->GetSelection(kIMESelections[i],
|
||||
getter_AddRefs(selectionOfIME)))) {
|
||||
RefPtr<Selection> selectionOfIME = selCon->GetDOMSelection(kIMESelections[i]);
|
||||
if (!selectionOfIME) {
|
||||
continue;
|
||||
}
|
||||
rv = selectionOfIME->RemoveAllRanges();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to remove all ranges of IME selection");
|
||||
selectionOfIME->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
|
||||
// Set caret position and selection of IME composition with TextRangeArray.
|
||||
|
||||
@@ -3444,8 +3444,11 @@ EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
|
||||
|
||||
// If we have not seen the selection yet, clear all of its ranges.
|
||||
if (range.mSelection != previousSelection) {
|
||||
nsresult rv = range.mSelection->RemoveAllRanges();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult rv;
|
||||
range.mSelection->RemoveAllRanges(rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
previousSelection = range.mSelection;
|
||||
}
|
||||
|
||||
@@ -4897,7 +4900,9 @@ EditorBase::ClearSelection()
|
||||
{
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
||||
return selection->RemoveAllRanges();
|
||||
ErrorResult rv;
|
||||
selection->RemoveAllRanges(rv);
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
already_AddRefed<Element>
|
||||
|
||||
@@ -80,7 +80,7 @@ SelectionState::RestoreSelection(Selection* aSel)
|
||||
NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// clear out selection
|
||||
aSel->RemoveAllRanges();
|
||||
aSel->RemoveAllRanges(IgnoreErrors());
|
||||
|
||||
// set the selection ranges anew
|
||||
size_t arrayCount = mArray.Length();
|
||||
|
||||
@@ -614,7 +614,7 @@ nsresult mozInlineSpellChecker::Cleanup(bool aDestroyingFrames)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
} else {
|
||||
if (!aDestroyingFrames) {
|
||||
spellCheckSelection->RemoveAllRanges();
|
||||
spellCheckSelection->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
|
||||
rv = UnregisterEventListeners();
|
||||
@@ -964,7 +964,7 @@ mozInlineSpellChecker::ReplaceWord(nsIDOMNode *aNode, int32_t aOffset,
|
||||
|
||||
RefPtr<Selection> selection = mTextEditor->GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_UNEXPECTED);
|
||||
selection->RemoveAllRanges();
|
||||
selection->RemoveAllRanges(IgnoreErrors());
|
||||
selection->AddRange(*editorRange, IgnoreErrors());
|
||||
|
||||
MOZ_ASSERT(mTextEditor);
|
||||
@@ -1307,7 +1307,7 @@ mozInlineSpellChecker::DoSpellCheckSelection(mozInlineSpellWordUtil& aWordUtil,
|
||||
// provides better performance. By ensuring that no ranges need to be
|
||||
// removed in DoSpellCheck, we can save checking range inclusion which is
|
||||
// slow.
|
||||
aSpellCheckSelection->RemoveAllRanges();
|
||||
aSpellCheckSelection->RemoveAllRanges(IgnoreErrors());
|
||||
|
||||
// We use this state object for all calls, and just update its range. Note
|
||||
// that we don't need to call FinishInit since we will be filling in the
|
||||
|
||||
@@ -3187,7 +3187,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll,
|
||||
// Select the anchor
|
||||
RefPtr<Selection> sel = mSelection->GetSelection(SelectionType::eNormal);
|
||||
if (sel) {
|
||||
sel->RemoveAllRanges();
|
||||
sel->RemoveAllRanges(IgnoreErrors());
|
||||
sel->AddRange(*jumpToRange, IgnoreErrors());
|
||||
if (!selectAnchor) {
|
||||
// Use a caret (collapsed selection) at the start of the anchor
|
||||
|
||||
@@ -2732,11 +2732,13 @@ NS_IMETHODIMP nsDocumentViewer::SelectAll()
|
||||
}
|
||||
if (!bodyNode) return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = selection->RemoveAllRanges();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ErrorResult err;
|
||||
selection->RemoveAllRanges(err);
|
||||
if (err.Failed()) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
mozilla::dom::Selection::AutoUserInitiated userSelection(selection);
|
||||
ErrorResult err;
|
||||
selection->SelectAllChildren(*bodyNode, err);
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
@@ -797,15 +797,15 @@ void nsTextControlFrame::SetFocus(bool aOn, bool aRepaint)
|
||||
// document since the focus is now on our independent selection.
|
||||
|
||||
nsCOMPtr<nsISelectionController> selcon = do_QueryInterface(presShell);
|
||||
nsCOMPtr<nsISelection> docSel;
|
||||
selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(docSel));
|
||||
if (!docSel) return;
|
||||
RefPtr<Selection> docSel =
|
||||
selcon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (!docSel) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isCollapsed = false;
|
||||
docSel->GetIsCollapsed(&isCollapsed);
|
||||
if (!isCollapsed)
|
||||
docSel->RemoveAllRanges();
|
||||
if (!docSel->IsCollapsed()) {
|
||||
docSel->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsTextControlFrame::SetFormProperty(nsAtom* aName, const nsAString& aValue)
|
||||
@@ -891,10 +891,12 @@ nsTextControlFrame::SetSelectionInternal(nsINode* aStartNode,
|
||||
direction = (aDirection == eBackward) ? eDirPrevious : eDirNext;
|
||||
}
|
||||
|
||||
rv = selection->RemoveAllRanges();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
ErrorResult err;
|
||||
selection->RemoveAllRanges(err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
selection->AddRange(*range, err); // NOTE: can destroy the world
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
|
||||
@@ -2043,7 +2043,9 @@ nsFrameSelection::ClearNormalSelection()
|
||||
if (!mDomSelections[index])
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return mDomSelections[index]->RemoveAllRanges();
|
||||
ErrorResult err;
|
||||
mDomSelections[index]->RemoveAllRanges(err);
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
static nsIContent*
|
||||
@@ -2160,7 +2162,7 @@ printf("HandleTableSelection: Dragged into a new cell\n");
|
||||
{
|
||||
// Force new selection block
|
||||
mStartSelectedCell = nullptr;
|
||||
mDomSelections[index]->RemoveAllRanges();
|
||||
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
||||
|
||||
if (startRowIndex == curRowIndex)
|
||||
mSelectingTableCellMode = nsISelectionPrivate::TABLESELECTION_ROW;
|
||||
@@ -2208,7 +2210,7 @@ printf("HandleTableSelection: Mouse down event\n");
|
||||
else
|
||||
{
|
||||
// No cells selected -- remove non-cell selection
|
||||
mDomSelections[index]->RemoveAllRanges();
|
||||
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
mDragSelectingCells = true; // Signal to start drag-cell-selection
|
||||
mSelectingTableCellMode = aTarget;
|
||||
@@ -2232,7 +2234,7 @@ printf("HandleTableSelection: Saving mUnselectCellOnMouseUp\n");
|
||||
if (previousCellNode &&
|
||||
!IsInSameTable(previousCellNode, childContent))
|
||||
{
|
||||
mDomSelections[index]->RemoveAllRanges();
|
||||
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
||||
// Reset selection mode that is cleared in RemoveAllRanges
|
||||
mSelectingTableCellMode = aTarget;
|
||||
}
|
||||
@@ -2252,7 +2254,7 @@ printf("HandleTableSelection: Saving mUnselectCellOnMouseUp\n");
|
||||
mEndSelectedCell = nullptr;
|
||||
|
||||
// Remove existing selection and select the table
|
||||
mDomSelections[index]->RemoveAllRanges();
|
||||
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
||||
return CreateAndAddRange(aParentContent, aContentOffset);
|
||||
}
|
||||
else if (aTarget == nsISelectionPrivate::TABLESELECTION_ROW || aTarget == nsISelectionPrivate::TABLESELECTION_COLUMN)
|
||||
@@ -2268,7 +2270,7 @@ printf("aTarget == %d\n", aTarget);
|
||||
|
||||
// Force new selection block
|
||||
mStartSelectedCell = nullptr;
|
||||
mDomSelections[index]->RemoveAllRanges();
|
||||
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
||||
// Always do this AFTER RemoveAllRanges
|
||||
mSelectingTableCellMode = aTarget;
|
||||
return SelectRowOrColumn(childContent, aTarget);
|
||||
|
||||
@@ -2165,7 +2165,7 @@ nsPrintJob::UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
|
||||
// Reset all existing selection ranges that might have been added by calling
|
||||
// this function before.
|
||||
if (selectionPS) {
|
||||
selectionPS->RemoveAllRanges();
|
||||
selectionPS->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
if (selection && selectionPS) {
|
||||
int32_t cnt = selection->RangeCount();
|
||||
|
||||
@@ -393,7 +393,7 @@ nsWebBrowserFind::SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow,
|
||||
RefPtr<Selection> selection =
|
||||
selCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (selection) {
|
||||
selection->RemoveAllRanges();
|
||||
selection->RemoveAllRanges(IgnoreErrors());
|
||||
selection->AddRange(*aRange, IgnoreErrors());
|
||||
|
||||
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
||||
@@ -718,7 +718,7 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMWindowOuter* aWindow, bool aWrapping,
|
||||
// selection) models are up to date.
|
||||
theDoc->FlushPendingNotifications(FlushType::Frames);
|
||||
|
||||
nsCOMPtr<nsISelection> sel = GetFrameSelection(aWindow);
|
||||
RefPtr<Selection> sel = GetFrameSelection(aWindow);
|
||||
NS_ENSURE_ARG_POINTER(sel);
|
||||
|
||||
RefPtr<nsRange> searchRange = new nsRange(theDoc);
|
||||
@@ -747,7 +747,7 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMWindowOuter* aWindow, bool aWrapping,
|
||||
|
||||
if (NS_SUCCEEDED(rv) && foundRange) {
|
||||
*aDidFind = true;
|
||||
sel->RemoveAllRanges();
|
||||
sel->RemoveAllRanges(IgnoreErrors());
|
||||
// Beware! This may flush notifications via synchronous
|
||||
// ScrollSelectionIntoView.
|
||||
SetSelectionAndScroll(aWindow, static_cast<nsRange*>(foundRange.get()));
|
||||
@@ -773,7 +773,7 @@ nsWebBrowserFind::OnEndSearchFrame(nsPIDOMWindowOuter* aWindow)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsISelection>
|
||||
already_AddRefed<Selection>
|
||||
nsWebBrowserFind::GetFrameSelection(nsPIDOMWindowOuter* aWindow)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
|
||||
@@ -818,9 +818,9 @@ nsresult
|
||||
nsWebBrowserFind::ClearFrameSelection(nsPIDOMWindowOuter* aWindow)
|
||||
{
|
||||
NS_ENSURE_ARG(aWindow);
|
||||
nsCOMPtr<nsISelection> selection = GetFrameSelection(aWindow);
|
||||
RefPtr<Selection> selection = GetFrameSelection(aWindow);
|
||||
if (selection) {
|
||||
selection->RemoveAllRanges();
|
||||
selection->RemoveAllRanges(IgnoreErrors());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
@@ -27,6 +27,12 @@ class nsIDOMWindow;
|
||||
class nsIDocShell;
|
||||
class nsRange;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class Selection;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
//*****************************************************************************
|
||||
// class nsWebBrowserFind
|
||||
//*****************************************************************************
|
||||
@@ -58,7 +64,8 @@ protected:
|
||||
nsresult OnStartSearchFrame(nsPIDOMWindowOuter* aWindow);
|
||||
nsresult OnEndSearchFrame(nsPIDOMWindowOuter* aWindow);
|
||||
|
||||
already_AddRefed<nsISelection> GetFrameSelection(nsPIDOMWindowOuter* aWindow);
|
||||
already_AddRefed<mozilla::dom::Selection>
|
||||
GetFrameSelection(nsPIDOMWindowOuter* aWindow);
|
||||
nsresult ClearFrameSelection(nsPIDOMWindowOuter* aWindow);
|
||||
|
||||
nsresult OnFind(nsPIDOMWindowOuter* aFoundWindow);
|
||||
|
||||
@@ -630,7 +630,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
|
||||
|
||||
// Select the found text
|
||||
if (selection) {
|
||||
selection->RemoveAllRanges();
|
||||
selection->RemoveAllRanges(IgnoreErrors());
|
||||
selection->AddRange(*returnRange, IgnoreErrors());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user