kjs_dom.h

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
00005  *  Copyright (C) 2003 Apple Computer, Inc.
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2 of the License, or (at your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Library General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public
00018  *  License along with this library; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _KJS_DOM_H_
00023 #define _KJS_DOM_H_
00024 
00025 #include "dom/dom_node.h"
00026 #include "dom/dom_doc.h"
00027 #include "dom/dom_element.h"
00028 #include "dom/dom_xml.h"
00029 
00030 #include "ecma/kjs_binding.h"
00031 
00032 namespace KJS {
00033 
00034   class DOMNode : public DOMObject {
00035   public:
00036     // Build a DOMNode
00037     DOMNode(ExecState *exec, const DOM::Node& n);
00038     // Constructor for inherited classes
00039     DOMNode(const Object& proto, const DOM::Node& n);
00040     ~DOMNode();
00041     virtual bool toBoolean(ExecState *) const;
00042     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00043     Value getValueProperty(ExecState *exec, int token) const;
00044 
00045     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00046     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00047     virtual DOM::Node toNode() const { return node; }
00048     virtual const ClassInfo* classInfo() const { return &info; }
00049     static const ClassInfo info;
00050 
00051     virtual Value toPrimitive(ExecState *exec, Type preferred = UndefinedType) const;
00052     virtual UString toString(ExecState *exec) const;
00053     void setListener(ExecState *exec, int eventId, const Value& func) const;
00054     Value getListener(int eventId) const;
00055     virtual void pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const;
00056 
00057     enum { NodeName, NodeValue, NodeType, ParentNode, ParentElement,
00058            ChildNodes, FirstChild, LastChild, PreviousSibling, NextSibling, Item,
00059            Attributes, NamespaceURI, Prefix, LocalName, OwnerDocument, InsertBefore,
00060            ReplaceChild, RemoveChild, AppendChild, HasAttributes, HasChildNodes,
00061            CloneNode, Normalize, IsSupported, AddEventListener, RemoveEventListener,
00062            DispatchEvent, Contains, InsertAdjacentHTML,
00063            OnAbort, OnBlur, OnChange, OnClick, OnDblClick, OnDragDrop, OnError,
00064            OnFocus, OnKeyDown, OnKeyPress, OnKeyUp, OnLoad, OnMouseDown,
00065            OnMouseMove, OnMouseOut, OnMouseOver, OnMouseUp, OnMove, OnReset,
00066            OnResize, OnSelect, OnSubmit, OnUnload,
00067            OffsetLeft, OffsetTop, OffsetWidth, OffsetHeight, OffsetParent,
00068            ClientWidth, ClientHeight, ScrollLeft, ScrollTop,
00069        ScrollWidth, ScrollHeight, SourceIndex };
00070 
00071   protected:
00072     DOM::Node node;
00073   };
00074 
00075   class DOMNodeList : public DOMObject {
00076   public:
00077     DOMNodeList(ExecState *, const DOM::NodeList& l);
00078     ~DOMNodeList();
00079     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00080     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00081     virtual Value call(ExecState *exec, Object &thisObj, const List&args);
00082     virtual Value tryCall(ExecState *exec, Object &thisObj, const List&args);
00083     virtual bool implementsCall() const { return true; }
00084     virtual ReferenceList propList(ExecState *exec, bool recursive);
00085 
00086     // no put - all read-only
00087     virtual const ClassInfo* classInfo() const { return &info; }
00088     virtual bool toBoolean(ExecState *) const { return true; }
00089     static const ClassInfo info;
00090     DOM::NodeList nodeList() const { return list; }
00091     enum { Item, NamedItem };
00092   private:
00093     DOM::NodeList list;
00094   };
00095 
00096   class DOMDocument : public DOMNode {
00097   public:
00098     // Build a DOMDocument
00099     DOMDocument(ExecState *exec, const DOM::Document& d);
00100     // Constructor for inherited classes
00101     DOMDocument(const Object& proto, const DOM::Document& d);
00102     virtual ~DOMDocument();
00103     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00104     Value getValueProperty(ExecState *exec, int token) const;
00105     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00106     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00107     virtual const ClassInfo* classInfo() const { return &info; }
00108     static const ClassInfo info;
00109     enum { DocType, Implementation, DocumentElement,
00110            // Functions
00111            CreateElement, CreateDocumentFragment, CreateTextNode, CreateComment,
00112            CreateCDATASection, CreateProcessingInstruction, CreateAttribute,
00113            CreateEntityReference, GetElementsByTagName, ImportNode, CreateElementNS,
00114            CreateAttributeNS, GetElementsByTagNameNS, GetElementById,
00115            CreateRange, CreateNodeIterator, CreateTreeWalker, DefaultView,
00116            CreateEvent, StyleSheets, GetOverrideStyle, Abort, Load, LoadXML,
00117            PreferredStylesheetSet, SelectedStylesheetSet, ReadyState, Async };
00118   };
00119 
00120   class DOMAttr : public DOMNode {
00121   public:
00122     DOMAttr(ExecState *exec, const DOM::Attr& a) : DOMNode(exec, a) { }
00123     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00124     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00125     Value getValueProperty(ExecState *exec, int token) const;
00126     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00127     virtual const ClassInfo* classInfo() const { return &info; }
00128     static const ClassInfo info;
00129     enum { Name, Specified, ValueProperty, OwnerElement };
00130   };
00131 
00132   class DOMElement : public DOMNode {
00133   public:
00134     // Build a DOMElement
00135     DOMElement(ExecState *exec, const DOM::Element& e);
00136     // Constructor for inherited classes
00137     DOMElement(const Object& proto, const DOM::Element& e);
00138     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00139     // no put - all read-only
00140     virtual const ClassInfo* classInfo() const { return &info; }
00141     static const ClassInfo info;
00142     enum { TagName, Style,
00143            GetAttribute, SetAttribute, RemoveAttribute, GetAttributeNode,
00144            SetAttributeNode, RemoveAttributeNode, GetElementsByTagName,
00145            GetAttributeNS, SetAttributeNS, RemoveAttributeNS, GetAttributeNodeNS,
00146            SetAttributeNodeNS, GetElementsByTagNameNS, HasAttribute, HasAttributeNS };
00147   };
00148 
00149   class DOMDOMImplementation : public DOMObject {
00150   public:
00151     // Build a DOMDOMImplementation
00152     DOMDOMImplementation(ExecState *, const DOM::DOMImplementation& i);
00153     ~DOMDOMImplementation();
00154     // no put - all functions
00155     virtual const ClassInfo* classInfo() const { return &info; }
00156     virtual bool toBoolean(ExecState *) const { return true; }
00157     static const ClassInfo info;
00158     enum { HasFeature, CreateDocumentType, CreateDocument, CreateCSSStyleSheet, CreateHTMLDocument };
00159     DOM::DOMImplementation toImplementation() const { return implementation; }
00160   private:
00161     DOM::DOMImplementation implementation;
00162   };
00163 
00164   class DOMDocumentType : public DOMNode {
00165   public:
00166     // Build a DOMDocumentType
00167     DOMDocumentType(ExecState *exec, const DOM::DocumentType& dt);
00168     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00169     Value getValueProperty(ExecState *exec, int token) const;
00170     // no put - all read-only
00171     virtual const ClassInfo* classInfo() const { return &info; }
00172     static const ClassInfo info;
00173     enum { Name, Entities, Notations, PublicId, SystemId, InternalSubset };
00174   };
00175 
00176   class DOMNamedNodeMap : public DOMObject {
00177   public:
00178     DOMNamedNodeMap(ExecState *, const DOM::NamedNodeMap& m);
00179     ~DOMNamedNodeMap();
00180     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00181     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00182     // no put - all read-only
00183     virtual const ClassInfo* classInfo() const { return &info; }
00184     virtual bool toBoolean(ExecState *) const { return true; }
00185     static const ClassInfo info;
00186     enum { GetNamedItem, SetNamedItem, RemoveNamedItem, Item, Length,
00187            GetNamedItemNS, SetNamedItemNS, RemoveNamedItemNS };
00188     DOM::NamedNodeMap toMap() const { return map; }
00189   private:
00190     DOM::NamedNodeMap map;
00191   };
00192 
00193   class DOMProcessingInstruction : public DOMNode {
00194   public:
00195     DOMProcessingInstruction(ExecState *exec, const DOM::ProcessingInstruction& pi) : DOMNode(exec, pi) { }
00196     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00197     Value getValueProperty(ExecState *exec, int token) const;
00198     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00199     virtual const ClassInfo* classInfo() const { return &info; }
00200     static const ClassInfo info;
00201     enum { Target, Data, Sheet };
00202   };
00203 
00204   class DOMNotation : public DOMNode {
00205   public:
00206     DOMNotation(ExecState *exec, const DOM::Notation& n) : DOMNode(exec, n) { }
00207     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00208     Value getValueProperty(ExecState *exec, int token) const;
00209     // no put - all read-only
00210     virtual const ClassInfo* classInfo() const { return &info; }
00211     static const ClassInfo info;
00212     enum { PublicId, SystemId };
00213   };
00214 
00215   class DOMEntity : public DOMNode {
00216   public:
00217     DOMEntity(ExecState *exec, const DOM::Entity& e) : DOMNode(exec, e) { }
00218     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00219     Value getValueProperty(ExecState *exec, int token) const;
00220     // no put - all read-only
00221     virtual const ClassInfo* classInfo() const { return &info; }
00222     static const ClassInfo info;
00223     enum { PublicId, SystemId, NotationName };
00224   };
00225 
00226   // Constructor for Node - constructor stuff not implemented yet
00227   class NodeConstructor : public DOMObject {
00228   public:
00229     NodeConstructor(ExecState *);
00230     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00231     Value getValueProperty(ExecState *exec, int token) const;
00232     // no put - all read-only
00233     virtual const ClassInfo* classInfo() const { return &info; }
00234     static const ClassInfo info;
00235   };
00236 
00237   // Constructor for DOMException - constructor stuff not implemented yet
00238   class DOMExceptionConstructor : public DOMObject {
00239   public:
00240     DOMExceptionConstructor(ExecState *);
00241     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00242     Value getValueProperty(ExecState *exec, int token) const;
00243     // no put - all read-only
00244     virtual const ClassInfo* classInfo() const { return &info; }
00245     static const ClassInfo info;
00246   };
00247 
00248   bool checkNodeSecurity(ExecState *exec, const DOM::Node& n);
00249   KDE_EXPORT Value getDOMNode(ExecState *exec, const DOM::Node& n);
00250   Value getDOMNamedNodeMap(ExecState *exec, const DOM::NamedNodeMap& m);
00251   Value getDOMNodeList(ExecState *exec, const DOM::NodeList& l);
00252   Value getDOMDOMImplementation(ExecState *exec, const DOM::DOMImplementation& i);
00253   Object getNodeConstructor(ExecState *exec);
00254   Object getDOMExceptionConstructor(ExecState *exec);
00255 
00256   // Internal class, used for the collection return by e.g. document.forms.myinput
00257   // when multiple nodes have the same name.
00258   class DOMNamedNodesCollection : public DOMObject {
00259   public:
00260     DOMNamedNodesCollection(ExecState *exec, const QValueList<DOM::Node>& nodes );
00261     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00262     virtual const ClassInfo* classInfo() const { return &info; }
00263     static const ClassInfo info;
00264     const QValueList<DOM::Node>& nodes() const { return m_nodes; }
00265     enum { Length };
00266   private:
00267     QValueList<DOM::Node> m_nodes;
00268   };
00269 
00270   class DOMCharacterData : public DOMNode {
00271   public:
00272     // Build a DOMCharacterData
00273     DOMCharacterData(ExecState *exec, const DOM::CharacterData& d);
00274     // Constructor for inherited classes
00275     DOMCharacterData(const Object& proto, const DOM::CharacterData& d);
00276     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00277     Value getValueProperty(ExecState *, int token) const;
00278     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00279     virtual const ClassInfo* classInfo() const { return &info; }
00280     static const ClassInfo info;
00281     DOM::CharacterData toData() const { return static_cast<DOM::CharacterData>(node); }
00282     enum { Data, Length,
00283            SubstringData, AppendData, InsertData, DeleteData, ReplaceData };
00284   };
00285 
00286   class DOMText : public DOMCharacterData {
00287   public:
00288     DOMText(ExecState *exec, const DOM::Text& t);
00289     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00290     Value getValueProperty(ExecState *, int token) const;
00291     virtual const ClassInfo* classInfo() const { return &info; }
00292     static const ClassInfo info;
00293     DOM::Text toText() const { return static_cast<DOM::Text>(node); }
00294     enum { SplitText };
00295   };
00296 
00297 } // namespace
00298 
00299 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys