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

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

Issue 10827145: Convert Aura to use 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/aura/desktop/desktop_activation_client.cc ('k') | ui/aura/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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_AURA_EVENT_H_
6 #define UI_AURA_EVENT_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/event_types.h"
11 #include "base/logging.h"
12 #include "base/time.h"
13 #include "ui/aura/aura_export.h"
14 #include "ui/base/dragdrop/os_exchange_data.h"
15 #include "ui/base/events.h"
16 #include "ui/base/gestures/gesture_types.h"
17 #include "ui/base/keycodes/keyboard_codes.h"
18 #include "ui/gfx/point.h"
19
20 namespace ui {
21 class Transform;
22 }
23
24 namespace aura {
25
26 class Window;
27
28 class AURA_EXPORT Event {
29 public:
30 virtual ~Event();
31
32 // For testing.
33 class TestApi {
34 public:
35 explicit TestApi(Event* event) : event_(event) {}
36
37 void set_time_stamp(const base::TimeDelta& time_stamp) {
38 event_->time_stamp_ = time_stamp;
39 }
40
41 private:
42 TestApi();
43 Event* event_;
44 };
45
46 const base::NativeEvent& native_event() const { return native_event_; }
47 ui::EventType type() const { return type_; }
48 // time_stamp represents time since machine was booted.
49 const base::TimeDelta& time_stamp() const { return time_stamp_; }
50 int flags() const { return flags_; }
51
52 // This is only intended to be used externally by classes that are modifying
53 // events in EventFilter::PreHandleKeyEvent().
54 void set_flags(int flags) { flags_ = flags; }
55
56 // The following methods return true if the respective keys were pressed at
57 // the time the event was created.
58 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; }
59 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; }
60 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; }
61 bool IsAltDown() const { return (flags_ & ui::EF_ALT_DOWN) != 0; }
62
63 // Returns true if the event has a valid |native_event_|.
64 bool HasNativeEvent() const;
65
66 protected:
67 Event(ui::EventType type, int flags);
68 Event(const base::NativeEvent& native_event, ui::EventType type, int flags);
69 Event(const Event& copy);
70 void set_type(ui::EventType type) { type_ = type; }
71 void set_delete_native_event(bool delete_native_event) {
72 delete_native_event_ = delete_native_event;
73 }
74 void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; }
75
76 private:
77 void operator=(const Event&);
78
79 // Safely initializes the native event members of this class.
80 void Init();
81 void InitWithNativeEvent(const base::NativeEvent& native_event);
82
83 base::NativeEvent native_event_;
84 ui::EventType type_;
85 base::TimeDelta time_stamp_;
86 int flags_;
87 bool delete_native_event_;
88 };
89
90 class AURA_EXPORT LocatedEvent : public Event {
91 public:
92 // For testing.
93 class TestApi : public Event::TestApi {
94 public:
95 explicit TestApi(LocatedEvent* located_event)
96 : Event::TestApi(located_event),
97 located_event_(located_event) {}
98
99 void set_location(const gfx::Point& location) {
100 located_event_->location_ = location;
101 }
102
103 private:
104 TestApi();
105 LocatedEvent* located_event_;
106 };
107
108 virtual ~LocatedEvent();
109
110 int x() const { return location_.x(); }
111 int y() const { return location_.y(); }
112 gfx::Point location() const { return location_; }
113 gfx::Point root_location() const { return root_location_; }
114
115 // Applies |root_transform| to the event.
116 // This is applied to both |location_| and |root_location_|.
117 virtual void UpdateForRootTransform(const ui::Transform& root_transform);
118
119 protected:
120 explicit LocatedEvent(const base::NativeEvent& native_event);
121
122 // Create a new LocatedEvent which is identical to the provided model.
123 // If source / target windows are provided, the model location will be
124 // converted from |source| coordinate system to |target| coordinate system.
125 LocatedEvent(const LocatedEvent& model, Window* source, Window* target);
126
127 // Used for synthetic events in testing.
128 LocatedEvent(ui::EventType type,
129 const gfx::Point& location,
130 const gfx::Point& root_location,
131 int flags);
132
133 gfx::Point location_;
134
135 gfx::Point root_location_;
136
137 private:
138 DISALLOW_COPY_AND_ASSIGN(LocatedEvent);
139 };
140
141 class AURA_EXPORT MouseEvent : public LocatedEvent {
142 public:
143 explicit MouseEvent(const base::NativeEvent& native_event);
144
145 // Create a new MouseEvent based on the provided model.
146 // Uses the provided |type| and |flags| for the new event.
147 // If source / target windows are provided, the model location will be
148 // converted from |source| coordinate system to |target| coordinate system.
149 MouseEvent(const MouseEvent& model, Window* source, Window* target);
150 MouseEvent(const MouseEvent& model,
151 Window* source,
152 Window* target,
153 ui::EventType type,
154 int flags);
155
156 // Used for synthetic events in testing and by the gesture recognizer.
157 MouseEvent(ui::EventType type,
158 const gfx::Point& location,
159 const gfx::Point& root_location,
160 int flags);
161
162 // Compares two mouse down events and returns true if the second one should
163 // be considered a repeat of the first.
164 static bool IsRepeatedClickEvent(
165 const MouseEvent& event1,
166 const MouseEvent& event2);
167
168 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
169 int GetClickCount() const;
170
171 // Set the click count for a mousedown message. Can be 1, 2 or 3.
172 void SetClickCount(int click_count);
173
174 private:
175 gfx::Point root_location_;
176
177 static MouseEvent* last_click_event_;
178 // Returns the repeat count based on the previous mouse click, if it is
179 // recent enough and within a small enough distance.
180 static int GetRepeatCount(const MouseEvent& click_event);
181
182 DISALLOW_COPY_AND_ASSIGN(MouseEvent);
183 };
184
185 class AURA_EXPORT TouchEvent : public LocatedEvent,
186 public ui::TouchEvent {
187 public:
188 explicit TouchEvent(const base::NativeEvent& native_event);
189
190 // Create a new TouchEvent which is identical to the provided model.
191 // If source / target windows are provided, the model location will be
192 // converted from |source| coordinate system to |target| coordinate system.
193 TouchEvent(const TouchEvent& model, Window* source, Window* target);
194
195 TouchEvent(ui::EventType type,
196 const gfx::Point& root_location,
197 int touch_id,
198 base::TimeDelta time_stamp);
199
200 virtual ~TouchEvent();
201
202 int touch_id() const { return touch_id_; }
203 float radius_x() const { return radius_x_; }
204 float radius_y() const { return radius_y_; }
205 float rotation_angle() const { return rotation_angle_; }
206 float force() const { return force_; }
207
208 // Used for unit tests.
209 void set_radius_x(const float r) { radius_x_ = r; }
210 void set_radius_y(const float r) { radius_y_ = r; }
211
212 // Overridden from LocatedEvent.
213 virtual void UpdateForRootTransform(
214 const ui::Transform& root_transform) OVERRIDE;
215
216 // Overridden from ui::TouchEvent.
217 virtual ui::EventType GetEventType() const OVERRIDE;
218 virtual gfx::Point GetLocation() const OVERRIDE;
219 virtual int GetTouchId() const OVERRIDE;
220 virtual int GetEventFlags() const OVERRIDE;
221 virtual base::TimeDelta GetTimestamp() const OVERRIDE;
222 virtual float RadiusX() const OVERRIDE;
223 virtual float RadiusY() const OVERRIDE;
224 virtual float RotationAngle() const OVERRIDE;
225 virtual float Force() const OVERRIDE;
226
227 private:
228 // The identity (typically finger) of the touch starting at 0 and incrementing
229 // for each separable additional touch that the hardware can detect.
230 const int touch_id_;
231
232 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
233 float radius_x_;
234
235 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
236 float radius_y_;
237
238 // Angle of the major axis away from the X axis. Default 0.0.
239 const float rotation_angle_;
240
241 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
242 const float force_;
243
244 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
245 };
246
247 class AURA_EXPORT KeyEvent : public Event {
248 public:
249 KeyEvent(const base::NativeEvent& native_event, bool is_char);
250
251 // Used for synthetic events in testing.
252 KeyEvent(ui::EventType type,
253 ui::KeyboardCode key_code,
254 int flags);
255
256 // These setters allow an I18N virtual keyboard to fabricate a keyboard event
257 // which does not have a corresponding ui::KeyboardCode (example: U+00E1 Latin
258 // small letter A with acute, U+0410 Cyrillic capital letter A.)
259 // GetCharacter() and GetUnmodifiedCharacter() return the character.
260 void set_character(uint16 character) { character_ = character; }
261 void set_unmodified_character(uint16 unmodified_character) {
262 unmodified_character_ = unmodified_character;
263 }
264
265 // Gets the character generated by this key event. It only supports Unicode
266 // BMP characters.
267 uint16 GetCharacter() const;
268
269 // Gets the character generated by this key event ignoring concurrently-held
270 // modifiers (except shift).
271 uint16 GetUnmodifiedCharacter() const;
272
273 // Returns the copy of this key event. Used in NativeWebKeyboardEvent.
274 KeyEvent* Copy();
275
276 ui::KeyboardCode key_code() const { return key_code_; }
277 bool is_char() const { return is_char_; }
278
279 // This is only intended to be used externally by classes that are modifying
280 // events in EventFilter::PreHandleKeyEvent(). set_character() should also be
281 // called.
282 void set_key_code(ui::KeyboardCode key_code) { key_code_ = key_code; }
283
284 private:
285 ui::KeyboardCode key_code_;
286 // True if this is a translated character event (vs. a raw key down). Both
287 // share the same type: ui::ET_KEY_PRESSED.
288 bool is_char_;
289
290 uint16 character_;
291 uint16 unmodified_character_;
292 };
293
294 // A key event which is translated by an input method (IME).
295 // For example, if an IME receives a KeyEvent(ui::VKEY_SPACE), and it does not
296 // consume the key, the IME usually generates and dispatches a
297 // TranslatedKeyEvent(ui::VKEY_SPACE) event. If the IME receives a KeyEvent and
298 // it does consume the event, it might dispatch a
299 // TranslatedKeyEvent(ui::VKEY_PROCESSKEY) event as defined in the DOM spec.
300 class AURA_EXPORT TranslatedKeyEvent : public aura::KeyEvent {
301 public:
302 TranslatedKeyEvent(const base::NativeEvent& native_event, bool is_char);
303
304 // Used for synthetic events such as a VKEY_PROCESSKEY key event.
305 TranslatedKeyEvent(bool is_press,
306 ui::KeyboardCode key_code,
307 int flags);
308
309 // Changes the type() of the object from ET_TRANSLATED_KEY_* to ET_KEY_* so
310 // that RenderWidgetHostViewAura and NativeWidgetAura could handle the event.
311 void ConvertToKeyEvent();
312 };
313
314 class AURA_EXPORT DropTargetEvent : public LocatedEvent {
315 public:
316 DropTargetEvent(const ui::OSExchangeData& data,
317 const gfx::Point& location,
318 const gfx::Point& root_location,
319 int source_operations)
320 : LocatedEvent(ui::ET_DROP_TARGET_EVENT, location, root_location, 0),
321 data_(data),
322 source_operations_(source_operations) {
323 }
324
325 const ui::OSExchangeData& data() const { return data_; }
326 int source_operations() const { return source_operations_; }
327
328 private:
329 // Data associated with the drag/drop session.
330 const ui::OSExchangeData& data_;
331
332 // Bitmask of supported ui::DragDropTypes::DragOperation by the source.
333 int source_operations_;
334
335 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
336 };
337
338 class AURA_EXPORT ScrollEvent : public MouseEvent {
339 public:
340 explicit ScrollEvent(const base::NativeEvent& native_event);
341 ScrollEvent(const ScrollEvent& model,
342 Window* source,
343 Window* target,
344 ui::EventType type,
345 int flags)
346 : MouseEvent(model, source, target, type, flags),
347 x_offset_(model.x_offset_),
348 y_offset_(model.y_offset_) {
349 }
350
351 float x_offset() const { return x_offset_; }
352 float y_offset() const { return y_offset_; }
353
354 private:
355 float x_offset_;
356 float y_offset_;
357
358 DISALLOW_COPY_AND_ASSIGN(ScrollEvent);
359 };
360
361 class AURA_EXPORT GestureEvent : public LocatedEvent,
362 public ui::GestureEvent {
363 public:
364 GestureEvent(ui::EventType type,
365 int x,
366 int y,
367 int flags,
368 base::Time time_stamp,
369 const ui::GestureEventDetails& details,
370 unsigned int touch_ids_bitfield);
371
372 // Create a new GestureEvent which is identical to the provided model.
373 // If source / target windows are provided, the model location will be
374 // converted from |source| coordinate system to |target| coordinate system.
375 GestureEvent(const GestureEvent& model, Window* source, Window* target);
376
377 virtual ~GestureEvent();
378
379 const ui::GestureEventDetails& details() const { return details_; }
380
381 // Returns the lowest touch-id of any of the touches which make up this
382 // gesture.
383 // If there are no touches associated with this gesture, returns -1.
384 virtual int GetLowestTouchId() const OVERRIDE;
385
386 private:
387 ui::GestureEventDetails details_;
388
389 // The set of indices of ones in the binary representation of
390 // touch_ids_bitfield_ is the set of touch_ids associate with this gesture.
391 // This value is stored as a bitfield because the number of touch ids varies,
392 // but we currently don't need more than 32 touches at a time.
393 const unsigned int touch_ids_bitfield_;
394
395 DISALLOW_COPY_AND_ASSIGN(GestureEvent);
396 };
397
398 } // namespace aura
399
400 #endif // UI_AURA_EVENT_H_
OLDNEW
« no previous file with comments | « ui/aura/desktop/desktop_activation_client.cc ('k') | ui/aura/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698