зеркало из https://github.com/mozilla/gecko-dev.git
Bug 74800, implemented FIXptr. r=harishd, sr=vidur.
This commit is contained in:
Родитель
5d2cdca788
Коммит
db89a9ce21
|
@ -2119,6 +2119,14 @@ nsDocument::Load(const nsAReadableString& aUrl)
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocument::EvaluateFIXptr(const nsAReadableString& aExpression, nsIDOMRange **aRange)
|
||||
{
|
||||
NS_ERROR("nsDocument::EvaluateFIXptr() should be overriden by subclass!");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets)
|
||||
|
|
|
@ -2373,6 +2373,13 @@
|
|||
<FILEKIND>Library</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsFIXptr.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
</FILELIST>
|
||||
<LINKORDER>
|
||||
<FILEREF>
|
||||
|
@ -3420,6 +3427,11 @@
|
|||
<PATH>contentSVG.o</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsFIXptr.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
</LINKORDER>
|
||||
</TARGET>
|
||||
<TARGET>
|
||||
|
@ -5742,6 +5754,13 @@
|
|||
<FILEKIND>Library</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsFIXptr.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
</FILELIST>
|
||||
<LINKORDER>
|
||||
<FILEREF>
|
||||
|
@ -6789,6 +6808,11 @@
|
|||
<PATH>contentSVGDebug.o</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsFIXptr.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
</LINKORDER>
|
||||
</TARGET>
|
||||
</TARGETLIST>
|
||||
|
@ -7770,6 +7794,12 @@
|
|||
<PATH>nsXMLDocument.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>content.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsFIXptr.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
</GROUP>
|
||||
<GROUP><NAME>xsl</NAME>
|
||||
<FILEREF>
|
||||
|
|
|
@ -55,6 +55,7 @@ REQUIRES = xpcom \
|
|||
CPPSRCS = \
|
||||
nsXMLContentSink.cpp \
|
||||
nsXMLDocument.cpp \
|
||||
nsFIXptr.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
|
|
|
@ -52,6 +52,7 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
|||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsXMLContentSink.obj \
|
||||
.\$(OBJDIR)\nsXMLDocument.obj \
|
||||
.\$(OBJDIR)\nsFIXptr.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -0,0 +1,333 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 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
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Heikki Toivonen <heikki@netscape.com> (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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Implementation for FIXptr, a W3C NOTE.
|
||||
*
|
||||
* http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm
|
||||
*
|
||||
*/
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsFIXptr.h"
|
||||
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
// Get nth child element
|
||||
static nsresult GetChild(nsIDOMNode *aParent, PRInt32 aChildNum, nsIDOMNode **aChild)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
NS_ENSURE_ARG_POINTER(aChild);
|
||||
|
||||
*aChild = nsnull;
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
aParent->GetChildNodes(getter_AddRefs(list));
|
||||
if (!list)
|
||||
return NS_OK;
|
||||
|
||||
PRUint32 count;
|
||||
list->GetLength(&count);
|
||||
PRUint32 i;
|
||||
PRInt32 curChildNum = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
list->Item(i, getter_AddRefs(node));
|
||||
if (!node)
|
||||
break;
|
||||
PRUint16 nodeType;
|
||||
node->GetNodeType(&nodeType);
|
||||
if (nodeType == nsIDOMNode::ELEMENT_NODE) {
|
||||
curChildNum++;
|
||||
}
|
||||
if (curChildNum == aChildNum) {
|
||||
*aChild = node;
|
||||
NS_ADDREF(*aChild);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get range for char index
|
||||
static nsresult GetCharRange(nsIDOMNode *aParent, PRInt32 aCharNum, nsIDOMRange **aRange)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
NS_ENSURE_ARG_POINTER(aRange);
|
||||
|
||||
*aRange = nsnull;
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
aParent->GetChildNodes(getter_AddRefs(list));
|
||||
if (!list)
|
||||
return NS_OK;
|
||||
|
||||
PRUint32 count;
|
||||
list->GetLength(&count);
|
||||
PRUint32 i;
|
||||
PRInt32 maxCharNum = 0;
|
||||
PRInt32 prevCharNum = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
list->Item(i, getter_AddRefs(node));
|
||||
if (!node)
|
||||
break;
|
||||
PRUint16 nodeType;
|
||||
node->GetNodeType(&nodeType);
|
||||
if (nodeType & (nsIDOMNode::TEXT_NODE | nsIDOMNode::CDATA_SECTION_NODE)) {
|
||||
nsAutoString value;
|
||||
node->GetNodeValue(value);
|
||||
maxCharNum += value.Length();
|
||||
}
|
||||
if (maxCharNum >= aCharNum) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
|
||||
if (!range)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
range->SetStart(node, aCharNum - prevCharNum);
|
||||
range->SetEnd(node, aCharNum - prevCharNum + 1);
|
||||
*aRange = range.get();
|
||||
NS_ADDREF(*aRange);
|
||||
break;
|
||||
}
|
||||
prevCharNum = maxCharNum;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get node by tumbler
|
||||
static nsresult GetTumblerNode(nsIDOMNode *aParent, const nsString &aTumbler, nsIDOMNode **aNode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
NS_ENSURE_ARG_POINTER(aNode);
|
||||
|
||||
*aNode = nsnull;
|
||||
nsAutoString tumbler(aTumbler);
|
||||
if (tumbler[0] == '/')
|
||||
tumbler.Cut(0, 1);
|
||||
nsCOMPtr<nsIDOMNode> node(aParent);
|
||||
while (!tumbler.IsEmpty() && node) {
|
||||
PRInt32 sep = tumbler.FindChar('/');
|
||||
if (sep > 0) {
|
||||
nsAutoString num;
|
||||
tumbler.Left(num, sep);
|
||||
PRInt32 error;
|
||||
PRInt32 n = num.ToInteger(&error);
|
||||
if (n <= 0) {
|
||||
node = nsnull;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
GetChild(node, n, getter_AddRefs(child));
|
||||
node = child;
|
||||
} else {
|
||||
// Last
|
||||
PRInt32 error;
|
||||
PRInt32 n = tumbler.ToInteger(&error);
|
||||
if (n <= 0) {
|
||||
node = nsnull;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
GetChild(node, n, getter_AddRefs(child));
|
||||
node = child;
|
||||
break;
|
||||
}
|
||||
tumbler.Cut(0, sep + 1);
|
||||
}
|
||||
*aNode = node.get();
|
||||
NS_IF_ADDREF(*aNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult GetRange(
|
||||
nsIDOMDocument *aDocument,
|
||||
const nsAString& aExpression,
|
||||
nsIDOMRange **aRange)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
if (nsString::IsAlpha(aExpression.First())) {
|
||||
// name
|
||||
nsAutoString id;
|
||||
const nsAutoString expression(aExpression);
|
||||
PRInt32 sep = expression.FindCharInSet("/(");
|
||||
if (sep > 0) {
|
||||
expression.Left(id,sep);
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
aDocument->GetElementById(id, getter_AddRefs(element));
|
||||
node = do_QueryInterface(element);
|
||||
if (node) {
|
||||
if (expression[sep] == '/') {
|
||||
// tumbler
|
||||
nsAutoString tumbler;
|
||||
expression.Mid(tumbler, sep, expression.Length());
|
||||
sep = tumbler.FindChar('(');
|
||||
if (sep > 0)
|
||||
tumbler.Truncate(sep);
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
GetTumblerNode(node, tumbler, getter_AddRefs(child));
|
||||
node = child;
|
||||
}
|
||||
// char
|
||||
sep = expression.FindChar('(');
|
||||
if (sep > 0) {
|
||||
nsAutoString charNum(aExpression);
|
||||
if (charNum[charNum.Length() -1] == ')') {
|
||||
charNum.Truncate(charNum.Length() - 1);
|
||||
charNum.Cut(0, sep + 1);
|
||||
PRInt32 error;
|
||||
PRInt32 n = charNum.ToInteger(&error);
|
||||
if (n < 1)
|
||||
return NS_OK;
|
||||
rv = GetCharRange(node, n - 1, aRange);
|
||||
if (!*aRange) {
|
||||
node = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// just name
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
aDocument->GetElementById(expression, getter_AddRefs(element));
|
||||
node = do_QueryInterface(element);
|
||||
}
|
||||
} else if (aExpression.First() == '/') {
|
||||
// Starts with tumbler
|
||||
node = do_QueryInterface(aDocument);
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
nsAutoString tumbler(aExpression);
|
||||
PRInt32 sep = tumbler.FindChar('(');
|
||||
if (sep > 0)
|
||||
tumbler.Truncate(sep);
|
||||
GetTumblerNode(node, tumbler, getter_AddRefs(child));
|
||||
node = child;
|
||||
// char
|
||||
sep = aExpression.FindChar('(');
|
||||
if (sep > 0) {
|
||||
nsAutoString charNum(aExpression);
|
||||
if (charNum[charNum.Length() -1] == ')') {
|
||||
charNum.Truncate(charNum.Length() - 1);
|
||||
charNum.Cut(0, sep + 1);
|
||||
PRInt32 error;
|
||||
PRInt32 n = charNum.ToInteger(&error);
|
||||
if (n < 1)
|
||||
return NS_OK;
|
||||
rv = GetCharRange(node, n - 1, aRange);
|
||||
if (!*aRange) {
|
||||
node = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not FIXptr
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !*aRange && node) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
|
||||
if (!range)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
range->SelectNode(node);
|
||||
*aRange = range.get();
|
||||
NS_ADDREF(*aRange);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate a FIXptr expression.
|
||||
*
|
||||
* @param aDocument The document in which to evaluate.
|
||||
* @param aExpression The FIXptr expression string to evaluate.
|
||||
* @param aRange The resulting range.
|
||||
*/
|
||||
nsresult
|
||||
nsFIXptr::Evaluate(nsIDOMDocument *aDocument,
|
||||
const nsAString& aExpression,
|
||||
nsIDOMRange **aRange)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDocument);
|
||||
NS_ENSURE_ARG_POINTER(aRange);
|
||||
*aRange = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 split = aExpression.FindChar(',');
|
||||
if (split >= 0) {
|
||||
nsAutoString expr1, expr2;
|
||||
nsCOMPtr<nsIDOMRange> range1, range2;
|
||||
|
||||
aExpression.Left(expr1, split);
|
||||
aExpression.Mid(expr2, split + 1, aExpression.Length());
|
||||
|
||||
rv = GetRange(aDocument, expr1, getter_AddRefs(range1));
|
||||
if (!range1)
|
||||
return rv;
|
||||
rv = GetRange(aDocument, expr2, getter_AddRefs(range2));
|
||||
if (!range2)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> begin, end;
|
||||
PRInt32 beginOffset, endOffset;
|
||||
range1->GetStartContainer(getter_AddRefs(begin));
|
||||
range1->GetStartOffset(&beginOffset);
|
||||
range2->GetEndContainer(getter_AddRefs(end));
|
||||
range2->GetEndOffset(&endOffset);
|
||||
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
range->SetStart(begin, beginOffset);
|
||||
range->SetEnd(end, endOffset);
|
||||
*aRange = range.get();
|
||||
NS_ADDREF(*aRange);
|
||||
} else {
|
||||
rv = GetRange(aDocument, aExpression, aRange);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 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
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Heikki Toivonen <heikki@netscape.com> (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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/**
|
||||
* Implementation for FIXptr, a W3C NOTE.
|
||||
*
|
||||
* http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm
|
||||
*
|
||||
*/
|
||||
#ifndef nsFIXptr_h__
|
||||
#define nsFIXptr_h__
|
||||
|
||||
class nsIDOMDocument;
|
||||
class nsIDOMRange;
|
||||
class nsISelection;
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
class nsFIXptr {
|
||||
nsFIXptr(); // Use the static members for now
|
||||
~nsFIXptr();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Evaluate a FIXptr expression.
|
||||
*
|
||||
* @param aDocument The document in which to evaluate.
|
||||
* @param aExpression The FIXptr expression string to evaluate.
|
||||
* @param aRange The range.
|
||||
*/
|
||||
static nsresult Evaluate(nsIDOMDocument *aDocument,
|
||||
const nsAString& aExpression,
|
||||
nsIDOMRange **aRange);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -91,7 +91,7 @@
|
|||
#include "nsContentCID.h"
|
||||
#include "nsDOMAttribute.h"
|
||||
#include "nsGUIEvent.h"
|
||||
|
||||
#include "nsFIXptr.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -310,6 +310,12 @@ nsXMLDocument::OnRedirect(nsIHttpChannel *aHttpChannel, nsIChannel *aNewChannel)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::EvaluateFIXptr(const nsAReadableString& aExpression, nsIDOMRange **aRange)
|
||||
{
|
||||
return nsFIXptr::Evaluate(this, aExpression, aRange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::Load(const nsAReadableString& aUrl)
|
||||
{
|
||||
|
|
|
@ -43,4 +43,14 @@
|
|||
interface nsIDOMXMLDocument : nsIDOMDocument
|
||||
{
|
||||
void load(in DOMString url);
|
||||
|
||||
/**
|
||||
* Evaluate FIXptr expression. FIXptr is a W3C NOTE, see
|
||||
*
|
||||
* http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm
|
||||
*
|
||||
* @param expression FIXptr string.
|
||||
* @return The range object that results from evaluation
|
||||
*/
|
||||
nsIDOMRange evaluateFIXptr(in DOMString expression);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,333 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 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
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Heikki Toivonen <heikki@netscape.com> (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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Implementation for FIXptr, a W3C NOTE.
|
||||
*
|
||||
* http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm
|
||||
*
|
||||
*/
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsFIXptr.h"
|
||||
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
// Get nth child element
|
||||
static nsresult GetChild(nsIDOMNode *aParent, PRInt32 aChildNum, nsIDOMNode **aChild)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
NS_ENSURE_ARG_POINTER(aChild);
|
||||
|
||||
*aChild = nsnull;
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
aParent->GetChildNodes(getter_AddRefs(list));
|
||||
if (!list)
|
||||
return NS_OK;
|
||||
|
||||
PRUint32 count;
|
||||
list->GetLength(&count);
|
||||
PRUint32 i;
|
||||
PRInt32 curChildNum = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
list->Item(i, getter_AddRefs(node));
|
||||
if (!node)
|
||||
break;
|
||||
PRUint16 nodeType;
|
||||
node->GetNodeType(&nodeType);
|
||||
if (nodeType == nsIDOMNode::ELEMENT_NODE) {
|
||||
curChildNum++;
|
||||
}
|
||||
if (curChildNum == aChildNum) {
|
||||
*aChild = node;
|
||||
NS_ADDREF(*aChild);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get range for char index
|
||||
static nsresult GetCharRange(nsIDOMNode *aParent, PRInt32 aCharNum, nsIDOMRange **aRange)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
NS_ENSURE_ARG_POINTER(aRange);
|
||||
|
||||
*aRange = nsnull;
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
aParent->GetChildNodes(getter_AddRefs(list));
|
||||
if (!list)
|
||||
return NS_OK;
|
||||
|
||||
PRUint32 count;
|
||||
list->GetLength(&count);
|
||||
PRUint32 i;
|
||||
PRInt32 maxCharNum = 0;
|
||||
PRInt32 prevCharNum = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
list->Item(i, getter_AddRefs(node));
|
||||
if (!node)
|
||||
break;
|
||||
PRUint16 nodeType;
|
||||
node->GetNodeType(&nodeType);
|
||||
if (nodeType & (nsIDOMNode::TEXT_NODE | nsIDOMNode::CDATA_SECTION_NODE)) {
|
||||
nsAutoString value;
|
||||
node->GetNodeValue(value);
|
||||
maxCharNum += value.Length();
|
||||
}
|
||||
if (maxCharNum >= aCharNum) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
|
||||
if (!range)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
range->SetStart(node, aCharNum - prevCharNum);
|
||||
range->SetEnd(node, aCharNum - prevCharNum + 1);
|
||||
*aRange = range.get();
|
||||
NS_ADDREF(*aRange);
|
||||
break;
|
||||
}
|
||||
prevCharNum = maxCharNum;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get node by tumbler
|
||||
static nsresult GetTumblerNode(nsIDOMNode *aParent, const nsString &aTumbler, nsIDOMNode **aNode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
NS_ENSURE_ARG_POINTER(aNode);
|
||||
|
||||
*aNode = nsnull;
|
||||
nsAutoString tumbler(aTumbler);
|
||||
if (tumbler[0] == '/')
|
||||
tumbler.Cut(0, 1);
|
||||
nsCOMPtr<nsIDOMNode> node(aParent);
|
||||
while (!tumbler.IsEmpty() && node) {
|
||||
PRInt32 sep = tumbler.FindChar('/');
|
||||
if (sep > 0) {
|
||||
nsAutoString num;
|
||||
tumbler.Left(num, sep);
|
||||
PRInt32 error;
|
||||
PRInt32 n = num.ToInteger(&error);
|
||||
if (n <= 0) {
|
||||
node = nsnull;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
GetChild(node, n, getter_AddRefs(child));
|
||||
node = child;
|
||||
} else {
|
||||
// Last
|
||||
PRInt32 error;
|
||||
PRInt32 n = tumbler.ToInteger(&error);
|
||||
if (n <= 0) {
|
||||
node = nsnull;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
GetChild(node, n, getter_AddRefs(child));
|
||||
node = child;
|
||||
break;
|
||||
}
|
||||
tumbler.Cut(0, sep + 1);
|
||||
}
|
||||
*aNode = node.get();
|
||||
NS_IF_ADDREF(*aNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult GetRange(
|
||||
nsIDOMDocument *aDocument,
|
||||
const nsAString& aExpression,
|
||||
nsIDOMRange **aRange)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
if (nsString::IsAlpha(aExpression.First())) {
|
||||
// name
|
||||
nsAutoString id;
|
||||
const nsAutoString expression(aExpression);
|
||||
PRInt32 sep = expression.FindCharInSet("/(");
|
||||
if (sep > 0) {
|
||||
expression.Left(id,sep);
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
aDocument->GetElementById(id, getter_AddRefs(element));
|
||||
node = do_QueryInterface(element);
|
||||
if (node) {
|
||||
if (expression[sep] == '/') {
|
||||
// tumbler
|
||||
nsAutoString tumbler;
|
||||
expression.Mid(tumbler, sep, expression.Length());
|
||||
sep = tumbler.FindChar('(');
|
||||
if (sep > 0)
|
||||
tumbler.Truncate(sep);
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
GetTumblerNode(node, tumbler, getter_AddRefs(child));
|
||||
node = child;
|
||||
}
|
||||
// char
|
||||
sep = expression.FindChar('(');
|
||||
if (sep > 0) {
|
||||
nsAutoString charNum(aExpression);
|
||||
if (charNum[charNum.Length() -1] == ')') {
|
||||
charNum.Truncate(charNum.Length() - 1);
|
||||
charNum.Cut(0, sep + 1);
|
||||
PRInt32 error;
|
||||
PRInt32 n = charNum.ToInteger(&error);
|
||||
if (n < 1)
|
||||
return NS_OK;
|
||||
rv = GetCharRange(node, n - 1, aRange);
|
||||
if (!*aRange) {
|
||||
node = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// just name
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
aDocument->GetElementById(expression, getter_AddRefs(element));
|
||||
node = do_QueryInterface(element);
|
||||
}
|
||||
} else if (aExpression.First() == '/') {
|
||||
// Starts with tumbler
|
||||
node = do_QueryInterface(aDocument);
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
nsAutoString tumbler(aExpression);
|
||||
PRInt32 sep = tumbler.FindChar('(');
|
||||
if (sep > 0)
|
||||
tumbler.Truncate(sep);
|
||||
GetTumblerNode(node, tumbler, getter_AddRefs(child));
|
||||
node = child;
|
||||
// char
|
||||
sep = aExpression.FindChar('(');
|
||||
if (sep > 0) {
|
||||
nsAutoString charNum(aExpression);
|
||||
if (charNum[charNum.Length() -1] == ')') {
|
||||
charNum.Truncate(charNum.Length() - 1);
|
||||
charNum.Cut(0, sep + 1);
|
||||
PRInt32 error;
|
||||
PRInt32 n = charNum.ToInteger(&error);
|
||||
if (n < 1)
|
||||
return NS_OK;
|
||||
rv = GetCharRange(node, n - 1, aRange);
|
||||
if (!*aRange) {
|
||||
node = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not FIXptr
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !*aRange && node) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
|
||||
if (!range)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
range->SelectNode(node);
|
||||
*aRange = range.get();
|
||||
NS_ADDREF(*aRange);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate a FIXptr expression.
|
||||
*
|
||||
* @param aDocument The document in which to evaluate.
|
||||
* @param aExpression The FIXptr expression string to evaluate.
|
||||
* @param aRange The resulting range.
|
||||
*/
|
||||
nsresult
|
||||
nsFIXptr::Evaluate(nsIDOMDocument *aDocument,
|
||||
const nsAString& aExpression,
|
||||
nsIDOMRange **aRange)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDocument);
|
||||
NS_ENSURE_ARG_POINTER(aRange);
|
||||
*aRange = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 split = aExpression.FindChar(',');
|
||||
if (split >= 0) {
|
||||
nsAutoString expr1, expr2;
|
||||
nsCOMPtr<nsIDOMRange> range1, range2;
|
||||
|
||||
aExpression.Left(expr1, split);
|
||||
aExpression.Mid(expr2, split + 1, aExpression.Length());
|
||||
|
||||
rv = GetRange(aDocument, expr1, getter_AddRefs(range1));
|
||||
if (!range1)
|
||||
return rv;
|
||||
rv = GetRange(aDocument, expr2, getter_AddRefs(range2));
|
||||
if (!range2)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> begin, end;
|
||||
PRInt32 beginOffset, endOffset;
|
||||
range1->GetStartContainer(getter_AddRefs(begin));
|
||||
range1->GetStartOffset(&beginOffset);
|
||||
range2->GetEndContainer(getter_AddRefs(end));
|
||||
range2->GetEndOffset(&endOffset);
|
||||
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
range->SetStart(begin, beginOffset);
|
||||
range->SetEnd(end, endOffset);
|
||||
*aRange = range.get();
|
||||
NS_ADDREF(*aRange);
|
||||
} else {
|
||||
rv = GetRange(aDocument, aExpression, aRange);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 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
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Heikki Toivonen <heikki@netscape.com> (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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/**
|
||||
* Implementation for FIXptr, a W3C NOTE.
|
||||
*
|
||||
* http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm
|
||||
*
|
||||
*/
|
||||
#ifndef nsFIXptr_h__
|
||||
#define nsFIXptr_h__
|
||||
|
||||
class nsIDOMDocument;
|
||||
class nsIDOMRange;
|
||||
class nsISelection;
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
class nsFIXptr {
|
||||
nsFIXptr(); // Use the static members for now
|
||||
~nsFIXptr();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Evaluate a FIXptr expression.
|
||||
*
|
||||
* @param aDocument The document in which to evaluate.
|
||||
* @param aExpression The FIXptr expression string to evaluate.
|
||||
* @param aRange The range.
|
||||
*/
|
||||
static nsresult Evaluate(nsIDOMDocument *aDocument,
|
||||
const nsAString& aExpression,
|
||||
nsIDOMRange **aRange);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -84,6 +84,7 @@
|
|||
#include "nsICaret.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIXMLDocument.h"
|
||||
#include "nsIDOMXMLDocument.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsParserCIID.h"
|
||||
|
@ -1157,7 +1158,7 @@ protected:
|
|||
nsresult SetPrefLinkRules(void);
|
||||
nsresult SetPrefFocusRules(void);
|
||||
|
||||
nsresult SelectContent(nsIContent *aContent);
|
||||
nsresult SelectRange(nsIDOMRange *aRange);
|
||||
|
||||
// IMPORTANT: The ownership implicit in the following member variables has been
|
||||
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
|
||||
|
@ -3931,7 +3932,22 @@ PresShell::GoToAnchor(const nsString& aAnchorName)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Finally try FIXptr
|
||||
nsCOMPtr<nsIDOMRange> fixPtrRange;
|
||||
if (!content) {
|
||||
nsCOMPtr<nsIDOMXMLDocument> xmldoc = do_QueryInterface(mDocument);
|
||||
if (xmldoc) {
|
||||
xmldoc->EvaluateFIXptr(aAnchorName,getter_AddRefs(fixPtrRange));
|
||||
if (fixPtrRange) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
fixPtrRange->GetStartContainer(getter_AddRefs(node));
|
||||
if (node) {
|
||||
node->QueryInterface(NS_GET_IID(nsIContent),getter_AddRefs(content));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (content) {
|
||||
nsIFrame* frame;
|
||||
|
||||
|
@ -3946,10 +3962,18 @@ PresShell::GoToAnchor(const nsString& aAnchorName)
|
|||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID,&rv));
|
||||
if (NS_SUCCEEDED(rv) && prefs) {
|
||||
PRBool selectAnchor;
|
||||
nsresult rvPref;
|
||||
rvPref = prefs->GetBoolPref("layout.selectanchor",&selectAnchor);
|
||||
nsresult rvPref = prefs->GetBoolPref("layout.selectanchor",&selectAnchor);
|
||||
if (NS_SUCCEEDED(rvPref) && selectAnchor) {
|
||||
rv = SelectContent(content);
|
||||
if (!fixPtrRange) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
|
||||
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
|
||||
if (range && node) {
|
||||
range->SelectNode(node);
|
||||
SelectRange(range);
|
||||
}
|
||||
} else {
|
||||
SelectRange(fixPtrRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3980,21 +4004,13 @@ PresShell::GoToAnchor(const nsString& aAnchorName)
|
|||
}
|
||||
|
||||
nsresult
|
||||
PresShell::SelectContent(nsIContent *aContent)
|
||||
PresShell::SelectRange(nsIDOMRange *aRange)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISelection> sel;
|
||||
rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));
|
||||
nsresult rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));
|
||||
if (NS_SUCCEEDED(rv) && sel) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID,&rv));
|
||||
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aContent));
|
||||
if (NS_SUCCEEDED(rv) && node) {
|
||||
rv = range->SelectNode(node);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
sel->RemoveAllRanges();
|
||||
rv = sel->AddRange(range);
|
||||
}
|
||||
}
|
||||
sel->RemoveAllRanges();
|
||||
sel->AddRange(aRange);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
#include "nsICaret.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIXMLDocument.h"
|
||||
#include "nsIDOMXMLDocument.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsParserCIID.h"
|
||||
|
@ -1157,7 +1158,7 @@ protected:
|
|||
nsresult SetPrefLinkRules(void);
|
||||
nsresult SetPrefFocusRules(void);
|
||||
|
||||
nsresult SelectContent(nsIContent *aContent);
|
||||
nsresult SelectRange(nsIDOMRange *aRange);
|
||||
|
||||
// IMPORTANT: The ownership implicit in the following member variables has been
|
||||
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
|
||||
|
@ -3931,7 +3932,22 @@ PresShell::GoToAnchor(const nsString& aAnchorName)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Finally try FIXptr
|
||||
nsCOMPtr<nsIDOMRange> fixPtrRange;
|
||||
if (!content) {
|
||||
nsCOMPtr<nsIDOMXMLDocument> xmldoc = do_QueryInterface(mDocument);
|
||||
if (xmldoc) {
|
||||
xmldoc->EvaluateFIXptr(aAnchorName,getter_AddRefs(fixPtrRange));
|
||||
if (fixPtrRange) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
fixPtrRange->GetStartContainer(getter_AddRefs(node));
|
||||
if (node) {
|
||||
node->QueryInterface(NS_GET_IID(nsIContent),getter_AddRefs(content));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (content) {
|
||||
nsIFrame* frame;
|
||||
|
||||
|
@ -3946,10 +3962,18 @@ PresShell::GoToAnchor(const nsString& aAnchorName)
|
|||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID,&rv));
|
||||
if (NS_SUCCEEDED(rv) && prefs) {
|
||||
PRBool selectAnchor;
|
||||
nsresult rvPref;
|
||||
rvPref = prefs->GetBoolPref("layout.selectanchor",&selectAnchor);
|
||||
nsresult rvPref = prefs->GetBoolPref("layout.selectanchor",&selectAnchor);
|
||||
if (NS_SUCCEEDED(rvPref) && selectAnchor) {
|
||||
rv = SelectContent(content);
|
||||
if (!fixPtrRange) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
|
||||
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
|
||||
if (range && node) {
|
||||
range->SelectNode(node);
|
||||
SelectRange(range);
|
||||
}
|
||||
} else {
|
||||
SelectRange(fixPtrRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3980,21 +4004,13 @@ PresShell::GoToAnchor(const nsString& aAnchorName)
|
|||
}
|
||||
|
||||
nsresult
|
||||
PresShell::SelectContent(nsIContent *aContent)
|
||||
PresShell::SelectRange(nsIDOMRange *aRange)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISelection> sel;
|
||||
rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));
|
||||
nsresult rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));
|
||||
if (NS_SUCCEEDED(rv) && sel) {
|
||||
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID,&rv));
|
||||
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aContent));
|
||||
if (NS_SUCCEEDED(rv) && node) {
|
||||
rv = range->SelectNode(node);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
sel->RemoveAllRanges();
|
||||
rv = sel->AddRange(range);
|
||||
}
|
||||
}
|
||||
sel->RemoveAllRanges();
|
||||
sel->AddRange(aRange);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
Загрузка…
Ссылка в новой задаче