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

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

Issue 404203003: Distinguish between keystroke and character events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsCharFromNative() for Mac build Created 6 years, 5 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/cocoa/events_mac.mm ('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"
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. 536 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
537 float radius_y_; 537 float radius_y_;
538 538
539 // Angle of the major axis away from the X axis. Default 0.0. 539 // Angle of the major axis away from the X axis. Default 0.0.
540 float rotation_angle_; 540 float rotation_angle_;
541 541
542 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. 542 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
543 float force_; 543 float force_;
544 }; 544 };
545 545
546 // A KeyEvent is really two distinct classes, melded together due to the
547 // DOM legacy of Windows key events: a keystroke event (is_char_ == false),
548 // or a character event (is_char_ == true).
549 //
550 // For a keystroke event,
551 // -- is_char_ is false.
552 // -- type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED,
553 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE.
554 // -- character_ functions as a bypass or cache for GetCharacter().
555 // -- key_code_ is a VKEY_ value associated with the key. For printable
556 // characters, this may or may not be a mapped value, imitating MS Windows:
557 // if the mapped key generates a character that has an associated VKEY_
558 // code, then key_code_ is that code; if not, then key_code_ is the unmapped
559 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use
560 // VKEY_Q for the key beside Tab, while French uses VKEY_A.
561 // -- code_ is in one-to-one correspondence with a physical keyboard
562 // location, and does not vary depending on key layout.
563 //
564 // For a character event,
565 // -- is_char_ is true.
566 // -- type() is ET_KEY_PRESSED.
567 // -- character_ is a UTF-16 character value.
568 // -- key_code_ is conflated with character_ by some code, because both
569 // arrive in the wParam field of a Windows event.
570 // -- code_ is "".
571 //
546 class EVENTS_EXPORT KeyEvent : public Event { 572 class EVENTS_EXPORT KeyEvent : public Event {
547 public: 573 public:
548 KeyEvent(const base::NativeEvent& native_event, bool is_char); 574 // Create a KeyEvent from a NativeEvent. For Windows this native event can
575 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message
576 // (WM_CHAR). Other systems have only keystroke events.
577 explicit KeyEvent(const base::NativeEvent& native_event);
549 578
550 // Used for synthetic events. 579 // Create a keystroke event.
551 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char); 580 KeyEvent(EventType type, KeyboardCode key_code, int flags);
581
582 // Create a character event.
583 KeyEvent(base::char16 character, KeyboardCode key_code, int flags);
552 584
553 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') 585 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA')
554 // See also: ui/events/keycodes/dom4/keycode_converter_data.h 586 // See also: ui/events/keycodes/dom4/keycode_converter_data.h
555 KeyEvent(EventType type, KeyboardCode key_code, const std::string& code, 587 KeyEvent(EventType type,
556 int flags, bool is_char); 588 KeyboardCode key_code,
589 const std::string& code,
590 int flags);
557 591
558 // This allows an I18N virtual keyboard to fabricate a keyboard event that 592 // This allows an I18N virtual keyboard to fabricate a keyboard event that
559 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small 593 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small
560 // letter A with acute, U+0410 Cyrillic capital letter A). 594 // letter A with acute, U+0410 Cyrillic capital letter A).
561 void set_character(uint16 character) { character_ = character; } 595 void set_character(base::char16 character) { character_ = character; }
562 596
563 // Gets the character generated by this key event. It only supports Unicode 597 // Gets the character generated by this key event. It only supports Unicode
564 // BMP characters. 598 // BMP characters.
565 uint16 GetCharacter() const; 599 base::char16 GetCharacter() const;
566 600
567 // Gets the platform key code. For XKB, this is the xksym value. 601 // Gets the platform key code. For XKB, this is the xksym value.
568 uint32 platform_keycode() const { return platform_keycode_; } 602 uint32 platform_keycode() const { return platform_keycode_; }
569 KeyboardCode key_code() const { return key_code_; } 603 KeyboardCode key_code() const { return key_code_; }
604
605 // True if this is a character event, false if this is a keystroke event.
570 bool is_char() const { return is_char_; } 606 bool is_char() const { return is_char_; }
571 607
572 // This is only intended to be used externally by classes that are modifying 608 // This is only intended to be used externally by classes that are modifying
573 // events in EventFilter::PreHandleKeyEvent(). set_character() should also be 609 // events in EventFilter::PreHandleKeyEvent(). set_character() should also be
574 // called. 610 // called.
575 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } 611 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; }
576 612
577 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. 613 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win.
578 // TODO(msw): Additional work may be needed for analogues on other platforms. 614 // TODO(msw): Additional work may be needed for analogues on other platforms.
579 bool IsUnicodeKeyCode() const; 615 bool IsUnicodeKeyCode() const;
580 616
581 std::string code() const { return code_; } 617 std::string code() const { return code_; }
582 618
583 // Normalizes flags_ to make it Windows/Mac compatible. Since the way 619 // Normalizes flags_ so that it describes the state after the event.
584 // of setting modifier mask on X is very different than Windows/Mac as shown 620 // (Native X11 event flags describe the state before the event.)
585 // in http://crbug.com/127142#c8, the normalization is necessary.
586 void NormalizeFlags(); 621 void NormalizeFlags();
587 622
588 // Returns true if the key event has already been processed by an input method 623 // Returns true if the key event has already been processed by an input method
589 // and there is no need to pass the key event to the input method again. 624 // and there is no need to pass the key event to the input method again.
590 bool IsTranslated() const; 625 bool IsTranslated() const;
591 // Marks this key event as translated or not translated. 626 // Marks this key event as translated or not translated.
592 void SetTranslated(bool translated); 627 void SetTranslated(bool translated);
593 628
594 protected: 629 protected:
630 friend class KeyEventTestApi;
631
595 // This allows a subclass TranslatedKeyEvent to be a non character event. 632 // This allows a subclass TranslatedKeyEvent to be a non character event.
596 void set_is_char(bool is_char) { is_char_ = is_char; } 633 void set_is_char(bool is_char) { is_char_ = is_char; }
597 634
598 private: 635 private:
599 KeyboardCode key_code_; 636 KeyboardCode key_code_;
600 637
601 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') 638 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space')
602 // http://www.w3.org/TR/uievents/#keyboard-key-codes. 639 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
603 // 640 //
604 // This value represents the physical position in the keyboard and can be 641 // This value represents the physical position in the keyboard and can be
605 // converted from / to keyboard scan code like XKB. 642 // converted from / to keyboard scan code like XKB.
606 std::string code_; 643 std::string code_;
607 644
608 // True if this is a translated character event (vs. a raw key down). Both 645 // True if this is a character event, false if this is a keystroke event.
609 // share the same type: ET_KEY_PRESSED.
610 bool is_char_; 646 bool is_char_;
611 647
612 // The platform related keycode value. For XKB, it's keysym value. 648 // The platform related keycode value. For XKB, it's keysym value.
613 // For now, this is used for CharacterComposer in ChromeOS. 649 // For now, this is used for CharacterComposer in ChromeOS.
614 uint32 platform_keycode_; 650 uint32 platform_keycode_;
615 651
616 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') 652 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â')
617 // http://www.w3.org/TR/uievents/#keyboard-key-codes. 653 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
618 // 654 //
619 // This value represents the text that the key event will insert to input 655 // This value represents the text that the key event will insert to input
620 // field. For key with modifier key, it may have specifial text. 656 // field. For key with modifier key, it may have specifial text.
621 // e.g. CTRL+A has '\x01'. 657 // e.g. CTRL+A has '\x01'.
622 uint16 character_; 658 base::char16 character_;
623 659
624 static bool IsRepeated(const KeyEvent& event); 660 static bool IsRepeated(const KeyEvent& event);
625 661
626 static KeyEvent* last_key_event_; 662 static KeyEvent* last_key_event_;
627 }; 663 };
628 664
629 class EVENTS_EXPORT ScrollEvent : public MouseEvent { 665 class EVENTS_EXPORT ScrollEvent : public MouseEvent {
630 public: 666 public:
631 explicit ScrollEvent(const base::NativeEvent& native_event); 667 explicit ScrollEvent(const base::NativeEvent& native_event);
632 template <class T> 668 template <class T>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 731
696 const GestureEventDetails& details() const { return details_; } 732 const GestureEventDetails& details() const { return details_; }
697 733
698 private: 734 private:
699 GestureEventDetails details_; 735 GestureEventDetails details_;
700 }; 736 };
701 737
702 } // namespace ui 738 } // namespace ui
703 739
704 #endif // UI_EVENTS_EVENT_H_ 740 #endif // UI_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « ui/events/cocoa/events_mac.mm ('k') | ui/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698