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

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

Issue 841263005: Use DOM- rather than Windows-based key code for non-layout cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments (sadrul) Created 5 years, 8 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
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 #include "ui/events/event.h" 5 #include "ui/events/event.h"
6 6
7 #if defined(USE_X11) 7 #if defined(USE_X11)
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/keysym.h> 9 #include <X11/keysym.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (is_char_) 690 if (is_char_)
691 character_ = native_event.wParam; 691 character_ = native_event.wParam;
692 #endif 692 #endif
693 } 693 }
694 694
695 KeyEvent::KeyEvent(EventType type, 695 KeyEvent::KeyEvent(EventType type,
696 KeyboardCode key_code, 696 KeyboardCode key_code,
697 int flags) 697 int flags)
698 : Event(type, EventTimeForNow(), flags), 698 : Event(type, EventTimeForNow(), flags),
699 key_code_(key_code), 699 key_code_(key_code),
700 code_(DomCode::NONE), 700 code_(UsLayoutKeyboardCodeToDomCode(key_code)),
701 is_char_(false), 701 is_char_(false),
702 platform_keycode_(0), 702 platform_keycode_(0),
703 key_(DomKey::NONE), 703 key_(DomKey::NONE),
704 character_() { 704 character_() {
705 } 705 }
706 706
707 KeyEvent::KeyEvent(EventType type, 707 KeyEvent::KeyEvent(EventType type,
708 KeyboardCode key_code, 708 KeyboardCode key_code,
709 DomCode code, 709 DomCode code,
710 int flags) 710 int flags)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 779
780 void KeyEvent::ApplyLayout() const { 780 void KeyEvent::ApplyLayout() const {
781 // If the client has set the character (e.g. faked key events from virtual 781 // If the client has set the character (e.g. faked key events from virtual
782 // keyboard), it's client's responsibility to set the dom key correctly. 782 // keyboard), it's client's responsibility to set the dom key correctly.
783 // Otherwise, set the dom key as unidentified. 783 // Otherwise, set the dom key as unidentified.
784 // Please refer to crbug.com/443889. 784 // Please refer to crbug.com/443889.
785 if (character_ != 0) { 785 if (character_ != 0) {
786 key_ = DomKey::UNIDENTIFIED; 786 key_ = DomKey::UNIDENTIFIED;
787 return; 787 return;
788 } 788 }
789 ui::DomCode code = code_;
790 if (code == DomCode::NONE) {
791 // Catch old code that tries to do layout without a physical key, and try
792 // to recover using the KeyboardCode. Once key events are fully defined
793 // on construction (see TODO in event.h) this will go away.
794 LOG(WARNING) << "DomCode::NONE keycode=" << key_code_;
795 code = UsLayoutKeyboardCodeToDomCode(key_code_);
796 if (code == DomCode::NONE) {
797 key_ = DomKey::UNIDENTIFIED;
798 return;
799 }
800 }
801 KeyboardCode dummy_key_code;
789 #if defined(OS_WIN) 802 #if defined(OS_WIN)
790 // Native Windows character events always have is_char_ == true, 803 // Native Windows character events always have is_char_ == true,
791 // so this is a synthetic or native keystroke event. 804 // so this is a synthetic or native keystroke event.
792 // Therefore, perform only the fallback action. 805 // Therefore, perform only the fallback action.
793 GetMeaningFromKeyCode(key_code_, flags(), &key_, &character_);
794 #elif defined(USE_X11) 806 #elif defined(USE_X11)
795 // When a control key is held, prefer ASCII characters to non ASCII 807 // When a control key is held, prefer ASCII characters to non ASCII
796 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode 808 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode
797 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. 809 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11.
798 // GetCharacterFromXEvent returns 'à' in that case. 810 // GetCharacterFromXEvent returns 'à' in that case.
799 character_ = (IsControlDown() || !native_event()) ? 811 if (!IsControlDown() && native_event()) {
800 GetCharacterFromKeyCode(key_code_, flags()) : 812 character_ = GetCharacterFromXEvent(native_event());
801 GetCharacterFromXEvent(native_event()); 813 // TODO(kpschoedel): set key_ field for X11.
802 // TODO(kpschoedel): set key_ field for X11. 814 return;
815 }
803 #elif defined(USE_OZONE) 816 #elif defined(USE_OZONE)
804 KeyboardCode key_code; 817 if (KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup(
805 if (!KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup( 818 code, flags(), &key_, &character_, &dummy_key_code,
806 code_, flags(), &key_, &character_, &key_code, &platform_keycode_)) { 819 &platform_keycode_)) {
807 GetMeaningFromKeyCode(key_code_, flags(), &key_, &character_); 820 return;
808 } 821 }
809 #else 822 #else
810 if (native_event()) { 823 if (native_event()) {
811 DCHECK(EventTypeFromNative(native_event()) == ET_KEY_PRESSED || 824 DCHECK(EventTypeFromNative(native_event()) == ET_KEY_PRESSED ||
812 EventTypeFromNative(native_event()) == ET_KEY_RELEASED); 825 EventTypeFromNative(native_event()) == ET_KEY_RELEASED);
813 } 826 }
814 // TODO(kpschoedel): revise to use DOM code_ instead of Windows key_code_
815 GetMeaningFromKeyCode(key_code_, flags(), &key_, &character_);
816 #endif 827 #endif
828 if (!DomCodeToUsLayoutMeaning(code, flags(), &key_, &character_,
829 &dummy_key_code)) {
830 key_ = DomKey::UNIDENTIFIED;
831 }
817 } 832 }
818 833
819 DomKey KeyEvent::GetDomKey() const { 834 DomKey KeyEvent::GetDomKey() const {
820 // Determination of character_ and key_ may be done lazily. 835 // Determination of character_ and key_ may be done lazily.
821 if (key_ == DomKey::NONE) 836 if (key_ == DomKey::NONE)
822 ApplyLayout(); 837 ApplyLayout();
823 return key_; 838 return key_;
824 } 839 }
825 840
826 base::char16 KeyEvent::GetCharacter() const { 841 base::char16 KeyEvent::GetCharacter() const {
827 // Determination of character_ and key_ may be done lazily. 842 // Determination of character_ and key_ may be done lazily.
828 if (key_ == DomKey::NONE) 843 if (key_ == DomKey::NONE)
829 ApplyLayout(); 844 ApplyLayout();
830 return character_; 845 return character_;
831 } 846 }
832 847
833 base::char16 KeyEvent::GetText() const { 848 base::char16 KeyEvent::GetText() const {
834 if ((flags() & EF_CONTROL_DOWN) != 0) { 849 if ((flags() & EF_CONTROL_DOWN) != 0) {
835 // TODO(kpschoedel): revise to use DOM code_ instead of Windows key_code_ 850 base::char16 character;
836 return GetControlCharacterForKeycode(key_code_, 851 ui::DomKey key;
837 (flags() & EF_SHIFT_DOWN) != 0); 852 ui::KeyboardCode key_code;
853 if (DomCodeToControlCharacter(code_, flags(), &key, &character, &key_code))
854 return character;
838 } 855 }
839 return GetUnmodifiedText(); 856 return GetUnmodifiedText();
840 } 857 }
841 858
842 base::char16 KeyEvent::GetUnmodifiedText() const { 859 base::char16 KeyEvent::GetUnmodifiedText() const {
843 if (!is_char_ && (key_code_ == VKEY_RETURN)) 860 if (!is_char_ && (key_code_ == VKEY_RETURN))
844 return '\r'; 861 return '\r';
845 return GetCharacter(); 862 return GetCharacter();
846 } 863 }
847 864
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 gfx::PointF(x, y), 1009 gfx::PointF(x, y),
993 time_stamp, 1010 time_stamp,
994 flags | EF_FROM_TOUCH), 1011 flags | EF_FROM_TOUCH),
995 details_(details) { 1012 details_(details) {
996 } 1013 }
997 1014
998 GestureEvent::~GestureEvent() { 1015 GestureEvent::~GestureEvent() {
999 } 1016 }
1000 1017
1001 } // namespace ui 1018 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event.h ('k') | ui/events/event_unittest.cc » ('j') | ui/keyboard/keyboard_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698