| 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 #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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 if (is_char_) | 673 if (is_char_) |
| 674 character_ = native_event.wParam; | 674 character_ = native_event.wParam; |
| 675 #endif | 675 #endif |
| 676 } | 676 } |
| 677 | 677 |
| 678 KeyEvent::KeyEvent(EventType type, | 678 KeyEvent::KeyEvent(EventType type, |
| 679 KeyboardCode key_code, | 679 KeyboardCode key_code, |
| 680 int flags) | 680 int flags) |
| 681 : Event(type, EventTimeForNow(), flags), | 681 : Event(type, EventTimeForNow(), flags), |
| 682 key_code_(key_code), | 682 key_code_(key_code), |
| 683 code_(DomCode::NONE), | 683 code_(KeyboardCodeToDomCode(key_code)), |
| 684 is_char_(false), | 684 is_char_(false), |
| 685 platform_keycode_(0), | 685 platform_keycode_(0), |
| 686 key_(DomKey::NONE), | 686 key_(DomKey::NONE), |
| 687 character_() { | 687 character_() { |
| 688 } | 688 } |
| 689 | 689 |
| 690 KeyEvent::KeyEvent(EventType type, | 690 KeyEvent::KeyEvent(EventType type, |
| 691 KeyboardCode key_code, | 691 KeyboardCode key_code, |
| 692 DomCode code, | 692 DomCode code, |
| 693 int flags) | 693 int flags) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 | 762 |
| 763 void KeyEvent::ApplyLayout() const { | 763 void KeyEvent::ApplyLayout() const { |
| 764 // If the client has set the character (e.g. faked key events from virtual | 764 // If the client has set the character (e.g. faked key events from virtual |
| 765 // keyboard), it's client's responsibility to set the dom key correctly. | 765 // keyboard), it's client's responsibility to set the dom key correctly. |
| 766 // Otherwise, set the dom key as unidentified. | 766 // Otherwise, set the dom key as unidentified. |
| 767 // Please refer to crbug.com/443889. | 767 // Please refer to crbug.com/443889. |
| 768 if (character_ != 0) { | 768 if (character_ != 0) { |
| 769 key_ = DomKey::UNIDENTIFIED; | 769 key_ = DomKey::UNIDENTIFIED; |
| 770 return; | 770 return; |
| 771 } | 771 } |
| 772 KeyboardCode dummy_key_code; |
| 772 #if defined(OS_WIN) | 773 #if defined(OS_WIN) |
| 773 // Native Windows character events always have is_char_ == true, | 774 // Native Windows character events always have is_char_ == true, |
| 774 // so this is a synthetic or native keystroke event. | 775 // so this is a synthetic or native keystroke event. |
| 775 // Therefore, perform only the fallback action. | 776 // Therefore, perform only the fallback action. |
| 776 GetMeaningFromKeyCode(key_code_, flags(), &key_, &character_); | 777 DomCodeToMeaning(code_, flags(), &key_, &character_, &dummy_key_code); |
| 777 #elif defined(USE_X11) | 778 #elif defined(USE_X11) |
| 778 // When a control key is held, prefer ASCII characters to non ASCII | 779 // When a control key is held, prefer ASCII characters to non ASCII |
| 779 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode | 780 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode |
| 780 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. | 781 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. |
| 781 // GetCharacterFromXEvent returns 'à' in that case. | 782 // GetCharacterFromXEvent returns 'à' in that case. |
| 782 character_ = (IsControlDown() || !native_event()) ? | 783 if (IsControlDown() || !native_event()) |
| 783 GetCharacterFromKeyCode(key_code_, flags()) : | 784 DomCodeToMeaning(code_, flags(), &key_, &character_, &dummy_key_code); |
| 784 GetCharacterFromXEvent(native_event()); | 785 else |
| 785 // TODO(kpschoedel): set key_ field for X11. | 786 GetMeaningFromXEvent(native_event(), &key_, &character_); |
| 786 #elif defined(USE_OZONE) | 787 #elif defined(USE_OZONE) |
| 787 KeyboardCode key_code; | |
| 788 if (!KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup( | 788 if (!KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup( |
| 789 code_, flags(), &key_, &character_, &key_code, &platform_keycode_)) { | 789 code_, flags(), &key_, &character_, &dummy_key_code, &platform_keycode_)) |
| 790 GetMeaningFromKeyCode(key_code_, flags(), &key_, &character_); | 790 DomCodeToMeaning(code_, flags(), &key_, &character_, &dummy_key_code); |
| 791 } | |
| 792 #else | 791 #else |
| 793 if (native_event()) { | 792 if (native_event()) { |
| 794 DCHECK(EventTypeFromNative(native_event()) == ET_KEY_PRESSED || | 793 DCHECK(EventTypeFromNative(native_event()) == ET_KEY_PRESSED || |
| 795 EventTypeFromNative(native_event()) == ET_KEY_RELEASED); | 794 EventTypeFromNative(native_event()) == ET_KEY_RELEASED); |
| 796 } | 795 } |
| 797 // TODO(kpschoedel): revise to use DOM code_ instead of Windows key_code_ | 796 DomCodeToMeaning(code_, flags(), &key_, &character_, &dummy_key_code); |
| 798 GetMeaningFromKeyCode(key_code_, flags(), &key_, &character_); | |
| 799 #endif | 797 #endif |
| 800 } | 798 } |
| 801 | 799 |
| 802 DomKey KeyEvent::GetDomKey() const { | 800 DomKey KeyEvent::GetDomKey() const { |
| 803 // Determination of character_ and key_ may be done lazily. | 801 // Determination of character_ and key_ may be done lazily. |
| 804 if (key_ == DomKey::NONE) | 802 if (key_ == DomKey::NONE) |
| 805 ApplyLayout(); | 803 ApplyLayout(); |
| 806 return key_; | 804 return key_; |
| 807 } | 805 } |
| 808 | 806 |
| 809 base::char16 KeyEvent::GetCharacter() const { | 807 base::char16 KeyEvent::GetCharacter() const { |
| 810 // Determination of character_ and key_ may be done lazily. | 808 // Determination of character_ and key_ may be done lazily. |
| 811 if (key_ == DomKey::NONE) | 809 if (key_ == DomKey::NONE) |
| 812 ApplyLayout(); | 810 ApplyLayout(); |
| 813 return character_; | 811 return character_; |
| 814 } | 812 } |
| 815 | 813 |
| 816 base::char16 KeyEvent::GetText() const { | 814 base::char16 KeyEvent::GetText() const { |
| 817 if ((flags() & EF_CONTROL_DOWN) != 0) { | 815 if ((flags() & EF_CONTROL_DOWN) != 0) { |
| 818 // TODO(kpschoedel): revise to use DOM code_ instead of Windows key_code_ | 816 base::char16 character; |
| 819 return GetControlCharacterForKeycode(key_code_, | 817 ui::DomKey key; |
| 820 (flags() & EF_SHIFT_DOWN) != 0); | 818 ui::KeyboardCode dummy_key_code; |
| 819 if (DomCodeToControlCharacter( |
| 820 code_, flags(), &key, &character, &dummy_key_code)) |
| 821 return character; |
| 821 } | 822 } |
| 822 return GetUnmodifiedText(); | 823 return GetUnmodifiedText(); |
| 823 } | 824 } |
| 824 | 825 |
| 825 base::char16 KeyEvent::GetUnmodifiedText() const { | 826 base::char16 KeyEvent::GetUnmodifiedText() const { |
| 826 if (!is_char_ && (key_code_ == VKEY_RETURN)) | 827 if (!is_char_ && (key_code_ == VKEY_RETURN)) |
| 827 return '\r'; | 828 return '\r'; |
| 828 return GetCharacter(); | 829 return GetCharacter(); |
| 829 } | 830 } |
| 830 | 831 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 gfx::PointF(x, y), | 977 gfx::PointF(x, y), |
| 977 time_stamp, | 978 time_stamp, |
| 978 flags | EF_FROM_TOUCH), | 979 flags | EF_FROM_TOUCH), |
| 979 details_(details) { | 980 details_(details) { |
| 980 } | 981 } |
| 981 | 982 |
| 982 GestureEvent::~GestureEvent() { | 983 GestureEvent::~GestureEvent() { |
| 983 } | 984 } |
| 984 | 985 |
| 985 } // namespace ui | 986 } // namespace ui |
| OLD | NEW |