Bug 1421553 - Part 2. Remove nsIDOMRange usages from nsTextServicesDocument. r?masayuki
nsITextServicesDocument isn't scriptable, so there is no reason to use
nsIDOMRange.
MozReview-Commit-ID: AVPgrwmz38H
--- a/editor/txtsvc/nsITextServicesDocument.h
+++ b/editor/txtsvc/nsITextServicesDocument.h
@@ -5,19 +5,19 @@
#ifndef nsITextServicesDocument_h__
#define nsITextServicesDocument_h__
#include "nsISupports.h"
#include "nsStringFwd.h"
class nsIDOMDocument;
-class nsIDOMRange;
class nsIEditor;
class nsITextServicesFilter;
+class nsRange;
/*
TextServicesDocument interface to outside world
*/
#define NS_ITEXTSERVICESDOCUMENT_IID \
{ /* 019718E1-CDB5-11d2-8D3C-000000000000 */ \
0x019718e1, 0xcdb5, 0x11d2, \
@@ -62,25 +62,25 @@ public:
* Sets the range/extent over which the text services document
* will iterate. Note that InitWithEditor() should have been called prior to
* calling this method. If this method is never called, the text services
* defaults to iterating over the entire document.
*
* @param aDOMRange is the range to use. aDOMRange must point to a
* valid range object.
*/
- NS_IMETHOD SetExtent(nsIDOMRange* aDOMRange) = 0;
+ NS_IMETHOD SetExtent(nsRange* aDOMRange) = 0;
/**
* Expands the end points of the range so that it spans complete words.
* This call does not change any internal state of the text services document.
*
* @param aDOMRange the range to be expanded/adjusted.
*/
- NS_IMETHOD ExpandRangeToWordBoundaries(nsIDOMRange *aRange) = 0;
+ NS_IMETHOD ExpandRangeToWordBoundaries(nsRange* aRange) = 0;
/**
* Sets the filter to be used while iterating over content.
* @param aFilter filter to be used while iterating over content.
*/
NS_IMETHOD SetFilter(nsITextServicesFilter *aFilter) = 0;
/**
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -17,17 +17,16 @@
#include "nsIContent.h" // for nsIContent, etc
#include "nsIContentIterator.h" // for nsIContentIterator
#include "nsID.h" // for NS_GET_IID
#include "nsIDOMDocument.h" // for nsIDOMDocument
#include "nsIDOMElement.h" // for nsIDOMElement
#include "nsIDOMHTMLDocument.h" // for nsIDOMHTMLDocument
#include "nsIDOMHTMLElement.h" // for nsIDOMHTMLElement
#include "nsIDOMNode.h" // for nsIDOMNode, etc
-#include "nsIDOMRange.h" // for nsIDOMRange, etc
#include "nsIEditor.h" // for nsIEditor, etc
#include "nsINode.h" // for nsINode
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor
#include "nsISelection.h" // for nsISelection
#include "nsISelectionController.h" // for nsISelectionController, etc
#include "nsISupportsBase.h" // for nsISupports
#include "nsISupportsUtils.h" // for NS_IF_ADDREF, NS_ADDREF, etc
#include "nsITextServicesFilter.h" // for nsITextServicesFilter
@@ -188,27 +187,27 @@ nsTextServicesDocument::GetDocument(nsID
*aDoc = mDOMDocument;
NS_ADDREF(*aDoc);
return NS_OK;
}
NS_IMETHODIMP
-nsTextServicesDocument::SetExtent(nsIDOMRange* aDOMRange)
+nsTextServicesDocument::SetExtent(nsRange* aRange)
{
- NS_ENSURE_ARG_POINTER(aDOMRange);
+ NS_ENSURE_ARG_POINTER(aRange);
NS_ENSURE_TRUE(mDOMDocument, NS_ERROR_FAILURE);
LOCK_DOC(this);
// We need to store a copy of aDOMRange since we don't
// know where it came from.
- mExtent = static_cast<nsRange*>(aDOMRange)->CloneRange();
+ mExtent = aRange->CloneRange();
// Create a new iterator based on our new extent range.
nsresult rv = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
@@ -222,37 +221,36 @@ nsTextServicesDocument::SetExtent(nsIDOM
rv = FirstBlock();
UNLOCK_DOC(this);
return rv;
}
NS_IMETHODIMP
-nsTextServicesDocument::ExpandRangeToWordBoundaries(nsIDOMRange *aRange)
+nsTextServicesDocument::ExpandRangeToWordBoundaries(nsRange* aRange)
{
NS_ENSURE_ARG_POINTER(aRange);
- RefPtr<nsRange> range = static_cast<nsRange*>(aRange);
// Get the end points of the range.
nsCOMPtr<nsINode> rngStartNode, rngEndNode;
int32_t rngStartOffset, rngEndOffset;
- nsresult rv = GetRangeEndPoints(range, getter_AddRefs(rngStartNode),
+ nsresult rv = GetRangeEndPoints(aRange, getter_AddRefs(rngStartNode),
&rngStartOffset,
getter_AddRefs(rngEndNode),
&rngEndOffset);
NS_ENSURE_SUCCESS(rv, rv);
// Create a content iterator based on the range.
nsCOMPtr<nsIContentIterator> iter;
- rv = CreateContentIterator(range, getter_AddRefs(iter));
+ rv = CreateContentIterator(aRange, getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
// Find the first text node in the range.
TSDIteratorStatus iterStatus;
rv = FirstTextNode(iter, &iterStatus);
@@ -367,18 +365,18 @@ nsTextServicesDocument::ExpandRangeToWor
rngEndOffset != wordStartOffset ||
(rngEndNode == rngStartNode && rngEndOffset == rngStartOffset)) {
rngEndNode = wordEndNode;
rngEndOffset = wordEndOffset;
}
// Now adjust the range so that it uses our new
// end points.
- rv = range->SetStartAndEnd(rngStartNode, rngStartOffset,
- rngEndNode, rngEndOffset);
+ rv = aRange->SetStartAndEnd(rngStartNode, rngStartOffset,
+ rngEndNode, rngEndOffset);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
nsTextServicesDocument::SetFilter(nsITextServicesFilter *aFilter)
--- a/editor/txtsvc/nsTextServicesDocument.h
+++ b/editor/txtsvc/nsTextServicesDocument.h
@@ -17,17 +17,16 @@
#include "nscore.h"
class OffsetEntry;
class nsIContent;
class nsIContentIterator;
class nsIDOMCharacterData;
class nsIDOMDocument;
class nsIDOMNode;
-class nsIDOMRange;
class nsIEditor;
class nsISelection;
class nsISelectionController;
class nsITextServicesFilter;
/** implementation of a text services object.
*
*/
@@ -72,18 +71,18 @@ public:
/* Macro for AddRef(), Release(), and QueryInterface() */
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTextServicesDocument, nsITextServicesDocument)
/* nsITextServicesDocument method implementations. */
NS_IMETHOD InitWithEditor(nsIEditor *aEditor) override;
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc) override;
- NS_IMETHOD SetExtent(nsIDOMRange* aDOMRange) override;
- NS_IMETHOD ExpandRangeToWordBoundaries(nsIDOMRange *aRange) override;
+ NS_IMETHOD SetExtent(nsRange* aRange) override;
+ NS_IMETHOD ExpandRangeToWordBoundaries(nsRange* aRange) override;
NS_IMETHOD SetFilter(nsITextServicesFilter *aFilter) override;
NS_IMETHOD GetCurrentTextBlock(nsString *aStr) override;
NS_IMETHOD FirstBlock() override;
NS_IMETHOD LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength) override;
NS_IMETHOD PrevBlock() override;
NS_IMETHOD NextBlock() override;
NS_IMETHOD IsDone(bool *aIsDone) override;
NS_IMETHOD SetSelection(int32_t aOffset, int32_t aLength) override;