OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) | 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) | 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
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 MouseEvent_h | 24 #ifndef MouseEvent_h |
25 #define MouseEvent_h | 25 #define MouseEvent_h |
26 | 26 |
27 #include "core/CoreExport.h" | 27 #include "core/CoreExport.h" |
28 #include "core/events/EventDispatchMediator.h" | 28 #include "core/events/EventDispatchMediator.h" |
29 #include "core/events/MouseEventInit.h" | 29 #include "core/events/MouseEventInit.h" |
30 #include "core/events/MouseRelatedEvent.h" | 30 #include "core/events/UIEventWithKeyState.h" |
31 #include "platform/PlatformMouseEvent.h" | 31 #include "platform/PlatformMouseEvent.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 class DataTransfer; | 34 class DataTransfer; |
35 class EventDispatcher; | 35 class EventDispatcher; |
36 | 36 |
37 class CORE_EXPORT MouseEvent : public MouseRelatedEvent { | 37 class CORE_EXPORT MouseEvent : public UIEventWithKeyState { |
38 DEFINE_WRAPPERTYPEINFO(); | 38 DEFINE_WRAPPERTYPEINFO(); |
39 | 39 |
40 public: | 40 public: |
41 static MouseEvent* create() { return new MouseEvent; } | 41 static MouseEvent* create() { return new MouseEvent; } |
42 | 42 |
43 // TODO(mustaq): Should replace most/all of these params with a | 43 // TODO(mustaq): Should replace most/all of these params with a |
44 // MouseEventInit. | 44 // MouseEventInit. |
45 static MouseEvent* create(const AtomicString& type, | 45 static MouseEvent* create(const AtomicString& type, |
46 bool canBubble, | 46 bool canBubble, |
47 bool cancelable, | 47 bool cancelable, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 bool isMouseEvent() const override; | 128 bool isMouseEvent() const override; |
129 int which() const final; | 129 int which() const final; |
130 | 130 |
131 EventDispatchMediator* createMediator() override; | 131 EventDispatchMediator* createMediator() override; |
132 | 132 |
133 int clickCount() { return detail(); } | 133 int clickCount() { return detail(); } |
134 | 134 |
135 const PlatformMouseEvent* mouseEvent() const { return m_mouseEvent.get(); } | 135 const PlatformMouseEvent* mouseEvent() const { return m_mouseEvent.get(); } |
136 | 136 |
| 137 enum class PositionType { |
| 138 Position, |
| 139 // Positionless mouse events are used, for example, for 'click' events from |
| 140 // keyboard input. It's kind of surprising for a mouse event not to have a |
| 141 // position. |
| 142 Positionless |
| 143 }; |
| 144 |
| 145 // Note that these values are adjusted to counter the effects of zoom, so that |
| 146 // values exposed via DOM APIs are invariant under zooming. |
| 147 // TODO(mustaq): Remove the PointerEvent specific code when mouse has |
| 148 // fractional coordinates. See crbug.com/655786. |
| 149 double screenX() const { |
| 150 return isPointerEvent() ? m_screenLocation.x() |
| 151 : static_cast<int>(m_screenLocation.x()); |
| 152 } |
| 153 double screenY() const { |
| 154 return isPointerEvent() ? m_screenLocation.y() |
| 155 : static_cast<int>(m_screenLocation.y()); |
| 156 } |
| 157 |
| 158 double clientX() const { |
| 159 return isPointerEvent() ? m_clientLocation.x() |
| 160 : static_cast<int>(m_clientLocation.x()); |
| 161 } |
| 162 double clientY() const { |
| 163 return isPointerEvent() ? m_clientLocation.y() |
| 164 : static_cast<int>(m_clientLocation.y()); |
| 165 } |
| 166 |
| 167 int movementX() const { return m_movementDelta.x(); } |
| 168 int movementY() const { return m_movementDelta.y(); } |
| 169 |
| 170 int layerX(); |
| 171 int layerY(); |
| 172 |
| 173 int offsetX(); |
| 174 int offsetY(); |
| 175 |
| 176 double pageX() const { |
| 177 return isPointerEvent() ? m_pageLocation.x() |
| 178 : static_cast<int>(m_pageLocation.x()); |
| 179 } |
| 180 double pageY() const { |
| 181 return isPointerEvent() ? m_pageLocation.y() |
| 182 : static_cast<int>(m_pageLocation.y()); |
| 183 } |
| 184 |
| 185 double x() const { return clientX(); } |
| 186 double y() const { return clientY(); } |
| 187 |
| 188 bool hasPosition() const { return m_positionType == PositionType::Position; } |
| 189 |
| 190 // Page point in "absolute" coordinates (i.e. post-zoomed, page-relative |
| 191 // coords, usable with LayoutObject::absoluteToLocal) relative to view(), i.e. |
| 192 // the local frame. |
| 193 const DoublePoint& absoluteLocation() const { return m_absoluteLocation; } |
| 194 |
137 DECLARE_VIRTUAL_TRACE(); | 195 DECLARE_VIRTUAL_TRACE(); |
138 | 196 |
139 protected: | 197 protected: |
140 MouseEvent(const AtomicString& type, | 198 MouseEvent(const AtomicString& type, |
141 bool canBubble, | 199 bool canBubble, |
142 bool cancelable, | 200 bool cancelable, |
143 AbstractView*, | 201 AbstractView*, |
144 int detail, | 202 int detail, |
145 int screenX, | 203 int screenX, |
146 int screenY, | 204 int screenY, |
(...skipping 26 matching lines...) Expand all Loading... |
173 int screenX, | 231 int screenX, |
174 int screenY, | 232 int screenY, |
175 int clientX, | 233 int clientX, |
176 int clientY, | 234 int clientY, |
177 PlatformEvent::Modifiers, | 235 PlatformEvent::Modifiers, |
178 short button, | 236 short button, |
179 EventTarget* relatedTarget, | 237 EventTarget* relatedTarget, |
180 InputDeviceCapabilities* sourceCapabilities, | 238 InputDeviceCapabilities* sourceCapabilities, |
181 unsigned short buttons = 0); | 239 unsigned short buttons = 0); |
182 | 240 |
| 241 void initCoordinates(const double clientX, const double clientY); |
| 242 void receivedTarget() final; |
| 243 |
| 244 void computePageLocation(); |
| 245 void computeRelativePosition(); |
| 246 |
| 247 DoublePoint m_screenLocation; |
| 248 DoublePoint m_clientLocation; |
| 249 DoublePoint m_movementDelta; |
| 250 |
| 251 DoublePoint m_pageLocation; |
| 252 DoublePoint m_layerLocation; |
| 253 DoublePoint m_offsetLocation; |
| 254 DoublePoint m_absoluteLocation; |
| 255 PositionType m_positionType; |
| 256 bool m_hasCachedRelativePosition; |
183 short m_button; | 257 short m_button; |
184 unsigned short m_buttons; | 258 unsigned short m_buttons; |
185 Member<EventTarget> m_relatedTarget; | 259 Member<EventTarget> m_relatedTarget; |
186 PlatformMouseEvent::SyntheticEventType m_syntheticEventType; | 260 PlatformMouseEvent::SyntheticEventType m_syntheticEventType; |
187 String m_region; | 261 String m_region; |
188 std::unique_ptr<PlatformMouseEvent> m_mouseEvent; | 262 std::unique_ptr<PlatformMouseEvent> m_mouseEvent; |
189 }; | 263 }; |
190 | 264 |
191 class MouseEventDispatchMediator final : public EventDispatchMediator { | 265 class MouseEventDispatchMediator final : public EventDispatchMediator { |
192 public: | 266 public: |
193 static MouseEventDispatchMediator* create(MouseEvent*); | 267 static MouseEventDispatchMediator* create(MouseEvent*); |
194 | 268 |
195 private: | 269 private: |
196 explicit MouseEventDispatchMediator(MouseEvent*); | 270 explicit MouseEventDispatchMediator(MouseEvent*); |
197 MouseEvent& event() const; | 271 MouseEvent& event() const; |
198 | 272 |
199 DispatchEventResult dispatchEvent(EventDispatcher&) const override; | 273 DispatchEventResult dispatchEvent(EventDispatcher&) const override; |
200 }; | 274 }; |
201 | 275 |
202 DEFINE_EVENT_TYPE_CASTS(MouseEvent); | 276 DEFINE_EVENT_TYPE_CASTS(MouseEvent); |
203 | 277 |
204 } // namespace blink | 278 } // namespace blink |
205 | 279 |
206 #endif // MouseEvent_h | 280 #endif // MouseEvent_h |
OLD | NEW |