KHtml

kjs_dom.h
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2000 Harri Porten ([email protected])
4  * Copyright (C) 2003 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef _KJS_DOM_H_
22 #define _KJS_DOM_H_
23 
24 #include "xml/dom_nodeimpl.h"
25 #include "xml/dom_docimpl.h"
26 #include "xml/dom_elementimpl.h"
27 #include "xml/dom_xmlimpl.h"
28 
29 #include "ecma/kjs_binding.h"
30 
31 namespace KJS
32 {
33 
34 class DOMNode : public DOMObject
35 {
36 public:
37  // Build a DOMNode
38  DOMNode(ExecState *exec, DOM::NodeImpl *n);
39  DOMNode(JSObject *proto, DOM::NodeImpl *n);
40  ~DOMNode();
41  bool toBoolean(ExecState *) const override;
42  using KJS::JSObject::getOwnPropertySlot;
43  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
44  JSValue *getValueProperty(ExecState *exec, int token) const;
45 
46  using KJS::JSObject::put;
47  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
48  void putValueProperty(ExecState *exec, int token, JSValue *value, int attr);
49  const ClassInfo *classInfo() const override
50  {
51  return &info;
52  }
53  static const ClassInfo info;
54 
55  JSValue *toPrimitive(ExecState *exec, JSType preferred = UndefinedType) const override;
56  UString toString(ExecState *exec) const override;
57  void setListener(ExecState *exec, int eventId, JSValue *func) const;
58  JSValue *getListener(int eventId) const;
59  virtual void pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const;
60 
61  enum { NodeName, NodeValue, NodeType, ParentNode, ParentElement,
62  ChildNodes, FirstChild, LastChild, PreviousSibling, NextSibling,
63  Attributes, NamespaceURI, Prefix, LocalName, OwnerDocument, InsertBefore,
64  ReplaceChild, RemoveChild, AppendChild, HasAttributes, HasChildNodes,
65  CloneNode, Normalize, IsSupported, AddEventListener, RemoveEventListener,
66  DispatchEvent, Contains, InsertAdjacentHTML,
67  OnAbort, OnBlur, OnChange, OnClick, OnDblClick, OnDragDrop, OnError,
68  OnFocus, OnKeyDown, OnKeyPress, OnKeyUp, OnLoad, OnMouseDown,
69  OnMouseMove, OnMouseOut, OnMouseOver, OnMouseUp, OnMove, OnReset,
70  OnResize, OnScroll, OnSelect, OnSubmit, OnUnload,
71  OffsetLeft, OffsetTop, OffsetWidth, OffsetHeight, OffsetParent,
72  ClientLeft, ClientTop, ClientWidth, ClientHeight, ScrollLeft, ScrollTop,
73  ScrollWidth, ScrollHeight, SourceIndex, TextContent, CompareDocumentPosition
74  };
75 
76  //### toNode? virtual
77  DOM::NodeImpl *impl() const
78  {
79  return m_impl.get();
80  }
81 protected:
82  SharedPtr<DOM::NodeImpl> m_impl;
83 };
84 
85 DEFINE_CONSTANT_TABLE(DOMNodeConstants)
86 KJS_DEFINE_PROTOTYPE(DOMNodeProto)
87 DEFINE_PSEUDO_CONSTRUCTOR(NodeConstructor)
88 
89 class DOMNodeList : public DOMObject
90 {
91 public:
92  DOMNodeList(ExecState *, DOM::NodeListImpl *l);
93  ~DOMNodeList();
94 
95  JSValue *indexGetter(ExecState *exec, unsigned index);
96  using KJS::JSObject::getOwnPropertySlot;
97  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
98  JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
99  bool implementsCall() const override
100  {
101  return true;
102  }
103  bool isFunctionType() const override
104  {
105  return false;
106  }
107  void getOwnPropertyNames(ExecState *, PropertyNameArray &, PropertyMap::PropertyMode mode) override;
108 
109  // no put - all read-only
110  const ClassInfo *classInfo() const override
111  {
112  return &info;
113  }
114  bool toBoolean(ExecState *) const override
115  {
116  return true;
117  }
118  static const ClassInfo info;
119 
120  enum { Length, Item, NamedItem };
121 
122  DOM::NodeListImpl *impl() const
123  {
124  return m_impl.get();
125  }
126 
127  DOM::NodeImpl *getByName(const Identifier &name);
128 private:
129  SharedPtr<DOM::NodeListImpl> m_impl;
130 
131  static JSValue *nameGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &);
132  static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &);
133 };
134 
135 DEFINE_PSEUDO_CONSTRUCTOR(NodeListPseudoCtor)
136 
137 class DOMDocument : public DOMNode
138 {
139 public:
140  // Build a DOMDocument
141  DOMDocument(ExecState *exec, DOM::DocumentImpl *d);
142  DOMDocument(JSObject *proto, DOM::DocumentImpl *d);
143 
144  using KJS::JSObject::getOwnPropertySlot;
145  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
146  JSValue *getValueProperty(ExecState *exec, int token) const;
147 
148  using KJS::JSObject::put;
149  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
150  void putValueProperty(ExecState *exec, int token, JSValue *value, int attr);
151  const ClassInfo *classInfo() const override
152  {
153  return &info;
154  }
155  static const ClassInfo info;
156  enum { DocType, Implementation, DocumentElement, CharacterSet,
157  // Functions
158  CreateElement, CreateDocumentFragment, CreateTextNode, CreateComment,
159  CreateCDATASection, CreateProcessingInstruction, CreateAttribute,
160  CreateEntityReference, GetElementsByTagName, ImportNode, CreateElementNS,
161  CreateAttributeNS, GetElementsByTagNameNS, GetElementById,
162  CreateRange, CreateNodeIterator, CreateTreeWalker, DefaultView,
163  CreateEvent, StyleSheets, GetOverrideStyle, Abort, Load, LoadXML,
164  PreferredStylesheetSet, SelectedStylesheetSet, ReadyState, Async,
165  GetElementsByClassName, Title, ExecCommand, QueryCommandEnabled,
166  QueryCommandIndeterm, QueryCommandState, QueryCommandSupported,
167  QueryCommandValue, QuerySelector, QuerySelectorAll,
168  CreateExpression, CreateNSResolver, Evaluate
169  };
170  DOM::DocumentImpl *impl()
171  {
172  return static_cast<DOM::DocumentImpl *>(m_impl.get());
173  }
174 };
175 
176 KJS_DEFINE_PROTOTYPE(DOMDocumentProto)
177 
178 DEFINE_PSEUDO_CONSTRUCTOR(DocumentPseudoCtor)
179 
180 class DOMDocumentFragment : public DOMNode
181 {
182 public:
183  DOMDocumentFragment(ExecState *exec, DOM::DocumentFragmentImpl *i);
184  const ClassInfo *classInfo() const override
185  {
186  return &info;
187  }
188  static const ClassInfo info;
189 
190  enum { QuerySelector, QuerySelectorAll };
191 };
192 DEFINE_PSEUDO_CONSTRUCTOR(DocumentFragmentPseudoCtor)
193 
194 class DOMAttr : public DOMNode
195 {
196 public:
197  DOMAttr(ExecState *exec, DOM::AttrImpl *a) : DOMNode(exec, a) { }
198  using KJS::JSObject::getOwnPropertySlot;
199  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
200  JSValue *getValueProperty(ExecState *exec, int token) const;
201 
202  using KJS::JSObject::put;
203  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
204  void putValueProperty(ExecState *exec, int token, JSValue *value, int attr);
205  const ClassInfo *classInfo() const override
206  {
207  return &info;
208  }
209  static const ClassInfo info;
210  enum { Name, Specified, ValueProperty, OwnerElement };
211 };
212 
213 class DOMElement : public DOMNode
214 {
215 public:
216  // Build a DOMElement
217  DOMElement(ExecState *exec, DOM::ElementImpl *e);
218  DOMElement(JSObject *proto, DOM::ElementImpl *e);
219  using KJS::JSObject::getOwnPropertySlot;
220  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
221  JSValue *getValueProperty(ExecState *exec, int token) const;
222 
223  // no put - all read-only
224  const ClassInfo *classInfo() const override
225  {
226  return &info;
227  }
228  static const ClassInfo info;
229  enum { TagName, Style, FirstElementChild, LastElementChild,
230  PreviousElementSibling, NextElementSibling, ChildElementCount,
231  GetAttribute, SetAttribute, RemoveAttribute, GetAttributeNode,
232  SetAttributeNode, RemoveAttributeNode, GetElementsByTagName,
233  GetAttributeNS, SetAttributeNS, RemoveAttributeNS, GetAttributeNodeNS,
234  SetAttributeNodeNS, GetElementsByTagNameNS, HasAttribute, HasAttributeNS,
235  GetElementsByClassName, Blur, Focus, QuerySelector, QuerySelectorAll,
236  GetClientRects, GetBoundingClientRect
237  };
238 private:
239 #if 0
240  static JSValue *attributeGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot &slot);
241 #endif
242 };
243 
244 DOM::AttrImpl *toAttr(JSValue *); // returns 0 if passed-in value is not a DOMAtt object
245 DOM::ElementImpl *toElement(JSValue *); // returns 0 if passed-in value is not a DOMElement object
246 
247 KJS_DEFINE_PROTOTYPE(DOMElementProto)
248 DEFINE_PSEUDO_CONSTRUCTOR(ElementPseudoCtor)
249 
250 class DOMDOMImplementation : public DOMObject
251 {
252 public:
253  // Build a DOMDOMImplementation
254  DOMDOMImplementation(ExecState *, DOM::DOMImplementationImpl *i);
255  ~DOMDOMImplementation();
256  // no put - all functions
257  const ClassInfo *classInfo() const override
258  {
259  return &info;
260  }
261  bool toBoolean(ExecState *) const override
262  {
263  return true;
264  }
265  static const ClassInfo info;
266  enum { HasFeature, CreateDocumentType, CreateDocument, CreateCSSStyleSheet, CreateHTMLDocument };
267 
268  DOM::DOMImplementationImpl *impl() const
269  {
270  return m_impl.get();
271  }
272 private:
273  SharedPtr<DOM::DOMImplementationImpl> m_impl;
274 };
275 
276 class DOMDocumentType : public DOMNode
277 {
278 public:
279  // Build a DOMDocumentType
280  DOMDocumentType(ExecState *exec, DOM::DocumentTypeImpl *dt);
281 
282  using KJS::JSObject::getOwnPropertySlot;
283  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
284  JSValue *getValueProperty(ExecState *exec, int token) const;
285  // no put - all read-only
286  const ClassInfo *classInfo() const override
287  {
288  return &info;
289  }
290  static const ClassInfo info;
291  enum { Name, Entities, Notations, PublicId, SystemId, InternalSubset };
292 };
293 
294 class DOMNamedNodeMap : public DOMObject
295 {
296 public:
297  DOMNamedNodeMap(ExecState *, DOM::NamedNodeMapImpl *m);
298  ~DOMNamedNodeMap();
299 
300  using KJS::JSObject::getOwnPropertySlot;
301  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
302  JSValue *getValueProperty(ExecState *exec, int token) const;
303  // no put - all read-only
304  const ClassInfo *classInfo() const override
305  {
306  return &info;
307  }
308  bool toBoolean(ExecState *) const override
309  {
310  return true;
311  }
312  static const ClassInfo info;
313  enum { GetNamedItem, SetNamedItem, RemoveNamedItem, Item, Length,
314  GetNamedItemNS, SetNamedItemNS, RemoveNamedItemNS
315  };
316 
317  DOM::NamedNodeMapImpl *impl() const
318  {
319  return m_impl.get();
320  }
321 
322  JSValue *indexGetter(ExecState *exec, unsigned index);
323 private:
324  static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &slot);
325  SharedPtr<DOM::NamedNodeMapImpl> m_impl;
326 };
327 
328 class DOMProcessingInstruction : public DOMNode
329 {
330 public:
331  DOMProcessingInstruction(ExecState *exec, DOM::ProcessingInstructionImpl *pi) : DOMNode(exec, pi) { }
332 
333  using KJS::JSObject::getOwnPropertySlot;
334  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
335  JSValue *getValueProperty(ExecState *exec, int token) const;
336 
337  using KJS::JSObject::put;
338  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
339  const ClassInfo *classInfo() const override
340  {
341  return &info;
342  }
343  static const ClassInfo info;
344  enum { Target, Data, Sheet };
345 };
346 
347 class DOMNotation : public DOMNode
348 {
349 public:
350  DOMNotation(ExecState *exec, DOM::NotationImpl *n) : DOMNode(exec, n) { }
351 
352  using KJS::JSObject::getOwnPropertySlot;
353  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
354  JSValue *getValueProperty(ExecState *exec, int token) const;
355  // no put - all read-only
356  const ClassInfo *classInfo() const override
357  {
358  return &info;
359  }
360  static const ClassInfo info;
361  enum { PublicId, SystemId };
362 };
363 
364 class DOMEntity : public DOMNode
365 {
366 public:
367  DOMEntity(ExecState *exec, DOM::EntityImpl *e) : DOMNode(exec, e) { }
368  using KJS::JSObject::getOwnPropertySlot;
369  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
370  JSValue *getValueProperty(ExecState *exec, int token) const;
371  // no put - all read-only
372  const ClassInfo *classInfo() const override
373  {
374  return &info;
375  }
376  static const ClassInfo info;
377  enum { PublicId, SystemId, NotationName };
378 };
379 
380 DEFINE_PSEUDO_CONSTRUCTOR(DOMExceptionPseudoCtor)
381 
382 class JSDOMException : public DOMObject
383 {
384 public:
385  JSDOMException(ExecState *exec);
386  const ClassInfo *classInfo() const override
387  {
388  return &info;
389  }
390  static const ClassInfo info;
391 };
392 
393 bool checkNodeSecurity(ExecState *exec, const DOM::NodeImpl *n);
394 JSValue *getEventTarget(ExecState *exec, DOM::EventTargetImpl *t);
395 JSValue *getDOMNode(ExecState *exec, DOM::NodeImpl *n);
396 JSValue *getDOMNamedNodeMap(ExecState *exec, DOM::NamedNodeMapImpl *m);
397 JSValue *getDOMNodeList(ExecState *exec, DOM::NodeListImpl *l);
398 JSValue *getDOMDOMImplementation(ExecState *exec, DOM::DOMImplementationImpl *i);
399 JSObject *getDOMExceptionConstructor(ExecState *exec);
400 
401 // Internal class, used for the collection return by e.g. document.forms.myinput
402 // when multiple nodes have the same name.
403 class DOMNamedNodesCollection : public DOMObject
404 {
405 public:
406  DOMNamedNodesCollection(ExecState *exec, const QList<SharedPtr<DOM::NodeImpl> > &nodes);
407  using KJS::JSObject::getOwnPropertySlot;
408  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
409  const ClassInfo *classInfo() const override
410  {
411  return &info;
412  }
413  static const ClassInfo info;
414  const QList<SharedPtr<DOM::NodeImpl> > nodes() const
415  {
416  return m_nodes;
417  }
418  enum { Length };
419 
420  JSValue *indexGetter(ExecState *exec, unsigned index);
421 private:
422  static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &slot);
424 };
425 
426 class DOMCharacterData : public DOMNode
427 {
428 public:
429  // Build a DOMCharacterData
430  DOMCharacterData(ExecState *exec, DOM::CharacterDataImpl *d);
431  using KJS::JSObject::getOwnPropertySlot;
432  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
433  JSValue *getValueProperty(ExecState *, int token) const;
434  using KJS::JSObject::put;
435  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
436  const ClassInfo *classInfo() const override
437  {
438  return &info;
439  }
440  static const ClassInfo info;
441  DOM::CharacterDataImpl *impl() const
442  {
443  return static_cast<DOM::CharacterDataImpl *>(m_impl.get());
444  }
445  enum { Data, Length,
446  SubstringData, AppendData, InsertData, DeleteData, ReplaceData
447  };
448 };
449 
450 class DOMText : public DOMCharacterData
451 {
452 public:
453  DOMText(ExecState *exec, DOM::TextImpl *t);
454  using KJS::JSObject::getOwnPropertySlot;
455  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
456  JSValue *getValueProperty(ExecState *exec, int token) const;
457  const ClassInfo *classInfo() const override
458  {
459  return &info;
460  }
461  static const ClassInfo info;
462  DOM::TextImpl *impl() const
463  {
464  return static_cast<DOM::TextImpl *>(m_impl.get());
465  }
466  enum { SplitText, WholeText, ReplaceWholeText };
467 };
468 
469 class DOMComment : public DOMCharacterData
470 {
471 public:
472  DOMComment(ExecState *exec, DOM::CommentImpl *t);
473  const ClassInfo *classInfo() const override
474  {
475  return &info;
476  }
477  static const ClassInfo info;
478  DOM::CommentImpl *impl() const
479  {
480  return static_cast<DOM::CommentImpl *>(m_impl.get());
481  }
482 };
483 
484 } // namespace
485 
486 #endif
KIOCORE_EXPORT TransferJob * put(const QUrl &url, int permissions, JobFlags flags=DefaultFlags)
char * toString(const T &value)
Title
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.