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

Unified 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, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/ime/ime_util.cc
diff --git a/ash/system/ime/ime_util.cc b/ash/system/ime/ime_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..27ee8a2dfc5f2850153334ccc26bd854ed90a4f7
--- /dev/null
+++ b/ash/system/ime/ime_util.cc
@@ -0,0 +1,111 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/ime/ime_util.h"
+
+#include <memory>
+#include <string>
+
+#include "ash/system/tray/ime_info.h"
+#include "base/strings/utf_string_conversions.h"
+#include "ui/base/ime/chromeos/extension_ime_util.h"
+#include "ui/base/ime/chromeos/input_method_descriptor.h"
+#include "ui/base/ime/chromeos/input_method_manager.h"
+#include "ui/base/ime/chromeos/input_method_util.h"
+#include "ui/chromeos/ime/input_method_menu_item.h"
+#include "ui/chromeos/ime/input_method_menu_manager.h"
+
+using chromeos::input_method::InputMethodDescriptor;
+using chromeos::input_method::InputMethodDescriptors;
+using chromeos::input_method::InputMethodManager;
+using chromeos::input_method::InputMethodUtil;
+
+namespace ash {
+namespace ime_util {
+namespace {
+
+IMEInfo* g_current_ime_for_testing = nullptr;
+std::vector<IMEInfo>* g_available_ime_list_for_testing = nullptr;
+
+IMEInfo ExtractIMEInfo(const InputMethodDescriptor& ime,
+ const InputMethodUtil& util) {
+ IMEInfo info;
+ info.id = ime.id();
+ info.name = util.GetInputMethodLongName(ime);
+ info.medium_name = util.GetInputMethodMediumName(ime);
+ info.short_name = util.GetInputMethodShortName(ime);
+ info.third_party = chromeos::extension_ime_util::IsExtensionIME(ime.id());
+ return info;
+}
+
+} // namespace
+
+IMEInfo GetCurrentIME() {
+ if (g_current_ime_for_testing)
+ return *g_current_ime_for_testing;
+
+ InputMethodManager* manager = InputMethodManager::Get();
+ InputMethodUtil* util = manager->GetInputMethodUtil();
+ InputMethodDescriptor ime =
+ manager->GetActiveIMEState()->GetCurrentInputMethod();
+ IMEInfo info = ExtractIMEInfo(ime, *util);
+ info.selected = true;
+ return info;
+}
+
+std::vector<IMEInfo> GetAvailableIMEList() {
+ if (g_available_ime_list_for_testing)
+ return *g_available_ime_list_for_testing;
+
+ std::vector<IMEInfo> list;
+ InputMethodManager* manager = InputMethodManager::Get();
+ InputMethodUtil* util = manager->GetInputMethodUtil();
+ std::unique_ptr<InputMethodDescriptors> ime_descriptors(
+ manager->GetActiveIMEState()->GetActiveInputMethods());
+ std::string current =
+ manager->GetActiveIMEState()->GetCurrentInputMethod().id();
+ for (const InputMethodDescriptor& ime : *ime_descriptors) {
+ IMEInfo info = ExtractIMEInfo(ime, *util);
+ info.selected = ime.id() == current;
+ list.push_back(info);
+ }
+ return list;
+}
+
+std::vector<IMEPropertyInfo> GetCurrentIMEProperties() {
+ std::vector<IMEPropertyInfo> list;
+ ui::ime::InputMethodMenuItemList menu_list =
+ ui::ime::InputMethodMenuManager::GetInstance()
+ ->GetCurrentInputMethodMenuItemList();
+ for (const ui::ime::InputMethodMenuItem& item : menu_list) {
+ IMEPropertyInfo property;
+ property.key = item.key;
+ property.name = base::UTF8ToUTF16(item.label);
+ property.selected = item.is_selection_item_checked;
+ list.push_back(property);
+ }
+ return list;
+}
+
+ScopedCurrentImeForTesting::ScopedCurrentImeForTesting(IMEInfo* info)
+ : last_info_(g_current_ime_for_testing) {
+ g_current_ime_for_testing = info;
+}
+
+ScopedCurrentImeForTesting::~ScopedCurrentImeForTesting() {
+ g_current_ime_for_testing = last_info_;
+}
+
+ScopedAvailableImeListForTesting::ScopedAvailableImeListForTesting(
+ std::vector<IMEInfo>* list)
+ : last_list_(g_available_ime_list_for_testing) {
+ g_available_ime_list_for_testing = list;
+}
+
+ScopedAvailableImeListForTesting::~ScopedAvailableImeListForTesting() {
+ g_available_ime_list_for_testing = last_list_;
+}
+
+} // namespace ime_util
+} // namespace ash
« 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