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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 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 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 <stddef.h> 7 #include <stddef.h>
8 #include <xkbcommon/xkbcommon-names.h> 8 #include <xkbcommon/xkbcommon-names.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 13 matching lines...) Expand all
24 #include "ui/events/keycodes/dom/dom_key.h" 24 #include "ui/events/keycodes/dom/dom_key.h"
25 #include "ui/events/keycodes/dom/keycode_converter.h" 25 #include "ui/events/keycodes/dom/keycode_converter.h"
26 #include "ui/events/keycodes/keyboard_code_conversion.h" 26 #include "ui/events/keycodes/keyboard_code_conversion.h"
27 #include "ui/events/keycodes/keyboard_code_conversion_xkb.h" 27 #include "ui/events/keycodes/keyboard_code_conversion_xkb.h"
28 28
29 namespace ui { 29 namespace ui {
30 30
31 namespace { 31 namespace {
32 32
33 typedef base::Callback<void(const std::string&, 33 typedef base::Callback<void(const std::string&,
34 scoped_ptr<char, base::FreeDeleter>)> 34 std::unique_ptr<char, base::FreeDeleter>)>
35 LoadKeymapCallback; 35 LoadKeymapCallback;
36 36
37 KeyboardCode AlphanumericKeyboardCode(xkb_keysym_t xkb_keysym, 37 KeyboardCode AlphanumericKeyboardCode(xkb_keysym_t xkb_keysym,
38 base::char16 character) { 38 base::char16 character) {
39 // Plain ASCII letters and digits map directly to VKEY values. 39 // Plain ASCII letters and digits map directly to VKEY values.
40 if ((character >= '0') && (character <= '9')) { 40 if ((character >= '0') && (character <= '9')) {
41 int zero = ((xkb_keysym >= XKB_KEY_KP_0) && (xkb_keysym <= XKB_KEY_KP_9)) 41 int zero = ((xkb_keysym >= XKB_KEY_KP_0) && (xkb_keysym <= XKB_KEY_KP_9))
42 ? VKEY_NUMPAD0 42 ? VKEY_NUMPAD0
43 : VKEY_0; 43 : VKEY_0;
44 return static_cast<KeyboardCode>(zero + character - '0'); 44 return static_cast<KeyboardCode>(zero + character - '0');
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 const LoadKeymapCallback& reply_callback) { 614 const LoadKeymapCallback& reply_callback) {
615 std::string layout_id; 615 std::string layout_id;
616 std::string layout_variant; 616 std::string layout_variant;
617 XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id, 617 XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id,
618 &layout_variant); 618 &layout_variant);
619 xkb_rule_names names = {.rules = NULL, 619 xkb_rule_names names = {.rules = NULL,
620 .model = "pc101", 620 .model = "pc101",
621 .layout = layout_id.c_str(), 621 .layout = layout_id.c_str(),
622 .variant = layout_variant.c_str(), 622 .variant = layout_variant.c_str(),
623 .options = ""}; 623 .options = ""};
624 scoped_ptr<xkb_context, XkbContextDeleter> context; 624 std::unique_ptr<xkb_context, XkbContextDeleter> context;
625 context.reset(xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES)); 625 context.reset(xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES));
626 xkb_context_include_path_append(context.get(), "/usr/share/X11/xkb"); 626 xkb_context_include_path_append(context.get(), "/usr/share/X11/xkb");
627 scoped_ptr<xkb_keymap, XkbKeymapDeleter> keymap; 627 std::unique_ptr<xkb_keymap, XkbKeymapDeleter> keymap;
628 keymap.reset(xkb_keymap_new_from_names(context.get(), &names, 628 keymap.reset(xkb_keymap_new_from_names(context.get(), &names,
629 XKB_KEYMAP_COMPILE_NO_FLAGS)); 629 XKB_KEYMAP_COMPILE_NO_FLAGS));
630 if (keymap) { 630 if (keymap) {
631 scoped_ptr<char, base::FreeDeleter> keymap_str( 631 std::unique_ptr<char, base::FreeDeleter> keymap_str(
632 xkb_keymap_get_as_string(keymap.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); 632 xkb_keymap_get_as_string(keymap.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
633 reply_runner->PostTask(FROM_HERE, base::Bind(reply_callback, layout_name, 633 reply_runner->PostTask(FROM_HERE, base::Bind(reply_callback, layout_name,
634 base::Passed(&keymap_str))); 634 base::Passed(&keymap_str)));
635 } else { 635 } else {
636 LOG(FATAL) << "Keymap file failed to load: " << layout_name; 636 LOG(FATAL) << "Keymap file failed to load: " << layout_name;
637 } 637 }
638 } 638 }
639 #endif 639 #endif
640 640
641 bool IsControlCharacter(uint32_t character) { 641 bool IsControlCharacter(uint32_t character) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 XKB_KEYMAP_COMPILE_NO_FLAGS); 699 XKB_KEYMAP_COMPILE_NO_FLAGS);
700 if (!keymap) 700 if (!keymap)
701 return false; 701 return false;
702 SetKeymap(keymap); 702 SetKeymap(keymap);
703 return true; 703 return true;
704 #endif // defined(OS_CHROMEOS) 704 #endif // defined(OS_CHROMEOS)
705 } 705 }
706 706
707 void XkbKeyboardLayoutEngine::OnKeymapLoaded( 707 void XkbKeyboardLayoutEngine::OnKeymapLoaded(
708 const std::string& layout_name, 708 const std::string& layout_name,
709 scoped_ptr<char, base::FreeDeleter> keymap_str) { 709 std::unique_ptr<char, base::FreeDeleter> keymap_str) {
710 if (keymap_str) { 710 if (keymap_str) {
711 xkb_keymap* keymap = xkb_keymap_new_from_string( 711 xkb_keymap* keymap = xkb_keymap_new_from_string(
712 xkb_context_.get(), keymap_str.get(), XKB_KEYMAP_FORMAT_TEXT_V1, 712 xkb_context_.get(), keymap_str.get(), XKB_KEYMAP_FORMAT_TEXT_V1,
713 XKB_KEYMAP_COMPILE_NO_FLAGS); 713 XKB_KEYMAP_COMPILE_NO_FLAGS);
714 XkbKeymapEntry entry = {layout_name, keymap}; 714 XkbKeymapEntry entry = {layout_name, keymap};
715 xkb_keymaps_.push_back(entry); 715 xkb_keymaps_.push_back(entry);
716 if (layout_name == current_layout_name_) 716 if (layout_name == current_layout_name_)
717 SetKeymap(keymap); 717 SetKeymap(keymap);
718 } else { 718 } else {
719 LOG(FATAL) << "Keymap file failed to load: " << layout_name; 719 LOG(FATAL) << "Keymap file failed to load: " << layout_name;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 close_index = layout_name.size(); 970 close_index = layout_name.size();
971 *layout_variant = layout_name.substr(parentheses_index + 1, 971 *layout_variant = layout_name.substr(parentheses_index + 1,
972 close_index - parentheses_index - 1); 972 close_index - parentheses_index - 1);
973 } else if (dash_index != std::string::npos) { 973 } else if (dash_index != std::string::npos) {
974 *layout_id = layout_name.substr(0, dash_index); 974 *layout_id = layout_name.substr(0, dash_index);
975 *layout_variant = layout_name.substr(dash_index + 1); 975 *layout_variant = layout_name.substr(dash_index + 1);
976 } 976 }
977 } 977 }
978 978
979 } // namespace ui 979 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698