зеркало из https://github.com/mozilla/gecko-dev.git
Bug 698384 - Make document.createNodeIterator's 2nd and 3rd parameters optional. r=smaug
This commit is contained in:
Родитель
22ac193955
Коммит
877f5228df
|
@ -73,6 +73,7 @@
|
|||
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsAsyncDOMEvent.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
|
||||
#include "nsIDOMStyleSheet.h"
|
||||
#include "nsDOMAttribute.h"
|
||||
|
@ -5024,11 +5025,15 @@ NS_IMETHODIMP
|
|||
nsDocument::CreateNodeIterator(nsIDOMNode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aEntityReferenceExpansion,
|
||||
PRUint8 aOptionalArgc,
|
||||
nsIDOMNodeIterator **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
if (!aOptionalArgc) {
|
||||
aWhatToShow = nsIDOMNodeFilter::SHOW_ALL;
|
||||
}
|
||||
|
||||
if (!aRoot)
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
|
||||
|
@ -5042,8 +5047,7 @@ nsDocument::CreateNodeIterator(nsIDOMNode *aRoot,
|
|||
|
||||
nsNodeIterator *iterator = new nsNodeIterator(root,
|
||||
aWhatToShow,
|
||||
aFilter,
|
||||
aEntityReferenceExpansion);
|
||||
aFilter);
|
||||
NS_ENSURE_TRUE(iterator, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*_retval = iterator);
|
||||
|
@ -5055,11 +5059,15 @@ NS_IMETHODIMP
|
|||
nsDocument::CreateTreeWalker(nsIDOMNode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aEntityReferenceExpansion,
|
||||
PRUint8 aOptionalArgc,
|
||||
nsIDOMTreeWalker **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
if (!aOptionalArgc) {
|
||||
aWhatToShow = nsIDOMNodeFilter::SHOW_ALL;
|
||||
}
|
||||
|
||||
if (!aRoot)
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
|
||||
|
@ -5073,8 +5081,7 @@ nsDocument::CreateTreeWalker(nsIDOMNode *aRoot,
|
|||
|
||||
nsTreeWalker* walker = new nsTreeWalker(root,
|
||||
aWhatToShow,
|
||||
aFilter,
|
||||
aEntityReferenceExpansion);
|
||||
aFilter);
|
||||
NS_ENSURE_TRUE(walker, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*_retval = walker);
|
||||
|
|
|
@ -170,9 +170,8 @@ void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
|
|||
|
||||
nsNodeIterator::nsNodeIterator(nsINode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aExpandEntityReferences) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter, aExpandEntityReferences),
|
||||
nsIDOMNodeFilter *aFilter) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter),
|
||||
mDetached(false),
|
||||
mPointer(mRoot, true)
|
||||
{
|
||||
|
@ -247,7 +246,7 @@ NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
|
|||
/* readonly attribute boolean expandEntityReferences; */
|
||||
NS_IMETHODIMP nsNodeIterator::GetExpandEntityReferences(bool *aExpandEntityReferences)
|
||||
{
|
||||
*aExpandEntityReferences = mExpandEntityReferences;
|
||||
*aExpandEntityReferences = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,8 +63,7 @@ public:
|
|||
|
||||
nsNodeIterator(nsINode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aExpandEntityReferences);
|
||||
nsIDOMNodeFilter *aFilter);
|
||||
virtual ~nsNodeIterator();
|
||||
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
||||
|
|
|
@ -49,12 +49,10 @@
|
|||
|
||||
nsTraversal::nsTraversal(nsINode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aExpandEntityReferences) :
|
||||
nsIDOMNodeFilter *aFilter) :
|
||||
mRoot(aRoot),
|
||||
mWhatToShow(aWhatToShow),
|
||||
mFilter(aFilter),
|
||||
mExpandEntityReferences(aExpandEntityReferences),
|
||||
mInAcceptNode(false)
|
||||
{
|
||||
NS_ASSERTION(aRoot, "invalid root in call to nsTraversal constructor");
|
||||
|
|
|
@ -54,15 +54,13 @@ class nsTraversal
|
|||
public:
|
||||
nsTraversal(nsINode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aExpandEntityReferences);
|
||||
nsIDOMNodeFilter *aFilter);
|
||||
virtual ~nsTraversal();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsINode> mRoot;
|
||||
PRUint32 mWhatToShow;
|
||||
nsCOMPtr<nsIDOMNodeFilter> mFilter;
|
||||
bool mExpandEntityReferences;
|
||||
bool mInAcceptNode;
|
||||
|
||||
/*
|
||||
|
|
|
@ -58,9 +58,8 @@
|
|||
|
||||
nsTreeWalker::nsTreeWalker(nsINode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aExpandEntityReferences) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter, aExpandEntityReferences),
|
||||
nsIDOMNodeFilter *aFilter) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter),
|
||||
mCurrentNode(aRoot)
|
||||
{
|
||||
}
|
||||
|
@ -127,7 +126,7 @@ NS_IMETHODIMP nsTreeWalker::GetFilter(nsIDOMNodeFilter * *aFilter)
|
|||
NS_IMETHODIMP
|
||||
nsTreeWalker::GetExpandEntityReferences(bool *aExpandEntityReferences)
|
||||
{
|
||||
*aExpandEntityReferences = mExpandEntityReferences;
|
||||
*aExpandEntityReferences = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,8 +63,7 @@ public:
|
|||
|
||||
nsTreeWalker(nsINode *aRoot,
|
||||
PRUint32 aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter,
|
||||
bool aExpandEntityReferences);
|
||||
nsIDOMNodeFilter *aFilter);
|
||||
virtual ~nsTreeWalker();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeWalker)
|
||||
|
|
|
@ -542,6 +542,7 @@ _TEST_FILES2 = \
|
|||
test_bug708620.html \
|
||||
file_bug708620.html \
|
||||
file_bug708620-2.html \
|
||||
test_bug698384.html \
|
||||
$(NULL)
|
||||
|
||||
_CHROME_FILES = \
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=698384
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 698384</title>
|
||||
<script type="text/javascript"
|
||||
src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script src="/tests/SimpleTest/EventUtils.js"
|
||||
type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body onload="runTests();">
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=698384">
|
||||
Mozilla Bug 698384</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
/*
|
||||
Checks to see if default parameter handling is correct when 0, 1
|
||||
or 2 parameters are passed.
|
||||
|
||||
If one is only passed, aFilter should default to null
|
||||
If none are passed, aFilter should be null and aWhatToShow should
|
||||
be NodeFilter.SHOW_ALL
|
||||
*/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var content = $('content'),
|
||||
ni;
|
||||
|
||||
content.innerHTML = ('<span id="A"><\/span><span id="B"><\/span>'
|
||||
+ '<span id="C"><\/span>');
|
||||
|
||||
function runTests() {
|
||||
|
||||
// Test NodeIterator when no optional arguments are given
|
||||
ni = document.createNodeIterator(content);
|
||||
is(ni.whatToShow, NodeFilter.SHOW_ALL, "whatToShow should be " +
|
||||
"NodeFilter.SHOW_ALL when both " +
|
||||
" optionals are not given");
|
||||
is(ni.filter, null, "filter should be defaulted to null when both " +
|
||||
" optionals are not given");
|
||||
|
||||
// Test NodeIterator when first optional is passed
|
||||
ni = document.createNodeIterator(content, NodeFilter.SHOW_ELEMENT);
|
||||
is(ni.filter, null, "filter should be defaulted to null when only " +
|
||||
" first argument is passed");
|
||||
is(ni.whatToShow, NodeFilter.SHOW_ELEMENT, "whatToShow should " +
|
||||
"properly be set to NodeFilter.SHOW_ELEMENT when whatToShow is " +
|
||||
"provided and filter is not");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -66,7 +66,7 @@ interface nsIDOMLocation;
|
|||
* http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html
|
||||
*/
|
||||
|
||||
[scriptable, uuid(5c3bff4d-ae7f-4c93-948c-519589672c30)]
|
||||
[scriptable, uuid(d7cdd08e-1bfd-4bc3-9742-d66586781ee2)]
|
||||
interface nsIDOMDocument : nsIDOMNode
|
||||
{
|
||||
readonly attribute nsIDOMDocumentType doctype;
|
||||
|
@ -118,15 +118,13 @@ interface nsIDOMDocument : nsIDOMNode
|
|||
*/
|
||||
nsIDOMRange createRange();
|
||||
|
||||
nsIDOMNodeIterator createNodeIterator(in nsIDOMNode root,
|
||||
in unsigned long whatToShow,
|
||||
in nsIDOMNodeFilter filter,
|
||||
in boolean entityReferenceExpansion)
|
||||
[optional_argc] nsIDOMNodeIterator createNodeIterator(in nsIDOMNode root,
|
||||
[optional] in unsigned long whatToShow,
|
||||
[optional] in nsIDOMNodeFilter filter)
|
||||
raises(DOMException);
|
||||
nsIDOMTreeWalker createTreeWalker(in nsIDOMNode root,
|
||||
in unsigned long whatToShow,
|
||||
in nsIDOMNodeFilter filter,
|
||||
in boolean entityReferenceExpansion)
|
||||
[optional_argc] nsIDOMTreeWalker createTreeWalker(in nsIDOMNode root,
|
||||
[optional] in unsigned long whatToShow,
|
||||
[optional] in nsIDOMNodeFilter filter)
|
||||
raises(DOMException);
|
||||
|
||||
nsIDOMEvent createEvent(in DOMString eventType)
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/* -*- Mode: IDL; 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 this file as it was released on May 1 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Jonas Sicking.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jonas Sicking <sicking@bigfoot.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 ***** */
|
||||
|
||||
#include "domstubs.idl"
|
||||
|
||||
interface nsIDOMNodeIterator;
|
||||
interface nsIDOMNodeFilter;
|
||||
interface nsIDOMTreeWalker;
|
||||
|
||||
|
||||
[scriptable, uuid(13f236c0-47f8-11d5-b6a3-009027446e84)]
|
||||
// Introduced in DOM Level 2:
|
||||
interface nsIDOMDocumentTraversal : nsISupports
|
||||
{
|
||||
nsIDOMNodeIterator createNodeIterator(in nsIDOMNode root,
|
||||
in unsigned long whatToShow,
|
||||
in nsIDOMNodeFilter filter,
|
||||
in boolean entityReferenceExpansion)
|
||||
raises(DOMException);
|
||||
nsIDOMTreeWalker createTreeWalker(in nsIDOMNode root,
|
||||
in unsigned long whatToShow,
|
||||
in nsIDOMNodeFilter filter,
|
||||
in boolean entityReferenceExpansion)
|
||||
raises(DOMException);
|
||||
};
|
|
@ -44,7 +44,7 @@ interface nsIDOMNodeFilter;
|
|||
|
||||
|
||||
[scriptable, uuid(5af83f50-c8d5-4824-be29-1aa9d640bacb)]
|
||||
// Introduced in DOM Level 2:
|
||||
// Introduced in DOM Level 2, updated to DOM Level 4:
|
||||
interface nsIDOMNodeIterator : nsISupports
|
||||
{
|
||||
readonly attribute nsIDOMNode root;
|
||||
|
|
|
@ -486,7 +486,7 @@ GetTextNode(nsISelection *selection, nsEditor *editor) {
|
|||
// if node is null, return it to indicate there's no text
|
||||
NS_ENSURE_TRUE(node, nsnull);
|
||||
// This should be the root node, walk the tree looking for text nodes
|
||||
nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, nsnull, true);
|
||||
nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, nsnull);
|
||||
while (!editor->IsTextNode(selNode)) {
|
||||
if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) {
|
||||
return nsnull;
|
||||
|
|
Загрузка…
Ссылка в новой задаче