chromeos: Make ash system tray IME menus work under mustash, part 1
Introduce ash::ImeManager. It will eventually proxy IME-related requests
from ash to chrome browser over mojo. For now it is an interface
implemented in chrome browser by InputMethodManagerImpl.
Move SystemTrayDelegate IME interface methods to the ImeManager interface.
Move the SystemTrayDelegateChromeOS IME method implementations into
InputMethodManagerImpl, which is the class that actually does the work.
Add an explicit IsImeManaged() method to detect enterprise-managed IMEs,
rather than encoding that concept in a string being non-empty.
Use a more specific tooltip string for the IME enterprise-managed
system tray icon. Put the string in ash eliminates a chrome dependency.
Eliminate TestSystemTrayDelegate because it no longer has any useful
methods.
Bug: 724305
Change-Id: I8545b00c2f0ad59cc276ca465d32a1952fedd4b6
Reviewed-on: https://chromium-review.googlesource.com/527555
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: Zachary Kuznia <zork@chromium.org>
Reviewed-by: Hadi Moshayedi <moshayedi@chromium.org>
Reviewed-by: Terry Anderson <tdanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478477}diff --git a/ash/BUILD.gn b/ash/BUILD.gn
index 04c1ca6..26914aa 100644
--- a/ash/BUILD.gn
+++ b/ash/BUILD.gn
@@ -188,6 +188,8 @@
"host/root_window_transformer.h",
"host/transformer_helper.cc",
"host/transformer_helper.h",
+ "ime/ime_controller.cc",
+ "ime/ime_controller.h",
"ime/ime_switch_type.h",
"key_event_watcher.cc",
"key_event_watcher.h",
diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd
index f4b54e9b..68fe43c 100644
--- a/ash/ash_strings.grd
+++ b/ash/ash_strings.grd
@@ -300,6 +300,9 @@
<message name="IDS_ASH_STATUS_TRAY_IME_SETTINGS" desc="The label used for IME settings entry.">
Customize languages and input...
</message>
+ <message name="IDS_ASH_STATUS_TRAY_IME_MANAGED" desc="Tooltip for the icon displayed when input methods are managed by enterprise policy">
+ Input methods are configured by your administrator.
+ </message>
<message name="IDS_ASH_STATUS_TRAY_IME_EMOJI" desc="The label used for IME emoji entry.">
Emoji palette
</message>
diff --git a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc
index 60fca91..8a708ec 100644
--- a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc
+++ b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc
@@ -19,7 +19,6 @@
#include "ash/test/content/test_shell_content_state.h"
#include "ash/test/screen_orientation_controller_test_api.h"
#include "ash/test/test_shell_delegate.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/wm/window_state.h"
#include "base/command_line.h"
diff --git a/ash/ime/ime_controller.cc b/ash/ime/ime_controller.cc
new file mode 100644
index 0000000..4fc7be5
--- /dev/null
+++ b/ash/ime/ime_controller.cc
@@ -0,0 +1,29 @@
+// 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/ime/ime_controller.h"
+
+namespace ash {
+
+ImeController::ImeController() = default;
+
+ImeController::~ImeController() = default;
+
+IMEInfo ImeController::GetCurrentIme() const {
+ return IMEInfo();
+}
+
+std::vector<IMEPropertyInfo> ImeController::GetCurrentImeProperties() const {
+ return std::vector<IMEPropertyInfo>();
+}
+
+std::vector<IMEInfo> ImeController::GetAvailableImes() const {
+ return std::vector<IMEInfo>();
+}
+
+bool ImeController::IsImeManaged() const {
+ return false;
+}
+
+} // namespace ash
diff --git a/ash/ime/ime_controller.h b/ash/ime/ime_controller.h
new file mode 100644
index 0000000..dce021b
--- /dev/null
+++ b/ash/ime/ime_controller.h
@@ -0,0 +1,44 @@
+// 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.
+
+#ifndef ASH_IME_IME_CONTROLLER_H_
+#define ASH_IME_IME_CONTROLLER_H_
+
+#include <vector>
+
+#include "ash/ash_export.h"
+#include "ash/system/tray/ime_info.h"
+#include "base/macros.h"
+
+namespace ash {
+struct IMEInfo;
+
+// Connects ash IME users (e.g. the system tray) to the IME implementation,
+// which might live in Chrome browser or in a separate mojo service.
+// TODO(jamescook): Convert to use mojo IME interface to Chrome browser.
+class ASH_EXPORT ImeController {
+ public:
+ ImeController();
+ virtual ~ImeController();
+
+ // Returns the currently selected IME.
+ virtual IMEInfo GetCurrentIme() const;
+
+ // Returns a list of properties for the currently selected IME.
+ virtual std::vector<IMEPropertyInfo> GetCurrentImeProperties() const;
+
+ // Returns a list of available IMEs. "Available" IMEs are both installed and
+ // enabled by the user in settings.
+ virtual std::vector<IMEInfo> GetAvailableImes() const;
+
+ // Returns true if the available IMEs are managed by enterprise policy.
+ virtual bool IsImeManaged() const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ImeController);
+};
+
+} // namespace ash
+
+#endif // ASH_IME_IME_CONTROLLER_H_
diff --git a/ash/mus/shell_delegate_mus.cc b/ash/mus/shell_delegate_mus.cc
index 744ec66..e6a79c8 100644
--- a/ash/mus/shell_delegate_mus.cc
+++ b/ash/mus/shell_delegate_mus.cc
@@ -87,6 +87,10 @@
return new SystemTrayDelegateMus();
}
+ImeController* ShellDelegateMus::GetImeController() {
+ return &stub_ime_controller_;
+}
+
std::unique_ptr<WallpaperDelegate> ShellDelegateMus::CreateWallpaperDelegate() {
return base::MakeUnique<WallpaperDelegateMus>();
}
diff --git a/ash/mus/shell_delegate_mus.h b/ash/mus/shell_delegate_mus.h
index 7736d37..4c9f266 100644
--- a/ash/mus/shell_delegate_mus.h
+++ b/ash/mus/shell_delegate_mus.h
@@ -7,6 +7,7 @@
#include <memory>
+#include "ash/ime/ime_controller.h"
#include "ash/shell_delegate.h"
#include "base/macros.h"
@@ -36,6 +37,7 @@
void ShelfInit() override;
void ShelfShutdown() override;
SystemTrayDelegate* CreateSystemTrayDelegate() override;
+ ImeController* GetImeController() override;
std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() override;
@@ -53,6 +55,7 @@
private:
// |connector_| may be null in tests.
service_manager::Connector* connector_;
+ ImeController stub_ime_controller_;
DISALLOW_COPY_AND_ASSIGN(ShellDelegateMus);
};
diff --git a/ash/shelf/shelf_view_unittest.cc b/ash/shelf/shelf_view_unittest.cc
index 361a947..4ee61920 100644
--- a/ash/shelf/shelf_view_unittest.cc
+++ b/ash/shelf/shelf_view_unittest.cc
@@ -34,7 +34,6 @@
#include "ash/test/shelf_view_test_api.h"
#include "ash/test/shell_test_api.h"
#include "ash/test/test_shell_delegate.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/test/wallpaper_controller_test_api.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "base/i18n/rtl.h"
diff --git a/ash/shell.cc b/ash/shell.cc
index 6ef34b2b..e7e58d4 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -42,6 +42,7 @@
#include "ash/frame/custom_frame_view_ash.h"
#include "ash/gpu_support.h"
#include "ash/high_contrast/high_contrast_controller.h"
+#include "ash/ime/ime_controller.h"
#include "ash/keyboard/keyboard_ui.h"
#include "ash/laser/laser_pointer_controller.h"
#include "ash/login/lock_screen_controller.h"
@@ -564,6 +565,7 @@
base::MakeUnique<system::BrightnessControllerChromeos>()),
cast_config_(base::MakeUnique<CastConfigController>()),
focus_cycler_(base::MakeUnique<FocusCycler>()),
+ ime_controller_(shell_delegate->GetImeController()),
immersive_context_(base::MakeUnique<ImmersiveContextAsh>()),
keyboard_brightness_control_delegate_(
base::MakeUnique<KeyboardBrightnessController>()),
@@ -589,6 +591,7 @@
native_cursor_manager_(nullptr),
simulate_modal_window_open_for_testing_(false),
is_touch_hud_projection_enabled_(false) {
+ DCHECK(ime_controller_);
// TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
// state on ShellPortClassic. http://crbug.com/671246.
diff --git a/ash/shell.h b/ash/shell.h
index 45a6995..910315c 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -109,6 +109,7 @@
class FocusCycler;
class GPUSupport;
class HighContrastController;
+class ImeController;
class ImmersiveContextAsh;
class ImmersiveHandlerFactoryAsh;
class KeyboardBrightnessControlDelegate;
@@ -323,6 +324,7 @@
}
::wm::CompoundEventFilter* env_filter() { return env_filter_.get(); }
FocusCycler* focus_cycler() { return focus_cycler_.get(); }
+ ImeController* ime_controller() { return ime_controller_; }
KeyboardBrightnessControlDelegate* keyboard_brightness_control_delegate() {
return keyboard_brightness_control_delegate_.get();
}
@@ -689,6 +691,7 @@
std::unique_ptr<CastConfigController> cast_config_;
std::unique_ptr<DragDropController> drag_drop_controller_;
std::unique_ptr<FocusCycler> focus_cycler_;
+ ImeController* const ime_controller_;
std::unique_ptr<ImmersiveContextAsh> immersive_context_;
std::unique_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate_;
diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc
index 6958fe8..5dc0147 100644
--- a/ash/shell/shell_delegate_impl.cc
+++ b/ash/shell/shell_delegate_impl.cc
@@ -14,8 +14,8 @@
#include "ash/shell/context_menu.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/toplevel_window.h"
+#include "ash/system/tray/system_tray_delegate.h"
#include "ash/test/test_keyboard_ui.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/window_state.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
@@ -107,7 +107,11 @@
void ShellDelegateImpl::ShelfShutdown() {}
SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
- return new test::TestSystemTrayDelegate;
+ return new SystemTrayDelegate;
+}
+
+ImeController* ShellDelegateImpl::GetImeController() {
+ return &stub_ime_controller_;
}
std::unique_ptr<WallpaperDelegate>
diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h
index 0074e50c..ba873a7 100644
--- a/ash/shell/shell_delegate_impl.h
+++ b/ash/shell/shell_delegate_impl.h
@@ -8,6 +8,7 @@
#include <memory>
#include <string>
+#include "ash/ime/ime_controller.h"
#include "ash/shell_delegate.h"
#include "base/macros.h"
@@ -38,6 +39,7 @@
void ShelfInit() override;
void ShelfShutdown() override;
SystemTrayDelegate* CreateSystemTrayDelegate() override;
+ ImeController* GetImeController() override;
std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() override;
@@ -53,6 +55,8 @@
void UpdateTouchscreenStatusFromPrefs() override;
private:
+ ImeController stub_ime_controller_;
+
DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl);
};
diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h
index f5c62c3b..583a852 100644
--- a/ash/shell_delegate.h
+++ b/ash/shell_delegate.h
@@ -39,6 +39,7 @@
class AccessibilityDelegate;
class GPUSupport;
+class ImeController;
class PaletteDelegate;
class Shelf;
struct ShelfItem;
@@ -98,6 +99,9 @@
// Creates a system-tray delegate. Shell takes ownership of the delegate.
virtual SystemTrayDelegate* CreateSystemTrayDelegate() = 0;
+ // TODO(jamescook): Remove in favor of chrome using a mojo interface on ash.
+ virtual ImeController* GetImeController() = 0;
+
// Creates a wallpaper delegate. Shell takes ownership of the delegate.
virtual std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() = 0;
diff --git a/ash/system/ime/tray_ime_chromeos.cc b/ash/system/ime/tray_ime_chromeos.cc
index 9ecec4f7..abd34c2 100644
--- a/ash/system/ime/tray_ime_chromeos.cc
+++ b/ash/system/ime/tray_ime_chromeos.cc
@@ -7,13 +7,13 @@
#include <memory>
#include <vector>
+#include "ash/ime/ime_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_controller.h"
-#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_details_view.h"
@@ -75,13 +75,15 @@
// enterprise-controlled icon).
class IMEDetailedView : public ImeListView {
public:
- explicit IMEDetailedView(SystemTrayItem* owner)
- : ImeListView(owner), settings_button_(nullptr) {}
+ IMEDetailedView(SystemTrayItem* owner, ImeController* ime_controller)
+ : ImeListView(owner), ime_controller_(ime_controller) {
+ DCHECK(ime_controller_);
+ }
~IMEDetailedView() override {}
- void SetImeManagedMessage(base::string16 ime_managed_message) {
- ime_managed_message_ = ime_managed_message;
+ views::ImageView* controlled_setting_icon() {
+ return controlled_setting_icon_;
}
void Update(const IMEInfoList& list,
@@ -110,11 +112,12 @@
}
void CreateExtraTitleRowButtons() override {
- if (!ime_managed_message_.empty()) {
+ if (ime_controller_->IsImeManaged()) {
controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView();
controlled_setting_icon_->SetImage(
gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor));
- controlled_setting_icon_->SetTooltipText(ime_managed_message_);
+ controlled_setting_icon_->SetTooltipText(
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_IME_MANAGED));
tri_view()->AddView(TriView::Container::END, controlled_setting_icon_);
}
@@ -131,13 +134,13 @@
owner()->system_tray()->CloseSystemBubble();
}
- views::Button* settings_button_;
+ ImeController* const ime_controller_;
+
+ // Gear icon that takes the user to IME settings.
+ views::Button* settings_button_ = nullptr;
// This icon says that the IMEs are managed by policy.
- views::ImageView* controlled_setting_icon_;
- // If non-empty, a controlled setting icon should be displayed with this
- // string as tooltip.
- base::string16 ime_managed_message_;
+ views::ImageView* controlled_setting_icon_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(IMEDetailedView);
};
@@ -146,11 +149,13 @@
TrayIME::TrayIME(SystemTray* system_tray)
: SystemTrayItem(system_tray, UMA_IME),
+ ime_controller_(Shell::Get()->ime_controller()),
tray_label_(nullptr),
default_(nullptr),
detailed_(nullptr),
keyboard_suppressed_(false),
is_visible_(true) {
+ DCHECK(ime_controller_);
SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier();
tray_notifier->AddVirtualKeyboardObserver(this);
tray_notifier->AddAccessibilityObserver(this);
@@ -181,7 +186,6 @@
default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1));
}
if (detailed_) {
- detailed_->SetImeManagedMessage(ime_managed_message_);
detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle(),
GetSingleImeBehavior());
}
@@ -211,9 +215,7 @@
base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) {
if (show_ime_label) {
- IMEInfo current;
- Shell::Get()->system_tray_delegate()->GetCurrentIME(¤t);
- return current.name;
+ return ime_controller_->GetCurrentIme().name;
} else {
// Display virtual keyboard status instead.
int id = keyboard::IsKeyboardEnabled()
@@ -244,8 +246,7 @@
views::View* TrayIME::CreateDetailedView(LoginStatus status) {
CHECK(detailed_ == nullptr);
- detailed_ = new tray::IMEDetailedView(this);
- detailed_->SetImeManagedMessage(ime_managed_message_);
+ detailed_ = new tray::IMEDetailedView(this, ime_controller_);
detailed_->Init(ShouldShowKeyboardToggle(), GetSingleImeBehavior());
return detailed_;
}
@@ -264,13 +265,9 @@
void TrayIME::OnIMERefresh() {
// Caches the current ime state.
- SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
- ime_list_.clear();
- property_list_.clear();
- delegate->GetCurrentIME(¤t_ime_);
- delegate->GetAvailableIMEList(&ime_list_);
- delegate->GetCurrentIMEProperties(&property_list_);
- ime_managed_message_ = delegate->GetIMEManagedMessage();
+ current_ime_ = ime_controller_->GetCurrentIme();
+ property_list_ = ime_controller_->GetCurrentImeProperties();
+ ime_list_ = ime_controller_->GetAvailableImes();
Update();
}
@@ -284,7 +281,7 @@
}
bool TrayIME::IsIMEManaged() {
- return !ime_managed_message_.empty();
+ return ime_controller_->IsImeManaged();
}
bool TrayIME::ShouldDefaultViewBeVisible() {
@@ -306,4 +303,8 @@
: ImeListView::HIDE_SINGLE_IME;
}
+views::View* TrayIME::GetControlledSettingIconForTesting() {
+ return detailed_ ? detailed_->controlled_setting_icon() : nullptr;
+}
+
} // namespace ash
diff --git a/ash/system/ime/tray_ime_chromeos.h b/ash/system/ime/tray_ime_chromeos.h
index ac60097..699f9696 100644
--- a/ash/system/ime/tray_ime_chromeos.h
+++ b/ash/system/ime/tray_ime_chromeos.h
@@ -22,6 +22,7 @@
class IMEDetailedView;
}
+class ImeController;
class TrayItemView;
// Controller for IME options in the system menu. Note this is separate from
@@ -67,7 +68,7 @@
void OnIMERefresh() override;
void OnIMEMenuActivationChanged(bool is_active) override;
- // Returns true input methods are managed by policy.
+ // Returns true if input methods are managed by policy.
bool IsIMEManaged();
// Whether the default view should be shown.
@@ -79,6 +80,10 @@
// sub-view.
ImeListView::SingleImeBehavior GetSingleImeBehavior();
+ // Returns the icon used when the IME is managed.
+ views::View* GetControlledSettingIconForTesting();
+
+ ImeController* ime_controller_;
TrayItemView* tray_label_;
tray::IMEDefaultView* default_;
tray::IMEDetailedView* detailed_;
@@ -88,9 +93,6 @@
IMEInfoList ime_list_;
IMEInfo current_ime_;
IMEPropertyInfoList property_list_;
- // If non-empty, a controlled-setting icon should be displayed with a tooltip
- // text defined by this string.
- base::string16 ime_managed_message_;
// Whether the IME label and tray items should be visible.
bool is_visible_;
diff --git a/ash/system/ime/tray_ime_chromeos_unittest.cc b/ash/system/ime/tray_ime_chromeos_unittest.cc
index a7b2fe47..9bbad2f 100644
--- a/ash/system/ime/tray_ime_chromeos_unittest.cc
+++ b/ash/system/ime/tray_ime_chromeos_unittest.cc
@@ -6,6 +6,7 @@
#include "ash/accessibility_delegate.h"
#include "ash/accessibility_types.h"
+#include "ash/ime/ime_controller.h"
#include "ash/public/cpp/config.h"
#include "ash/shell.h"
#include "ash/system/ime_menu/ime_list_view.h"
@@ -16,6 +17,31 @@
#include "ui/keyboard/keyboard_util.h"
namespace ash {
+namespace {
+
+class TestImeController : public ImeController {
+ public:
+ TestImeController() = default;
+ ~TestImeController() override = default;
+
+ // ImeController:
+ std::vector<IMEPropertyInfo> GetCurrentImeProperties() const override {
+ return current_ime_properties_;
+ }
+ std::vector<IMEInfo> GetAvailableImes() const override {
+ return available_imes_;
+ }
+ bool IsImeManaged() const override { return is_ime_managed_; }
+
+ std::vector<IMEPropertyInfo> current_ime_properties_;
+ std::vector<IMEInfo> available_imes_;
+ bool is_ime_managed_ = false;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestImeController);
+};
+
+} // namespace
class TrayIMETest : public test::AshTestBase {
public:
@@ -30,15 +56,18 @@
// is not created in ash tests.
void SetAccessibilityKeyboardEnabled(bool enabled);
- // Sets the current number of active IMEs.
- void SetIMELength(int length);
+ // Creates |count| simulated active IMEs.
+ void SetActiveImeCount(int count);
// Returns the view responsible for toggling virtual keyboard.
views::View* GetToggleView() const;
- // Sets the managed IMEs tooltip message (and thus also if IMEs are managed =
- // non-empty or not = empty)
- void SetManagedMessage(base::string16 managed_message);
+ // Simulates IME being managed by policy.
+ void SetImeManaged(bool managed);
+
+ views::View* GetImeManagedIcon();
+
+ void AddPropertyToCurrentIme(IMEPropertyInfo property);
void SuppressKeyboard();
void RestoreKeyboard();
@@ -48,6 +77,7 @@
void TearDown() override;
private:
+ TestImeController test_ime_controller_;
std::unique_ptr<TrayIME> tray_;
std::unique_ptr<views::View> default_view_;
std::unique_ptr<views::View> detailed_view_;
@@ -68,13 +98,13 @@
notification);
}
-void TrayIMETest::SetIMELength(int length) {
- tray_->ime_list_.clear();
+void TrayIMETest::SetActiveImeCount(int count) {
+ test_ime_controller_.available_imes_.clear();
IMEInfo ime;
- for (int i = 0; i < length; i++) {
- tray_->ime_list_.push_back(ime);
+ for (int i = 0; i < count; i++) {
+ test_ime_controller_.available_imes_.push_back(ime);
}
- tray_->Update();
+ tray_->OnIMERefresh();
}
views::View* TrayIMETest::GetToggleView() const {
@@ -82,9 +112,18 @@
return test_api.GetToggleView();
}
-void TrayIMETest::SetManagedMessage(base::string16 managed_message) {
- tray_->ime_managed_message_ = managed_message;
- tray_->Update();
+void TrayIMETest::SetImeManaged(bool managed) {
+ test_ime_controller_.is_ime_managed_ = true;
+ tray_->OnIMERefresh();
+}
+
+views::View* TrayIMETest::GetImeManagedIcon() {
+ return tray_->GetControlledSettingIconForTesting();
+}
+
+void TrayIMETest::AddPropertyToCurrentIme(IMEPropertyInfo property) {
+ test_ime_controller_.current_ime_properties_.push_back(property);
+ tray_->OnIMERefresh();
}
void TrayIMETest::SuppressKeyboard() {
@@ -120,6 +159,7 @@
void TrayIMETest::SetUp() {
test::AshTestBase::SetUp();
tray_.reset(new TrayIME(GetPrimarySystemTray()));
+ tray_->ime_controller_ = &test_ime_controller_;
default_view_.reset(tray_->CreateDefaultView(LoginStatus::USER));
detailed_view_.reset(tray_->CreateDetailedView(LoginStatus::USER));
}
@@ -137,26 +177,57 @@
// Tests that if the keyboard is not suppressed the default view is hidden
// if less than 2 IMEs are present.
TEST_F(TrayIMETest, HiddenWithNoIMEs) {
- SetIMELength(0);
+ SetActiveImeCount(0);
EXPECT_FALSE(default_view()->visible());
- SetIMELength(1);
+ SetActiveImeCount(1);
EXPECT_FALSE(default_view()->visible());
- SetIMELength(2);
+ SetActiveImeCount(2);
EXPECT_TRUE(default_view()->visible());
}
// Tests that if IMEs are managed, the default view is displayed even for a
// single IME.
TEST_F(TrayIMETest, ShownWithSingleIMEWhenManaged) {
- SetManagedMessage(base::ASCIIToUTF16("managed"));
- SetIMELength(0);
+ SetImeManaged(true);
+ SetActiveImeCount(0);
EXPECT_FALSE(default_view()->visible());
- SetIMELength(1);
+ SetActiveImeCount(1);
EXPECT_TRUE(default_view()->visible());
- SetIMELength(2);
+ SetActiveImeCount(2);
EXPECT_TRUE(default_view()->visible());
}
+// Tests that if an IME has multiple properties the default view is
+// displayed even for a single IME.
+TEST_F(TrayIMETest, ShownWithSingleImeWithProperties) {
+ SetActiveImeCount(1);
+ EXPECT_FALSE(default_view()->visible());
+
+ IMEPropertyInfo property1;
+ AddPropertyToCurrentIme(property1);
+ EXPECT_FALSE(default_view()->visible());
+
+ IMEPropertyInfo property2;
+ AddPropertyToCurrentIme(property2);
+ EXPECT_TRUE(default_view()->visible());
+}
+
+// Tests that when IMEs are managed an icon appears in the tray with an
+// appropriate tooltip.
+TEST_F(TrayIMETest, ImeManagedIcon) {
+ SetActiveImeCount(1);
+ EXPECT_FALSE(GetImeManagedIcon());
+
+ SetImeManaged(true);
+ views::View* icon = GetImeManagedIcon();
+ ASSERT_TRUE(icon);
+ base::string16 tooltip;
+ icon->GetTooltipText(gfx::Point(), &tooltip);
+ EXPECT_EQ(
+ base::ASCIIToUTF16("Input methods are configured by your administrator."),
+ tooltip);
+}
+
// Tests that if no IMEs are present the default view is hidden when a11y is
// enabled.
TEST_F(TrayIMETest, HidesOnA11yEnabled) {
@@ -164,7 +235,7 @@
if (Shell::GetAshConfig() == Config::MASH)
return;
- SetIMELength(0);
+ SetActiveImeCount(0);
SuppressKeyboard();
EXPECT_TRUE(default_view()->visible());
// Enable a11y keyboard.
@@ -182,7 +253,7 @@
if (Shell::GetAshConfig() == Config::MASH)
return;
- SetIMELength(0);
+ SetActiveImeCount(0);
SuppressKeyboard();
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
views::View* toggle = GetToggleView();
diff --git a/ash/system/ime_menu/ime_list_view.cc b/ash/system/ime_menu/ime_list_view.cc
index 8f2e655f..5600479 100644
--- a/ash/system/ime_menu/ime_list_view.cc
+++ b/ash/system/ime_menu/ime_list_view.cc
@@ -4,6 +4,7 @@
#include "ash/system/ime_menu/ime_list_view.h"
+#include "ash/ime/ime_controller.h"
#include "ash/ime/ime_switch_type.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
@@ -12,7 +13,6 @@
#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/ime_info.h"
#include "ash/system/tray/system_menu_button.h"
-#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_details_view.h"
#include "ash/system/tray/tray_popup_header_button.h"
@@ -195,11 +195,9 @@
void ImeListView::Init(bool show_keyboard_toggle,
SingleImeBehavior single_ime_behavior) {
- SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
- IMEInfoList list;
- delegate->GetAvailableIMEList(&list);
- IMEPropertyInfoList property_list;
- delegate->GetCurrentIMEProperties(&property_list);
+ ImeController* ime_controller = Shell::Get()->ime_controller();
+ IMEInfoList list = ime_controller->GetAvailableImes();
+ IMEPropertyInfoList property_list = ime_controller->GetCurrentImeProperties();
Update(list, property_list, show_keyboard_toggle, single_ime_behavior);
}
diff --git a/ash/system/ime_menu/ime_menu_tray.cc b/ash/system/ime_menu/ime_menu_tray.cc
index 17720b43..ce3f458 100644
--- a/ash/system/ime_menu/ime_menu_tray.cc
+++ b/ash/system/ime_menu/ime_menu_tray.cc
@@ -6,6 +6,7 @@
#include "ash/accessibility_delegate.h"
#include "ash/ash_constants.h"
+#include "ash/ime/ime_controller.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shelf/shelf.h"
@@ -15,7 +16,6 @@
#include "ash/system/ime_menu/ime_list_view.h"
#include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/system_tray_controller.h"
-#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_container.h"
@@ -279,12 +279,14 @@
ImeMenuTray::ImeMenuTray(Shelf* shelf)
: TrayBackgroundView(shelf),
+ ime_controller_(Shell::Get()->ime_controller()),
label_(new ImeMenuLabel()),
show_keyboard_(false),
force_show_keyboard_(false),
keyboard_suppressed_(false),
show_bubble_after_keyboard_hidden_(false),
weak_ptr_factory_(this) {
+ DCHECK(ime_controller_);
SetInkDropMode(InkDropMode::ON);
SetupLabelForTray(label_);
label_->SetElideBehavior(gfx::TRUNCATE);
@@ -443,11 +445,9 @@
void ImeMenuTray::OnIMERefresh() {
UpdateTrayLabel();
if (bubble_ && ime_list_view_) {
- SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
- IMEInfoList list;
- delegate->GetAvailableIMEList(&list);
- IMEPropertyInfoList property_list;
- delegate->GetCurrentIMEProperties(&property_list);
+ std::vector<IMEInfo> list = ime_controller_->GetAvailableImes();
+ IMEPropertyInfoList property_list =
+ ime_controller_->GetCurrentImeProperties();
ime_list_view_->Update(list, property_list, false,
ImeListView::SHOW_SINGLE_IME);
}
@@ -534,7 +534,7 @@
}
void ImeMenuTray::UpdateTrayLabel() {
- Shell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_);
+ current_ime_ = ime_controller_->GetCurrentIme();
// Updates the tray label based on the current input method.
if (current_ime_.third_party)
diff --git a/ash/system/ime_menu/ime_menu_tray.h b/ash/system/ime_menu/ime_menu_tray.h
index 3019158ca..d2c9eda 100644
--- a/ash/system/ime_menu/ime_menu_tray.h
+++ b/ash/system/ime_menu/ime_menu_tray.h
@@ -20,6 +20,7 @@
} // namespace views
namespace ash {
+class ImeController;
class ImeListView;
// A button in the tray which displays the short name of the currently-activated
@@ -95,6 +96,8 @@
// Disables the virtual keyboard.
void DisableVirtualKeyboard();
+ ImeController* ime_controller_;
+
// Bubble for default and detailed views.
std::unique_ptr<TrayBubbleWrapper> bubble_;
ImeListView* ime_list_view_;
diff --git a/ash/system/ime_menu/ime_menu_tray_unittest.cc b/ash/system/ime_menu/ime_menu_tray_unittest.cc
index 10ea62d8..7bc17e95 100644
--- a/ash/system/ime_menu/ime_menu_tray_unittest.cc
+++ b/ash/system/ime_menu/ime_menu_tray_unittest.cc
@@ -6,6 +6,7 @@
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accessibility_delegate.h"
+#include "ash/ime/ime_controller.h"
#include "ash/shell.h"
#include "ash/system/ime_menu/ime_list_view.h"
#include "ash/system/status_area_widget.h"
@@ -13,7 +14,6 @@
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/status_area_widget_test_helper.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_node_data.h"
@@ -27,16 +27,43 @@
using base::UTF8ToUTF16;
namespace ash {
+namespace {
+
+class TestImeController : public ImeController {
+ public:
+ TestImeController() = default;
+ ~TestImeController() override = default;
+
+ // ImeController:
+ IMEInfo GetCurrentIme() const override { return current_ime_; }
+ std::vector<IMEInfo> GetAvailableImes() const override {
+ return available_imes_;
+ }
+
+ IMEInfo current_ime_;
+ std::vector<IMEInfo> available_imes_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestImeController);
+};
ImeMenuTray* GetTray() {
return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray();
}
+} // namespace
+
class ImeMenuTrayTest : public test::AshTestBase {
public:
ImeMenuTrayTest() {}
~ImeMenuTrayTest() override {}
+ // test::AshTestBase:
+ void SetUp() override {
+ test::AshTestBase::SetUp();
+ GetTray()->ime_controller_ = &test_ime_controller_;
+ }
+
protected:
// Returns true if the IME menu tray is visible.
bool IsVisible() { return GetTray()->visible(); }
@@ -50,13 +77,12 @@
// Returns true if the IME menu bubble has been shown.
bool IsBubbleShown() { return GetTray()->IsImeMenuBubbleShown(); }
- // Returns true if the IME menu list has been updated with the right IME list.
- bool IsTrayImeListValid(const std::vector<IMEInfo>& expected_imes,
+ // Verifies the IME menu list has been updated with the right IME list.
+ void ExpectValidImeList(const std::vector<IMEInfo>& expected_imes,
const IMEInfo& expected_current_ime) {
const std::map<views::View*, std::string>& ime_map =
ImeListViewTestApi(GetTray()->ime_list_view_).ime_map();
- if (ime_map.size() != expected_imes.size())
- return false;
+ EXPECT_EQ(expected_imes.size(), ime_map.size());
std::vector<std::string> expected_ime_ids;
for (const auto& ime : expected_imes) {
@@ -64,22 +90,16 @@
}
for (const auto& ime : ime_map) {
// Tests that all the IMEs on the view is in the list of selected IMEs.
- if (std::find(expected_ime_ids.begin(), expected_ime_ids.end(),
- ime.second) == expected_ime_ids.end()) {
- return false;
- }
+ EXPECT_TRUE(base::ContainsValue(expected_ime_ids, ime.second));
// Tests that the checked IME is the current IME.
ui::AXNodeData node_data;
ime.first->GetAccessibleNodeData(&node_data);
const auto checked_state = static_cast<ui::AXCheckedState>(
node_data.GetIntAttribute(ui::AX_ATTR_CHECKED_STATE));
- if (checked_state == ui::AX_CHECKED_STATE_TRUE) {
- if (ime.second != expected_current_ime.id)
- return false;
- }
+ if (checked_state == ui::AX_CHECKED_STATE_TRUE)
+ EXPECT_EQ(expected_current_ime.id, ime.second);
}
- return true;
}
// Focuses in the given type of input context.
@@ -89,7 +109,15 @@
ui::IMEBridge::Get()->SetCurrentInputContext(input_context);
}
+ void SetCurrentIme(IMEInfo ime) { test_ime_controller_.current_ime_ = ime; }
+
+ void SetAvailableImes(const std::vector<IMEInfo>& imes) {
+ test_ime_controller_.available_imes_ = imes;
+ }
+
private:
+ TestImeController test_ime_controller_;
+
DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest);
};
@@ -118,7 +146,7 @@
info1.short_name = UTF8ToUTF16("US");
info1.third_party = false;
info1.selected = true;
- GetSystemTrayDelegate()->SetCurrentIME(info1);
+ SetCurrentIme(info1);
Shell::Get()->system_tray_notifier()->NotifyRefreshIME();
EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
@@ -130,7 +158,7 @@
info2.short_name = UTF8ToUTF16("UK");
info2.third_party = true;
info2.selected = true;
- GetSystemTrayDelegate()->SetCurrentIME(info2);
+ SetCurrentIme(info2);
Shell::Get()->system_tray_notifier()->NotifyRefreshIME();
EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText());
}
@@ -206,19 +234,19 @@
std::vector<IMEInfo> ime_info_list{info1, info2, info3};
- GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list);
- GetSystemTrayDelegate()->SetCurrentIME(info1);
+ SetAvailableImes(ime_info_list);
+ SetCurrentIme(info1);
Shell::Get()->system_tray_notifier()->NotifyRefreshIME();
EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
- EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1));
+ ExpectValidImeList(ime_info_list, info1);
ime_info_list[0].selected = false;
ime_info_list[2].selected = true;
- GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list);
- GetSystemTrayDelegate()->SetCurrentIME(info3);
+ SetAvailableImes(ime_info_list);
+ SetCurrentIme(info3);
Shell::Get()->system_tray_notifier()->NotifyRefreshIME();
EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText());
- EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3));
+ ExpectValidImeList(ime_info_list, info3);
// Closes the menu before quitting.
GetTray()->PerformAction(tap);
diff --git a/ash/system/screen_layout_observer_unittest.cc b/ash/system/screen_layout_observer_unittest.cc
index 08e71ff..502fb39b 100644
--- a/ash/system/screen_layout_observer_unittest.cc
+++ b/ash/system/screen_layout_observer_unittest.cc
@@ -9,7 +9,6 @@
#include "ash/system/devicetype_utils.h"
#include "ash/system/tray/system_tray.h"
#include "ash/test/ash_test_base.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
diff --git a/ash/system/supervised/tray_supervised_user_unittest.cc b/ash/system/supervised/tray_supervised_user_unittest.cc
index 683df04..8faf755 100644
--- a/ash/system/supervised/tray_supervised_user_unittest.cc
+++ b/ash/system/supervised/tray_supervised_user_unittest.cc
@@ -12,7 +12,6 @@
#include "ash/system/tray/system_tray_test_api.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_session_controller_client.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/message_center/message_center.h"
diff --git a/ash/system/tray/system_tray_delegate.cc b/ash/system/tray/system_tray_delegate.cc
index 82c4ced6..c2d3b6e 100644
--- a/ash/system/tray/system_tray_delegate.cc
+++ b/ash/system/tray/system_tray_delegate.cc
@@ -4,8 +4,6 @@
#include "ash/system/tray/system_tray_delegate.h"
-#include "ash/system/tray/ime_info.h"
-
namespace ash {
SystemTrayDelegate::SystemTrayDelegate() = default;
@@ -16,16 +14,6 @@
void SystemTrayDelegate::ShowUserLogin() {}
-void SystemTrayDelegate::GetCurrentIME(IMEInfo* info) {}
-
-void SystemTrayDelegate::GetAvailableIMEList(IMEInfoList* list) {}
-
-void SystemTrayDelegate::GetCurrentIMEProperties(IMEPropertyInfoList* list) {}
-
-base::string16 SystemTrayDelegate::GetIMEManagedMessage() {
- return base::string16();
-}
-
NetworkingConfigDelegate* SystemTrayDelegate::GetNetworkingConfigDelegate()
const {
return nullptr;
diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h
index 81ba1b1..a363254 100644
--- a/ash/system/tray/system_tray_delegate.h
+++ b/ash/system/tray/system_tray_delegate.h
@@ -5,18 +5,9 @@
#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_DELEGATE_H_
#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_DELEGATE_H_
-#include <string>
-#include <vector>
-
#include "ash/ash_export.h"
-#include "base/strings/string16.h"
namespace ash {
-struct IMEInfo;
-struct IMEPropertyInfo;
-
-using IMEInfoList = std::vector<IMEInfo>;
-using IMEPropertyInfoList = std::vector<IMEPropertyInfo>;
class NetworkingConfigDelegate;
@@ -38,18 +29,6 @@
// Shows login UI to add other users to this session.
virtual void ShowUserLogin();
- // Returns the currently selected IME.
- virtual void GetCurrentIME(IMEInfo* info);
-
- // Returns a list of availble IMEs.
- virtual void GetAvailableIMEList(IMEInfoList* list);
-
- // Returns a list of properties for the currently selected IME.
- virtual void GetCurrentIMEProperties(IMEPropertyInfoList* list);
-
- // Returns a non-empty string if IMEs are managed by policy.
- virtual base::string16 GetIMEManagedMessage();
-
// Returns NetworkingConfigDelegate. May return nullptr.
virtual NetworkingConfigDelegate* GetNetworkingConfigDelegate() const;
diff --git a/ash/system/web_notification/web_notification_tray_unittest.cc b/ash/system/web_notification/web_notification_tray_unittest.cc
index 5f487d8c..5a5d7ca 100644
--- a/ash/system/web_notification/web_notification_tray_unittest.cc
+++ b/ash/system/web_notification/web_notification_tray_unittest.cc
@@ -19,7 +19,6 @@
#include "ash/system/web_notification/ash_popup_alignment_delegate.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/status_area_widget_test_helper.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/window_state.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
diff --git a/ash/test/BUILD.gn b/ash/test/BUILD.gn
index 41785fea3..d7e3f43 100644
--- a/ash/test/BUILD.gn
+++ b/ash/test/BUILD.gn
@@ -113,8 +113,6 @@
"test_session_state_animator.h",
"test_shell_delegate.cc",
"test_shell_delegate.h",
- "test_system_tray_delegate.cc",
- "test_system_tray_delegate.h",
"test_system_tray_item.cc",
"test_system_tray_item.h",
"test_wallpaper_delegate.cc",
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index ef6c1f1..5c556b9 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -25,7 +25,6 @@
#include "ash/test/ash_test_helper.h"
#include "ash/test/test_session_controller_client.h"
#include "ash/test/test_shell_delegate.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/window_positioner.h"
#include "services/ui/public/cpp/property_type_converters.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
@@ -413,11 +412,6 @@
return ash_test_helper_->test_session_controller_client();
}
-TestSystemTrayDelegate* AshTestBase::GetSystemTrayDelegate() {
- return static_cast<TestSystemTrayDelegate*>(
- Shell::Get()->system_tray_delegate());
-}
-
void AshTestBase::SetSessionStarted(bool session_started) {
if (session_started)
GetSessionControllerClient()->CreatePredefinedUserSessions(1);
diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h
index e078e46..c6f0f42 100644
--- a/ash/test/ash_test_base.h
+++ b/ash/test/ash_test_base.h
@@ -58,7 +58,6 @@
class AshTestHelper;
class TestScreenshotDelegate;
class TestSessionControllerClient;
-class TestSystemTrayDelegate;
class AshTestBase : public testing::Test {
public:
@@ -179,8 +178,6 @@
TestSessionControllerClient* GetSessionControllerClient();
- TestSystemTrayDelegate* GetSystemTrayDelegate();
-
// Utility methods to emulate user logged in or not, session started or not
// and user able to lock screen or not cases.
void SetSessionStarted(bool session_started);
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index f506bfcc..b5b6f5d 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -24,7 +24,6 @@
#include "ash/test/display_configuration_controller_test_api.h"
#include "ash/test/test_screenshot_delegate.h"
#include "ash/test/test_shell_delegate.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/strings/string_split.h"
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc
index 846c6e5..e010d9f 100644
--- a/ash/test/test_shell_delegate.cc
+++ b/ash/test/test_shell_delegate.cc
@@ -13,10 +13,10 @@
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/shell_observer.h"
+#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/test/test_accessibility_delegate.h"
#include "ash/test/test_keyboard_ui.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/test/test_wallpaper_delegate.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
@@ -102,7 +102,11 @@
void TestShellDelegate::ShelfShutdown() {}
SystemTrayDelegate* TestShellDelegate::CreateSystemTrayDelegate() {
- return new TestSystemTrayDelegate;
+ return new SystemTrayDelegate;
+}
+
+ImeController* TestShellDelegate::GetImeController() {
+ return &stub_ime_controller_;
}
std::unique_ptr<WallpaperDelegate>
diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h
index a5a0467..84e1131 100644
--- a/ash/test/test_shell_delegate.h
+++ b/ash/test/test_shell_delegate.h
@@ -8,6 +8,7 @@
#include <memory>
#include <string>
+#include "ash/ime/ime_controller.h"
#include "ash/shell_delegate.h"
#include "base/macros.h"
@@ -50,6 +51,7 @@
void ShelfShutdown() override;
void OpenUrlFromArc(const GURL& url) override;
SystemTrayDelegate* CreateSystemTrayDelegate() override;
+ ImeController* GetImeController() override;
std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() override;
@@ -80,6 +82,7 @@
bool touchscreen_enabled_in_local_pref_ = true;
bool media_sessions_suspended_ = false;
std::unique_ptr<ShelfInitializer> shelf_initializer_;
+ ImeController stub_ime_controller_;
PrefService* active_user_pref_service_ = nullptr; // Not owned.
DISALLOW_COPY_AND_ASSIGN(TestShellDelegate);
diff --git a/ash/test/test_system_tray_delegate.cc b/ash/test/test_system_tray_delegate.cc
deleted file mode 100644
index f14d374e9f..0000000
--- a/ash/test/test_system_tray_delegate.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2013 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/test/test_system_tray_delegate.h"
-
-namespace ash {
-namespace test {
-
-TestSystemTrayDelegate::TestSystemTrayDelegate() = default;
-
-TestSystemTrayDelegate::~TestSystemTrayDelegate() = default;
-
-void TestSystemTrayDelegate::SetCurrentIME(const IMEInfo& info) {
- current_ime_ = info;
-}
-
-void TestSystemTrayDelegate::SetAvailableIMEList(const IMEInfoList& list) {
- ime_list_ = list;
-}
-
-void TestSystemTrayDelegate::GetCurrentIME(IMEInfo* info) {
- *info = current_ime_;
-}
-
-void TestSystemTrayDelegate::GetAvailableIMEList(IMEInfoList* list) {
- *list = ime_list_;
-}
-
-} // namespace test
-} // namespace ash
diff --git a/ash/test/test_system_tray_delegate.h b/ash/test/test_system_tray_delegate.h
deleted file mode 100644
index 38548c0..0000000
--- a/ash/test/test_system_tray_delegate.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2013 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.
-
-#ifndef ASH_TEST_TEST_SYSTEM_TRAY_DELEGATE_H_
-#define ASH_TEST_TEST_SYSTEM_TRAY_DELEGATE_H_
-
-#include "ash/system/tray/ime_info.h"
-#include "ash/system/tray/system_tray_delegate.h"
-#include "base/macros.h"
-
-namespace ash {
-namespace test {
-
-class TestSystemTrayDelegate : public SystemTrayDelegate {
- public:
- TestSystemTrayDelegate();
- ~TestSystemTrayDelegate() override;
-
- // Sets the IME info.
- void SetCurrentIME(const IMEInfo& info);
-
- // Sets the list of available IMEs.
- void SetAvailableIMEList(const IMEInfoList& list);
-
- // SystemTrayDelegate:
- void GetCurrentIME(IMEInfo* info) override;
- void GetAvailableIMEList(IMEInfoList* list) override;
-
- private:
- IMEInfo current_ime_;
- IMEInfoList ime_list_;
-
- DISALLOW_COPY_AND_ASSIGN(TestSystemTrayDelegate);
-};
-
-} // namespace test
-} // namespace ash
-
-#endif // ASH_TEST_TEST_SYSTEM_TRAY_DELEGATE_H_
diff --git a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
index cf6bb66..4b813e4f 100644
--- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
+++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
@@ -13,7 +13,6 @@
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/test/ash_test_base.h"
-#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "base/command_line.h"
#include "base/run_loop.h"
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
index 059746f..703e114 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
@@ -12,7 +12,9 @@
#include <sstream>
#include <utility>
+#include "ash/ime/ime_controller.h"
#include "ash/shell.h"
+#include "ash/system/tray/ime_info.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/hash.h"
@@ -21,6 +23,7 @@
#include "base/metrics/sparse_histogram.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
@@ -52,6 +55,19 @@
namespace {
+InputMethodManagerImpl* g_instance = nullptr;
+
+ash::IMEInfo GetAshImeInfo(const InputMethodDescriptor& ime,
+ const InputMethodUtil& util) {
+ ash::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 = extension_ime_util::IsExtensionIME(ime.id());
+ return info;
+}
+
bool Contains(const std::vector<std::string>& container,
const std::string& value) {
return std::find(container.begin(), container.end(), value) !=
@@ -939,14 +955,25 @@
component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
util_.ResetInputMethods(descriptors);
chromeos::UserAddingScreen::Get()->AddObserver(this);
+
+ DCHECK(!g_instance);
+ g_instance = this;
}
InputMethodManagerImpl::~InputMethodManagerImpl() {
+ DCHECK_EQ(g_instance, this);
+ g_instance = nullptr;
+
if (candidate_window_controller_.get())
candidate_window_controller_->RemoveObserver(this);
chromeos::UserAddingScreen::Get()->RemoveObserver(this);
}
+// static
+InputMethodManagerImpl* InputMethodManagerImpl::Get() {
+ return g_instance;
+}
+
void InputMethodManagerImpl::RecordInputMethodUsage(
const std::string& input_method_id) {
UMA_HISTOGRAM_ENUMERATION("InputMethod.Category",
@@ -1335,5 +1362,55 @@
return base::FeatureList::IsEnabled(features::kEHVInputOnImeMenu);
}
+ash::IMEInfo InputMethodManagerImpl::GetCurrentIme() const {
+ if (!state_)
+ return ash::IMEInfo();
+
+ InputMethodDescriptor ime = state_->GetCurrentInputMethod();
+ ash::IMEInfo info = GetAshImeInfo(ime, util_);
+ info.selected = true;
+ return info;
+}
+
+std::vector<ash::IMEPropertyInfo>
+InputMethodManagerImpl::GetCurrentImeProperties() const {
+ std::vector<ash::IMEPropertyInfo> properties;
+ ui::ime::InputMethodMenuItemList menu_list =
+ ui::ime::InputMethodMenuManager::GetInstance()
+ ->GetCurrentInputMethodMenuItemList();
+ for (size_t i = 0; i < menu_list.size(); ++i) {
+ ash::IMEPropertyInfo property;
+ property.key = menu_list[i].key;
+ property.name = base::UTF8ToUTF16(menu_list[i].label);
+ property.selected = menu_list[i].is_selection_item_checked;
+ properties.push_back(property);
+ }
+ return properties;
+}
+
+std::vector<ash::IMEInfo> InputMethodManagerImpl::GetAvailableImes() const {
+ if (!state_)
+ return std::vector<ash::IMEInfo>();
+
+ std::vector<ash::IMEInfo> imes;
+ std::string current_ime_id = state_->GetCurrentInputMethod().id();
+ std::unique_ptr<InputMethodDescriptors> descriptors =
+ state_->GetActiveInputMethods();
+ for (const InputMethodDescriptor& descriptor : *descriptors) {
+ ash::IMEInfo info = GetAshImeInfo(descriptor, util_);
+ info.selected = descriptor.id() == current_ime_id;
+ imes.push_back(info);
+ }
+ return imes;
+}
+
+bool InputMethodManagerImpl::IsImeManaged() const {
+ if (!state_)
+ return false;
+
+ // Having a non-empty "allowed" list indicates that IMEs are managed.
+ return !state_->GetAllowedInputMethods().empty();
+}
+
} // namespace input_method
} // namespace chromeos
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
index dfd8fdc4..a3ba164 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
@@ -12,6 +12,7 @@
#include <string>
#include <vector>
+#include "ash/ime/ime_controller.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
@@ -35,7 +36,9 @@
class ImeKeyboard;
// The implementation of InputMethodManager.
+// TODO(jamescook): Replace ash::ImeController with mojo interface.
class InputMethodManagerImpl : public InputMethodManager,
+ public ash::ImeController,
public CandidateWindowController::Observer,
public UserAddingScreen::Observer {
public:
@@ -164,6 +167,8 @@
bool enable_extension_loading);
~InputMethodManagerImpl() override;
+ static InputMethodManagerImpl* Get();
+
// Receives notification of an InputMethodManager::UISessionState transition.
void SetUISessionState(UISessionState new_ui_session);
@@ -191,6 +196,12 @@
void OverrideKeyboardUrlRef(const std::string& keyset) override;
bool IsEmojiHandwritingVoiceOnImeMenuEnabled() override;
+ // ash::ImeController:
+ ash::IMEInfo GetCurrentIme() const override;
+ std::vector<ash::IMEPropertyInfo> GetCurrentImeProperties() const override;
+ std::vector<ash::IMEInfo> GetAvailableImes() const override;
+ bool IsImeManaged() const override;
+
// chromeos::UserAddingScreen:
void OnUserAddingStarted() override;
void OnUserAddingFinished() override;
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc
index 9aa1fd61..616f3cf 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc
@@ -32,6 +32,7 @@
#include "chrome/browser/chromeos/background/ash_wallpaper_delegate.h"
#include "chrome/browser/chromeos/display/display_configuration_observer.h"
#include "chrome/browser/chromeos/display/display_preferences.h"
+#include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
#include "chrome/browser/chromeos/policy/display_rotation_default_handler.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
@@ -613,6 +614,10 @@
return chromeos::CreateSystemTrayDelegate();
}
+ash::ImeController* ChromeShellDelegate::GetImeController() {
+ return chromeos::input_method::InputMethodManagerImpl::Get();
+}
+
std::unique_ptr<ash::WallpaperDelegate>
ChromeShellDelegate::CreateWallpaperDelegate() {
return base::WrapUnique(chromeos::CreateWallpaperDelegate());
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.h b/chrome/browser/ui/ash/chrome_shell_delegate.h
index 1002ad8..34d5717 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate.h
+++ b/chrome/browser/ui/ash/chrome_shell_delegate.h
@@ -45,6 +45,7 @@
void ShelfInit() override;
void ShelfShutdown() override;
ash::SystemTrayDelegate* CreateSystemTrayDelegate() override;
+ ash::ImeController* GetImeController() override;
std::unique_ptr<ash::WallpaperDelegate> CreateWallpaperDelegate() override;
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
std::unique_ptr<ash::PaletteDelegate> CreatePaletteDelegate() override;
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
index 67648c4c..7e207451 100644
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
@@ -17,7 +17,6 @@
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/system/date/clock_observer.h"
-#include "ash/system/ime/ime_observer.h"
#include "ash/system/power/power_status.h"
#include "ash/system/session/logout_button_observer.h"
#include "ash/system/tray/system_tray_notifier.h"
@@ -56,29 +55,14 @@
#include "components/user_manager/user_type.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
-#include "ui/base/ime/chromeos/extension_ime_util.h"
-#include "ui/base/ime/chromeos/input_method_manager.h"
-#include "ui/base/ime/chromeos/input_method_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/chromeos/events/pref_names.h"
-#include "ui/chromeos/ime/input_method_menu_item.h"
-#include "ui/chromeos/ime/input_method_menu_manager.h"
namespace chromeos {
namespace {
-void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
- const input_method::InputMethodUtil& util,
- ash::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 = extension_ime_util::IsExtensionIME(ime.id());
-}
-
void OnAcceptMultiprofilesIntro(bool no_show_again) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again);
@@ -181,54 +165,6 @@
}
}
-void SystemTrayDelegateChromeOS::GetCurrentIME(ash::IMEInfo* info) {
- input_method::InputMethodManager* manager =
- input_method::InputMethodManager::Get();
- input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
- input_method::InputMethodDescriptor ime =
- manager->GetActiveIMEState()->GetCurrentInputMethod();
- ExtractIMEInfo(ime, *util, info);
- info->selected = true;
-}
-
-void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList* list) {
- input_method::InputMethodManager* manager =
- input_method::InputMethodManager::Get();
- input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
- std::unique_ptr<input_method::InputMethodDescriptors> ime_descriptors(
- manager->GetActiveIMEState()->GetActiveInputMethods());
- std::string current =
- manager->GetActiveIMEState()->GetCurrentInputMethod().id();
- for (size_t i = 0; i < ime_descriptors->size(); i++) {
- input_method::InputMethodDescriptor& ime = ime_descriptors->at(i);
- ash::IMEInfo info;
- ExtractIMEInfo(ime, *util, &info);
- info.selected = ime.id() == current;
- list->push_back(info);
- }
-}
-
-void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
- ash::IMEPropertyInfoList* list) {
- ui::ime::InputMethodMenuItemList menu_list =
- ui::ime::InputMethodMenuManager::GetInstance()->
- GetCurrentInputMethodMenuItemList();
- for (size_t i = 0; i < menu_list.size(); ++i) {
- ash::IMEPropertyInfo property;
- property.key = menu_list[i].key;
- property.name = base::UTF8ToUTF16(menu_list[i].label);
- property.selected = menu_list[i].is_selection_item_checked;
- list->push_back(property);
- }
-}
-
-base::string16 SystemTrayDelegateChromeOS::GetIMEManagedMessage() {
- auto ime_state = input_method::InputMethodManager::Get()->GetActiveIMEState();
- return ime_state->GetAllowedInputMethods().empty()
- ? base::string16()
- : l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY);
-}
-
ash::NetworkingConfigDelegate*
SystemTrayDelegateChromeOS::GetNetworkingConfigDelegate() const {
return networking_config_delegate_.get();
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h
index a7d6a9b..2e267bd 100644
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h
@@ -12,7 +12,6 @@
#include <vector>
#include "ash/accessibility_types.h"
-#include "ash/system/tray/ime_info.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "base/macros.h"
#include "base/observer_list.h"
@@ -48,10 +47,6 @@
// Overridden from ash::SystemTrayDelegate:
void Initialize() override;
void ShowUserLogin() override;
- void GetCurrentIME(ash::IMEInfo* info) override;
- void GetAvailableIMEList(ash::IMEInfoList* list) override;
- void GetCurrentIMEProperties(ash::IMEPropertyInfoList* list) override;
- base::string16 GetIMEManagedMessage() override;
ash::NetworkingConfigDelegate* GetNetworkingConfigDelegate() const override;
void ActiveUserWasChanged() override;
bool IsSearchKeyMappedToCapsLock() override;