OLD | NEW |
1 | 1 |
2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #ifndef UI_VIEWS_EVENTS_EVENT_H_ | 6 #ifndef UI_VIEWS_EVENTS_EVENT_H_ |
7 #define UI_VIEWS_EVENTS_EVENT_H_ | 7 #define UI_VIEWS_EVENTS_EVENT_H_ |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "ui/base/event.h" |
13 #include "ui/base/events.h" | 14 #include "ui/base/events.h" |
14 #include "ui/base/gestures/gesture_types.h" | 15 #include "ui/base/gestures/gesture_types.h" |
15 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
16 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
17 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 class Event; | 21 class Event; |
21 class OSExchangeData; | 22 class OSExchangeData; |
22 } | 23 } |
23 | 24 |
24 | 25 |
25 namespace views { | 26 namespace views { |
26 | 27 |
27 #if defined(USE_AURA) | |
28 typedef ui::Event* NativeEvent; | |
29 #else | |
30 typedef base::NativeEvent NativeEvent; | |
31 #endif | |
32 | |
33 class View; | 28 class View; |
34 | 29 |
35 namespace internal { | 30 namespace internal { |
36 class RootView; | 31 class RootView; |
37 } | 32 } |
38 | 33 |
39 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
40 // | 35 // |
41 // Event class | |
42 // | |
43 // An event encapsulates an input event that can be propagated into view | |
44 // hierarchies. An event has a type, some flags and a time stamp. | |
45 // | |
46 // Each major event type has a corresponding Event subclass. | |
47 // | |
48 // Events are immutable but support copy | |
49 // | |
50 //////////////////////////////////////////////////////////////////////////////// | |
51 class VIEWS_EXPORT Event { | |
52 public: | |
53 const NativeEvent& native_event() const { return native_event_; } | |
54 ui::EventType type() const { return type_; } | |
55 const base::Time& time_stamp() const { return time_stamp_; } | |
56 | |
57 // Required for Gesture testing purposes. | |
58 void set_time_stamp(base::Time time_stamp) { time_stamp_ = time_stamp; } | |
59 | |
60 int flags() const { return flags_; } | |
61 void set_flags(int flags) { flags_ = flags; } | |
62 | |
63 // The following methods return true if the respective keys were pressed at | |
64 // the time the event was created. | |
65 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; } | |
66 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; } | |
67 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; } | |
68 bool IsAltDown() const { return (flags_ & ui::EF_ALT_DOWN) != 0; } | |
69 | |
70 bool IsMouseEvent() const { | |
71 return type_ == ui::ET_MOUSE_PRESSED || | |
72 type_ == ui::ET_MOUSE_DRAGGED || | |
73 type_ == ui::ET_MOUSE_RELEASED || | |
74 type_ == ui::ET_MOUSE_MOVED || | |
75 type_ == ui::ET_MOUSE_ENTERED || | |
76 type_ == ui::ET_MOUSE_EXITED || | |
77 type_ == ui::ET_MOUSEWHEEL; | |
78 } | |
79 | |
80 bool IsTouchEvent() const { | |
81 return type_ == ui::ET_TOUCH_RELEASED || | |
82 type_ == ui::ET_TOUCH_PRESSED || | |
83 type_ == ui::ET_TOUCH_MOVED || | |
84 type_ == ui::ET_TOUCH_STATIONARY || | |
85 type_ == ui::ET_TOUCH_CANCELLED; | |
86 } | |
87 | |
88 bool IsScrollGestureEvent() const { | |
89 return type_ == ui::ET_GESTURE_SCROLL_BEGIN || | |
90 type_ == ui::ET_GESTURE_SCROLL_UPDATE || | |
91 type_ == ui::ET_GESTURE_SCROLL_END; | |
92 } | |
93 | |
94 bool IsFlingScrollEvent() const { | |
95 return type_ == ui::ET_SCROLL_FLING_CANCEL || | |
96 type_ == ui::ET_SCROLL_FLING_START; | |
97 } | |
98 | |
99 protected: | |
100 Event(ui::EventType type, int flags); | |
101 Event(const NativeEvent& native_event, ui::EventType type, int flags); | |
102 Event(const Event& model) | |
103 : native_event_(model.native_event()), | |
104 type_(model.type()), | |
105 time_stamp_(model.time_stamp()), | |
106 flags_(model.flags()) { | |
107 } | |
108 | |
109 void set_type(ui::EventType type) { type_ = type; } | |
110 | |
111 private: | |
112 void operator=(const Event&); | |
113 | |
114 NativeEvent native_event_; | |
115 ui::EventType type_; | |
116 base::Time time_stamp_; | |
117 int flags_; | |
118 }; | |
119 | |
120 //////////////////////////////////////////////////////////////////////////////// | |
121 // | |
122 // LocatedEvent class | 36 // LocatedEvent class |
123 // | 37 // |
124 // A generic event that is used for any events that is located at a specific | 38 // A generic event that is used for any events that is located at a specific |
125 // position in the screen. | 39 // position in the screen. |
126 // | 40 // |
127 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
128 class VIEWS_EXPORT LocatedEvent : public Event { | 42 class VIEWS_EXPORT LocatedEvent : public ui::Event { |
129 public: | 43 public: |
130 int x() const { return location_.x(); } | 44 int x() const { return location_.x(); } |
131 int y() const { return location_.y(); } | 45 int y() const { return location_.y(); } |
132 const gfx::Point& location() const { return location_; } | 46 const gfx::Point& location() const { return location_; } |
133 | 47 |
134 protected: | 48 protected: |
135 explicit LocatedEvent(const NativeEvent& native_event); | 49 explicit LocatedEvent(const ui::NativeEvent& native_event); |
136 | 50 |
137 // TODO(msw): Kill this legacy constructor when we update uses. | 51 // TODO(msw): Kill this legacy constructor when we update uses. |
138 // Simple initialization from cracked metadata. | 52 // Simple initialization from cracked metadata. |
139 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); | 53 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); |
140 | 54 |
141 // Create a new LocatedEvent which is identical to the provided model. | 55 // Create a new LocatedEvent which is identical to the provided model. |
142 // If source / target views are provided, the model location will be converted | 56 // If source / target views are provided, the model location will be converted |
143 // from |source| coordinate system to |target| coordinate system. | 57 // from |source| coordinate system to |target| coordinate system. |
144 LocatedEvent(const LocatedEvent& model, View* source, View* target); | 58 LocatedEvent(const LocatedEvent& model, View* source, View* target); |
145 | 59 |
146 // This constructor is to allow converting the location of an event from the | 60 // This constructor is to allow converting the location of an event from the |
147 // widget's coordinate system to the RootView's coordinate system. | 61 // widget's coordinate system to the RootView's coordinate system. |
148 LocatedEvent(const LocatedEvent& model, View* root); | 62 LocatedEvent(const LocatedEvent& model, View* root); |
149 | 63 |
150 gfx::Point location_; | 64 gfx::Point location_; |
151 }; | 65 }; |
152 | 66 |
153 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
154 // | 68 // |
155 // MouseEvent class | 69 // MouseEvent class |
156 // | 70 // |
157 // A mouse event is used for any input event related to the mouse. | 71 // A mouse event is used for any input event related to the mouse. |
158 // | 72 // |
159 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
160 class VIEWS_EXPORT MouseEvent : public LocatedEvent { | 74 class VIEWS_EXPORT MouseEvent : public LocatedEvent { |
161 public: | 75 public: |
162 explicit MouseEvent(const NativeEvent& native_event); | 76 explicit MouseEvent(const ui::NativeEvent& native_event); |
163 // Create a new MouseEvent which is identical to the provided model. | 77 // Create a new MouseEvent which is identical to the provided model. |
164 // If source / target views are provided, the model location will be converted | 78 // If source / target views are provided, the model location will be converted |
165 // from |source| coordinate system to |target| coordinate system. | 79 // from |source| coordinate system to |target| coordinate system. |
166 MouseEvent(const MouseEvent& model, View* source, View* target); | 80 MouseEvent(const MouseEvent& model, View* source, View* target); |
167 | 81 |
168 // TODO(msw): Kill this legacy constructor when we update uses. | 82 // TODO(msw): Kill this legacy constructor when we update uses. |
169 // Create a new mouse event | 83 // Create a new mouse event |
170 MouseEvent(ui::EventType type, int x, int y, int flags) | 84 MouseEvent(ui::EventType type, int x, int y, int flags) |
171 : LocatedEvent(type, gfx::Point(x, y), flags) { | 85 : LocatedEvent(type, gfx::Point(x, y), flags) { |
172 } | 86 } |
(...skipping 26 matching lines...) Expand all Loading... |
199 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) != 0; | 113 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) != 0; |
200 } | 114 } |
201 | 115 |
202 protected: | 116 protected: |
203 MouseEvent(const MouseEvent& model, View* root) | 117 MouseEvent(const MouseEvent& model, View* root) |
204 : LocatedEvent(model, root) { | 118 : LocatedEvent(model, root) { |
205 } | 119 } |
206 | 120 |
207 private: | 121 private: |
208 friend class internal::RootView; | 122 friend class internal::RootView; |
209 | |
210 DISALLOW_COPY_AND_ASSIGN(MouseEvent); | |
211 }; | 123 }; |
212 | 124 |
213 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
214 // | 126 // |
215 // TouchEvent class | 127 // TouchEvent class |
216 // | 128 // |
217 // A touch event is generated by touch screen and advanced track | 129 // A touch event is generated by touch screen and advanced track |
218 // pad devices. There is a deliberate direct correspondence between | 130 // pad devices. There is a deliberate direct correspondence between |
219 // TouchEvent and PlatformTouchPoint. | 131 // TouchEvent and PlatformTouchPoint. |
220 // | 132 // |
221 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
222 class VIEWS_EXPORT TouchEvent : public LocatedEvent { | 134 class VIEWS_EXPORT TouchEvent : public LocatedEvent { |
223 public: | 135 public: |
224 explicit TouchEvent(const NativeEvent& native_event); | 136 explicit TouchEvent(const ui::NativeEvent& native_event); |
225 | 137 |
226 // Create a new touch event. | 138 // Create a new touch event. |
227 TouchEvent(ui::EventType type, | 139 TouchEvent(ui::EventType type, |
228 int x, | 140 int x, |
229 int y, | 141 int y, |
230 int flags, | 142 int flags, |
231 int touch_id, | 143 int touch_id, |
232 float radius_x, | 144 float radius_x, |
233 float radius_y, | 145 float radius_y, |
234 float angle, | 146 float angle, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 // | 192 // |
281 // A MouseWheelEvent is used to propagate mouse wheel user events. | 193 // A MouseWheelEvent is used to propagate mouse wheel user events. |
282 // Note: e.GetOffset() > 0 means scroll up / left. | 194 // Note: e.GetOffset() > 0 means scroll up / left. |
283 // | 195 // |
284 //////////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////////// |
285 class VIEWS_EXPORT MouseWheelEvent : public MouseEvent { | 197 class VIEWS_EXPORT MouseWheelEvent : public MouseEvent { |
286 public: | 198 public: |
287 // See |offset| for details. | 199 // See |offset| for details. |
288 static const int kWheelDelta; | 200 static const int kWheelDelta; |
289 | 201 |
290 explicit MouseWheelEvent(const NativeEvent& native_event); | 202 explicit MouseWheelEvent(const ui::NativeEvent& native_event); |
291 explicit MouseWheelEvent(const ScrollEvent& scroll_event); | 203 explicit MouseWheelEvent(const ScrollEvent& scroll_event); |
292 | 204 |
293 // The amount to scroll. This is in multiples of kWheelDelta. | 205 // The amount to scroll. This is in multiples of kWheelDelta. |
294 int offset() const { return offset_; } | 206 int offset() const { return offset_; } |
295 | 207 |
296 private: | 208 private: |
297 friend class internal::RootView; | 209 friend class internal::RootView; |
298 | 210 |
299 MouseWheelEvent(const MouseWheelEvent& model, View* root) | 211 MouseWheelEvent(const MouseWheelEvent& model, View* root) |
300 : MouseEvent(model, root), | 212 : MouseEvent(model, root), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 const ui::OSExchangeData& data_; | 246 const ui::OSExchangeData& data_; |
335 | 247 |
336 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. | 248 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. |
337 int source_operations_; | 249 int source_operations_; |
338 | 250 |
339 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 251 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
340 }; | 252 }; |
341 | 253 |
342 class VIEWS_EXPORT ScrollEvent : public MouseEvent { | 254 class VIEWS_EXPORT ScrollEvent : public MouseEvent { |
343 public: | 255 public: |
344 explicit ScrollEvent(const NativeEvent& native_event); | 256 explicit ScrollEvent(const ui::NativeEvent& native_event); |
345 | 257 |
346 float x_offset() const { return x_offset_; } | 258 float x_offset() const { return x_offset_; } |
347 float y_offset() const { return y_offset_; } | 259 float y_offset() const { return y_offset_; } |
348 | 260 |
349 private: | 261 private: |
350 friend class internal::RootView; | 262 friend class internal::RootView; |
351 | 263 |
352 ScrollEvent(const ScrollEvent& model, View* root) | 264 ScrollEvent(const ScrollEvent& model, View* root) |
353 : MouseEvent(model, root), | 265 : MouseEvent(model, root), |
354 x_offset_(model.x_offset()), | 266 x_offset_(model.x_offset()), |
355 y_offset_(model.y_offset()) { | 267 y_offset_(model.y_offset()) { |
356 } | 268 } |
357 | 269 |
358 float x_offset_; | 270 float x_offset_; |
359 float y_offset_; | 271 float y_offset_; |
360 | 272 |
361 DISALLOW_COPY_AND_ASSIGN(ScrollEvent); | 273 DISALLOW_COPY_AND_ASSIGN(ScrollEvent); |
362 }; | 274 }; |
363 | 275 |
364 //////////////////////////////////////////////////////////////////////////////// | 276 //////////////////////////////////////////////////////////////////////////////// |
365 // GestureEvent class | 277 // GestureEvent class |
366 // | 278 // |
367 //////////////////////////////////////////////////////////////////////////////// | 279 //////////////////////////////////////////////////////////////////////////////// |
368 class VIEWS_EXPORT GestureEvent : public LocatedEvent { | 280 class VIEWS_EXPORT GestureEvent : public LocatedEvent { |
369 public: | 281 public: |
370 explicit GestureEvent(const NativeEvent& native_event); | 282 explicit GestureEvent(const ui::NativeEvent& native_event); |
371 | 283 |
372 // Create a new GestureEvent which is identical to the provided model. | 284 // Create a new GestureEvent which is identical to the provided model. |
373 // If source / target views are provided, the model location will be converted | 285 // If source / target views are provided, the model location will be converted |
374 // from |source| coordinate system to |target| coordinate system. | 286 // from |source| coordinate system to |target| coordinate system. |
375 GestureEvent(const GestureEvent& model, View* source, View* target); | 287 GestureEvent(const GestureEvent& model, View* source, View* target); |
376 | 288 |
377 virtual ~GestureEvent(); | 289 virtual ~GestureEvent(); |
378 | 290 |
379 const ui::GestureEventDetails& details() const { return details_; } | 291 const ui::GestureEventDetails& details() const { return details_; } |
380 | 292 |
(...skipping 18 matching lines...) Expand all Loading... |
399 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); | 311 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); |
400 }; | 312 }; |
401 | 313 |
402 #if defined(OS_WIN) | 314 #if defined(OS_WIN) |
403 int GetModifiersFromKeyState(); | 315 int GetModifiersFromKeyState(); |
404 #endif | 316 #endif |
405 | 317 |
406 } // namespace views | 318 } // namespace views |
407 | 319 |
408 #endif // UI_VIEWS_EVENTS_EVENT_H_ | 320 #endif // UI_VIEWS_EVENTS_EVENT_H_ |
OLD | NEW |