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

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

Issue 742103002: Ozone keyboard layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lite-code
Patch Set: address review comments (Wez, 2) Created 6 years 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
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/point.h"
21 #include "ui/gfx/point_conversions.h" 21 #include "ui/gfx/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; 29 enum class DomCode;
30 enum class DomKey;
30 31
31 class EVENTS_EXPORT Event { 32 class EVENTS_EXPORT Event {
32 public: 33 public:
33 static scoped_ptr<Event> Clone(const Event& event); 34 static scoped_ptr<Event> Clone(const Event& event);
34 35
35 virtual ~Event(); 36 virtual ~Event();
36 37
37 class DispatcherApi { 38 class DispatcherApi {
38 public: 39 public:
39 explicit DispatcherApi(Event* event) : event_(event) {} 40 explicit DispatcherApi(Event* event) : event_(event) {}
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 567
567 virtual ExtendedKeyEventData* Clone() const = 0; 568 virtual ExtendedKeyEventData* Clone() const = 0;
568 }; 569 };
569 570
570 // A KeyEvent is really two distinct classes, melded together due to the 571 // A KeyEvent is really two distinct classes, melded together due to the
571 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), 572 // DOM legacy of Windows key events: a keystroke event (is_char_ == false),
572 // or a character event (is_char_ == true). 573 // or a character event (is_char_ == true).
573 // 574 //
574 // For a keystroke event, 575 // For a keystroke event,
575 // -- is_char_ is false. 576 // -- is_char_ is false.
576 // -- type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED, 577 // -- Event::type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED,
577 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE. 578 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE.
578 // -- character_ functions as a bypass or cache for GetCharacter(). 579 // -- code_ and Event::flags() represent the physical key event.
580 // - code_ is a platform-independent representation of the physical key,
581 // based on DOM KeyboardEvent |code| values. It does not vary depending
582 // on key layout.
583 // - Event::flags() provides the active modifiers for the physical key
584 // press. Its value reflects the state after the event; that is, for
585 // a modifier key, a press includes the corresponding flag and a release
586 // does not.
587 // -- key_ and character_ provide the meaning of the key event. Together they
Wez 2014/12/12 20:04:18 nit: suggest "in the context of the active layout
kpschoedel 2014/12/12 21:20:39 Done.
588 // correspond to DOM KeyboardEvent |key| values.
589 // - key_ is an enumeration of non-Unicode meanings, plus sentinels
590 // (specifically DomKey::CHARACTER for Unicode meanings).
591 // - character_ is the code point for Unicode meanings.
579 // -- key_code_ is a VKEY_ value associated with the key. For printable 592 // -- key_code_ is a VKEY_ value associated with the key. For printable
Wez 2014/12/12 20:04:18 nit: Worth mentioning that this supports the legac
580 // characters, this may or may not be a mapped value, imitating MS Windows: 593 // characters, this may or may not be a mapped value, imitating MS Windows:
581 // if the mapped key generates a character that has an associated VKEY_ 594 // if the mapped key generates a character that has an associated VKEY_
582 // code, then key_code_ is that code; if not, then key_code_ is the unmapped 595 // code, then key_code_ is that code; if not, then key_code_ is the unmapped
583 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use 596 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use
584 // VKEY_Q for the key beside Tab, while French uses VKEY_A. 597 // VKEY_Q for the key beside Tab, while French uses VKEY_A.
585 // -- code_ is in one-to-one correspondence with a physical keyboard
586 // location, and does not vary depending on key layout.
587 // 598 //
588 // For a character event, 599 // For a character event,
589 // -- is_char_ is true. 600 // -- is_char_ is true.
590 // -- type() is ET_KEY_PRESSED. 601 // -- type() is ET_KEY_PRESSED.
591 // -- character_ is a UTF-16 character value. 602 // -- code_ is DomCode::NONE.
603 // -- key_ is DomKey::CHARACTER and character_ is a UTF-16 code point.
Wez 2014/12/12 20:04:18 Setting |key_| for character events feels wrong, e
kpschoedel 2014/12/12 21:20:39 The reason for doing so here is that some event-co
592 // -- key_code_ is conflated with character_ by some code, because both 604 // -- key_code_ is conflated with character_ by some code, because both
593 // arrive in the wParam field of a Windows event. 605 // arrive in the wParam field of a Windows event.
594 // -- code_ is DomCode::NONE.
595 // 606 //
596 class EVENTS_EXPORT KeyEvent : public Event { 607 class EVENTS_EXPORT KeyEvent : public Event {
597 public: 608 public:
598 // Create a KeyEvent from a NativeEvent. For Windows this native event can 609 // Create a KeyEvent from a NativeEvent. For Windows this native event can
599 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message 610 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message
600 // (WM_CHAR). Other systems have only keystroke events. 611 // (WM_CHAR). Other systems have only keystroke events.
601 explicit KeyEvent(const base::NativeEvent& native_event); 612 explicit KeyEvent(const base::NativeEvent& native_event);
602 613
603 // Create a keystroke event. 614 // Create a keystroke event.
604 KeyEvent(EventType type, KeyboardCode key_code, int flags); 615 KeyEvent(EventType type, KeyboardCode key_code, int flags);
605 616
617 // Create a fully defined keystroke event.
618 KeyEvent(EventType type,
619 KeyboardCode key_code,
620 DomCode code,
621 int flags,
622 DomKey key,
623 base::char16 character);
624
606 // Create a character event. 625 // Create a character event.
607 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); 626 KeyEvent(base::char16 character, KeyboardCode key_code, int flags);
608 627
609 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') 628 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA')
610 // See also: ui/events/keycodes/dom3/dom_values.txt 629 // See also: ui/events/keycodes/dom3/dom_values.txt
611 KeyEvent(EventType type, 630 KeyEvent(EventType type,
612 KeyboardCode key_code, 631 KeyboardCode key_code,
613 DomCode code, 632 DomCode code,
614 int flags); 633 int flags);
615 634
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 uint16 GetConflatedWindowsKeyCode() const; 698 uint16 GetConflatedWindowsKeyCode() const;
680 699
681 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. 700 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win.
682 // TODO(msw): Additional work may be needed for analogues on other platforms. 701 // TODO(msw): Additional work may be needed for analogues on other platforms.
683 bool IsUnicodeKeyCode() const; 702 bool IsUnicodeKeyCode() const;
684 703
685 // Returns the DOM .code (physical key identifier) for a keystroke event. 704 // Returns the DOM .code (physical key identifier) for a keystroke event.
686 DomCode code() const { return code_; }; 705 DomCode code() const { return code_; };
687 std::string GetCodeString() const; 706 std::string GetCodeString() const;
688 707
708 // Returns the DOM .key (layout meaning) for a keystroke event.
709 DomKey GetDomKey() const;
710
689 // Normalizes flags_ so that it describes the state after the event. 711 // Normalizes flags_ so that it describes the state after the event.
690 // (Native X11 event flags describe the state before the event.) 712 // (Native X11 event flags describe the state before the event.)
691 void NormalizeFlags(); 713 void NormalizeFlags();
692 714
693 // Returns true if the key event has already been processed by an input method 715 // Returns true if the key event has already been processed by an input method
694 // and there is no need to pass the key event to the input method again. 716 // and there is no need to pass the key event to the input method again.
695 bool IsTranslated() const; 717 bool IsTranslated() const;
696 // Marks this key event as translated or not translated. 718 // Marks this key event as translated or not translated.
697 void SetTranslated(bool translated); 719 void SetTranslated(bool translated);
698 720
699 protected: 721 protected:
700 friend class KeyEventTestApi; 722 friend class KeyEventTestApi;
701 723
702 // This allows a subclass TranslatedKeyEvent to be a non character event. 724 // This allows a subclass TranslatedKeyEvent to be a non character event.
703 void set_is_char(bool is_char) { is_char_ = is_char; } 725 void set_is_char(bool is_char) { is_char_ = is_char; }
704 726
705 private: 727 private:
706 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). 728 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.).
707 bool IsRightSideKey() const; 729 bool IsRightSideKey() const;
708 730
731 // Determine key_ and character_ on a keystroke event from code_ and flags().
732 void ApplyLayout() const;
733
709 KeyboardCode key_code_; 734 KeyboardCode key_code_;
710 735
711 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). 736 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE).
712 // http://www.w3.org/TR/DOM-Level-3-Events-code/ 737 // http://www.w3.org/TR/DOM-Level-3-Events-code/
713 // 738 //
714 // This value represents the physical position in the keyboard and can be 739 // This value represents the physical position in the keyboard and can be
715 // converted from / to keyboard scan code like XKB. 740 // converted from / to keyboard scan code like XKB.
716 DomCode code_; 741 DomCode code_;
717 742
718 // True if this is a character event, false if this is a keystroke event. 743 // True if this is a character event, false if this is a keystroke event.
719 bool is_char_; 744 bool is_char_;
720 745
721 // The platform related keycode value. For XKB, it's keysym value. 746 // The platform related keycode value. For XKB, it's keysym value.
722 // For now, this is used for CharacterComposer in ChromeOS. 747 // For now, this is used for CharacterComposer in ChromeOS.
723 uint32 platform_keycode_; 748 uint32 platform_keycode_;
724 749
750 // TODO(kpschoedel): refactor so that key_ and character_ are not mutable.
751 // This requires defining the KeyEvent completely at construction rather
752 // than lazily under GetCharacter(), which likely also means removing
753 // the two 'incomplete' constructors.
754 //
755 // DOM KeyboardEvent |key|
756 // http://www.w3.org/TR/DOM-Level-3-Events-key/
757 //
758 // This value, together with character_, represents the meaning of a key.
759 // The value is DomKey::CHARACTER when the interpretation is a character.
760 // This, along with character_, is not necessarily initialized when the
761 // event is constructed; it may be set only if and when GetCharacter()
762 // or GetDomKey() is called.
763 mutable DomKey key_;
764
725 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') 765 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â')
726 // http://www.w3.org/TR/uievents/#keyboard-key-codes. 766 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
727 // 767 //
728 // This value represents the text that the key event will insert to input 768 // This value represents the text that the key event will insert to input
729 // field. For key with modifier key, it may have specifial text. 769 // field. For key with modifier key, it may have specifial text.
730 // e.g. CTRL+A has '\x01'. 770 // e.g. CTRL+A has '\x01'.
731 mutable base::char16 character_; 771 mutable base::char16 character_;
732 772
733 // Parts of our event handling require raw native events (see both the 773 // Parts of our event handling require raw native events (see both the
734 // windows and linux implementations of web_input_event in content/). Because 774 // windows and linux implementations of web_input_event in content/). Because
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 850
811 const GestureEventDetails& details() const { return details_; } 851 const GestureEventDetails& details() const { return details_; }
812 852
813 private: 853 private:
814 GestureEventDetails details_; 854 GestureEventDetails details_;
815 }; 855 };
816 856
817 } // namespace ui 857 } // namespace ui
818 858
819 #endif // UI_EVENTS_EVENT_H_ 859 #endif // UI_EVENTS_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698