OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_EVENT_H_ | 5 #ifndef UI_BASE_EVENT_H_ |
6 #define UI_BASE_EVENT_H_ | 6 #define UI_BASE_EVENT_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/event_types.h" | 10 #include "base/event_types.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/dragdrop/os_exchange_data.h" | 13 #include "ui/base/dragdrop/os_exchange_data.h" |
14 #include "ui/base/events.h" | 14 #include "ui/base/events.h" |
15 #include "ui/base/gestures/gesture_types.h" | 15 #include "ui/base/gestures/gesture_types.h" |
16 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
17 #include "ui/base/ui_export.h" | 17 #include "ui/base/ui_export.h" |
18 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
19 | 19 |
20 namespace ui { | 20 namespace ui { |
21 class Transform; | 21 class Transform; |
22 | 22 |
23 #if defined(USE_AURA) | |
24 typedef Event* NativeEvent; | |
25 #else | |
26 typedef base::NativeEvent NativeEvent; | |
27 #endif | |
28 | |
29 class UI_EXPORT Event { | 23 class UI_EXPORT Event { |
30 public: | 24 public: |
31 virtual ~Event(); | 25 virtual ~Event(); |
32 | 26 |
33 // For testing. | 27 // For testing. |
34 class TestApi { | 28 class TestApi { |
35 public: | 29 public: |
36 explicit TestApi(Event* event) : event_(event) {} | 30 explicit TestApi(Event* event) : event_(event) {} |
37 | 31 |
38 void set_time_stamp(const base::TimeDelta& time_stamp) { | 32 void set_time_stamp(const base::TimeDelta& time_stamp) { |
39 event_->time_stamp_ = time_stamp; | 33 event_->time_stamp_ = time_stamp; |
40 } | 34 } |
41 | 35 |
42 private: | 36 private: |
43 TestApi(); | 37 TestApi(); |
44 Event* event_; | 38 Event* event_; |
45 }; | 39 }; |
46 | 40 |
47 const base::NativeEvent& native_event() const { return native_event_; } | 41 const base::NativeEvent& native_event() const { return native_event_; } |
48 const NativeEvent& ui_native_event() const { return ui_native_event_; } | |
49 EventType type() const { return type_; } | 42 EventType type() const { return type_; } |
50 // time_stamp represents time since machine was booted. | 43 // time_stamp represents time since machine was booted. |
51 const base::TimeDelta& time_stamp() const { return time_stamp_; } | 44 const base::TimeDelta& time_stamp() const { return time_stamp_; } |
52 int flags() const { return flags_; } | 45 int flags() const { return flags_; } |
53 | 46 |
54 // This is only intended to be used externally by classes that are modifying | 47 // This is only intended to be used externally by classes that are modifying |
55 // events in EventFilter::PreHandleKeyEvent(). | 48 // events in EventFilter::PreHandleKeyEvent(). |
56 void set_flags(int flags) { flags_ = flags; } | 49 void set_flags(int flags) { flags_ = flags; } |
57 | 50 |
58 // The following methods return true if the respective keys were pressed at | 51 // The following methods return true if the respective keys were pressed at |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; } | 98 void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; } |
106 | 99 |
107 private: | 100 private: |
108 void operator=(const Event&); | 101 void operator=(const Event&); |
109 | 102 |
110 // Safely initializes the native event members of this class. | 103 // Safely initializes the native event members of this class. |
111 void Init(); | 104 void Init(); |
112 void InitWithNativeEvent(const base::NativeEvent& native_event); | 105 void InitWithNativeEvent(const base::NativeEvent& native_event); |
113 | 106 |
114 base::NativeEvent native_event_; | 107 base::NativeEvent native_event_; |
115 // TODO(beng): check to see if this is necessary. | |
116 NativeEvent ui_native_event_; | |
117 EventType type_; | 108 EventType type_; |
118 base::TimeDelta time_stamp_; | 109 base::TimeDelta time_stamp_; |
119 int flags_; | 110 int flags_; |
120 bool delete_native_event_; | 111 bool delete_native_event_; |
121 }; | 112 }; |
122 | 113 |
123 class UI_EXPORT LocatedEvent : public Event { | 114 class UI_EXPORT LocatedEvent : public Event { |
124 public: | 115 public: |
125 // For testing. | 116 // For testing. |
126 class TestApi : public Event::TestApi { | 117 class TestApi : public Event::TestApi { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 if (target && target != source) | 154 if (target && target != source) |
164 T::ConvertPointToTarget(source, target, &location_); | 155 T::ConvertPointToTarget(source, target, &location_); |
165 } | 156 } |
166 | 157 |
167 // Used for synthetic events in testing. | 158 // Used for synthetic events in testing. |
168 LocatedEvent(EventType type, | 159 LocatedEvent(EventType type, |
169 const gfx::Point& location, | 160 const gfx::Point& location, |
170 const gfx::Point& root_location, | 161 const gfx::Point& root_location, |
171 int flags); | 162 int flags); |
172 | 163 |
173 LocatedEvent(const LocatedEvent& model); | 164 // Called from MouseEvent's copy ctor. |
| 165 explicit LocatedEvent(const LocatedEvent& model); |
174 | 166 |
175 gfx::Point location_; | 167 gfx::Point location_; |
176 | 168 |
177 gfx::Point root_location_; | 169 gfx::Point root_location_; |
178 }; | 170 }; |
179 | 171 |
180 class UI_EXPORT MouseEvent : public LocatedEvent { | 172 class UI_EXPORT MouseEvent : public LocatedEvent { |
181 public: | 173 public: |
182 explicit MouseEvent(const base::NativeEvent& native_event); | 174 explicit MouseEvent(const base::NativeEvent& native_event); |
183 | 175 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 void SetClickCount(int click_count); | 242 void SetClickCount(int click_count); |
251 | 243 |
252 // Identifies the button that changed. During a press this corresponds to the | 244 // Identifies the button that changed. During a press this corresponds to the |
253 // button that was pressed and during a release this corresponds to the button | 245 // button that was pressed and during a release this corresponds to the button |
254 // that was released. | 246 // that was released. |
255 // NOTE: during a press and release flags() contains the complete set of | 247 // NOTE: during a press and release flags() contains the complete set of |
256 // flags. Use this to determine the button that was pressed or released. | 248 // flags. Use this to determine the button that was pressed or released. |
257 int changed_button_flags() const { return changed_button_flags_; } | 249 int changed_button_flags() const { return changed_button_flags_; } |
258 | 250 |
259 protected: | 251 protected: |
| 252 // Called from MouseWheelEvent's ctor. |
260 explicit MouseEvent(const MouseEvent& model); | 253 explicit MouseEvent(const MouseEvent& model); |
261 | 254 |
262 private: | 255 private: |
263 // Returns the repeat count based on the previous mouse click, if it is | 256 // Returns the repeat count based on the previous mouse click, if it is |
264 // recent enough and within a small enough distance. | 257 // recent enough and within a small enough distance. |
265 static int GetRepeatCount(const MouseEvent& click_event); | 258 static int GetRepeatCount(const MouseEvent& click_event); |
266 | 259 |
267 gfx::Point root_location_; | 260 gfx::Point root_location_; |
268 | 261 |
269 // See description above getter for details. | 262 // See description above getter for details. |
270 int changed_button_flags_; | 263 int changed_button_flags_; |
271 | 264 |
272 static MouseEvent* last_click_event_; | 265 static MouseEvent* last_click_event_; |
273 }; | 266 }; |
274 | 267 |
275 class ScrollEvent; | 268 class ScrollEvent; |
276 | 269 |
277 class UI_EXPORT MouseWheelEvent : public MouseEvent { | 270 class UI_EXPORT MouseWheelEvent : public MouseEvent { |
278 public: | 271 public: |
279 // See |offset| for details. | 272 // See |offset| for details. |
280 static const int kWheelDelta; | 273 static const int kWheelDelta; |
281 | 274 |
282 explicit MouseWheelEvent(const NativeEvent& native_event); | 275 explicit MouseWheelEvent(const base::NativeEvent& native_event); |
| 276 explicit MouseWheelEvent(const MouseEvent& mouse_event); |
283 explicit MouseWheelEvent(const ScrollEvent& scroll_event); | 277 explicit MouseWheelEvent(const ScrollEvent& scroll_event); |
284 | 278 |
285 // The amount to scroll. This is in multiples of kWheelDelta. | 279 // The amount to scroll. This is in multiples of kWheelDelta. |
286 // Note: offset() > 0 means scroll up / left. | 280 // Note: offset() > 0 means scroll up / left. |
287 int offset() const { return offset_; } | 281 int offset() const { return offset_; } |
288 | 282 |
289 private: | 283 private: |
290 int offset_; | 284 int offset_; |
291 | 285 |
292 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); | 286 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } | 407 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } |
414 | 408 |
415 private: | 409 private: |
416 KeyboardCode key_code_; | 410 KeyboardCode key_code_; |
417 // True if this is a translated character event (vs. a raw key down). Both | 411 // True if this is a translated character event (vs. a raw key down). Both |
418 // share the same type: ET_KEY_PRESSED. | 412 // share the same type: ET_KEY_PRESSED. |
419 bool is_char_; | 413 bool is_char_; |
420 | 414 |
421 uint16 character_; | 415 uint16 character_; |
422 uint16 unmodified_character_; | 416 uint16 unmodified_character_; |
| 417 |
| 418 DISALLOW_COPY_AND_ASSIGN(KeyEvent); |
423 }; | 419 }; |
424 | 420 |
425 // A key event which is translated by an input method (IME). | 421 // A key event which is translated by an input method (IME). |
426 // For example, if an IME receives a KeyEvent(VKEY_SPACE), and it does not | 422 // For example, if an IME receives a KeyEvent(VKEY_SPACE), and it does not |
427 // consume the key, the IME usually generates and dispatches a | 423 // consume the key, the IME usually generates and dispatches a |
428 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and | 424 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and |
429 // it does consume the event, it might dispatch a | 425 // it does consume the event, it might dispatch a |
430 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. | 426 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. |
431 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { | 427 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { |
432 public: | 428 public: |
433 TranslatedKeyEvent(const base::NativeEvent& native_event, bool is_char); | 429 TranslatedKeyEvent(const base::NativeEvent& native_event, bool is_char); |
434 | 430 |
435 // Used for synthetic events such as a VKEY_PROCESSKEY key event. | 431 // Used for synthetic events such as a VKEY_PROCESSKEY key event. |
436 TranslatedKeyEvent(bool is_press, KeyboardCode key_code, int flags); | 432 TranslatedKeyEvent(bool is_press, KeyboardCode key_code, int flags); |
437 | 433 |
438 // Changes the type() of the object from ET_TRANSLATED_KEY_* to ET_KEY_* so | 434 // Changes the type() of the object from ET_TRANSLATED_KEY_* to ET_KEY_* so |
439 // that RenderWidgetHostViewAura and NativeWidgetAura could handle the event. | 435 // that RenderWidgetHostViewAura and NativeWidgetAura could handle the event. |
440 void ConvertToKeyEvent(); | 436 void ConvertToKeyEvent(); |
| 437 |
| 438 private: |
| 439 DISALLOW_COPY_AND_ASSIGN(TranslatedKeyEvent); |
441 }; | 440 }; |
442 | 441 |
443 class UI_EXPORT DropTargetEvent : public LocatedEvent { | 442 class UI_EXPORT DropTargetEvent : public LocatedEvent { |
444 public: | 443 public: |
445 DropTargetEvent(const OSExchangeData& data, | 444 DropTargetEvent(const OSExchangeData& data, |
446 const gfx::Point& location, | 445 const gfx::Point& location, |
447 const gfx::Point& root_location, | 446 const gfx::Point& root_location, |
448 int source_operations) | 447 int source_operations) |
449 : LocatedEvent(ET_DROP_TARGET_EVENT, location, root_location, 0), | 448 : LocatedEvent(ET_DROP_TARGET_EVENT, location, root_location, 0), |
450 data_(data), | 449 data_(data), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 // This value is stored as a bitfield because the number of touch ids varies, | 523 // This value is stored as a bitfield because the number of touch ids varies, |
525 // but we currently don't need more than 32 touches at a time. | 524 // but we currently don't need more than 32 touches at a time. |
526 const unsigned int touch_ids_bitfield_; | 525 const unsigned int touch_ids_bitfield_; |
527 | 526 |
528 DISALLOW_COPY_AND_ASSIGN(GestureEvent); | 527 DISALLOW_COPY_AND_ASSIGN(GestureEvent); |
529 }; | 528 }; |
530 | 529 |
531 } // namespace ui | 530 } // namespace ui |
532 | 531 |
533 #endif // UI_BASE_EVENT_H_ | 532 #endif // UI_BASE_EVENT_H_ |
OLD | NEW |