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

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

Issue 10827271: Replace views::Event with ui::Event. (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_result_list_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"
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
23 class UI_EXPORT Event { 29 class UI_EXPORT Event {
24 public: 30 public:
25 virtual ~Event(); 31 virtual ~Event();
26 32
27 // For testing. 33 // For testing.
28 class TestApi { 34 class TestApi {
29 public: 35 public:
30 explicit TestApi(Event* event) : event_(event) {} 36 explicit TestApi(Event* event) : event_(event) {}
31 37
32 void set_time_stamp(const base::TimeDelta& time_stamp) { 38 void set_time_stamp(const base::TimeDelta& time_stamp) {
33 event_->time_stamp_ = time_stamp; 39 event_->time_stamp_ = time_stamp;
34 } 40 }
35 41
36 private: 42 private:
37 TestApi(); 43 TestApi();
38 Event* event_; 44 Event* event_;
39 }; 45 };
40 46
41 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_; }
42 EventType type() const { return type_; } 49 EventType type() const { return type_; }
43 // time_stamp represents time since machine was booted. 50 // time_stamp represents time since machine was booted.
44 const base::TimeDelta& time_stamp() const { return time_stamp_; } 51 const base::TimeDelta& time_stamp() const { return time_stamp_; }
45 int flags() const { return flags_; } 52 int flags() const { return flags_; }
46 53
47 // 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
48 // events in EventFilter::PreHandleKeyEvent(). 55 // events in EventFilter::PreHandleKeyEvent().
49 void set_flags(int flags) { flags_ = flags; } 56 void set_flags(int flags) { flags_ = flags; }
50 57
51 // 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
52 // the time the event was created. 59 // the time the event was created.
53 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } 60 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; }
54 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } 61 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; }
55 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; } 62 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; }
56 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } 63 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; }
57 64
65 bool IsMouseEvent() const {
66 return type_ == ui::ET_MOUSE_PRESSED ||
67 type_ == ui::ET_MOUSE_DRAGGED ||
68 type_ == ui::ET_MOUSE_RELEASED ||
69 type_ == ui::ET_MOUSE_MOVED ||
70 type_ == ui::ET_MOUSE_ENTERED ||
71 type_ == ui::ET_MOUSE_EXITED ||
72 type_ == ui::ET_MOUSEWHEEL;
73 }
74
75 bool IsTouchEvent() const {
76 return type_ == ui::ET_TOUCH_RELEASED ||
77 type_ == ui::ET_TOUCH_PRESSED ||
78 type_ == ui::ET_TOUCH_MOVED ||
79 type_ == ui::ET_TOUCH_STATIONARY ||
80 type_ == ui::ET_TOUCH_CANCELLED;
81 }
82
83 bool IsScrollGestureEvent() const {
84 return type_ == ui::ET_GESTURE_SCROLL_BEGIN ||
85 type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
86 type_ == ui::ET_GESTURE_SCROLL_END;
87 }
88
89 bool IsFlingScrollEvent() const {
90 return type_ == ui::ET_SCROLL_FLING_CANCEL ||
91 type_ == ui::ET_SCROLL_FLING_START;
92 }
93
58 // Returns true if the event has a valid |native_event_|. 94 // Returns true if the event has a valid |native_event_|.
59 bool HasNativeEvent() const; 95 bool HasNativeEvent() const;
60 96
61 protected: 97 protected:
62 Event(EventType type, int flags); 98 Event(EventType type, int flags);
63 Event(const base::NativeEvent& native_event, EventType type, int flags); 99 Event(const base::NativeEvent& native_event, EventType type, int flags);
64 Event(const Event& copy); 100 Event(const Event& copy);
65 void set_type(EventType type) { type_ = type; } 101 void set_type(EventType type) { type_ = type; }
66 void set_delete_native_event(bool delete_native_event) { 102 void set_delete_native_event(bool delete_native_event) {
67 delete_native_event_ = delete_native_event; 103 delete_native_event_ = delete_native_event;
68 } 104 }
69 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; }
70 106
71 private: 107 private:
72 void operator=(const Event&); 108 void operator=(const Event&);
73 109
74 // Safely initializes the native event members of this class. 110 // Safely initializes the native event members of this class.
75 void Init(); 111 void Init();
76 void InitWithNativeEvent(const base::NativeEvent& native_event); 112 void InitWithNativeEvent(const base::NativeEvent& native_event);
77 113
78 base::NativeEvent native_event_; 114 base::NativeEvent native_event_;
115 // TODO(beng): check to see if this is necessary.
116 ui::NativeEvent ui_native_event_;
79 EventType type_; 117 EventType type_;
80 base::TimeDelta time_stamp_; 118 base::TimeDelta time_stamp_;
81 int flags_; 119 int flags_;
82 bool delete_native_event_; 120 bool delete_native_event_;
83 }; 121 };
84 122
85 class UI_EXPORT LocatedEvent : public Event { 123 class UI_EXPORT LocatedEvent : public Event {
86 public: 124 public:
87 // For testing. 125 // For testing.
88 class TestApi : public Event::TestApi { 126 class TestApi : public Event::TestApi {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // This value is stored as a bitfield because the number of touch ids varies, 446 // This value is stored as a bitfield because the number of touch ids varies,
409 // but we currently don't need more than 32 touches at a time. 447 // but we currently don't need more than 32 touches at a time.
410 const unsigned int touch_ids_bitfield_; 448 const unsigned int touch_ids_bitfield_;
411 449
412 DISALLOW_COPY_AND_ASSIGN(GestureEvent); 450 DISALLOW_COPY_AND_ASSIGN(GestureEvent);
413 }; 451 };
414 452
415 } // namespace ui 453 } // namespace ui
416 454
417 #endif // UI_BASE_EVENT_H_ 455 #endif // UI_BASE_EVENT_H_
OLDNEW
« no previous file with comments | « ui/app_list/search_result_list_view.cc ('k') | ui/base/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698