| OLD | NEW |
| 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 "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" | 5 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
| 6 | 6 |
| 7 #include <xkbcommon/xkbcommon-names.h> | 7 #include <xkbcommon/xkbcommon-names.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 #if defined(OS_CHROMEOS) | 640 #if defined(OS_CHROMEOS) |
| 641 return true; | 641 return true; |
| 642 #else | 642 #else |
| 643 return false; | 643 return false; |
| 644 #endif | 644 #endif |
| 645 } | 645 } |
| 646 | 646 |
| 647 bool XkbKeyboardLayoutEngine::SetCurrentLayoutByName( | 647 bool XkbKeyboardLayoutEngine::SetCurrentLayoutByName( |
| 648 const std::string& layout_name) { | 648 const std::string& layout_name) { |
| 649 #if defined(OS_CHROMEOS) | 649 #if defined(OS_CHROMEOS) |
| 650 size_t dash_index = layout_name.find("-"); | 650 size_t dash_index = layout_name.find('-'); |
| 651 size_t parentheses_index = layout_name.find("("); | 651 size_t parentheses_index = layout_name.find('('); |
| 652 std::string layout_id = layout_name; | 652 std::string layout_id = layout_name; |
| 653 std::string layout_variant = ""; | 653 std::string layout_variant = ""; |
| 654 if (dash_index != std::string::npos) { | 654 if (parentheses_index != std::string::npos) { |
| 655 layout_id = layout_name.substr(0, parentheses_index); |
| 656 size_t close_index = layout_name.find(')', parentheses_index); |
| 657 if (close_index == std::string::npos) |
| 658 close_index = layout_name.size(); |
| 659 layout_variant = layout_name.substr(parentheses_index + 1, |
| 660 close_index - parentheses_index - 1); |
| 661 } else if (dash_index != std::string::npos) { |
| 655 layout_id = layout_name.substr(0, dash_index); | 662 layout_id = layout_name.substr(0, dash_index); |
| 656 layout_variant = layout_name.substr(dash_index + 1); | 663 layout_variant = layout_name.substr(dash_index + 1); |
| 657 } else if (parentheses_index != std::string::npos) { | |
| 658 layout_id = layout_name.substr(0, parentheses_index); | |
| 659 layout_variant = layout_name.substr(parentheses_index + 1, | |
| 660 layout_name.size() - 1); | |
| 661 } | 664 } |
| 662 struct xkb_rule_names names = { | 665 struct xkb_rule_names names = { |
| 663 .rules = NULL, | 666 .rules = NULL, |
| 664 .model = "pc101", | 667 .model = "pc101", |
| 665 .layout = layout_id.c_str(), | 668 .layout = layout_id.c_str(), |
| 666 .variant = layout_variant.c_str(), | 669 .variant = layout_variant.c_str(), |
| 667 .options = "" | 670 .options = "" |
| 668 }; | 671 }; |
| 669 xkb_keymap* keymap = xkb_keymap_new_from_names(xkb_context_.get(), | 672 xkb_keymap* keymap = xkb_keymap_new_from_names(xkb_context_.get(), |
| 670 &names, | 673 &names, |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 if (flags == base_flags) | 867 if (flags == base_flags) |
| 865 return base_character; | 868 return base_character; |
| 866 xkb_keysym_t keysym; | 869 xkb_keysym_t keysym; |
| 867 base::char16 character = 0; | 870 base::char16 character = 0; |
| 868 if (!XkbLookup(xkb_keycode, flags, &keysym, &character)) | 871 if (!XkbLookup(xkb_keycode, flags, &keysym, &character)) |
| 869 character = kNone; | 872 character = kNone; |
| 870 return character; | 873 return character; |
| 871 } | 874 } |
| 872 | 875 |
| 873 } // namespace ui | 876 } // namespace ui |
| OLD | NEW |