OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_EVENT_H_ | 5 #ifndef VIEWS_EVENTS_EVENT_H_ |
6 #define VIEWS_EVENT_H_ | 6 #define VIEWS_EVENTS_EVENT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "ui/base/events.h" | 11 #include "ui/base/events.h" |
12 #include "ui/base/keycodes/keyboard_codes.h" | 12 #include "ui/base/keycodes/keyboard_codes.h" |
13 #include "ui/gfx/point.h" | 13 #include "ui/gfx/point.h" |
14 #include "views/native_types.h" | 14 #include "views/native_types.h" |
15 | 15 |
16 #if defined(OS_LINUX) | |
17 typedef struct _GdkEventKey GdkEventKey; | |
18 #endif | |
19 | |
20 #if defined(TOUCH_UI) | 16 #if defined(TOUCH_UI) |
21 typedef union _XEvent XEvent; | 17 typedef union _XEvent XEvent; |
22 #endif | 18 #endif |
23 | 19 |
24 namespace ui { | 20 namespace ui { |
25 class OSExchangeData; | 21 class OSExchangeData; |
26 } | 22 } |
27 using ui::OSExchangeData; | 23 using ui::OSExchangeData; |
28 | 24 |
29 namespace views { | 25 namespace views { |
30 | 26 |
31 class View; | 27 class View; |
32 | 28 |
33 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
34 // | 30 // |
35 // Event class | 31 // Event class |
36 // | 32 // |
37 // An event encapsulates an input event that can be propagated into view | 33 // An event encapsulates an input event that can be propagated into view |
38 // hierarchies. An event has a type, some flags and a time stamp. | 34 // hierarchies. An event has a type, some flags and a time stamp. |
39 // | 35 // |
40 // Each major event type has a corresponding Event subclass. | 36 // Each major event type has a corresponding Event subclass. |
41 // | 37 // |
42 // Events are immutable but support copy | 38 // Events are immutable but support copy |
43 // | 39 // |
44 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
45 class Event { | 41 class Event { |
46 public: | 42 public: |
| 43 // This type exists to distinguish between the NativeEvent and NativeEvent2 |
| 44 // constructors. |
| 45 // TODO(beng): remove once we rid views of Gtk/Gdk. |
| 46 struct FromNativeEvent2 {}; |
| 47 |
47 const NativeEvent& native_event() const { return native_event_; } | 48 const NativeEvent& native_event() const { return native_event_; } |
| 49 const NativeEvent2& native_event_2() const { return native_event_2_; } |
48 ui::EventType type() const { return type_; } | 50 ui::EventType type() const { return type_; } |
49 const base::Time& time_stamp() const { return time_stamp_; } | 51 const base::Time& time_stamp() const { return time_stamp_; } |
50 int flags() const { return flags_; } | 52 int flags() const { return flags_; } |
51 void set_flags(int flags) { flags_ = flags; } | 53 void set_flags(int flags) { flags_ = flags; } |
52 | 54 |
53 // The following methods return true if the respective keys were pressed at | 55 // The following methods return true if the respective keys were pressed at |
54 // the time the event was created. | 56 // the time the event was created. |
55 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; } | 57 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; } |
56 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; } | 58 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; } |
57 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; } | 59 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; } |
(...skipping 25 matching lines...) Expand all Loading... |
83 | 85 |
84 // Convert windows flags to views::Event flags | 86 // Convert windows flags to views::Event flags |
85 static int ConvertWindowsFlags(uint32 win_flags); | 87 static int ConvertWindowsFlags(uint32 win_flags); |
86 #elif defined(OS_LINUX) | 88 #elif defined(OS_LINUX) |
87 // Convert the state member on a GdkEvent to views::Event flags | 89 // Convert the state member on a GdkEvent to views::Event flags |
88 static int GetFlagsFromGdkState(int state); | 90 static int GetFlagsFromGdkState(int state); |
89 #endif | 91 #endif |
90 | 92 |
91 protected: | 93 protected: |
92 Event(ui::EventType type, int flags); | 94 Event(ui::EventType type, int flags); |
| 95 Event(NativeEvent native_event, ui::EventType type, int flags); |
| 96 // Because the world is complicated, sometimes we have two different kinds of |
| 97 // NativeEvent in play in the same executable. See native_types.h for the tale |
| 98 // of woe. |
| 99 Event(NativeEvent2 native_event, ui::EventType type, int flags, |
| 100 FromNativeEvent2); |
93 | 101 |
94 Event(const Event& model) | 102 Event(const Event& model) |
95 : native_event_(model.native_event()), | 103 : native_event_(model.native_event()), |
96 type_(model.type()), | 104 type_(model.type()), |
97 time_stamp_(model.time_stamp()), | 105 time_stamp_(model.time_stamp()), |
98 flags_(model.flags()) { | 106 flags_(model.flags()) { |
99 } | 107 } |
100 | 108 |
101 private: | 109 private: |
102 void operator=(const Event&); | 110 void operator=(const Event&); |
103 | 111 |
| 112 // Safely initializes the native event members of this class. |
| 113 void Init(); |
| 114 void InitWithNativeEvent(NativeEvent native_event); |
| 115 void InitWithNativeEvent2(NativeEvent2 native_event_2, FromNativeEvent2); |
| 116 |
104 NativeEvent native_event_; | 117 NativeEvent native_event_; |
| 118 NativeEvent2 native_event_2_; |
105 ui::EventType type_; | 119 ui::EventType type_; |
106 base::Time time_stamp_; | 120 base::Time time_stamp_; |
107 int flags_; | 121 int flags_; |
108 }; | 122 }; |
109 | 123 |
110 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
111 // | 125 // |
112 // LocatedEvent class | 126 // LocatedEvent class |
113 // | 127 // |
114 // A generic event that is used for any events that is located at a specific | 128 // A generic event that is used for any events that is located at a specific |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 private: | 253 private: |
240 // The identity (typically finger) of the touch starting at 0 and incrementing | 254 // The identity (typically finger) of the touch starting at 0 and incrementing |
241 // for each separable additional touch that the hardware can detect. | 255 // for each separable additional touch that the hardware can detect. |
242 const int touch_id_; | 256 const int touch_id_; |
243 | 257 |
244 DISALLOW_COPY_AND_ASSIGN(TouchEvent); | 258 DISALLOW_COPY_AND_ASSIGN(TouchEvent); |
245 }; | 259 }; |
246 #endif | 260 #endif |
247 | 261 |
248 //////////////////////////////////////////////////////////////////////////////// | 262 //////////////////////////////////////////////////////////////////////////////// |
249 // | |
250 // KeyEvent class | 263 // KeyEvent class |
251 // | 264 // |
252 // A key event is used for any input event related to the keyboard. | 265 // KeyEvent encapsulates keyboard input events - key press and release. |
253 // Note: this event is about key pressed, not typed characters. | |
254 // | 266 // |
255 //////////////////////////////////////////////////////////////////////////////// | |
256 class KeyEvent : public Event { | 267 class KeyEvent : public Event { |
257 public: | 268 public: |
258 // Create a new key event | 269 explicit KeyEvent(NativeEvent native_event); |
| 270 explicit KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2); |
| 271 |
| 272 // Creates a new KeyEvent synthetically (i.e. not in response to an input |
| 273 // event from the host environment). This is typically only used in testing as |
| 274 // some metadata obtainable from the underlying native event is not present. |
| 275 // TODO(beng): see if we can kill this. |
259 KeyEvent(ui::EventType type, | 276 KeyEvent(ui::EventType type, |
260 ui::KeyboardCode key_code, | 277 ui::KeyboardCode key_code, |
261 int event_flags, | 278 int event_flags); |
262 int repeat_count, | |
263 int message_flags); | |
264 | |
265 #if defined(OS_WIN) | |
266 KeyEvent(ui::EventType type, | |
267 ui::KeyboardCode key_code, | |
268 int event_flags, | |
269 int repeat_count, | |
270 int message_flags, | |
271 UINT message); | |
272 #endif | |
273 #if defined(OS_LINUX) | |
274 explicit KeyEvent(const GdkEventKey* event); | |
275 | |
276 const GdkEventKey* native_event() const { return native_event_; } | |
277 #endif | |
278 #if defined(TOUCH_UI) | |
279 // Create a key event from an X key event. | |
280 explicit KeyEvent(XEvent* xevent); | |
281 #endif | |
282 | 279 |
283 ui::KeyboardCode key_code() const { return key_code_; } | 280 ui::KeyboardCode key_code() const { return key_code_; } |
284 | 281 |
285 #if defined(OS_WIN) | 282 private: |
286 bool IsExtendedKey() const; | 283 ui::KeyboardCode key_code_; |
287 | 284 |
288 UINT message() const { return message_; } | |
289 #endif | |
290 | |
291 int repeat_count() const { return repeat_count_; } | |
292 | |
293 #if defined(OS_WIN) | |
294 static int GetKeyStateFlags(); | |
295 #endif | |
296 | |
297 private: | |
298 | |
299 ui::KeyboardCode key_code_; | |
300 int repeat_count_; | |
301 int message_flags_; | |
302 #if defined(OS_WIN) | |
303 UINT message_; | |
304 #elif defined(OS_LINUX) | |
305 const GdkEventKey* native_event_; | |
306 #endif | |
307 DISALLOW_COPY_AND_ASSIGN(KeyEvent); | 285 DISALLOW_COPY_AND_ASSIGN(KeyEvent); |
308 }; | 286 }; |
309 | 287 |
310 //////////////////////////////////////////////////////////////////////////////// | 288 //////////////////////////////////////////////////////////////////////////////// |
311 // | 289 // |
312 // MouseWheelEvent class | 290 // MouseWheelEvent class |
313 // | 291 // |
314 // A MouseWheelEvent is used to propagate mouse wheel user events. | 292 // A MouseWheelEvent is used to propagate mouse wheel user events. |
315 // Note: e.GetOffset() > 0 means scroll up. | 293 // Note: e.GetOffset() > 0 means scroll up. |
316 // | 294 // |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 const OSExchangeData& data_; | 340 const OSExchangeData& data_; |
363 | 341 |
364 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. | 342 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. |
365 int source_operations_; | 343 int source_operations_; |
366 | 344 |
367 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 345 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
368 }; | 346 }; |
369 | 347 |
370 } // namespace views | 348 } // namespace views |
371 | 349 |
372 #endif // VIEWS_EVENT_H_ | 350 #endif // VIEWS_EVENTS_EVENT_H_ |
OLD | NEW |