khtml Library API Documentation

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