| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // By default, events are "cancelable", this means any default processing that | 82 // By default, events are "cancelable", this means any default processing that |
| 83 // the containing abstraction layer may perform can be prevented by calling | 83 // the containing abstraction layer may perform can be prevented by calling |
| 84 // SetHandled(). SetHandled() or StopPropagation() must not be called for | 84 // SetHandled(). SetHandled() or StopPropagation() must not be called for |
| 85 // events that are not cancelable. | 85 // events that are not cancelable. |
| 86 bool cancelable() const { return cancelable_; } | 86 bool cancelable() const { return cancelable_; } |
| 87 | 87 |
| 88 // The following methods return true if the respective keys were pressed at | 88 // The following methods return true if the respective keys were pressed at |
| 89 // the time the event was created. | 89 // the time the event was created. |
| 90 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } | 90 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } |
| 91 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } | 91 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } |
| 92 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; } | |
| 93 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } | 92 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } |
| 93 bool IsCommandDown() const { return (flags_ & EF_COMMAND_DOWN) != 0; } |
| 94 bool IsAltGrDown() const { return (flags_ & EF_ALTGR_DOWN) != 0; } | 94 bool IsAltGrDown() const { return (flags_ & EF_ALTGR_DOWN) != 0; } |
| 95 bool IsCommandDown() const { return (flags_ & EF_COMMAND_DOWN) != 0; } | 95 bool IsCapsLockOn() const { return (flags_ & EF_CAPS_LOCK_ON) != 0; } |
| 96 bool IsRepeat() const { return (flags_ & EF_IS_REPEAT) != 0; } | |
| 97 | 96 |
| 98 bool IsKeyEvent() const { | 97 bool IsKeyEvent() const { |
| 99 return type_ == ET_KEY_PRESSED || type_ == ET_KEY_RELEASED; | 98 return type_ == ET_KEY_PRESSED || type_ == ET_KEY_RELEASED; |
| 100 } | 99 } |
| 101 | 100 |
| 102 bool IsMouseEvent() const { | 101 bool IsMouseEvent() const { |
| 103 return type_ == ET_MOUSE_PRESSED || | 102 return type_ == ET_MOUSE_PRESSED || |
| 104 type_ == ET_MOUSE_DRAGGED || | 103 type_ == ET_MOUSE_DRAGGED || |
| 105 type_ == ET_MOUSE_RELEASED || | 104 type_ == ET_MOUSE_RELEASED || |
| 106 type_ == ET_MOUSE_MOVED || | 105 type_ == ET_MOUSE_MOVED || |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 436 } |
| 438 | 437 |
| 439 bool IsRightMouseButton() const { | 438 bool IsRightMouseButton() const { |
| 440 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0; | 439 return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0; |
| 441 } | 440 } |
| 442 | 441 |
| 443 bool IsAnyButton() const { | 442 bool IsAnyButton() const { |
| 444 return button_flags() != 0; | 443 return button_flags() != 0; |
| 445 } | 444 } |
| 446 | 445 |
| 446 // Returns the flags for the mouse buttons. |
| 447 int button_flags() const { |
| 448 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | |
| 449 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON | |
| 450 EF_FORWARD_MOUSE_BUTTON); |
| 451 } |
| 452 |
| 447 // Compares two mouse down events and returns true if the second one should | 453 // Compares two mouse down events and returns true if the second one should |
| 448 // be considered a repeat of the first. | 454 // be considered a repeat of the first. |
| 449 static bool IsRepeatedClickEvent( | 455 static bool IsRepeatedClickEvent( |
| 450 const MouseEvent& event1, | 456 const MouseEvent& event1, |
| 451 const MouseEvent& event2); | 457 const MouseEvent& event2); |
| 452 | 458 |
| 453 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. | 459 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. |
| 454 int GetClickCount() const; | 460 int GetClickCount() const; |
| 455 | 461 |
| 456 // Set the click count for a mousedown message. Can be 1, 2 or 3. | 462 // Set the click count for a mousedown message. Can be 1, 2 or 3. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 469 // Event details common to MouseEvent and TouchEvent. | 475 // Event details common to MouseEvent and TouchEvent. |
| 470 const PointerDetails& pointer_details() const { return pointer_details_; } | 476 const PointerDetails& pointer_details() const { return pointer_details_; } |
| 471 void set_pointer_details(const PointerDetails& details) { | 477 void set_pointer_details(const PointerDetails& details) { |
| 472 pointer_details_ = details; | 478 pointer_details_ = details; |
| 473 } | 479 } |
| 474 | 480 |
| 475 private: | 481 private: |
| 476 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 482 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
| 477 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 483 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
| 478 | 484 |
| 479 // Returns the flags for the mouse buttons. | |
| 480 int button_flags() const { | |
| 481 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | | |
| 482 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON | | |
| 483 EF_FORWARD_MOUSE_BUTTON); | |
| 484 } | |
| 485 | |
| 486 // Returns the repeat count based on the previous mouse click, if it is | 485 // Returns the repeat count based on the previous mouse click, if it is |
| 487 // recent enough and within a small enough distance. | 486 // recent enough and within a small enough distance. |
| 488 static int GetRepeatCount(const MouseEvent& click_event); | 487 static int GetRepeatCount(const MouseEvent& click_event); |
| 489 | 488 |
| 490 // Resets the last_click_event_ for unit tests. | 489 // Resets the last_click_event_ for unit tests. |
| 491 static void ResetLastClickForTest(); | 490 static void ResetLastClickForTest(); |
| 492 | 491 |
| 493 // See description above getter for details. | 492 // See description above getter for details. |
| 494 int changed_button_flags_; | 493 int changed_button_flags_; |
| 495 | 494 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 750 |
| 752 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; | 751 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; |
| 753 // otherwise returns the same as GetCharacter(). | 752 // otherwise returns the same as GetCharacter(). |
| 754 base::char16 GetUnmodifiedText() const; | 753 base::char16 GetUnmodifiedText() const; |
| 755 | 754 |
| 756 // If the Control key is down in the event, returns a layout-independent | 755 // If the Control key is down in the event, returns a layout-independent |
| 757 // character (corresponding to US layout); otherwise returns the same | 756 // character (corresponding to US layout); otherwise returns the same |
| 758 // as GetUnmodifiedText(). | 757 // as GetUnmodifiedText(). |
| 759 base::char16 GetText() const; | 758 base::char16 GetText() const; |
| 760 | 759 |
| 760 // True if this is a character event, false if this is a keystroke event. |
| 761 bool is_char() const { return is_char_; } |
| 762 |
| 763 bool is_repeat() const { return (flags() & EF_IS_REPEAT) != 0; } |
| 764 |
| 761 // Gets the associated (Windows-based) KeyboardCode for this key event. | 765 // Gets the associated (Windows-based) KeyboardCode for this key event. |
| 762 // Historically, this has also been used to obtain the character associated | 766 // Historically, this has also been used to obtain the character associated |
| 763 // with a character event, because both use the Window message 'wParam' field. | 767 // with a character event, because both use the Window message 'wParam' field. |
| 764 // This should be avoided; if necessary for backwards compatibility, use | 768 // This should be avoided; if necessary for backwards compatibility, use |
| 765 // GetConflatedWindowsKeyCode(). | 769 // GetConflatedWindowsKeyCode(). |
| 766 KeyboardCode key_code() const { return key_code_; } | 770 KeyboardCode key_code() const { return key_code_; } |
| 767 | 771 |
| 768 // True if this is a character event, false if this is a keystroke event. | |
| 769 bool is_char() const { return is_char_; } | |
| 770 | |
| 771 // This is only intended to be used externally by classes that are modifying | 772 // This is only intended to be used externally by classes that are modifying |
| 772 // events in an EventRewriter. | 773 // events in an EventRewriter. |
| 773 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } | 774 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } |
| 774 | 775 |
| 775 // Returns the same value as key_code(), except that located codes are | 776 // Returns the same value as key_code(), except that located codes are |
| 776 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT | 777 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT |
| 777 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical | 778 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical |
| 778 // for legacy DOM reasons. | 779 // for legacy DOM reasons. |
| 779 KeyboardCode GetLocatedWindowsKeyboardCode() const; | 780 KeyboardCode GetLocatedWindowsKeyboardCode() const; |
| 780 | 781 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 | 915 |
| 915 const GestureEventDetails& details() const { return details_; } | 916 const GestureEventDetails& details() const { return details_; } |
| 916 | 917 |
| 917 private: | 918 private: |
| 918 GestureEventDetails details_; | 919 GestureEventDetails details_; |
| 919 }; | 920 }; |
| 920 | 921 |
| 921 } // namespace ui | 922 } // namespace ui |
| 922 | 923 |
| 923 #endif // UI_EVENTS_EVENT_H_ | 924 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |