зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 7 changesets (bug 832920, bug 776536, bug 843261) for mochitest-a11y assertions on a CLOSED TREE.
--HG-- rename : content/base/src/NodeIterator.cpp => content/base/src/nsNodeIterator.cpp rename : content/base/src/NodeIterator.h => content/base/src/nsNodeIterator.h rename : content/base/src/TreeWalker.cpp => content/base/src/nsTreeWalker.cpp rename : content/base/src/TreeWalker.h => content/base/src/nsTreeWalker.h
This commit is contained in:
Родитель
a4a0dd7987
Коммит
c952e87e03
|
@ -24,56 +24,39 @@ function test()
|
|||
|
||||
let scriptShown = false;
|
||||
let framesAdded = false;
|
||||
let resumed = false;
|
||||
let testStarted = false;
|
||||
|
||||
gTab = addTab(TAB_URL, function onAddTab() {
|
||||
info("tab added");
|
||||
gDebuggee = gTab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||
|
||||
let target = TargetFactory.forTab(gTab);
|
||||
|
||||
gDevTools.showToolbox(target, "jsdebugger").then(function(toolbox) {
|
||||
info("jsdebugger panel opened");
|
||||
gPane = toolbox.getCurrentPanel();
|
||||
gDebugger = gPane.panelWin;
|
||||
gDebugger.addEventListener("Debugger:AfterScriptsAdded",
|
||||
onAfterScriptsAdded);
|
||||
});
|
||||
});
|
||||
|
||||
function onAfterScriptsAdded()
|
||||
{
|
||||
info("scripts added");
|
||||
gDebugger.removeEventListener("Debugger:AfterScriptsAdded",
|
||||
onAfterScriptsAdded, true);
|
||||
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
|
||||
gTab = aTab;
|
||||
gDebuggee = aDebuggee;
|
||||
gPane = aPane;
|
||||
gDebugger = gPane.panelWin;
|
||||
resumed = true;
|
||||
|
||||
gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
|
||||
|
||||
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded",
|
||||
function onFramesAdded() {
|
||||
info("frames added");
|
||||
framesAdded = true;
|
||||
executeSoon(startTest);
|
||||
});
|
||||
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
|
||||
framesAdded = true;
|
||||
executeSoon(startTest);
|
||||
});
|
||||
|
||||
executeSoon(function() {
|
||||
gDebuggee.firstCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function onScriptShown(aEvent)
|
||||
{
|
||||
scriptShown = aEvent.detail.url.indexOf("-02.js") != -1;
|
||||
info("script shown " + aEvent.detail.url);
|
||||
executeSoon(startTest);
|
||||
}
|
||||
|
||||
function startTest()
|
||||
{
|
||||
if (scriptShown && framesAdded && !testStarted) {
|
||||
if (scriptShown && framesAdded && resumed && !testStarted) {
|
||||
gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
|
||||
testStarted = true;
|
||||
info("test started");
|
||||
Services.tm.currentThread.dispatch({ run: performTest }, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -474,7 +474,6 @@ Toolbox.prototype = {
|
|||
iframe.className = "toolbox-panel-iframe";
|
||||
iframe.id = "toolbox-panel-iframe-" + id;
|
||||
iframe.setAttribute("flex", 1);
|
||||
iframe.setAttribute("forceOwnRefreshDriver", "");
|
||||
|
||||
let vbox = this.doc.getElementById("toolbox-panel-" + id);
|
||||
vbox.appendChild(iframe);
|
||||
|
|
|
@ -28,5 +28,5 @@
|
|||
modifiers="accel"/>
|
||||
</keyset>
|
||||
|
||||
<iframe id="toolbox-iframe" flex="1" forceOwnRefreshDriver=""></iframe>
|
||||
<iframe id="toolbox-iframe" flex="1"></iframe>
|
||||
</window>
|
||||
|
|
|
@ -96,9 +96,7 @@ class GlobalObject;
|
|||
class HTMLBodyElement;
|
||||
class Link;
|
||||
class NodeFilter;
|
||||
class NodeIterator;
|
||||
class ProcessingInstruction;
|
||||
class TreeWalker;
|
||||
class UndoManager;
|
||||
template<typename> class Sequence;
|
||||
|
||||
|
@ -1941,18 +1939,18 @@ public:
|
|||
already_AddRefed<nsIDOMEvent> CreateEvent(const nsAString& aEventType,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<nsRange> CreateRange(mozilla::ErrorResult& rv);
|
||||
already_AddRefed<mozilla::dom::NodeIterator>
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
mozilla::dom::NodeFilter* aFilter,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<mozilla::dom::NodeIterator>
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const mozilla::dom::NodeFilterHolder& aFilter,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<mozilla::dom::TreeWalker>
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
mozilla::dom::NodeFilter* aFilter, mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<mozilla::dom::TreeWalker>
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const mozilla::dom::NodeFilterHolder& aFilter,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
|
|
|
@ -51,9 +51,7 @@ EXPORTS_mozilla/dom = \
|
|||
DOMImplementation.h \
|
||||
EventSource.h \
|
||||
Link.h \
|
||||
NodeIterator.h \
|
||||
Text.h \
|
||||
TreeWalker.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -109,7 +107,7 @@ CPPSRCS = \
|
|||
nsNoDataProtocolContentPolicy.cpp \
|
||||
nsNodeInfo.cpp \
|
||||
nsNodeInfoManager.cpp \
|
||||
NodeIterator.cpp \
|
||||
nsNodeIterator.cpp \
|
||||
nsNodeUtils.cpp \
|
||||
nsObjectLoadingContent.cpp \
|
||||
nsPlainTextSerializer.cpp \
|
||||
|
@ -128,7 +126,7 @@ CPPSRCS = \
|
|||
nsTextNode.cpp \
|
||||
nsTraversal.cpp \
|
||||
nsTreeSanitizer.cpp \
|
||||
TreeWalker.cpp \
|
||||
nsTreeWalker.cpp \
|
||||
nsViewportInfo.cpp \
|
||||
WebSocket.cpp \
|
||||
nsXHTMLContentSerializer.cpp \
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Implementation of DOM Traversal's nsIDOMNodeIterator
|
||||
*/
|
||||
|
||||
#ifndef mozilla_dom_NodeIterator_h
|
||||
#define mozilla_dom_NodeIterator_h
|
||||
|
||||
#include "nsIDOMNodeIterator.h"
|
||||
#include "nsTraversal.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDOMNode;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class NodeIterator MOZ_FINAL : public nsIDOMNodeIterator,
|
||||
public nsTraversal,
|
||||
public nsStubMutationObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIDOMNODEITERATOR
|
||||
|
||||
NodeIterator(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const NodeFilterHolder &aFilter);
|
||||
virtual ~NodeIterator();
|
||||
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(NodeIterator, nsIDOMNodeIterator)
|
||||
|
||||
// WebIDL API
|
||||
nsINode* Root() const
|
||||
{
|
||||
return mRoot;
|
||||
}
|
||||
nsINode* GetReferenceNode() const
|
||||
{
|
||||
return mPointer.mNode;
|
||||
}
|
||||
bool PointerBeforeReferenceNode() const
|
||||
{
|
||||
return mPointer.mBeforeNode;
|
||||
}
|
||||
uint32_t WhatToShow() const
|
||||
{
|
||||
return mWhatToShow;
|
||||
}
|
||||
already_AddRefed<NodeFilter> GetFilter()
|
||||
{
|
||||
return mFilter.ToWebIDLCallback();
|
||||
}
|
||||
already_AddRefed<nsINode> NextNode(ErrorResult& aResult)
|
||||
{
|
||||
return NextOrPrevNode(&NodePointer::MoveToNext, aResult);
|
||||
}
|
||||
already_AddRefed<nsINode> PreviousNode(ErrorResult& aResult)
|
||||
{
|
||||
return NextOrPrevNode(&NodePointer::MoveToPrevious, aResult);
|
||||
}
|
||||
// The XPCOM Detach() is fine for our purposes
|
||||
|
||||
JSObject* WrapObject(JSContext *cx, JSObject *scope);
|
||||
|
||||
private:
|
||||
struct NodePointer {
|
||||
NodePointer() : mNode(nullptr) {}
|
||||
NodePointer(nsINode *aNode, bool aBeforeNode);
|
||||
|
||||
typedef bool (NodePointer::*MoveToMethodType)(nsINode*);
|
||||
bool MoveToNext(nsINode *aRoot);
|
||||
bool MoveToPrevious(nsINode *aRoot);
|
||||
|
||||
bool MoveForward(nsINode *aRoot, nsINode *aNode);
|
||||
void MoveBackward(nsINode *aParent, nsINode *aNode);
|
||||
|
||||
void AdjustAfterRemoval(nsINode *aRoot, nsINode *aContainer, nsIContent *aChild, nsIContent *aPreviousSibling);
|
||||
|
||||
void Clear() { mNode = nullptr; }
|
||||
|
||||
nsINode *mNode;
|
||||
bool mBeforeNode;
|
||||
};
|
||||
|
||||
// Implementation for some of our XPCOM getters
|
||||
typedef already_AddRefed<nsINode> (NodeIterator::*NodeGetter)(ErrorResult&);
|
||||
inline nsresult ImplNodeGetter(NodeGetter aGetter, nsIDOMNode** aRetval)
|
||||
{
|
||||
mozilla::ErrorResult rv;
|
||||
nsCOMPtr<nsINode> node = (this->*aGetter)(rv);
|
||||
if (rv.Failed()) {
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
*aRetval = node ? node.forget().get()->AsDOMNode() : nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Have to return a strong ref, because the act of testing the node can
|
||||
// remove it from the DOM so we're holding the only ref to it.
|
||||
already_AddRefed<nsINode>
|
||||
NextOrPrevNode(NodePointer::MoveToMethodType aMove, ErrorResult& aResult);
|
||||
|
||||
bool mDetached;
|
||||
NodePointer mPointer;
|
||||
NodePointer mWorkingPointer;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_NodeIterator_h
|
|
@ -1,110 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim: set ts=4 et sw=4 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Implementation of DOM Traversal's nsIDOMTreeWalker
|
||||
*/
|
||||
|
||||
#ifndef mozilla_dom_TreeWalker_h
|
||||
#define mozilla_dom_TreeWalker_h
|
||||
|
||||
#include "nsIDOMTreeWalker.h"
|
||||
#include "nsTraversal.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDOMNode;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class TreeWalker MOZ_FINAL : public nsIDOMTreeWalker, public nsTraversal
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIDOMTREEWALKER
|
||||
|
||||
TreeWalker(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const NodeFilterHolder &aFilter);
|
||||
virtual ~TreeWalker();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(TreeWalker)
|
||||
|
||||
// WebIDL API
|
||||
nsINode* Root() const
|
||||
{
|
||||
return mRoot;
|
||||
}
|
||||
uint32_t WhatToShow() const
|
||||
{
|
||||
return mWhatToShow;
|
||||
}
|
||||
already_AddRefed<NodeFilter> GetFilter()
|
||||
{
|
||||
return mFilter.ToWebIDLCallback();
|
||||
}
|
||||
nsINode* CurrentNode() const
|
||||
{
|
||||
return mCurrentNode;
|
||||
}
|
||||
void SetCurrentNode(nsINode& aNode, ErrorResult& aResult);
|
||||
// All our traversal methods return strong refs because filtering can
|
||||
// remove nodes from the tree.
|
||||
already_AddRefed<nsINode> ParentNode(ErrorResult& aResult);
|
||||
already_AddRefed<nsINode> FirstChild(ErrorResult& aResult);
|
||||
already_AddRefed<nsINode> LastChild(ErrorResult& aResult);
|
||||
already_AddRefed<nsINode> PreviousSibling(ErrorResult& aResult);
|
||||
already_AddRefed<nsINode> NextSibling(ErrorResult& aResult);
|
||||
already_AddRefed<nsINode> PreviousNode(ErrorResult& aResult);
|
||||
already_AddRefed<nsINode> NextNode(ErrorResult& aResult);
|
||||
|
||||
JSObject* WrapObject(JSContext *cx, JSObject *scope);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsINode> mCurrentNode;
|
||||
|
||||
/*
|
||||
* Implements FirstChild and LastChild which only vary in which direction
|
||||
* they search.
|
||||
* @param aReversed Controls whether we search forwards or backwards
|
||||
* @param aResult Whether we threw or not.
|
||||
* @returns The desired node. Null if no child is found
|
||||
*/
|
||||
already_AddRefed<nsINode> FirstChildInternal(bool aReversed,
|
||||
ErrorResult& aResult);
|
||||
|
||||
/*
|
||||
* Implements NextSibling and PreviousSibling which only vary in which
|
||||
* direction they search.
|
||||
* @param aReversed Controls whether we search forwards or backwards
|
||||
* @param aResult Whether we threw or not.
|
||||
* @returns The desired node. Null if no child is found
|
||||
*/
|
||||
already_AddRefed<nsINode> NextSiblingInternal(bool aReversed,
|
||||
ErrorResult& aResult);
|
||||
|
||||
// Implementation for our various XPCOM getters
|
||||
typedef already_AddRefed<nsINode> (TreeWalker::*NodeGetter)(ErrorResult&);
|
||||
inline nsresult ImplNodeGetter(NodeGetter aGetter, nsIDOMNode** aRetval)
|
||||
{
|
||||
mozilla::ErrorResult rv;
|
||||
nsCOMPtr<nsINode> node = (this->*aGetter)(rv);
|
||||
if (rv.Failed()) {
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
*aRetval = node ? node.forget().get()->AsDOMNode() : nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_TreeWalker_h
|
||||
|
|
@ -56,9 +56,9 @@
|
|||
#include "nsRange.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMComment.h"
|
||||
#include "mozilla/dom/DocumentType.h"
|
||||
#include "mozilla/dom/NodeIterator.h"
|
||||
#include "mozilla/dom/TreeWalker.h"
|
||||
#include "DocumentType.h"
|
||||
#include "nsNodeIterator.h"
|
||||
#include "nsTreeWalker.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
|
@ -4746,7 +4746,7 @@ nsDocument::CreateProcessingInstruction(const nsAString& aTarget,
|
|||
already_AddRefed<ProcessingInstruction>
|
||||
nsIDocument::CreateProcessingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData,
|
||||
ErrorResult& rv) const
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
nsresult res = nsContentUtils::CheckQName(aTarget, false);
|
||||
if (NS_FAILED(res)) {
|
||||
|
@ -4823,7 +4823,7 @@ nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI,
|
|||
already_AddRefed<nsIDOMAttr>
|
||||
nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
ErrorResult& rv)
|
||||
mozilla::ErrorResult& rv)
|
||||
{
|
||||
WarnOnceAbout(eCreateAttributeNS);
|
||||
|
||||
|
@ -5361,19 +5361,23 @@ nsDocument::CreateNodeIterator(nsIDOMNode *aRoot,
|
|||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
already_AddRefed<NodeIterator>
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
NodeFilter* aFilter,
|
||||
ErrorResult& rv) const
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
NodeFilterHolder holder(aFilter);
|
||||
return CreateNodeIterator(aRoot, aWhatToShow, holder, rv);
|
||||
// We don't really know how to handle WebIDL callbacks yet, in
|
||||
// nsTraversal, so just go ahead and convert to an XPCOM callback.
|
||||
nsCOMPtr<nsIDOMNodeFilter> filter = holder.ToXPCOMCallback();
|
||||
NodeFilterHolder holder2(filter);
|
||||
return CreateNodeIterator(aRoot, aWhatToShow, holder2, rv);
|
||||
}
|
||||
|
||||
already_AddRefed<NodeIterator>
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const NodeFilterHolder& aFilter,
|
||||
ErrorResult& rv) const
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
nsINode* root = &aRoot;
|
||||
nsresult res = nsContentUtils::CheckSameOrigin(this, root);
|
||||
|
@ -5382,8 +5386,8 @@ nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<NodeIterator> iterator = new NodeIterator(root, aWhatToShow,
|
||||
aFilter);
|
||||
nsRefPtr<nsNodeIterator> iterator = new nsNodeIterator(root, aWhatToShow,
|
||||
aFilter);
|
||||
return iterator.forget();
|
||||
}
|
||||
|
||||
|
@ -5410,19 +5414,23 @@ nsDocument::CreateTreeWalker(nsIDOMNode *aRoot,
|
|||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
already_AddRefed<TreeWalker>
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
nsIDocument::CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
NodeFilter* aFilter,
|
||||
ErrorResult& rv) const
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
NodeFilterHolder holder(aFilter);
|
||||
return CreateTreeWalker(aRoot, aWhatToShow, holder, rv);
|
||||
// We don't really know how to handle WebIDL callbacks yet, in
|
||||
// nsTraversal, so just go ahead and convert to an XPCOM callback.
|
||||
nsCOMPtr<nsIDOMNodeFilter> filter = holder.ToXPCOMCallback();
|
||||
NodeFilterHolder holder2(filter);
|
||||
return CreateTreeWalker(aRoot, aWhatToShow, holder2, rv);
|
||||
}
|
||||
|
||||
already_AddRefed<TreeWalker>
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
nsIDocument::CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const NodeFilterHolder& aFilter,
|
||||
ErrorResult& rv) const
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
nsINode* root = &aRoot;
|
||||
nsresult res = nsContentUtils::CheckSameOrigin(this, root);
|
||||
|
@ -5431,7 +5439,7 @@ nsIDocument::CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<TreeWalker> walker = new TreeWalker(root, aWhatToShow, aFilter);
|
||||
nsRefPtr<nsTreeWalker> walker = new nsTreeWalker(root, aWhatToShow, aFilter);
|
||||
return walker.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -372,7 +372,6 @@ GK_ATOM(fontpicker, "fontpicker")
|
|||
GK_ATOM(footer, "footer")
|
||||
GK_ATOM(_for, "for")
|
||||
GK_ATOM(forEach, "for-each")
|
||||
GK_ATOM(forceOwnRefreshDriver, "forceOwnRefreshDriver")
|
||||
GK_ATOM(form, "form")
|
||||
GK_ATOM(formaction, "formaction")
|
||||
GK_ATOM(format, "format")
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
* Implementation of DOM Traversal's nsIDOMNodeIterator
|
||||
*/
|
||||
|
||||
#include "mozilla/dom/NodeIterator.h"
|
||||
#include "nsNodeIterator.h"
|
||||
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
#include "nsError.h"
|
||||
|
||||
#include "nsIContent.h"
|
||||
|
@ -18,23 +19,21 @@
|
|||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/dom/NodeIteratorBinding.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
|
||||
DOMCI_DATA(NodeIterator, mozilla::dom::NodeIterator)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/*
|
||||
* NodePointer implementation
|
||||
*/
|
||||
NodeIterator::NodePointer::NodePointer(nsINode *aNode, bool aBeforeNode) :
|
||||
nsNodeIterator::NodePointer::NodePointer(nsINode *aNode,
|
||||
bool aBeforeNode) :
|
||||
mNode(aNode),
|
||||
mBeforeNode(aBeforeNode)
|
||||
{
|
||||
}
|
||||
|
||||
bool NodeIterator::NodePointer::MoveToNext(nsINode *aRoot)
|
||||
bool nsNodeIterator::NodePointer::MoveToNext(nsINode *aRoot)
|
||||
{
|
||||
if (!mNode)
|
||||
return false;
|
||||
|
@ -53,7 +52,7 @@ bool NodeIterator::NodePointer::MoveToNext(nsINode *aRoot)
|
|||
return MoveForward(aRoot, mNode);
|
||||
}
|
||||
|
||||
bool NodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot)
|
||||
bool nsNodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot)
|
||||
{
|
||||
if (!mNode)
|
||||
return false;
|
||||
|
@ -71,10 +70,10 @@ bool NodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot)
|
|||
return true;
|
||||
}
|
||||
|
||||
void NodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot,
|
||||
nsINode *aContainer,
|
||||
nsIContent *aChild,
|
||||
nsIContent *aPreviousSibling)
|
||||
void nsNodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot,
|
||||
nsINode *aContainer,
|
||||
nsIContent *aChild,
|
||||
nsIContent *aPreviousSibling)
|
||||
{
|
||||
// If mNode is null or the root there is nothing to do.
|
||||
if (!mNode || mNode == aRoot)
|
||||
|
@ -106,7 +105,7 @@ void NodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot,
|
|||
MoveBackward(aContainer, aPreviousSibling);
|
||||
}
|
||||
|
||||
bool NodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode)
|
||||
bool nsNodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode)
|
||||
{
|
||||
while (1) {
|
||||
if (aNode == aRoot)
|
||||
|
@ -123,7 +122,7 @@ bool NodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode)
|
|||
return false;
|
||||
}
|
||||
|
||||
void NodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
|
||||
void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
|
||||
{
|
||||
if (aNode) {
|
||||
do {
|
||||
|
@ -139,9 +138,9 @@ void NodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
|
|||
* Factories, constructors and destructors
|
||||
*/
|
||||
|
||||
NodeIterator::NodeIterator(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const NodeFilterHolder &aFilter) :
|
||||
nsNodeIterator::nsNodeIterator(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const NodeFilterHolder &aFilter) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter),
|
||||
mDetached(false),
|
||||
mPointer(mRoot, true)
|
||||
|
@ -149,7 +148,7 @@ NodeIterator::NodeIterator(nsINode *aRoot,
|
|||
aRoot->AddMutationObserver(this);
|
||||
}
|
||||
|
||||
NodeIterator::~NodeIterator()
|
||||
nsNodeIterator::~nsNodeIterator()
|
||||
{
|
||||
/* destructor code */
|
||||
if (!mDetached && mRoot)
|
||||
|
@ -160,44 +159,50 @@ NodeIterator::~NodeIterator()
|
|||
* nsISupports and cycle collection stuff
|
||||
*/
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(NodeIterator)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsNodeIterator)
|
||||
if (!tmp->mDetached && tmp->mRoot)
|
||||
tmp->mRoot->RemoveMutationObserver(tmp);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFilter)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(NodeIterator)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNodeIterator)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFilter)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
// QueryInterface implementation for NodeIterator
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(NodeIterator)
|
||||
DOMCI_DATA(NodeIterator, nsNodeIterator)
|
||||
|
||||
// QueryInterface implementation for nsNodeIterator
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNodeIterator)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeIterator)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeIterator)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NodeIterator)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(NodeIterator)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(NodeIterator)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeIterator)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeIterator)
|
||||
|
||||
/* readonly attribute nsIDOMNode root; */
|
||||
NS_IMETHODIMP NodeIterator::GetRoot(nsIDOMNode * *aRoot)
|
||||
NS_IMETHODIMP nsNodeIterator::GetRoot(nsIDOMNode * *aRoot)
|
||||
{
|
||||
NS_ADDREF(*aRoot = Root()->AsDOMNode());
|
||||
if (mRoot)
|
||||
return CallQueryInterface(mRoot, aRoot);
|
||||
|
||||
*aRoot = nullptr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long whatToShow; */
|
||||
NS_IMETHODIMP NodeIterator::GetWhatToShow(uint32_t *aWhatToShow)
|
||||
NS_IMETHODIMP nsNodeIterator::GetWhatToShow(uint32_t *aWhatToShow)
|
||||
{
|
||||
*aWhatToShow = WhatToShow();
|
||||
*aWhatToShow = mWhatToShow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMNodeFilter filter; */
|
||||
NS_IMETHODIMP NodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
|
||||
NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFilter);
|
||||
|
||||
|
@ -207,25 +212,28 @@ NS_IMETHODIMP NodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
|
|||
}
|
||||
|
||||
/* nsIDOMNode nextNode () raises (DOMException); */
|
||||
NS_IMETHODIMP NodeIterator::NextNode(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsNodeIterator::NextNode(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&NodeIterator::NextNode, _retval);
|
||||
return NextOrPrevNode(&NodePointer::MoveToNext, _retval);
|
||||
}
|
||||
|
||||
/* nsIDOMNode previousNode () raises (DOMException); */
|
||||
NS_IMETHODIMP NodeIterator::PreviousNode(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsNodeIterator::PreviousNode(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&NodeIterator::PreviousNode, _retval);
|
||||
return NextOrPrevNode(&NodePointer::MoveToPrevious, _retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
NodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove,
|
||||
ErrorResult& aResult)
|
||||
nsresult
|
||||
nsNodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove,
|
||||
nsIDOMNode **_retval)
|
||||
{
|
||||
if (mDetached || mInAcceptNode) {
|
||||
aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
nsresult rv;
|
||||
int16_t filtered;
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
if (mDetached || mInAcceptNode)
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
|
||||
mWorkingPointer = mPointer;
|
||||
|
||||
|
@ -237,27 +245,23 @@ NodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove,
|
|||
|
||||
while ((mWorkingPointer.*aMove)(mRoot)) {
|
||||
nsCOMPtr<nsINode> testNode = mWorkingPointer.mNode;
|
||||
int16_t filtered = TestNode(testNode, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(testNode, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mDetached) {
|
||||
aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
if (mDetached)
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
mPointer = mWorkingPointer;
|
||||
return testNode.forget();
|
||||
return CallQueryInterface(testNode, _retval);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void detach (); */
|
||||
NS_IMETHODIMP NodeIterator::Detach(void)
|
||||
NS_IMETHODIMP nsNodeIterator::Detach(void)
|
||||
{
|
||||
if (!mDetached) {
|
||||
mRoot->RemoveMutationObserver(this);
|
||||
|
@ -271,17 +275,19 @@ NS_IMETHODIMP NodeIterator::Detach(void)
|
|||
}
|
||||
|
||||
/* readonly attribute nsIDOMNode referenceNode; */
|
||||
NS_IMETHODIMP NodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode)
|
||||
NS_IMETHODIMP nsNodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(GetReferenceNode()));
|
||||
node.forget(aRefNode);
|
||||
if (mPointer.mNode)
|
||||
return CallQueryInterface(mPointer.mNode, aRefNode);
|
||||
|
||||
*aRefNode = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute boolean pointerBeforeReferenceNode; */
|
||||
NS_IMETHODIMP NodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode)
|
||||
NS_IMETHODIMP nsNodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode)
|
||||
{
|
||||
*aBeforeNode = PointerBeforeReferenceNode();
|
||||
*aBeforeNode = mPointer.mBeforeNode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -289,23 +295,14 @@ NS_IMETHODIMP NodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode)
|
|||
* nsIMutationObserver interface
|
||||
*/
|
||||
|
||||
void NodeIterator::ContentRemoved(nsIDocument *aDocument,
|
||||
nsIContent *aContainer,
|
||||
nsIContent *aChild,
|
||||
int32_t aIndexInContainer,
|
||||
nsIContent *aPreviousSibling)
|
||||
void nsNodeIterator::ContentRemoved(nsIDocument *aDocument,
|
||||
nsIContent *aContainer,
|
||||
nsIContent *aChild,
|
||||
int32_t aIndexInContainer,
|
||||
nsIContent *aPreviousSibling)
|
||||
{
|
||||
nsINode *container = NODE_FROM(aContainer, aDocument);
|
||||
|
||||
mPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling);
|
||||
mWorkingPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
NodeIterator::WrapObject(JSContext *cx, JSObject *scope)
|
||||
{
|
||||
return NodeIteratorBinding::Wrap(cx, scope, this);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Implementation of DOM Traversal's nsIDOMNodeIterator
|
||||
*/
|
||||
|
||||
#ifndef nsNodeIterator_h___
|
||||
#define nsNodeIterator_h___
|
||||
|
||||
#include "nsIDOMNodeIterator.h"
|
||||
#include "nsTraversal.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDOMNode;
|
||||
class nsIDOMNodeFilter;
|
||||
|
||||
class nsNodeIterator : public nsIDOMNodeIterator,
|
||||
public nsTraversal,
|
||||
public nsStubMutationObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIDOMNODEITERATOR
|
||||
|
||||
nsNodeIterator(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const mozilla::dom::NodeFilterHolder &aFilter);
|
||||
virtual ~nsNodeIterator();
|
||||
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsNodeIterator, nsIDOMNodeIterator)
|
||||
|
||||
private:
|
||||
struct NodePointer {
|
||||
NodePointer() : mNode(nullptr) {}
|
||||
NodePointer(nsINode *aNode, bool aBeforeNode);
|
||||
|
||||
typedef bool (NodePointer::*MoveToMethodType)(nsINode*);
|
||||
bool MoveToNext(nsINode *aRoot);
|
||||
bool MoveToPrevious(nsINode *aRoot);
|
||||
|
||||
bool MoveForward(nsINode *aRoot, nsINode *aNode);
|
||||
void MoveBackward(nsINode *aParent, nsINode *aNode);
|
||||
|
||||
void AdjustAfterRemoval(nsINode *aRoot, nsINode *aContainer, nsIContent *aChild, nsIContent *aPreviousSibling);
|
||||
|
||||
void Clear() { mNode = nullptr; }
|
||||
|
||||
nsINode *mNode;
|
||||
bool mBeforeNode;
|
||||
};
|
||||
|
||||
inline nsresult
|
||||
NextOrPrevNode(NodePointer::MoveToMethodType aMove,
|
||||
nsIDOMNode **_retval);
|
||||
|
||||
bool mDetached;
|
||||
NodePointer mPointer;
|
||||
NodePointer mWorkingPointer;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -7,8 +7,10 @@
|
|||
#include "nsTraversal.h"
|
||||
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
#include "nsError.h"
|
||||
#include "nsINode.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
|
||||
#include "nsGkAtoms.h"
|
||||
|
@ -36,42 +38,37 @@ nsTraversal::~nsTraversal()
|
|||
* Tests if and how a node should be filtered. Uses mWhatToShow and
|
||||
* mFilter to test the node.
|
||||
* @param aNode Node to test
|
||||
* @param aResult Whether we succeeded
|
||||
* @returns Filtervalue. See nsIDOMNodeFilter.idl
|
||||
* @param _filtered Returned filtervalue. See nsIDOMNodeFilter.idl
|
||||
* @returns Errorcode
|
||||
*/
|
||||
int16_t
|
||||
nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult)
|
||||
nsresult nsTraversal::TestNode(nsINode* aNode, int16_t* _filtered)
|
||||
{
|
||||
if (mInAcceptNode) {
|
||||
aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return 0;
|
||||
}
|
||||
NS_ENSURE_TRUE(!mInAcceptNode, NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
|
||||
*_filtered = nsIDOMNodeFilter::FILTER_SKIP;
|
||||
|
||||
uint16_t nodeType = aNode->NodeType();
|
||||
|
||||
if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) {
|
||||
return nsIDOMNodeFilter::FILTER_SKIP;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mFilter.GetISupports()) {
|
||||
// No filter, just accept
|
||||
return nsIDOMNodeFilter::FILTER_ACCEPT;
|
||||
*_filtered = nsIDOMNodeFilter::FILTER_ACCEPT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mFilter.HasWebIDLCallback()) {
|
||||
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
||||
mInAcceptNode = true;
|
||||
return mFilter.GetWebIDLCallback()->
|
||||
AcceptNode(*aNode, aResult, CallbackObject::eRethrowExceptions);
|
||||
ErrorResult res;
|
||||
*_filtered = mFilter.GetWebIDLCallback()->AcceptNode(*aNode, res);
|
||||
return res.ErrorCode();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNode);
|
||||
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
||||
mInAcceptNode = true;
|
||||
int16_t filtered;
|
||||
nsresult rv = mFilter.GetXPCOMCallback()->AcceptNode(domNode, &filtered);
|
||||
if (NS_FAILED(rv)) {
|
||||
aResult.Throw(rv);
|
||||
}
|
||||
return filtered;
|
||||
return mFilter.GetXPCOMCallback()->AcceptNode(domNode, _filtered);
|
||||
}
|
||||
|
|
|
@ -14,11 +14,9 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "mozilla/dom/CallbackObject.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDOMNodeFilter;
|
||||
|
||||
class nsTraversal
|
||||
{
|
||||
|
@ -38,10 +36,10 @@ protected:
|
|||
* Tests if and how a node should be filtered. Uses mWhatToShow and
|
||||
* mFilter to test the node.
|
||||
* @param aNode Node to test
|
||||
* @param aResult Whether we succeeded
|
||||
* @returns Filtervalue. See nsIDOMNodeFilter.idl
|
||||
* @param _filtered Returned filtervalue. See nsIDOMNodeFilter.idl
|
||||
* @returns Errorcode
|
||||
*/
|
||||
int16_t TestNode(nsINode* aNode, mozilla::ErrorResult& aResult);
|
||||
nsresult TestNode(nsINode* aNode, int16_t* _filtered);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,33 +8,31 @@
|
|||
* Implementation of DOM Traversal's nsIDOMTreeWalker
|
||||
*/
|
||||
|
||||
#include "mozilla/dom/TreeWalker.h"
|
||||
#include "nsTreeWalker.h"
|
||||
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
#include "nsError.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/TreeWalkerBinding.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
|
||||
DOMCI_DATA(TreeWalker, mozilla::dom::TreeWalker)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/*
|
||||
* Factories, constructors and destructors
|
||||
*/
|
||||
|
||||
TreeWalker::TreeWalker(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const NodeFilterHolder &aFilter) :
|
||||
nsTreeWalker::nsTreeWalker(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const NodeFilterHolder &aFilter) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter),
|
||||
mCurrentNode(aRoot)
|
||||
{
|
||||
}
|
||||
|
||||
TreeWalker::~TreeWalker()
|
||||
nsTreeWalker::~nsTreeWalker()
|
||||
{
|
||||
/* destructor code */
|
||||
}
|
||||
|
@ -43,17 +41,19 @@ TreeWalker::~TreeWalker()
|
|||
* nsISupports and cycle collection stuff
|
||||
*/
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_3(TreeWalker, mFilter, mCurrentNode, mRoot)
|
||||
NS_IMPL_CYCLE_COLLECTION_3(nsTreeWalker, mFilter, mCurrentNode, mRoot)
|
||||
|
||||
// QueryInterface implementation for TreeWalker
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TreeWalker)
|
||||
DOMCI_DATA(TreeWalker, nsTreeWalker)
|
||||
|
||||
// QueryInterface implementation for nsTreeWalker
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTreeWalker)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMTreeWalker)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMTreeWalker)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TreeWalker)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(TreeWalker)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(TreeWalker)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTreeWalker)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTreeWalker)
|
||||
|
||||
|
||||
|
||||
|
@ -62,21 +62,26 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(TreeWalker)
|
|||
*/
|
||||
|
||||
/* readonly attribute nsIDOMNode root; */
|
||||
NS_IMETHODIMP TreeWalker::GetRoot(nsIDOMNode * *aRoot)
|
||||
NS_IMETHODIMP nsTreeWalker::GetRoot(nsIDOMNode * *aRoot)
|
||||
{
|
||||
NS_ADDREF(*aRoot = Root()->AsDOMNode());
|
||||
if (mRoot) {
|
||||
return CallQueryInterface(mRoot, aRoot);
|
||||
}
|
||||
|
||||
*aRoot = nullptr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long whatToShow; */
|
||||
NS_IMETHODIMP TreeWalker::GetWhatToShow(uint32_t *aWhatToShow)
|
||||
NS_IMETHODIMP nsTreeWalker::GetWhatToShow(uint32_t *aWhatToShow)
|
||||
{
|
||||
*aWhatToShow = WhatToShow();
|
||||
*aWhatToShow = mWhatToShow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMNodeFilter filter; */
|
||||
NS_IMETHODIMP TreeWalker::GetFilter(nsIDOMNodeFilter * *aFilter)
|
||||
NS_IMETHODIMP nsTreeWalker::GetFilter(nsIDOMNodeFilter * *aFilter)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFilter);
|
||||
|
||||
|
@ -86,7 +91,7 @@ NS_IMETHODIMP TreeWalker::GetFilter(nsIDOMNodeFilter * *aFilter)
|
|||
}
|
||||
|
||||
/* attribute nsIDOMNode currentNode; */
|
||||
NS_IMETHODIMP TreeWalker::GetCurrentNode(nsIDOMNode * *aCurrentNode)
|
||||
NS_IMETHODIMP nsTreeWalker::GetCurrentNode(nsIDOMNode * *aCurrentNode)
|
||||
{
|
||||
if (mCurrentNode) {
|
||||
return CallQueryInterface(mCurrentNode, aCurrentNode);
|
||||
|
@ -96,7 +101,7 @@ NS_IMETHODIMP TreeWalker::GetCurrentNode(nsIDOMNode * *aCurrentNode)
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP TreeWalker::SetCurrentNode(nsIDOMNode * aCurrentNode)
|
||||
NS_IMETHODIMP nsTreeWalker::SetCurrentNode(nsIDOMNode * aCurrentNode)
|
||||
{
|
||||
NS_ENSURE_TRUE(aCurrentNode, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
NS_ENSURE_TRUE(mRoot, NS_ERROR_UNEXPECTED);
|
||||
|
@ -104,20 +109,11 @@ NS_IMETHODIMP TreeWalker::SetCurrentNode(nsIDOMNode * aCurrentNode)
|
|||
nsCOMPtr<nsINode> node = do_QueryInterface(aCurrentNode);
|
||||
NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
|
||||
|
||||
ErrorResult rv;
|
||||
SetCurrentNode(*node, rv);
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
nsresult rv = nsContentUtils::CheckSameOrigin(mRoot, node);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
void
|
||||
TreeWalker::SetCurrentNode(nsINode& aNode, ErrorResult& aResult)
|
||||
{
|
||||
aResult = nsContentUtils::CheckSameOrigin(mRoot, &aNode);
|
||||
if (aResult.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCurrentNode = &aNode;
|
||||
mCurrentNode.swap(node);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -125,152 +121,113 @@ TreeWalker::SetCurrentNode(nsINode& aNode, ErrorResult& aResult)
|
|||
*/
|
||||
|
||||
/* nsIDOMNode parentNode (); */
|
||||
NS_IMETHODIMP TreeWalker::ParentNode(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsTreeWalker::ParentNode(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::ParentNode, _retval);
|
||||
}
|
||||
*_retval = nullptr;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::ParentNode(ErrorResult& aResult)
|
||||
{
|
||||
nsCOMPtr<nsINode> node = mCurrentNode;
|
||||
|
||||
while (node && node != mRoot) {
|
||||
node = node->GetParentNode();
|
||||
|
||||
if (node) {
|
||||
int16_t filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
int16_t filtered;
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
return CallQueryInterface(node, _retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIDOMNode firstChild (); */
|
||||
NS_IMETHODIMP TreeWalker::FirstChild(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsTreeWalker::FirstChild(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::FirstChild, _retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::FirstChild(ErrorResult& aResult)
|
||||
{
|
||||
return FirstChildInternal(false, aResult);
|
||||
return FirstChildInternal(false, _retval);
|
||||
}
|
||||
|
||||
/* nsIDOMNode lastChild (); */
|
||||
NS_IMETHODIMP TreeWalker::LastChild(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsTreeWalker::LastChild(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::LastChild, _retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::LastChild(ErrorResult& aResult)
|
||||
{
|
||||
return FirstChildInternal(true, aResult);
|
||||
return FirstChildInternal(true, _retval);
|
||||
}
|
||||
|
||||
/* nsIDOMNode previousSibling (); */
|
||||
NS_IMETHODIMP TreeWalker::PreviousSibling(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsTreeWalker::PreviousSibling(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::PreviousSibling, _retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::PreviousSibling(ErrorResult& aResult)
|
||||
{
|
||||
return NextSiblingInternal(true, aResult);
|
||||
return NextSiblingInternal(true, _retval);
|
||||
}
|
||||
|
||||
/* nsIDOMNode nextSibling (); */
|
||||
NS_IMETHODIMP TreeWalker::NextSibling(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsTreeWalker::NextSibling(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::NextSibling, _retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::NextSibling(ErrorResult& aResult)
|
||||
{
|
||||
return NextSiblingInternal(false, aResult);
|
||||
return NextSiblingInternal(false, _retval);
|
||||
}
|
||||
|
||||
/* nsIDOMNode previousNode (); */
|
||||
NS_IMETHODIMP TreeWalker::PreviousNode(nsIDOMNode **_retval)
|
||||
NS_IMETHODIMP nsTreeWalker::PreviousNode(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::PreviousNode, _retval);
|
||||
}
|
||||
nsresult rv;
|
||||
int16_t filtered;
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::PreviousNode(ErrorResult& aResult)
|
||||
{
|
||||
nsCOMPtr<nsINode> node = mCurrentNode;
|
||||
|
||||
while (node != mRoot) {
|
||||
while (nsINode *previousSibling = node->GetPreviousSibling()) {
|
||||
node = previousSibling;
|
||||
|
||||
int16_t filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsINode *lastChild;
|
||||
while (filtered != nsIDOMNodeFilter::FILTER_REJECT &&
|
||||
(lastChild = node->GetLastChild())) {
|
||||
node = lastChild;
|
||||
filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
return CallQueryInterface(node, _retval);
|
||||
}
|
||||
}
|
||||
|
||||
if (node == mRoot) {
|
||||
if (node == mRoot)
|
||||
break;
|
||||
}
|
||||
|
||||
node = node->GetParentNode();
|
||||
if (!node) {
|
||||
if (!node)
|
||||
break;
|
||||
}
|
||||
|
||||
int16_t filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
return CallQueryInterface(node, _retval);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIDOMNode nextNode (); */
|
||||
NS_IMETHODIMP TreeWalker::NextNode(nsIDOMNode **_retval)
|
||||
{
|
||||
return ImplNodeGetter(&TreeWalker::NextNode, _retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::NextNode(ErrorResult& aResult)
|
||||
NS_IMETHODIMP nsTreeWalker::NextNode(nsIDOMNode **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
int16_t filtered = nsIDOMNodeFilter::FILTER_ACCEPT; // pre-init for inner loop
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
nsCOMPtr<nsINode> node = mCurrentNode;
|
||||
|
||||
while (1) {
|
||||
|
@ -280,15 +237,13 @@ TreeWalker::NextNode(ErrorResult& aResult)
|
|||
(firstChild = node->GetFirstChild())) {
|
||||
node = firstChild;
|
||||
|
||||
filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
// Node found
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
return CallQueryInterface(node, _retval);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,49 +266,49 @@ TreeWalker::NextNode(ErrorResult& aResult)
|
|||
node = sibling;
|
||||
|
||||
// Found a sibling. Either ours or ancestor's
|
||||
filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
// Node found
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
return CallQueryInterface(node, _retval);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* TreeWalker helper functions
|
||||
* nsTreeWalker helper functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Implements FirstChild and LastChild which only vary in which direction
|
||||
* they search.
|
||||
* @param aReversed Controls whether we search forwards or backwards
|
||||
* @param aResult Whether we threw or not.
|
||||
* @returns The desired node. Null if no child is found
|
||||
* @param _retval Returned node. Null if no child is found
|
||||
* @returns Errorcode
|
||||
*/
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::FirstChildInternal(bool aReversed, ErrorResult& aResult)
|
||||
nsresult nsTreeWalker::FirstChildInternal(bool aReversed, nsIDOMNode **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
int16_t filtered;
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
nsCOMPtr<nsINode> node = aReversed ? mCurrentNode->GetLastChild()
|
||||
: mCurrentNode->GetFirstChild();
|
||||
|
||||
while (node) {
|
||||
int16_t filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
switch (filtered) {
|
||||
case nsIDOMNodeFilter::FILTER_ACCEPT:
|
||||
// Node found
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
return CallQueryInterface(node, _retval);
|
||||
case nsIDOMNodeFilter::FILTER_SKIP: {
|
||||
nsINode *child = aReversed ? node->GetLastChild()
|
||||
: node->GetFirstChild();
|
||||
|
@ -379,7 +334,7 @@ TreeWalker::FirstChildInternal(bool aReversed, ErrorResult& aResult)
|
|||
nsINode *parent = node->GetParentNode();
|
||||
|
||||
if (!parent || parent == mRoot || parent == mCurrentNode) {
|
||||
return nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
node = parent;
|
||||
|
@ -387,24 +342,27 @@ TreeWalker::FirstChildInternal(bool aReversed, ErrorResult& aResult)
|
|||
} while (node);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implements NextSibling and PreviousSibling which only vary in which
|
||||
* direction they search.
|
||||
* @param aReversed Controls whether we search forwards or backwards
|
||||
* @param aResult Whether we threw or not.
|
||||
* @returns The desired node. Null if no child is found
|
||||
* @param _retval Returned node. Null if no child is found
|
||||
* @returns Errorcode
|
||||
*/
|
||||
already_AddRefed<nsINode>
|
||||
TreeWalker::NextSiblingInternal(bool aReversed, ErrorResult& aResult)
|
||||
nsresult nsTreeWalker::NextSiblingInternal(bool aReversed, nsIDOMNode **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
int16_t filtered;
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
nsCOMPtr<nsINode> node = mCurrentNode;
|
||||
|
||||
if (node == mRoot) {
|
||||
return nullptr;
|
||||
}
|
||||
if (node == mRoot)
|
||||
return NS_OK;
|
||||
|
||||
while (1) {
|
||||
nsINode* sibling = aReversed ? node->GetPreviousSibling()
|
||||
|
@ -413,15 +371,13 @@ TreeWalker::NextSiblingInternal(bool aReversed, ErrorResult& aResult)
|
|||
while (sibling) {
|
||||
node = sibling;
|
||||
|
||||
int16_t filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
// Node found
|
||||
mCurrentNode = node;
|
||||
return node.forget();
|
||||
mCurrentNode.swap(node);
|
||||
return CallQueryInterface(mCurrentNode, _retval);
|
||||
}
|
||||
|
||||
// If rejected or no children, try a sibling
|
||||
|
@ -435,26 +391,13 @@ TreeWalker::NextSiblingInternal(bool aReversed, ErrorResult& aResult)
|
|||
|
||||
node = node->GetParentNode();
|
||||
|
||||
if (!node || node == mRoot) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!node || node == mRoot)
|
||||
return NS_OK;
|
||||
|
||||
// Is parent transparent in filtered view?
|
||||
int16_t filtered = TestNode(node, aResult);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT) {
|
||||
return nullptr;
|
||||
}
|
||||
rv = TestNode(node, &filtered);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (filtered == nsIDOMNodeFilter::FILTER_ACCEPT)
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
JSObject*
|
||||
TreeWalker::WrapObject(JSContext *cx, JSObject *scope)
|
||||
{
|
||||
return TreeWalkerBinding::Wrap(cx, scope, this);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,60 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim: set ts=4 et sw=4 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Implementation of DOM Traversal's nsIDOMTreeWalker
|
||||
*/
|
||||
|
||||
#ifndef nsTreeWalker_h___
|
||||
#define nsTreeWalker_h___
|
||||
|
||||
#include "nsIDOMTreeWalker.h"
|
||||
#include "nsTraversal.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDOMNode;
|
||||
class nsIDOMNodeFilter;
|
||||
|
||||
class nsTreeWalker : public nsIDOMTreeWalker, public nsTraversal
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIDOMTREEWALKER
|
||||
|
||||
nsTreeWalker(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
const mozilla::dom::NodeFilterHolder &aFilter);
|
||||
virtual ~nsTreeWalker();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeWalker)
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsINode> mCurrentNode;
|
||||
|
||||
/*
|
||||
* Implements FirstChild and LastChild which only vary in which direction
|
||||
* they search.
|
||||
* @param aReversed Controls whether we search forwards or backwards
|
||||
* @param _retval Returned node. Null if no child is found
|
||||
* @returns Errorcode
|
||||
*/
|
||||
nsresult FirstChildInternal(bool aReversed, nsIDOMNode **_retval);
|
||||
|
||||
/*
|
||||
* Implements NextSibling and PreviousSibling which only vary in which
|
||||
* direction they search.
|
||||
* @param aReversed Controls whether we search forwards or backwards
|
||||
* @param _retval Returned node. Null if no child is found
|
||||
* @returns Errorcode
|
||||
*/
|
||||
nsresult NextSiblingInternal(bool aReversed, nsIDOMNode **_retval);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -534,9 +534,9 @@ DOMInterfaces = {
|
|||
'attributes' ]
|
||||
},
|
||||
|
||||
'NodeIterator': {
|
||||
'wrapperCache': False,
|
||||
'resultNotAddRefed': [ 'root', 'referenceNode' ],
|
||||
'NodeFilter': {
|
||||
'nativeType': 'nsIDOMNodeFilter',
|
||||
'headerFile': 'nsIDOMNodeFilter.h',
|
||||
},
|
||||
|
||||
'NodeList': {
|
||||
|
@ -848,11 +848,6 @@ DOMInterfaces = {
|
|||
'implicitJSContext': [ 'encode' ],
|
||||
}],
|
||||
|
||||
'TreeWalker': {
|
||||
'wrapperCache': False,
|
||||
'resultNotAddRefed': [ 'root', 'currentNode' ],
|
||||
},
|
||||
|
||||
'URL' : [{
|
||||
'concrete': False,
|
||||
},
|
||||
|
@ -1217,6 +1212,7 @@ addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSou
|
|||
addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True)
|
||||
addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder')
|
||||
addExternalIface('NamedNodeMap')
|
||||
addExternalIface('NodeIterator')
|
||||
addExternalIface('nsIStreamListener', nativeType='nsIStreamListener', notflattened=True)
|
||||
addExternalIface('nsISupports', nativeType='nsISupports')
|
||||
addExternalIface('nsIEditor', nativeType='nsIEditor', notflattened=True)
|
||||
|
@ -1234,6 +1230,7 @@ addExternalIface('SVGAnimatedString')
|
|||
addExternalIface('SVGLength')
|
||||
addExternalIface('SVGNumber')
|
||||
addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
|
||||
addExternalIface('TreeWalker')
|
||||
addExternalIface('Touch', headerFile='nsIDOMTouchEvent.h')
|
||||
addExternalIface('TouchList', headerFile='nsIDOMTouchEvent.h')
|
||||
addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h',
|
||||
|
|
|
@ -5179,16 +5179,24 @@ ${doConversionsToJS}
|
|||
(templateVars, type) = arg
|
||||
assert not type.nullable() # flatMemberTypes never has nullable types
|
||||
val = "mValue.m%(name)s.Value()" % templateVars
|
||||
if type.isObject():
|
||||
# We'll have a NonNull<JSObject> while the wrapping code
|
||||
# wants a JSObject*
|
||||
val = "%s.get()" % val
|
||||
elif type.isSpiderMonkeyInterface():
|
||||
# We have a NonNull<TypedArray> object while the wrapping code
|
||||
# wants a JSObject*. Cheat with .get() so we don't have to
|
||||
# figure out the right reference type to cast to.
|
||||
val = "%s.get()->Obj()" % val
|
||||
wrapCode = wrapForType(
|
||||
if type.isString():
|
||||
# XPConnect string-to-JS conversion wants to mutate the string. So
|
||||
# let's give it a string it can mutate
|
||||
# XXXbz if we try to do a sequence of strings, this will kinda fail.
|
||||
prepend = "nsString mutableStr(%s);\n" % val
|
||||
val = "mutableStr"
|
||||
else:
|
||||
prepend = ""
|
||||
if type.isObject():
|
||||
# We'll have a NonNull<JSObject> while the wrapping code
|
||||
# wants a JSObject*
|
||||
val = "%s.get()" % val
|
||||
elif type.isSpiderMonkeyInterface():
|
||||
# We have a NonNull<TypedArray> object while the wrapping code
|
||||
# wants a JSObject*. Cheat with .get() so we don't have to
|
||||
# figure out the right reference type to cast to.
|
||||
val = "%s.get()->Obj()" % val
|
||||
wrapCode = prepend + wrapForType(
|
||||
type, self.descriptorProvider,
|
||||
{
|
||||
"jsvalRef": "*vp",
|
||||
|
|
|
@ -18,8 +18,6 @@ callback interface TestCallbackInterface {
|
|||
attribute DOMString bar;
|
||||
void doSomething();
|
||||
long doSomethingElse(DOMString arg, TestInterface otherArg);
|
||||
void doSequenceLongArg(sequence<long> arg);
|
||||
void doSequenceStringArg(sequence<DOMString> arg);
|
||||
};
|
||||
|
||||
callback interface TestSingleOperationCallbackInterface {
|
||||
|
|
|
@ -131,6 +131,23 @@
|
|||
"Range interface: calling isPointInRange(Node,unsigned long) on detachedRange with too few arguments must throw TypeError": true,
|
||||
"Range interface: calling comparePoint(Node,unsigned long) on detachedRange with too few arguments must throw TypeError": true,
|
||||
"Range interface: calling intersectsNode(Node) on detachedRange with too few arguments must throw TypeError": true,
|
||||
"NodeIterator interface: existence and properties of interface object": true,
|
||||
"NodeIterator interface: existence and properties of interface prototype object": true,
|
||||
"NodeIterator interface: existence and properties of interface prototype object's \"constructor\" property": true,
|
||||
"NodeIterator interface: attribute root": true,
|
||||
"NodeIterator interface: attribute referenceNode": true,
|
||||
"NodeIterator interface: attribute pointerBeforeReferenceNode": true,
|
||||
"NodeIterator interface: attribute whatToShow": true,
|
||||
"NodeIterator interface: attribute filter": true,
|
||||
"Stringification of document.createNodeIterator(document.body, NodeFilter.SHOW_ALL, null)": "debug",
|
||||
"TreeWalker interface: existence and properties of interface object": true,
|
||||
"TreeWalker interface: existence and properties of interface prototype object": true,
|
||||
"TreeWalker interface: existence and properties of interface prototype object's \"constructor\" property": true,
|
||||
"TreeWalker interface: attribute root": true,
|
||||
"TreeWalker interface: attribute whatToShow": true,
|
||||
"TreeWalker interface: attribute filter": true,
|
||||
"TreeWalker interface: attribute currentNode": true,
|
||||
"Stringification of document.createTreeWalker(document.body, NodeFilter.SHOW_ALL, null)": "debug",
|
||||
"NodeFilter interface: existence and properties of interface object": true,
|
||||
"NodeFilter interface: existence and properties of interface prototype object": true,
|
||||
"NodeFilter interface: existence and properties of interface prototype object's \"constructor\" property": true,
|
||||
|
|
|
@ -17,10 +17,12 @@
|
|||
|
||||
interface Attr;
|
||||
interface Comment;
|
||||
interface NodeIterator;
|
||||
interface Range;
|
||||
interface StyleSheetList;
|
||||
interface Touch;
|
||||
interface TouchList;
|
||||
interface TreeWalker;
|
||||
interface WindowProxy;
|
||||
interface nsISupports;
|
||||
|
||||
|
|
|
@ -11,21 +11,14 @@
|
|||
*/
|
||||
|
||||
interface NodeIterator {
|
||||
[Constant]
|
||||
readonly attribute Node root;
|
||||
[Pure]
|
||||
readonly attribute Node? referenceNode;
|
||||
[Pure]
|
||||
readonly attribute boolean pointerBeforeReferenceNode;
|
||||
[Constant]
|
||||
readonly attribute unsigned long whatToShow;
|
||||
[Constant]
|
||||
readonly attribute NodeFilter? filter;
|
||||
|
||||
[Throws]
|
||||
Node? nextNode();
|
||||
[Throws]
|
||||
Node? previousNode();
|
||||
|
||||
void detach();
|
||||
};
|
||||
;}
|
||||
|
|
|
@ -11,27 +11,16 @@
|
|||
*/
|
||||
|
||||
interface TreeWalker {
|
||||
[Constant]
|
||||
readonly attribute Node root;
|
||||
[Constant]
|
||||
readonly attribute unsigned long whatToShow;
|
||||
[Constant]
|
||||
readonly attribute NodeFilter? filter;
|
||||
[Pure, SetterThrows]
|
||||
attribute Node currentNode;
|
||||
|
||||
[Throws]
|
||||
Node? parentNode();
|
||||
[Throws]
|
||||
Node? firstChild();
|
||||
[Throws]
|
||||
Node? lastChild();
|
||||
[Throws]
|
||||
Node? previousSibling();
|
||||
[Throws]
|
||||
Node? nextSibling();
|
||||
[Throws]
|
||||
Node? previousNode();
|
||||
[Throws]
|
||||
Node? nextNode();
|
||||
};
|
||||
|
|
|
@ -121,7 +121,6 @@ webidl_files = \
|
|||
MutationObserver.webidl \
|
||||
Node.webidl \
|
||||
NodeFilter.webidl \
|
||||
NodeIterator.webidl \
|
||||
NodeList.webidl \
|
||||
PaintRequest.webidl \
|
||||
PaintRequestList.webidl \
|
||||
|
@ -212,7 +211,6 @@ webidl_files = \
|
|||
Text.webidl \
|
||||
TextDecoder.webidl \
|
||||
TextEncoder.webidl \
|
||||
TreeWalker.webidl \
|
||||
URL.webidl \
|
||||
ValidityState.webidl \
|
||||
WebSocket.webidl \
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "nsISelectionPrivate.h"
|
||||
#include "nsISupportsBase.h"
|
||||
#include "nsLiteralString.h"
|
||||
#include "mozilla/dom/NodeIterator.h"
|
||||
#include "nsNodeIterator.h"
|
||||
#include "nsTextEditRules.h"
|
||||
#include "nsTextEditUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
|
@ -450,7 +450,7 @@ GetTextNode(nsISelection *selection, nsEditor *editor) {
|
|||
NS_ENSURE_TRUE(node, nullptr);
|
||||
// This should be the root node, walk the tree looking for text nodes
|
||||
mozilla::dom::NodeFilterHolder filter;
|
||||
mozilla::dom::NodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter);
|
||||
nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter);
|
||||
while (!editor->IsTextNode(selNode)) {
|
||||
if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) {
|
||||
return nullptr;
|
||||
|
|
|
@ -291,20 +291,6 @@ inline bool StringToJsval(JSContext *cx, nsAString &str, JS::Value *rval)
|
|||
return NonVoidStringToJsval(cx, str, rval);
|
||||
}
|
||||
|
||||
inline bool
|
||||
NonVoidStringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
|
||||
{
|
||||
nsString mutableCopy(str);
|
||||
return NonVoidStringToJsval(cx, mutableCopy, rval);
|
||||
}
|
||||
|
||||
inline bool
|
||||
StringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
|
||||
{
|
||||
nsString mutableCopy(str);
|
||||
return StringToJsval(cx, mutableCopy, rval);
|
||||
}
|
||||
|
||||
/**
|
||||
* As above, but for mozilla::dom::DOMString.
|
||||
*/
|
||||
|
|
|
@ -37,6 +37,7 @@ MOCHITEST_FILES = chrome_wrappers_helper.html \
|
|||
test_bug478438.html \
|
||||
test_bug500691.html \
|
||||
bug500931_helper.html \
|
||||
test_bug502959.html \
|
||||
test_bug503926.html \
|
||||
test_bug504877.html \
|
||||
bug504877_helper.html \
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=502959
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 502959</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=502959">Mozilla Bug 502959</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 502959 **/
|
||||
// Whatever you do don't use the word "wrapped" in this function.
|
||||
function foo() {
|
||||
ok(true, "Able to call the function");
|
||||
}
|
||||
|
||||
var iter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, foo);
|
||||
var doublewrapped = iter.filter;
|
||||
|
||||
ok(doublewrapped.toString().indexOf("wrapped") > 0, "got a double-wrapped object back");
|
||||
|
||||
(function () {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Components.utils.forceGC();
|
||||
})();
|
||||
|
||||
doublewrapped.acceptNode(document);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -948,14 +948,7 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext)
|
|||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
ourItem->GetSameTypeParent(getter_AddRefs(parentItem));
|
||||
if (parentItem) {
|
||||
Element* containingElement =
|
||||
parent->FindContentForSubDocument(mDocument);
|
||||
if (!containingElement->IsXUL() ||
|
||||
!containingElement->
|
||||
HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::forceOwnRefreshDriver)) {
|
||||
mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
|
||||
}
|
||||
mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче