| OLD | NEW |
| 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" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 event_->result_ = static_cast<EventResult>(result); | 46 event_->result_ = static_cast<EventResult>(result); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 DispatcherApi(); | 50 DispatcherApi(); |
| 51 Event* event_; | 51 Event* event_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(DispatcherApi); | 53 DISALLOW_COPY_AND_ASSIGN(DispatcherApi); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 const base::NativeEvent& native_event() const { return native_event_; } | |
| 57 EventType type() const { return type_; } | 56 EventType type() const { return type_; } |
| 58 const std::string& name() const { return name_; } | 57 void set_type(EventType type) { type_ = type; } |
| 58 |
| 59 // time_stamp represents time since machine was booted. | 59 // time_stamp represents time since machine was booted. |
| 60 const base::TimeDelta& time_stamp() const { return time_stamp_; } | 60 const base::TimeDelta& time_stamp() const { return time_stamp_; } |
| 61 void set_time_stamp(const base::TimeDelta& stamp) { time_stamp_ = stamp; } |
| 62 |
| 61 int flags() const { return flags_; } | 63 int flags() const { return flags_; } |
| 62 | |
| 63 // This is only intended to be used externally by classes that are modifying | |
| 64 // events in an EventRewriter. | |
| 65 void set_flags(int flags) { flags_ = flags; } | 64 void set_flags(int flags) { flags_ = flags; } |
| 66 | 65 |
| 67 EventTarget* target() const { return target_; } | 66 EventTarget* target() const { return target_; } |
| 68 EventPhase phase() const { return phase_; } | 67 EventPhase phase() const { return phase_; } |
| 69 EventResult result() const { return result_; } | 68 EventResult result() const { return result_; } |
| 70 | 69 |
| 71 LatencyInfo* latency() { return &latency_; } | 70 LatencyInfo* latency() { return &latency_; } |
| 72 const LatencyInfo* latency() const { return &latency_; } | 71 const LatencyInfo* latency() const { return &latency_; } |
| 73 void set_latency(const LatencyInfo& latency) { latency_ = latency; } | 72 void set_latency(const LatencyInfo& latency) { latency_ = latency; } |
| 74 | 73 |
| 75 int source_device_id() const { return source_device_id_; } | 74 int source_device_id() const { return source_device_id_; } |
| 75 void set_source_device_id(const int id) { source_device_id_ = id; } |
| 76 | 76 |
| 77 // By default, events are "cancelable", this means any default processing that | 77 // By default, events are "cancelable", this means any default processing that |
| 78 // the containing abstraction layer may perform can be prevented by calling | 78 // the containing abstraction layer may perform can be prevented by calling |
| 79 // SetHandled(). SetHandled() or StopPropagation() must not be called for | 79 // SetHandled(). SetHandled() or StopPropagation() must not be called for |
| 80 // events that are not cancelable. | 80 // events that are not cancelable. |
| 81 bool cancelable() const { return cancelable_; } | 81 bool cancelable() const { return cancelable_; } |
| 82 | 82 |
| 83 // The following methods return true if the respective keys were pressed at | 83 // The following methods return true if the respective keys were pressed at |
| 84 // the time the event was created. | 84 // the time the event was created. |
| 85 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } | 85 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | |
| 205 // Immediately stops the propagation of the event. This must be called only | 202 // Immediately stops the propagation of the event. This must be called only |
| 206 // from an EventHandler during an event-dispatch. Any event handler that may | 203 // from an EventHandler during an event-dispatch. Any event handler that may |
| 207 // be in the list will not receive the event after this is called. | 204 // be in the list will not receive the event after this is called. |
| 208 // Note that StopPropagation() can be called only for cancelable events. | 205 // Note that StopPropagation() can be called only for cancelable events. |
| 209 void StopPropagation(); | 206 void StopPropagation(); |
| 210 bool stopped_propagation() const { return !!(result_ & ER_CONSUMED); } | 207 bool stopped_propagation() const { return !!(result_ & ER_CONSUMED); } |
| 211 | 208 |
| 212 // Marks the event as having been handled. A handled event does not reach the | 209 // Marks the event as having been handled. A handled event does not reach the |
| 213 // next event phase. For example, if an event is handled during the pre-target | 210 // next event phase. For example, if an event is handled during the pre-target |
| 214 // phase, then the event is dispatched to all pre-target handlers, but not to | 211 // phase, then the event is dispatched to all pre-target handlers, but not to |
| 215 // the target or post-target handlers. | 212 // the target or post-target handlers. |
| 216 // Note that SetHandled() can be called only for cancelable events. | 213 // Note that SetHandled() can be called only for cancelable events. |
| 217 void SetHandled(); | 214 void SetHandled(); |
| 218 bool handled() const { return result_ != ER_UNHANDLED; } | 215 bool handled() const { return result_ != ER_UNHANDLED; } |
| 219 | 216 |
| 220 protected: | 217 protected: |
| 218 Event(); |
| 221 Event(EventType type, base::TimeDelta time_stamp, int flags); | 219 Event(EventType type, base::TimeDelta time_stamp, int flags); |
| 222 Event(const base::NativeEvent& native_event, EventType type, int flags); | |
| 223 Event(const Event& copy); | 220 Event(const Event& copy); |
| 224 void SetType(EventType type); | 221 void SetType(EventType type); |
| 225 void set_delete_native_event(bool delete_native_event) { | |
| 226 delete_native_event_ = delete_native_event; | |
| 227 } | |
| 228 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } | 222 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } |
| 229 | 223 |
| 230 void set_time_stamp(const base::TimeDelta& time_stamp) { | |
| 231 time_stamp_ = time_stamp; | |
| 232 } | |
| 233 | |
| 234 void set_name(const std::string& name) { name_ = name; } | |
| 235 | |
| 236 private: | 224 private: |
| 237 friend class EventTestApi; | 225 friend class EventTestApi; |
| 238 | 226 |
| 239 EventType type_; | 227 EventType type_; |
| 240 std::string name_; | |
| 241 base::TimeDelta time_stamp_; | 228 base::TimeDelta time_stamp_; |
| 242 LatencyInfo latency_; | 229 LatencyInfo latency_; |
| 243 int flags_; | 230 int flags_; |
| 244 base::NativeEvent native_event_; | |
| 245 bool delete_native_event_; | |
| 246 bool cancelable_; | 231 bool cancelable_; |
| 247 EventTarget* target_; | 232 EventTarget* target_; |
| 248 EventPhase phase_; | 233 EventPhase phase_; |
| 249 EventResult result_; | 234 EventResult result_; |
| 250 | 235 |
| 251 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 236 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
| 252 // is not available. | 237 // is not available. |
| 253 int source_device_id_; | 238 int source_device_id_; |
| 254 }; | 239 }; |
| 255 | 240 |
| 256 class EVENTS_EXPORT CancelModeEvent : public Event { | 241 class EVENTS_EXPORT CancelModeEvent : public Event { |
| 257 public: | 242 public: |
| 258 CancelModeEvent(); | 243 CancelModeEvent(); |
| 259 ~CancelModeEvent() override; | 244 ~CancelModeEvent() override; |
| 260 }; | 245 }; |
| 261 | 246 |
| 262 class EVENTS_EXPORT LocatedEvent : public Event { | 247 class EVENTS_EXPORT LocatedEvent : public Event { |
| 263 public: | 248 public: |
| 249 LocatedEvent(); |
| 264 ~LocatedEvent() override; | 250 ~LocatedEvent() override; |
| 265 | 251 |
| 266 float x() const { return location_.x(); } | 252 float x() const { return location_.x(); } |
| 267 float y() const { return location_.y(); } | 253 float y() const { return location_.y(); } |
| 268 void set_location(const gfx::PointF& location) { location_ = location; } | 254 void set_location(const gfx::PointF& location) { location_ = location; } |
| 269 // TODO(tdresser): Always return floating point location. See | 255 // TODO(tdresser): Always return floating point location. See |
| 270 // crbug.com/337824. | 256 // crbug.com/337824. |
| 271 gfx::Point location() const { return gfx::ToFlooredPoint(location_); } | 257 gfx::Point location() const { return gfx::ToFlooredPoint(location_); } |
| 272 const gfx::PointF& location_f() const { return location_; } | 258 const gfx::PointF& location_f() const { return location_; } |
| 273 void set_root_location(const gfx::PointF& root_location) { | 259 void set_root_location(const gfx::PointF& root_location) { |
| 274 root_location_ = root_location; | 260 root_location_ = root_location; |
| 275 } | 261 } |
| 276 gfx::Point root_location() const { | 262 gfx::Point root_location() const { |
| 277 return gfx::ToFlooredPoint(root_location_); | 263 return gfx::ToFlooredPoint(root_location_); |
| 278 } | 264 } |
| 279 const gfx::PointF& root_location_f() const { | 265 const gfx::PointF& root_location_f() const { |
| 280 return root_location_; | 266 return root_location_; |
| 281 } | 267 } |
| 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 } |
| 282 | 272 |
| 283 // Transform the locations using |inverted_root_transform|. | 273 // Transform the locations using |inverted_root_transform|. |
| 284 // This is applied to both |location_| and |root_location_|. | 274 // This is applied to both |location_| and |root_location_|. |
| 285 virtual void UpdateForRootTransform( | 275 virtual void UpdateForRootTransform( |
| 286 const gfx::Transform& inverted_root_transform); | 276 const gfx::Transform& inverted_root_transform); |
| 287 | 277 |
| 288 template <class T> void ConvertLocationToTarget(T* source, T* target) { | 278 template <class T> void ConvertLocationToTarget(T* source, T* target) { |
| 289 if (!target || target == source) | 279 if (!target || target == source) |
| 290 return; | 280 return; |
| 291 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See | 281 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See |
| 292 // crbug.com/337824. | 282 // crbug.com/337824. |
| 293 gfx::Point offset = gfx::ToFlooredPoint(location_); | 283 gfx::Point offset = gfx::ToFlooredPoint(location_); |
| 294 T::ConvertPointToTarget(source, target, &offset); | 284 T::ConvertPointToTarget(source, target, &offset); |
| 295 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; | 285 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; |
| 296 location_= location_ - diff; | 286 location_= location_ - diff; |
| 297 } | 287 } |
| 298 | 288 |
| 299 protected: | 289 protected: |
| 300 friend class LocatedEventTestApi; | 290 friend class LocatedEventTestApi; |
| 301 explicit LocatedEvent(const base::NativeEvent& native_event); | |
| 302 | 291 |
| 303 // Create a new LocatedEvent which is identical to the provided model. | 292 // Create a new LocatedEvent which is identical to the provided model. |
| 304 // If source / target windows are provided, the model location will be | 293 // If source / target windows are provided, the model location will be |
| 305 // converted from |source| coordinate system to |target| coordinate system. | 294 // converted from |source| coordinate system to |target| coordinate system. |
| 306 template <class T> | 295 template <class T> |
| 307 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 296 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
| 308 : Event(model), | 297 : Event(model), |
| 309 location_(model.location_), | 298 location_(model.location_), |
| 310 root_location_(model.root_location_) { | 299 root_location_(model.root_location_), |
| 300 screen_location_(model.screen_location_) { |
| 311 ConvertLocationToTarget(source, target); | 301 ConvertLocationToTarget(source, target); |
| 312 } | 302 } |
| 313 | 303 |
| 314 // Used for synthetic events in testing. | 304 // Used for synthetic events in testing. |
| 315 LocatedEvent(EventType type, | 305 LocatedEvent(EventType type, |
| 316 const gfx::PointF& location, | 306 const gfx::PointF& location, |
| 317 const gfx::PointF& root_location, | 307 const gfx::PointF& root_location, |
| 318 base::TimeDelta time_stamp, | 308 base::TimeDelta time_stamp, |
| 319 int flags); | 309 int flags); |
| 320 | 310 |
| 321 gfx::PointF location_; | 311 gfx::PointF location_; |
| 322 | 312 |
| 323 // |location_| multiplied by an optional transformation matrix for | 313 // |location_| multiplied by an optional transformation matrix for |
| 324 // rotations, animations and skews. | 314 // rotations, animations and skews. |
| 325 gfx::PointF root_location_; | 315 gfx::PointF root_location_; |
| 316 |
| 317 // The system provided location of the event. |
| 318 gfx::Point screen_location_; |
| 326 }; | 319 }; |
| 327 | 320 |
| 328 class EVENTS_EXPORT MouseEvent : public LocatedEvent { | 321 class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| 329 public: | 322 public: |
| 330 explicit MouseEvent(const base::NativeEvent& native_event); | 323 MouseEvent(); |
| 331 | 324 |
| 332 // Create a new MouseEvent based on the provided model. | 325 // Create a new MouseEvent based on the provided model. |
| 333 // Uses the provided |type| and |flags| for the new event. | 326 // Uses the provided |type| and |flags| for the new event. |
| 334 // If source / target windows are provided, the model location will be | 327 // If source / target windows are provided, the model location will be |
| 335 // converted from |source| coordinate system to |target| coordinate system. | 328 // converted from |source| coordinate system to |target| coordinate system. |
| 336 template <class T> | 329 template <class T> |
| 337 MouseEvent(const MouseEvent& model, T* source, T* target) | 330 MouseEvent(const MouseEvent& model, T* source, T* target) |
| 338 : LocatedEvent(model, source, target), | 331 : LocatedEvent(model, source, target), |
| 339 changed_button_flags_(model.changed_button_flags_) { | 332 changed_button_flags_(model.changed_button_flags_) { |
| 340 } | 333 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // Identifies the button that changed. During a press this corresponds to the | 399 // Identifies the button that changed. During a press this corresponds to the |
| 407 // button that was pressed and during a release this corresponds to the button | 400 // button that was pressed and during a release this corresponds to the button |
| 408 // that was released. | 401 // that was released. |
| 409 // NOTE: during a press and release flags() contains the complete set of | 402 // NOTE: during a press and release flags() contains the complete set of |
| 410 // flags. Use this to determine the button that was pressed or released. | 403 // flags. Use this to determine the button that was pressed or released. |
| 411 int changed_button_flags() const { return changed_button_flags_; } | 404 int changed_button_flags() const { return changed_button_flags_; } |
| 412 | 405 |
| 413 // Updates the button that changed. | 406 // Updates the button that changed. |
| 414 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 407 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
| 415 | 408 |
| 409 // Returns the repeat count based on the previous mouse click, if it is |
| 410 // recent enough and within a small enough distance. |
| 411 static int GetRepeatCount(const MouseEvent& click_event); |
| 412 |
| 416 private: | 413 private: |
| 417 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 414 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
| 418 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 415 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
| 419 | 416 |
| 420 // Returns the repeat count based on the previous mouse click, if it is | |
| 421 // recent enough and within a small enough distance. | |
| 422 static int GetRepeatCount(const MouseEvent& click_event); | |
| 423 | |
| 424 // Resets the last_click_event_ for unit tests. | |
| 425 static void ResetLastClickForTest(); | |
| 426 | |
| 427 // See description above getter for details. | 417 // See description above getter for details. |
| 428 int changed_button_flags_; | 418 int changed_button_flags_; |
| 429 | |
| 430 static MouseEvent* last_click_event_; | |
| 431 | |
| 432 // We can create a MouseEvent for a native event more than once. We set this | |
| 433 // to true when the next event either has a different timestamp or we see a | |
| 434 // release signalling that the press (click) event was completed. | |
| 435 static bool last_click_complete_; | |
| 436 }; | 419 }; |
| 437 | 420 |
| 438 class ScrollEvent; | 421 class ScrollEvent; |
| 439 | 422 |
| 440 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent { | 423 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent { |
| 441 public: | 424 public: |
| 442 // See |offset| for details. | 425 // See |offset| for details. |
| 443 static const int kWheelDelta; | 426 static const int kWheelDelta; |
| 444 | 427 |
| 445 explicit MouseWheelEvent(const base::NativeEvent& native_event); | 428 MouseWheelEvent(); |
| 446 explicit MouseWheelEvent(const ScrollEvent& scroll_event); | 429 explicit MouseWheelEvent(const ScrollEvent& scroll_event); |
| 447 MouseWheelEvent(const MouseEvent& mouse_event, int x_offset, int y_offset); | 430 MouseWheelEvent(const MouseEvent& mouse_event, int x_offset, int y_offset); |
| 448 MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event); | 431 MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event); |
| 449 | 432 |
| 450 template <class T> | 433 template <class T> |
| 451 MouseWheelEvent(const MouseWheelEvent& model, | 434 MouseWheelEvent(const MouseWheelEvent& model, |
| 452 T* source, | 435 T* source, |
| 453 T* target) | 436 T* target) |
| 454 : MouseEvent(model, source, target, model.type(), model.flags()), | 437 : MouseEvent(model, source, target, model.type(), model.flags()), |
| 455 offset_(model.x_offset(), model.y_offset()) { | 438 offset_(model.x_offset(), model.y_offset()) { |
| 456 } | 439 } |
| 457 | 440 |
| 458 // Used for synthetic events in testing and by the gesture recognizer. | 441 // Used for synthetic events in testing and by the gesture recognizer. |
| 459 MouseWheelEvent(const gfx::Vector2d& offset, | 442 MouseWheelEvent(const gfx::Vector2d& offset, |
| 460 const gfx::PointF& location, | 443 const gfx::PointF& location, |
| 461 const gfx::PointF& root_location, | 444 const gfx::PointF& root_location, |
| 462 int flags, | 445 int flags, |
| 463 int changed_button_flags); | 446 int changed_button_flags); |
| 464 | 447 |
| 465 // The amount to scroll. This is in multiples of kWheelDelta. | 448 // The amount to scroll. This is in multiples of kWheelDelta. |
| 466 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. | 449 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. |
| 467 int x_offset() const { return offset_.x(); } | 450 int x_offset() const { return offset_.x(); } |
| 468 int y_offset() const { return offset_.y(); } | 451 int y_offset() const { return offset_.y(); } |
| 469 const gfx::Vector2d& offset() const { return offset_; } | 452 const gfx::Vector2d& offset() const { return offset_; } |
| 453 void set_offset(const gfx::Vector2d& offset) { offset_ = offset; } |
| 470 | 454 |
| 471 // Overridden from LocatedEvent. | 455 // Overridden from LocatedEvent. |
| 472 void UpdateForRootTransform( | 456 void UpdateForRootTransform( |
| 473 const gfx::Transform& inverted_root_transform) override; | 457 const gfx::Transform& inverted_root_transform) override; |
| 474 | 458 |
| 475 private: | 459 private: |
| 476 gfx::Vector2d offset_; | 460 gfx::Vector2d offset_; |
| 477 }; | 461 }; |
| 478 | 462 |
| 479 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 463 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| 480 public: | 464 public: |
| 481 explicit TouchEvent(const base::NativeEvent& native_event); | 465 TouchEvent(); |
| 482 | 466 |
| 483 // Create a new TouchEvent which is identical to the provided model. | 467 // Create a new TouchEvent which is identical to the provided model. |
| 484 // If source / target windows are provided, the model location will be | 468 // If source / target windows are provided, the model location will be |
| 485 // converted from |source| coordinate system to |target| coordinate system. | 469 // converted from |source| coordinate system to |target| coordinate system. |
| 486 template <class T> | 470 template <class T> |
| 487 TouchEvent(const TouchEvent& model, T* source, T* target) | 471 TouchEvent(const TouchEvent& model, T* source, T* target) |
| 488 : LocatedEvent(model, source, target), | 472 : LocatedEvent(model, source, target), |
| 489 touch_id_(model.touch_id_), | 473 touch_id_(model.touch_id_), |
| 490 radius_x_(model.radius_x_), | 474 radius_x_(model.radius_x_), |
| 491 radius_y_(model.radius_y_), | 475 radius_y_(model.radius_y_), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 504 int touch_id, | 488 int touch_id, |
| 505 base::TimeDelta timestamp, | 489 base::TimeDelta timestamp, |
| 506 float radius_x, | 490 float radius_x, |
| 507 float radius_y, | 491 float radius_y, |
| 508 float angle, | 492 float angle, |
| 509 float force); | 493 float force); |
| 510 | 494 |
| 511 ~TouchEvent() override; | 495 ~TouchEvent() override; |
| 512 | 496 |
| 513 int touch_id() const { return touch_id_; } | 497 int touch_id() const { return touch_id_; } |
| 498 void set_touch_id(int touch_id) { touch_id_ = touch_id; } |
| 499 |
| 514 float radius_x() const { return radius_x_; } | 500 float radius_x() const { return radius_x_; } |
| 501 void set_radius_x(const float r) { radius_x_ = r; } |
| 515 float radius_y() const { return radius_y_; } | 502 float radius_y() const { return radius_y_; } |
| 503 void set_radius_y(const float r) { radius_y_ = r; } |
| 504 |
| 516 float rotation_angle() const { return rotation_angle_; } | 505 float rotation_angle() const { return rotation_angle_; } |
| 506 void set_rotation_angle(float rotation_angle) { |
| 507 rotation_angle_ = rotation_angle; |
| 508 } |
| 509 |
| 517 float force() const { return force_; } | 510 float force() const { return force_; } |
| 518 | 511 void set_force(float force) { force_ = force; } |
| 519 // Used for unit tests. | |
| 520 void set_radius_x(const float r) { radius_x_ = r; } | |
| 521 void set_radius_y(const float r) { radius_y_ = r; } | |
| 522 | 512 |
| 523 // Overridden from LocatedEvent. | 513 // Overridden from LocatedEvent. |
| 524 void UpdateForRootTransform( | 514 void UpdateForRootTransform( |
| 525 const gfx::Transform& inverted_root_transform) override; | 515 const gfx::Transform& inverted_root_transform) override; |
| 526 | 516 |
| 527 protected: | 517 protected: |
| 528 void set_radius(float radius_x, float radius_y) { | 518 void set_radius(float radius_x, float radius_y) { |
| 529 radius_x_ = radius_x; | 519 radius_x_ = radius_x; |
| 530 radius_y_ = radius_y; | 520 radius_y_ = radius_y; |
| 531 } | 521 } |
| 532 | 522 |
| 533 void set_rotation_angle(float rotation_angle) { | |
| 534 rotation_angle_ = rotation_angle; | |
| 535 } | |
| 536 | |
| 537 void set_force(float force) { force_ = force; } | |
| 538 | |
| 539 private: | 523 private: |
| 540 // The identity (typically finger) of the touch starting at 0 and incrementing | 524 // The identity (typically finger) of the touch starting at 0 and incrementing |
| 541 // for each separable additional touch that the hardware can detect. | 525 // for each separable additional touch that the hardware can detect. |
| 542 const int touch_id_; | 526 int touch_id_; |
| 543 | 527 |
| 544 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 528 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
| 545 float radius_x_; | 529 float radius_x_; |
| 546 | 530 |
| 547 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 531 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| 548 float radius_y_; | 532 float radius_y_; |
| 549 | 533 |
| 550 // Angle of the major axis away from the X axis. Default 0.0. | 534 // Angle of the major axis away from the X axis. Default 0.0. |
| 551 float rotation_angle_; | 535 float rotation_angle_; |
| 552 | 536 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 // For a character event, | 570 // For a character event, |
| 587 // -- is_char_ is true. | 571 // -- is_char_ is true. |
| 588 // -- type() is ET_KEY_PRESSED. | 572 // -- type() is ET_KEY_PRESSED. |
| 589 // -- character_ is a UTF-16 character value. | 573 // -- character_ is a UTF-16 character value. |
| 590 // -- key_code_ is conflated with character_ by some code, because both | 574 // -- key_code_ is conflated with character_ by some code, because both |
| 591 // arrive in the wParam field of a Windows event. | 575 // arrive in the wParam field of a Windows event. |
| 592 // -- code_ is the empty string. | 576 // -- code_ is the empty string. |
| 593 // | 577 // |
| 594 class EVENTS_EXPORT KeyEvent : public Event { | 578 class EVENTS_EXPORT KeyEvent : public Event { |
| 595 public: | 579 public: |
| 596 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 580 KeyEvent(); |
| 597 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | |
| 598 // (WM_CHAR). Other systems have only keystroke events. | |
| 599 explicit KeyEvent(const base::NativeEvent& native_event); | |
| 600 | 581 |
| 601 // Create a keystroke event. | 582 // Create a keystroke event. |
| 602 KeyEvent(EventType type, KeyboardCode key_code, int flags); | 583 KeyEvent(EventType type, KeyboardCode key_code, int flags); |
| 603 | 584 |
| 604 // Create a character event. | 585 // Create a character event. |
| 605 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); | 586 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); |
| 606 | 587 |
| 607 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') | 588 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') |
| 608 // See also: ui/events/keycodes/dom4/keycode_converter_data.h | 589 // See also: ui/events/keycodes/dom4/keycode_converter_data.h |
| 609 KeyEvent(EventType type, | 590 KeyEvent(EventType type, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; | 622 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; |
| 642 // otherwise returns the same as GetCharacter(). | 623 // otherwise returns the same as GetCharacter(). |
| 643 base::char16 GetUnmodifiedText() const; | 624 base::char16 GetUnmodifiedText() const; |
| 644 | 625 |
| 645 // If the Control key is down in the event, returns a layout-independent | 626 // If the Control key is down in the event, returns a layout-independent |
| 646 // character (corresponding to US layout); otherwise returns the same | 627 // character (corresponding to US layout); otherwise returns the same |
| 647 // as GetUnmodifiedText(). | 628 // as GetUnmodifiedText(). |
| 648 base::char16 GetText() const; | 629 base::char16 GetText() const; |
| 649 | 630 |
| 650 // Gets the platform key code. For XKB, this is the xksym value. | 631 // Gets the platform key code. For XKB, this is the xksym value. |
| 632 uint32 platform_keycode() const { return platform_keycode_; } |
| 651 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } | 633 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } |
| 652 uint32 platform_keycode() const { return platform_keycode_; } | |
| 653 | 634 |
| 654 // Gets the associated (Windows-based) KeyboardCode for this key event. | 635 // Gets the associated (Windows-based) KeyboardCode for this key event. |
| 655 // Historically, this has also been used to obtain the character associated | 636 // Historically, this has also been used to obtain the character associated |
| 656 // with a character event, because both use the Window message 'wParam' field. | 637 // with a character event, because both use the Window message 'wParam' field. |
| 657 // This should be avoided; if necessary for backwards compatibility, use | 638 // This should be avoided; if necessary for backwards compatibility, use |
| 658 // GetConflatedWindowsKeyCode(). | 639 // GetConflatedWindowsKeyCode(). |
| 659 KeyboardCode key_code() const { return key_code_; } | 640 KeyboardCode key_code() const { return key_code_; } |
| 641 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } |
| 660 | 642 |
| 661 // True if this is a character event, false if this is a keystroke event. | 643 // True if this is a character event, false if this is a keystroke event. |
| 662 bool is_char() const { return is_char_; } | 644 bool is_char() const { return is_char_; } |
| 663 | 645 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 664 // This is only intended to be used externally by classes that are modifying | |
| 665 // events in an EventRewriter. | |
| 666 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } | |
| 667 | 646 |
| 668 // Returns the same value as key_code(), except that located codes are | 647 // Returns the same value as key_code(), except that located codes are |
| 669 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT | 648 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT |
| 670 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical | 649 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical |
| 671 // for legacy DOM reasons. | 650 // for legacy DOM reasons. |
| 672 KeyboardCode GetLocatedWindowsKeyboardCode() const; | 651 KeyboardCode GetLocatedWindowsKeyboardCode() const; |
| 673 | 652 |
| 674 // For a keystroke event, returns the same value as key_code(). | 653 // For a keystroke event, returns the same value as key_code(). |
| 675 // For a character event, returns the same value as GetCharacter(). | 654 // For a character event, returns the same value as GetCharacter(). |
| 676 // This exists for backwards compatibility with Windows key events. | 655 // This exists for backwards compatibility with Windows key events. |
| 677 uint16 GetConflatedWindowsKeyCode() const; | 656 uint16 GetConflatedWindowsKeyCode() const; |
| 678 | 657 |
| 679 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. | 658 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. |
| 680 // TODO(msw): Additional work may be needed for analogues on other platforms. | 659 // TODO(msw): Additional work may be needed for analogues on other platforms. |
| 681 bool IsUnicodeKeyCode() const; | 660 bool IsUnicodeKeyCode() const; |
| 682 | 661 |
| 683 std::string code() const { return code_; } | 662 std::string code() const { return code_; } |
| 663 void set_code(const std::string& code) { code_ = code; } |
| 684 | 664 |
| 685 // Normalizes flags_ so that it describes the state after the event. | 665 // Normalizes flags_ so that it describes the state after the event. |
| 686 // (Native X11 event flags describe the state before the event.) | 666 // (Native X11 event flags describe the state before the event.) |
| 687 void NormalizeFlags(); | 667 void NormalizeFlags(); |
| 688 | 668 |
| 689 // Returns true if the key event has already been processed by an input method | 669 // Returns true if the key event has already been processed by an input method |
| 690 // and there is no need to pass the key event to the input method again. | 670 // and there is no need to pass the key event to the input method again. |
| 691 bool IsTranslated() const; | 671 bool IsTranslated() const; |
| 692 // Marks this key event as translated or not translated. | 672 // Marks this key event as translated or not translated. |
| 693 void SetTranslated(bool translated); | 673 void SetTranslated(bool translated); |
| 694 | 674 |
| 695 protected: | 675 protected: |
| 696 friend class KeyEventTestApi; | 676 friend class KeyEventTestApi; |
| 697 | 677 |
| 698 // This allows a subclass TranslatedKeyEvent to be a non character event. | |
| 699 void set_is_char(bool is_char) { is_char_ = is_char; } | |
| 700 | |
| 701 private: | 678 private: |
| 702 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). | 679 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). |
| 703 bool IsRightSideKey() const; | 680 bool IsRightSideKey() const; |
| 704 | 681 |
| 705 KeyboardCode key_code_; | 682 KeyboardCode key_code_; |
| 706 | 683 |
| 707 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') | 684 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') |
| 708 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 685 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 709 // | 686 // |
| 710 // This value represents the physical position in the keyboard and can be | 687 // This value represents the physical position in the keyboard and can be |
| (...skipping 13 matching lines...) Expand all Loading... |
| 724 // This value represents the text that the key event will insert to input | 701 // This value represents the text that the key event will insert to input |
| 725 // field. For key with modifier key, it may have specifial text. | 702 // field. For key with modifier key, it may have specifial text. |
| 726 // e.g. CTRL+A has '\x01'. | 703 // e.g. CTRL+A has '\x01'. |
| 727 mutable base::char16 character_; | 704 mutable base::char16 character_; |
| 728 | 705 |
| 729 // Parts of our event handling require raw native events (see both the | 706 // Parts of our event handling require raw native events (see both the |
| 730 // windows and linux implementations of web_input_event in content/). Because | 707 // windows and linux implementations of web_input_event in content/). Because |
| 731 // mojo instead serializes and deserializes events in potentially different | 708 // mojo instead serializes and deserializes events in potentially different |
| 732 // processes, we need to have a mechanism to keep track of this data. | 709 // processes, we need to have a mechanism to keep track of this data. |
| 733 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; | 710 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; |
| 734 | |
| 735 static bool IsRepeated(const KeyEvent& event); | |
| 736 | |
| 737 static KeyEvent* last_key_event_; | |
| 738 }; | 711 }; |
| 739 | 712 |
| 740 class EVENTS_EXPORT ScrollEvent : public MouseEvent { | 713 class EVENTS_EXPORT ScrollEvent : public MouseEvent { |
| 741 public: | 714 public: |
| 742 explicit ScrollEvent(const base::NativeEvent& native_event); | 715 ScrollEvent(); |
| 743 template <class T> | 716 template <class T> |
| 744 ScrollEvent(const ScrollEvent& model, | 717 ScrollEvent(const ScrollEvent& model, |
| 745 T* source, | 718 T* source, |
| 746 T* target) | 719 T* target) |
| 747 : MouseEvent(model, source, target), | 720 : MouseEvent(model, source, target), |
| 748 x_offset_(model.x_offset_), | 721 x_offset_(model.x_offset_), |
| 749 y_offset_(model.y_offset_), | 722 y_offset_(model.y_offset_), |
| 750 x_offset_ordinal_(model.x_offset_ordinal_), | 723 x_offset_ordinal_(model.x_offset_ordinal_), |
| 751 y_offset_ordinal_(model.y_offset_ordinal_), | 724 y_offset_ordinal_(model.y_offset_ordinal_), |
| 752 finger_count_(model.finger_count_){ | 725 finger_count_(model.finger_count_){ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 763 float y_offset_ordinal, | 736 float y_offset_ordinal, |
| 764 int finger_count); | 737 int finger_count); |
| 765 | 738 |
| 766 // Scale the scroll event's offset value. | 739 // Scale the scroll event's offset value. |
| 767 // This is useful in the multi-monitor setup where it needs to be scaled | 740 // This is useful in the multi-monitor setup where it needs to be scaled |
| 768 // to provide a consistent user experience. | 741 // to provide a consistent user experience. |
| 769 void Scale(const float factor); | 742 void Scale(const float factor); |
| 770 | 743 |
| 771 float x_offset() const { return x_offset_; } | 744 float x_offset() const { return x_offset_; } |
| 772 float y_offset() const { return y_offset_; } | 745 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 |
| 773 float x_offset_ordinal() const { return x_offset_ordinal_; } | 751 float x_offset_ordinal() const { return x_offset_ordinal_; } |
| 774 float y_offset_ordinal() const { return y_offset_ordinal_; } | 752 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 |
| 775 int finger_count() const { return finger_count_; } | 758 int finger_count() const { return finger_count_; } |
| 759 void set_finger_count(int finger_count) { finger_count_ = finger_count; } |
| 776 | 760 |
| 777 private: | 761 private: |
| 778 // Potential accelerated offsets. | 762 // Potential accelerated offsets. |
| 779 float x_offset_; | 763 float x_offset_; |
| 780 float y_offset_; | 764 float y_offset_; |
| 781 // Unaccelerated offsets. | 765 // Unaccelerated offsets. |
| 782 float x_offset_ordinal_; | 766 float x_offset_ordinal_; |
| 783 float y_offset_ordinal_; | 767 float y_offset_ordinal_; |
| 784 // Number of fingers on the pad. | 768 // Number of fingers on the pad. |
| 785 int finger_count_; | 769 int finger_count_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 806 | 790 |
| 807 const GestureEventDetails& details() const { return details_; } | 791 const GestureEventDetails& details() const { return details_; } |
| 808 | 792 |
| 809 private: | 793 private: |
| 810 GestureEventDetails details_; | 794 GestureEventDetails details_; |
| 811 }; | 795 }; |
| 812 | 796 |
| 813 } // namespace ui | 797 } // namespace ui |
| 814 | 798 |
| 815 #endif // UI_EVENTS_EVENT_H_ | 799 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |