adding NSIRangeUtil implementation and interface to content so that folks outside of layout will have some way to compare dom points to ranges or other points. Groundwork for 65557, among others. r=fm; sr=kin

This commit is contained in:
jfrancis%netscape.com 2001-04-28 12:02:14 +00:00
Родитель b9cd285721
Коммит 92252b9581
10 изменённых файлов: 257 добавлений и 26 удалений

Просмотреть файл

@ -17,6 +17,7 @@ nsINameSpace.h
nsINameSpaceManager.h
nsINodeInfo.h
nsIPrivateDOMImplementation.h
nsIRangeUtils.h
nsIStyledContent.h
nsIStyleRule.h
nsIStyleRuleProcessor.h

Просмотреть файл

@ -44,6 +44,7 @@ nsIElementFactory.h \
nsINameSpace.h \
nsINameSpaceManager.h \
nsINodeInfo.h \
nsIRangeUtils.h \
nsIStyledContent.h \
nsIStyleRule.h \
nsIStyleRuleSupplier.h \

Просмотреть файл

@ -24,38 +24,39 @@ DEPTH=..\..\..
EXPORTS = \
nsContentPolicyUtils.h \
nsIContent.h \
nsIAnonymousContent.h \
nsIAnonymousContent.h \
nsIContentIterator.h \
nsIDocument.h \
nsIDocumentContainer.h \
nsIDocumentEncoder.h \
nsIDocumentObserver.h \
nsIDocumentViewer.h \
nsIElementFactory.h \
nsIElementFactory.h \
nsINameSpace.h \
nsINameSpaceManager.h \
nsINodeInfo.h \
nsIRangeUtils.h \
nsIStyledContent.h \
nsIStyleRule.h \
nsIStyleRuleSupplier.h \
nsIStyleRuleSupplier.h \
nsIStyleSheet.h \
nsIStyleSheetLinkingElement.h \
nsIStyleRuleProcessor.h \
nsIStyleRuleProcessor.h \
nsITextContent.h \
nsContentUtils.h \
nsIPrivateDOMImplementation.h \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
nsContentUtils.h \
nsIPrivateDOMImplementation.h \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
$(NULL)
MODULE=content_base
XPIDLSRCS= \
.\nsIContentPolicy.idl \
.\nsIDiskDocument.idl \
.\nsIDiskDocument.idl \
.\nsISelectionController.idl \
.\nsISelectionListener.idl \
.\nsISelection.idl \
.\nsISelection.idl \
.\nsISelectionPrivate.idl \
$(NULL)

Просмотреть файл

@ -253,4 +253,8 @@
#define NS_XULPROTOTYPECACHE_CID \
{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {a6cf9126-15b3-11d2-932e-00805f8add32}
#define NS_RANGEUTILS_CID \
{ 0xa6cf9126, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#endif /* nsContentCID_h__ */

Просмотреть файл

@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/* A class for range utilities. */
#ifndef nsIRangeUtils_h___
#define nsIRangeUtils_h___
#include "nsISupports.h"
// Forward declarations
class nsIDOMRange;
class nsIDOMNode;
class nsIContent;
// IID for the nsIRangeUtils interface
#define NS_IRANGEUTILS_IID \
{ 0xa6cf9127, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsIRangeUtils : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRANGEUTILS_IID; return iid; }
NS_IMETHOD_(PRInt32) ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2) = 0;
NS_IMETHOD_(PRBool) IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange) = 0;
NS_IMETHOD CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
PRBool *outNodeBefore,
PRBool *outNodeAfter) = 0;
};
#endif /* nsIRangeUtils_h___ */

Просмотреть файл

@ -26,7 +26,6 @@
#include "nsRange.h"
#include "nsIDOMRange.h"
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
@ -58,6 +57,15 @@ nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
nsresult NS_NewGenRegularIterator(nsIContentIterator** aInstancePtrResult);
nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult);
#ifdef XP_MAC
#pragma mark -
#pragma mark utility functions (some exposed through nsRangeUtils, below
#pragma mark -
#endif
/******************************************************
* stack based utilty class for managing monitor
******************************************************/
@ -70,22 +78,9 @@ class nsAutoRangeLock
};
/******************************************************
* non members
******************************************************/
nsresult
NS_NewRange(nsIDOMRange** aInstancePtrResult)
{
nsRange * range = new nsRange();
if (range)
return range->QueryInterface(NS_GET_IID(nsIDOMRange), (void**) aInstancePtrResult);
return NS_ERROR_OUT_OF_MEMORY;
}
// Returns -1 if point1 < point2, 1, if point1 > point2,
// 0 if error or if point1 == point2.
// 0 if error or if point1 == point2.
PRInt32 ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2)
{
@ -155,7 +150,7 @@ PRBool IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange)
// If outNodeAfter is returned true, then the node ends after the range does.
// Note that both of the above might be true.
// If neither are true, the node is contained inside of the range.
// XXX - callers responsibility to ensure node in same doc as range!
// XXX - callers responsibility to ensure node in same doc as range!
nsresult CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
PRBool *outNodeBefore,
@ -268,6 +263,125 @@ PRBool GetNodeBracketPoints(nsIContent* aNode,
return PR_TRUE;
}
#ifdef XP_MAC
#pragma mark -
#pragma mark class nsRangeUtils
#pragma mark -
#endif
/******************************************************
* non members
******************************************************/
nsresult
NS_NewRangeUtils(nsIRangeUtils** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRangeUtils* rangeUtil = new nsRangeUtils();
if (rangeUtil)
return rangeUtil->QueryInterface(NS_GET_IID(nsIRangeUtils), (void**) aResult);
return NS_ERROR_OUT_OF_MEMORY;
}
/******************************************************
* constructor/destructor
******************************************************/
nsRangeUtils::nsRangeUtils()
{
NS_INIT_REFCNT();
}
nsRangeUtils::~nsRangeUtils()
{
}
/******************************************************
* nsISupports
******************************************************/
NS_IMPL_ADDREF(nsRangeUtils)
NS_IMPL_RELEASE(nsRangeUtils)
nsresult nsRangeUtils::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(aInstancePtrResult, "null pointer");
if (!aInstancePtrResult)
{
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID))
{
*aInstancePtrResult = (void*)(nsISupports*)(nsIRangeUtils *)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIRangeUtils)))
{
*aInstancePtrResult = (void*)(nsIRangeUtils*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
/******************************************************
* nsIRangeUtils methods
******************************************************/
NS_IMETHODIMP_(PRInt32)
nsRangeUtils::ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2)
{
return ::ComparePoints(aParent1, aOffset1, aParent2, aOffset2);
}
NS_IMETHODIMP_(PRBool)
nsRangeUtils::IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange)
{
return ::IsNodeIntersectsRange( aNode, aRange);
}
NS_IMETHODIMP
nsRangeUtils::CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
PRBool *outNodeBefore,
PRBool *outNodeAfter)
{
return ::CompareNodeToRange(aNode, aRange, outNodeBefore, outNodeAfter);
}
#ifdef XP_MAC
#pragma mark -
#pragma mark class nsRange
#pragma mark -
#endif
/******************************************************
* non members
******************************************************/
nsresult
NS_NewRange(nsIDOMRange** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRange * range = new nsRange();
if (range)
return range->QueryInterface(NS_GET_IID(nsIDOMRange), (void**) aResult);
return NS_ERROR_OUT_OF_MEMORY;
}
/******************************************************
* constructor/destructor
******************************************************/

Просмотреть файл

@ -27,6 +27,7 @@
*/
#include "nsIDOMRange.h"
#include "nsIRangeUtils.h"
#include "nsIDOMNSRange.h"
#include "nsCOMPtr.h"
#include "nsIDOMDocumentFragment.h"
@ -37,6 +38,30 @@
class nsVoidArray;
// -------------------------------------------------------------------------------
class nsRangeUtils : public nsIRangeUtils
{
public:
NS_DECL_ISUPPORTS
nsRangeUtils();
virtual ~nsRangeUtils();
// nsIRangeUtils interface
NS_IMETHOD_(PRInt32) ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2);
NS_IMETHOD_(PRBool) IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange);
NS_IMETHOD CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
PRBool *outNodeBefore,
PRBool *outNodeAfter);
};
// -------------------------------------------------------------------------------
class nsRange : public nsIDOMRange,
public nsIDOMNSRange,
public nsIScriptObjectOwner
@ -195,6 +220,9 @@ public:
// Make a new nsIDOMRange object
nsresult NS_NewRange(nsIDOMRange** aInstancePtrResult);
// Make a new nsIRangeUtils object
nsresult NS_NewRangeUtils(nsIRangeUtils** aInstancePtrResult);
/*************************************************************************************
* Utility routine to compare two "points", were a point is a node/offset pair

Просмотреть файл

@ -253,4 +253,8 @@
#define NS_XULPROTOTYPECACHE_CID \
{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {a6cf9126-15b3-11d2-932e-00805f8add32}
#define NS_RANGEUTILS_CID \
{ 0xa6cf9126, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#endif /* nsContentCID_h__ */

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsICSSStyleSheet.h"
#include "nsICSSLoader.h"
#include "nsIDOMRange.h"
#include "nsIRangeUtils.h"
#include "nsIContentIterator.h"
#include "nsINameSpaceManager.h"
#include "nsIScriptNameSetRegistry.h"
@ -135,11 +136,13 @@ static NS_DEFINE_CID(kComputedDOMStyleCID, NS_COMPUTEDDOMSTYLE_CID);
static NS_DEFINE_CID(kControllerCommandManagerCID, NS_CONTROLLERCOMMANDMANAGER_CID);
static NS_DEFINE_CID(kContentHTTPStartupCID, NS_CONTENTHTTPSTARTUP_CID);
static NS_DEFINE_CID(kRangeUtilsCID, NS_RANGEUTILS_CID);
extern nsresult NS_NewSelection(nsIFrameSelection** aResult);
extern nsresult NS_NewDomSelection(nsISelection** aResult);
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
extern nsresult NS_NewRange(nsIDOMRange** aResult);
extern nsresult NS_NewRangeUtils(nsIRangeUtils** aResult);
extern nsresult NS_NewContentIterator(nsIContentIterator** aResult);
extern nsresult NS_NewGenRegularIterator(nsIContentIterator** aResult);
extern nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aResult);
@ -605,6 +608,13 @@ nsContentFactory::CreateInstance(nsISupports *aOuter,
return res;
}
}
else if (mClassID.Equals(kRangeUtilsCID)) {
res = NS_NewRangeUtils((nsIRangeUtils**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewRangeUtils", res);
return res;
}
}
#endif
else {
return NS_NOINTERFACE;

Просмотреть файл

@ -316,6 +316,7 @@ static Components gComponents[] = {
{ "Dom selection", NS_DOMSELECTION_CID, nsnull, },
{ "Frame selection", NS_FRAMESELECTION_CID, nsnull, },
{ "Range", NS_RANGE_CID, nsnull, },
{ "Range Utils", NS_RANGEUTILS_CID, nsnull, },
{ "Content iterator", NS_CONTENTITERATOR_CID, nsnull, },
{ "Generated Content iterator", NS_GENERATEDCONTENTITERATOR_CID, nsnull, },
{ "Generated Subtree iterator", NS_GENERATEDSUBTREEITERATOR_CID, nsnull, },