File indexing completed on 2024-04-28 11:38:03

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
0004  *
0005  *  This library is free software; you can redistribute it and/or
0006  *  modify it under the terms of the GNU Library General Public
0007  *  License as published by the Free Software Foundation; either
0008  *  version 2 of the License, or (at your option) any later version.
0009  *
0010  *  This library is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  *  Library General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU Library General Public
0016  *  License along with this library; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #ifndef _KJS_TRAVERSAL_H_
0021 #define _KJS_TRAVERSAL_H_
0022 
0023 #include "ecma/kjs_binding.h"
0024 #include "ecma/kjs_dom.h"
0025 #include "dom/dom2_traversal.h"
0026 
0027 namespace KJS
0028 {
0029 
0030 class DOMNodeIterator : public DOMObject
0031 {
0032 public:
0033     DOMNodeIterator(ExecState *exec, DOM::NodeIteratorImpl *ni);
0034     ~DOMNodeIterator();
0035     using KJS::JSObject::getOwnPropertySlot;
0036     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0037     JSValue *getValueProperty(ExecState *exec, int token) const;
0038     // no put - all read-only
0039     const ClassInfo *classInfo() const override
0040     {
0041         return &info;
0042     }
0043     static const ClassInfo info;
0044     enum { Filter, Root, WhatToShow, ExpandEntityReferences,
0045            NextNode, PreviousNode, Detach
0046          };
0047     DOM::NodeIteratorImpl *impl() const
0048     {
0049         return m_impl.get();
0050     }
0051 protected:
0052     SharedPtr<DOM::NodeIteratorImpl> m_impl;
0053 };
0054 
0055 // Constructor object NodeFilter
0056 class NodeFilterConstructor : public DOMObject
0057 {
0058 public:
0059     NodeFilterConstructor(ExecState *);
0060     using KJS::JSObject::getOwnPropertySlot;
0061     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0062     JSValue *getValueProperty(ExecState *exec, int token) const;
0063     // no put - all read-only
0064     const ClassInfo *classInfo() const override
0065     {
0066         return &info;
0067     }
0068     static const ClassInfo info;
0069 };
0070 
0071 class DOMTreeWalker : public DOMObject
0072 {
0073 public:
0074     DOMTreeWalker(ExecState *exec, DOM::TreeWalkerImpl *tw);
0075     ~DOMTreeWalker();
0076     using KJS::JSObject::getOwnPropertySlot;
0077     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0078     JSValue *getValueProperty(ExecState *exec, int token) const;
0079     void mark() override;
0080     using KJS::JSObject::put;
0081     virtual void put(ExecState *exec, const Identifier &propertyName,
0082                      JSValue *value, int attr = None) override;
0083     const ClassInfo *classInfo() const override
0084     {
0085         return &info;
0086     }
0087     static const ClassInfo info;
0088     enum { Root, WhatToShow, Filter, ExpandEntityReferences, CurrentNode,
0089            ParentNode, FirstChild, LastChild, PreviousSibling, NextSibling,
0090            PreviousNode, NextNode
0091          };
0092     DOM::TreeWalkerImpl *impl() const
0093     {
0094         return m_impl.get();
0095     }
0096 protected:
0097     SharedPtr<DOM::TreeWalkerImpl> m_impl;
0098 };
0099 
0100 JSValue *getDOMNodeIterator(ExecState *exec, DOM::NodeIteratorImpl *ni);
0101 JSValue *getNodeFilterConstructor(ExecState *exec);
0102 JSValue *getDOMNodeFilter(ExecState *exec, DOM::NodeFilterImpl *nf);
0103 JSValue *getDOMTreeWalker(ExecState *exec, DOM::TreeWalkerImpl *tw);
0104 
0105 /**
0106  * Convert an object to a NodeFilter. Returns a null Node if not possible.
0107  */
0108 DOM::NodeFilterImpl *toNodeFilter(JSValue *);
0109 
0110 class JSNodeFilter : public DOM::NodeFilterImpl
0111 {
0112 public:
0113     JSNodeFilter(JSObject *_filter);
0114     virtual ~JSNodeFilter();
0115 
0116     bool  isJSFilter() const override;
0117     short acceptNode(const DOM::Node &n, void *&bindingsException) override;
0118 
0119     void mark();
0120 
0121     JSObject *filter() const
0122     {
0123         return m_filter;
0124     }
0125 
0126     // Extracts a JSNodeFilter contained insode a DOM::NodeFilterImpl,
0127     // if any (or returns 0);
0128     static JSNodeFilter *fromDOMFilter(DOM::NodeFilterImpl *nf);
0129 protected:
0130     // The filter here can be either a function or
0131     // an object with the acceptNode property. We will use either one.
0132 
0133     // Memory management note: we expect the wrapper object to mark us.
0134     JSObject *m_filter;
0135 };
0136 
0137 } // namespace
0138 
0139 #endif