зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1447890 part 1. Remove nsISelection::AddRange. r=mystor
MozReview-Commit-ID: 1JNLZp7tbII
This commit is contained in:
Родитель
a8a190f4e1
Коммит
54d1f87ff4
|
@ -38,6 +38,7 @@
|
|||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/HTMLLabelElement.h"
|
||||
#include "mozilla/dom/MouseEventBinding.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -258,8 +259,9 @@ nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
|||
nsIPresShell::ScrollAxis aVertical,
|
||||
nsIPresShell::ScrollAxis aHorizontal)
|
||||
{
|
||||
if (!aFrame)
|
||||
if (!aFrame || !aRange) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsPresContext *presContext = aFrame->PresContext();
|
||||
|
||||
|
@ -267,13 +269,12 @@ nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
|||
aFrame->GetSelectionController(presContext, getter_AddRefs(selCon));
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY,
|
||||
getter_AddRefs(selection));
|
||||
RefPtr<dom::Selection> selection =
|
||||
selCon->GetDOMSelection(nsISelectionController::SELECTION_ACCESSIBILITY);
|
||||
|
||||
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(selection));
|
||||
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryObject(selection));
|
||||
selection->RemoveAllRanges();
|
||||
selection->AddRange(aRange);
|
||||
selection->AddRange(*aRange, IgnoreErrors());
|
||||
|
||||
privSel->ScrollIntoViewInternal(
|
||||
nsISelectionController::SELECTION_ANCHOR_REGION,
|
||||
|
|
|
@ -1661,11 +1661,16 @@ HyperTextAccessible::SetSelectionBoundsAt(int32_t aSelectionNum,
|
|||
|
||||
// If new range was created then add it, otherwise notify selection listeners
|
||||
// that existing selection range was changed.
|
||||
if (aSelectionNum == static_cast<int32_t>(rangeCount))
|
||||
return NS_SUCCEEDED(domSel->AddRange(range));
|
||||
if (aSelectionNum == static_cast<int32_t>(rangeCount)) {
|
||||
IgnoredErrorResult err;
|
||||
domSel->AddRange(*range, err);
|
||||
return !err.Failed();
|
||||
}
|
||||
|
||||
domSel->RemoveRange(range);
|
||||
return NS_SUCCEEDED(domSel->AddRange(range));
|
||||
IgnoredErrorResult err;
|
||||
domSel->AddRange(*range, err);
|
||||
return !err.Failed();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -2288,21 +2288,6 @@ Selection::RemoveAllRangesTemporarily()
|
|||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
/** AddRange adds the specified range to the selection
|
||||
* @param aRange is the range to be added
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
Selection::AddRange(nsIDOMRange* aDOMRange)
|
||||
{
|
||||
if (!aDOMRange) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsRange* range = static_cast<nsRange*>(aDOMRange);
|
||||
ErrorResult result;
|
||||
AddRange(*range, result);
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
void
|
||||
Selection::AddRangeJS(nsRange& aRange, ErrorResult& aRv)
|
||||
{
|
||||
|
@ -4078,9 +4063,8 @@ Selection::SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
|||
return;
|
||||
}
|
||||
|
||||
rv = AddRange(newRange);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
AddRange(*newRange, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2434,7 +2434,7 @@ nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell, nsIContent* aContent)
|
|||
nsCOMPtr<nsIDocument> doc = aPresShell->GetDocument();
|
||||
if (doc) {
|
||||
RefPtr<nsFrameSelection> frameSelection = aPresShell->FrameSelection();
|
||||
nsCOMPtr<nsISelection> domSelection =
|
||||
RefPtr<Selection> domSelection =
|
||||
frameSelection->GetSelection(SelectionType::eNormal);
|
||||
if (domSelection) {
|
||||
// First clear the selection. This way, if there is no currently focused
|
||||
|
@ -2460,7 +2460,7 @@ nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell, nsIContent* aContent)
|
|||
newRange->SetStartBefore(*aContent, IgnoreErrors());
|
||||
newRange->SetEndBefore(*aContent, IgnoreErrors());
|
||||
}
|
||||
domSelection->AddRange(newRange);
|
||||
domSelection->AddRange(*newRange, IgnoreErrors());
|
||||
domSelection->CollapseToStart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,11 +113,6 @@ interface nsISelection : nsISupports
|
|||
*/
|
||||
void selectAllChildren(in nsIDOMNode parentNode);
|
||||
|
||||
/**
|
||||
* Adds a range to the current selection.
|
||||
*/
|
||||
void addRange(in nsIDOMRange range);
|
||||
|
||||
/**
|
||||
* Removes a range from the current selection.
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,9 @@ interface Selection {
|
|||
readonly attribute DOMString type;
|
||||
[Throws]
|
||||
Range getRangeAt(unsigned long index);
|
||||
/**
|
||||
* Adds a range to the current selection.
|
||||
*/
|
||||
[Throws, BinaryName="addRangeJS"]
|
||||
void addRange(Range range);
|
||||
[Throws]
|
||||
|
|
|
@ -325,8 +325,9 @@ CompositionTransaction::SetIMESelection(EditorBase& aEditorBase,
|
|||
break;
|
||||
}
|
||||
|
||||
rv = selectionOfIME->AddRange(clauseRange);
|
||||
if (NS_FAILED(rv)) {
|
||||
IgnoredErrorResult err;
|
||||
selectionOfIME->AddRange(*clauseRange, err);
|
||||
if (err.Failed()) {
|
||||
NS_WARNING("Failed to add selection range for a clause of composition");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3477,8 +3477,11 @@ EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
|
|||
range.mEndOffset,
|
||||
getter_AddRefs(newRange));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = range.mSelection->AddRange(newRange);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult err;
|
||||
range.mSelection->AddRange(*newRange, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSetSelection) {
|
||||
|
@ -4884,7 +4887,9 @@ EditorBase::AppendNodeToSelectionAsRange(nsIDOMNode* aNode)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
|
||||
|
||||
return selection->AddRange(range);
|
||||
ErrorResult err;
|
||||
selection->AddRange(*range, err);
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -88,9 +88,10 @@ SelectionState::RestoreSelection(Selection* aSel)
|
|||
RefPtr<nsRange> range = mArray[i]->GetRange();
|
||||
NS_ENSURE_TRUE(range, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsresult rv = aSel->AddRange(range);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
ErrorResult rv;
|
||||
aSel->AddRange(*range, rv);
|
||||
if (rv.Failed()) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
|
|
@ -962,11 +962,10 @@ mozInlineSpellChecker::ReplaceWord(nsIDOMNode *aNode, int32_t aOffset,
|
|||
|
||||
AutoPlaceholderBatch phb(mTextEditor, nullptr);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
res = mTextEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
RefPtr<Selection> selection = mTextEditor->GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_UNEXPECTED);
|
||||
selection->RemoveAllRanges();
|
||||
selection->AddRange(editorRange);
|
||||
selection->AddRange(*editorRange, IgnoreErrors());
|
||||
|
||||
MOZ_ASSERT(mTextEditor);
|
||||
mTextEditor->InsertText(newword);
|
||||
|
@ -1711,8 +1710,8 @@ mozInlineSpellChecker::RemoveRange(Selection *aSpellCheckSelection,
|
|||
// bound, stop adding the ranges
|
||||
|
||||
nsresult
|
||||
mozInlineSpellChecker::AddRange(nsISelection* aSpellCheckSelection,
|
||||
nsIDOMRange* aRange)
|
||||
mozInlineSpellChecker::AddRange(Selection* aSpellCheckSelection,
|
||||
nsRange* aRange)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aSpellCheckSelection);
|
||||
NS_ENSURE_ARG_POINTER(aRange);
|
||||
|
@ -1721,9 +1720,13 @@ mozInlineSpellChecker::AddRange(nsISelection* aSpellCheckSelection,
|
|||
|
||||
if (!SpellCheckSelectionIsFull())
|
||||
{
|
||||
rv = aSpellCheckSelection->AddRange(aRange);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
IgnoredErrorResult err;
|
||||
aSpellCheckSelection->AddRange(*aRange, err);
|
||||
if (err.Failed()) {
|
||||
rv = err.StealNSResult();
|
||||
} else {
|
||||
mNumWordsInSpellSelection++;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -232,7 +232,8 @@ public:
|
|||
|
||||
nsresult RemoveRange(mozilla::dom::Selection *aSpellCheckSelection,
|
||||
nsRange *aRange);
|
||||
nsresult AddRange(nsISelection *aSpellCheckSelection, nsIDOMRange * aRange);
|
||||
nsresult AddRange(mozilla::dom::Selection *aSpellCheckSelection,
|
||||
nsRange* aRange);
|
||||
bool SpellCheckSelectionIsFull() { return mNumWordsInSpellSelection >= mMaxNumWordsInSpellSelection; }
|
||||
|
||||
nsresult MakeSpellCheckRange(nsIDOMNode* aStartNode, int32_t aStartOffset,
|
||||
|
|
|
@ -3188,7 +3188,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll,
|
|||
RefPtr<Selection> sel = mSelection->GetSelection(SelectionType::eNormal);
|
||||
if (sel) {
|
||||
sel->RemoveAllRanges();
|
||||
sel->AddRange(jumpToRange);
|
||||
sel->AddRange(*jumpToRange, IgnoreErrors());
|
||||
if (!selectAnchor) {
|
||||
// Use a caret (collapsed selection) at the start of the anchor
|
||||
sel->CollapseToStart();
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "nsRange.h" //for selection setting helper func
|
||||
#include "nsINode.h"
|
||||
#include "nsPIDOMWindow.h" //needed for notify selection changed to update the menus ect.
|
||||
#include "nsQueryObject.h"
|
||||
|
||||
#include "nsFocusManager.h"
|
||||
#include "nsPresState.h"
|
||||
|
@ -875,11 +876,11 @@ nsTextControlFrame::SetSelectionInternal(nsINode* aStartNode,
|
|||
nsISelectionController* selCon = txtCtrl->GetSelectionController();
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
RefPtr<Selection> selection =
|
||||
selCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection, &rv);
|
||||
nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryObject(selection, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsDirection direction;
|
||||
|
@ -893,8 +894,11 @@ nsTextControlFrame::SetSelectionInternal(nsINode* aStartNode,
|
|||
rv = selection->RemoveAllRanges();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = selection->AddRange(range); // NOTE: can destroy the world
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult err;
|
||||
selection->AddRange(*range, err); // NOTE: can destroy the world
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
selPriv->SetSelectionDirection(direction);
|
||||
return rv;
|
||||
|
|
|
@ -1381,7 +1381,7 @@ nsFrameSelection::TakeFocus(nsIContent* aNewFocus,
|
|||
RefPtr<nsRange> newRange = new nsRange(aNewFocus);
|
||||
|
||||
newRange->CollapseTo(aNewFocus, aContentOffset);
|
||||
mDomSelections[index]->AddRange(newRange);
|
||||
mDomSelections[index]->AddRange(*newRange, IgnoreErrors());
|
||||
mBatching = batching;
|
||||
mChangesDuringBatching = changes;
|
||||
} else {
|
||||
|
@ -2812,7 +2812,9 @@ nsFrameSelection::CreateAndAddRange(nsINode* aContainer, int32_t aOffset)
|
|||
if (!mDomSelections[index])
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return mDomSelections[index]->AddRange(range);
|
||||
ErrorResult err;
|
||||
mDomSelections[index]->AddRange(*range, err);
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
// End of Table Selection
|
||||
|
|
|
@ -2171,7 +2171,7 @@ nsPrintJob::UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
|
|||
int32_t cnt = selection->RangeCount();
|
||||
int32_t inx;
|
||||
for (inx = 0; inx < cnt; ++inx) {
|
||||
selectionPS->AddRange(selection->GetRangeAt(inx));
|
||||
selectionPS->AddRange(*selection->GetRangeAt(inx), IgnoreErrors());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2592,7 +2592,7 @@ DeleteUnselectedNodes(nsIDocument* aOrigDoc, nsIDocument* aDoc)
|
|||
endOffset, getter_AddRefs(range));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !range->Collapsed()) {
|
||||
selection->AddRange(range);
|
||||
selection->AddRange(*range, IgnoreErrors());
|
||||
|
||||
// Unless we've already added an ellipsis at the start, if we ended mid
|
||||
// text node then add ellipsis.
|
||||
|
@ -2628,7 +2628,7 @@ DeleteUnselectedNodes(nsIDocument* aOrigDoc, nsIDocument* aDoc)
|
|||
bodyNode->GetChildCount(),
|
||||
getter_AddRefs(lastRange));
|
||||
if (NS_SUCCEEDED(rv) && !lastRange->Collapsed()) {
|
||||
selection->AddRange(lastRange);
|
||||
selection->AddRange(*lastRange, IgnoreErrors());
|
||||
}
|
||||
|
||||
selection->DeleteFromDocument();
|
||||
|
|
|
@ -353,7 +353,7 @@ IsInNativeAnonymousSubtree(nsIContent* aContent)
|
|||
|
||||
void
|
||||
nsWebBrowserFind::SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow,
|
||||
nsIDOMRange* aRange)
|
||||
nsRange* aRange)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
|
||||
if (!doc) {
|
||||
|
@ -365,9 +365,7 @@ nsWebBrowserFind::SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow,
|
|||
return;
|
||||
}
|
||||
|
||||
nsRange* range = static_cast<nsRange*>(aRange);
|
||||
|
||||
nsCOMPtr<nsINode> node = range->GetStartContainer();
|
||||
nsCOMPtr<nsINode> node = aRange->GetStartContainer();
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
||||
nsIFrame* frame = content->GetPrimaryFrame();
|
||||
if (!frame) {
|
||||
|
@ -391,14 +389,12 @@ nsWebBrowserFind::SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow,
|
|||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(selection));
|
||||
RefPtr<Selection> selection =
|
||||
selCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (selection) {
|
||||
selection->RemoveAllRanges();
|
||||
selection->AddRange(aRange);
|
||||
selection->AddRange(*aRange, IgnoreErrors());
|
||||
|
||||
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
||||
if (fm) {
|
||||
|
@ -754,7 +750,7 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMWindowOuter* aWindow, bool aWrapping,
|
|||
sel->RemoveAllRanges();
|
||||
// Beware! This may flush notifications via synchronous
|
||||
// ScrollSelectionIntoView.
|
||||
SetSelectionAndScroll(aWindow, foundRange);
|
||||
SetSelectionAndScroll(aWindow, static_cast<nsRange*>(foundRange.get()));
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -63,7 +63,7 @@ protected:
|
|||
|
||||
nsresult OnFind(nsPIDOMWindowOuter* aFoundWindow);
|
||||
|
||||
void SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow, nsIDOMRange* aRange);
|
||||
void SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow, nsRange* aRange);
|
||||
|
||||
nsresult GetRootNode(nsIDOMDocument* aDomDoc, nsIDOMNode** aNode);
|
||||
nsresult GetSearchLimits(nsRange* aRange,
|
||||
|
|
|
@ -631,7 +631,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
|
|||
// Select the found text
|
||||
if (selection) {
|
||||
selection->RemoveAllRanges();
|
||||
selection->AddRange(returnRange);
|
||||
selection->AddRange(*returnRange, IgnoreErrors());
|
||||
}
|
||||
|
||||
if (!mFoundEditable && fm) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче