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

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

Issue 1287103004: Sync ui/events to chromium @ https://codereview.chromium.org/1210203002 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 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
« no previous file with comments | « ui/events/devices/x11/touch_factory_x11.cc ('k') | ui/events/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_EVENTS_EVENT_H_ 5 #ifndef UI_EVENTS_EVENT_H_
6 #define UI_EVENTS_EVENT_H_ 6 #define UI_EVENTS_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/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "ui/events/event_constants.h" 15 #include "ui/events/event_constants.h"
16 #include "ui/events/gesture_event_details.h" 16 #include "ui/events/gesture_event_details.h"
17 #include "ui/events/gestures/gesture_types.h" 17 #include "ui/events/gestures/gesture_types.h"
18 #include "ui/events/keycodes/keyboard_codes.h" 18 #include "ui/events/keycodes/keyboard_codes.h"
19 #include "ui/events/latency_info.h" 19 #include "ui/events/latency_info.h"
20 #include "ui/gfx/point.h" 20 #include "ui/gfx/geometry/point.h"
21 #include "ui/gfx/point_conversions.h" 21 #include "ui/gfx/geometry/point_conversions.h"
22 22
23 namespace gfx { 23 namespace gfx {
24 class Transform; 24 class Transform;
25 } 25 }
26 26
27 namespace ui { 27 namespace ui {
28 class EventTarget; 28 class EventTarget;
29 enum class DomCode;
30 enum class DomKey;
29 31
30 class EVENTS_EXPORT Event { 32 class EVENTS_EXPORT Event {
31 public: 33 public:
32 static scoped_ptr<Event> Clone(const Event& event); 34 static scoped_ptr<Event> Clone(const Event& event);
33 35
34 virtual ~Event(); 36 virtual ~Event();
35 37
36 class DispatcherApi { 38 class DispatcherApi {
37 public: 39 public:
38 explicit DispatcherApi(Event* event) : event_(event) {} 40 explicit DispatcherApi(Event* event) : event_(event) {}
39 41
40 void set_target(EventTarget* target) { 42 void set_target(EventTarget* target) {
41 event_->target_ = target; 43 event_->target_ = target;
42 } 44 }
43 45
44 void set_phase(EventPhase phase) { event_->phase_ = phase; } 46 void set_phase(EventPhase phase) { event_->phase_ = phase; }
45 void set_result(int result) { 47 void set_result(int result) {
46 event_->result_ = static_cast<EventResult>(result); 48 event_->result_ = static_cast<EventResult>(result);
47 } 49 }
48 50
49 private: 51 private:
50 DispatcherApi(); 52 DispatcherApi();
51 Event* event_; 53 Event* event_;
52 54
53 DISALLOW_COPY_AND_ASSIGN(DispatcherApi); 55 DISALLOW_COPY_AND_ASSIGN(DispatcherApi);
54 }; 56 };
55 57
58 const base::NativeEvent& native_event() const { return native_event_; }
56 EventType type() const { return type_; } 59 EventType type() const { return type_; }
57 void set_type(EventType type) { type_ = type; } 60 const std::string& name() const { return name_; }
58
59 // time_stamp represents time since machine was booted. 61 // time_stamp represents time since machine was booted.
60 const base::TimeDelta& time_stamp() const { return time_stamp_; } 62 const base::TimeDelta& time_stamp() const { return time_stamp_; }
61 void set_time_stamp(const base::TimeDelta& stamp) { time_stamp_ = stamp; } 63 int flags() const { return flags_; }
62 64
63 int flags() const { return flags_; } 65 // This is only intended to be used externally by classes that are modifying
66 // events in an EventRewriter.
64 void set_flags(int flags) { flags_ = flags; } 67 void set_flags(int flags) { flags_ = flags; }
65 68
66 EventTarget* target() const { return target_; } 69 EventTarget* target() const { return target_; }
67 EventPhase phase() const { return phase_; } 70 EventPhase phase() const { return phase_; }
68 EventResult result() const { return result_; } 71 EventResult result() const { return result_; }
69 72
70 LatencyInfo* latency() { return &latency_; } 73 LatencyInfo* latency() { return &latency_; }
71 const LatencyInfo* latency() const { return &latency_; } 74 const LatencyInfo* latency() const { return &latency_; }
72 void set_latency(const LatencyInfo& latency) { latency_ = latency; } 75 void set_latency(const LatencyInfo& latency) { latency_ = latency; }
73 76
74 int source_device_id() const { return source_device_id_; } 77 int source_device_id() const { return source_device_id_; }
75 void set_source_device_id(const int id) { source_device_id_ = id; } 78 void set_source_device_id(int id) { source_device_id_ = id; }
76 79
77 // By default, events are "cancelable", this means any default processing that 80 // By default, events are "cancelable", this means any default processing that
78 // the containing abstraction layer may perform can be prevented by calling 81 // the containing abstraction layer may perform can be prevented by calling
79 // SetHandled(). SetHandled() or StopPropagation() must not be called for 82 // SetHandled(). SetHandled() or StopPropagation() must not be called for
80 // events that are not cancelable. 83 // events that are not cancelable.
81 bool cancelable() const { return cancelable_; } 84 bool cancelable() const { return cancelable_; }
82 85
83 // The following methods return true if the respective keys were pressed at 86 // The following methods return true if the respective keys were pressed at
84 // the time the event was created. 87 // the time the event was created.
85 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } 88 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; }
86 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } 89 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; }
87 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; } 90 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; }
88 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } 91 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; }
89 bool IsAltGrDown() const { return (flags_ & EF_ALTGR_DOWN) != 0; } 92 bool IsAltGrDown() const { return (flags_ & EF_ALTGR_DOWN) != 0; }
90 bool IsCommandDown() const { return (flags_ & EF_COMMAND_DOWN) != 0; } 93 bool IsCommandDown() const { return (flags_ & EF_COMMAND_DOWN) != 0; }
91 bool IsRepeat() const { return (flags_ & EF_IS_REPEAT) != 0; } 94 bool IsRepeat() const { return (flags_ & EF_IS_REPEAT) != 0; }
92 95
93 bool IsKeyEvent() const { 96 bool IsKeyEvent() const {
94 return type_ == ET_KEY_PRESSED || 97 return type_ == ET_KEY_PRESSED || type_ == ET_KEY_RELEASED;
95 type_ == ET_KEY_RELEASED ||
96 type_ == ET_TRANSLATED_KEY_PRESS ||
97 type_ == ET_TRANSLATED_KEY_RELEASE;
98 } 98 }
99 99
100 bool IsMouseEvent() const { 100 bool IsMouseEvent() const {
101 return type_ == ET_MOUSE_PRESSED || 101 return type_ == ET_MOUSE_PRESSED ||
102 type_ == ET_MOUSE_DRAGGED || 102 type_ == ET_MOUSE_DRAGGED ||
103 type_ == ET_MOUSE_RELEASED || 103 type_ == ET_MOUSE_RELEASED ||
104 type_ == ET_MOUSE_MOVED || 104 type_ == ET_MOUSE_MOVED ||
105 type_ == ET_MOUSE_ENTERED || 105 type_ == ET_MOUSE_ENTERED ||
106 type_ == ET_MOUSE_EXITED || 106 type_ == ET_MOUSE_EXITED ||
107 type_ == ET_MOUSEWHEEL || 107 type_ == ET_MOUSEWHEEL ||
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool IsLocatedEvent() const { 192 bool IsLocatedEvent() const {
193 return IsMouseEvent() || IsScrollEvent() || IsTouchEvent() || 193 return IsMouseEvent() || IsScrollEvent() || IsTouchEvent() ||
194 IsGestureEvent(); 194 IsGestureEvent();
195 } 195 }
196 196
197 // Convenience methods to cast |this| to a GestureEvent. IsGestureEvent() 197 // Convenience methods to cast |this| to a GestureEvent. IsGestureEvent()
198 // must be true as a precondition to calling these methods. 198 // must be true as a precondition to calling these methods.
199 GestureEvent* AsGestureEvent(); 199 GestureEvent* AsGestureEvent();
200 const GestureEvent* AsGestureEvent() const; 200 const GestureEvent* AsGestureEvent() const;
201 201
202 // Returns true if the event has a valid |native_event_|.
203 bool HasNativeEvent() const;
204
202 // Immediately stops the propagation of the event. This must be called only 205 // Immediately stops the propagation of the event. This must be called only
203 // from an EventHandler during an event-dispatch. Any event handler that may 206 // from an EventHandler during an event-dispatch. Any event handler that may
204 // be in the list will not receive the event after this is called. 207 // be in the list will not receive the event after this is called.
205 // Note that StopPropagation() can be called only for cancelable events. 208 // Note that StopPropagation() can be called only for cancelable events.
206 void StopPropagation(); 209 void StopPropagation();
207 bool stopped_propagation() const { return !!(result_ & ER_CONSUMED); } 210 bool stopped_propagation() const { return !!(result_ & ER_CONSUMED); }
208 211
209 // Marks the event as having been handled. A handled event does not reach the 212 // Marks the event as having been handled. A handled event does not reach the
210 // next event phase. For example, if an event is handled during the pre-target 213 // next event phase. For example, if an event is handled during the pre-target
211 // phase, then the event is dispatched to all pre-target handlers, but not to 214 // phase, then the event is dispatched to all pre-target handlers, but not to
212 // the target or post-target handlers. 215 // the target or post-target handlers.
213 // Note that SetHandled() can be called only for cancelable events. 216 // Note that SetHandled() can be called only for cancelable events.
214 void SetHandled(); 217 void SetHandled();
215 bool handled() const { return result_ != ER_UNHANDLED; } 218 bool handled() const { return result_ != ER_UNHANDLED; }
216 219
217 protected: 220 protected:
218 Event();
219 Event(EventType type, base::TimeDelta time_stamp, int flags); 221 Event(EventType type, base::TimeDelta time_stamp, int flags);
222 Event(const base::NativeEvent& native_event, EventType type, int flags);
220 Event(const Event& copy); 223 Event(const Event& copy);
221 void SetType(EventType type); 224 void SetType(EventType type);
222 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } 225 void set_cancelable(bool cancelable) { cancelable_ = cancelable; }
223 226
227 void set_time_stamp(const base::TimeDelta& time_stamp) {
228 time_stamp_ = time_stamp;
229 }
230
231 void set_name(const std::string& name) { name_ = name; }
232
224 private: 233 private:
225 friend class EventTestApi; 234 friend class EventTestApi;
226 235
227 EventType type_; 236 EventType type_;
237 std::string name_;
228 base::TimeDelta time_stamp_; 238 base::TimeDelta time_stamp_;
229 LatencyInfo latency_; 239 LatencyInfo latency_;
230 int flags_; 240 int flags_;
241 base::NativeEvent native_event_;
242 bool delete_native_event_;
231 bool cancelable_; 243 bool cancelable_;
232 EventTarget* target_; 244 EventTarget* target_;
233 EventPhase phase_; 245 EventPhase phase_;
234 EventResult result_; 246 EventResult result_;
235 247
236 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information 248 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information
237 // is not available. 249 // is not available.
238 int source_device_id_; 250 int source_device_id_;
239 }; 251 };
240 252
241 class EVENTS_EXPORT CancelModeEvent : public Event { 253 class EVENTS_EXPORT CancelModeEvent : public Event {
242 public: 254 public:
243 CancelModeEvent(); 255 CancelModeEvent();
244 ~CancelModeEvent() override; 256 ~CancelModeEvent() override;
245 }; 257 };
246 258
247 class EVENTS_EXPORT LocatedEvent : public Event { 259 class EVENTS_EXPORT LocatedEvent : public Event {
248 public: 260 public:
249 LocatedEvent();
250 ~LocatedEvent() override; 261 ~LocatedEvent() override;
251 262
252 float x() const { return location_.x(); } 263 float x() const { return location_.x(); }
253 float y() const { return location_.y(); } 264 float y() const { return location_.y(); }
254 void set_location(const gfx::PointF& location) { location_ = location; } 265 void set_location(const gfx::PointF& location) { location_ = location; }
255 // TODO(tdresser): Always return floating point location. See 266 // TODO(tdresser): Always return floating point location. See
256 // crbug.com/337824. 267 // crbug.com/337824.
257 gfx::Point location() const { return gfx::ToFlooredPoint(location_); } 268 gfx::Point location() const { return gfx::ToFlooredPoint(location_); }
258 const gfx::PointF& location_f() const { return location_; } 269 const gfx::PointF& location_f() const { return location_; }
259 void set_root_location(const gfx::PointF& root_location) { 270 void set_root_location(const gfx::PointF& root_location) {
260 root_location_ = root_location; 271 root_location_ = root_location;
261 } 272 }
262 gfx::Point root_location() const { 273 gfx::Point root_location() const {
263 return gfx::ToFlooredPoint(root_location_); 274 return gfx::ToFlooredPoint(root_location_);
264 } 275 }
265 const gfx::PointF& root_location_f() const { 276 const gfx::PointF& root_location_f() const {
266 return root_location_; 277 return root_location_;
267 } 278 }
268 const gfx::Point& screen_location() const { return screen_location_; }
269 void set_screen_location(const gfx::Point& screen_location) {
270 screen_location_ = screen_location;
271 }
272 279
273 // Transform the locations using |inverted_root_transform|. 280 // Transform the locations using |inverted_root_transform|.
274 // This is applied to both |location_| and |root_location_|. 281 // This is applied to both |location_| and |root_location_|.
275 virtual void UpdateForRootTransform( 282 virtual void UpdateForRootTransform(
276 const gfx::Transform& inverted_root_transform); 283 const gfx::Transform& inverted_root_transform);
277 284
278 template <class T> void ConvertLocationToTarget(T* source, T* target) { 285 template <class T> void ConvertLocationToTarget(T* source, T* target) {
279 if (!target || target == source) 286 if (!target || target == source)
280 return; 287 return;
281 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See 288 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See
282 // crbug.com/337824. 289 // crbug.com/337824.
283 gfx::Point offset = gfx::ToFlooredPoint(location_); 290 gfx::Point offset = gfx::ToFlooredPoint(location_);
284 T::ConvertPointToTarget(source, target, &offset); 291 T::ConvertPointToTarget(source, target, &offset);
285 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; 292 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset;
286 location_= location_ - diff; 293 location_= location_ - diff;
287 } 294 }
288 295
289 protected: 296 protected:
290 friend class LocatedEventTestApi; 297 friend class LocatedEventTestApi;
298 explicit LocatedEvent(const base::NativeEvent& native_event);
291 299
292 // Create a new LocatedEvent which is identical to the provided model. 300 // Create a new LocatedEvent which is identical to the provided model.
293 // If source / target windows are provided, the model location will be 301 // If source / target windows are provided, the model location will be
294 // converted from |source| coordinate system to |target| coordinate system. 302 // converted from |source| coordinate system to |target| coordinate system.
295 template <class T> 303 template <class T>
296 LocatedEvent(const LocatedEvent& model, T* source, T* target) 304 LocatedEvent(const LocatedEvent& model, T* source, T* target)
297 : Event(model), 305 : Event(model),
298 location_(model.location_), 306 location_(model.location_),
299 root_location_(model.root_location_), 307 root_location_(model.root_location_) {
300 screen_location_(model.screen_location_) {
301 ConvertLocationToTarget(source, target); 308 ConvertLocationToTarget(source, target);
302 } 309 }
303 310
304 // Used for synthetic events in testing. 311 // Used for synthetic events in testing.
305 LocatedEvent(EventType type, 312 LocatedEvent(EventType type,
306 const gfx::PointF& location, 313 const gfx::PointF& location,
307 const gfx::PointF& root_location, 314 const gfx::PointF& root_location,
308 base::TimeDelta time_stamp, 315 base::TimeDelta time_stamp,
309 int flags); 316 int flags);
310 317
311 gfx::PointF location_; 318 gfx::PointF location_;
312 319
313 // |location_| multiplied by an optional transformation matrix for 320 // |location_| multiplied by an optional transformation matrix for
314 // rotations, animations and skews. 321 // rotations, animations and skews.
315 gfx::PointF root_location_; 322 gfx::PointF root_location_;
316
317 // The system provided location of the event.
318 gfx::Point screen_location_;
319 }; 323 };
320 324
321 class EVENTS_EXPORT MouseEvent : public LocatedEvent { 325 class EVENTS_EXPORT MouseEvent : public LocatedEvent {
322 public: 326 public:
323 MouseEvent(); 327 explicit MouseEvent(const base::NativeEvent& native_event);
324 328
325 // Create a new MouseEvent based on the provided model. 329 // Create a new MouseEvent based on the provided model.
326 // Uses the provided |type| and |flags| for the new event. 330 // Uses the provided |type| and |flags| for the new event.
327 // If source / target windows are provided, the model location will be 331 // If source / target windows are provided, the model location will be
328 // converted from |source| coordinate system to |target| coordinate system. 332 // converted from |source| coordinate system to |target| coordinate system.
329 template <class T> 333 template <class T>
330 MouseEvent(const MouseEvent& model, T* source, T* target) 334 MouseEvent(const MouseEvent& model, T* source, T* target)
331 : LocatedEvent(model, source, target), 335 : LocatedEvent(model, source, target),
332 changed_button_flags_(model.changed_button_flags_) { 336 changed_button_flags_(model.changed_button_flags_) {
333 } 337 }
334 338
335 template <class T> 339 template <class T>
336 MouseEvent(const MouseEvent& model, 340 MouseEvent(const MouseEvent& model,
337 T* source, 341 T* source,
338 T* target, 342 T* target,
339 EventType type, 343 EventType type,
340 int flags) 344 int flags)
341 : LocatedEvent(model, source, target), 345 : LocatedEvent(model, source, target),
342 changed_button_flags_(model.changed_button_flags_) { 346 changed_button_flags_(model.changed_button_flags_) {
343 SetType(type); 347 SetType(type);
344 set_flags(flags); 348 set_flags(flags);
345 } 349 }
346 350
347 // Used for synthetic events in testing and by the gesture recognizer. 351 // Used for synthetic events in testing, gesture recognizer and Ozone
348 MouseEvent(EventType type, 352 MouseEvent(EventType type,
349 const gfx::PointF& location, 353 const gfx::PointF& location,
350 const gfx::PointF& root_location, 354 const gfx::PointF& root_location,
355 base::TimeDelta time_stamp,
351 int flags, 356 int flags,
352 int changed_button_flags); 357 int changed_button_flags);
353 358
354 // Conveniences to quickly test what button is down 359 // Conveniences to quickly test what button is down
355 bool IsOnlyLeftMouseButton() const { 360 bool IsOnlyLeftMouseButton() const {
356 return (flags() & EF_LEFT_MOUSE_BUTTON) && 361 return button_flags() == EF_LEFT_MOUSE_BUTTON;
357 !(flags() & (EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON));
358 } 362 }
359 363
360 bool IsLeftMouseButton() const { 364 bool IsLeftMouseButton() const {
361 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0; 365 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0;
362 } 366 }
363 367
364 bool IsOnlyMiddleMouseButton() const { 368 bool IsOnlyMiddleMouseButton() const {
365 return (flags() & EF_MIDDLE_MOUSE_BUTTON) && 369 return button_flags() == EF_MIDDLE_MOUSE_BUTTON;
366 !(flags() & (EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON));
367 } 370 }
368 371
369 bool IsMiddleMouseButton() const { 372 bool IsMiddleMouseButton() const {
370 return (flags() & EF_MIDDLE_MOUSE_BUTTON) != 0; 373 return (flags() & EF_MIDDLE_MOUSE_BUTTON) != 0;
371 } 374 }
372 375
373 bool IsOnlyRightMouseButton() const { 376 bool IsOnlyRightMouseButton() const {
374 return (flags() & EF_RIGHT_MOUSE_BUTTON) && 377 return button_flags() == EF_RIGHT_MOUSE_BUTTON;
375 !(flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON));
376 } 378 }
377 379
378 bool IsRightMouseButton() const { 380 bool IsRightMouseButton() const {
379 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0; 381 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0;
380 } 382 }
381 383
382 bool IsAnyButton() const { 384 bool IsAnyButton() const {
383 return (flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | 385 return button_flags() != 0;
384 EF_RIGHT_MOUSE_BUTTON)) != 0;
385 } 386 }
386 387
387 // Compares two mouse down events and returns true if the second one should 388 // Compares two mouse down events and returns true if the second one should
388 // be considered a repeat of the first. 389 // be considered a repeat of the first.
389 static bool IsRepeatedClickEvent( 390 static bool IsRepeatedClickEvent(
390 const MouseEvent& event1, 391 const MouseEvent& event1,
391 const MouseEvent& event2); 392 const MouseEvent& event2);
392 393
393 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. 394 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
394 int GetClickCount() const; 395 int GetClickCount() const;
395 396
396 // Set the click count for a mousedown message. Can be 1, 2 or 3. 397 // Set the click count for a mousedown message. Can be 1, 2 or 3.
397 void SetClickCount(int click_count); 398 void SetClickCount(int click_count);
398 399
399 // Identifies the button that changed. During a press this corresponds to the 400 // Identifies the button that changed. During a press this corresponds to the
400 // button that was pressed and during a release this corresponds to the button 401 // button that was pressed and during a release this corresponds to the button
401 // that was released. 402 // that was released.
402 // NOTE: during a press and release flags() contains the complete set of 403 // NOTE: during a press and release flags() contains the complete set of
403 // flags. Use this to determine the button that was pressed or released. 404 // flags. Use this to determine the button that was pressed or released.
404 int changed_button_flags() const { return changed_button_flags_; } 405 int changed_button_flags() const { return changed_button_flags_; }
405 406
406 // Updates the button that changed. 407 // Updates the button that changed.
407 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } 408 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; }
408 409
410 private:
411 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease);
412 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft);
413
414 // Returns the flags for the mouse buttons.
415 int button_flags() const {
416 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON |
417 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON |
418 EF_FORWARD_MOUSE_BUTTON);
419 }
420
409 // Returns the repeat count based on the previous mouse click, if it is 421 // Returns the repeat count based on the previous mouse click, if it is
410 // recent enough and within a small enough distance. 422 // recent enough and within a small enough distance.
411 static int GetRepeatCount(const MouseEvent& click_event); 423 static int GetRepeatCount(const MouseEvent& click_event);
412 424
413 private: 425 // Resets the last_click_event_ for unit tests.
414 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); 426 static void ResetLastClickForTest();
415 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft);
416 427
417 // See description above getter for details. 428 // See description above getter for details.
418 int changed_button_flags_; 429 int changed_button_flags_;
430
431 static MouseEvent* last_click_event_;
432
433 // We can create a MouseEvent for a native event more than once. We set this
434 // to true when the next event either has a different timestamp or we see a
435 // release signalling that the press (click) event was completed.
436 static bool last_click_complete_;
419 }; 437 };
420 438
421 class ScrollEvent; 439 class ScrollEvent;
422 440
423 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent { 441 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent {
424 public: 442 public:
425 // See |offset| for details. 443 // See |offset| for details.
426 static const int kWheelDelta; 444 static const int kWheelDelta;
427 445
428 MouseWheelEvent(); 446 explicit MouseWheelEvent(const base::NativeEvent& native_event);
429 explicit MouseWheelEvent(const ScrollEvent& scroll_event); 447 explicit MouseWheelEvent(const ScrollEvent& scroll_event);
430 MouseWheelEvent(const MouseEvent& mouse_event, int x_offset, int y_offset); 448 MouseWheelEvent(const MouseEvent& mouse_event, int x_offset, int y_offset);
431 MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event); 449 MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event);
432 450
433 template <class T> 451 template <class T>
434 MouseWheelEvent(const MouseWheelEvent& model, 452 MouseWheelEvent(const MouseWheelEvent& model,
435 T* source, 453 T* source,
436 T* target) 454 T* target)
437 : MouseEvent(model, source, target, model.type(), model.flags()), 455 : MouseEvent(model, source, target, model.type(), model.flags()),
438 offset_(model.x_offset(), model.y_offset()) { 456 offset_(model.x_offset(), model.y_offset()) {
439 } 457 }
440 458
441 // Used for synthetic events in testing and by the gesture recognizer. 459 // Used for synthetic events in testing and by the gesture recognizer.
442 MouseWheelEvent(const gfx::Vector2d& offset, 460 MouseWheelEvent(const gfx::Vector2d& offset,
443 const gfx::PointF& location, 461 const gfx::PointF& location,
444 const gfx::PointF& root_location, 462 const gfx::PointF& root_location,
463 base::TimeDelta time_stamp,
445 int flags, 464 int flags,
446 int changed_button_flags); 465 int changed_button_flags);
447 466
448 // The amount to scroll. This is in multiples of kWheelDelta. 467 // The amount to scroll. This is in multiples of kWheelDelta.
449 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. 468 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up.
450 int x_offset() const { return offset_.x(); } 469 int x_offset() const { return offset_.x(); }
451 int y_offset() const { return offset_.y(); } 470 int y_offset() const { return offset_.y(); }
452 const gfx::Vector2d& offset() const { return offset_; } 471 const gfx::Vector2d& offset() const { return offset_; }
453 void set_offset(const gfx::Vector2d& offset) { offset_ = offset; }
454
455 // Overridden from LocatedEvent.
456 void UpdateForRootTransform(
457 const gfx::Transform& inverted_root_transform) override;
458 472
459 private: 473 private:
460 gfx::Vector2d offset_; 474 gfx::Vector2d offset_;
461 }; 475 };
462 476
463 class EVENTS_EXPORT TouchEvent : public LocatedEvent { 477 class EVENTS_EXPORT TouchEvent : public LocatedEvent {
464 public: 478 public:
465 TouchEvent(); 479 explicit TouchEvent(const base::NativeEvent& native_event);
466 480
467 // Create a new TouchEvent which is identical to the provided model. 481 // Create a new TouchEvent which is identical to the provided model.
468 // If source / target windows are provided, the model location will be 482 // If source / target windows are provided, the model location will be
469 // converted from |source| coordinate system to |target| coordinate system. 483 // converted from |source| coordinate system to |target| coordinate system.
470 template <class T> 484 template <class T>
471 TouchEvent(const TouchEvent& model, T* source, T* target) 485 TouchEvent(const TouchEvent& model, T* source, T* target)
472 : LocatedEvent(model, source, target), 486 : LocatedEvent(model, source, target),
473 touch_id_(model.touch_id_), 487 touch_id_(model.touch_id_),
488 unique_event_id_(model.unique_event_id_),
474 radius_x_(model.radius_x_), 489 radius_x_(model.radius_x_),
475 radius_y_(model.radius_y_), 490 radius_y_(model.radius_y_),
476 rotation_angle_(model.rotation_angle_), 491 rotation_angle_(model.rotation_angle_),
477 force_(model.force_) { 492 force_(model.force_),
478 } 493 may_cause_scrolling_(model.may_cause_scrolling_),
494 should_remove_native_touch_id_mapping_(false) {}
479 495
480 TouchEvent(EventType type, 496 TouchEvent(EventType type,
481 const gfx::PointF& location, 497 const gfx::PointF& location,
482 int touch_id, 498 int touch_id,
483 base::TimeDelta time_stamp); 499 base::TimeDelta time_stamp);
484 500
485 TouchEvent(EventType type, 501 TouchEvent(EventType type,
486 const gfx::PointF& location, 502 const gfx::PointF& location,
487 int flags, 503 int flags,
488 int touch_id, 504 int touch_id,
489 base::TimeDelta timestamp, 505 base::TimeDelta timestamp,
490 float radius_x, 506 float radius_x,
491 float radius_y, 507 float radius_y,
492 float angle, 508 float angle,
493 float force); 509 float force);
494 510
511 TouchEvent(const TouchEvent& copy);
512
495 ~TouchEvent() override; 513 ~TouchEvent() override;
496 514
515 // The id of the pointer this event modifies.
497 int touch_id() const { return touch_id_; } 516 int touch_id() const { return touch_id_; }
498 void set_touch_id(int touch_id) { touch_id_ = touch_id; } 517 // A unique identifier for this event.
518 uint32 unique_event_id() const { return unique_event_id_; }
519 // If we aren't provided with a radius on one axis, use the
520 // information from the other axis.
521 float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; }
522 float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; }
523 float rotation_angle() const { return rotation_angle_; }
524 float force() const { return force_; }
499 525
500 float radius_x() const { return radius_x_; } 526 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; }
527 bool may_cause_scrolling() const { return may_cause_scrolling_; }
528
529 // Used for unit tests.
501 void set_radius_x(const float r) { radius_x_ = r; } 530 void set_radius_x(const float r) { radius_x_ = r; }
502 float radius_y() const { return radius_y_; }
503 void set_radius_y(const float r) { radius_y_ = r; } 531 void set_radius_y(const float r) { radius_y_ = r; }
504 532
505 float rotation_angle() const { return rotation_angle_; } 533 void set_should_remove_native_touch_id_mapping(
506 void set_rotation_angle(float rotation_angle) { 534 bool should_remove_native_touch_id_mapping) {
507 rotation_angle_ = rotation_angle; 535 should_remove_native_touch_id_mapping_ =
536 should_remove_native_touch_id_mapping;
508 } 537 }
509 538
510 float force() const { return force_; }
511 void set_force(float force) { force_ = force; }
512
513 // Overridden from LocatedEvent. 539 // Overridden from LocatedEvent.
514 void UpdateForRootTransform( 540 void UpdateForRootTransform(
515 const gfx::Transform& inverted_root_transform) override; 541 const gfx::Transform& inverted_root_transform) override;
516 542
517 protected: 543 // Marks the event as not participating in synchronous gesture recognition.
518 void set_radius(float radius_x, float radius_y) { 544 void DisableSynchronousHandling();
519 radius_x_ = radius_x; 545 bool synchronous_handling_disabled() const {
520 radius_y_ = radius_y; 546 return !!(result() & ER_DISABLE_SYNC_HANDLING);
521 } 547 }
522 548
523 private: 549 private:
550 // Adjusts rotation_angle_ to within the acceptable range.
551 void FixRotationAngle();
552
524 // The identity (typically finger) of the touch starting at 0 and incrementing 553 // The identity (typically finger) of the touch starting at 0 and incrementing
525 // for each separable additional touch that the hardware can detect. 554 // for each separable additional touch that the hardware can detect.
526 int touch_id_; 555 const int touch_id_;
556
557 // A unique identifier for the touch event.
558 const uint32 unique_event_id_;
527 559
528 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. 560 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
529 float radius_x_; 561 float radius_x_;
530 562
531 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. 563 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
532 float radius_y_; 564 float radius_y_;
533 565
534 // Angle of the major axis away from the X axis. Default 0.0. 566 // Clockwise angle (in degrees) of the major axis from the X axis. Must be
567 // less than 180 and non-negative.
535 float rotation_angle_; 568 float rotation_angle_;
536 569
537 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. 570 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
538 float force_; 571 float force_;
572
573 // Whether the (unhandled) touch event will produce a scroll event (e.g., a
574 // touchmove that exceeds the platform slop region, or a touchend that
575 // causes a fling). Defaults to false.
576 bool may_cause_scrolling_;
577
578 // True if this event should remove the mapping between the native
579 // event id and the touch_id_. This should only be the case for
580 // release and cancel events where the associated touch press event
581 // created a mapping between the native id and the touch_id_.
582 bool should_remove_native_touch_id_mapping_;
539 }; 583 };
540 584
541 // An interface that individual platforms can use to store additional data on 585 // An interface that individual platforms can use to store additional data on
542 // KeyEvent. 586 // KeyEvent.
543 // 587 //
544 // Currently only used in mojo. 588 // Currently only used in mojo.
545 class EVENTS_EXPORT ExtendedKeyEventData { 589 class EVENTS_EXPORT ExtendedKeyEventData {
546 public: 590 public:
547 virtual ~ExtendedKeyEventData() {} 591 virtual ~ExtendedKeyEventData() {}
548 592
549 virtual ExtendedKeyEventData* Clone() const = 0; 593 virtual ExtendedKeyEventData* Clone() const = 0;
550 }; 594 };
551 595
552 // A KeyEvent is really two distinct classes, melded together due to the 596 // A KeyEvent is really two distinct classes, melded together due to the
553 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), 597 // DOM legacy of Windows key events: a keystroke event (is_char_ == false),
554 // or a character event (is_char_ == true). 598 // or a character event (is_char_ == true).
555 // 599 //
556 // For a keystroke event, 600 // For a keystroke event,
557 // -- is_char_ is false. 601 // -- is_char_ is false.
558 // -- type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED, 602 // -- Event::type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED.
559 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE. 603 // -- code_ and Event::flags() represent the physical key event.
560 // -- character_ functions as a bypass or cache for GetCharacter(). 604 // - code_ is a platform-independent representation of the physical key,
561 // -- key_code_ is a VKEY_ value associated with the key. For printable 605 // based on DOM KeyboardEvent |code| values. It does not vary depending
562 // characters, this may or may not be a mapped value, imitating MS Windows: 606 // on key layout.
607 // - Event::flags() provides the active modifiers for the physical key
608 // press. Its value reflects the state after the event; that is, for
609 // a modifier key, a press includes the corresponding flag and a release
610 // does not.
611 // -- key_ and character_ provide the meaning of the key event, in the context
612 // of the active layout and modifiers. Together they correspond to DOM
613 // KeyboardEvent |key| values.
614 // - key_ is an enumeration of non-Unicode meanings, plus sentinels
615 // (specifically DomKey::CHARACTER for Unicode meanings).
616 // - character_ is the code point for Unicode meanings.
617 // -- key_code_ is a KeyboardCode value associated with the key. This supports
618 // the legacy web event |keyCode| field, and the VKEY_ values are chosen
619 // to match Windows/IE for compatibility. For printable characters, this
620 // may or may not be a layout-mapped value, imitating MS Windows:
563 // if the mapped key generates a character that has an associated VKEY_ 621 // if the mapped key generates a character that has an associated VKEY_
564 // code, then key_code_ is that code; if not, then key_code_ is the unmapped 622 // code, then key_code_ is that code; if not, then key_code_ is the unmapped
565 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use 623 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use
566 // VKEY_Q for the key beside Tab, while French uses VKEY_A. 624 // VKEY_Q for the key beside Tab, while French uses VKEY_A.
567 // -- code_ is in one-to-one correspondence with a physical keyboard
568 // location, and does not vary depending on key layout.
569 // 625 //
570 // For a character event, 626 // For a character event,
571 // -- is_char_ is true. 627 // -- is_char_ is true.
572 // -- type() is ET_KEY_PRESSED. 628 // -- type() is ET_KEY_PRESSED.
573 // -- character_ is a UTF-16 character value. 629 // -- code_ is DomCode::NONE.
630 // -- key_ is DomKey::CHARACTER and character_ is a UTF-16 code point.
574 // -- key_code_ is conflated with character_ by some code, because both 631 // -- key_code_ is conflated with character_ by some code, because both
575 // arrive in the wParam field of a Windows event. 632 // arrive in the wParam field of a Windows event.
576 // -- code_ is the empty string.
577 // 633 //
578 class EVENTS_EXPORT KeyEvent : public Event { 634 class EVENTS_EXPORT KeyEvent : public Event {
579 public: 635 public:
580 KeyEvent(); 636 // Create a KeyEvent from a NativeEvent. For Windows this native event can
637 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message
638 // (WM_CHAR). Other systems have only keystroke events.
639 explicit KeyEvent(const base::NativeEvent& native_event);
581 640
582 // Create a keystroke event. 641 // Create a keystroke event.
583 KeyEvent(EventType type, KeyboardCode key_code, int flags); 642 KeyEvent(EventType type, KeyboardCode key_code, int flags);
584 643
644 // Create a fully defined keystroke event.
645 KeyEvent(EventType type,
646 KeyboardCode key_code,
647 DomCode code,
648 int flags,
649 DomKey key,
650 base::char16 character,
651 base::TimeDelta time_stamp);
652
585 // Create a character event. 653 // Create a character event.
586 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); 654 KeyEvent(base::char16 character, KeyboardCode key_code, int flags);
587 655
588 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') 656 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA')
589 // See also: ui/events/keycodes/dom4/keycode_converter_data.h 657 // See also: ui/events/keycodes/dom/dom_values.txt
590 KeyEvent(EventType type, 658 KeyEvent(EventType type,
591 KeyboardCode key_code, 659 KeyboardCode key_code,
592 const std::string& code, 660 DomCode code,
593 int flags); 661 int flags);
594 662
595 KeyEvent(const KeyEvent& rhs); 663 KeyEvent(const KeyEvent& rhs);
596 664
597 KeyEvent& operator=(const KeyEvent& rhs); 665 KeyEvent& operator=(const KeyEvent& rhs);
598 666
599 ~KeyEvent() override; 667 ~KeyEvent() override;
600 668
601 // TODO(erg): While we transition to mojo, we have to hack around a mismatch 669 // TODO(erg): While we transition to mojo, we have to hack around a mismatch
602 // in our event types. Our ui::Events don't really have all the data we need 670 // in our event types. Our ui::Events don't really have all the data we need
(...skipping 19 matching lines...) Expand all
622 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; 690 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r';
623 // otherwise returns the same as GetCharacter(). 691 // otherwise returns the same as GetCharacter().
624 base::char16 GetUnmodifiedText() const; 692 base::char16 GetUnmodifiedText() const;
625 693
626 // If the Control key is down in the event, returns a layout-independent 694 // If the Control key is down in the event, returns a layout-independent
627 // character (corresponding to US layout); otherwise returns the same 695 // character (corresponding to US layout); otherwise returns the same
628 // as GetUnmodifiedText(). 696 // as GetUnmodifiedText().
629 base::char16 GetText() const; 697 base::char16 GetText() const;
630 698
631 // Gets the platform key code. For XKB, this is the xksym value. 699 // Gets the platform key code. For XKB, this is the xksym value.
700 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; }
632 uint32 platform_keycode() const { return platform_keycode_; } 701 uint32 platform_keycode() const { return platform_keycode_; }
633 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; }
634 702
635 // Gets the associated (Windows-based) KeyboardCode for this key event. 703 // Gets the associated (Windows-based) KeyboardCode for this key event.
636 // Historically, this has also been used to obtain the character associated 704 // Historically, this has also been used to obtain the character associated
637 // with a character event, because both use the Window message 'wParam' field. 705 // with a character event, because both use the Window message 'wParam' field.
638 // This should be avoided; if necessary for backwards compatibility, use 706 // This should be avoided; if necessary for backwards compatibility, use
639 // GetConflatedWindowsKeyCode(). 707 // GetConflatedWindowsKeyCode().
640 KeyboardCode key_code() const { return key_code_; } 708 KeyboardCode key_code() const { return key_code_; }
641 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; }
642 709
643 // True if this is a character event, false if this is a keystroke event. 710 // True if this is a character event, false if this is a keystroke event.
644 bool is_char() const { return is_char_; } 711 bool is_char() const { return is_char_; }
645 void set_is_char(bool is_char) { is_char_ = is_char; } 712
713 // This is only intended to be used externally by classes that are modifying
714 // events in an EventRewriter.
715 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; }
646 716
647 // Returns the same value as key_code(), except that located codes are 717 // Returns the same value as key_code(), except that located codes are
648 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT 718 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT
649 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical 719 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical
650 // for legacy DOM reasons. 720 // for legacy DOM reasons.
651 KeyboardCode GetLocatedWindowsKeyboardCode() const; 721 KeyboardCode GetLocatedWindowsKeyboardCode() const;
652 722
653 // For a keystroke event, returns the same value as key_code(). 723 // For a keystroke event, returns the same value as key_code().
654 // For a character event, returns the same value as GetCharacter(). 724 // For a character event, returns the same value as GetCharacter().
655 // This exists for backwards compatibility with Windows key events. 725 // This exists for backwards compatibility with Windows key events.
656 uint16 GetConflatedWindowsKeyCode() const; 726 uint16 GetConflatedWindowsKeyCode() const;
657 727
658 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. 728 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win.
659 // TODO(msw): Additional work may be needed for analogues on other platforms. 729 // TODO(msw): Additional work may be needed for analogues on other platforms.
660 bool IsUnicodeKeyCode() const; 730 bool IsUnicodeKeyCode() const;
661 731
662 std::string code() const { return code_; } 732 // Returns the DOM .code (physical key identifier) for a keystroke event.
663 void set_code(const std::string& code) { code_ = code; } 733 DomCode code() const { return code_; };
734 std::string GetCodeString() const;
735
736 // Returns the DOM .key (layout meaning) for a keystroke event.
737 DomKey GetDomKey() const;
664 738
665 // Normalizes flags_ so that it describes the state after the event. 739 // Normalizes flags_ so that it describes the state after the event.
666 // (Native X11 event flags describe the state before the event.) 740 // (Native X11 event flags describe the state before the event.)
667 void NormalizeFlags(); 741 void NormalizeFlags();
668 742
669 // Returns true if the key event has already been processed by an input method
670 // and there is no need to pass the key event to the input method again.
671 bool IsTranslated() const;
672 // Marks this key event as translated or not translated.
673 void SetTranslated(bool translated);
674
675 protected: 743 protected:
676 friend class KeyEventTestApi; 744 friend class KeyEventTestApi;
677 745
746 // This allows a subclass TranslatedKeyEvent to be a non character event.
747 void set_is_char(bool is_char) { is_char_ = is_char; }
748
678 private: 749 private:
679 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). 750 // Determine key_ and character_ on a keystroke event from code_ and flags().
680 bool IsRightSideKey() const; 751 void ApplyLayout() const;
681 752
682 KeyboardCode key_code_; 753 KeyboardCode key_code_;
683 754
684 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') 755 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE).
685 // http://www.w3.org/TR/uievents/#keyboard-key-codes. 756 // http://www.w3.org/TR/DOM-Level-3-Events-code/
686 // 757 //
687 // This value represents the physical position in the keyboard and can be 758 // This value represents the physical position in the keyboard and can be
688 // converted from / to keyboard scan code like XKB. 759 // converted from / to keyboard scan code like XKB.
689 std::string code_; 760 DomCode code_;
690 761
691 // True if this is a character event, false if this is a keystroke event. 762 // True if this is a character event, false if this is a keystroke event.
692 bool is_char_; 763 bool is_char_;
693 764
694 // The platform related keycode value. For XKB, it's keysym value. 765 // The platform related keycode value. For XKB, it's keysym value.
695 // For now, this is used for CharacterComposer in ChromeOS. 766 // For now, this is used for CharacterComposer in ChromeOS.
696 uint32 platform_keycode_; 767 mutable uint32 platform_keycode_;
768
769 // TODO(kpschoedel): refactor so that key_ and character_ are not mutable.
770 // This requires defining the KeyEvent completely at construction rather
771 // than lazily under GetCharacter(), which likely also means removing
772 // the two 'incomplete' constructors. crbug.com/444045
773 //
774 // DOM KeyboardEvent |key|
775 // http://www.w3.org/TR/DOM-Level-3-Events-key/
776 //
777 // This value, together with character_, represents the meaning of a key.
778 // The value is DomKey::CHARACTER when the interpretation is a character.
779 // This, along with character_, is not necessarily initialized when the
780 // event is constructed; it may be set only if and when GetCharacter()
781 // or GetDomKey() is called.
782 mutable DomKey key_;
697 783
698 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') 784 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â')
699 // http://www.w3.org/TR/uievents/#keyboard-key-codes. 785 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
700 // 786 //
701 // This value represents the text that the key event will insert to input 787 // This value represents the text that the key event will insert to input
702 // field. For key with modifier key, it may have specifial text. 788 // field. For key with modifier key, it may have specifial text.
703 // e.g. CTRL+A has '\x01'. 789 // e.g. CTRL+A has '\x01'.
704 mutable base::char16 character_; 790 mutable base::char16 character_;
705 791
706 // Parts of our event handling require raw native events (see both the 792 // Parts of our event handling require raw native events (see both the
707 // windows and linux implementations of web_input_event in content/). Because 793 // windows and linux implementations of web_input_event in content/). Because
708 // mojo instead serializes and deserializes events in potentially different 794 // mojo instead serializes and deserializes events in potentially different
709 // processes, we need to have a mechanism to keep track of this data. 795 // processes, we need to have a mechanism to keep track of this data.
710 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; 796 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_;
797
798 static bool IsRepeated(const KeyEvent& event);
799
800 static KeyEvent* last_key_event_;
711 }; 801 };
712 802
713 class EVENTS_EXPORT ScrollEvent : public MouseEvent { 803 class EVENTS_EXPORT ScrollEvent : public MouseEvent {
714 public: 804 public:
715 ScrollEvent(); 805 explicit ScrollEvent(const base::NativeEvent& native_event);
716 template <class T> 806 template <class T>
717 ScrollEvent(const ScrollEvent& model, 807 ScrollEvent(const ScrollEvent& model,
718 T* source, 808 T* source,
719 T* target) 809 T* target)
720 : MouseEvent(model, source, target), 810 : MouseEvent(model, source, target),
721 x_offset_(model.x_offset_), 811 x_offset_(model.x_offset_),
722 y_offset_(model.y_offset_), 812 y_offset_(model.y_offset_),
723 x_offset_ordinal_(model.x_offset_ordinal_), 813 x_offset_ordinal_(model.x_offset_ordinal_),
724 y_offset_ordinal_(model.y_offset_ordinal_), 814 y_offset_ordinal_(model.y_offset_ordinal_),
725 finger_count_(model.finger_count_){ 815 finger_count_(model.finger_count_){
(...skipping 10 matching lines...) Expand all
736 float y_offset_ordinal, 826 float y_offset_ordinal,
737 int finger_count); 827 int finger_count);
738 828
739 // Scale the scroll event's offset value. 829 // Scale the scroll event's offset value.
740 // This is useful in the multi-monitor setup where it needs to be scaled 830 // This is useful in the multi-monitor setup where it needs to be scaled
741 // to provide a consistent user experience. 831 // to provide a consistent user experience.
742 void Scale(const float factor); 832 void Scale(const float factor);
743 833
744 float x_offset() const { return x_offset_; } 834 float x_offset() const { return x_offset_; }
745 float y_offset() const { return y_offset_; } 835 float y_offset() const { return y_offset_; }
746 void set_offset(float x, float y) {
747 x_offset_ = x;
748 y_offset_ = y;
749 }
750
751 float x_offset_ordinal() const { return x_offset_ordinal_; } 836 float x_offset_ordinal() const { return x_offset_ordinal_; }
752 float y_offset_ordinal() const { return y_offset_ordinal_; } 837 float y_offset_ordinal() const { return y_offset_ordinal_; }
753 void set_offset_ordinal(float x, float y) {
754 x_offset_ordinal_ = x;
755 y_offset_ordinal_ = y;
756 }
757
758 int finger_count() const { return finger_count_; } 838 int finger_count() const { return finger_count_; }
759 void set_finger_count(int finger_count) { finger_count_ = finger_count; }
760 839
761 private: 840 private:
762 // Potential accelerated offsets. 841 // Potential accelerated offsets.
763 float x_offset_; 842 float x_offset_;
764 float y_offset_; 843 float y_offset_;
765 // Unaccelerated offsets. 844 // Unaccelerated offsets.
766 float x_offset_ordinal_; 845 float x_offset_ordinal_;
767 float y_offset_ordinal_; 846 float y_offset_ordinal_;
768 // Number of fingers on the pad. 847 // Number of fingers on the pad.
769 int finger_count_; 848 int finger_count_;
(...skipping 20 matching lines...) Expand all
790 869
791 const GestureEventDetails& details() const { return details_; } 870 const GestureEventDetails& details() const { return details_; }
792 871
793 private: 872 private:
794 GestureEventDetails details_; 873 GestureEventDetails details_;
795 }; 874 };
796 875
797 } // namespace ui 876 } // namespace ui
798 877
799 #endif // UI_EVENTS_EVENT_H_ 878 #endif // UI_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « ui/events/devices/x11/touch_factory_x11.cc ('k') | ui/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698