| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // Used for synthetic events in testing, gesture recognizer and Ozone | 354 // Used for synthetic events in testing, gesture recognizer and Ozone |
| 355 MouseEvent(EventType type, | 355 MouseEvent(EventType type, |
| 356 const gfx::PointF& location, | 356 const gfx::PointF& location, |
| 357 const gfx::PointF& root_location, | 357 const gfx::PointF& root_location, |
| 358 base::TimeDelta time_stamp, | 358 base::TimeDelta time_stamp, |
| 359 int flags, | 359 int flags, |
| 360 int changed_button_flags); | 360 int changed_button_flags); |
| 361 | 361 |
| 362 // Conveniences to quickly test what button is down | 362 // Conveniences to quickly test what button is down |
| 363 bool IsOnlyLeftMouseButton() const { | 363 bool IsOnlyLeftMouseButton() const { |
| 364 return (flags() & EF_LEFT_MOUSE_BUTTON) && | 364 return button_flags() == EF_LEFT_MOUSE_BUTTON; |
| 365 !(flags() & (EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON)); | |
| 366 } | 365 } |
| 367 | 366 |
| 368 bool IsLeftMouseButton() const { | 367 bool IsLeftMouseButton() const { |
| 369 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0; | 368 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0; |
| 370 } | 369 } |
| 371 | 370 |
| 372 bool IsOnlyMiddleMouseButton() const { | 371 bool IsOnlyMiddleMouseButton() const { |
| 373 return (flags() & EF_MIDDLE_MOUSE_BUTTON) && | 372 return button_flags() == EF_MIDDLE_MOUSE_BUTTON; |
| 374 !(flags() & (EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON)); | |
| 375 } | 373 } |
| 376 | 374 |
| 377 bool IsMiddleMouseButton() const { | 375 bool IsMiddleMouseButton() const { |
| 378 return (flags() & EF_MIDDLE_MOUSE_BUTTON) != 0; | 376 return (flags() & EF_MIDDLE_MOUSE_BUTTON) != 0; |
| 379 } | 377 } |
| 380 | 378 |
| 381 bool IsOnlyRightMouseButton() const { | 379 bool IsOnlyRightMouseButton() const { |
| 382 return (flags() & EF_RIGHT_MOUSE_BUTTON) && | 380 return button_flags() == EF_RIGHT_MOUSE_BUTTON; |
| 383 !(flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON)); | |
| 384 } | 381 } |
| 385 | 382 |
| 386 bool IsRightMouseButton() const { | 383 bool IsRightMouseButton() const { |
| 387 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0; | 384 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0; |
| 388 } | 385 } |
| 389 | 386 |
| 390 bool IsAnyButton() const { | 387 bool IsAnyButton() const { |
| 391 return (flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | | 388 return button_flags() != 0; |
| 392 EF_RIGHT_MOUSE_BUTTON)) != 0; | |
| 393 } | 389 } |
| 394 | 390 |
| 395 // Compares two mouse down events and returns true if the second one should | 391 // Compares two mouse down events and returns true if the second one should |
| 396 // be considered a repeat of the first. | 392 // be considered a repeat of the first. |
| 397 static bool IsRepeatedClickEvent( | 393 static bool IsRepeatedClickEvent( |
| 398 const MouseEvent& event1, | 394 const MouseEvent& event1, |
| 399 const MouseEvent& event2); | 395 const MouseEvent& event2); |
| 400 | 396 |
| 401 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. | 397 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. |
| 402 int GetClickCount() const; | 398 int GetClickCount() const; |
| 403 | 399 |
| 404 // Set the click count for a mousedown message. Can be 1, 2 or 3. | 400 // Set the click count for a mousedown message. Can be 1, 2 or 3. |
| 405 void SetClickCount(int click_count); | 401 void SetClickCount(int click_count); |
| 406 | 402 |
| 407 // Identifies the button that changed. During a press this corresponds to the | 403 // Identifies the button that changed. During a press this corresponds to the |
| 408 // button that was pressed and during a release this corresponds to the button | 404 // button that was pressed and during a release this corresponds to the button |
| 409 // that was released. | 405 // that was released. |
| 410 // NOTE: during a press and release flags() contains the complete set of | 406 // NOTE: during a press and release flags() contains the complete set of |
| 411 // flags. Use this to determine the button that was pressed or released. | 407 // flags. Use this to determine the button that was pressed or released. |
| 412 int changed_button_flags() const { return changed_button_flags_; } | 408 int changed_button_flags() const { return changed_button_flags_; } |
| 413 | 409 |
| 414 // Updates the button that changed. | 410 // Updates the button that changed. |
| 415 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 411 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
| 416 | 412 |
| 417 private: | 413 private: |
| 418 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 414 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
| 419 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 415 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
| 420 | 416 |
| 417 // Returns the flags for the mouse buttons. |
| 418 int button_flags() const { |
| 419 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | |
| 420 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON | |
| 421 EF_FORWARD_MOUSE_BUTTON); |
| 422 } |
| 423 |
| 421 // Returns the repeat count based on the previous mouse click, if it is | 424 // Returns the repeat count based on the previous mouse click, if it is |
| 422 // recent enough and within a small enough distance. | 425 // recent enough and within a small enough distance. |
| 423 static int GetRepeatCount(const MouseEvent& click_event); | 426 static int GetRepeatCount(const MouseEvent& click_event); |
| 424 | 427 |
| 425 // Resets the last_click_event_ for unit tests. | 428 // Resets the last_click_event_ for unit tests. |
| 426 static void ResetLastClickForTest(); | 429 static void ResetLastClickForTest(); |
| 427 | 430 |
| 428 // See description above getter for details. | 431 // See description above getter for details. |
| 429 int changed_button_flags_; | 432 int changed_button_flags_; |
| 430 | 433 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 | 881 |
| 879 const GestureEventDetails& details() const { return details_; } | 882 const GestureEventDetails& details() const { return details_; } |
| 880 | 883 |
| 881 private: | 884 private: |
| 882 GestureEventDetails details_; | 885 GestureEventDetails details_; |
| 883 }; | 886 }; |
| 884 | 887 |
| 885 } // namespace ui | 888 } // namespace ui |
| 886 | 889 |
| 887 #endif // UI_EVENTS_EVENT_H_ | 890 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |