mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 838686 part 2. Use NodeFilterHolder in treewalker and nodeiterator and start using WebIDL codegen for NodeFilter. r=peterv
This commit is contained in:
parent
af3b8795b8
commit
247b3cc18a
@ -95,9 +95,13 @@ class Element;
|
||||
class GlobalObject;
|
||||
class HTMLBodyElement;
|
||||
class Link;
|
||||
class NodeFilter;
|
||||
class ProcessingInstruction;
|
||||
class UndoManager;
|
||||
template<typename> class Sequence;
|
||||
|
||||
template<typename, typename> class CallbackObjectHolder;
|
||||
typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
@ -1919,10 +1923,19 @@ public:
|
||||
already_AddRefed<nsRange> CreateRange(mozilla::ErrorResult& rv);
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter* aFilter, mozilla::ErrorResult& rv) const;
|
||||
mozilla::dom::NodeFilter* aFilter,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const mozilla::dom::NodeFilterHolder& aFilter,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter* aFilter, mozilla::ErrorResult& rv) const;
|
||||
mozilla::dom::NodeFilter* aFilter, mozilla::ErrorResult& rv) const;
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const mozilla::dom::NodeFilterHolder& aFilter,
|
||||
mozilla::ErrorResult& rv) const;
|
||||
|
||||
// Deprecated WebIDL bits
|
||||
already_AddRefed<mozilla::dom::CDATASection>
|
||||
|
@ -184,6 +184,7 @@
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "mozilla/dom/HTMLBodyElement.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
#include "mozilla/dom/UndoManager.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsDOMCaretPosition.h"
|
||||
@ -5354,14 +5355,28 @@ nsDocument::CreateNodeIterator(nsIDOMNode *aRoot,
|
||||
NS_ENSURE_TRUE(root, NS_ERROR_UNEXPECTED);
|
||||
|
||||
ErrorResult rv;
|
||||
*_retval = nsIDocument::CreateNodeIterator(*root, aWhatToShow, aFilter,
|
||||
NodeFilterHolder holder(aFilter);
|
||||
*_retval = nsIDocument::CreateNodeIterator(*root, aWhatToShow, holder,
|
||||
rv).get();
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMNodeIterator>
|
||||
nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter* aFilter,
|
||||
NodeFilter* aFilter,
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
NodeFilterHolder holder(aFilter);
|
||||
// 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<nsIDOMNodeIterator>
|
||||
nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const NodeFilterHolder& aFilter,
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
nsINode* root = &aRoot;
|
||||
@ -5393,14 +5408,28 @@ nsDocument::CreateTreeWalker(nsIDOMNode *aRoot,
|
||||
NS_ENSURE_TRUE(root, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
|
||||
ErrorResult rv;
|
||||
*_retval = nsIDocument::CreateTreeWalker(*root, aWhatToShow, aFilter,
|
||||
NodeFilterHolder holder(aFilter);
|
||||
*_retval = nsIDocument::CreateTreeWalker(*root, aWhatToShow, holder,
|
||||
rv).get();
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMTreeWalker>
|
||||
nsIDocument::CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter* aFilter,
|
||||
NodeFilter* aFilter,
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
NodeFilterHolder holder(aFilter);
|
||||
// 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<nsIDOMTreeWalker>
|
||||
nsIDocument::CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
|
||||
const NodeFilterHolder& aFilter,
|
||||
mozilla::ErrorResult& rv) const
|
||||
{
|
||||
nsINode* root = &aRoot;
|
||||
|
@ -19,6 +19,9 @@
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/*
|
||||
* NodePointer implementation
|
||||
@ -137,7 +140,7 @@ void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
|
||||
|
||||
nsNodeIterator::nsNodeIterator(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter) :
|
||||
const NodeFilterHolder &aFilter) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter),
|
||||
mDetached(false),
|
||||
mPointer(mRoot, true)
|
||||
@ -203,7 +206,7 @@ NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFilter);
|
||||
|
||||
NS_IF_ADDREF(*aFilter = mFilter);
|
||||
*aFilter = mFilter.ToXPCOMCallback().get();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
nsNodeIterator(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter);
|
||||
const mozilla::dom::NodeFilterHolder &aFilter);
|
||||
virtual ~nsNodeIterator();
|
||||
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
||||
|
@ -10,12 +10,17 @@
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
#include "nsError.h"
|
||||
#include "nsINode.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
|
||||
#include "nsGkAtoms.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
nsTraversal::nsTraversal(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter) :
|
||||
const NodeFilterHolder &aFilter) :
|
||||
mRoot(aRoot),
|
||||
mWhatToShow(aWhatToShow),
|
||||
mFilter(aFilter),
|
||||
@ -40,8 +45,6 @@ nsresult nsTraversal::TestNode(nsINode* aNode, int16_t* _filtered)
|
||||
{
|
||||
NS_ENSURE_TRUE(!mInAcceptNode, NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
|
||||
nsresult rv;
|
||||
|
||||
*_filtered = nsIDOMNodeFilter::FILTER_SKIP;
|
||||
|
||||
uint16_t nodeType = aNode->NodeType();
|
||||
@ -50,14 +53,22 @@ nsresult nsTraversal::TestNode(nsINode* aNode, int16_t* _filtered)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mFilter) {
|
||||
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNode);
|
||||
mInAcceptNode = true;
|
||||
rv = mFilter->AcceptNode(domNode, _filtered);
|
||||
mInAcceptNode = false;
|
||||
return rv;
|
||||
if (!mFilter.GetISupports()) {
|
||||
// No filter, just accept
|
||||
*_filtered = nsIDOMNodeFilter::FILTER_ACCEPT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_filtered = nsIDOMNodeFilter::FILTER_ACCEPT;
|
||||
return NS_OK;
|
||||
if (mFilter.HasWebIDLCallback()) {
|
||||
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
||||
mInAcceptNode = true;
|
||||
ErrorResult res;
|
||||
*_filtered = mFilter.GetWebIDLCallback()->AcceptNode(*aNode, res);
|
||||
return res.ErrorCode();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNode);
|
||||
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
||||
mInAcceptNode = true;
|
||||
return mFilter.GetXPCOMCallback()->AcceptNode(domNode, _filtered);
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
#define nsTraversal_h___
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "mozilla/dom/CallbackObject.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDOMNodeFilter;
|
||||
@ -21,13 +23,13 @@ class nsTraversal
|
||||
public:
|
||||
nsTraversal(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter);
|
||||
const mozilla::dom::NodeFilterHolder &aFilter);
|
||||
virtual ~nsTraversal();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsINode> mRoot;
|
||||
uint32_t mWhatToShow;
|
||||
nsCOMPtr<nsIDOMNodeFilter> mFilter;
|
||||
mozilla::dom::NodeFilterHolder mFilter;
|
||||
bool mInAcceptNode;
|
||||
|
||||
/*
|
||||
|
@ -16,6 +16,9 @@
|
||||
#include "nsINode.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/NodeFilterBinding.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/*
|
||||
* Factories, constructors and destructors
|
||||
@ -23,7 +26,7 @@
|
||||
|
||||
nsTreeWalker::nsTreeWalker(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter) :
|
||||
const NodeFilterHolder &aFilter) :
|
||||
nsTraversal(aRoot, aWhatToShow, aFilter),
|
||||
mCurrentNode(aRoot)
|
||||
{
|
||||
@ -82,7 +85,7 @@ NS_IMETHODIMP nsTreeWalker::GetFilter(nsIDOMNodeFilter * *aFilter)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFilter);
|
||||
|
||||
NS_IF_ADDREF(*aFilter = mFilter);
|
||||
*aFilter = mFilter.ToXPCOMCallback().get();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
nsTreeWalker(nsINode *aRoot,
|
||||
uint32_t aWhatToShow,
|
||||
nsIDOMNodeFilter *aFilter);
|
||||
const mozilla::dom::NodeFilterHolder &aFilter);
|
||||
virtual ~nsTreeWalker();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeWalker)
|
||||
|
@ -2624,7 +2624,6 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||
type.unroll().inner.identifier.name)
|
||||
|
||||
if (descriptor.interface.isCallback() and
|
||||
descriptor.interface.identifier.name != "NodeFilter" and
|
||||
descriptor.interface.identifier.name != "EventListener"):
|
||||
if descriptor.workers:
|
||||
if type.nullable():
|
||||
@ -3470,8 +3469,7 @@ if (!returnArray) {
|
||||
|
||||
if (type.isGeckoInterface() and
|
||||
(not type.isCallbackInterface() or
|
||||
type.unroll().inner.identifier.name == "EventListener" or
|
||||
type.unroll().inner.identifier.name == "NodeFilter")):
|
||||
type.unroll().inner.identifier.name == "EventListener")):
|
||||
descriptor = descriptorProvider.getDescriptor(type.unroll().inner.identifier.name)
|
||||
if type.nullable():
|
||||
wrappingCode = ("if (!%s) {\n" % (result) +
|
||||
@ -7464,7 +7462,6 @@ class CGNativeMember(ClassMethod):
|
||||
|
||||
if (type.isGeckoInterface() and
|
||||
(not type.isCallbackInterface() or
|
||||
type.unroll().inner.identifier.name == "NodeFilter" or
|
||||
type.unroll().inner.identifier.name == "EventListener")):
|
||||
iface = type.unroll().inner
|
||||
argIsPointer = type.nullable() or iface.isExternal()
|
||||
|
@ -449,7 +449,8 @@ GetTextNode(nsISelection *selection, nsEditor *editor) {
|
||||
// if node is null, return it to indicate there's no text
|
||||
NS_ENSURE_TRUE(node, nullptr);
|
||||
// This should be the root node, walk the tree looking for text nodes
|
||||
nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, nullptr);
|
||||
mozilla::dom::NodeFilterHolder filter;
|
||||
nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter);
|
||||
while (!editor->IsTextNode(selNode)) {
|
||||
if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) {
|
||||
return nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user