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

Side by Side Diff: ash/system/ime/ime_util.cc

Issue 2917683003: chromeos: Remove the last IME methods from ash::SystemTrayDelegate (Closed)
Patch Set: cleanup Created 3 years, 6 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 | « ash/system/ime/ime_util.h ('k') | ash/system/ime/tray_ime_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/ime/ime_util.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "ash/system/tray/ime_info.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/base/ime/chromeos/extension_ime_util.h"
13 #include "ui/base/ime/chromeos/input_method_descriptor.h"
14 #include "ui/base/ime/chromeos/input_method_manager.h"
15 #include "ui/base/ime/chromeos/input_method_util.h"
16 #include "ui/chromeos/ime/input_method_menu_item.h"
17 #include "ui/chromeos/ime/input_method_menu_manager.h"
18
19 using chromeos::input_method::InputMethodDescriptor;
20 using chromeos::input_method::InputMethodDescriptors;
21 using chromeos::input_method::InputMethodManager;
22 using chromeos::input_method::InputMethodUtil;
23
24 namespace ash {
25 namespace ime_util {
26 namespace {
27
28 IMEInfo* g_current_ime_for_testing = nullptr;
29 std::vector<IMEInfo>* g_available_ime_list_for_testing = nullptr;
30
31 IMEInfo ExtractIMEInfo(const InputMethodDescriptor& ime,
32 const InputMethodUtil& util) {
33 IMEInfo info;
34 info.id = ime.id();
35 info.name = util.GetInputMethodLongName(ime);
36 info.medium_name = util.GetInputMethodMediumName(ime);
37 info.short_name = util.GetInputMethodShortName(ime);
38 info.third_party = chromeos::extension_ime_util::IsExtensionIME(ime.id());
39 return info;
40 }
41
42 } // namespace
43
44 IMEInfo GetCurrentIME() {
45 if (g_current_ime_for_testing)
46 return *g_current_ime_for_testing;
47
48 InputMethodManager* manager = InputMethodManager::Get();
49 InputMethodUtil* util = manager->GetInputMethodUtil();
50 InputMethodDescriptor ime =
51 manager->GetActiveIMEState()->GetCurrentInputMethod();
52 IMEInfo info = ExtractIMEInfo(ime, *util);
53 info.selected = true;
54 return info;
55 }
56
57 std::vector<IMEInfo> GetAvailableIMEList() {
58 if (g_available_ime_list_for_testing)
59 return *g_available_ime_list_for_testing;
60
61 std::vector<IMEInfo> list;
62 InputMethodManager* manager = InputMethodManager::Get();
63 InputMethodUtil* util = manager->GetInputMethodUtil();
64 std::unique_ptr<InputMethodDescriptors> ime_descriptors(
65 manager->GetActiveIMEState()->GetActiveInputMethods());
66 std::string current =
67 manager->GetActiveIMEState()->GetCurrentInputMethod().id();
68 for (const InputMethodDescriptor& ime : *ime_descriptors) {
69 IMEInfo info = ExtractIMEInfo(ime, *util);
70 info.selected = ime.id() == current;
71 list.push_back(info);
72 }
73 return list;
74 }
75
76 std::vector<IMEPropertyInfo> GetCurrentIMEProperties() {
77 std::vector<IMEPropertyInfo> list;
78 ui::ime::InputMethodMenuItemList menu_list =
79 ui::ime::InputMethodMenuManager::GetInstance()
80 ->GetCurrentInputMethodMenuItemList();
81 for (const ui::ime::InputMethodMenuItem& item : menu_list) {
82 IMEPropertyInfo property;
83 property.key = item.key;
84 property.name = base::UTF8ToUTF16(item.label);
85 property.selected = item.is_selection_item_checked;
86 list.push_back(property);
87 }
88 return list;
89 }
90
91 ScopedCurrentImeForTesting::ScopedCurrentImeForTesting(IMEInfo* info)
92 : last_info_(g_current_ime_for_testing) {
93 g_current_ime_for_testing = info;
94 }
95
96 ScopedCurrentImeForTesting::~ScopedCurrentImeForTesting() {
97 g_current_ime_for_testing = last_info_;
98 }
99
100 ScopedAvailableImeListForTesting::ScopedAvailableImeListForTesting(
101 std::vector<IMEInfo>* list)
102 : last_list_(g_available_ime_list_for_testing) {
103 g_available_ime_list_for_testing = list;
104 }
105
106 ScopedAvailableImeListForTesting::~ScopedAvailableImeListForTesting() {
107 g_available_ime_list_for_testing = last_list_;
108 }
109
110 } // namespace ime_util
111 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/ime/ime_util.h ('k') | ash/system/ime/tray_ime_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698