OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public License | |
15 * along with this library; see the file COPYING.LIB. If not, write to | |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 * Boston, MA 02110-1301, USA. | |
18 */ | |
19 | |
20 #ifndef EventRetargeter_h | |
21 #define EventRetargeter_h | |
22 | |
23 #include "SVGNames.h" | |
24 #include "core/dom/ContainerNode.h" | |
25 #include "core/events/EventContext.h" | |
26 #include "core/dom/shadow/ShadowRoot.h" | |
27 #include "core/svg/SVGElementInstance.h" | |
28 #include "core/svg/SVGUseElement.h" | |
29 #include "wtf/HashMap.h" | |
30 #include "wtf/RefPtr.h" | |
31 | |
32 namespace WebCore { | |
33 | |
34 class EventTarget; | |
35 class FocusEvent; | |
36 class MouseEvent; | |
37 class Node; | |
38 class TouchEvent; | |
39 class TreeScope; | |
40 | |
41 enum EventDispatchBehavior { | |
42 RetargetEvent, | |
43 StayInsideShadowDOM | |
44 }; | |
45 | |
46 class EventRetargeter { | |
47 public: | |
48 static void ensureEventPath(Node*, Event*); | |
49 static void adjustForMouseEvent(Node*, MouseEvent&); | |
50 static void adjustForFocusEvent(Node*, FocusEvent&); | |
51 typedef Vector<RefPtr<TouchList> > EventPathTouchLists; | |
52 static void adjustForTouchEvent(Node*, TouchEvent&); | |
53 static EventTarget* eventTargetRespectingTargetRules(Node* referenceNode); | |
54 | |
55 private: | |
56 typedef Vector<RefPtr<Node> > AdjustedNodes; | |
57 typedef HashMap<TreeScope*, Node*> RelatedNodeMap; | |
58 enum EventWithRelatedTargetDispatchBehavior { | |
59 StopAtBoundaryIfNeeded, | |
60 DoesNotStopAtBoundary | |
61 }; | |
62 static void calculateEventPath(Node*, Event*); | |
63 static void calculateAdjustedEventPathForEachNode(EventPath&); | |
64 | |
65 static void adjustForRelatedTarget(const Node*, EventTarget* relatedTarget,
EventPath&); | |
66 static void calculateAdjustedNodes(const Node*, const Node* relatedNode, Eve
ntWithRelatedTargetDispatchBehavior, EventPath&, AdjustedNodes&); | |
67 static void buildRelatedNodeMap(const Node*, RelatedNodeMap&); | |
68 static Node* findRelatedNode(TreeScope*, RelatedNodeMap&); | |
69 static void adjustTouchList(const Node*, const TouchList*, const EventPath&,
EventPathTouchLists&); | |
70 }; | |
71 | |
72 inline EventTarget* EventRetargeter::eventTargetRespectingTargetRules(Node* refe
renceNode) | |
73 { | |
74 ASSERT(referenceNode); | |
75 | |
76 if (referenceNode->isPseudoElement()) | |
77 return referenceNode->parentNode(); | |
78 | |
79 if (!referenceNode->isSVGElement() || !referenceNode->isInShadowTree()) | |
80 return referenceNode; | |
81 | |
82 // Spec: The event handling for the non-exposed tree works as if the referen
ced element had been textually included | |
83 // as a deeply cloned child of the 'use' element, except that events are dis
patched to the SVGElementInstance objects. | |
84 Node* rootNode = referenceNode->treeScope().rootNode(); | |
85 Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNod
e)->host() : 0; | |
86 // At this time, SVG nodes are not supported in non-<use> shadow trees. | |
87 if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag)) | |
88 return referenceNode; | |
89 SVGUseElement* useElement = toSVGUseElement(shadowHostElement); | |
90 if (SVGElementInstance* instance = useElement->instanceForShadowTreeElement(
referenceNode)) | |
91 return instance; | |
92 | |
93 return referenceNode; | |
94 } | |
95 | |
96 } | |
97 | |
98 #endif // EventRetargeter_h | |
OLD | NEW |