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

Side by Side Diff: ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine_unittest.cc

Issue 1284433002: Revise ui::DomKey to unify character and non-character codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsDead Created 5 years, 3 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/ozone/layout/xkb/xkb_keyboard_layout_engine.cc ('k') | ui/keyboard/keyboard_util.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/events/event_constants.h" 6 #include "ui/events/event_constants.h"
7 #include "ui/events/keycodes/dom/dom_code.h" 7 #include "ui/events/keycodes/dom/dom_code.h"
8 #include "ui/events/keycodes/dom/dom_key.h" 8 #include "ui/events/keycodes/dom/dom_key.h"
9 #include "ui/events/keycodes/keyboard_code_conversion.h" 9 #include "ui/events/keycodes/keyboard_code_conversion.h"
10 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" 10 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 xkb_keysym_t CharacterToKeySym(base::char16 c) const { 79 xkb_keysym_t CharacterToKeySym(base::char16 c) const {
80 return 0x01000000u + c; 80 return 0x01000000u + c;
81 } 81 }
82 82
83 KeyboardCode GetKeyboardCode(DomCode dom_code, 83 KeyboardCode GetKeyboardCode(DomCode dom_code,
84 int flags, 84 int flags,
85 base::char16 character) const { 85 base::char16 character) const {
86 KeyboardCode key_code = DifficultKeyboardCode( 86 KeyboardCode key_code = DifficultKeyboardCode(
87 dom_code, flags, key_code_converter_.DomCodeToXkbKeyCode(dom_code), 87 dom_code, flags, key_code_converter_.DomCodeToXkbKeyCode(dom_code),
88 flags, CharacterToKeySym(character), DomKey::CHARACTER, character); 88 flags, CharacterToKeySym(character), character);
89 if (key_code == VKEY_UNKNOWN) { 89 if (key_code == VKEY_UNKNOWN) {
90 DomKey dummy_dom_key; 90 DomKey dummy_dom_key;
91 base::char16 dummy_character;
92 // If this fails, key_code remains VKEY_UNKNOWN. 91 // If this fails, key_code remains VKEY_UNKNOWN.
93 ignore_result(DomCodeToUsLayoutMeaning(dom_code, EF_NONE, &dummy_dom_key, 92 ignore_result(DomCodeToUsLayoutDomKey(dom_code, EF_NONE, &dummy_dom_key,
94 &dummy_character, &key_code)); 93 &key_code));
95 } 94 }
96 return key_code; 95 return key_code;
97 } 96 }
98 97
99 // XkbKeyboardLayoutEngine overrides: 98 // XkbKeyboardLayoutEngine overrides:
100 bool XkbLookup(xkb_keycode_t xkb_keycode, 99 bool XkbLookup(xkb_keycode_t xkb_keycode,
101 xkb_mod_mask_t xkb_flags, 100 xkb_mod_mask_t xkb_flags,
102 xkb_keysym_t* xkb_keysym, 101 xkb_keysym_t* xkb_keysym,
103 base::char16* character) const override { 102 uint32_t* character) const override {
104 switch (entry_type_) { 103 switch (entry_type_) {
105 case EntryType::NONE: 104 case EntryType::NONE:
106 break; 105 break;
107 case EntryType::PRINTABLE: 106 case EntryType::PRINTABLE:
108 if (!printable_entry_ || 107 if (!printable_entry_ ||
109 (xkb_keycode != 108 (xkb_keycode !=
110 static_cast<xkb_keycode_t>(printable_entry_->dom_code))) { 109 static_cast<xkb_keycode_t>(printable_entry_->dom_code))) {
111 return false; 110 return false;
112 } 111 }
113 if (xkb_flags & EF_ALTGR_DOWN) 112 if (xkb_flags & EF_ALTGR_DOWN)
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 {{DomCode::NUMPAD1, XKB_KEY_KP_1}, VKEY_1}, 809 {{DomCode::NUMPAD1, XKB_KEY_KP_1}, VKEY_1},
811 {{DomCode::CAPS_LOCK, XKB_KEY_Caps_Lock}, VKEY_CAPITAL}, 810 {{DomCode::CAPS_LOCK, XKB_KEY_Caps_Lock}, VKEY_CAPITAL},
812 {{DomCode::ENTER, XKB_KEY_Return}, VKEY_RETURN}, 811 {{DomCode::ENTER, XKB_KEY_Return}, VKEY_RETURN},
813 {{DomCode::NUMPAD_ENTER, XKB_KEY_KP_Enter}, VKEY_RETURN}, 812 {{DomCode::NUMPAD_ENTER, XKB_KEY_KP_Enter}, VKEY_RETURN},
814 {{DomCode::SLEEP, XKB_KEY_XF86Sleep}, VKEY_SLEEP}, 813 {{DomCode::SLEEP, XKB_KEY_XF86Sleep}, VKEY_SLEEP},
815 }; 814 };
816 for (const auto& e : kVkeyTestCase) { 815 for (const auto& e : kVkeyTestCase) {
817 SCOPED_TRACE(static_cast<int>(e.test.dom_code)); 816 SCOPED_TRACE(static_cast<int>(e.test.dom_code));
818 layout_engine_->SetEntry(&e.test); 817 layout_engine_->SetEntry(&e.test);
819 DomKey dom_key = DomKey::NONE; 818 DomKey dom_key = DomKey::NONE;
820 base::char16 character = 0;
821 KeyboardCode key_code = VKEY_UNKNOWN; 819 KeyboardCode key_code = VKEY_UNKNOWN;
822 uint32_t keysym; 820 uint32_t keysym;
823 EXPECT_TRUE(layout_engine_->Lookup(e.test.dom_code, EF_NONE, &dom_key, 821 EXPECT_TRUE(layout_engine_->Lookup(e.test.dom_code, EF_NONE, &dom_key,
824 &character, &key_code, &keysym)); 822 &key_code, &keysym));
825 EXPECT_EQ(e.test.keysym, keysym); 823 EXPECT_EQ(e.test.keysym, keysym);
826 EXPECT_EQ(e.key_code, key_code); 824 EXPECT_EQ(e.key_code, key_code);
827 } 825 }
828 } 826 }
829 827
830 828
831 TEST_F(XkbLayoutEngineVkTest, XkbRuleNamesForLayoutName) { 829 TEST_F(XkbLayoutEngineVkTest, XkbRuleNamesForLayoutName) {
832 static const VkTestXkbKeyboardLayoutEngine::RuleNames kVkeyTestCase[] = { 830 static const VkTestXkbKeyboardLayoutEngine::RuleNames kVkeyTestCase[] = {
833 /* 0 */ {"us", "us", ""}, 831 /* 0 */ {"us", "us", ""},
834 /* 1 */ {"jp", "jp", ""}, 832 /* 1 */ {"jp", "jp", ""},
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 std::string layout_id; 887 std::string layout_id;
890 std::string layout_variant; 888 std::string layout_variant;
891 XkbKeyboardLayoutEngine::ParseLayoutName(e->layout_name, &layout_id, 889 XkbKeyboardLayoutEngine::ParseLayoutName(e->layout_name, &layout_id,
892 &layout_variant); 890 &layout_variant);
893 EXPECT_EQ(layout_id, e->layout); 891 EXPECT_EQ(layout_id, e->layout);
894 EXPECT_EQ(layout_variant, e->variant); 892 EXPECT_EQ(layout_variant, e->variant);
895 } 893 }
896 } 894 }
897 895
898 } // namespace ui 896 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc ('k') | ui/keyboard/keyboard_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698