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 PUBLIC_DEFINE_PROTOTYPE("DOMDocument", DOMDocumentProto)
00033 
00034 namespace KJS {
00035 
00036   class DOMNode : public DOMObject {
00037   public:
00038     // Build a DOMNode
00039     DOMNode(ExecState *exec, const DOM::Node& n);
00040     // Constructor for inherited classes
00041     DOMNode(const Object& proto, const DOM::Node& n);
00042     ~DOMNode();
00043     virtual bool toBoolean(ExecState *) const;
00044     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00045     Value getValueProperty(ExecState *exec, int token) const;
00046 
00047     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00048     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00049     virtual DOM::Node toNode() const { return node; }
00050     virtual const ClassInfo* classInfo() const { return &info; }
00051     static const ClassInfo info;
00052 
00053     virtual Value toPrimitive(ExecState *exec, Type preferred = UndefinedType) const;
00054     virtual UString toString(ExecState *exec) const;
00055     void setListener(ExecState *exec, int eventId, const Value& func) const;
00056     Value getListener(int eventId) const;
00057     virtual void pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const;
00058 
00059     enum { NodeName, NodeValue, NodeType, ParentNode, ParentElement,
00060            ChildNodes, FirstChild, LastChild, PreviousSibling, NextSibling, Item,
00061            Attributes, NamespaceURI, Prefix, LocalName, OwnerDocument, InsertBefore,
00062            ReplaceChild, RemoveChild, AppendChild, HasAttributes, HasChildNodes,
00063            CloneNode, Normalize, IsSupported, AddEventListener, RemoveEventListener,
00064            DispatchEvent, Contains, InsertAdjacentHTML,
00065            OnAbort, OnBlur, OnChange, OnClick, OnDblClick, OnDragDrop, OnError,
00066            OnFocus, OnKeyDown, OnKeyPress, OnKeyUp, OnLoad, OnMouseDown,
00067            OnMouseMove, OnMouseOut, OnMouseOver, OnMouseUp, OnMove, OnReset,
00068            OnResize, OnSelect, OnSubmit, OnUnload,
00069            OffsetLeft, OffsetTop, OffsetWidth, OffsetHeight, OffsetParent,
00070            ClientWidth, ClientHeight, ScrollLeft, ScrollTop,
00071        ScrollWidth, ScrollHeight, SourceIndex };
00072 
00073   protected:
00074     DOM::Node node;
00075   };
00076 
00077   class DOMNodeList : public DOMObject {
00078   public:
00079     DOMNodeList(ExecState *, const DOM::NodeList& l);
00080     ~DOMNodeList();
00081     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00082     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00083     virtual Value call(ExecState *exec, Object &thisObj, const List&args);
00084     virtual Value tryCall(ExecState *exec, Object &thisObj, const List&args);
00085     virtual bool implementsCall() const { return true; }
00086     virtual ReferenceList propList(ExecState *exec, bool recursive);
00087 
00088     // no put - all read-only
00089     virtual const ClassInfo* classInfo() const { return &info; }
00090     virtual bool toBoolean(ExecState *) const { return true; }
00091     static const ClassInfo info;
00092     DOM::NodeList nodeList() const { return list; }
00093     enum { Item, NamedItem };
00094   private:
00095     DOM::NodeList list;
00096   };
00097 
00098   class DOMDocument : public DOMNode {
00099   public:
00100     // Build a DOMDocument
00101     DOMDocument(ExecState *exec, const DOM::Document& d);
00102     // Constructor for inherited classes
00103     DOMDocument(const Object& proto, const DOM::Document& d);
00104     virtual ~DOMDocument();
00105     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00106     Value getValueProperty(ExecState *exec, int token) const;
00107     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00108     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00109     virtual const ClassInfo* classInfo() const { return &info; }
00110     static const ClassInfo info;
00111     enum { DocType, Implementation, DocumentElement, CharacterSet, 
00112            // Functions
00113            CreateElement, CreateDocumentFragment, CreateTextNode, CreateComment,
00114            CreateCDATASection, CreateProcessingInstruction, CreateAttribute,
00115            CreateEntityReference, GetElementsByTagName, ImportNode, CreateElementNS,
00116            CreateAttributeNS, GetElementsByTagNameNS, GetElementById,
00117            CreateRange, CreateNodeIterator, CreateTreeWalker, DefaultView,
00118            CreateEvent, StyleSheets, GetOverrideStyle, Abort, Load, LoadXML,
00119            PreferredStylesheetSet, SelectedStylesheetSet, ReadyState, Async };
00120   };
00121 
00122   DEFINE_PSEUDO_CONSTRUCTOR(DocumentPseudoCtor)
00123 
00124   class DOMAttr : public DOMNode {
00125   public:
00126     DOMAttr(ExecState *exec, const DOM::Attr& a) : DOMNode(exec, a) { }
00127     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00128     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00129     Value getValueProperty(ExecState *exec, int token) const;
00130     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00131     virtual const ClassInfo* classInfo() const { return &info; }
00132     static const ClassInfo info;
00133     enum { Name, Specified, ValueProperty, OwnerElement };
00134   };
00135 
00136   class DOMElement : public DOMNode {
00137   public:
00138     // Build a DOMElement
00139     DOMElement(ExecState *exec, const DOM::Element& e);
00140     // Constructor for inherited classes
00141     DOMElement(const Object& proto, const DOM::Element& e);
00142     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00143     // no put - all read-only
00144     virtual const ClassInfo* classInfo() const { return &info; }
00145     static const ClassInfo info;
00146     enum { TagName, Style,
00147            GetAttribute, SetAttribute, RemoveAttribute, GetAttributeNode,
00148            SetAttributeNode, RemoveAttributeNode, GetElementsByTagName,
00149            GetAttributeNS, SetAttributeNS, RemoveAttributeNS, GetAttributeNodeNS,
00150            SetAttributeNodeNS, GetElementsByTagNameNS, HasAttribute, HasAttributeNS };
00151   };
00152 
00153   DEFINE_PSEUDO_CONSTRUCTOR(ElementPseudoCtor)
00154 
00155   class DOMDOMImplementation : public DOMObject {
00156   public:
00157     // Build a DOMDOMImplementation
00158     DOMDOMImplementation(ExecState *, const DOM::DOMImplementation& i);
00159     ~DOMDOMImplementation();
00160     // no put - all functions
00161     virtual const ClassInfo* classInfo() const { return &info; }
00162     virtual bool toBoolean(ExecState *) const { return true; }
00163     static const ClassInfo info;
00164     enum { HasFeature, CreateDocumentType, CreateDocument, CreateCSSStyleSheet, CreateHTMLDocument };
00165     DOM::DOMImplementation toImplementation() const { return implementation; }
00166   private:
00167     DOM::DOMImplementation implementation;
00168   };
00169 
00170   class DOMDocumentType : public DOMNode {
00171   public:
00172     // Build a DOMDocumentType
00173     DOMDocumentType(ExecState *exec, const DOM::DocumentType& dt);
00174     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00175     Value getValueProperty(ExecState *exec, int token) const;
00176     // no put - all read-only
00177     virtual const ClassInfo* classInfo() const { return &info; }
00178     static const ClassInfo info;
00179     enum { Name, Entities, Notations, PublicId, SystemId, InternalSubset };
00180   };
00181 
00182   class DOMNamedNodeMap : public DOMObject {
00183   public:
00184     DOMNamedNodeMap(ExecState *, const DOM::NamedNodeMap& m);
00185     ~DOMNamedNodeMap();
00186     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00187     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00188     // no put - all read-only
00189     virtual const ClassInfo* classInfo() const { return &info; }
00190     virtual bool toBoolean(ExecState *) const { return true; }
00191     static const ClassInfo info;
00192     enum { GetNamedItem, SetNamedItem, RemoveNamedItem, Item, Length,
00193            GetNamedItemNS, SetNamedItemNS, RemoveNamedItemNS };
00194     DOM::NamedNodeMap toMap() const { return map; }
00195   private:
00196     DOM::NamedNodeMap map;
00197   };
00198 
00199   class DOMProcessingInstruction : public DOMNode {
00200   public:
00201     DOMProcessingInstruction(ExecState *exec, const DOM::ProcessingInstruction& pi) : DOMNode(exec, pi) { }
00202     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00203     Value getValueProperty(ExecState *exec, int token) const;
00204     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00205     virtual const ClassInfo* classInfo() const { return &info; }
00206     static const ClassInfo info;
00207     enum { Target, Data, Sheet };
00208   };
00209 
00210   class DOMNotation : public DOMNode {
00211   public:
00212     DOMNotation(ExecState *exec, const DOM::Notation& n) : DOMNode(exec, n) { }
00213     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00214     Value getValueProperty(ExecState *exec, int token) const;
00215     // no put - all read-only
00216     virtual const ClassInfo* classInfo() const { return &info; }
00217     static const ClassInfo info;
00218     enum { PublicId, SystemId };
00219   };
00220 
00221   class DOMEntity : public DOMNode {
00222   public:
00223     DOMEntity(ExecState *exec, const DOM::Entity& e) : DOMNode(exec, e) { }
00224     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00225     Value getValueProperty(ExecState *exec, int token) const;
00226     // no put - all read-only
00227     virtual const ClassInfo* classInfo() const { return &info; }
00228     static const ClassInfo info;
00229     enum { PublicId, SystemId, NotationName };
00230   };
00231 
00232   DEFINE_PSEUDO_CONSTRUCTOR(NodeConstructor)
00233 
00234   // Constructor for DOMException - constructor stuff not implemented yet
00235   class DOMExceptionConstructor : public DOMObject {
00236   public:
00237     DOMExceptionConstructor(ExecState *);
00238     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00239     Value getValueProperty(ExecState *exec, int token) const;
00240     // no put - all read-only
00241     virtual const ClassInfo* classInfo() const { return &info; }
00242     static const ClassInfo info;
00243   };
00244 
00245   bool checkNodeSecurity(ExecState *exec, const DOM::Node& n);
00246   KDE_EXPORT Value getDOMNode(ExecState *exec, const DOM::Node& n);
00247   Value getDOMNamedNodeMap(ExecState *exec, const DOM::NamedNodeMap& m);
00248   Value getDOMNodeList(ExecState *exec, const DOM::NodeList& l);
00249   Value getDOMDOMImplementation(ExecState *exec, const DOM::DOMImplementation& i);
00250   Object getDOMExceptionConstructor(ExecState *exec);
00251 
00252   // Internal class, used for the collection return by e.g. document.forms.myinput
00253   // when multiple nodes have the same name.
00254   class DOMNamedNodesCollection : public DOMObject {
00255   public:
00256     DOMNamedNodesCollection(ExecState *exec, const QValueList<DOM::Node>& nodes );
00257     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00258     virtual const ClassInfo* classInfo() const { return &info; }
00259     static const ClassInfo info;
00260     const QValueList<DOM::Node>& nodes() const { return m_nodes; }
00261     enum { Length };
00262   private:
00263     QValueList<DOM::Node> m_nodes;
00264   };
00265 
00266   class DOMCharacterData : public DOMNode {
00267   public:
00268     // Build a DOMCharacterData
00269     DOMCharacterData(ExecState *exec, const DOM::CharacterData& d);
00270     // Constructor for inherited classes
00271     DOMCharacterData(const Object& proto, const DOM::CharacterData& d);
00272     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00273     Value getValueProperty(ExecState *, int token) const;
00274     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00275     virtual const ClassInfo* classInfo() const { return &info; }
00276     static const ClassInfo info;
00277     DOM::CharacterData toData() const { return static_cast<DOM::CharacterData>(node); }
00278     enum { Data, Length,
00279            SubstringData, AppendData, InsertData, DeleteData, ReplaceData };
00280   };
00281 
00282   class DOMText : public DOMCharacterData {
00283   public:
00284     DOMText(ExecState *exec, const DOM::Text& t);
00285     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00286     Value getValueProperty(ExecState *, int token) const;
00287     virtual const ClassInfo* classInfo() const { return &info; }
00288     static const ClassInfo info;
00289     DOM::Text toText() const { return static_cast<DOM::Text>(node); }
00290     enum { SplitText };
00291   };
00292 
00293 } // namespace
00294 
00295 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys