OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 * | 21 * |
22 */ | 22 */ |
23 | 23 |
24 #ifndef Node_h | 24 #ifndef Node_h |
25 #define Node_h | 25 #define Node_h |
26 | 26 |
27 #include "DocPtr.h" | 27 #include "DocPtr.h" |
| 28 #include "EventTarget.h" |
28 #include "KURLHash.h" | 29 #include "KURLHash.h" |
29 #include "PlatformString.h" | 30 #include "PlatformString.h" |
30 #include "TreeShared.h" | 31 #include "TreeShared.h" |
31 #include <wtf/Assertions.h> | 32 #include <wtf/Assertions.h> |
32 #include <wtf/ListHashSet.h> | 33 #include <wtf/ListHashSet.h> |
33 #include <wtf/OwnPtr.h> | 34 #include <wtf/OwnPtr.h> |
34 #include <wtf/PassRefPtr.h> | 35 #include <wtf/PassRefPtr.h> |
35 | 36 |
36 namespace WebCore { | 37 namespace WebCore { |
37 | 38 |
38 class AtomicString; | 39 class AtomicString; |
| 40 class Attribute; |
39 class ContainerNode; | 41 class ContainerNode; |
40 class Document; | 42 class Document; |
41 class DynamicNodeList; | 43 class DynamicNodeList; |
42 class Element; | 44 class Element; |
43 class Event; | 45 class Event; |
44 class EventListener; | 46 class EventListener; |
| 47 class Frame; |
45 class IntRect; | 48 class IntRect; |
46 class KeyboardEvent; | 49 class KeyboardEvent; |
47 class NSResolver; | 50 class NSResolver; |
48 class NamedAttrMap; | 51 class NamedAttrMap; |
49 class NodeList; | 52 class NodeList; |
50 class NodeRareData; | 53 class NodeRareData; |
51 class PlatformKeyboardEvent; | 54 class PlatformKeyboardEvent; |
52 class PlatformMouseEvent; | 55 class PlatformMouseEvent; |
53 class PlatformWheelEvent; | 56 class PlatformWheelEvent; |
54 class QualifiedName; | 57 class QualifiedName; |
| 58 class RegisteredEventListener; |
55 class RenderArena; | 59 class RenderArena; |
56 class RenderBox; | 60 class RenderBox; |
57 class RenderObject; | 61 class RenderObject; |
58 class RenderStyle; | 62 class RenderStyle; |
59 class StringBuilder; | 63 class StringBuilder; |
60 | 64 |
61 typedef int ExceptionCode; | 65 typedef int ExceptionCode; |
62 | 66 |
| 67 typedef Vector<RefPtr<RegisteredEventListener> > RegisteredEventListenerVector; |
| 68 |
63 enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange, Animat
ionStyleChange }; | 69 enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange, Animat
ionStyleChange }; |
64 | 70 |
65 const unsigned short DOCUMENT_POSITION_EQUIVALENT = 0x00; | 71 const unsigned short DOCUMENT_POSITION_EQUIVALENT = 0x00; |
66 const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; | 72 const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; |
67 const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; | 73 const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; |
68 const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; | 74 const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; |
69 const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; | 75 const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; |
70 const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; | 76 const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; |
71 const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; | 77 const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; |
72 | 78 |
73 // this class implements nodes, which can have a parent but no children: | 79 // this class implements nodes, which can have a parent but no children: |
74 class Node : public TreeShared<Node> { | 80 class Node : public EventTarget, public TreeShared<Node> { |
75 friend class Document; | 81 friend class Document; |
76 public: | 82 public: |
77 enum NodeType { | 83 enum NodeType { |
78 ELEMENT_NODE = 1, | 84 ELEMENT_NODE = 1, |
79 ATTRIBUTE_NODE = 2, | 85 ATTRIBUTE_NODE = 2, |
80 TEXT_NODE = 3, | 86 TEXT_NODE = 3, |
81 CDATA_SECTION_NODE = 4, | 87 CDATA_SECTION_NODE = 4, |
82 ENTITY_REFERENCE_NODE = 5, | 88 ENTITY_REFERENCE_NODE = 5, |
83 ENTITY_NODE = 6, | 89 ENTITY_NODE = 6, |
84 PROCESSING_INSTRUCTION_NODE = 7, | 90 PROCESSING_INSTRUCTION_NODE = 7, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 #else | 179 #else |
174 static bool isWMLElement() { return false; } | 180 static bool isWMLElement() { return false; } |
175 #endif | 181 #endif |
176 | 182 |
177 virtual bool isStyledElement() const { return false; } | 183 virtual bool isStyledElement() const { return false; } |
178 virtual bool isFrameOwnerElement() const { return false; } | 184 virtual bool isFrameOwnerElement() const { return false; } |
179 virtual bool isAttributeNode() const { return false; } | 185 virtual bool isAttributeNode() const { return false; } |
180 virtual bool isCommentNode() const { return false; } | 186 virtual bool isCommentNode() const { return false; } |
181 virtual bool isCharacterDataNode() const { return false; } | 187 virtual bool isCharacterDataNode() const { return false; } |
182 bool isDocumentNode() const; | 188 bool isDocumentNode() const; |
183 virtual bool isEventTargetNode() const { return false; } | |
184 virtual bool isShadowNode() const { return false; } | 189 virtual bool isShadowNode() const { return false; } |
185 virtual Node* shadowParentNode() { return 0; } | 190 virtual Node* shadowParentNode() { return 0; } |
186 Node* shadowAncestorNode(); | 191 Node* shadowAncestorNode(); |
187 Node* shadowTreeRootNode(); | 192 Node* shadowTreeRootNode(); |
188 bool isInShadowTree(); | 193 bool isInShadowTree(); |
189 | 194 |
190 // The node's parent for the purpose of event capture and bubbling. | 195 // The node's parent for the purpose of event capture and bubbling. |
191 virtual ContainerNode* eventParentNode(); | 196 virtual ContainerNode* eventParentNode(); |
192 | 197 |
193 bool isBlockFlow() const; | 198 bool isBlockFlow() const; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI
, const String& localName); | 487 PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI
, const String& localName); |
483 PassRefPtr<NodeList> getElementsByName(const String& elementName); | 488 PassRefPtr<NodeList> getElementsByName(const String& elementName); |
484 PassRefPtr<NodeList> getElementsByClassName(const String& classNames); | 489 PassRefPtr<NodeList> getElementsByClassName(const String& classNames); |
485 | 490 |
486 PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&); | 491 PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&); |
487 PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode
&); | 492 PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode
&); |
488 | 493 |
489 unsigned short compareDocumentPosition(Node*); | 494 unsigned short compareDocumentPosition(Node*); |
490 | 495 |
491 protected: | 496 protected: |
492 virtual void willMoveToNewOwnerDocument() { } | 497 virtual void willMoveToNewOwnerDocument(); |
493 virtual void didMoveToNewOwnerDocument() { } | 498 virtual void didMoveToNewOwnerDocument(); |
494 | 499 |
495 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { } | 500 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { } |
496 void setTabIndexExplicitly(short); | 501 void setTabIndexExplicitly(short); |
497 | 502 |
498 bool hasRareData() const { return m_hasRareData; } | 503 bool hasRareData() const { return m_hasRareData; } |
499 | 504 |
500 NodeRareData* rareData() const; | 505 NodeRareData* rareData() const; |
501 NodeRareData* ensureRareData(); | 506 NodeRareData* ensureRareData(); |
502 | 507 |
| 508 public: |
| 509 virtual Node* toNode() { return this; } |
| 510 |
| 511 virtual ScriptExecutionContext* scriptExecutionContext() const; |
| 512 |
| 513 virtual void addEventListener(const AtomicString& eventType, PassRefPtr<Even
tListener>, bool useCapture); |
| 514 virtual void removeEventListener(const AtomicString& eventType, EventListene
r*, bool useCapture); |
| 515 virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); |
| 516 void removeAllEventListeners() { if (hasRareData()) removeAllEventListenersS
lowCase(); } |
| 517 |
| 518 void setInlineEventListenerForType(const AtomicString& eventType, PassRefPtr
<EventListener>); |
| 519 void setInlineEventListenerForTypeAndAttribute(const AtomicString& eventType
, Attribute*); |
| 520 void removeInlineEventListenerForType(const AtomicString& eventType); |
| 521 bool dispatchEventForType(const AtomicString& eventType, bool canBubble, boo
l cancelable); |
| 522 EventListener* inlineEventListenerForType(const AtomicString& eventType) con
st; |
| 523 |
| 524 bool dispatchSubtreeModifiedEvent(); |
| 525 void dispatchWindowEvent(PassRefPtr<Event>); |
| 526 void dispatchWindowEvent(const AtomicString& eventType, bool canBubble, bool
cancelable); |
| 527 bool dispatchUIEvent(const AtomicString& eventType, int detail = 0, PassRefP
tr<Event> underlyingEvent = 0); |
| 528 bool dispatchKeyEvent(const PlatformKeyboardEvent&); |
| 529 void dispatchWheelEvent(PlatformWheelEvent&); |
| 530 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& event
Type, |
| 531 int clickCount = 0, Node* relatedTarget = 0); |
| 532 bool dispatchMouseEvent(const AtomicString& eventType, int button, int click
Count, |
| 533 int pageX, int pageY, int screenX, int screenY, |
| 534 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
| 535 bool isSimulated = false, Node* relatedTarget = 0, PassRefPtr<Event> und
erlyingEvent = 0); |
| 536 void dispatchSimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<E
vent> underlyingEvent = 0); |
| 537 void dispatchSimulatedClick(PassRefPtr<Event> underlyingEvent, bool sendMous
eEvents = false, bool showPressedLook = true); |
| 538 bool dispatchProgressEvent(const AtomicString &eventType, bool lengthComputa
bleArg, unsigned loadedArg, unsigned totalArg); |
| 539 void dispatchStorageEvent(const AtomicString &eventType, const String& key,
const String& oldValue, const String& newValue, Frame* source); |
| 540 bool dispatchWebKitAnimationEvent(const AtomicString& eventType, const Strin
g& animationName, double elapsedTime); |
| 541 bool dispatchWebKitTransitionEvent(const AtomicString& eventType, const Stri
ng& propertyName, double elapsedTime); |
| 542 bool dispatchGenericEvent(PassRefPtr<Event>); |
| 543 |
| 544 virtual void handleLocalEvents(Event*, bool useCapture); |
| 545 |
| 546 virtual void dispatchFocusEvent(); |
| 547 virtual void dispatchBlurEvent(); |
| 548 |
| 549 /** |
| 550 * Perform the default action for an event e.g. submitting a form |
| 551 */ |
| 552 virtual void defaultEventHandler(Event*); |
| 553 |
| 554 /** |
| 555 * Used for disabled form elements; if true, prevents mouse events from bein
g dispatched |
| 556 * to event listeners, and prevents DOMActivate events from being sent at al
l. |
| 557 */ |
| 558 virtual bool disabled() const; |
| 559 |
| 560 const RegisteredEventListenerVector& eventListeners() const; |
| 561 |
| 562 EventListener* onabort() const; |
| 563 void setOnabort(PassRefPtr<EventListener>); |
| 564 EventListener* onblur() const; |
| 565 void setOnblur(PassRefPtr<EventListener>); |
| 566 EventListener* onchange() const; |
| 567 void setOnchange(PassRefPtr<EventListener>); |
| 568 EventListener* onclick() const; |
| 569 void setOnclick(PassRefPtr<EventListener>); |
| 570 EventListener* oncontextmenu() const; |
| 571 void setOncontextmenu(PassRefPtr<EventListener>); |
| 572 EventListener* ondblclick() const; |
| 573 void setOndblclick(PassRefPtr<EventListener>); |
| 574 EventListener* onerror() const; |
| 575 void setOnerror(PassRefPtr<EventListener>); |
| 576 EventListener* onfocus() const; |
| 577 void setOnfocus(PassRefPtr<EventListener>); |
| 578 EventListener* oninput() const; |
| 579 void setOninput(PassRefPtr<EventListener>); |
| 580 EventListener* onkeydown() const; |
| 581 void setOnkeydown(PassRefPtr<EventListener>); |
| 582 EventListener* onkeypress() const; |
| 583 void setOnkeypress(PassRefPtr<EventListener>); |
| 584 EventListener* onkeyup() const; |
| 585 void setOnkeyup(PassRefPtr<EventListener>); |
| 586 EventListener* onload() const; |
| 587 void setOnload(PassRefPtr<EventListener>); |
| 588 EventListener* onmousedown() const; |
| 589 void setOnmousedown(PassRefPtr<EventListener>); |
| 590 EventListener* onmousemove() const; |
| 591 void setOnmousemove(PassRefPtr<EventListener>); |
| 592 EventListener* onmouseout() const; |
| 593 void setOnmouseout(PassRefPtr<EventListener>); |
| 594 EventListener* onmouseover() const; |
| 595 void setOnmouseover(PassRefPtr<EventListener>); |
| 596 EventListener* onmouseup() const; |
| 597 void setOnmouseup(PassRefPtr<EventListener>); |
| 598 EventListener* onmousewheel() const; |
| 599 void setOnmousewheel(PassRefPtr<EventListener>); |
| 600 EventListener* onbeforecut() const; |
| 601 void setOnbeforecut(PassRefPtr<EventListener>); |
| 602 EventListener* oncut() const; |
| 603 void setOncut(PassRefPtr<EventListener>); |
| 604 EventListener* onbeforecopy() const; |
| 605 void setOnbeforecopy(PassRefPtr<EventListener>); |
| 606 EventListener* oncopy() const; |
| 607 void setOncopy(PassRefPtr<EventListener>); |
| 608 EventListener* onbeforepaste() const; |
| 609 void setOnbeforepaste(PassRefPtr<EventListener>); |
| 610 EventListener* onpaste() const; |
| 611 void setOnpaste(PassRefPtr<EventListener>); |
| 612 EventListener* ondragenter() const; |
| 613 void setOndragenter(PassRefPtr<EventListener>); |
| 614 EventListener* ondragover() const; |
| 615 void setOndragover(PassRefPtr<EventListener>); |
| 616 EventListener* ondragleave() const; |
| 617 void setOndragleave(PassRefPtr<EventListener>); |
| 618 EventListener* ondrop() const; |
| 619 void setOndrop(PassRefPtr<EventListener>); |
| 620 EventListener* ondragstart() const; |
| 621 void setOndragstart(PassRefPtr<EventListener>); |
| 622 EventListener* ondrag() const; |
| 623 void setOndrag(PassRefPtr<EventListener>); |
| 624 EventListener* ondragend() const; |
| 625 void setOndragend(PassRefPtr<EventListener>); |
| 626 EventListener* onreset() const; |
| 627 void setOnreset(PassRefPtr<EventListener>); |
| 628 EventListener* onresize() const; |
| 629 void setOnresize(PassRefPtr<EventListener>); |
| 630 EventListener* onscroll() const; |
| 631 void setOnscroll(PassRefPtr<EventListener>); |
| 632 EventListener* onsearch() const; |
| 633 void setOnsearch(PassRefPtr<EventListener>); |
| 634 EventListener* onselect() const; |
| 635 void setOnselect(PassRefPtr<EventListener>); |
| 636 EventListener* onselectstart() const; |
| 637 void setOnselectstart(PassRefPtr<EventListener>); |
| 638 EventListener* onsubmit() const; |
| 639 void setOnsubmit(PassRefPtr<EventListener>); |
| 640 EventListener* onunload() const; |
| 641 void setOnunload(PassRefPtr<EventListener>); |
| 642 |
| 643 using TreeShared<Node>::ref; |
| 644 using TreeShared<Node>::deref; |
| 645 |
| 646 private: |
| 647 virtual void refEventTarget() { ref(); } |
| 648 virtual void derefEventTarget() { deref(); } |
| 649 |
| 650 void removeAllEventListenersSlowCase(); |
| 651 |
503 private: | 652 private: |
504 virtual NodeRareData* createRareData(); | 653 virtual NodeRareData* createRareData(); |
505 Node* containerChildNode(unsigned index) const; | 654 Node* containerChildNode(unsigned index) const; |
506 unsigned containerChildNodeCount() const; | 655 unsigned containerChildNodeCount() const; |
507 Node* containerFirstChild() const; | 656 Node* containerFirstChild() const; |
508 Node* containerLastChild() const; | 657 Node* containerLastChild() const; |
509 bool rareDataFocused() const; | 658 bool rareDataFocused() const; |
510 | 659 |
511 virtual RenderStyle* nonRendererRenderStyle() const; | 660 virtual RenderStyle* nonRendererRenderStyle() const; |
512 | 661 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 720 |
572 } //namespace | 721 } //namespace |
573 | 722 |
574 #ifndef NDEBUG | 723 #ifndef NDEBUG |
575 // Outside the WebCore namespace for ease of invocation from gdb. | 724 // Outside the WebCore namespace for ease of invocation from gdb. |
576 void showTree(const WebCore::Node*); | 725 void showTree(const WebCore::Node*); |
577 #endif | 726 #endif |
578 | 727 |
579 #endif | 728 #endif |
580 | 729 |
OLD | NEW |