OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_VIEWS_EVENT_H_ | |
sky
2011/02/01 18:56:22
VIEWS_EVENTS
| |
6 #define UI_VIEWS_EVENT_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "gfx/point.h" | |
11 #include "ui/base/keycodes/keyboard_codes.h" | |
12 #include "ui/views/native_types.h" | |
13 | |
14 class OSExchangeData; | |
15 | |
16 namespace ui { | |
17 | |
18 class View; | |
19 | |
20 class Event { | |
21 public: | |
22 // Event types. | |
23 enum EventType { ET_UNKNOWN = 0, | |
24 ET_MOUSE_PRESSED, | |
25 ET_MOUSE_DRAGGED, | |
26 ET_MOUSE_RELEASED, | |
27 ET_MOUSE_MOVED, | |
28 ET_MOUSE_ENTERED, | |
29 ET_MOUSE_EXITED, | |
30 ET_KEY_PRESSED, | |
31 ET_KEY_RELEASED, | |
32 ET_MOUSEWHEEL, | |
33 ET_DROP_TARGET_EVENT }; | |
34 | |
35 // Event flags currently supported. Although this is a "views" | |
36 // file, this header is used on non-views platforms (e.g. OSX). For | |
37 // example, these EventFlags are used by the automation provider for | |
38 // all platforms. | |
39 enum EventFlags { EF_CAPS_LOCK_DOWN = 1 << 0, | |
40 EF_SHIFT_DOWN = 1 << 1, | |
41 EF_CONTROL_DOWN = 1 << 2, | |
42 EF_ALT_DOWN = 1 << 3, | |
43 EF_LEFT_BUTTON_DOWN = 1 << 4, | |
44 EF_MIDDLE_BUTTON_DOWN = 1 << 5, | |
45 EF_RIGHT_BUTTON_DOWN = 1 << 6, | |
46 EF_COMMAND_DOWN = 1 << 7, // Only useful on OSX | |
47 }; | |
48 | |
49 EventType type() const { return type_; } | |
50 int flags() const { return flags_; } | |
51 void set_flags(int flags) { flags_ = flags; } | |
52 | |
53 // The following methods return true if the respective keys were pressed at | |
54 // the time the event was created. | |
55 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } | |
sky
2011/02/01 18:56:22
I think all this should be named unix_hacker_style
| |
56 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } | |
57 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; } | |
58 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } | |
59 | |
60 // Returns true if the event is any kind of mouse event. | |
61 bool IsMouseEvent() const { | |
62 return type_ == ET_MOUSE_PRESSED || | |
63 type_ == ET_MOUSE_RELEASED || | |
64 type_ == ET_MOUSE_MOVED || | |
65 type_ == ET_MOUSE_EXITED || | |
66 type_ == ET_MOUSEWHEEL; | |
67 } | |
68 | |
69 protected: | |
70 Event(EventType type, int flags); | |
71 | |
72 private: | |
73 EventType type_; | |
74 int flags_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(Event); | |
77 }; | |
78 | |
79 class LocatedEvent : public Event { | |
80 public: | |
81 int x() const { return location_.x(); } | |
82 int y() const { return location_.y(); } | |
83 const gfx::Point& location() const { return location_; } | |
84 | |
85 protected: | |
86 LocatedEvent(EventType type, const gfx::Point& location, int flags); | |
87 | |
88 LocatedEvent(const LocatedEvent& other, View* source, View* target); | |
sky
2011/02/01 18:56:22
This is worth documenting.
| |
89 | |
90 private: | |
91 gfx::Point location_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(LocatedEvent); | |
94 }; | |
95 | |
96 class MouseEvent : public LocatedEvent { | |
97 public: | |
98 // Flags specific to mouse events | |
99 enum MouseEventFlags { | |
100 EF_IS_DOUBLE_CLICK = 1 << 16, | |
101 EF_IS_NON_CLIENT = 1 << 17 | |
102 }; | |
103 | |
104 MouseEvent(NativeEvent native_event); | |
sky
2011/02/01 18:56:22
explicit
| |
105 | |
106 MouseEvent(const MouseEvent& other, View* source, View* target); | |
107 | |
108 // Conveniences to quickly test what button is down: | |
109 bool IsOnlyLeftMouseButton() const { | |
110 return (flags() & EF_LEFT_BUTTON_DOWN) && | |
111 !(flags() & (EF_MIDDLE_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN)); | |
112 } | |
113 bool IsLeftMouseButton() const { | |
114 return (flags() & EF_LEFT_BUTTON_DOWN) != 0; | |
115 } | |
116 bool IsOnlyMiddleMouseButton() const { | |
117 return (flags() & EF_MIDDLE_BUTTON_DOWN) && | |
118 !(flags() & (EF_LEFT_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN)); | |
119 } | |
120 bool IsMiddleMouseButton() const { | |
121 return (flags() & EF_MIDDLE_BUTTON_DOWN) != 0; | |
122 } | |
123 bool IsOnlyRightMouseButton() const { | |
124 return (flags() & EF_RIGHT_BUTTON_DOWN) && | |
125 !(flags() & (EF_LEFT_BUTTON_DOWN | EF_MIDDLE_BUTTON_DOWN)); | |
126 } | |
127 bool IsRightMouseButton() const { | |
128 return (flags() & EF_RIGHT_BUTTON_DOWN) != 0; | |
129 } | |
130 | |
131 private: | |
132 DISALLOW_COPY_AND_ASSIGN(MouseEvent); | |
133 }; | |
134 | |
135 class KeyEvent : public Event { | |
136 public: | |
137 KeyEvent(NativeEvent native_event); | |
sky
2011/02/01 18:56:22
explicit
| |
138 | |
139 KeyboardCode key_code() const { return key_code_; } | |
140 | |
141 int repeat_count() const { return repeat_count_; } | |
142 | |
143 private: | |
144 KeyboardCode key_code_; | |
145 int repeat_count_; | |
146 int message_flags_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(KeyEvent); | |
149 }; | |
150 | |
151 class MouseWheelEvent : public LocatedEvent { | |
152 public: | |
153 MouseWheelEvent(NativeEvent native_event); | |
sky
2011/02/01 18:56:22
explicit
| |
154 | |
155 int offset() const { return offset_; } | |
156 | |
157 private: | |
158 int offset_; | |
159 | |
160 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); | |
161 }; | |
162 | |
163 /* | |
sky
2011/02/01 18:56:22
Did you mean to leave this commented out?
Ben Goodger (Google)
2011/02/01 20:04:57
Yes I have not tested it yet.
| |
164 class DropTargetEvent : public LocatedEvent { | |
165 public: | |
166 DropTargetEvent(NativeEvent native_event); | |
167 | |
168 const OSExchangeData& data() const { return data_; } | |
169 int source_operations() const { return source_operations_; } | |
170 | |
171 private: | |
172 const OSExchangeData& data_; | |
173 int source_operations_; | |
174 | |
175 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | |
176 }; | |
177 */ | |
178 | |
179 } // namespace ui | |
180 | |
181 #endif // UI_VIEWS_EVENT_H_ | |
OLD | NEW |