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  *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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,
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     // no put - all read-only
00085     virtual const ClassInfo* classInfo() const { return &info; }
00086     virtual bool toBoolean(ExecState *) const { return true; }
00087     static const ClassInfo info;
00088     DOM::NodeList nodeList() const { return list; }
00089     enum { Item, NamedItem };
00090   private:
00091     DOM::NodeList list;
00092   };
00093 
00094   class DOMDocument : public DOMNode {
00095   public:
00096     // Build a DOMDocument
00097     DOMDocument(ExecState *exec, const DOM::Document& d);
00098     // Constructor for inherited classes
00099     DOMDocument(const Object& proto, const DOM::Document& d);
00100     virtual ~DOMDocument();
00101     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00102     Value getValueProperty(ExecState *exec, int token) const;
00103     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00104     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00105     virtual const ClassInfo* classInfo() const { return &info; }
00106     static const ClassInfo info;
00107     enum { DocType, Implementation, DocumentElement,
00108            // Functions
00109            CreateElement, CreateDocumentFragment, CreateTextNode, CreateComment,
00110            CreateCDATASection, CreateProcessingInstruction, CreateAttribute,
00111            CreateEntityReference, GetElementsByTagName, ImportNode, CreateElementNS,
00112            CreateAttributeNS, GetElementsByTagNameNS, GetElementById,
00113            CreateRange, CreateNodeIterator, CreateTreeWalker, DefaultView,
00114            CreateEvent, StyleSheets, GetOverrideStyle, Abort, Load, LoadXML,
00115            PreferredStylesheetSet, SelectedStylesheetSet, ReadyState, Async };
00116   };
00117 
00118   class DOMAttr : public DOMNode {
00119   public:
00120     DOMAttr(ExecState *exec, const DOM::Attr& a) : DOMNode(exec, a) { }
00121     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00122     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00123     Value getValueProperty(ExecState *exec, int token) const;
00124     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00125     virtual const ClassInfo* classInfo() const { return &info; }
00126     static const ClassInfo info;
00127     enum { Name, Specified, ValueProperty, OwnerElement };
00128   };
00129 
00130   class DOMElement : public DOMNode {
00131   public:
00132     // Build a DOMElement
00133     DOMElement(ExecState *exec, const DOM::Element& e);
00134     // Constructor for inherited classes
00135     DOMElement(const Object& proto, const DOM::Element& e);
00136     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00137     // no put - all read-only
00138     virtual const ClassInfo* classInfo() const { return &info; }
00139     static const ClassInfo info;
00140     enum { TagName, Style,
00141            GetAttribute, SetAttribute, RemoveAttribute, GetAttributeNode,
00142            SetAttributeNode, RemoveAttributeNode, GetElementsByTagName,
00143            GetAttributeNS, SetAttributeNS, RemoveAttributeNS, GetAttributeNodeNS,
00144            SetAttributeNodeNS, GetElementsByTagNameNS, HasAttribute, HasAttributeNS };
00145   };
00146 
00147   class DOMDOMImplementation : public DOMObject {
00148   public:
00149     // Build a DOMDOMImplementation
00150     DOMDOMImplementation(ExecState *, const DOM::DOMImplementation& i);
00151     ~DOMDOMImplementation();
00152     // no put - all functions
00153     virtual const ClassInfo* classInfo() const { return &info; }
00154     virtual bool toBoolean(ExecState *) const { return true; }
00155     static const ClassInfo info;
00156     enum { HasFeature, CreateDocumentType, CreateDocument, CreateCSSStyleSheet, CreateHTMLDocument };
00157     DOM::DOMImplementation toImplementation() const { return implementation; }
00158   private:
00159     DOM::DOMImplementation implementation;
00160   };
00161 
00162   class DOMDocumentType : public DOMNode {
00163   public:
00164     // Build a DOMDocumentType
00165     DOMDocumentType(ExecState *exec, const DOM::DocumentType& dt);
00166     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00167     Value getValueProperty(ExecState *exec, int token) const;
00168     // no put - all read-only
00169     virtual const ClassInfo* classInfo() const { return &info; }
00170     static const ClassInfo info;
00171     enum { Name, Entities, Notations, PublicId, SystemId, InternalSubset };
00172   };
00173 
00174   class DOMNamedNodeMap : public DOMObject {
00175   public:
00176     DOMNamedNodeMap(ExecState *, const DOM::NamedNodeMap& m);
00177     ~DOMNamedNodeMap();
00178     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00179     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00180     // no put - all read-only
00181     virtual const ClassInfo* classInfo() const { return &info; }
00182     virtual bool toBoolean(ExecState *) const { return true; }
00183     static const ClassInfo info;
00184     enum { GetNamedItem, SetNamedItem, RemoveNamedItem, Item,
00185            GetNamedItemNS, SetNamedItemNS, RemoveNamedItemNS };
00186     DOM::NamedNodeMap toMap() const { return map; }
00187   private:
00188     DOM::NamedNodeMap map;
00189   };
00190 
00191   class DOMProcessingInstruction : public DOMNode {
00192   public:
00193     DOMProcessingInstruction(ExecState *exec, const DOM::ProcessingInstruction& pi) : DOMNode(exec, pi) { }
00194     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00195     Value getValueProperty(ExecState *exec, int token) const;
00196     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00197     virtual const ClassInfo* classInfo() const { return &info; }
00198     static const ClassInfo info;
00199     enum { Target, Data, Sheet };
00200   };
00201 
00202   class DOMNotation : public DOMNode {
00203   public:
00204     DOMNotation(ExecState *exec, const DOM::Notation& n) : DOMNode(exec, n) { }
00205     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00206     Value getValueProperty(ExecState *exec, int token) const;
00207     // no put - all read-only
00208     virtual const ClassInfo* classInfo() const { return &info; }
00209     static const ClassInfo info;
00210     enum { PublicId, SystemId };
00211   };
00212 
00213   class DOMEntity : public DOMNode {
00214   public:
00215     DOMEntity(ExecState *exec, const DOM::Entity& e) : DOMNode(exec, e) { }
00216     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00217     Value getValueProperty(ExecState *exec, int token) const;
00218     // no put - all read-only
00219     virtual const ClassInfo* classInfo() const { return &info; }
00220     static const ClassInfo info;
00221     enum { PublicId, SystemId, NotationName };
00222   };
00223 
00224   // Constructor for Node - constructor stuff not implemented yet
00225   class NodeConstructor : public DOMObject {
00226   public:
00227     NodeConstructor(ExecState *);
00228     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00229     Value getValueProperty(ExecState *exec, int token) const;
00230     // no put - all read-only
00231     virtual const ClassInfo* classInfo() const { return &info; }
00232     static const ClassInfo info;
00233   };
00234 
00235   // Constructor for DOMException - constructor stuff not implemented yet
00236   class DOMExceptionConstructor : public DOMObject {
00237   public:
00238     DOMExceptionConstructor(ExecState *);
00239     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00240     Value getValueProperty(ExecState *exec, int token) const;
00241     // no put - all read-only
00242     virtual const ClassInfo* classInfo() const { return &info; }
00243     static const ClassInfo info;
00244   };
00245 
00246   bool checkNodeSecurity(ExecState *exec, const DOM::Node& n);
00247   Value getDOMNode(ExecState *exec, const DOM::Node& n);
00248   Value getDOMNamedNodeMap(ExecState *exec, const DOM::NamedNodeMap& m);
00249   Value getDOMNodeList(ExecState *exec, const DOM::NodeList& l);
00250   Value getDOMDOMImplementation(ExecState *exec, const DOM::DOMImplementation& i);
00251   Object getNodeConstructor(ExecState *exec);
00252   Object getDOMExceptionConstructor(ExecState *exec);
00253 
00254   // Internal class, used for the collection return by e.g. document.forms.myinput
00255   // when multiple nodes have the same name.
00256   class DOMNamedNodesCollection : public DOMObject {
00257   public:
00258     DOMNamedNodesCollection(ExecState *exec, const QValueList<DOM::Node>& nodes );
00259     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00260     virtual const ClassInfo* classInfo() const { return &info; }
00261     static const ClassInfo info;
00262     const QValueList<DOM::Node>& nodes() const { return m_nodes; }
00263   private:
00264     QValueList<DOM::Node> m_nodes;
00265   };
00266 
00267   class DOMCharacterData : public DOMNode {
00268   public:
00269     // Build a DOMCharacterData
00270     DOMCharacterData(ExecState *exec, const DOM::CharacterData& d);
00271     // Constructor for inherited classes
00272     DOMCharacterData(const Object& proto, const DOM::CharacterData& d);
00273     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00274     Value getValueProperty(ExecState *, int token) const;
00275     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00276     virtual const ClassInfo* classInfo() const { return &info; }
00277     static const ClassInfo info;
00278     DOM::CharacterData toData() const { return static_cast<DOM::CharacterData>(node); }
00279     enum { Data, Length,
00280            SubstringData, AppendData, InsertData, DeleteData, ReplaceData };
00281   };
00282 
00283   class DOMText : public DOMCharacterData {
00284   public:
00285     DOMText(ExecState *exec, const DOM::Text& t);
00286     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00287     Value getValueProperty(ExecState *, int token) const;
00288     virtual const ClassInfo* classInfo() const { return &info; }
00289     static const ClassInfo info;
00290     DOM::Text toText() const { return static_cast<DOM::Text>(node); }
00291     enum { SplitText };
00292   };
00293 
00294 } // namespace
00295 
00296 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 22 14:26:07 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003