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

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

Issue 796003005: Located vs non-located ui::KeyboardCode functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 break; 882 break;
883 case ET_KEY_RELEASED: 883 case ET_KEY_RELEASED:
884 case ET_TRANSLATED_KEY_RELEASE: 884 case ET_TRANSLATED_KEY_RELEASE:
885 SetType(translated ? ET_TRANSLATED_KEY_RELEASE : ET_KEY_RELEASED); 885 SetType(translated ? ET_TRANSLATED_KEY_RELEASE : ET_KEY_RELEASED);
886 break; 886 break;
887 default: 887 default:
888 NOTREACHED(); 888 NOTREACHED();
889 } 889 }
890 } 890 }
891 891
892 bool KeyEvent::IsRightSideKey() const {
893 switch (key_code_) {
894 case VKEY_CONTROL:
895 case VKEY_SHIFT:
896 case VKEY_MENU:
897 case VKEY_LWIN:
898 #if defined(USE_X11)
899 // Under X11, setting code_ requires platform-dependent information, and
900 // currently assumes that X keycodes are based on Linux evdev keycodes.
901 // In certain test environments this is not the case, and code_ is not
902 // set accurately, so we need a different mechanism. Fortunately X11 key
903 // mapping preserves the left-right distinction, so testing keysyms works
904 // if the value is available (as it is for all X11 native-based events).
kpschoedel 2015/01/09 20:25:40 The comment here no longer applies, since the old
905 if (platform_keycode_) {
906 return (platform_keycode_ == XK_Shift_R) ||
907 (platform_keycode_ == XK_Control_R) ||
908 (platform_keycode_ == XK_Alt_R) ||
909 (platform_keycode_ == XK_Meta_R) ||
910 (platform_keycode_ == XK_Super_R) ||
911 (platform_keycode_ == XK_Hyper_R);
912 }
913 // Fall through to the generic code if we have no platform_keycode_.
914 // Under X11, this must be a synthetic event, so we can require that
915 // code_ be set correctly.
916 #endif
917 return (code_ == DomCode::SHIFT_RIGHT) ||
918 (code_ == DomCode::CONTROL_RIGHT) ||
919 (code_ == DomCode::ALT_RIGHT) ||
920 (code_ == DomCode::OS_RIGHT);
921 default:
922 return false;
923 }
924 }
925
926 KeyboardCode KeyEvent::GetLocatedWindowsKeyboardCode() const { 892 KeyboardCode KeyEvent::GetLocatedWindowsKeyboardCode() const {
Wez 2015/01/10 02:06:28 AFAICT, this only seems to be used when converting
kpschoedel 2015/01/12 16:34:06 There's another call inside mojo.
Wez 2015/01/13 03:08:36 Ah, I wonder if they opted to use located values t
927 switch (key_code_) { 893 return NonLocatedToLocatedKeyboardCode(key_code_, code_);
928 case VKEY_SHIFT:
929 return IsRightSideKey() ? VKEY_RSHIFT : VKEY_LSHIFT;
930 case VKEY_CONTROL:
931 return IsRightSideKey() ? VKEY_RCONTROL : VKEY_LCONTROL;
932 case VKEY_MENU:
933 return IsRightSideKey() ? VKEY_RMENU : VKEY_LMENU;
934 case VKEY_LWIN:
935 return IsRightSideKey() ? VKEY_RWIN : VKEY_LWIN;
936 // TODO(kpschoedel): EF_NUMPAD_KEY is present only on X11. Currently this
937 // function is only called on X11. Likely the tests here will be replaced
938 // with a DOM-based code enumeration test in the course of Ozone
939 // platform-indpendent key event work.
940 case VKEY_0:
941 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD0 : VKEY_0;
942 case VKEY_1:
943 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD1 : VKEY_1;
944 case VKEY_2:
945 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD2 : VKEY_2;
946 case VKEY_3:
947 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD3 : VKEY_3;
948 case VKEY_4:
949 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD4 : VKEY_4;
950 case VKEY_5:
951 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD5 : VKEY_5;
952 case VKEY_6:
953 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD6 : VKEY_6;
954 case VKEY_7:
955 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD7 : VKEY_7;
956 case VKEY_8:
957 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD8 : VKEY_8;
958 case VKEY_9:
959 return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD9 : VKEY_9;
960 default:
961 return key_code_;
962 }
963 } 894 }
964 895
965 uint16 KeyEvent::GetConflatedWindowsKeyCode() const { 896 uint16 KeyEvent::GetConflatedWindowsKeyCode() const {
966 if (is_char_) 897 if (is_char_)
967 return character_; 898 return character_;
968 return key_code_; 899 return key_code_;
969 } 900 }
970 901
971 std::string KeyEvent::GetCodeString() const { 902 std::string KeyEvent::GetCodeString() const {
972 return KeycodeConverter::DomCodeToCodeString(code_); 903 return KeycodeConverter::DomCodeToCodeString(code_);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 gfx::PointF(x, y), 964 gfx::PointF(x, y),
1034 time_stamp, 965 time_stamp,
1035 flags | EF_FROM_TOUCH), 966 flags | EF_FROM_TOUCH),
1036 details_(details) { 967 details_(details) {
1037 } 968 }
1038 969
1039 GestureEvent::~GestureEvent() { 970 GestureEvent::~GestureEvent() {
1040 } 971 }
1041 972
1042 } // namespace ui 973 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698