OLD | NEW |
1 // Copyright (c) 2011 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_EVENTS_EVENT_H_ | 5 #ifndef VIEWS_EVENTS_EVENT_H_ |
6 #define VIEWS_EVENTS_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 #include "views/views_export.h" | 15 #include "views/views_export.h" |
16 | 16 |
17 #if defined(USE_X11) | |
18 typedef union _XEvent XEvent; | |
19 #endif | |
20 | |
21 namespace ui { | 17 namespace ui { |
22 class OSExchangeData; | 18 class OSExchangeData; |
23 } | 19 } |
24 using ui::OSExchangeData; | |
25 | 20 |
26 namespace views { | 21 namespace views { |
27 | 22 |
28 class View; | 23 class View; |
29 | 24 |
30 namespace internal { | 25 namespace internal { |
31 class NativeWidgetView; | 26 class NativeWidgetView; |
32 class RootView; | 27 class RootView; |
33 } | 28 } |
34 | 29 |
35 #if defined(OS_WIN) || defined(USE_AURA) | |
36 VIEWS_EXPORT bool IsClientMouseEvent(const views::NativeEvent& native_event); | |
37 VIEWS_EXPORT bool IsNonClientMouseEvent(const views::NativeEvent& native_event); | |
38 #endif | |
39 | |
40 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
41 // | 31 // |
42 // Event class | 32 // Event class |
43 // | 33 // |
44 // An event encapsulates an input event that can be propagated into view | 34 // An event encapsulates an input event that can be propagated into view |
45 // hierarchies. An event has a type, some flags and a time stamp. | 35 // hierarchies. An event has a type, some flags and a time stamp. |
46 // | 36 // |
47 // Each major event type has a corresponding Event subclass. | 37 // Each major event type has a corresponding Event subclass. |
48 // | 38 // |
49 // Events are immutable but support copy | 39 // Events are immutable but support copy |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 71 } |
82 | 72 |
83 bool IsTouchEvent() const { | 73 bool IsTouchEvent() const { |
84 return type_ == ui::ET_TOUCH_RELEASED || | 74 return type_ == ui::ET_TOUCH_RELEASED || |
85 type_ == ui::ET_TOUCH_PRESSED || | 75 type_ == ui::ET_TOUCH_PRESSED || |
86 type_ == ui::ET_TOUCH_MOVED || | 76 type_ == ui::ET_TOUCH_MOVED || |
87 type_ == ui::ET_TOUCH_STATIONARY || | 77 type_ == ui::ET_TOUCH_STATIONARY || |
88 type_ == ui::ET_TOUCH_CANCELLED; | 78 type_ == ui::ET_TOUCH_CANCELLED; |
89 } | 79 } |
90 | 80 |
91 #if defined(OS_WIN) && !defined(USE_AURA) | |
92 // Returns the EventFlags in terms of windows flags. | |
93 int GetWindowsFlags() const; | |
94 #elif defined(OS_LINUX) | |
95 // Get the views::Event flags from a native GdkEvent. | |
96 static int GetFlagsFromGdkEvent(NativeEvent native_event); | |
97 #endif | |
98 | |
99 protected: | 81 protected: |
100 Event(ui::EventType type, int flags); | 82 Event(ui::EventType type, int flags); |
101 Event(NativeEvent native_event, ui::EventType type, int flags); | 83 Event(const NativeEvent& native_event, ui::EventType type, int flags); |
102 // Because the world is complicated, sometimes we have two different kinds of | 84 // Because the world is complicated, sometimes we have two different kinds of |
103 // NativeEvent in play in the same executable. See native_types.h for the tale | 85 // NativeEvent in play in the same executable. See native_types.h for the tale |
104 // of woe. | 86 // of woe. |
105 Event(NativeEvent2 native_event, ui::EventType type, int flags, | 87 Event(const NativeEvent2& native_event, |
| 88 ui::EventType type, |
| 89 int flags, |
106 FromNativeEvent2); | 90 FromNativeEvent2); |
107 | 91 |
108 Event(const Event& model) | 92 Event(const Event& model) |
109 : native_event_(model.native_event()), | 93 : native_event_(model.native_event()), |
110 native_event_2_(model.native_event_2()), | 94 native_event_2_(model.native_event_2()), |
111 type_(model.type()), | 95 type_(model.type()), |
112 time_stamp_(model.time_stamp()), | 96 time_stamp_(model.time_stamp()), |
113 flags_(model.flags()) { | 97 flags_(model.flags()) { |
114 } | 98 } |
115 | 99 |
116 void set_type(ui::EventType type) { type_ = type; } | 100 void set_type(ui::EventType type) { type_ = type; } |
117 | 101 |
118 private: | 102 private: |
119 void operator=(const Event&); | 103 void operator=(const Event&); |
120 | 104 |
121 // Safely initializes the native event members of this class. | 105 // Safely initializes the native event members of this class. |
122 void Init(); | 106 void Init(); |
123 void InitWithNativeEvent(NativeEvent native_event); | 107 void InitWithNativeEvent(const NativeEvent& native_event); |
124 void InitWithNativeEvent2(NativeEvent2 native_event_2, FromNativeEvent2); | 108 void InitWithNativeEvent2(const NativeEvent2& native_event_2, |
| 109 FromNativeEvent2); |
125 | 110 |
126 NativeEvent native_event_; | 111 NativeEvent native_event_; |
127 NativeEvent2 native_event_2_; | 112 NativeEvent2 native_event_2_; |
128 ui::EventType type_; | 113 ui::EventType type_; |
129 base::Time time_stamp_; | 114 base::Time time_stamp_; |
130 int flags_; | 115 int flags_; |
131 }; | 116 }; |
132 | 117 |
133 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
134 // | 119 // |
135 // LocatedEvent class | 120 // LocatedEvent class |
136 // | 121 // |
137 // A generic event that is used for any events that is located at a specific | 122 // A generic event that is used for any events that is located at a specific |
138 // position in the screen. | 123 // position in the screen. |
139 // | 124 // |
140 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
141 class VIEWS_EXPORT LocatedEvent : public Event { | 126 class VIEWS_EXPORT LocatedEvent : public Event { |
142 public: | 127 public: |
143 int x() const { return location_.x(); } | 128 int x() const { return location_.x(); } |
144 int y() const { return location_.y(); } | 129 int y() const { return location_.y(); } |
145 const gfx::Point& location() const { return location_; } | 130 const gfx::Point& location() const { return location_; } |
146 | 131 |
147 protected: | 132 protected: |
148 explicit LocatedEvent(NativeEvent native_event); | 133 explicit LocatedEvent(const NativeEvent& native_event); |
149 LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 134 LocatedEvent(const NativeEvent2& native_event_2, |
| 135 FromNativeEvent2 from_native); |
150 | 136 |
151 // TODO(msw): Kill this legacy constructor when we update uses. | 137 // TODO(msw): Kill this legacy constructor when we update uses. |
152 // Simple initialization from cracked metadata. | 138 // Simple initialization from cracked metadata. |
153 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); | 139 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); |
154 | 140 |
155 // Create a new LocatedEvent which is identical to the provided model. | 141 // Create a new LocatedEvent which is identical to the provided model. |
156 // If source / target views are provided, the model location will be converted | 142 // If source / target views are provided, the model location will be converted |
157 // from |source| coordinate system to |target| coordinate system. | 143 // from |source| coordinate system to |target| coordinate system. |
158 LocatedEvent(const LocatedEvent& model, View* source, View* target); | 144 LocatedEvent(const LocatedEvent& model, View* source, View* target); |
159 | 145 |
160 // This constructor is to allow converting the location of an event from the | 146 // This constructor is to allow converting the location of an event from the |
161 // widget's coordinate system to the RootView's coordinate system. | 147 // widget's coordinate system to the RootView's coordinate system. |
162 LocatedEvent(const LocatedEvent& model, View* root); | 148 LocatedEvent(const LocatedEvent& model, View* root); |
163 | 149 |
164 gfx::Point location_; | 150 gfx::Point location_; |
165 }; | 151 }; |
166 | 152 |
167 class TouchEvent; | 153 class TouchEvent; |
168 | 154 |
169 //////////////////////////////////////////////////////////////////////////////// | 155 //////////////////////////////////////////////////////////////////////////////// |
170 // | 156 // |
171 // MouseEvent class | 157 // MouseEvent class |
172 // | 158 // |
173 // A mouse event is used for any input event related to the mouse. | 159 // A mouse event is used for any input event related to the mouse. |
174 // | 160 // |
175 //////////////////////////////////////////////////////////////////////////////// | 161 //////////////////////////////////////////////////////////////////////////////// |
176 class VIEWS_EXPORT MouseEvent : public LocatedEvent { | 162 class VIEWS_EXPORT MouseEvent : public LocatedEvent { |
177 public: | 163 public: |
178 explicit MouseEvent(NativeEvent native_event); | 164 explicit MouseEvent(const NativeEvent& native_event); |
179 MouseEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 165 MouseEvent(const NativeEvent2& native_event_2, FromNativeEvent2 from_native); |
180 | 166 |
181 // Create a new MouseEvent which is identical to the provided model. | 167 // Create a new MouseEvent which is identical to the provided model. |
182 // If source / target views are provided, the model location will be converted | 168 // If source / target views are provided, the model location will be converted |
183 // from |source| coordinate system to |target| coordinate system. | 169 // from |source| coordinate system to |target| coordinate system. |
184 MouseEvent(const MouseEvent& model, View* source, View* target); | 170 MouseEvent(const MouseEvent& model, View* source, View* target); |
185 | 171 |
186 // Creates a new MouseEvent from a TouchEvent. The location of the TouchEvent | 172 // Creates a new MouseEvent from a TouchEvent. The location of the TouchEvent |
187 // is the same as the MouseEvent. Other attributes (e.g. type, flags) are | 173 // is the same as the MouseEvent. Other attributes (e.g. type, flags) are |
188 // mapped from the TouchEvent to appropriate MouseEvent attributes. | 174 // mapped from the TouchEvent to appropriate MouseEvent attributes. |
189 // GestureManager uses this to convert TouchEvents that are not handled by any | 175 // GestureManager uses this to convert TouchEvents that are not handled by any |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // | 226 // |
241 // TouchEvent class | 227 // TouchEvent class |
242 // | 228 // |
243 // A touch event is generated by touch screen and advanced track | 229 // A touch event is generated by touch screen and advanced track |
244 // pad devices. There is a deliberate direct correspondence between | 230 // pad devices. There is a deliberate direct correspondence between |
245 // TouchEvent and PlatformTouchPoint. | 231 // TouchEvent and PlatformTouchPoint. |
246 // | 232 // |
247 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
248 class VIEWS_EXPORT TouchEvent : public LocatedEvent { | 234 class VIEWS_EXPORT TouchEvent : public LocatedEvent { |
249 public: | 235 public: |
250 TouchEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 236 TouchEvent(const NativeEvent2& native_event_2, FromNativeEvent2 from_native); |
251 | 237 |
252 // Create a new touch event. | 238 // Create a new touch event. |
253 TouchEvent(ui::EventType type, | 239 TouchEvent(ui::EventType type, |
254 int x, | 240 int x, |
255 int y, | 241 int y, |
256 int flags, | 242 int flags, |
257 int touch_id, | 243 int touch_id, |
258 float radius_x, | 244 float radius_x, |
259 float radius_y, | 245 float radius_y, |
260 float angle, | 246 float angle, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 }; | 284 }; |
299 | 285 |
300 //////////////////////////////////////////////////////////////////////////////// | 286 //////////////////////////////////////////////////////////////////////////////// |
301 // KeyEvent class | 287 // KeyEvent class |
302 // | 288 // |
303 // KeyEvent encapsulates keyboard input events - key press and release. | 289 // KeyEvent encapsulates keyboard input events - key press and release. |
304 // | 290 // |
305 //////////////////////////////////////////////////////////////////////////////// | 291 //////////////////////////////////////////////////////////////////////////////// |
306 class VIEWS_EXPORT KeyEvent : public Event { | 292 class VIEWS_EXPORT KeyEvent : public Event { |
307 public: | 293 public: |
308 explicit KeyEvent(NativeEvent native_event); | 294 explicit KeyEvent(const NativeEvent& native_event); |
309 KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 295 KeyEvent(const NativeEvent2& native_event_2, FromNativeEvent2 from_native); |
310 | 296 |
311 // Creates a new KeyEvent synthetically (i.e. not in response to an input | 297 // Creates a new KeyEvent synthetically (i.e. not in response to an input |
312 // event from the host environment). This is typically only used in testing as | 298 // event from the host environment). This is typically only used in testing as |
313 // some metadata obtainable from the underlying native event is not present. | 299 // some metadata obtainable from the underlying native event is not present. |
314 // It's also used by input methods to fabricate keyboard events. | 300 // It's also used by input methods to fabricate keyboard events. |
315 KeyEvent(ui::EventType type, | 301 KeyEvent(ui::EventType type, |
316 ui::KeyboardCode key_code, | 302 ui::KeyboardCode key_code, |
317 int event_flags); | 303 int event_flags); |
318 | 304 |
319 ui::KeyboardCode key_code() const { return key_code_; } | 305 ui::KeyboardCode key_code() const { return key_code_; } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // | 360 // |
375 // A MouseWheelEvent is used to propagate mouse wheel user events. | 361 // A MouseWheelEvent is used to propagate mouse wheel user events. |
376 // Note: e.GetOffset() > 0 means scroll up / left. | 362 // Note: e.GetOffset() > 0 means scroll up / left. |
377 // | 363 // |
378 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
379 class VIEWS_EXPORT MouseWheelEvent : public MouseEvent { | 365 class VIEWS_EXPORT MouseWheelEvent : public MouseEvent { |
380 public: | 366 public: |
381 // See |offset| for details. | 367 // See |offset| for details. |
382 static const int kWheelDelta; | 368 static const int kWheelDelta; |
383 | 369 |
384 explicit MouseWheelEvent(NativeEvent native_event); | 370 explicit MouseWheelEvent(const NativeEvent& native_event); |
385 MouseWheelEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 371 MouseWheelEvent(const NativeEvent2& native_event_2, |
| 372 FromNativeEvent2 from_native); |
386 | 373 |
387 // The amount to scroll. This is in multiples of kWheelDelta. | 374 // The amount to scroll. This is in multiples of kWheelDelta. |
388 int offset() const { return offset_; } | 375 int offset() const { return offset_; } |
389 | 376 |
390 private: | 377 private: |
391 friend class internal::RootView; | 378 friend class internal::RootView; |
392 friend class internal::NativeWidgetView; | 379 friend class internal::NativeWidgetView; |
393 | 380 |
394 MouseWheelEvent(const MouseWheelEvent& model, View* root) | 381 MouseWheelEvent(const MouseWheelEvent& model, View* root) |
395 : MouseEvent(model, root), | 382 : MouseEvent(model, root), |
396 offset_(model.offset_) { | 383 offset_(model.offset_) { |
397 } | 384 } |
398 | 385 |
399 int offset_; | 386 int offset_; |
400 | 387 |
401 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); | 388 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); |
402 }; | 389 }; |
403 | 390 |
404 //////////////////////////////////////////////////////////////////////////////// | 391 //////////////////////////////////////////////////////////////////////////////// |
405 // | 392 // |
406 // DropTargetEvent class | 393 // DropTargetEvent class |
407 // | 394 // |
408 // A DropTargetEvent is sent to the view the mouse is over during a drag and | 395 // A DropTargetEvent is sent to the view the mouse is over during a drag and |
409 // drop operation. | 396 // drop operation. |
410 // | 397 // |
411 //////////////////////////////////////////////////////////////////////////////// | 398 //////////////////////////////////////////////////////////////////////////////// |
412 class VIEWS_EXPORT DropTargetEvent : public LocatedEvent { | 399 class VIEWS_EXPORT DropTargetEvent : public LocatedEvent { |
413 public: | 400 public: |
414 DropTargetEvent(const OSExchangeData& data, | 401 DropTargetEvent(const ui::OSExchangeData& data, |
415 int x, | 402 int x, |
416 int y, | 403 int y, |
417 int source_operations) | 404 int source_operations) |
418 : LocatedEvent(ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0), | 405 : LocatedEvent(ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0), |
419 data_(data), | 406 data_(data), |
420 source_operations_(source_operations) { | 407 source_operations_(source_operations) { |
421 // TODO(msw): Hook up key state flags for CTRL + drag and drop, etc. | 408 // TODO(msw): Hook up key state flags for CTRL + drag and drop, etc. |
422 } | 409 } |
423 | 410 |
424 const OSExchangeData& data() const { return data_; } | 411 const ui::OSExchangeData& data() const { return data_; } |
425 int source_operations() const { return source_operations_; } | 412 int source_operations() const { return source_operations_; } |
426 | 413 |
427 private: | 414 private: |
428 // Data associated with the drag/drop session. | 415 // Data associated with the drag/drop session. |
429 const OSExchangeData& data_; | 416 const ui::OSExchangeData& data_; |
430 | 417 |
431 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. | 418 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. |
432 int source_operations_; | 419 int source_operations_; |
433 | 420 |
434 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 421 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
435 }; | 422 }; |
436 | 423 |
437 } // namespace views | 424 } // namespace views |
438 | 425 |
439 #endif // VIEWS_EVENTS_EVENT_H_ | 426 #endif // VIEWS_EVENTS_EVENT_H_ |
OLD | NEW |