OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 17 matching lines...) Expand all Loading... |
28 #define EventContext_h | 28 #define EventContext_h |
29 | 29 |
30 #include "EventTarget.h" | 30 #include "EventTarget.h" |
31 #include "Node.h" | 31 #include "Node.h" |
32 #include "TreeScope.h" | 32 #include "TreeScope.h" |
33 #include <wtf/RefPtr.h> | 33 #include <wtf/RefPtr.h> |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
37 class Event; | 37 class Event; |
| 38 #if ENABLE(TOUCH_EVENTS) |
38 class TouchList; | 39 class TouchList; |
| 40 #endif |
39 | 41 |
40 class EventContext { | 42 class EventContext { |
41 public: | 43 public: |
42 // FIXME: Use ContainerNode instead of Node. | 44 // FIXME: Use ContainerNode instead of Node. |
43 EventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, PassRe
fPtr<EventTarget> target); | 45 EventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, PassRe
fPtr<EventTarget> target); |
44 virtual ~EventContext(); | 46 virtual ~EventContext(); |
45 | 47 |
46 Node* node() const { return m_node.get(); } | 48 Node* node() const { return m_node.get(); } |
47 EventTarget* target() const { return m_target.get(); } | 49 EventTarget* target() const { return m_target.get(); } |
48 bool currentTargetSameAsTarget() const { return m_currentTarget.get() == m_t
arget.get(); } | 50 bool currentTargetSameAsTarget() const { return m_currentTarget.get() == m_t
arget.get(); } |
(...skipping 20 matching lines...) Expand all Loading... |
69 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } | 71 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } |
70 void setRelatedTarget(PassRefPtr<EventTarget>); | 72 void setRelatedTarget(PassRefPtr<EventTarget>); |
71 virtual void handleLocalEvents(Event*) const OVERRIDE; | 73 virtual void handleLocalEvents(Event*) const OVERRIDE; |
72 virtual bool isMouseOrFocusEventContext() const OVERRIDE; | 74 virtual bool isMouseOrFocusEventContext() const OVERRIDE; |
73 | 75 |
74 private: | 76 private: |
75 RefPtr<EventTarget> m_relatedTarget; | 77 RefPtr<EventTarget> m_relatedTarget; |
76 }; | 78 }; |
77 | 79 |
78 | 80 |
| 81 #if ENABLE(TOUCH_EVENTS) |
79 class TouchEventContext : public EventContext { | 82 class TouchEventContext : public EventContext { |
80 public: | 83 public: |
81 TouchEventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, P
assRefPtr<EventTarget> target); | 84 TouchEventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, P
assRefPtr<EventTarget> target); |
82 virtual ~TouchEventContext(); | 85 virtual ~TouchEventContext(); |
83 | 86 |
84 virtual void handleLocalEvents(Event*) const OVERRIDE; | 87 virtual void handleLocalEvents(Event*) const OVERRIDE; |
85 virtual bool isTouchEventContext() const OVERRIDE; | 88 virtual bool isTouchEventContext() const OVERRIDE; |
86 | 89 |
87 TouchList* touches() { return m_touches.get(); } | 90 TouchList* touches() { return m_touches.get(); } |
88 TouchList* targetTouches() { return m_targetTouches.get(); } | 91 TouchList* targetTouches() { return m_targetTouches.get(); } |
89 TouchList* changedTouches() { return m_changedTouches.get(); } | 92 TouchList* changedTouches() { return m_changedTouches.get(); } |
90 | 93 |
91 private: | 94 private: |
92 RefPtr<TouchList> m_touches; | 95 RefPtr<TouchList> m_touches; |
93 RefPtr<TouchList> m_targetTouches; | 96 RefPtr<TouchList> m_targetTouches; |
94 RefPtr<TouchList> m_changedTouches; | 97 RefPtr<TouchList> m_changedTouches; |
95 #ifndef NDEBUG | 98 #ifndef NDEBUG |
96 void checkReachability(TouchList*) const; | 99 void checkReachability(TouchList*) const; |
97 #endif | 100 #endif |
98 }; | 101 }; |
99 | 102 |
100 inline TouchEventContext* toTouchEventContext(EventContext* eventContext) | 103 inline TouchEventContext* toTouchEventContext(EventContext* eventContext) |
101 { | 104 { |
102 ASSERT_WITH_SECURITY_IMPLICATION(!eventContext || eventContext->isTouchEvent
Context()); | 105 ASSERT_WITH_SECURITY_IMPLICATION(!eventContext || eventContext->isTouchEvent
Context()); |
103 return static_cast<TouchEventContext*>(eventContext); | 106 return static_cast<TouchEventContext*>(eventContext); |
104 } | 107 } |
| 108 #endif // ENABLE(TOUCH_EVENTS) |
105 | 109 |
106 #ifndef NDEBUG | 110 #ifndef NDEBUG |
107 inline bool EventContext::isUnreachableNode(EventTarget* target) | 111 inline bool EventContext::isUnreachableNode(EventTarget* target) |
108 { | 112 { |
109 // FIXME: Checks also for SVG elements. | 113 // FIXME: Checks also for SVG elements. |
110 return target && target->toNode() && !target->toNode()->isSVGElement() && !i
sReachable(target->toNode()); | 114 return target && target->toNode() && !target->toNode()->isSVGElement() && !i
sReachable(target->toNode()); |
111 } | 115 } |
112 | 116 |
113 inline bool EventContext::isReachable(Node* target) const | 117 inline bool EventContext::isReachable(Node* target) const |
114 { | 118 { |
115 ASSERT(target); | 119 ASSERT(target); |
116 TreeScope* targetScope = target->treeScope(); | 120 TreeScope* targetScope = target->treeScope(); |
117 for (TreeScope* scope = m_node->treeScope(); scope; scope = scope->parentTre
eScope()) { | 121 for (TreeScope* scope = m_node->treeScope(); scope; scope = scope->parentTre
eScope()) { |
118 if (scope == targetScope) | 122 if (scope == targetScope) |
119 return true; | 123 return true; |
120 } | 124 } |
121 return false; | 125 return false; |
122 } | 126 } |
123 #endif | 127 #endif |
124 | 128 |
125 inline void MouseOrFocusEventContext::setRelatedTarget(PassRefPtr<EventTarget> r
elatedTarget) | 129 inline void MouseOrFocusEventContext::setRelatedTarget(PassRefPtr<EventTarget> r
elatedTarget) |
126 { | 130 { |
127 ASSERT(!isUnreachableNode(relatedTarget.get())); | 131 ASSERT(!isUnreachableNode(relatedTarget.get())); |
128 m_relatedTarget = relatedTarget; | 132 m_relatedTarget = relatedTarget; |
129 } | 133 } |
130 | 134 |
131 } | 135 } |
132 | 136 |
133 #endif // EventContext_h | 137 #endif // EventContext_h |
OLD | NEW |