Bug 682611 - Part 2: Remove nsIRange; r=smaug

This commit is contained in:
David Zbarsky 2012-01-10 15:19:54 +01:00
parent 3484fe1ebe
commit 785e84c27d
49 changed files with 527 additions and 847 deletions

View File

@ -46,7 +46,7 @@
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMRange.h"
#include "nsRange.h"
#include "nsIDOMWindow.h"
#include "nsIDOMXULElement.h"
#include "nsIDocShell.h"
@ -63,13 +63,10 @@
#include "nsIView.h"
#include "nsLayoutUtils.h"
#include "nsContentCID.h"
#include "nsComponentManagerUtils.h"
#include "nsIInterfaceRequestorUtils.h"
#include "mozilla/dom/Element.h"
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
////////////////////////////////////////////////////////////////////////////////
// nsCoreUtils
////////////////////////////////////////////////////////////////////////////////
@ -317,9 +314,7 @@ nsCoreUtils::ScrollSubstringTo(nsIFrame *aFrame,
nsPresContext *presContext = aFrame->PresContext();
nsCOMPtr<nsIDOMRange> scrollToRange = do_CreateInstance(kRangeCID);
NS_ENSURE_TRUE(scrollToRange, NS_ERROR_FAILURE);
nsRefPtr<nsIDOMRange> scrollToRange = new nsRange();
nsCOMPtr<nsISelectionController> selCon;
aFrame->GetSelectionController(presContext, getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);

View File

@ -45,7 +45,6 @@
#include "nsTextAttrs.h"
#include "nsIClipboard.h"
#include "nsContentCID.h"
#include "nsFocusManager.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMDocument.h"
@ -66,8 +65,6 @@
using namespace mozilla::a11y;
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
////////////////////////////////////////////////////////////////////////////////
// nsHyperTextAccessible
////////////////////////////////////////////////////////////////////////////////
@ -1738,7 +1735,7 @@ nsHyperTextAccessible::FrameSelection()
void
nsHyperTextAccessible::GetSelectionDOMRanges(PRInt16 aType,
nsCOMArray<nsIDOMRange>* aRanges)
nsTArray<nsRange*>* aRanges)
{
nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
if (!frameSelection)
@ -1762,20 +1759,18 @@ nsHyperTextAccessible::GetSelectionDOMRanges(PRInt16 aType,
return;
PRUint32 childCount = startNode->GetChildCount();
nsCOMPtr<nsIDOMNode> startDOMNode(do_QueryInterface(startNode));
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(domSel));
nsresult rv = privSel->
GetRangesForIntervalCOMArray(startDOMNode, 0, startDOMNode, childCount,
true, aRanges);
GetRangesForIntervalArray(startNode, 0, startNode, childCount, true, aRanges);
NS_ENSURE_SUCCESS(rv,);
// Remove collapsed ranges
PRInt32 numRanges = aRanges->Count();
for (PRInt32 count = 0; count < numRanges; count ++) {
PRUint32 numRanges = aRanges->Length();
for (PRUint32 count = 0; count < numRanges; count ++) {
bool isCollapsed = false;
(*aRanges)[count]->GetCollapsed(&isCollapsed);
if (isCollapsed) {
aRanges->RemoveObjectAt(count);
aRanges->RemoveElementAt(count);
--numRanges;
--count;
}
@ -1791,9 +1786,9 @@ nsHyperTextAccessible::GetSelectionCount(PRInt32* aSelectionCount)
NS_ENSURE_ARG_POINTER(aSelectionCount);
*aSelectionCount = 0;
nsCOMArray<nsIDOMRange> ranges;
nsTArray<nsRange*> ranges;
GetSelectionDOMRanges(nsISelectionController::SELECTION_NORMAL, &ranges);
*aSelectionCount = ranges.Count();
*aSelectionCount = PRInt32(ranges.Length());
return NS_OK;
}
@ -1810,14 +1805,14 @@ nsHyperTextAccessible::GetSelectionBounds(PRInt32 aSelectionNum,
NS_ENSURE_ARG_POINTER(aEndOffset);
*aStartOffset = *aEndOffset = 0;
nsCOMArray<nsIDOMRange> ranges;
nsTArray<nsRange*> ranges;
GetSelectionDOMRanges(nsISelectionController::SELECTION_NORMAL, &ranges);
PRInt32 rangeCount = ranges.Count();
PRUint32 rangeCount = ranges.Length();
if (aSelectionNum < 0 || aSelectionNum >= rangeCount)
return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsIDOMRange> range = ranges[aSelectionNum];
nsRange* range = ranges[aSelectionNum];
// Get start point
nsCOMPtr<nsIDOMNode> startDOMNode;
@ -1879,8 +1874,7 @@ nsHyperTextAccessible::SetSelectionBounds(PRInt32 aSelectionNum,
domSel->GetRangeCount(&rangeCount);
nsCOMPtr<nsIDOMRange> range;
if (aSelectionNum == rangeCount) { // Add a range
range = do_CreateInstance(kRangeCID);
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
range = new nsRange();
}
else if (aSelectionNum < 0 || aSelectionNum > rangeCount) {
return NS_ERROR_INVALID_ARG;
@ -2304,10 +2298,10 @@ nsHyperTextAccessible::GetDOMPointByFrameOffset(nsIFrame *aFrame,
// nsHyperTextAccessible
nsresult
nsHyperTextAccessible::DOMRangeBoundToHypertextOffset(nsIDOMRange *aRange,
bool aIsStartBound,
bool aIsStartHTOffset,
PRInt32 *aHTOffset)
nsHyperTextAccessible::RangeBoundToHypertextOffset(nsRange *aRange,
bool aIsStartBound,
bool aIsStartHTOffset,
PRInt32 *aHTOffset)
{
nsCOMPtr<nsIDOMNode> DOMNode;
PRInt32 nodeOffset = 0;
@ -2345,16 +2339,15 @@ nsHyperTextAccessible::GetSpellTextAttribute(nsIDOMNode *aNode,
PRInt32 *aHTEndOffset,
nsIPersistentProperties *aAttributes)
{
nsCOMArray<nsIDOMRange> ranges;
nsTArray<nsRange*> ranges;
GetSelectionDOMRanges(nsISelectionController::SELECTION_SPELLCHECK, &ranges);
PRInt32 rangeCount = ranges.Count();
PRUint32 rangeCount = ranges.Length();
if (!rangeCount)
return NS_OK;
for (PRInt32 index = 0; index < rangeCount; index++) {
nsCOMPtr<nsIDOMRange> range = ranges[index];
NS_ENSURE_STATE(range);
for (PRUint32 index = 0; index < rangeCount; index++) {
nsRange* range = ranges[index];
PRInt16 result;
nsresult rv = range->ComparePoint(aNode, aNodeOffset, &result);
@ -2376,8 +2369,8 @@ nsHyperTextAccessible::GetSpellTextAttribute(nsIDOMNode *aNode,
if (result == 1) { // range is before point
PRInt32 startHTOffset = 0;
nsresult rv = DOMRangeBoundToHypertextOffset(range, false, true,
&startHTOffset);
nsresult rv = RangeBoundToHypertextOffset(range, false, true,
&startHTOffset);
NS_ENSURE_SUCCESS(rv, rv);
if (startHTOffset > *aHTStartOffset)
@ -2385,8 +2378,8 @@ nsHyperTextAccessible::GetSpellTextAttribute(nsIDOMNode *aNode,
} else if (result == -1) { // range is after point
PRInt32 endHTOffset = 0;
nsresult rv = DOMRangeBoundToHypertextOffset(range, true, false,
&endHTOffset);
nsresult rv = RangeBoundToHypertextOffset(range, true, false,
&endHTOffset);
NS_ENSURE_SUCCESS(rv, rv);
if (endHTOffset < *aHTEndOffset)
@ -2394,13 +2387,13 @@ nsHyperTextAccessible::GetSpellTextAttribute(nsIDOMNode *aNode,
} else { // point is in range
PRInt32 startHTOffset = 0;
nsresult rv = DOMRangeBoundToHypertextOffset(range, true, true,
&startHTOffset);
nsresult rv = RangeBoundToHypertextOffset(range, true, true,
&startHTOffset);
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 endHTOffset = 0;
rv = DOMRangeBoundToHypertextOffset(range, false, false,
&endHTOffset);
rv = RangeBoundToHypertextOffset(range, false, false,
&endHTOffset);
NS_ENSURE_SUCCESS(rv, rv);
if (startHTOffset > *aHTStartOffset)

View File

@ -360,7 +360,7 @@ protected:
/**
* Return selection ranges within the accessible subtree.
*/
void GetSelectionDOMRanges(PRInt16 aType, nsCOMArray<nsIDOMRange>* aRanges);
void GetSelectionDOMRanges(PRInt16 aType, nsTArray<nsRange*>* aRanges);
nsresult SetSelectionRange(PRInt32 aStartPos, PRInt32 aEndPos);
@ -390,10 +390,10 @@ protected:
* outside of hyper text
* @param aHTOffset [out] the result offset
*/
nsresult DOMRangeBoundToHypertextOffset(nsIDOMRange *aRange,
bool aIsStartBound,
bool aIsStartOffset,
PRInt32 *aHTOffset);
nsresult RangeBoundToHypertextOffset(nsRange *aRange,
bool aIsStartBound,
bool aIsStartOffset,
PRInt32 *aHTOffset);
/**
* Set 'misspelled' text attribute and return range offsets where the

View File

@ -62,7 +62,6 @@ nsINameSpaceManager.h \
nsINode.h \
nsINodeInfo.h \
nsINodeList.h \
nsIRange.h \
nsIRangeUtils.h \
nsIScriptElement.h \
nsIStyleSheetLinkingElement.h \

View File

@ -97,10 +97,6 @@
0xd9783472, 0x8fe9, 0x11d2, \
{0x9d, 0x3c, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
#define NS_RANGE_CID \
{/* {56AD2981-8A87-11d2-918C-0080C8E44DB5}*/ \
0x56ad2981, 0x8a87, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
#define NS_CONTENTITERATOR_CID \
{/* {a6cf90e3-15b3-11d2-932e-00805f8add32}*/ \
0xa6cf90e3, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }

View File

@ -42,8 +42,6 @@
class nsINode;
class nsIDOMRange;
class nsIRange;
class nsRange;
#define NS_ICONTENTITERATOR_IID \
{ 0x2550078e, 0xae87, 0x4914, \
@ -62,7 +60,6 @@ public:
Subclasses should make sure they implement both of these!
*/
virtual nsresult Init(nsIDOMRange* aRange) = 0;
virtual nsresult Init(nsIRange* aRange) = 0;
/** First will reset the list.
*/

View File

@ -1,181 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla.com.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIRange_h___
#define nsIRange_h___
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsHashKeys.h"
#include "nsINode.h"
#include "nsIDOMRange.h"
#include "nsTHashtable.h"
// IID for the nsIRange interface
#define NS_IRANGE_IID \
{ 0x09dec26b, 0x1ab7, 0x4ff0, \
{ 0xa1, 0x67, 0x7f, 0x22, 0x9c, 0xaa, 0xc3, 0x04 } }
class nsIDOMFontFaceList;
class nsIRange : public nsIDOMRange {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IRANGE_IID)
nsIRange()
: mRoot(nsnull),
mStartOffset(0),
mEndOffset(0),
mIsPositioned(false),
mIsDetached(false),
mMaySpanAnonymousSubtrees(false),
mInSelection(false)
{
}
nsINode* GetRoot() const
{
return mRoot;
}
nsINode* GetStartParent() const
{
return mStartParent;
}
nsINode* GetEndParent() const
{
return mEndParent;
}
PRInt32 StartOffset() const
{
return mStartOffset;
}
PRInt32 EndOffset() const
{
return mEndOffset;
}
bool IsPositioned() const
{
return mIsPositioned;
}
bool IsDetached() const
{
return mIsDetached;
}
bool Collapsed() const
{
return mIsPositioned && mStartParent == mEndParent &&
mStartOffset == mEndOffset;
}
void SetMaySpanAnonymousSubtrees(bool aMaySpanAnonymousSubtrees)
{
mMaySpanAnonymousSubtrees = aMaySpanAnonymousSubtrees;
}
/**
* Return true iff this range is part of at least one Selection object
* and isn't detached.
*/
bool IsInSelection() const
{
return mInSelection;
}
/**
* Called when the range is added/removed from a Selection.
*/
void SetInSelection(bool aInSelection)
{
if (mInSelection == aInSelection || mIsDetached) {
return;
}
mInSelection = aInSelection;
nsINode* commonAncestor = GetCommonAncestor();
NS_ASSERTION(commonAncestor, "unexpected disconnected nodes");
if (mInSelection) {
RegisterCommonAncestor(commonAncestor);
} else {
UnregisterCommonAncestor(commonAncestor);
}
}
virtual nsINode* GetCommonAncestor() const = 0;
virtual void Reset() = 0;
// XXXbz we could make these non-virtual if a bunch of nsRange stuff
// became nsIRange stuff... and if no one outside layout needs them.
virtual nsresult SetStart(nsINode* aParent, PRInt32 aOffset) = 0;
virtual nsresult SetEnd(nsINode* aParent, PRInt32 aOffset) = 0;
virtual nsresult CloneRange(nsIRange** aNewRange) const = 0;
// Work around hiding warnings
NS_IMETHOD SetStart(nsIDOMNode* aParent, PRInt32 aOffset) = 0;
NS_IMETHOD SetEnd(nsIDOMNode* aParent, PRInt32 aOffset) = 0;
NS_IMETHOD CloneRange(nsIDOMRange** aNewRange) = 0;
// To support the font inspector API
NS_IMETHOD GetUsedFontFaces(nsIDOMFontFaceList** aResult) = 0;
typedef nsTHashtable<nsPtrHashKey<nsIRange> > RangeHashTable;
protected:
void RegisterCommonAncestor(nsINode* aNode);
void UnregisterCommonAncestor(nsINode* aNode);
nsINode* IsValidBoundary(nsINode* aNode);
nsCOMPtr<nsINode> mRoot;
nsCOMPtr<nsINode> mStartParent;
nsCOMPtr<nsINode> mEndParent;
PRInt32 mStartOffset;
PRInt32 mEndOffset;
bool mIsPositioned;
bool mIsDetached;
bool mMaySpanAnonymousSubtrees;
bool mInSelection;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIRange, NS_IRANGE_IID)
#endif /* nsIRange_h___ */

View File

@ -45,7 +45,7 @@
#include "nsISupports.h"
// Forward declarations
class nsIDOMRange;
class nsRange;
class nsIDOMNode;
class nsIContent;
@ -61,7 +61,7 @@ public:
nsIDOMNode* aParent2, PRInt32 aOffset2) = 0;
NS_IMETHOD CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
nsRange* aRange,
bool *outNodeBefore,
bool *outNodeAfter) = 0;
};

View File

@ -40,10 +40,11 @@
#include "nsIEnumerator.idl"
#include "nsISelection.idl"
interface nsIDOMRange;
interface nsRange;
interface nsIDOMNode;
interface nsISelectionListener;
interface nsIContent;
interface nsINode;
%{C++
class nsFrameSelection;
@ -52,13 +53,13 @@ class nsIPresShell;
struct nsTextRangeStyle;
struct nsPoint;
#include "nsIFrame.h"
#include "nsCOMArray.h"
#include "nsTArray.h"
%}
[ptr] native nsFrameSelection(nsFrameSelection);
[ptr] native nsIFrame(nsIFrame);
[ptr] native nsIPresShell(nsIPresShell);
[ptr] native RangeArray(nsCOMArray<nsIDOMRange>);
[ptr] native RangeArray(nsTArray<nsRange*>);
[ref] native constTextRangeStyleRef(const nsTextRangeStyle);
[ref] native nsPointRef(nsPoint);
native nsDirection(nsDirection);
@ -157,9 +158,9 @@ interface nsISelectionPrivate : nsISelection
out PRUint32 resultCount,
[retval, array, size_is(resultCount)] out nsIDOMRange results);
[noscript] void GetRangesForIntervalCOMArray(
in nsIDOMNode beginNode, in PRInt32 beginOffset,
in nsIDOMNode endNode, in PRInt32 endOffset,
[noscript] void GetRangesForIntervalArray(
in nsINode beginNode, in PRInt32 beginOffset,
in nsINode endNode, in PRInt32 endOffset,
in boolean allowAdjacent,
in RangeArray results);

View File

@ -58,6 +58,7 @@ EXPORTS = \
nsNodeInfoManager.h \
nsNodeUtils.h \
nsPropertyTable.h \
nsRange.h \
nsScriptLoader.h \
nsStubDocumentObserver.h \
nsStubImageDecoderObserver.h \

View File

@ -129,7 +129,6 @@ public:
virtual nsresult Init(nsINode* aRoot);
virtual nsresult Init(nsIDOMRange* aRange);
virtual nsresult Init(nsIRange* aRange);
virtual void First();
@ -303,34 +302,26 @@ nsContentIterator::Init(nsINode* aRoot)
return NS_OK;
}
nsresult
nsContentIterator::Init(nsIDOMRange* aRange)
nsContentIterator::Init(nsIDOMRange* aDOMRange)
{
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
return Init(range);
}
nsresult
nsContentIterator::Init(nsIRange* aRange)
{
NS_ENSURE_ARG_POINTER(aRange);
NS_ENSURE_ARG_POINTER(aDOMRange);
nsRange* range = static_cast<nsRange*>(aDOMRange);
mIsDone = false;
// get common content parent
mCommonParent = aRange->GetCommonAncestor();
mCommonParent = range->GetCommonAncestor();
NS_ENSURE_TRUE(mCommonParent, NS_ERROR_FAILURE);
// get the start node and offset
PRInt32 startIndx = aRange->StartOffset();
nsINode* startNode = aRange->GetStartParent();
PRInt32 startIndx = range->StartOffset();
nsINode* startNode = range->GetStartParent();
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
// get the end node and offset
PRInt32 endIndx = aRange->EndOffset();
nsINode* endNode = aRange->GetEndParent();
PRInt32 endIndx = range->EndOffset();
nsINode* endNode = range->GetEndParent();
NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
bool startIsData = startNode->IsNodeOfType(nsINode::eDATA_NODE);
@ -1179,7 +1170,6 @@ public:
virtual nsresult Init(nsINode* aRoot);
virtual nsresult Init(nsIDOMRange* aRange);
virtual nsresult Init(nsIRange* aRange);
virtual void Next();
@ -1202,7 +1192,7 @@ protected:
nsContentSubtreeIterator(const nsContentSubtreeIterator&);
nsContentSubtreeIterator& operator=(const nsContentSubtreeIterator&);
nsCOMPtr<nsIDOMRange> mRange;
nsRefPtr<nsRange> mRange;
// these arrays all typically are used and have elements
#if 0
nsAutoTArray<nsIContent*, 8> mStartNodes;
@ -1221,7 +1211,7 @@ NS_INTERFACE_MAP_END_INHERITING(nsContentIterator)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsContentSubtreeIterator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsContentSubtreeIterator, nsContentIterator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRange, nsIDOMRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsContentSubtreeIterator, nsContentIterator)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRange)
@ -1268,7 +1258,7 @@ nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange)
mIsDone = false;
mRange = aRange;
mRange = static_cast<nsRange*>(aRange);
// get the start node and offset, convert to nsINode
nsCOMPtr<nsIDOMNode> commonParent;
@ -1366,7 +1356,7 @@ nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange)
// does not fully contain any node.
bool nodeBefore, nodeAfter;
if (NS_FAILED(nsRange::CompareNodeToRange(firstCandidate, aRange,
if (NS_FAILED(nsRange::CompareNodeToRange(firstCandidate, mRange,
&nodeBefore, &nodeAfter)))
return NS_ERROR_FAILURE;
@ -1417,7 +1407,7 @@ nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange)
// is indeed contained. Else we have a range that
// does not fully contain any node.
if (NS_FAILED(nsRange::CompareNodeToRange(lastCandidate, aRange, &nodeBefore,
if (NS_FAILED(nsRange::CompareNodeToRange(lastCandidate, mRange, &nodeBefore,
&nodeAfter)))
return NS_ERROR_FAILURE;
@ -1438,12 +1428,6 @@ nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange)
return NS_OK;
}
nsresult nsContentSubtreeIterator::Init(nsIRange* aRange)
{
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(aRange);
return Init(range);
}
/****************************************************************
* nsContentSubtreeIterator overrides of ContentIterator routines
****************************************************************/

View File

@ -311,11 +311,9 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode,
// Make a temporary selection with aNode in a single range.
nsresult rv = NS_NewDomSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMRange> range;
rv = NS_NewRange(getter_AddRefs(range));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
nsRefPtr<nsRange> range = new nsRange();
rv = range->SelectNode(node);
NS_ENSURE_SUCCESS(rv, rv);
rv = selection->AddRange(range);

View File

@ -62,7 +62,7 @@
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMNodeList.h"
#include "nsIRange.h"
#include "nsRange.h"
#include "nsIDOMRange.h"
#include "nsIDOMDocument.h"
#include "nsICharsetConverterManager.h"
@ -113,9 +113,9 @@ protected:
// This serializes the content of aNode.
nsresult SerializeToStringIterative(nsINode* aNode,
nsAString& aStr);
nsresult SerializeRangeToString(nsIRange *aRange,
nsresult SerializeRangeToString(nsRange *aRange,
nsAString& aOutputString);
nsresult SerializeRangeNodes(nsIRange* aRange,
nsresult SerializeRangeNodes(nsRange* aRange,
nsINode* aNode,
nsAString& aString,
PRInt32 aDepth);
@ -155,7 +155,7 @@ protected:
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsISelection> mSelection;
nsCOMPtr<nsIRange> mRange;
nsRefPtr<nsRange> mRange;
nsCOMPtr<nsINode> mNode;
nsCOMPtr<nsIOutputStream> mStream;
nsCOMPtr<nsIContentSerializer> mSerializer;
@ -204,7 +204,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocumentEncoder)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSelection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRange, nsIDOMRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCommonParent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -289,7 +289,7 @@ nsDocumentEncoder::SetSelection(nsISelection* aSelection)
NS_IMETHODIMP
nsDocumentEncoder::SetRange(nsIDOMRange* aRange)
{
mRange = do_QueryInterface(aRange);
mRange = static_cast<nsRange*>(aRange);
return NS_OK;
}
@ -766,7 +766,7 @@ static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, PRUint32 &aCount)
}
nsresult
nsDocumentEncoder::SerializeRangeNodes(nsIRange* aRange,
nsDocumentEncoder::SerializeRangeNodes(nsRange* aRange,
nsINode* aNode,
nsAString& aString,
PRInt32 aDepth)
@ -937,7 +937,7 @@ nsDocumentEncoder::SerializeRangeContextEnd(const nsTArray<nsINode*>& aAncestorA
}
nsresult
nsDocumentEncoder::SerializeRangeToString(nsIRange *aRange,
nsDocumentEncoder::SerializeRangeToString(nsRange *aRange,
nsAString& aOutputString)
{
if (!aRange || aRange->Collapsed())
@ -1079,7 +1079,7 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
}
}
nsCOMPtr<nsIRange> r = do_QueryInterface(range);
nsRange* r = static_cast<nsRange*>(range.get());
rv = SerializeRangeToString(r, output);
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -92,7 +92,7 @@
#include "nsFrameManager.h"
#include "nsFrameSelection.h"
#ifdef DEBUG
#include "nsIRange.h"
#include "nsRange.h"
#endif
#include "nsBindingManager.h"
@ -4974,8 +4974,8 @@ nsGenericElement::List(FILE* out, PRInt32 aIndent,
fprintf(out, " state=[%llx]", State().GetInternalValue());
fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
if (IsCommonAncestorForRangeInSelection()) {
nsIRange::RangeHashTable* ranges =
static_cast<nsIRange::RangeHashTable*>(GetProperty(nsGkAtoms::range));
nsRange::RangeHashTable* ranges =
static_cast<nsRange::RangeHashTable*>(GetProperty(nsGkAtoms::range));
fprintf(out, " ranges:%d", ranges ? ranges->Count() : 0);
}
fprintf(out, " primaryframe=%p", static_cast<void*>(GetPrimaryFrame()));

View File

@ -119,19 +119,7 @@ static void InvalidateAllFrames(nsINode* aNode)
// static
nsresult
nsRange::CompareNodeToRange(nsINode* aNode, nsIDOMRange* aRange,
bool *outNodeBefore, bool *outNodeAfter)
{
nsresult rv;
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return CompareNodeToRange(aNode, range, outNodeBefore, outNodeAfter);
}
// static
nsresult
nsRange::CompareNodeToRange(nsINode* aNode, nsIRange* aRange,
nsRange::CompareNodeToRange(nsINode* aNode, nsRange* aRange,
bool *outNodeBefore, bool *outNodeAfter)
{
NS_ENSURE_STATE(aNode);
@ -186,15 +174,15 @@ nsRange::CompareNodeToRange(nsINode* aNode, nsIRange* aRange,
struct FindSelectedRangeData
{
nsINode* mNode;
nsIRange* mResult;
nsRange* mResult;
PRUint32 mStartOffset;
PRUint32 mEndOffset;
};
static PLDHashOperator
FindSelectedRange(nsPtrHashKey<nsIRange>* aEntry, void* userArg)
FindSelectedRange(nsPtrHashKey<nsRange>* aEntry, void* userArg)
{
nsIRange* range = aEntry->GetKey();
nsRange* range = aEntry->GetKey();
if (range->IsInSelection() && !range->Collapsed()) {
FindSelectedRangeData* data = static_cast<FindSelectedRangeData*>(userArg);
PRInt32 cmp = nsContentUtils::ComparePoints(data->mNode, data->mEndOffset,
@ -285,30 +273,13 @@ nsRangeUtils::ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
}
NS_IMETHODIMP
nsRangeUtils::CompareNodeToRange(nsIContent* aNode, nsIDOMRange* aRange,
nsRangeUtils::CompareNodeToRange(nsIContent* aNode, nsRange* aRange,
bool *outNodeBefore, bool *outNodeAfter)
{
return nsRange::CompareNodeToRange(aNode, aRange, outNodeBefore,
outNodeAfter);
}
/******************************************************
* non members
******************************************************/
nsresult
NS_NewRange(nsIDOMRange** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
nsRange * range = new nsRange();
if (!range) {
return NS_ERROR_OUT_OF_MEMORY;
}
return CallQueryInterface(range, aResult);
}
/******************************************************
* constructor/destructor
******************************************************/
@ -335,9 +306,8 @@ DOMCI_DATA(Range, nsRange)
// QueryInterface implementation for nsRange
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsRange)
NS_INTERFACE_MAP_ENTRY(nsIDOMRange)
NS_INTERFACE_MAP_ENTRY(nsIRange)
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRange)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMRange)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Range)
NS_INTERFACE_MAP_END
@ -355,8 +325,8 @@ static void
RangeHashTableDtor(void* aObject, nsIAtom* aPropertyName, void* aPropertyValue,
void* aData)
{
nsIRange::RangeHashTable* ranges =
static_cast<nsIRange::RangeHashTable*>(aPropertyValue);
nsRange::RangeHashTable* ranges =
static_cast<nsRange::RangeHashTable*>(aPropertyValue);
delete ranges;
}
@ -403,7 +373,7 @@ static void UnmarkDescendants(nsINode* aNode)
}
void
nsIRange::RegisterCommonAncestor(nsINode* aNode)
nsRange::RegisterCommonAncestor(nsINode* aNode)
{
NS_PRECONDITION(aNode, "bad arg");
NS_ASSERTION(IsInSelection(), "registering range not in selection");
@ -422,7 +392,7 @@ nsIRange::RegisterCommonAncestor(nsINode* aNode)
}
void
nsIRange::UnregisterCommonAncestor(nsINode* aNode)
nsRange::UnregisterCommonAncestor(nsINode* aNode)
{
NS_PRECONDITION(aNode, "bad arg");
NS_ASSERTION(aNode->IsCommonAncestorForRangeInSelection(), "wrong node");
@ -819,11 +789,7 @@ IndexOf(nsIDOMNode* aChildNode)
return parent ? parent->IndexOf(child) : -1;
}
/******************************************************
* nsIRange implementation
******************************************************/
/* virtual */ nsINode*
nsINode*
nsRange::GetCommonAncestor() const
{
return mIsPositioned ?
@ -831,7 +797,7 @@ nsRange::GetCommonAncestor() const
nsnull;
}
/* virtual */ void
void
nsRange::Reset()
{
DoSetRange(nsnull, 0, nsnull, 0, nsnull);
@ -911,7 +877,8 @@ nsRange::GetCommonAncestorContainer(nsIDOMNode** aCommonParent)
return NS_ERROR_NOT_INITIALIZED;
}
nsINode* nsIRange::IsValidBoundary(nsINode* aNode)
nsINode*
nsRange::IsValidBoundary(nsINode* aNode)
{
if (!aNode) {
return nsnull;
@ -1799,7 +1766,7 @@ NS_IMETHODIMP
nsRange::CompareBoundaryPoints(PRUint16 aHow, nsIDOMRange* aOtherRange,
PRInt16* aCmpRet)
{
nsCOMPtr<nsIRange> otherRange = do_QueryInterface(aOtherRange);
nsRange* otherRange = static_cast<nsRange*>(aOtherRange);
NS_ENSURE_TRUE(otherRange, NS_ERROR_NULL_POINTER);
if(mIsDetached || otherRange->IsDetached())
@ -2095,7 +2062,8 @@ nsRange::CloneContents(nsIDOMDocumentFragment** aReturn)
return NS_OK;
}
nsresult nsRange::DoCloneRange(nsIRange** aReturn) const
nsresult
nsRange::CloneRange(nsRange** aReturn) const
{
if(mIsDetached)
return NS_ERROR_DOM_INVALID_STATE_ERR;
@ -2104,33 +2072,25 @@ nsresult nsRange::DoCloneRange(nsIRange** aReturn) const
return NS_ERROR_NULL_POINTER;
nsRefPtr<nsRange> range = new nsRange();
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
range->SetMaySpanAnonymousSubtrees(mMaySpanAnonymousSubtrees);
range->DoSetRange(mStartParent, mStartOffset, mEndParent, mEndOffset, mRoot);
*aReturn = range.forget().get();
range.forget(aReturn);
return NS_OK;
}
NS_IMETHODIMP nsRange::CloneRange(nsIDOMRange** aReturn)
NS_IMETHODIMP
nsRange::CloneRange(nsIDOMRange** aReturn)
{
nsIRange* clone;
nsresult rv = DoCloneRange(&clone);
if (NS_SUCCEEDED(rv)) {
*aReturn = clone;
}
nsRefPtr<nsRange> range;
nsresult rv = CloneRange(getter_AddRefs(range));
range.forget(aReturn);
return rv;
}
/* virtual */ nsresult
nsRange::CloneRange(nsIRange** aReturn) const
{
return DoCloneRange(aReturn);
}
NS_IMETHODIMP
nsRange::InsertNode(nsIDOMNode* aN)
{
@ -2311,7 +2271,7 @@ nsRange::ToString(nsAString& aReturn)
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
rv = iter->Init(static_cast<nsIRange*>(this));
rv = iter->Init(this);
NS_ENSURE_SUCCESS(rv, rv);
nsString tempString;

View File

@ -42,7 +42,6 @@
#ifndef nsRange_h___
#define nsRange_h___
#include "nsIRange.h"
#include "nsIDOMRange.h"
#include "nsIRangeUtils.h"
#include "nsCOMPtr.h"
@ -52,44 +51,105 @@
#include "prmon.h"
#include "nsStubMutationObserver.h"
// -------------------------------------------------------------------------------
class nsRangeUtils : public nsIRangeUtils
{
public:
NS_DECL_ISUPPORTS
// nsIRangeUtils interface
NS_IMETHOD_(PRInt32) ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2);
NS_IMETHOD CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
bool *outNodeBefore,
bool *outNodeAfter);
};
// -------------------------------------------------------------------------------
class nsRange : public nsIRange,
class nsRange : public nsIDOMRange,
public nsStubMutationObserver
{
public:
nsRange(){}
nsRange()
: mRoot(nsnull)
, mStartOffset(0)
, mEndOffset(0)
, mIsPositioned(false)
, mIsDetached(false)
, mMaySpanAnonymousSubtrees(false)
, mInSelection(false)
{}
virtual ~nsRange();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsRange, nsIRange)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsRange, nsIDOMRange)
// nsIDOMRange interface
NS_DECL_NSIDOMRANGE
// nsIRange interface
virtual nsINode* GetCommonAncestor() const;
virtual void Reset();
virtual nsresult SetStart(nsINode* aParent, PRInt32 aOffset);
virtual nsresult SetEnd(nsINode* aParent, PRInt32 aOffset);
virtual nsresult CloneRange(nsIRange** aNewRange) const;
nsINode* GetRoot() const
{
return mRoot;
}
nsINode* GetStartParent() const
{
return mStartParent;
}
nsINode* GetEndParent() const
{
return mEndParent;
}
PRInt32 StartOffset() const
{
return mStartOffset;
}
PRInt32 EndOffset() const
{
return mEndOffset;
}
bool IsPositioned() const
{
return mIsPositioned;
}
bool IsDetached() const
{
return mIsDetached;
}
bool Collapsed() const
{
return mIsPositioned && mStartParent == mEndParent &&
mStartOffset == mEndOffset;
}
void SetMaySpanAnonymousSubtrees(bool aMaySpanAnonymousSubtrees)
{
mMaySpanAnonymousSubtrees = aMaySpanAnonymousSubtrees;
}
/**
* Return true iff this range is part of at least one Selection object
* and isn't detached.
*/
bool IsInSelection() const
{
return mInSelection;
}
/**
* Called when the range is added/removed from a Selection.
*/
void SetInSelection(bool aInSelection)
{
if (mInSelection == aInSelection || mIsDetached) {
return;
}
mInSelection = aInSelection;
nsINode* commonAncestor = GetCommonAncestor();
NS_ASSERTION(commonAncestor, "unexpected disconnected nodes");
if (mInSelection) {
RegisterCommonAncestor(commonAncestor);
} else {
UnregisterCommonAncestor(commonAncestor);
}
}
nsINode* GetCommonAncestor() const;
void Reset();
nsresult SetStart(nsINode* aParent, PRInt32 aOffset);
nsresult SetEnd(nsINode* aParent, PRInt32 aOffset);
nsresult CloneRange(nsRange** aNewRange) const;
nsresult Set(nsINode* aStartParent, PRInt32 aStartOffset,
nsINode* aEndParent, PRInt32 aEndOffset)
@ -124,11 +184,6 @@ private:
*/
nsresult CutContents(nsIDOMDocumentFragment** frag);
/**
* Guts of cloning a range. Addrefs the new range.
*/
nsresult DoCloneRange(nsIRange** aNewRange) const;
static nsresult CloneParentsBetween(nsIDOMNode *aAncestor,
nsIDOMNode *aNode,
nsIDOMNode **aClosestAncestor,
@ -142,17 +197,19 @@ public:
* XXX - callers responsibility to ensure node in same doc as range!
*
*****************************************************************************/
static nsresult CompareNodeToRange(nsINode* aNode, nsIDOMRange* aRange,
bool *outNodeBefore,
bool *outNodeAfter);
static nsresult CompareNodeToRange(nsINode* aNode, nsIRange* aRange,
static nsresult CompareNodeToRange(nsINode* aNode, nsRange* aRange,
bool *outNodeBefore,
bool *outNodeAfter);
static bool IsNodeSelected(nsINode* aNode, PRUint32 aStartOffset,
PRUint32 aEndOffset);
typedef nsTHashtable<nsPtrHashKey<nsRange> > RangeHashTable;
protected:
void RegisterCommonAncestor(nsINode* aNode);
void UnregisterCommonAncestor(nsINode* aNode);
nsINode* IsValidBoundary(nsINode* aNode);
// CharacterDataChanged set aNotInsertedYet to true to disable an assertion
// and suppress re-registering a range common ancestor node since
// the new text node of a splitText hasn't been inserted yet.
@ -194,10 +251,33 @@ protected:
static bool mIsNested;
};
nsCOMPtr<nsINode> mRoot;
nsCOMPtr<nsINode> mStartParent;
nsCOMPtr<nsINode> mEndParent;
PRInt32 mStartOffset;
PRInt32 mEndOffset;
bool mIsPositioned;
bool mIsDetached;
bool mMaySpanAnonymousSubtrees;
bool mInSelection;
};
// Make a new nsIDOMRange object
nsresult NS_NewRange(nsIDOMRange** aInstancePtrResult);
class nsRangeUtils : public nsIRangeUtils
{
public:
NS_DECL_ISUPPORTS
// nsIRangeUtils interface
NS_IMETHOD_(PRInt32) ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2);
NS_IMETHOD CompareNodeToRange(nsIContent* aNode,
nsRange* aRange,
bool *outNodeBefore,
bool *outNodeAfter);
};
// Make a new nsIRangeUtils object
nsresult NS_NewRangeUtils(nsIRangeUtils** aInstancePtrResult);

View File

@ -47,7 +47,7 @@
#include "nsIDocument.h"
#include "nsThreadUtils.h"
#ifdef DEBUG
#include "nsIRange.h"
#include "nsRange.h"
#endif
using namespace mozilla::dom;
@ -228,7 +228,7 @@ nsTextNode::List(FILE* out, PRInt32 aIndent) const
fprintf(out, "Text@%p", static_cast<const void*>(this));
fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
if (IsCommonAncestorForRangeInSelection()) {
typedef nsTHashtable<nsPtrHashKey<nsIRange> > RangeHashTable;
typedef nsTHashtable<nsPtrHashKey<nsRange> > RangeHashTable;
RangeHashTable* ranges =
static_cast<RangeHashTable*>(GetProperty(nsGkAtoms::range));
fprintf(out, " ranges:%d", ranges ? ranges->Count() : 0);

View File

@ -98,8 +98,7 @@ nsContentEventHandler::InitCommon()
// This shell doesn't support selection.
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
mFirstSelectedRange = do_QueryInterface(firstRange);
NS_ENSURE_TRUE(mFirstSelectedRange, NS_ERROR_FAILURE);
mFirstSelectedRange = static_cast<nsRange*>(firstRange.get());
nsINode* startNode = mFirstSelectedRange->GetStartParent();
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
@ -280,16 +279,14 @@ static PRUint32 ConvertToXPOffset(nsIContent* aContent, PRUint32 aNativeOffset)
#endif
}
static nsresult GenerateFlatTextContent(nsIRange* aRange,
static nsresult GenerateFlatTextContent(nsRange* aRange,
nsAFlatString& aString)
{
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(aRange));
NS_ASSERTION(domRange, "aRange doesn't have nsIDOMRange!");
iter->Init(domRange);
iter->Init(aRange);
NS_ASSERTION(aString.IsEmpty(), "aString must be empty string");
@ -374,7 +371,7 @@ nsContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent,
nsresult
nsContentEventHandler::SetRangeFromFlatTextOffset(
nsIRange* aRange,
nsRange* aRange,
PRUint32 aNativeOffset,
PRUint32 aNativeLength,
bool aExpandToClusterBoundaries)
@ -385,8 +382,6 @@ nsContentEventHandler::SetRangeFromFlatTextOffset(
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
rv = iter->Init(mRootContent);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(aRange));
NS_ASSERTION(domRange, "aRange doesn't have nsIDOMRange!");
PRUint32 nativeOffset = 0;
PRUint32 nativeEndOffset = aNativeOffset + aNativeLength;
@ -416,11 +411,11 @@ nsContentEventHandler::SetRangeFromFlatTextOffset(
NS_ENSURE_SUCCESS(rv, rv);
}
rv = domRange->SetStart(domNode, PRInt32(xpOffset));
rv = aRange->SetStart(domNode, PRInt32(xpOffset));
NS_ENSURE_SUCCESS(rv, rv);
if (aNativeLength == 0) {
// Ensure that the end offset and the start offset are same.
rv = domRange->SetEnd(domNode, PRInt32(xpOffset));
rv = aRange->SetEnd(domNode, PRInt32(xpOffset));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -446,7 +441,7 @@ nsContentEventHandler::SetRangeFromFlatTextOffset(
domNode = do_QueryInterface(iter->GetCurrentNode());
}
rv = domRange->SetEnd(domNode, PRInt32(xpOffset));
rv = aRange->SetEnd(domNode, PRInt32(xpOffset));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -460,10 +455,10 @@ nsContentEventHandler::SetRangeFromFlatTextOffset(
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mRootContent));
NS_ASSERTION(domNode, "lastContent doesn't have nsIDOMNode!");
if (!content) {
rv = domRange->SetStart(domNode, 0);
rv = aRange->SetStart(domNode, 0);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = domRange->SetEnd(domNode, PRInt32(mRootContent->GetChildCount()));
rv = aRange->SetEnd(domNode, PRInt32(mRootContent->GetChildCount()));
NS_ASSERTION(NS_SUCCEEDED(rv), "nsIDOMRange::SetEnd failed");
return rv;
}
@ -503,8 +498,7 @@ nsContentEventHandler::OnQuerySelectedText(nsQueryContentEvent* aEvent)
aEvent->mReply.mReversed = compare > 0;
if (compare) {
nsCOMPtr<nsIRange> range = mFirstSelectedRange;
rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
rv = GenerateFlatTextContent(mFirstSelectedRange, aEvent->mReply.mString);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -522,8 +516,7 @@ nsContentEventHandler::OnQueryTextContent(nsQueryContentEvent* aEvent)
NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
"The reply string must be empty");
nsCOMPtr<nsIRange> range = new nsRange();
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsRange> range = new nsRange();
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
aEvent->mInput.mLength, false);
NS_ENSURE_SUCCESS(rv, rv);
@ -580,10 +573,7 @@ nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent)
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIRange> range = new nsRange();
if (!range) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsRefPtr<nsRange> range = new nsRange();
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
aEvent->mInput.mLength, true);
NS_ENSURE_SUCCESS(rv, rv);
@ -728,8 +718,7 @@ nsContentEventHandler::OnQueryCaretRect(nsQueryContentEvent* aEvent)
}
// Otherwise, we should set the guessed caret rect.
nsCOMPtr<nsIRange> range = new nsRange();
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsRange> range = new nsRange();
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, 0, true);
NS_ENSURE_SUCCESS(rv, rv);
@ -916,22 +905,19 @@ nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
{
NS_ASSERTION(aNativeOffset, "param is invalid");
nsCOMPtr<nsIRange> prev = new nsRange();
NS_ENSURE_TRUE(prev, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIDOMRange> domPrev(do_QueryInterface(prev));
NS_ASSERTION(domPrev, "nsRange doesn't have nsIDOMRange??");
nsRefPtr<nsRange> prev = new nsRange();
nsCOMPtr<nsIDOMNode> rootDOMNode(do_QueryInterface(aRootContent));
domPrev->SetStart(rootDOMNode, 0);
prev->SetStart(rootDOMNode, 0);
nsCOMPtr<nsIDOMNode> startDOMNode(do_QueryInterface(aNode));
NS_ASSERTION(startDOMNode, "startNode doesn't have nsIDOMNode");
domPrev->SetEnd(startDOMNode, aNodeOffset);
prev->SetEnd(startDOMNode, aNodeOffset);
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
iter->Init(domPrev);
iter->Init(prev);
nsCOMPtr<nsINode> startNode = do_QueryInterface(startDOMNode);
nsINode* endNode = aNode;
@ -964,7 +950,7 @@ nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
nsresult
nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
nsIRange* aRange,
nsRange* aRange,
PRUint32* aNativeOffset)
{
nsINode* startNode = aRange->GetStartParent();
@ -975,7 +961,7 @@ nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
}
nsresult
nsContentEventHandler::GetStartFrameAndOffset(nsIRange* aRange,
nsContentEventHandler::GetStartFrameAndOffset(nsRange* aRange,
nsIFrame** aFrame,
PRInt32* aOffsetInFrame)
{

View File

@ -44,7 +44,7 @@
#include "nsCOMPtr.h"
#include "nsISelection.h"
#include "nsIRange.h"
#include "nsRange.h"
#include "nsIContent.h"
#include "nsIDOMTreeWalker.h"
@ -93,7 +93,7 @@ protected:
nsPresContext* mPresContext;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsISelection> mSelection;
nsCOMPtr<nsIRange> mFirstSelectedRange;
nsRefPtr<nsRange> mFirstSelectedRange;
nsCOMPtr<nsIContent> mRootContent;
nsresult Init(nsQueryContentEvent* aEvent);
@ -112,19 +112,19 @@ public:
PRInt32 aNodeOffset,
PRUint32* aOffset);
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
nsIRange* aRange,
nsRange* aRange,
PRUint32* aOffset);
protected:
// Make the DOM range from the offset of FlatText and the text length.
// If aExpandToClusterBoundaries is true, the start offset and the end one are
// expanded to nearest cluster boundaries.
nsresult SetRangeFromFlatTextOffset(nsIRange* aRange,
nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
PRUint32 aNativeOffset,
PRUint32 aNativeLength,
bool aExpandToClusterBoundaries);
// Find the first textframe for the range, and get the start offset in
// the frame.
nsresult GetStartFrameAndOffset(nsIRange* aRange,
nsresult GetStartFrameAndOffset(nsRange* aRange,
nsIFrame** aFrame,
PRInt32* aOffsetInFrame);
// Convert the frame relative offset to the root view relative offset.

View File

@ -492,7 +492,7 @@ nsTextStateManager::Init(nsIWidget* aWidget,
rv = sel->GetRangeAt(0, getter_AddRefs(selDomRange));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIRange> selRange(do_QueryInterface(selDomRange));
nsRange* selRange = static_cast<nsRange*>(selDomRange.get());
NS_ENSURE_TRUE(selRange && selRange->GetStartParent(),
NS_ERROR_UNEXPECTED);

View File

@ -2664,7 +2664,7 @@ nsIContent* nsHTMLMediaElement::GetNextSource()
nsresult rv = NS_OK;
if (!mSourcePointer) {
// First time this has been run, create a selection to cover children.
mSourcePointer = do_CreateInstance("@mozilla.org/content/range;1");
mSourcePointer = new nsRange();
rv = mSourcePointer->SelectNodeContents(thisDomNode);
if (NS_FAILED(rv)) return nsnull;

View File

@ -2526,10 +2526,7 @@ nsHTMLDocument::DeferredContentEditableCountChange(nsIContent *aElement)
nsCOMPtr<nsIEditor> editor;
editorDocShell->GetEditor(getter_AddRefs(editor));
if (editor) {
nsCOMPtr<nsIDOMRange> range;
rv = NS_NewRange(getter_AddRefs(range));
NS_ENSURE_SUCCESS(rv, );
nsRefPtr<nsRange> range = new nsRange();
rv = range->SelectNode(node);
if (NS_FAILED(rv)) {
// The node might be detached from the document at this point,

View File

@ -46,7 +46,7 @@
* http://www.w3.org/TR/DOM-Level-2-Traversal-Range/
*/
[scriptable, uuid(a059eea8-fece-4c14-93d3-7f50a944ae43)]
[scriptable, builtinclass, uuid(a059eea8-fece-4c14-93d3-7f50a944ae43)]
interface nsIDOMRange : nsISupports
{
readonly attribute nsIDOMNode startContainer;

View File

@ -96,8 +96,6 @@ using mozilla::DefaultXDisplay;
#include "nsIScrollableFrame.h"
#include "nsContentCID.h"
static NS_DEFINE_CID(kRangeCID, NS_RANGE_CID);
#include "nsWidgetsCID.h"
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
@ -833,10 +831,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetTagText(const char* *result)
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID,&rv));
if (NS_FAILED(rv))
return rv;
nsRefPtr<nsRange> range = new nsRange();
rv = range->SelectNode(node);
if (NS_FAILED(rv))
return rv;

View File

@ -38,7 +38,7 @@
#include "IMETextTxn.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMRange.h"
#include "nsRange.h"
#include "nsIPrivateTextRange.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
@ -338,12 +338,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void)
if(NS_FAILED(result))
break;
nsCOMPtr<nsIDOMRange> newRange = do_CreateInstance(
"@mozilla.org/content/range;1", &result);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot create new nsIDOMRange");
if(NS_FAILED(result))
break;
nsRefPtr<nsRange> newRange = new nsRange();
result = newRange->SetStart(mElement,mOffset+selectionStart);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetStart");
if(NS_FAILED(result))

View File

@ -4980,13 +4980,9 @@ nsEditor::CreateRange(nsIDOMNode *aStartParent, PRInt32 aStartOffset,
nsIDOMNode *aEndParent, PRInt32 aEndOffset,
nsIDOMRange **aRange)
{
nsresult result;
result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
NS_ENSURE_SUCCESS(result, result);
NS_ADDREF(*aRange = new nsRange());
NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
result = (*aRange)->SetStart(aStartParent, aStartOffset);
nsresult result = (*aRange)->SetStart(aStartParent, aStartOffset);
if (NS_SUCCEEDED(result))
result = (*aRange)->SetEnd(aEndParent, aEndOffset);

View File

@ -38,7 +38,7 @@
#include "nsSelectionState.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsRange.h"
#include "nsISelection.h"
#include "nsEditor.h"
#include "nsEditorUtils.h"
@ -122,8 +122,8 @@ nsSelectionState::RestoreSelection(nsISelection *aSel)
// set the selection ranges anew
for (i=0; i<arrayCount; i++)
{
nsCOMPtr<nsIDOMRange> range;
mArray[i].GetRange(address_of(range));
nsRefPtr<nsRange> range;
mArray[i].GetRange(getter_AddRefs(range));
NS_ENSURE_TRUE(range, NS_ERROR_UNEXPECTED);
res = aSel->AddRange(range);
@ -137,8 +137,8 @@ bool
nsSelectionState::IsCollapsed()
{
if (1 != mArray.Length()) return false;
nsCOMPtr<nsIDOMRange> range;
mArray[0].GetRange(address_of(range));
nsRefPtr<nsRange> range;
mArray[0].GetRange(getter_AddRefs(range));
NS_ENSURE_TRUE(range, false);
bool bIsCollapsed = false;
range->GetCollapsed(&bIsCollapsed);
@ -155,9 +155,9 @@ nsSelectionState::IsEqual(nsSelectionState *aSelState)
for (i=0; i<myCount; i++)
{
nsCOMPtr<nsIDOMRange> myRange, itsRange;
mArray[i].GetRange(address_of(myRange));
aSelState->mArray[i].GetRange(address_of(itsRange));
nsRefPtr<nsRange> myRange, itsRange;
mArray[i].GetRange(getter_AddRefs(myRange));
aSelState->mArray[i].GetRange(getter_AddRefs(itsRange));
NS_ENSURE_TRUE(myRange && itsRange, false);
PRInt16 compResult;
@ -700,14 +700,13 @@ nsresult nsRangeStore::StoreRange(nsIDOMRange *aRange)
return NS_OK;
}
nsresult nsRangeStore::GetRange(nsCOMPtr<nsIDOMRange> *outRange)
nsresult nsRangeStore::GetRange(nsRange** outRange)
{
NS_ENSURE_TRUE(outRange, NS_ERROR_NULL_POINTER);
nsresult res;
*outRange = do_CreateInstance("@mozilla.org/content/range;1", &res);
if(NS_FAILED(res)) return res;
*outRange = new nsRange();
NS_ADDREF((*outRange));
res = (*outRange)->SetStart(startNode, startOffset);
nsresult res = (*outRange)->SetStart(startNode, startOffset);
if(NS_FAILED(res)) return res;
res = (*outRange)->SetEnd(endNode, endOffset);

View File

@ -46,6 +46,7 @@
class nsIDOMCharacterData;
class nsISelection;
class nsRange;
/***************************************************************************
* class for recording selection info. stores selection as collection of
@ -59,7 +60,7 @@ struct nsRangeStore
nsRangeStore();
~nsRangeStore();
nsresult StoreRange(nsIDOMRange *aRange);
nsresult GetRange(nsCOMPtr<nsIDOMRange> *outRange);
nsresult GetRange(nsRange** outRange);
nsCOMPtr<nsIDOMNode> startNode;
PRInt32 startOffset;

View File

@ -2656,10 +2656,7 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode,
aEndOffset = fragLen;
}
nsCOMPtr<nsIDOMRange> docFragRange =
do_CreateInstance("@mozilla.org/content/range;1");
NS_ENSURE_TRUE(docFragRange, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsRange> docFragRange = new nsRange();
res = docFragRange->SetStart(aStartNode, aStartOffset);
NS_ENSURE_SUCCESS(res, res);
res = docFragRange->SetEnd(aEndNode, aEndOffset);

View File

@ -64,7 +64,7 @@
#include "nsIDOMCharacterData.h"
#include "nsIEnumerator.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIRange.h"
#include "nsRange.h"
#include "nsEditorUtils.h"
#include "nsWSRunObject.h"
@ -252,8 +252,7 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor)
mReturnInEmptyLIKillsList = !returnInEmptyLIKillsList.EqualsLiteral("false");
// make a utility range for use by the listenter
mUtilRange = do_CreateInstance("@mozilla.org/content/range;1");
NS_ENSURE_TRUE(mUtilRange, NS_ERROR_NULL_POINTER);
mUtilRange = new nsRange();
// set up mDocChangeRange to be whole doc
nsCOMPtr<nsIDOMElement> rootElem = do_QueryInterface(mHTMLEditor->GetRoot());
@ -263,8 +262,7 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor)
nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this);
if (!mDocChangeRange)
{
mDocChangeRange = do_CreateInstance("@mozilla.org/content/range;1");
NS_ENSURE_TRUE(mDocChangeRange, NS_ERROR_NULL_POINTER);
mDocChangeRange = new nsRange();
}
mDocChangeRange->SelectNode(rootElem);
res = AdjustSpecialBreaks();
@ -300,7 +298,7 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
// remember where our selection was before edit action took place:
// get selection
nsCOMPtr<nsISelection>selection;
nsCOMPtr<nsISelection> selection;
nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(res, res);
@ -328,14 +326,12 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
if(mDocChangeRange)
{
// clear out our accounting of what changed
nsCOMPtr<nsIRange> range = do_QueryInterface(mDocChangeRange);
range->Reset();
mDocChangeRange->Reset();
}
if(mUtilRange)
{
// ditto for mUtilRange.
nsCOMPtr<nsIRange> range = do_QueryInterface(mUtilRange);
range->Reset();
mUtilRange->Reset();
}
// remember current inline styles for deletion and normal insertion operations
@ -594,7 +590,7 @@ nsHTMLEditRules::WillDoAction(nsISelection *aSelection,
return NS_OK;
}
nsCOMPtr<nsIRange> range = do_QueryInterface(domRange);
nsRange* range = static_cast<nsRange*>(domRange.get());
nsCOMPtr<nsIDOMNode> ancestor =
do_QueryInterface(range->GetCommonAncestor());
if (!mHTMLEditor->IsModifiableNode(ancestor))
@ -1488,8 +1484,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
// the correct portion of the document.
if (!mDocChangeRange)
{
mDocChangeRange = do_CreateInstance("@mozilla.org/content/range;1");
NS_ENSURE_TRUE(mDocChangeRange, NS_ERROR_NULL_POINTER);
mDocChangeRange = new nsRange();
}
res = mDocChangeRange->SetStart(selNode, selOffset);
NS_ENSURE_SUCCESS(res, res);
@ -5255,8 +5250,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
bool nodeBefore=false, nodeAfter=false;
// create a range that represents expanded selection
nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
nsRefPtr<nsRange> range = new nsRange();
res = range->SetStart(selStartNode, selStartOffset);
NS_ENSURE_SUCCESS(res, res);
res = range->SetEnd(selEndNode, selEndOffset);
@ -5896,7 +5890,9 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
{
nsRangeStore *item = rangeItemArray.Elements() + i;
mHTMLEditor->mRangeUpdater.DropRangeItem(item);
nsresult res2 = item->GetRange(address_of(opRange));
nsRefPtr<nsRange> range;
nsresult res2 = item->GetRange(getter_AddRefs(range));
opRange = range;
if (NS_FAILED(res2) && NS_SUCCEEDED(res)) {
// Remember the failure, but keep going so we make sure to unregister
// all our range items.
@ -6414,7 +6410,7 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point,
point.GetPoint(node, offset);
// use it to make a range
nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
nsRefPtr<nsRange> range = new nsRange();
res = range->SetStart(node, offset);
NS_ENSURE_SUCCESS(res, res);
/* SetStart() will also set the end for this new range
@ -7634,7 +7630,7 @@ nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection)
temp = selNode;
// use ranges and sRangeHelper to compare sel point to new block
nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
nsRefPtr<nsRange> range = new nsRange();
res = range->SetStart(selNode, selOffset);
NS_ENSURE_SUCCESS(res, res);
res = range->SetEnd(selNode, selOffset);
@ -8429,9 +8425,10 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange)
if (!mDocChangeRange)
{
// clone aRange.
res = aRange->CloneRange(getter_AddRefs(mDocChangeRange));
return res;
// clone aRange.
nsCOMPtr<nsIDOMRange> range;
res = aRange->CloneRange(getter_AddRefs(range));
mDocChangeRange = static_cast<nsRange*>(range.get());
}
else
{

View File

@ -50,6 +50,7 @@
#include "TypeInState.h"
#include "nsReadableUtils.h"
#include "nsTArray.h"
#include "nsRange.h"
class nsIDOMElement;
class nsIEditor;
@ -303,13 +304,13 @@ protected:
// data members
protected:
nsHTMLEditor *mHTMLEditor;
nsCOMPtr<nsIDOMRange> mDocChangeRange;
nsRefPtr<nsRange> mDocChangeRange;
bool mListenerEnabled;
bool mReturnInEmptyLIKillsList;
bool mDidDeleteSelection;
bool mDidRangedDelete;
bool mRestoreContentEditableCount;
nsCOMPtr<nsIDOMRange> mUtilRange;
nsRefPtr<nsRange> mUtilRange;
PRUint32 mJoinOffset; // need to remember an int across willJoin/didJoin...
nsCOMPtr<nsIDOMNode> mNewBlock;
nsRangeStore mRangeItem;

View File

@ -44,6 +44,7 @@
#include "nsIDOMCharacterData.h"
#include "nsCRT.h"
#include "nsIRangeUtils.h"
#include "nsRange.h"
const PRUnichar nbsp = 160;
@ -1550,7 +1551,7 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset,
// then just go through them from the beginning.
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIDOMCharacterData> textnode;
nsCOMPtr<nsIDOMRange> range;
nsRefPtr<nsRange> range;
if (aStartNode == aEndNode)
{
@ -1593,8 +1594,7 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset,
{
if (!range)
{
range = do_CreateInstance("@mozilla.org/content/range;1");
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
range = new nsRange();
res = range->SetStart(aStartNode, aStartOffset);
NS_ENSURE_SUCCESS(res, res);
res = range->SetEnd(aEndNode, aEndOffset);

View File

@ -45,8 +45,6 @@
#include "nsTextServicesDocument.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsIRange.h"
//------------------------------------------------------------
nsFilteredContentIterator::nsFilteredContentIterator(nsITextServicesFilter* aFilter) :
@ -91,18 +89,15 @@ nsFilteredContentIterator::Init(nsINode* aRoot)
mDirection = eForward;
mCurrentIterator = mPreIterator;
nsresult rv;
mRange = do_CreateInstance("@mozilla.org/content/range;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(mRange));
mRange = new nsRange();
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aRoot));
if (domRange && domNode) {
domRange->SelectNode(domNode);
if (domNode) {
mRange->SelectNode(domNode);
}
rv = mPreIterator->Init(domRange);
nsresult rv = mPreIterator->Init(mRange);
NS_ENSURE_SUCCESS(rv, rv);
return mIterator->Init(domRange);
return mIterator->Init(mRange);
}
//------------------------------------------------------------
@ -126,13 +121,6 @@ nsFilteredContentIterator::Init(nsIDOMRange* aRange)
return mIterator->Init(domRange);
}
nsresult
nsFilteredContentIterator::Init(nsIRange* aRange)
{
nsCOMPtr<nsIDOMRange> domRange = do_QueryInterface(aRange);
return Init(domRange);
}
//------------------------------------------------------------
nsresult
nsFilteredContentIterator::SwitchDirections(bool aChangeToForward)
@ -287,10 +275,10 @@ ContentIsInTraversalRange(nsIDOMRange *aRange, nsIDOMNode* aNextNode, bool aIsPr
nsCOMPtr<nsIDOMNode> eNode;
PRInt32 sOffset;
PRInt32 eOffset;
range->GetStartContainer(getter_AddRefs(sNode));
range->GetStartOffset(&sOffset);
range->GetEndContainer(getter_AddRefs(eNode));
range->GetEndOffset(&eOffset);
aRange->GetStartContainer(getter_AddRefs(sNode));
aRange->GetStartOffset(&sOffset);
aRange->GetEndContainer(getter_AddRefs(eNode));
aRange->GetEndOffset(&eOffset);
return ContentIsInTraversalRange(content, aIsPreMode, sNode, sOffset, eNode, eOffset);
}

View File

@ -42,7 +42,7 @@
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsITextServicesFilter.h"
#include "nsIDOMRange.h"
#include "nsRange.h"
#include "nsIRangeUtils.h"
#include "nsCycleCollectionParticipant.h"
@ -64,7 +64,6 @@ public:
/* nsIContentIterator */
virtual nsresult Init(nsINode* aRoot);
virtual nsresult Init(nsIDOMRange* aRange);
virtual nsresult Init(nsIRange* aRange);
virtual void First();
virtual void Last();
virtual void Next();

View File

@ -2122,10 +2122,8 @@ nsTextServicesDocument::CreateDocumentContentRange(nsIDOMRange **aRange)
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
*aRange = new nsRange();
NS_ADDREF(*aRange);
result = (*aRange)->SelectNodeContents(node);
@ -2202,8 +2200,8 @@ nsTextServicesDocument::CreateDocumentContentRootToNodeOffsetRange(nsIDOMNode *a
}
}
result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
NS_ENSURE_SUCCESS(result, result);
*aRange = new nsRange();
NS_ADDREF((*aRange));
NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
@ -3314,14 +3312,9 @@ nsTextServicesDocument::CreateRange(nsIDOMNode *aStartParent, PRInt32 aStartOffs
nsIDOMNode *aEndParent, PRInt32 aEndOffset,
nsIDOMRange **aRange)
{
nsresult result;
NS_ADDREF(*aRange = new nsRange());
result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
result = (*aRange)->SetStart(aStartParent, aStartOffset);
nsresult result = (*aRange)->SetStart(aStartParent, aStartOffset);
if (NS_SUCCEEDED(result))
result = (*aRange)->SetEnd(aEndParent, aEndOffset);

View File

@ -61,14 +61,13 @@
#include "nsIDOMElement.h"
#include "nsIWordBreaker.h"
#include "nsCRT.h"
#include "nsIRange.h"
#include "nsRange.h"
// Yikes! Casting a char to unichar can fill with ones!
#define CHAR_TO_UNICHAR(c) ((PRUnichar)(const unsigned char)c)
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_CID(kCPreContentIteratorCID, NS_PRECONTENTITERATOR_CID);
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
#define CH_SHY ((PRUnichar) 0xAD)
@ -133,11 +132,6 @@ public:
NS_NOTREACHED("internal error");
return NS_ERROR_NOT_IMPLEMENTED;
}
virtual nsresult Init(nsIRange* aRange)
{
NS_NOTREACHED("internal error");
return NS_ERROR_NOT_IMPLEMENTED;
}
// Not a range because one of the endpoints may be anonymous.
nsresult Init(nsIDOMNode* aStartNode, PRInt32 aStartOffset,
nsIDOMNode* aEndNode, PRInt32 aEndOffset);
@ -1320,14 +1314,7 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange,
already_AddRefed<nsIDOMRange>
nsFind::CreateRange()
{
nsCOMPtr<nsIRange> range = do_CreateInstance(kRangeCID);
if (!range) {
return nsnull;
}
nsRefPtr<nsRange> range = new nsRange();
range->SetMaySpanAnonymousSubtrees(true);
nsIDOMRange* result;
CallQueryInterface(range.get(), &result);
return result;
return range.forget();
}

View File

@ -78,7 +78,7 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMRange.h"
#include "nsRange.h"
#include "nsIPlaintextEditor.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
@ -279,7 +279,7 @@ mozInlineSpellStatus::InitForSelection()
// a change operation over the given range.
nsresult
mozInlineSpellStatus::InitForRange(nsIRange* aRange)
mozInlineSpellStatus::InitForRange(nsRange* aRange)
{
mOp = eOpChange;
mRange = aRange;
@ -369,7 +369,7 @@ mozInlineSpellStatus::FinishNavigationEvent(mozInlineSpellWordUtil& aWordUtil)
// find the word on the old caret position, this is the one that we MAY need
// to check
nsCOMPtr<nsIRange> oldWord;
nsRefPtr<nsRange> oldWord;
rv = aWordUtil.GetRangeForWord(oldAnchorNode, oldAnchorOffset,
getter_AddRefs(oldWord));
NS_ENSURE_SUCCESS(rv, rv);
@ -789,7 +789,7 @@ mozInlineSpellChecker::SpellCheckRange(nsIDOMRange* aRange)
NS_ENSURE_TRUE(mSpellCheck, NS_ERROR_NOT_INITIALIZED);
mozInlineSpellStatus status(this);
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
nsRange* range = static_cast<nsRange*>(aRange);
nsresult rv = status.InitForRange(range);
NS_ENSURE_SUCCESS(rv, rv);
return ScheduleSpellCheck(status);
@ -872,8 +872,7 @@ mozInlineSpellChecker::RemoveWordFromDictionary(const nsAString &word)
NS_ENSURE_SUCCESS(rv, rv);
mozInlineSpellStatus status(this);
nsCOMPtr<nsIRange> range = do_QueryInterface(NULL); // Check everything
rv = status.InitForRange(range);
rv = status.InitForRange(nsnull);
NS_ENSURE_SUCCESS(rv, rv);
return ScheduleSpellCheck(status);
}
@ -1014,7 +1013,7 @@ nsresult
mozInlineSpellChecker::MakeSpellCheckRange(
nsIDOMNode* aStartNode, PRInt32 aStartOffset,
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
nsIRange** aRange)
nsRange** aRange)
{
nsresult rv;
*aRange = nsnull;
@ -1069,7 +1068,7 @@ mozInlineSpellChecker::MakeSpellCheckRange(
rv = range->SetEndAfter(aEndNode);
NS_ENSURE_SUCCESS(rv, rv);
CallQueryInterface(range, aRange);
*aRange = static_cast<nsRange*>(range.forget().get());
return NS_OK;
}
@ -1079,7 +1078,7 @@ mozInlineSpellChecker::SpellCheckBetweenNodes(nsIDOMNode *aStartNode,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset)
{
nsCOMPtr<nsIRange> range;
nsRefPtr<nsRange> range;
nsresult rv = MakeSpellCheckRange(aStartNode, aStartOffset,
aEndNode, aEndOffset,
getter_AddRefs(range));
@ -1244,7 +1243,7 @@ mozInlineSpellChecker::DoSpellCheckSelection(mozInlineSpellWordUtil& aWordUtil,
// check range over it that needs to be deleted. All the old ranges
// were cleared above. We also need to clear the word count so that we
// check all words instead of stopping early.
status.mRange = do_QueryInterface(checkRange);
status.mRange = static_cast<nsRange*>(checkRange.get());
rv = DoSpellCheck(aWordUtil, aSpellCheckSelection, &status,
&doneChecking);
NS_ENSURE_SUCCESS(rv, rv);
@ -1347,7 +1346,7 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
PRTime beginTime = PR_Now();
nsAutoString wordText;
nsCOMPtr<nsIRange> wordRange;
nsRefPtr<nsRange> wordRange;
bool dontCheckWord;
while (NS_SUCCEEDED(aWordUtil.GetNextWord(wordText,
getter_AddRefs(wordRange),
@ -1381,12 +1380,14 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
if (aStatus->mCreatedRange)
aStatus->mCreatedRange->IsPointInRange(beginNode, beginOffset, &inCreatedRange);
if (! inCreatedRange) {
nsCOMArray<nsIDOMRange> ranges;
rv = privSel->GetRangesForIntervalCOMArray(beginNode, beginOffset,
endNode, endOffset,
true, &ranges);
nsTArray<nsRange*> ranges;
nsCOMPtr<nsINode> firstNode = do_QueryInterface(beginNode);
nsCOMPtr<nsINode> lastNode = do_QueryInterface(endNode);
rv = privSel->GetRangesForIntervalArray(firstNode, beginOffset,
lastNode, endOffset,
true, &ranges);
NS_ENSURE_SUCCESS(rv, rv);
for (PRInt32 i = 0; i < ranges.Count(); i ++)
for (PRUint32 i = 0; i < ranges.Length(); i++)
RemoveRange(aSpellCheckSelection, ranges[i]);
}
}
@ -1545,12 +1546,13 @@ mozInlineSpellChecker::IsPointInSelection(nsISelection *aSelection,
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(aSelection));
nsCOMArray<nsIDOMRange> ranges;
nsresult rv = privSel->GetRangesForIntervalCOMArray(aNode, aOffset, aNode, aOffset,
true, &ranges);
nsTArray<nsRange*> ranges;
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
nsresult rv = privSel->GetRangesForIntervalArray(node, aOffset, node, aOffset,
true, &ranges);
NS_ENSURE_SUCCESS(rv, rv);
if (ranges.Count() == 0)
if (ranges.Length() == 0)
return NS_OK; // no matches
// there may be more than one range returned, and we don't know what do

View File

@ -40,7 +40,7 @@
#define __mozinlinespellchecker_h__
#include "nsAutoPtr.h"
#include "nsIRange.h"
#include "nsRange.h"
#include "nsIEditorSpellCheck.h"
#include "nsIEditActionListener.h"
#include "nsIInlineSpellChecker.h"
@ -78,7 +78,7 @@ public:
nsIDOMNode* aNewAnchorNode, PRInt32 aNewAnchorOffset,
bool* aContinue);
nsresult InitForSelection();
nsresult InitForRange(nsIRange* aRange);
nsresult InitForRange(nsRange* aRange);
nsresult FinishInitOnEvent(mozInlineSpellWordUtil& aWordUtil);
@ -104,14 +104,14 @@ public:
// Used for events where we have already computed the range to use. It can
// also be NULL in these cases where we need to check the entire range.
nsCOMPtr<nsIRange> mRange;
nsRefPtr<nsRange> mRange;
// If we happen to know something was inserted, this is that range.
// Can be NULL (this only allows an optimization, so not setting doesn't hurt)
nsCOMPtr<nsIDOMRange> mCreatedRange;
// Contains the range computed for the current word. Can be NULL.
nsCOMPtr<nsIRange> mNoCheckRange;
nsRefPtr<nsRange> mNoCheckRange;
// Indicates the position of the cursor for the event (so we can compute
// mNoCheckRange). It can be NULL if we don't care about the cursor position
@ -292,7 +292,7 @@ public:
nsresult MakeSpellCheckRange(nsIDOMNode* aStartNode, PRInt32 aStartOffset,
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
nsIRange** aRange);
nsRange** aRange);
// DOM and editor event registration helper routines
nsresult RegisterEventListeners();

View File

@ -256,7 +256,7 @@ mozInlineSpellWordUtil::EnsureWords()
}
nsresult
mozInlineSpellWordUtil::MakeRangeForWord(const RealWord& aWord, nsIRange** aRange)
mozInlineSpellWordUtil::MakeRangeForWord(const RealWord& aWord, nsRange** aRange)
{
NodeOffset begin = MapSoftTextOffsetToDOMPosition(aWord.mSoftTextOffset, HINT_BEGIN);
NodeOffset end = MapSoftTextOffsetToDOMPosition(aWord.EndOffset(), HINT_END);
@ -268,7 +268,7 @@ mozInlineSpellWordUtil::MakeRangeForWord(const RealWord& aWord, nsIRange** aRang
nsresult
mozInlineSpellWordUtil::GetRangeForWord(nsIDOMNode* aWordNode,
PRInt32 aWordOffset,
nsIRange** aRange)
nsRange** aRange)
{
// Set our soft end and start
nsCOMPtr<nsINode> wordNode = do_QueryInterface(aWordNode);
@ -315,7 +315,7 @@ NormalizeWord(const nsSubstring& aInput, PRInt32 aPos, PRInt32 aLen, nsAString&
// range unless the word was misspelled. This may or may not be possible.
nsresult
mozInlineSpellWordUtil::GetNextWord(nsAString& aText, nsIRange** aRange,
mozInlineSpellWordUtil::GetNextWord(nsAString& aText, nsRange** aRange,
bool* aSkipChecking)
{
#ifdef DEBUG_SPELLCHECK
@ -351,7 +351,7 @@ mozInlineSpellWordUtil::GetNextWord(nsAString& aText, nsIRange** aRange,
nsresult
mozInlineSpellWordUtil::MakeRange(NodeOffset aBegin, NodeOffset aEnd,
nsIRange** aRange)
nsRange** aRange)
{
if (!mDOMDocument)
return NS_ERROR_NOT_INITIALIZED;

View File

@ -44,7 +44,7 @@
//#define DEBUG_SPELLCHECK
class nsIRange;
class nsRange;
class nsINode;
/**
@ -101,13 +101,13 @@ public:
// before you actually generate the range you are interested in and iterate
// the words in it.
nsresult GetRangeForWord(nsIDOMNode* aWordNode, PRInt32 aWordOffset,
nsIRange** aRange);
nsRange** aRange);
// Moves to the the next word in the range, and retrieves it's text and range.
// An empty word and a NULL range are returned when we are done checking.
// aSkipChecking will be set if the word is "special" and shouldn't be
// checked (e.g., an email address).
nsresult GetNextWord(nsAString& aText, nsIRange** aRange,
nsresult GetNextWord(nsAString& aText, nsRange** aRange,
bool* aSkipChecking);
// Call to normalize some punctuation. This function takes an autostring
@ -191,6 +191,6 @@ private:
void SplitDOMWord(PRInt32 aStart, PRInt32 aEnd);
// Convenience functions, object must be initialized
nsresult MakeRange(NodeOffset aBegin, NodeOffset aEnd, nsIRange** aRange);
nsresult MakeRangeForWord(const RealWord& aWord, nsIRange** aRange);
nsresult MakeRange(NodeOffset aBegin, NodeOffset aEnd, nsRange** aRange);
nsresult MakeRangeForWord(const RealWord& aWord, nsRange** aRange);
};

View File

@ -200,6 +200,9 @@
#include "imgIEncoder.h"
#include "gfxPlatform.h"
/* for NS_MEMORY_REPORTER_IMPLEMENT */
#include "nsIMemoryReporter.h"
#include "mozilla/FunctionTimer.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
@ -224,12 +227,6 @@
#define ANCHOR_SCROLL_FLAGS (SCROLL_OVERFLOW_HIDDEN | SCROLL_NO_PARENT_FRAMES)
#include "nsContentCID.h"
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
/* for NS_MEMORY_REPORTER_IMPLEMENT */
#include "nsIMemoryReporter.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layers;
@ -257,14 +254,14 @@ static void ColorToString(nscolor aColor, nsAutoString &aString);
// RangePaintInfo is used to paint ranges to offscreen buffers
struct RangePaintInfo {
nsCOMPtr<nsIRange> mRange;
nsRefPtr<nsRange> mRange;
nsDisplayListBuilder mBuilder;
nsDisplayList mList;
// offset of builder's reference frame to the root frame
nsPoint mRootOffset;
RangePaintInfo(nsIRange* aRange, nsIFrame* aFrame)
RangePaintInfo(nsRange* aRange, nsIFrame* aFrame)
: mRange(aRange), mBuilder(aFrame, nsDisplayListBuilder::PAINTING, false)
{
MOZ_COUNT_CTOR(RangePaintInfo);
@ -3156,37 +3153,34 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll)
// Even if select anchor pref is false, we must still move the
// caret there. That way tabbing will start from the new
// location
nsCOMPtr<nsIDOMRange> jumpToRange = do_CreateInstance(kRangeCID);
if (jumpToRange) {
while (content && content->GetChildCount() > 0) {
content = content->GetChildAt(0);
}
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
NS_ASSERTION(node, "No nsIDOMNode for descendant of anchor");
jumpToRange->SelectNodeContents(node);
nsRefPtr<nsIDOMRange> jumpToRange = new nsRange();
while (content && content->GetChildCount() > 0) {
content = content->GetChildAt(0);
}
if (jumpToRange) {
// Select the anchor
nsISelection* sel = mSelection->
GetSelection(nsISelectionController::SELECTION_NORMAL);
if (sel) {
sel->RemoveAllRanges();
sel->AddRange(jumpToRange);
if (!selectAnchor) {
// Use a caret (collapsed selection) at the start of the anchor
sel->CollapseToStart();
}
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
NS_ASSERTION(node, "No nsIDOMNode for descendant of anchor");
jumpToRange->SelectNodeContents(node);
// Select the anchor
nsISelection* sel = mSelection->
GetSelection(nsISelectionController::SELECTION_NORMAL);
if (sel) {
sel->RemoveAllRanges();
sel->AddRange(jumpToRange);
if (!selectAnchor) {
// Use a caret (collapsed selection) at the start of the anchor
sel->CollapseToStart();
}
// Selection is at anchor.
// Now focus the document itself if focus is on an element within it.
nsPIDOMWindow *win = mDocument->GetWindow();
}
// Selection is at anchor.
// Now focus the document itself if focus is on an element within it.
nsPIDOMWindow *win = mDocument->GetWindow();
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && win) {
nsCOMPtr<nsIDOMWindow> focusedWindow;
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
if (SameCOMIdentity(win, focusedWindow))
fm->ClearFocus(focusedWindow);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && win) {
nsCOMPtr<nsIDOMWindow> focusedWindow;
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
if (SameCOMIdentity(win, focusedWindow)) {
fm->ClearFocus(focusedWindow);
}
}
} else {
@ -4631,7 +4625,7 @@ PresShell::RenderDocument(const nsRect& aRect, PRUint32 aFlags,
nsRect
PresShell::ClipListToRange(nsDisplayListBuilder *aBuilder,
nsDisplayList* aList,
nsIRange* aRange)
nsRange* aRange)
{
NS_TIME_FUNCTION_WITH_DOCURL;
@ -4743,9 +4737,7 @@ PresShell::CreateRangePaintInfo(nsIDOMRange* aRange,
RangePaintInfo* info = nsnull;
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
if (!range)
return nsnull;
nsRange* range = static_cast<nsRange*>(aRange);
nsIFrame* ancestorFrame;
nsIFrame* rootFrame = GetRootFrame();
@ -4962,8 +4954,7 @@ PresShell::RenderNode(nsIDOMNode* aNode,
if (!node->IsInDoc())
return nsnull;
nsCOMPtr<nsIDOMRange> range;
NS_NewRange(getter_AddRefs(range));
nsRefPtr<nsRange> range = new nsRange();
if (NS_FAILED(range->SelectNode(aNode)))
return nsnull;

View File

@ -74,7 +74,7 @@
#include "nsContentUtils.h"
#include "nsRefreshDriver.h"
class nsIRange;
class nsRange;
class nsIDragService;
class nsCSSStyleSheet;
@ -548,7 +548,7 @@ protected:
// the range
nsRect ClipListToRange(nsDisplayListBuilder *aBuilder,
nsDisplayList* aList,
nsIRange* aRange);
nsRange* aRange);
// create a RangePaintInfo for the range aRange containing the
// display list needed to paint the range to a surface

View File

@ -57,7 +57,6 @@
#include "nsIController.h"
#include "nsIControllers.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMRange.h"
#include "nsIDocument.h"
#include "nsIDocumentEncoder.h"
#include "nsIFactory.h"
@ -424,7 +423,6 @@ nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
nsresult NS_NewDomSelection(nsISelection** aResult);
nsresult NS_NewContentViewer(nsIContentViewer** aResult);
nsresult NS_NewRange(nsIDOMRange** aResult);
nsresult NS_NewRangeUtils(nsIRangeUtils** aResult);
nsresult NS_NewContentIterator(nsIContentIterator** aResult);
nsresult NS_NewPreContentIterator(nsIContentIterator** aResult);
@ -493,7 +491,6 @@ MAKE_CTOR(CreateXMLDocument, nsIDocument, NS_NewXML
MAKE_CTOR(CreateSVGDocument, nsIDocument, NS_NewSVGDocument)
MAKE_CTOR(CreateImageDocument, nsIDocument, NS_NewImageDocument)
MAKE_CTOR(CreateDOMSelection, nsISelection, NS_NewDomSelection)
MAKE_CTOR(CreateRange, nsIDOMRange, NS_NewRange)
MAKE_CTOR(CreateRangeUtils, nsIRangeUtils, NS_NewRangeUtils)
MAKE_CTOR(CreateContentIterator, nsIContentIterator, NS_NewContentIterator)
MAKE_CTOR(CreatePreContentIterator, nsIContentIterator, NS_NewPreContentIterator)
@ -687,7 +684,6 @@ NS_DEFINE_NAMED_CID(NS_XMLDOCUMENT_CID);
NS_DEFINE_NAMED_CID(NS_SVGDOCUMENT_CID);
NS_DEFINE_NAMED_CID(NS_IMAGEDOCUMENT_CID);
NS_DEFINE_NAMED_CID(NS_DOMSELECTION_CID);
NS_DEFINE_NAMED_CID(NS_RANGE_CID);
NS_DEFINE_NAMED_CID(NS_RANGEUTILS_CID);
NS_DEFINE_NAMED_CID(NS_CONTENTITERATOR_CID);
NS_DEFINE_NAMED_CID(NS_PRECONTENTITERATOR_CID);
@ -959,7 +955,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_SVGDOCUMENT_CID, false, NULL, CreateSVGDocument },
{ &kNS_IMAGEDOCUMENT_CID, false, NULL, CreateImageDocument },
{ &kNS_DOMSELECTION_CID, false, NULL, CreateDOMSelection },
{ &kNS_RANGE_CID, false, NULL, CreateRange },
{ &kNS_RANGEUTILS_CID, false, NULL, CreateRangeUtils },
{ &kNS_CONTENTITERATOR_CID, false, NULL, CreateContentIterator },
{ &kNS_PRECONTENTITERATOR_CID, false, NULL, CreatePreContentIterator },
@ -1094,7 +1089,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ "@mozilla.org/xml/xml-document;1", &kNS_XMLDOCUMENT_CID },
{ "@mozilla.org/svg/svg-document;1", &kNS_SVGDOCUMENT_CID },
{ "@mozilla.org/content/dom-selection;1", &kNS_DOMSELECTION_CID },
{ "@mozilla.org/content/range;1", &kNS_RANGE_CID },
{ "@mozilla.org/content/range-utils;1", &kNS_RANGEUTILS_CID },
{ "@mozilla.org/content/post-content-iterator;1", &kNS_CONTENTITERATOR_CID },
{ "@mozilla.org/content/pre-content-iterator;1", &kNS_PRECONTENTITERATOR_CID },

View File

@ -114,9 +114,6 @@
#define DEFAULT_COLUMN_WIDTH 20
#include "nsContentCID.h"
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
nsIFrame*
NS_NewTextControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{
@ -855,9 +852,7 @@ nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
// Note that we use a new range to avoid having to do
// isIncreasing checks to avoid possible errors.
nsCOMPtr<nsIDOMRange> range = do_CreateInstance(kRangeCID);
NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
nsRefPtr<nsRange> range = new nsRange();
nsresult rv = range->SetStart(aStartNode, aStartOffset);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -47,7 +47,7 @@
#include "nsITableCellLayout.h"
#include "nsIDOMElement.h"
#include "nsGUIEvent.h"
#include "nsIRange.h"
#include "nsRange.h"
// IID for the nsFrameSelection interface
// 3c6ae2d0-4cf1-44a1-9e9d-2411867f19c6
@ -684,12 +684,12 @@ private:
// Get our first range, if its first selected node is a cell. If this does
// not return null, then the first node in the returned range is a cell
// (according to GetFirstCellNodeInRange).
nsIRange* GetFirstCellRange();
nsRange* GetFirstCellRange();
// Get our next range, if its first selected node is a cell. If this does
// not return null, then the first node in the returned range is a cell
// (according to GetFirstCellNodeInRange).
nsIRange* GetNextCellRange();
nsIContent* GetFirstCellNodeInRange(nsIRange *aRange) const;
nsRange* GetNextCellRange();
nsIContent* GetFirstCellNodeInRange(nsRange *aRange) const;
// Returns non-null table if in same table, null otherwise
nsIContent* IsInSameTable(nsIContent *aContent1, nsIContent *aContent2) const;
// Might return null
@ -706,7 +706,7 @@ private:
PRInt32 mSelectedCellIndex;
// maintain selection
nsCOMPtr<nsIRange> mMaintainRange;
nsRefPtr<nsRange> mMaintainRange;
nsSelectionAmount mMaintainedAmount;
//batching

View File

@ -134,7 +134,7 @@ static nsINode* ParentOffset(nsINode *aNode, PRInt32 *aChildOffset);
static nsINode* GetCellParent(nsINode *aDomNode);
#ifdef PRINT_RANGE
static void printRange(nsIRange *aDomRange);
static void printRange(nsRange *aDomRange);
#define DEBUG_OUT_RANGE(x) printRange(x)
#else
#define DEBUG_OUT_RANGE(x)
@ -164,10 +164,11 @@ struct CachedOffsetForFrame {
struct RangeData
{
RangeData(nsIRange* aRange) :
mRange(aRange) {}
RangeData(nsRange* aRange)
: mRange(aRange)
{}
nsCOMPtr<nsIRange> mRange;
nsRefPtr<nsRange> mRange;
nsTextRangeStyle mTextRangeStyle;
};
@ -219,21 +220,15 @@ public:
PRInt16 aVPercent = NS_PRESSHELL_SCROLL_ANYWHERE,
PRInt16 aHPercent = NS_PRESSHELL_SCROLL_ANYWHERE,
PRInt32 aFlags = 0);
nsresult SubtractRange(RangeData* aRange, nsIRange* aSubtract,
nsresult SubtractRange(RangeData* aRange, nsRange* aSubtract,
nsTArray<RangeData>* aOutput);
nsresult AddItem(nsIRange *aRange, PRInt32* aOutIndex = nsnull);
nsresult RemoveItem(nsIRange *aRange);
nsresult AddItem(nsRange *aRange, PRInt32* aOutIndex = nsnull);
nsresult RemoveItem(nsRange *aRange);
nsresult RemoveCollapsedRanges();
nsresult Clear(nsPresContext* aPresContext);
nsresult Collapse(nsINode* aParentNode, PRInt32 aOffset);
nsresult Extend(nsINode* aParentNode, PRInt32 aOffset);
nsresult AddRange(nsIRange* aRange);
// The nsIRange version of RemoveRange assumes the caller is holding
// a strong reference to aRange.
nsresult RemoveRange(nsIRange* aRange);
nsIRange* GetRangeAt(PRInt32 aIndex);
nsresult GetTableSelectionType(nsIRange* aRange,
PRInt32* aTableSelectionType);
nsRange* GetRangeAt(PRInt32 aIndex);
// methods for convenience. Note, these don't addref
nsINode* GetAnchorNode();
@ -244,14 +239,14 @@ public:
// Get the anchor-to-focus range if we don't care which end is
// anchor and which end is focus.
const nsIRange* GetAnchorFocusRange() const {
const nsRange* GetAnchorFocusRange() const {
return mAnchorFocusRange;
}
nsDirection GetDirection(){return mDirection;}
void SetDirection(nsDirection aDir){mDirection = aDir;}
nsresult CopyRangeToAnchorFocus(nsIRange *aRange);
void ReplaceAnchorFocusRange(nsIRange *aRange);
nsresult CopyRangeToAnchorFocus(nsRange *aRange);
void ReplaceAnchorFocusRange(nsRange *aRange);
// NS_IMETHOD GetPrimaryFrameForRangeEndpoint(nsIDOMNode *aNode, PRInt32 aOffset, bool aIsEndNode, nsIFrame **aResultFrame);
NS_IMETHOD GetPrimaryFrameForAnchorNode(nsIFrame **aResultFrame);
@ -309,22 +304,18 @@ private:
nsresult SelectAllFramesForContent(nsIContentIterator *aInnerIter,
nsIContent *aContent,
bool aSelected);
nsresult selectFrames(nsPresContext* aPresContext, nsIRange *aRange, bool aSelect);
nsresult getTableCellLocationFromRange(nsIRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol);
nsresult addTableCellRange(nsIRange *aRange, bool *aDidAddRange, PRInt32 *aOutIndex);
nsresult selectFrames(nsPresContext* aPresContext, nsRange *aRange, bool aSelect);
nsresult getTableCellLocationFromRange(nsRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol);
nsresult addTableCellRange(nsRange *aRange, bool *aDidAddRange, PRInt32 *aOutIndex);
nsresult FindInsertionPoint(
nsTArray<RangeData>* aElementArray,
nsINode* aPointNode, PRInt32 aPointOffset,
nsresult (*aComparator)(nsINode*,PRInt32,nsIRange*,PRInt32*),
nsresult (*aComparator)(nsINode*,PRInt32,nsRange*,PRInt32*),
PRInt32* aPoint);
bool EqualsRangeAtPoint(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
PRInt32 aRangeIndex);
nsresult GetRangesForIntervalCOMArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
nsCOMArray<nsIRange>* aRanges);
void GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
@ -346,7 +337,7 @@ private:
// O(log n) time, though this would require rebalancing and other overhead.
nsTArray<RangeData> mRanges;
nsCOMPtr<nsIRange> mAnchorFocusRange;
nsRefPtr<nsRange> mAnchorFocusRange;
nsRefPtr<nsFrameSelection> mFrameSelection;
nsWeakPtr mPresShellWeak;
nsRefPtr<nsAutoScrollTimer> mAutoScrollTimer;
@ -387,7 +378,7 @@ see the nsIEnumerator for more details*/
/*END nsIEnumerator interfaces*/
/*BEGIN Helper Methods*/
nsIRange* CurrentItem();
nsRange* CurrentItem();
/*END Helper Methods*/
private:
friend class nsTypedSelection;
@ -665,7 +656,7 @@ nsSelectionIterator::Last()
NS_IMETHODIMP
nsSelectionIterator::CurrentItem(nsISupports **aItem)
{
*aItem = CurrentItem();
*aItem = static_cast<nsIDOMRange*>(CurrentItem());
if (!*aItem) {
return NS_ERROR_FAILURE;
}
@ -674,7 +665,7 @@ nsSelectionIterator::CurrentItem(nsISupports **aItem)
return NS_OK;
}
nsIRange*
nsRange*
nsSelectionIterator::CurrentItem()
{
return mDomSelection->mRanges.SafeElementAt(mIndex, sEmptyData).mRange;
@ -777,7 +768,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFrameSelection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEndSelectedCell)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAppendStartSelectedCell)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mUnselectCellOnMouseUp)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mMaintainRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mMaintainRange, nsIDOMRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameSelection)
@ -1006,7 +997,7 @@ nsFrameSelection::UndefineCaretBidiLevel()
#ifdef PRINT_RANGE
void printRange(nsIRange *aDomRange)
void printRange(nsRange *aDomRange)
{
if (!aDomRange)
{
@ -1154,7 +1145,7 @@ nsFrameSelection::MoveCaret(PRUint32 aKeycode,
case nsIDOMKeyEvent::DOM_VK_LEFT :
case nsIDOMKeyEvent::DOM_VK_UP :
{
const nsIRange* anchorFocusRange = sel->GetAnchorFocusRange();
const nsRange* anchorFocusRange = sel->GetAnchorFocusRange();
if (anchorFocusRange) {
sel->Collapse(anchorFocusRange->GetStartParent(),
anchorFocusRange->StartOffset());
@ -1168,7 +1159,7 @@ nsFrameSelection::MoveCaret(PRUint32 aKeycode,
case nsIDOMKeyEvent::DOM_VK_RIGHT :
case nsIDOMKeyEvent::DOM_VK_DOWN :
{
const nsIRange* anchorFocusRange = sel->GetAnchorFocusRange();
const nsRange* anchorFocusRange = sel->GetAnchorFocusRange();
if (anchorFocusRange) {
sel->Collapse(anchorFocusRange->GetEndParent(),
anchorFocusRange->EndOffset());
@ -1520,7 +1511,7 @@ nsFrameSelection::MaintainSelection(nsSelectionAmount aAmount)
mMaintainedAmount = aAmount;
const nsIRange* anchorFocusRange =
const nsRange* anchorFocusRange =
mDomSelections[index]->GetAnchorFocusRange();
if (anchorFocusRange) {
return anchorFocusRange->CloneRange(getter_AddRefs(mMaintainRange));
@ -1825,7 +1816,7 @@ nsFrameSelection::TakeFocus(nsIContent *aNewFocus,
// non-anchor/focus collapsed ranges.
mDomSelections[index]->RemoveCollapsedRanges();
nsCOMPtr<nsIRange> newRange = new nsRange();
nsRefPtr<nsRange> newRange = new nsRange();
newRange->SetStart(aNewFocus, aContentOffset);
newRange->SetEnd(aNewFocus, aContentOffset);
@ -2327,7 +2318,7 @@ nsFrameSelection::ClearNormalSelection()
}
static nsIContent*
GetFirstSelectedContent(nsIRange* aRange)
GetFirstSelectedContent(nsRange* aRange)
{
if (!aRange) {
return nsnull;
@ -2609,7 +2600,7 @@ printf("HandleTableSelection: Unselecting mUnselectCellOnMouseUp; rangeCount=%d\
{
// Strong reference, because sometimes we want to remove
// this range, and then we might be the only owner.
nsCOMPtr<nsIRange> range = mDomSelections[index]->GetRangeAt(i);
nsRefPtr<nsRange> range = mDomSelections[index]->GetRangeAt(i);
if (!range) return NS_ERROR_NULL_POINTER;
nsINode* parent = range->GetStartParent();
@ -2720,7 +2711,7 @@ nsFrameSelection::UnselectCells(nsIContent *aTableContent,
PRInt32 maxColIndex = NS_MAX(aStartColumnIndex, aEndColumnIndex);
// Strong reference because we sometimes remove the range
nsCOMPtr<nsIRange> range = GetFirstCellRange();
nsRefPtr<nsRange> range = GetFirstCellRange();
nsIContent* cellNode = GetFirstSelectedContent(range);
NS_PRECONDITION(!range || cellNode, "Must have cellNode if had a range");
@ -2983,7 +2974,7 @@ nsFrameSelection::SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget)
}
nsIContent*
nsFrameSelection::GetFirstCellNodeInRange(nsIRange *aRange) const
nsFrameSelection::GetFirstCellNodeInRange(nsRange *aRange) const
{
if (!aRange) return nsnull;
@ -3003,14 +2994,14 @@ nsFrameSelection::GetFirstCellNodeInRange(nsIRange *aRange) const
return childContent;
}
nsIRange*
nsRange*
nsFrameSelection::GetFirstCellRange()
{
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return nsnull;
nsIRange* firstRange = mDomSelections[index]->GetRangeAt(0);
nsRange* firstRange = mDomSelections[index]->GetRangeAt(0);
if (!GetFirstCellNodeInRange(firstRange)) {
return nsnull;
}
@ -3021,14 +3012,14 @@ nsFrameSelection::GetFirstCellRange()
return firstRange;
}
nsIRange*
nsRange*
nsFrameSelection::GetNextCellRange()
{
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return nsnull;
nsIRange* range = mDomSelections[index]->GetRangeAt(mSelectedCellIndex);
nsRange* range = mDomSelections[index]->GetRangeAt(mSelectedCellIndex);
// Get first node in next range of selection - test if it's a cell
if (!GetFirstCellNodeInRange(range)) {
@ -3100,7 +3091,7 @@ nsFrameSelection::SelectCellElement(nsIContent *aCellElement)
}
nsresult
nsTypedSelection::getTableCellLocationFromRange(nsIRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol)
nsTypedSelection::getTableCellLocationFromRange(nsRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol)
{
if (!aRange || !aSelectionType || !aRow || !aCol)
return NS_ERROR_NULL_POINTER;
@ -3142,7 +3133,7 @@ nsTypedSelection::getTableCellLocationFromRange(nsIRange *aRange, PRInt32 *aSele
}
nsresult
nsTypedSelection::addTableCellRange(nsIRange *aRange, bool *aDidAddRange,
nsTypedSelection::addTableCellRange(nsRange *aRange, bool *aDidAddRange,
PRInt32 *aOutIndex)
{
if (!aDidAddRange || !aOutIndex)
@ -3182,37 +3173,30 @@ nsTypedSelection::addTableCellRange(nsIRange *aRange, bool *aDidAddRange,
}
//TODO: Figure out TABLESELECTION_COLUMN and TABLESELECTION_ALLCELLS
NS_IMETHODIMP
nsTypedSelection::GetTableSelectionType(nsIDOMRange* aRange,
PRInt32* aTableSelectionType)
{
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
return GetTableSelectionType(range, aTableSelectionType);
}
nsresult
nsTypedSelection::GetTableSelectionType(nsIRange* aRange,
nsTypedSelection::GetTableSelectionType(nsIDOMRange* aDOMRange,
PRInt32* aTableSelectionType)
{
if (!aRange || !aTableSelectionType)
if (!aDOMRange || !aTableSelectionType)
return NS_ERROR_NULL_POINTER;
nsRange* range = static_cast<nsRange*>(aDOMRange);
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
// Must have access to frame selection to get cell info
if(!mFrameSelection) return NS_OK;
nsINode* startNode = aRange->GetStartParent();
nsINode* startNode = range->GetStartParent();
if (!startNode) return NS_ERROR_FAILURE;
nsINode* endNode = aRange->GetEndParent();
nsINode* endNode = range->GetEndParent();
if (!endNode) return NS_ERROR_FAILURE;
// Not a single selected node
if (startNode != endNode) return NS_OK;
PRInt32 startOffset = aRange->StartOffset();
PRInt32 endOffset = aRange->EndOffset();
PRInt32 startOffset = range->StartOffset();
PRInt32 endOffset = range->EndOffset();
// Not a single selected node
if ((endOffset - startOffset) != 1)
@ -3253,7 +3237,7 @@ nsFrameSelection::CreateAndAddRange(nsINode *aParentNode, PRInt32 aOffset)
{
if (!aParentNode) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIRange> range = new nsRange();
nsRefPtr<nsRange> range = new nsRange();
// Set range around child at given offset
nsresult result = range->SetStart(aParentNode, aOffset);
@ -3334,7 +3318,7 @@ nsFrameSelection::DeleteFromDocument()
while (iter.IsDone())
{
nsCOMPtr<nsIRange> range = iter.CurrentItem();
nsRefPtr<nsRange> range = iter.CurrentItem();
res = range->DeleteContents();
if (NS_FAILED(res))
return res;
@ -3451,10 +3435,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsTypedSelection)
{
PRUint32 i, count = tmp->mRanges.Length();
for (i = 0; i < count; ++i) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRanges[i].mRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRanges[i].mRange, nsIDOMRange)
}
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchorFocusRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mAnchorFocusRange, nsIDOMRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFrameSelection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mSelectionListeners)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -3587,7 +3571,7 @@ nsTypedSelection::GetFocusOffset()
static nsresult
CompareToRangeStart(nsINode* aCompareNode, PRInt32 aCompareOffset,
nsIRange* aRange, PRInt32* aCmp)
nsRange* aRange, PRInt32* aCmp)
{
nsINode* start = aRange->GetStartParent();
NS_ENSURE_STATE(aCompareNode && start);
@ -3605,7 +3589,7 @@ CompareToRangeStart(nsINode* aCompareNode, PRInt32 aCompareOffset,
static nsresult
CompareToRangeEnd(nsINode* aCompareNode, PRInt32 aCompareOffset,
nsIRange* aRange, PRInt32* aCmp)
nsRange* aRange, PRInt32* aCmp)
{
nsINode* end = aRange->GetEndParent();
NS_ENSURE_STATE(aCompareNode && end);
@ -3634,7 +3618,7 @@ nsresult
nsTypedSelection::FindInsertionPoint(
nsTArray<RangeData>* aElementArray,
nsINode* aPointNode, PRInt32 aPointOffset,
nsresult (*aComparator)(nsINode*,PRInt32,nsIRange*,PRInt32*),
nsresult (*aComparator)(nsINode*,PRInt32,nsRange*,PRInt32*),
PRInt32* aPoint)
{
*aPoint = 0;
@ -3643,7 +3627,7 @@ nsTypedSelection::FindInsertionPoint(
while (endSearch - beginSearch > 0) {
PRInt32 center = (endSearch - beginSearch) / 2 + beginSearch;
nsIRange* range = (*aElementArray)[center].mRange;
nsRange* range = (*aElementArray)[center].mRange;
PRInt32 cmp;
nsresult rv = aComparator(aPointNode, aPointOffset, range, &cmp);
@ -3670,10 +3654,10 @@ nsTypedSelection::FindInsertionPoint(
// aRange and aSubtract do indeed overlap
nsresult
nsTypedSelection::SubtractRange(RangeData* aRange, nsIRange* aSubtract,
nsTypedSelection::SubtractRange(RangeData* aRange, nsRange* aSubtract,
nsTArray<RangeData>* aOutput)
{
nsIRange* range = aRange->mRange;
nsRange* range = aRange->mRange;
// First we want to compare to the range start
PRInt32 cmp;
@ -3697,7 +3681,7 @@ nsTypedSelection::SubtractRange(RangeData* aRange, nsIRange* aSubtract,
if (cmp2 > 0) {
// We need to add a new RangeData to the output, running from
// the end of aSubtract to the end of range
nsIRange* postOverlap = new nsRange();
nsRange* postOverlap = new nsRange();
rv =
postOverlap->SetStart(aSubtract->GetEndParent(), aSubtract->EndOffset());
@ -3715,7 +3699,7 @@ nsTypedSelection::SubtractRange(RangeData* aRange, nsIRange* aSubtract,
if (cmp < 0) {
// We need to add a new RangeData to the output, running from
// the start of the range to the start of aSubtract
nsIRange* preOverlap = new nsRange();
nsRange* preOverlap = new nsRange();
nsresult rv =
preOverlap->SetStart(range->GetStartParent(), range->StartOffset());
@ -3735,7 +3719,7 @@ nsTypedSelection::SubtractRange(RangeData* aRange, nsIRange* aSubtract,
}
nsresult
nsTypedSelection::AddItem(nsIRange *aItem, PRInt32 *aOutIndex)
nsTypedSelection::AddItem(nsRange *aItem, PRInt32 *aOutIndex)
{
if (!aItem)
return NS_ERROR_NULL_POINTER;
@ -3844,7 +3828,7 @@ nsTypedSelection::AddItem(nsIRange *aItem, PRInt32 *aOutIndex)
}
nsresult
nsTypedSelection::RemoveItem(nsIRange *aItem)
nsTypedSelection::RemoveItem(nsRange *aItem)
{
if (!aItem)
return NS_ERROR_NULL_POINTER;
@ -3923,13 +3907,13 @@ nsTypedSelection::GetType(PRInt16 *aType)
// exactly matches the given DOM point.
static inline bool
RangeMatchesBeginPoint(nsIRange* aRange, nsINode* aNode, PRInt32 aOffset)
RangeMatchesBeginPoint(nsRange* aRange, nsINode* aNode, PRInt32 aOffset)
{
return aRange->GetStartParent() == aNode && aRange->StartOffset() == aOffset;
}
static inline bool
RangeMatchesEndPoint(nsIRange* aRange, nsINode* aNode, PRInt32 aOffset)
RangeMatchesEndPoint(nsRange* aRange, nsINode* aNode, PRInt32 aOffset)
{
return aRange->GetEndParent() == aNode && aRange->EndOffset() == aOffset;
}
@ -3945,7 +3929,7 @@ nsTypedSelection::EqualsRangeAtPoint(
PRInt32 aRangeIndex)
{
if (aRangeIndex >=0 && aRangeIndex < (PRInt32) mRanges.Length()) {
nsIRange* range = mRanges[aRangeIndex].mRange;
nsRange* range = mRanges[aRangeIndex].mRange;
if (RangeMatchesBeginPoint(range, aBeginNode, aBeginOffset) &&
RangeMatchesEndPoint(range, aEndNode, aEndOffset))
return true;
@ -3955,7 +3939,7 @@ nsTypedSelection::EqualsRangeAtPoint(
// nsTypedSelection::GetRangesForInterval
//
// XPCOM wrapper for the COMArray version
// XPCOM wrapper for the nsTArray version
NS_IMETHODIMP
nsTypedSelection::GetRangesForInterval(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
@ -3969,58 +3953,32 @@ nsTypedSelection::GetRangesForInterval(nsIDOMNode* aBeginNode, PRInt32 aBeginOff
*aResultCount = 0;
*aResults = nsnull;
nsCOMPtr<nsINode> beginNode = do_QueryInterface(aBeginNode);
nsCOMPtr<nsINode> endNode = do_QueryInterface(aEndNode);
nsCOMArray<nsIDOMRange> results;
nsresult rv = GetRangesForIntervalCOMArray(aBeginNode, aBeginOffset,
aEndNode, aEndOffset,
aAllowAdjacent,
&results);
nsTArray<nsRange*> results;
nsresult rv = GetRangesForIntervalArray(beginNode, aBeginOffset,
endNode, aEndOffset,
aAllowAdjacent, &results);
NS_ENSURE_SUCCESS(rv, rv);
if (results.Count() == 0)
*aResultCount = results.Length();
if (*aResultCount == 0) {
return NS_OK;
}
*aResults = static_cast<nsIDOMRange**>
(nsMemory::Alloc(sizeof(nsIDOMRange*) * results.Count()));
(nsMemory::Alloc(sizeof(nsIDOMRange*) * *aResultCount));
NS_ENSURE_TRUE(*aResults, NS_ERROR_OUT_OF_MEMORY);
*aResultCount = results.Count();
for (PRInt32 i = 0; i < results.Count(); i ++)
for (PRUint32 i = 0; i < *aResultCount; i++)
NS_ADDREF((*aResults)[i] = results[i]);
return NS_OK;
}
// nsTypedSelection::GetRangesForIntervalCOMArray
// nsTypedSelection::GetRangesForIntervalArray
//
// Fills a COM array with the ranges overlapping the range specified by
// the given endpoints. Ranges in the selection exactly adjacent to the
// input range are not returned unless aAllowAdjacent is set.
NS_IMETHODIMP
nsTypedSelection::GetRangesForIntervalCOMArray(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
nsCOMArray<nsIDOMRange>* aRanges)
{
nsCOMPtr<nsINode> begin = do_QueryInterface(aBeginNode);
nsCOMPtr<nsINode> end = do_QueryInterface(aEndNode);
nsCOMArray<nsIRange> ranges;
nsresult rv = GetRangesForIntervalCOMArray(begin, aBeginOffset,
end, aEndOffset,
aAllowAdjacent, &ranges);
NS_ENSURE_SUCCESS(rv, rv);
for (PRInt32 i = 0; i < ranges.Count(); ++i) {
nsCOMPtr<nsIDOMRange> r = do_QueryInterface(ranges[i]);
if (!aRanges->AppendObject(r)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
return NS_OK;
}
// nsTypedSelection::GetRangesForIntervalCOMArray
//
// Fills a COM array with the ranges overlapping the range specified by
// Fills a nsTArray with the ranges overlapping the range specified by
// the given endpoints. Ranges in the selection exactly adjacent to the
// input range are not returned unless aAllowAdjacent is set.
//
@ -4039,10 +3997,10 @@ nsTypedSelection::GetRangesForIntervalCOMArray(nsIDOMNode* aBeginNode, PRInt32 a
// 2 adjacent ranges
nsresult
nsTypedSelection::GetRangesForIntervalCOMArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
nsCOMArray<nsIRange>* aRanges)
nsTypedSelection::GetRangesForIntervalArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
nsTArray<nsRange*>* aRanges)
{
aRanges->Clear();
PRInt32 startIndex, endIndex;
@ -4052,7 +4010,7 @@ nsTypedSelection::GetRangesForIntervalCOMArray(nsINode* aBeginNode, PRInt32 aBeg
return NS_OK;
for (PRInt32 i = startIndex; i < endIndex; i++) {
if (!aRanges->AppendObject(mRanges[i].mRange))
if (!aRanges->AppendElement(mRanges[i].mRange))
return NS_ERROR_OUT_OF_MEMORY;
}
@ -4061,7 +4019,7 @@ nsTypedSelection::GetRangesForIntervalCOMArray(nsINode* aBeginNode, PRInt32 aBeg
// nsTypedSelection::GetIndicesForInterval
//
// Works on the same principle as GetRangesForIntervalCOMArray above, however
// Works on the same principle as GetRangesForIntervalArray above, however
// instead this returns the indices into mRanges between which the
// overlapping ranges lie.
@ -4100,7 +4058,7 @@ nsTypedSelection::GetIndicesForInterval(nsINode* aBeginNode,
}
if (endsBeforeIndex == 0) {
nsIRange* endRange = mRanges[endsBeforeIndex].mRange;
nsRange* endRange = mRanges[endsBeforeIndex].mRange;
// If the interval is strictly before the range at index 0, we can optimize
// by returning now - all ranges start after the given interval
@ -4138,7 +4096,7 @@ nsTypedSelection::GetIndicesForInterval(nsINode* aBeginNode,
// final case, we need to increment endsBeforeIndex, until one of the
// first two possibilites hold
while (endsBeforeIndex < (PRInt32) mRanges.Length()) {
nsIRange* endRange = mRanges[endsBeforeIndex].mRange;
nsRange* endRange = mRanges[endsBeforeIndex].mRange;
if (!RangeMatchesBeginPoint(endRange, aEndNode, aEndOffset))
break;
endsBeforeIndex++;
@ -4155,7 +4113,7 @@ nsTypedSelection::GetIndicesForInterval(nsINode* aBeginNode,
// final case, we only need to take action if both those ranges exist, and
// we are pointing to the collapsed range - we need to point to the
// adjacent range
nsIRange* beginRange = mRanges[beginsAfterIndex].mRange;
nsRange* beginRange = mRanges[beginsAfterIndex].mRange;
if (beginsAfterIndex > 0 && beginRange->Collapsed() &&
RangeMatchesEndPoint(beginRange, aBeginNode, aBeginOffset)) {
beginRange = mRanges[beginsAfterIndex - 1].mRange;
@ -4167,7 +4125,7 @@ nsTypedSelection::GetIndicesForInterval(nsINode* aBeginNode,
// need to take action is when the range at beginsAfterIndex ends on
// the given interval's start point, but that range isn't collapsed (a
// collapsed range should be included in the returned results).
nsIRange* beginRange = mRanges[beginsAfterIndex].mRange;
nsRange* beginRange = mRanges[beginsAfterIndex].mRange;
if (RangeMatchesEndPoint(beginRange, aBeginNode, aBeginOffset) &&
!beginRange->Collapsed())
beginsAfterIndex++;
@ -4177,7 +4135,7 @@ nsTypedSelection::GetIndicesForInterval(nsINode* aBeginNode,
// represents the point at the end of the interval - this range should be
// included
if (endsBeforeIndex < (PRInt32) mRanges.Length()) {
nsIRange* endRange = mRanges[endsBeforeIndex].mRange;
nsRange* endRange = mRanges[endsBeforeIndex].mRange;
if (RangeMatchesBeginPoint(endRange, aEndNode, aEndOffset) &&
endRange->Collapsed())
endsBeforeIndex++;
@ -4340,7 +4298,7 @@ nsTypedSelection::SelectAllFramesForContent(nsIContentIterator *aInnerIter,
//the idea of this helper method is to select, deselect "top to bottom" traversing through the frames
nsresult
nsTypedSelection::selectFrames(nsPresContext* aPresContext, nsIRange *aRange, bool aFlags)
nsTypedSelection::selectFrames(nsPresContext* aPresContext, nsRange* aRange, bool aFlags)
{
if (!mFrameSelection || !aPresContext || !aPresContext->GetPresShell()) {
return NS_OK; // nothing to do
@ -4469,17 +4427,17 @@ nsTypedSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset,
if (mRanges.Length() == 0)
return NS_OK;
nsCOMArray<nsIRange> overlappingRanges;
rv = GetRangesForIntervalCOMArray(aContent, aContentOffset,
aContent, aContentOffset + aContentLength,
false,
&overlappingRanges);
nsTArray<nsRange*> overlappingRanges;
rv = GetRangesForIntervalArray(aContent, aContentOffset,
aContent, aContentOffset + aContentLength,
false,
&overlappingRanges);
NS_ENSURE_SUCCESS(rv, rv);
if (overlappingRanges.Count() == 0)
if (overlappingRanges.Length() == 0)
return NS_OK;
for (PRInt32 i = 0; i < overlappingRanges.Count(); i ++) {
nsIRange* range = overlappingRanges[i];
for (PRUint32 i = 0; i < overlappingRanges.Length(); i++) {
nsRange* range = overlappingRanges[i];
nsINode* startNode = range->GetStartParent();
nsINode* endNode = range->GetEndParent();
PRInt32 startOffset = range->StartOffset();
@ -4768,27 +4726,23 @@ nsTypedSelection::RemoveAllRanges()
* @param aRange is the range to be added
*/
NS_IMETHODIMP
nsTypedSelection::AddRange(nsIDOMRange* aRange)
nsTypedSelection::AddRange(nsIDOMRange* aDOMRange)
{
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
return AddRange(range);
}
nsresult
nsTypedSelection::AddRange(nsIRange* aRange)
{
if (!aRange) return NS_ERROR_NULL_POINTER;
if (!aDOMRange) {
return NS_ERROR_NULL_POINTER;
}
nsRange* range = static_cast<nsRange*>(aDOMRange);
// This inserts a table cell range in proper document order
// and returns NS_OK if range doesn't contain just one table cell
bool didAddRange;
PRInt32 rangeIndex;
nsresult result = addTableCellRange(aRange, &didAddRange, &rangeIndex);
nsresult result = addTableCellRange(range, &didAddRange, &rangeIndex);
if (NS_FAILED(result)) return result;
if (!didAddRange)
{
result = AddItem(aRange, &rangeIndex);
result = AddItem(range, &rangeIndex);
if (NS_FAILED(result)) return result;
}
@ -4801,7 +4755,7 @@ nsTypedSelection::AddRange(nsIRange* aRange)
nsRefPtr<nsPresContext> presContext;
GetPresContext(getter_AddRefs(presContext));
selectFrames(presContext, aRange, true);
selectFrames(presContext, range, true);
if (!mFrameSelection)
return NS_OK;//nothing to do
@ -4821,24 +4775,20 @@ nsTypedSelection::AddRange(nsIRange* aRange)
// being removed, and cause them to set the selected bits back on their
// selected frames after we've cleared the bit from ours.
NS_IMETHODIMP
nsTypedSelection::RemoveRange(nsIDOMRange* aRange)
{
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
return RemoveRange(range);
}
nsresult
nsTypedSelection::RemoveRange(nsIRange* aRange)
nsTypedSelection::RemoveRange(nsIDOMRange* aDOMRange)
{
if (!aRange)
if (!aDOMRange) {
return NS_ERROR_INVALID_ARG;
nsresult rv = RemoveItem(aRange);
}
nsRefPtr<nsRange> range = static_cast<nsRange*>(aDOMRange);
nsresult rv = RemoveItem(range);
if (NS_FAILED(rv))
return rv;
nsINode* beginNode = aRange->GetStartParent();
nsINode* endNode = aRange->GetEndParent();
nsINode* beginNode = range->GetStartParent();
nsINode* endNode = range->GetEndParent();
if (!beginNode || !endNode) {
// Detached range; nothing else to do here.
@ -4855,27 +4805,27 @@ nsTypedSelection::RemoveRange(nsIRange* aRange)
endOffset = static_cast<nsIContent*>(endNode)->TextLength();
} else {
// For non-text nodes, the given offsets should be sufficient.
beginOffset = aRange->StartOffset();
endOffset = aRange->EndOffset();
beginOffset = range->StartOffset();
endOffset = range->EndOffset();
}
// clear the selected bit from the removed range's frames
nsRefPtr<nsPresContext> presContext;
GetPresContext(getter_AddRefs(presContext));
selectFrames(presContext, aRange, false);
selectFrames(presContext, range, false);
// add back the selected bit for each range touching our nodes
nsCOMArray<nsIRange> affectedRanges;
rv = GetRangesForIntervalCOMArray(beginNode, beginOffset,
endNode, endOffset,
true, &affectedRanges);
nsTArray<nsRange*> affectedRanges;
rv = GetRangesForIntervalArray(beginNode, beginOffset,
endNode, endOffset,
true, &affectedRanges);
NS_ENSURE_SUCCESS(rv, rv);
for (PRInt32 i = 0; i < affectedRanges.Count(); i ++) {
for (PRUint32 i = 0; i < affectedRanges.Length(); i++) {
selectFrames(presContext, affectedRanges[i], true);
}
PRInt32 cnt = mRanges.Length();
if (aRange == mAnchorFocusRange) {
if (range == mAnchorFocusRange) {
// Reset anchor to LAST range or clear it if there are no ranges.
setAnchorFocusRange(cnt - 1);
@ -4927,7 +4877,7 @@ nsTypedSelection::Collapse(nsINode* aParentNode, PRInt32 aOffset)
// Turn off signal for table selection
mFrameSelection->ClearTableCellSelection();
nsCOMPtr<nsIRange> range = new nsRange();
nsRefPtr<nsRange> range = new nsRange();
result = range->SetEnd(aParentNode, aOffset);
if (NS_FAILED(result))
return result;
@ -4967,7 +4917,7 @@ nsTypedSelection::CollapseToStart()
return NS_ERROR_DOM_INVALID_STATE_ERR;
// Get the first range
nsIRange* firstRange = mRanges[0].mRange;
nsRange* firstRange = mRanges[0].mRange;
if (!firstRange)
return NS_ERROR_FAILURE;
@ -4987,7 +4937,7 @@ nsTypedSelection::CollapseToEnd()
return NS_ERROR_DOM_INVALID_STATE_ERR;
// Get the last range
nsIRange* lastRange = mRanges[cnt-1].mRange;
nsRange* lastRange = mRanges[cnt - 1].mRange;
if (!lastRange)
return NS_ERROR_FAILURE;
@ -5041,7 +4991,7 @@ nsTypedSelection::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)
return NS_OK;
}
nsIRange*
nsRange*
nsTypedSelection::GetRangeAt(PRInt32 aIndex)
{
return mRanges.SafeElementAt(aIndex, sEmptyData).mRange;
@ -5051,7 +5001,7 @@ nsTypedSelection::GetRangeAt(PRInt32 aIndex)
utility function
*/
nsresult
nsTypedSelection::CopyRangeToAnchorFocus(nsIRange *aRange)
nsTypedSelection::CopyRangeToAnchorFocus(nsRange *aRange)
{
// XXXbz could we just clone into mAnchorFocusRange, or do consumers
// expect that pointer to not change across this call?
@ -5075,7 +5025,7 @@ nsTypedSelection::CopyRangeToAnchorFocus(nsIRange *aRange)
}
void
nsTypedSelection::ReplaceAnchorFocusRange(nsIRange *aRange)
nsTypedSelection::ReplaceAnchorFocusRange(nsRange *aRange)
{
nsRefPtr<nsPresContext> presContext;
GetPresContext(getter_AddRefs(presContext));
@ -5140,8 +5090,6 @@ nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset)
return NS_ERROR_FAILURE;
//mFrameSelection->InvalidateDesiredX();
nsCOMPtr<nsIRange> difRange = new nsRange();
nsCOMPtr<nsIRange> range;
nsINode* anchorNode = GetAnchorNode();
nsINode* focusNode = GetFocusNode();
@ -5151,6 +5099,7 @@ nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset)
if (focusNode == aParentNode && focusOffset == aOffset)
return NS_OK; //same node nothing to do!
nsRefPtr<nsRange> range;
res = mAnchorFocusRange->CloneRange(getter_AddRefs(range));
if (NS_FAILED(res))
return res;
@ -5188,6 +5137,7 @@ nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset)
nsRefPtr<nsPresContext> presContext;
GetPresContext(getter_AddRefs(presContext));
nsRefPtr<nsRange> difRange = new nsRange();
if ((result1 == 0 && result3 < 0) || (result1 <= 0 && result2 < 0)){//a1,2 a,1,2
//select from 1 to 2 unless they are collapsed
res = range->SetEnd(aParentNode, aOffset);
@ -5411,11 +5361,11 @@ nsTypedSelection::ContainsNode(nsIDOMNode* aNode, bool aAllowPartial,
nodeLength = node->GetChildCount();
}
nsCOMArray<nsIRange> overlappingRanges;
rv = GetRangesForIntervalCOMArray(node, 0, node, nodeLength,
false, &overlappingRanges);
nsTArray<nsRange*> overlappingRanges;
rv = GetRangesForIntervalArray(node, 0, node, nodeLength,
false, &overlappingRanges);
NS_ENSURE_SUCCESS(rv, rv);
if (overlappingRanges.Count() == 0)
if (overlappingRanges.Length() == 0)
return NS_OK; // no ranges overlap
// if the caller said partial intersections are OK, we're done
@ -5432,7 +5382,7 @@ nsTypedSelection::ContainsNode(nsIDOMNode* aNode, bool aAllowPartial,
// The caller wants to know if the node is entirely within the given range,
// so we have to check all intersecting ranges.
for (PRInt32 i = 0; i < overlappingRanges.Count(); i ++) {
for (PRUint32 i = 0; i < overlappingRanges.Length(); i++) {
bool nodeStartsBeforeRange, nodeEndsAfterRange;
if (NS_SUCCEEDED(nsRange::CompareNodeToRange(node, overlappingRanges[i],
&nodeStartsBeforeRange,

View File

@ -58,7 +58,7 @@
#include "nsComputedDOMStyle.h"
#include "nsEventStateManager.h"
#include "nsIAtom.h"
#include "nsIRange.h"
#include "nsRange.h"
#include "mozilla/dom/Element.h"
@ -355,8 +355,5 @@ NS_IMETHODIMP
inDOMUtils::GetUsedFontFaces(nsIDOMRange* aRange,
nsIDOMFontFaceList** aFontFaceList)
{
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
NS_ENSURE_TRUE(range, NS_ERROR_UNEXPECTED);
return range->GetUsedFontFaces(aFontFaceList);
return static_cast<nsRange*>(aRange)->GetUsedFontFaces(aFontFaceList);
}

View File

@ -2195,10 +2195,7 @@ static nsresult CloneRangeToSelection(nsIDOMRange* aRange,
nsCOMPtr<nsIDOMNode> newEnd = GetEqualNodeInCloneTree(endContainer, aDoc);
NS_ENSURE_STATE(newStart && newEnd);
nsCOMPtr<nsIDOMRange> range;
NS_NewRange(getter_AddRefs(range));
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsRange> range = new nsRange();
nsresult rv = range->SetStart(newStart, startOffset);
NS_ENSURE_SUCCESS(rv, rv);
rv = range->SetEnd(newEnd, endOffset);

View File

@ -88,6 +88,7 @@
#include "nsIObserverService.h"
#include "nsFocusManager.h"
#include "mozilla/dom/Element.h"
#include "nsRange.h"
#include "nsTypeAheadFind.h"
@ -101,7 +102,6 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsTypeAheadFind)
NS_IMPL_RELEASE(nsTypeAheadFind)
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
#define NS_FIND_CONTRACTID "@mozilla.org/embedcomp/rangefind;1"
@ -127,11 +127,11 @@ nsresult
nsTypeAheadFind::Init(nsIDocShell* aDocShell)
{
nsCOMPtr<nsIPrefBranch2> prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID));
mSearchRange = do_CreateInstance(kRangeCID);
mStartPointRange = do_CreateInstance(kRangeCID);
mEndPointRange = do_CreateInstance(kRangeCID);
mSearchRange = new nsRange();
mStartPointRange = new nsRange();
mEndPointRange = new nsRange();
mFind = do_CreateInstance(NS_FIND_CONTRACTID);
if (!prefInternal || !mSearchRange || !mStartPointRange || !mEndPointRange || !mFind)
if (!prefInternal || !mFind)
return NS_ERROR_FAILURE;
SetDocShell(aDocShell);
@ -201,8 +201,8 @@ nsTypeAheadFind::SetDocShell(nsIDocShell* aDocShell)
mPresShell = do_GetWeakReference(presShell);
mStartFindRange = nsnull;
mStartPointRange = do_CreateInstance(kRangeCID);
mSearchRange = do_CreateInstance(kRangeCID);
mStartPointRange = new nsRange();
mSearchRange = new nsRange();
mFoundLink = nsnull;
mFoundEditable = nsnull;