Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Side by Side Diff: ui/base/event.h

Issue 10824295: Rid the world of the last of views::Event types: TouchEvent, GestureEvent, MouseWheelEvent, ScrollE… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/app_list/search_box_view.cc ('k') | ui/base/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 27 matching lines...) Expand all
38 void set_time_stamp(const base::TimeDelta& time_stamp) { 38 void set_time_stamp(const base::TimeDelta& time_stamp) {
39 event_->time_stamp_ = time_stamp; 39 event_->time_stamp_ = time_stamp;
40 } 40 }
41 41
42 private: 42 private:
43 TestApi(); 43 TestApi();
44 Event* event_; 44 Event* event_;
45 }; 45 };
46 46
47 const base::NativeEvent& native_event() const { return native_event_; } 47 const base::NativeEvent& native_event() const { return native_event_; }
48 const ui::NativeEvent& ui_native_event() const { return ui_native_event_; } 48 const NativeEvent& ui_native_event() const { return ui_native_event_; }
49 EventType type() const { return type_; } 49 EventType type() const { return type_; }
50 // time_stamp represents time since machine was booted. 50 // time_stamp represents time since machine was booted.
51 const base::TimeDelta& time_stamp() const { return time_stamp_; } 51 const base::TimeDelta& time_stamp() const { return time_stamp_; }
52 int flags() const { return flags_; } 52 int flags() const { return flags_; }
53 53
54 // This is only intended to be used externally by classes that are modifying 54 // This is only intended to be used externally by classes that are modifying
55 // events in EventFilter::PreHandleKeyEvent(). 55 // events in EventFilter::PreHandleKeyEvent().
56 void set_flags(int flags) { flags_ = flags; } 56 void set_flags(int flags) { flags_ = flags; }
57 57
58 // The following methods return true if the respective keys were pressed at 58 // The following methods return true if the respective keys were pressed at
59 // the time the event was created. 59 // the time the event was created.
60 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } 60 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; }
61 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } 61 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; }
62 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; } 62 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; }
63 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } 63 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; }
64 64
65 bool IsMouseEvent() const { 65 bool IsMouseEvent() const {
66 return type_ == ui::ET_MOUSE_PRESSED || 66 return type_ == ET_MOUSE_PRESSED ||
67 type_ == ui::ET_MOUSE_DRAGGED || 67 type_ == ET_MOUSE_DRAGGED ||
68 type_ == ui::ET_MOUSE_RELEASED || 68 type_ == ET_MOUSE_RELEASED ||
69 type_ == ui::ET_MOUSE_MOVED || 69 type_ == ET_MOUSE_MOVED ||
70 type_ == ui::ET_MOUSE_ENTERED || 70 type_ == ET_MOUSE_ENTERED ||
71 type_ == ui::ET_MOUSE_EXITED || 71 type_ == ET_MOUSE_EXITED ||
72 type_ == ui::ET_MOUSEWHEEL; 72 type_ == ET_MOUSEWHEEL;
73 } 73 }
74 74
75 bool IsTouchEvent() const { 75 bool IsTouchEvent() const {
76 return type_ == ui::ET_TOUCH_RELEASED || 76 return type_ == ET_TOUCH_RELEASED ||
77 type_ == ui::ET_TOUCH_PRESSED || 77 type_ == ET_TOUCH_PRESSED ||
78 type_ == ui::ET_TOUCH_MOVED || 78 type_ == ET_TOUCH_MOVED ||
79 type_ == ui::ET_TOUCH_STATIONARY || 79 type_ == ET_TOUCH_STATIONARY ||
80 type_ == ui::ET_TOUCH_CANCELLED; 80 type_ == ET_TOUCH_CANCELLED;
81 } 81 }
82 82
83 bool IsScrollGestureEvent() const { 83 bool IsScrollGestureEvent() const {
84 return type_ == ui::ET_GESTURE_SCROLL_BEGIN || 84 return type_ == ET_GESTURE_SCROLL_BEGIN ||
85 type_ == ui::ET_GESTURE_SCROLL_UPDATE || 85 type_ == ET_GESTURE_SCROLL_UPDATE ||
86 type_ == ui::ET_GESTURE_SCROLL_END; 86 type_ == ET_GESTURE_SCROLL_END;
87 } 87 }
88 88
89 bool IsFlingScrollEvent() const { 89 bool IsFlingScrollEvent() const {
90 return type_ == ui::ET_SCROLL_FLING_CANCEL || 90 return type_ == ET_SCROLL_FLING_CANCEL ||
91 type_ == ui::ET_SCROLL_FLING_START; 91 type_ == ET_SCROLL_FLING_START;
92 } 92 }
93 93
94 // Returns true if the event has a valid |native_event_|. 94 // Returns true if the event has a valid |native_event_|.
95 bool HasNativeEvent() const; 95 bool HasNativeEvent() const;
96 96
97 protected: 97 protected:
98 Event(EventType type, int flags); 98 Event(EventType type, int flags);
99 Event(const base::NativeEvent& native_event, EventType type, int flags); 99 Event(const base::NativeEvent& native_event, EventType type, int flags);
100 Event(const Event& copy); 100 Event(const Event& copy);
101 void set_type(EventType type) { type_ = type; } 101 void set_type(EventType type) { type_ = type; }
102 void set_delete_native_event(bool delete_native_event) { 102 void set_delete_native_event(bool delete_native_event) {
103 delete_native_event_ = delete_native_event; 103 delete_native_event_ = delete_native_event;
104 } 104 }
105 void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; } 105 void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; }
106 106
107 private: 107 private:
108 void operator=(const Event&); 108 void operator=(const Event&);
109 109
110 // Safely initializes the native event members of this class. 110 // Safely initializes the native event members of this class.
111 void Init(); 111 void Init();
112 void InitWithNativeEvent(const base::NativeEvent& native_event); 112 void InitWithNativeEvent(const base::NativeEvent& native_event);
113 113
114 base::NativeEvent native_event_; 114 base::NativeEvent native_event_;
115 // TODO(beng): check to see if this is necessary. 115 // TODO(beng): check to see if this is necessary.
116 ui::NativeEvent ui_native_event_; 116 NativeEvent ui_native_event_;
117 EventType type_; 117 EventType type_;
118 base::TimeDelta time_stamp_; 118 base::TimeDelta time_stamp_;
119 int flags_; 119 int flags_;
120 bool delete_native_event_; 120 bool delete_native_event_;
121 }; 121 };
122 122
123 class UI_EXPORT LocatedEvent : public Event { 123 class UI_EXPORT LocatedEvent : public Event {
124 public: 124 public:
125 // For testing. 125 // For testing.
126 class TestApi : public Event::TestApi { 126 class TestApi : public Event::TestApi {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 202 }
203 203
204 // Used for synthetic events in testing and by the gesture recognizer. 204 // Used for synthetic events in testing and by the gesture recognizer.
205 MouseEvent(EventType type, 205 MouseEvent(EventType type,
206 const gfx::Point& location, 206 const gfx::Point& location,
207 const gfx::Point& root_location, 207 const gfx::Point& root_location,
208 int flags); 208 int flags);
209 209
210 // Conveniences to quickly test what button is down 210 // Conveniences to quickly test what button is down
211 bool IsOnlyLeftMouseButton() const { 211 bool IsOnlyLeftMouseButton() const {
212 return (flags() & ui::EF_LEFT_MOUSE_BUTTON) && 212 return (flags() & EF_LEFT_MOUSE_BUTTON) &&
213 !(flags() & (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); 213 !(flags() & (EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON));
214 } 214 }
215 215
216 bool IsLeftMouseButton() const { 216 bool IsLeftMouseButton() const {
217 return (flags() & ui::EF_LEFT_MOUSE_BUTTON) != 0; 217 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0;
218 } 218 }
219 219
220 bool IsOnlyMiddleMouseButton() const { 220 bool IsOnlyMiddleMouseButton() const {
221 return (flags() & ui::EF_MIDDLE_MOUSE_BUTTON) && 221 return (flags() & EF_MIDDLE_MOUSE_BUTTON) &&
222 !(flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); 222 !(flags() & (EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON));
223 } 223 }
224 224
225 bool IsMiddleMouseButton() const { 225 bool IsMiddleMouseButton() const {
226 return (flags() & ui::EF_MIDDLE_MOUSE_BUTTON) != 0; 226 return (flags() & EF_MIDDLE_MOUSE_BUTTON) != 0;
227 } 227 }
228 228
229 bool IsOnlyRightMouseButton() const { 229 bool IsOnlyRightMouseButton() const {
230 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) && 230 return (flags() & EF_RIGHT_MOUSE_BUTTON) &&
231 !(flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON)); 231 !(flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON));
232 } 232 }
233 233
234 bool IsRightMouseButton() const { 234 bool IsRightMouseButton() const {
235 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) != 0; 235 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0;
236 } 236 }
237 237
238 // Compares two mouse down events and returns true if the second one should 238 // Compares two mouse down events and returns true if the second one should
239 // be considered a repeat of the first. 239 // be considered a repeat of the first.
240 static bool IsRepeatedClickEvent( 240 static bool IsRepeatedClickEvent(
241 const MouseEvent& event1, 241 const MouseEvent& event1,
242 const MouseEvent& event2); 242 const MouseEvent& event2);
243 243
244 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. 244 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
245 int GetClickCount() const; 245 int GetClickCount() const;
246 246
247 // Set the click count for a mousedown message. Can be 1, 2 or 3. 247 // Set the click count for a mousedown message. Can be 1, 2 or 3.
248 void SetClickCount(int click_count); 248 void SetClickCount(int click_count);
249 249
250 protected: 250 protected:
251 explicit MouseEvent(const MouseEvent& model); 251 explicit MouseEvent(const MouseEvent& model);
252 252
253 private: 253 private:
254 gfx::Point root_location_; 254 gfx::Point root_location_;
255 255
256 static MouseEvent* last_click_event_; 256 static MouseEvent* last_click_event_;
257 // Returns the repeat count based on the previous mouse click, if it is 257 // Returns the repeat count based on the previous mouse click, if it is
258 // recent enough and within a small enough distance. 258 // recent enough and within a small enough distance.
259 static int GetRepeatCount(const MouseEvent& click_event); 259 static int GetRepeatCount(const MouseEvent& click_event);
260 }; 260 };
261 261
262 class ScrollEvent;
263
264 class UI_EXPORT MouseWheelEvent : public MouseEvent {
265 public:
266 // See |offset| for details.
267 static const int kWheelDelta;
268
269 explicit MouseWheelEvent(const NativeEvent& native_event);
270 explicit MouseWheelEvent(const ScrollEvent& scroll_event);
271
272 // The amount to scroll. This is in multiples of kWheelDelta.
273 // Note: offset() > 0 means scroll up / left.
274 int offset() const { return offset_; }
275
276 private:
277 int offset_;
278
279 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent);
280 };
281
262 class UI_EXPORT TouchEvent : public LocatedEvent { 282 class UI_EXPORT TouchEvent : public LocatedEvent {
263 public: 283 public:
264 explicit TouchEvent(const base::NativeEvent& native_event); 284 explicit TouchEvent(const base::NativeEvent& native_event);
265 285
266 // Create a new TouchEvent which is identical to the provided model. 286 // Create a new TouchEvent which is identical to the provided model.
267 // If source / target windows are provided, the model location will be 287 // If source / target windows are provided, the model location will be
268 // converted from |source| coordinate system to |target| coordinate system. 288 // converted from |source| coordinate system to |target| coordinate system.
269 template <class T> 289 template <class T>
270 TouchEvent(const TouchEvent& model, T* source, T* target) 290 TouchEvent(const TouchEvent& model, T* source, T* target)
271 : LocatedEvent(model, source, target), 291 : LocatedEvent(model, source, target),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 341
322 // Angle of the major axis away from the X axis. Default 0.0. 342 // Angle of the major axis away from the X axis. Default 0.0.
323 float rotation_angle_; 343 float rotation_angle_;
324 344
325 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. 345 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
326 float force_; 346 float force_;
327 347
328 DISALLOW_COPY_AND_ASSIGN(TouchEvent); 348 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
329 }; 349 };
330 350
351 class UI_EXPORT TestTouchEvent : public TouchEvent {
352 public:
353 // Create a new touch event.
354 TestTouchEvent(EventType type,
355 int x,
356 int y,
357 int flags,
358 int touch_id,
359 float radius_x,
360 float radius_y,
361 float angle,
362 float force);
363 private:
364 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent);
365 };
366
331 class UI_EXPORT KeyEvent : public Event { 367 class UI_EXPORT KeyEvent : public Event {
332 public: 368 public:
333 KeyEvent(const base::NativeEvent& native_event, bool is_char); 369 KeyEvent(const base::NativeEvent& native_event, bool is_char);
334 370
335 // Used for synthetic events in testing. 371 // Used for synthetic events in testing.
336 KeyEvent(EventType type, KeyboardCode key_code, int flags); 372 KeyEvent(EventType type, KeyboardCode key_code, int flags);
337 373
338 // These setters allow an I18N virtual keyboard to fabricate a keyboard event 374 // These setters allow an I18N virtual keyboard to fabricate a keyboard event
339 // which does not have a corresponding KeyboardCode (example: U+00E1 Latin 375 // which does not have a corresponding KeyboardCode (example: U+00E1 Latin
340 // small letter A with acute, U+0410 Cyrillic capital letter A.) 376 // small letter A with acute, U+0410 Cyrillic capital letter A.)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // This value is stored as a bitfield because the number of touch ids varies, 511 // This value is stored as a bitfield because the number of touch ids varies,
476 // but we currently don't need more than 32 touches at a time. 512 // but we currently don't need more than 32 touches at a time.
477 const unsigned int touch_ids_bitfield_; 513 const unsigned int touch_ids_bitfield_;
478 514
479 DISALLOW_COPY_AND_ASSIGN(GestureEvent); 515 DISALLOW_COPY_AND_ASSIGN(GestureEvent);
480 }; 516 };
481 517
482 } // namespace ui 518 } // namespace ui
483 519
484 #endif // UI_BASE_EVENT_H_ 520 #endif // UI_BASE_EVENT_H_
OLDNEW
« no previous file with comments | « ui/app_list/search_box_view.cc ('k') | ui/base/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698