Commit 5ade0d0b authored by uekawa@chromium.org's avatar uekawa@chromium.org

Reland of: Split out InputMethodMenuManager from InputMethodManager.

Rename input_method_property to input_method_menu_item, and move to ash/ime.

This is a reland of https://codereview.chromium.org/150203015,reverted by https://codereview.chromium.org/165453002

Use Singleton<> instead of trying to maintain my own singleton.

BUG=342336, 343044

Review URL: https://codereview.chromium.org/165783002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251327 0039d316-1c4b-4281-b951-d872f2087c98
parent 649ee534
......@@ -167,6 +167,10 @@
'ime/candidate_window_view.h',
'ime/infolist_window.cc',
'ime/infolist_window.h',
'ime/input_method_menu_item.cc',
'ime/input_method_menu_item.h',
'ime/input_method_menu_manager.cc',
'ime/input_method_menu_manager.h',
'ime/mode_indicator_view.cc',
'ime/mode_indicator_view.h',
'keyboard_uma_event_filter.cc',
......@@ -849,6 +853,8 @@
'extended_desktop_unittest.cc',
'focus_cycler_unittest.cc',
'ime/candidate_window_view_unittest.cc',
'ime/input_method_menu_item_unittest.cc',
'ime/input_method_menu_manager_unittest.cc',
'keyboard_overlay/keyboard_overlay_delegate_unittest.cc',
'keyboard_overlay/keyboard_overlay_view_unittest.cc',
'magnifier/magnification_controller_unittest.cc',
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 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 "chromeos/ime/input_method_property.h"
#include "ash/ime/input_method_menu_item.h"
#include <sstream>
#include "base/logging.h"
namespace chromeos {
namespace input_method {
namespace ash {
namespace ime {
InputMethodProperty::InputMethodProperty(const std::string& in_key,
InputMethodMenuItem::InputMethodMenuItem(const std::string& in_key,
const std::string& in_label,
bool in_is_selection_item,
bool in_is_selection_item_checked)
......@@ -22,26 +22,26 @@ InputMethodProperty::InputMethodProperty(const std::string& in_key,
DCHECK(!key.empty());
}
InputMethodProperty::InputMethodProperty()
InputMethodMenuItem::InputMethodMenuItem()
: is_selection_item(false),
is_selection_item_checked(false) {
}
InputMethodProperty::~InputMethodProperty() {
InputMethodMenuItem::~InputMethodMenuItem() {
}
bool InputMethodProperty::operator==(const InputMethodProperty& other) const {
bool InputMethodMenuItem::operator==(const InputMethodMenuItem& other) const {
return key == other.key &&
label == other.label &&
is_selection_item == other.is_selection_item &&
is_selection_item_checked == other.is_selection_item_checked;
}
bool InputMethodProperty::operator!=(const InputMethodProperty& other) const {
bool InputMethodMenuItem::operator!=(const InputMethodMenuItem& other) const {
return !(*this == other);
}
std::string InputMethodProperty::ToString() const {
std::string InputMethodMenuItem::ToString() const {
std::stringstream stream;
stream << "key=" << key
<< ", label=" << label
......@@ -50,5 +50,5 @@ std::string InputMethodProperty::ToString() const {
return stream.str();
}
} // namespace input_method
} // namespace chromeos
} // namespace ime
} // namespace ash
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 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 CHROMEOS_IME_INPUT_METHOD_PROPERTY_H_
#define CHROMEOS_IME_INPUT_METHOD_PROPERTY_H_
#ifndef ASH_IME_INPUT_METHOD_MENU_ITEM_H_
#define ASH_IME_INPUT_METHOD_MENU_ITEM_H_
#include <string>
#include <vector>
#include "chromeos/chromeos_export.h"
#include "ash/ash_export.h"
namespace chromeos {
namespace input_method {
namespace ash {
namespace ime {
// A structure which represents a property for an input method engine.
struct CHROMEOS_EXPORT InputMethodProperty {
InputMethodProperty(const std::string& in_key,
struct ASH_EXPORT InputMethodMenuItem {
InputMethodMenuItem(const std::string& in_key,
const std::string& in_label,
bool in_is_selection_item,
bool in_is_selection_item_checked);
InputMethodProperty();
~InputMethodProperty();
InputMethodMenuItem();
~InputMethodMenuItem();
bool operator==(const InputMethodProperty& other) const;
bool operator!=(const InputMethodProperty& other) const;
bool operator==(const InputMethodMenuItem& other) const;
bool operator!=(const InputMethodMenuItem& other) const;
// Debug print function.
std::string ToString() const;
......@@ -36,9 +36,9 @@ struct CHROMEOS_EXPORT InputMethodProperty {
bool is_selection_item_checked; // true if |is_selection_item| is true and
// the selection_item is selected.
};
typedef std::vector<InputMethodProperty> InputMethodPropertyList;
typedef std::vector<InputMethodMenuItem> InputMethodMenuItemList;
} // namespace input_method
} // namespace chromeos
} // namespace ime
} // namespace ash
#endif // CHROMEOS_IME_INPUT_METHOD_PROPERTY_H_
#endif // ASH_IME_INPUT_METHOD_MENU_ITEM_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 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/input_method_menu_item.h"
#include "base/logging.h"
#include "chromeos/ime/input_method_property.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace input_method {
namespace ash {
namespace ime {
TEST(InputMethodPropertyTest, TestOperatorEqual) {
InputMethodProperty empty;
InputMethodProperty reference("key", "label", true, true);
TEST(InputMethodMenuItemTest, TestOperatorEqual) {
InputMethodMenuItem empty;
InputMethodMenuItem reference("key", "label", true, true);
InputMethodProperty p1("X", "label", true, true);
InputMethodProperty p2("key", "X", true, true);
InputMethodProperty p3("key", "label", false, true);
InputMethodProperty p4("key", "label", true, false);
InputMethodMenuItem p1("X", "label", true, true);
InputMethodMenuItem p2("key", "X", true, true);
InputMethodMenuItem p3("key", "label", false, true);
InputMethodMenuItem p4("key", "label", true, false);
EXPECT_EQ(empty, empty);
EXPECT_EQ(reference, reference);
......@@ -27,5 +28,5 @@ TEST(InputMethodPropertyTest, TestOperatorEqual) {
EXPECT_NE(reference, p4);
}
} // namespace input_method
} // namespace chromeos
} // namespace ime
} // namespace ash
// Copyright 2014 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/input_method_menu_manager.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
namespace ash {
namespace ime {
InputMethodMenuManager::InputMethodMenuManager()
: menu_list_(), observers_() {}
InputMethodMenuManager::~InputMethodMenuManager() {}
void InputMethodMenuManager::AddObserver(
InputMethodMenuManager::Observer* observer) {
observers_.AddObserver(observer);
}
void InputMethodMenuManager::RemoveObserver(
InputMethodMenuManager::Observer* observer) {
observers_.RemoveObserver(observer);
}
InputMethodMenuItemList
InputMethodMenuManager::GetCurrentInputMethodMenuItemList() const {
return menu_list_;
}
void InputMethodMenuManager::SetCurrentInputMethodMenuItemList(
const InputMethodMenuItemList& menu_list) {
menu_list_ = menu_list;
FOR_EACH_OBSERVER(InputMethodMenuManager::Observer,
observers_,
InputMethodMenuItemChanged(this));
}
bool InputMethodMenuManager::HasInputMethodMenuItemForKey(
const std::string& key) const {
for (size_t i = 0; i < menu_list_.size(); ++i) {
if (menu_list_[i].key == key) {
return true;
}
}
return false;
}
// static
InputMethodMenuManager* InputMethodMenuManager::GetInstance() {
return Singleton<InputMethodMenuManager>::get();
}
} // namespace ime
} // namespace ash
// Copyright 2014 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/ash_export.h"
#include "ash/ime/input_method_menu_item.h"
#include "base/observer_list.h"
#ifndef ASH_IME_INPUT_METHOD_MENU_MANAGER_H_
#define ASH_IME_INPUT_METHOD_MENU_MANAGER_H_
template<typename Type> struct DefaultSingletonTraits;
namespace ash {
namespace ime {
class ASH_EXPORT InputMethodMenuManager {
public:
class Observer {
public:
virtual ~Observer() {}
// Called when the list of menu items is changed.
virtual void InputMethodMenuItemChanged(
InputMethodMenuManager* manager) = 0;
};
~InputMethodMenuManager();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// Obtains the singleton instance.
static InputMethodMenuManager* GetInstance();
// Sets the list of input method menu items. The list could be empty().
void SetCurrentInputMethodMenuItemList(
const InputMethodMenuItemList& menu_list);
// Gets the list of input method menu items. The list could be empty().
InputMethodMenuItemList GetCurrentInputMethodMenuItemList() const;
// True if the key exists in the menu_list_.
bool HasInputMethodMenuItemForKey(const std::string& key) const;
private:
InputMethodMenuManager();
// For Singleton to be able to construct an instance.
friend struct DefaultSingletonTraits<InputMethodMenuManager>;
// Menu item list of the input method. This is set by extension IMEs.
InputMethodMenuItemList menu_list_;
// Observers who will be notified when menu changes.
ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(InputMethodMenuManager);
};
} // namespace ime
} // namespace ash
#endif // ASH_IME_INPUT_METHOD_MENU_MANAGER_H_
// Copyright 2014 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/input_method_menu_manager.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash {
namespace ime {
TEST(InputMethodMenuManagerTest, TestGetSingleton) {
EXPECT_TRUE(InputMethodMenuManager::GetInstance());
}
class MockObserver : public InputMethodMenuManager::Observer {
public:
MockObserver() : input_method_menu_item_changed_count_(0) {}
virtual ~MockObserver() {}
// Called when the list of menu items is changed.
virtual void InputMethodMenuItemChanged(
InputMethodMenuManager* manager) OVERRIDE {
input_method_menu_item_changed_count_++;
}
int input_method_menu_item_changed_count_;
};
class InputMethodMenuManagerStatefulTest : public testing::Test{
public:
InputMethodMenuManagerStatefulTest()
: observer_(new MockObserver()) {}
virtual ~InputMethodMenuManagerStatefulTest() {}
virtual void SetUp() OVERRIDE {
menu_manager_ = InputMethodMenuManager::GetInstance();
menu_manager_->AddObserver(observer_.get());
}
virtual void TearDown() OVERRIDE {
menu_manager_->RemoveObserver(observer_.get());
}
InputMethodMenuManager* menu_manager_;
scoped_ptr<MockObserver> observer_;
};
TEST_F(InputMethodMenuManagerStatefulTest, AddAndObserve) {
EXPECT_EQ(observer_->input_method_menu_item_changed_count_, 0);
menu_manager_->SetCurrentInputMethodMenuItemList(InputMethodMenuItemList());
EXPECT_EQ(observer_->input_method_menu_item_changed_count_, 1);
}
TEST_F(InputMethodMenuManagerStatefulTest, AddAndCheckExists) {
InputMethodMenuItemList list;
list.push_back(InputMethodMenuItem("key1", "label1", false, false));
list.push_back(InputMethodMenuItem("key2", "label2", false, false));
menu_manager_->SetCurrentInputMethodMenuItemList(list);
EXPECT_EQ(menu_manager_->GetCurrentInputMethodMenuItemList().size(), 2U);
EXPECT_EQ(
menu_manager_->GetCurrentInputMethodMenuItemList().at(0).ToString(),
"key=key1, label=label1, "
"is_selection_item=0, is_selection_item_checked=0");
EXPECT_EQ(
menu_manager_->GetCurrentInputMethodMenuItemList().at(1).ToString(),
"key=key2, label=label2, "
"is_selection_item=0, is_selection_item_checked=0");
EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key1"));
EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key2"));
EXPECT_FALSE(menu_manager_->HasInputMethodMenuItemForKey("key-not-exist"));
}
} // namespace ime
} // namespace ash
......@@ -28,8 +28,6 @@ class ExtensionInputMethodEventRouter
virtual void InputMethodChanged(
input_method::InputMethodManager* manager,
bool show_message) OVERRIDE;
virtual void InputMethodPropertyChanged(
input_method::InputMethodManager* manager) OVERRIDE {}
private:
content::BrowserContext* context_;
......
......@@ -54,9 +54,5 @@ void Accessibility::InputMethodChanged(InputMethodManager* imm,
ui::AccessibilityTypes::EVENT_ALERT, &event);
}
void Accessibility::InputMethodPropertyChanged(InputMethodManager* imm) {
// Do nothing.
}
} // namespace input_method
} // namespace chromeos
......@@ -21,8 +21,6 @@ class Accessibility
// InputMethodManager::Observer implementation.
virtual void InputMethodChanged(InputMethodManager* imm,
bool show_message) OVERRIDE;
virtual void InputMethodPropertyChanged(InputMethodManager* imm) OVERRIDE;
InputMethodManager* imm_;
DISALLOW_COPY_AND_ASSIGN(Accessibility);
......
......@@ -14,6 +14,8 @@
#undef RootWindow
#include <map>
#include "ash/ime/input_method_menu_item.h"
#include "ash/ime/input_method_menu_manager.h"
#include "ash/shell.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
......@@ -371,19 +373,17 @@ bool InputMethodEngine::UpdateMenuItems(
if (!active_)
return false;
input_method::InputMethodPropertyList property_list;
ash::ime::InputMethodMenuItemList menu_item_list;
for (std::vector<MenuItem>::const_iterator item = items.begin();
item != items.end(); ++item) {
input_method::InputMethodProperty property;
ash::ime::InputMethodMenuItem property;
MenuItemToProperty(*item, &property);
property_list.push_back(property);
menu_item_list.push_back(property);
}
input_method::InputMethodManager* manager =
input_method::InputMethodManager::Get();
if (manager)
manager->SetCurrentInputMethodProperties(property_list);
ash::ime::InputMethodMenuManager::GetInstance()->
SetCurrentInputMethodMenuItemList(
menu_item_list);
return true;
}
......@@ -583,9 +583,10 @@ void InputMethodEngine::SetSurroundingText(const std::string& text,
static_cast<int>(anchor_pos));
}
// TODO(uekawa): rename this method to a more reasonable name.
void InputMethodEngine::MenuItemToProperty(
const MenuItem& item,
input_method::InputMethodProperty* property) {
ash::ime::InputMethodMenuItem* property) {
property->key = item.id;
if (item.modified & MENU_ITEM_MODIFIED_LABEL) {
......
......@@ -17,12 +17,17 @@ class CandidateWindow;
class KeyEvent;
} // namespace ui
namespace ash {
namespace ime {
struct InputMethodMenuItem;
} // namespace ime
} // namespace ash
namespace chromeos {
class CompositionText;
namespace input_method {
struct InputMethodProperty;
struct KeyEventHandle;
} // namespace input_method
......@@ -95,9 +100,9 @@ class InputMethodEngine : public InputMethodEngineInterface {
virtual void HideInputView() OVERRIDE;
private:
// Converts MenuItem to InputMethodProperty.
// Converts MenuItem to InputMethodMenuItem.
void MenuItemToProperty(const MenuItem& item,
input_method::InputMethodProperty* property);
ash::ime::InputMethodMenuItem* property);
// Descriptor of this input method.
input_method::InputMethodDescriptor descriptor_;
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/ime/input_method_menu_item.h"
#include "ash/ime/input_method_menu_manager.h"
#include "base/bind_helpers.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_browsertest.h"
......@@ -795,8 +797,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineIBusBrowserTest,
ASSERT_TRUE(content::ExecuteScript(
host->host_contents(), set_menu_item_test_script));
const InputMethodPropertyList& props =
InputMethodManager::Get()->GetCurrentInputMethodProperties();
const ash::ime::InputMethodMenuItemList& props =
ash::ime::InputMethodMenuManager::GetInstance()->
GetCurrentInputMethodMenuItemList();
ASSERT_EQ(5U, props.size());
EXPECT_EQ("ID0", props[0].key);
......
......@@ -6,6 +6,8 @@
#include <algorithm> // std::find
#include "ash/ime/input_method_menu_item.h"
#include "ash/ime/input_method_menu_manager.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/location.h"
......@@ -350,8 +352,11 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
// extension IMEs via InputMethodEngine::(Set|Update)MenuItems.
// If the current input method is a keyboard layout, empty
// properties are sufficient.
const InputMethodPropertyList empty_property_list;
SetCurrentInputMethodProperties(empty_property_list);
const ash::ime::InputMethodMenuItemList empty_menu_item_list;
ash::ime::InputMethodMenuManager* input_method_menu_manager =
ash::ime::InputMethodMenuManager::GetInstance();
input_method_menu_manager->SetCurrentInputMethodMenuItemList(
empty_menu_item_list);
const InputMethodDescriptor* descriptor = NULL;
if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) {
......@@ -419,21 +424,20 @@ void InputMethodManagerImpl::LoadNecessaryComponentExtensions() {
}
}
void InputMethodManagerImpl::ActivateInputMethodProperty(
void InputMethodManagerImpl::ActivateInputMethodMenuItem(
const std::string& key) {
DCHECK(!key.empty());
for (size_t i = 0; i < property_list_.size(); ++i) {
if (property_list_[i].key == key) {
IMEEngineHandlerInterface* engine =
IMEBridge::Get()->GetCurrentEngineHandler();
if (engine)
engine->PropertyActivate(key);
return;
}
if (ash::ime::InputMethodMenuManager::GetInstance()->
HasInputMethodMenuItemForKey(key)) {
IMEEngineHandlerInterface* engine =
IMEBridge::Get()->GetCurrentEngineHandler();
if (engine)
engine->PropertyActivate(key);
return;
}
DVLOG(1) << "ActivateInputMethodProperty: unknown key: " << key;
DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key;
}
void InputMethodManagerImpl::AddInputMethodExtension(
......@@ -687,21 +691,6 @@ InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const {
return current_input_method_;
}
InputMethodPropertyList
InputMethodManagerImpl::GetCurrentInputMethodProperties() const {
// This check is necessary since an IME property (e.g. for Pinyin) might be
// sent from ibus-daemon AFTER the current input method is switched to XKB.
if (InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id()))
return InputMethodPropertyList(); // Empty list.
return property_list_;
}
void InputMethodManagerImpl::SetCurrentInputMethodProperties(
const InputMethodPropertyList& property_list) {
property_list_ = property_list;
PropertyChanged();
}
XKeyboard* InputMethodManagerImpl::GetXKeyboard() {
return xkeyboard_.get();
}
......@@ -757,12 +746,6 @@ void InputMethodManagerImpl::InitializeComponentExtensionForTesting(
OnComponentExtensionInitialized(delegate.Pass());
}
void InputMethodManagerImpl::PropertyChanged() {
FOR_EACH_OBSERVER(InputMethodManager::Observer,
observers_,
InputMethodPropertyChanged(this));
}
void InputMethodManagerImpl::CandidateClicked(int index) {
IMEEngineHandlerInterface* engine =
IMEBridge::Get()->GetCurrentEngineHandler();
......
......@@ -66,7 +66,7 @@ class InputMethodManagerImpl : public InputMethodManager,
virtual bool EnableInputMethod(const std::string& new_active_input_method_id)
OVERRIDE;
virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
virtual void ActivateInputMethodProperty(const std::string& key) OVERRIDE;
virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
virtual void AddInputMethodExtension(
const std::string& id,
InputMethodEngineInterface* instance) OVERRIDE;
......@@ -80,10 +80,6 @@ class InputMethodManagerImpl : public InputMethodManager,
const ui::Accelerator& accelerator) OVERRIDE;
virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
virtual InputMethodPropertyList
GetCurrentInputMethodProperties() const OVERRIDE;
virtual void SetCurrentInputMethodProperties(
const InputMethodPropertyList& property_list) OVERRIDE;
virtual XKeyboard* GetXKeyboard() OVERRIDE;
virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE;
......@@ -101,9 +97,6 @@ class InputMethodManagerImpl : public InputMethodManager,
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
private:
// Notifies observers that the property list is updated.
void PropertyChanged();
// CandidateWindowController::Observer overrides:
virtual void CandidateClicked(int index) OVERRIDE;
virtual void CandidateWindowOpened() OVERRIDE;
......@@ -189,9 +182,6 @@ class InputMethodManagerImpl : public InputMethodManager,
// those created by extension.
std::map<std::string, InputMethodDescriptor> extra_input_methods_;
// Property list of the input method. This is set by extension IMEs.
InputMethodPropertyList property_list_;
// The candidate window. This will be deleted when the APP_TERMINATING
// message is sent.
scoped_ptr<CandidateWindowController> candidate_window_controller_;
......
......@@ -6,6 +6,8 @@
#include <algorithm>
#include "ash/ime/input_method_menu_item.h"
#include "ash/ime/input_method_menu_manager.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
......@@ -71,6 +73,8 @@ class InputMethodManagerImplTest : public testing::Test {
IMEBridge::Initialize();
IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get());
menu_manager_ = ash::ime::InputMethodMenuManager::GetInstance();
ime_list_.clear();
ComponentExtensionIME ext1;
......@@ -121,6 +125,7 @@ class InputMethodManagerImplTest : public testing::Test {
candidate_window_controller_ = NULL;
xkeyboard_ = NULL;
manager_.reset();
IMEBridge::Get()->SetCurrentEngineHandler(NULL);
IMEBridge::Shutdown();
}
......@@ -153,16 +158,18 @@ class InputMethodManagerImplTest : public testing::Test {
base::MessageLoop message_loop_;
MockComponentExtIMEManagerDelegate* mock_delegate_;
std::vector<ComponentExtensionIME> ime_list_;
ash::ime::InputMethodMenuManager* menu_manager_;
private:
DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest);
};
class TestObserver : public InputMethodManager::Observer {
class TestObserver : public InputMethodManager::Observer,
public ash::ime::InputMethodMenuManager::Observer{
public:
TestObserver()
: input_method_changed_count_(0),
input_method_property_changed_count_(0),
input_method_menu_item_changed_count_(0),
last_show_message_(false) {
}
virtual ~TestObserver() {}
......@@ -172,13 +179,13 @@ class TestObserver : public InputMethodManager::Observer {
++input_method_changed_count_;
last_show_message_ = show_message;
}
virtual void InputMethodPropertyChanged(
InputMethodManager* manager) OVERRIDE {
++input_method_property_changed_count_;
virtual void InputMethodMenuItemChanged(
ash::ime::InputMethodMenuManager* manager) OVERRIDE {
++input_method_menu_item_changed_count_;
}
int input_method_changed_count_;
int input_method_property_changed_count_;
int input_method_menu_item_changed_count_;
bool last_show_message_;
private:
......@@ -236,14 +243,15 @@ TEST_F(InputMethodManagerImplTest, TestObserver) {
TestObserver observer;
InitComponentExtension();
manager_->AddObserver(&observer);
menu_manager_->AddObserver(&observer);
EXPECT_EQ(0, observer.input_method_changed_count_);
manager_->EnableLoginLayouts("en-US", "xkb:us::eng");
EXPECT_EQ(1, observer.input_method_changed_count_);
EXPECT_EQ(1, observer.input_method_property_changed_count_);
EXPECT_EQ(1, observer.input_method_menu_item_changed_count_);
manager_->ChangeInputMethod("xkb:us:dvorak:eng");
EXPECT_FALSE(observer.last_show_message_);
EXPECT_EQ(2, observer.input_method_changed_count_);
EXPECT_EQ(2, observer.input_method_property_changed_count_);
EXPECT_EQ(2, observer.input_method_menu_item_changed_count_);
manager_->ChangeInputMethod("xkb:us:dvorak:eng");
EXPECT_FALSE(observer.last_show_message_);
......@@ -254,7 +262,7 @@ TEST_F(InputMethodManagerImplTest, TestObserver) {
// If the same input method ID is passed, PropertyChanged() is not
// notified.
EXPECT_EQ(2, observer.input_method_property_changed_count_);
EXPECT_EQ(2, observer.input_method_menu_item_changed_count_);
manager_->RemoveObserver(&observer);
}
......@@ -593,23 +601,24 @@ TEST_F(InputMethodManagerImplTest, TestXkbSetting) {
EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_);
}
TEST_F(InputMethodManagerImplTest, TestActivateInputMethodProperty) {
TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) {
const std::string kKey = "key";
InputMethodPropertyList property_list;
property_list.push_back(InputMethodProperty(kKey, "label", false, false));
manager_->SetCurrentInputMethodProperties(property_list);
ash::ime::InputMethodMenuItemList menu_list;
menu_list.push_back(ash::ime::InputMethodMenuItem(
kKey, "label", false, false));
menu_manager_->SetCurrentInputMethodMenuItemList(menu_list);
manager_->ActivateInputMethodProperty(kKey);
manager_->ActivateInputMethodMenuItem(kKey);
EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property());
// Key2 is not registered, so activated property should not be changed.
manager_->ActivateInputMethodProperty("key2");
manager_->ActivateInputMethodMenuItem("key2");
EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property());
}
TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) {
InitComponentExtension();
EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty());
EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
std::vector<std::string> ids;
......@@ -617,26 +626,25 @@ TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) {
ids.push_back(kNaclMozcUsId);
EXPECT_TRUE(manager_->EnableInputMethods(ids));
EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty());
EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
manager_->ChangeInputMethod(kNaclMozcUsId);
InputMethodPropertyList current_property_list;
current_property_list.push_back(InputMethodProperty("key",
"label",
false,
false));
manager_->SetCurrentInputMethodProperties(current_property_list);
ash::ime::InputMethodMenuItemList current_property_list;
current_property_list.push_back(ash::ime::InputMethodMenuItem(
"key", "label", false, false));
menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list);
ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size());
EXPECT_EQ("key", manager_->GetCurrentInputMethodProperties().at(0).key);
ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size());
EXPECT_EQ("key",
menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key);
manager_->ChangeInputMethod("xkb:us::eng");
EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty());
EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
}
TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) {
InitComponentExtension();
EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty());
EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
std::vector<std::string> ids;
......@@ -644,32 +652,31 @@ TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) {
ids.push_back(kExt2Engine1Id); // T-Chinese
EXPECT_TRUE(manager_->EnableInputMethods(ids));
EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty());
EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
InputMethodPropertyList current_property_list;
current_property_list.push_back(InputMethodProperty("key-mozc",
"label",
false,
false));
manager_->SetCurrentInputMethodProperties(current_property_list);
ash::ime::InputMethodMenuItemList current_property_list;
current_property_list.push_back(ash::ime::InputMethodMenuItem("key-mozc",
"label",
false,
false));
menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list);
ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size());
EXPECT_EQ("key-mozc", manager_->GetCurrentInputMethodProperties().at(0).key);
ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size());
EXPECT_EQ("key-mozc",
menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key);
manager_->ChangeInputMethod(kExt2Engine1Id);
// Since the IME is changed, the property for mozc Japanese should be hidden.
EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty());
EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
// Asynchronous property update signal from mozc-chewing.
current_property_list.clear();
current_property_list.push_back(InputMethodProperty("key-chewing",
"label",
false,
false));
manager_->SetCurrentInputMethodProperties(current_property_list);
ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size());
current_property_list.push_back(ash::ime::InputMethodMenuItem(
"key-chewing", "label", false, false));
menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list);
ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size());
EXPECT_EQ("key-chewing",
manager_->GetCurrentInputMethodProperties().at(0).key);
menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key);
}
TEST_F(InputMethodManagerImplTest, TestNextInputMethod) {
......
......@@ -142,9 +142,6 @@ void InputMethodPersistence::InputMethodChanged(
NOTREACHED();
}
void InputMethodPersistence::InputMethodPropertyChanged(
InputMethodManager* manager) {}
void InputMethodPersistence::OnSessionStateChange(
InputMethodManager::State new_state) {
state_ = new_state;
......
......@@ -31,7 +31,6 @@ class InputMethodPersistence : public InputMethodManager::Observer {
// InputMethodManager::Observer overrides.
virtual void InputMethodChanged(InputMethodManager* manager,
bool show_message) OVERRIDE;
virtual void InputMethodPropertyChanged(InputMethodManager* manager) OVERRIDE;
private:
InputMethodManager* input_method_manager_;
......
......@@ -15,13 +15,18 @@ namespace ui {
class KeyEvent;
} // namespace ui
namespace ash {
namespace ime {
struct InputMethodMenuItem;
} // namespace ime
} // namespace ash
namespace chromeos {
class CompositionText;
namespace input_method {
class CandidateWindow;
struct InputMethodProperty;
struct KeyEventHandle;
} // namespace input_method
......
......@@ -91,7 +91,7 @@ void MockInputMethodManager::ChangeInputMethod(
const std::string& input_method_id) {
}
void MockInputMethodManager::ActivateInputMethodProperty(
void MockInputMethodManager::ActivateInputMethodMenuItem(
const std::string& key) {
}
......@@ -144,15 +144,6 @@ InputMethodDescriptor MockInputMethodManager::GetCurrentInputMethod() const {
return descriptor;
}
InputMethodPropertyList
MockInputMethodManager::GetCurrentInputMethodProperties() const {
return InputMethodPropertyList();
}
void MockInputMethodManager::SetCurrentInputMethodProperties(
const InputMethodPropertyList& property_list) {
}
XKeyboard* MockInputMethodManager::GetXKeyboard() {
return &xkeyboard_;
}
......
......@@ -43,7 +43,7 @@ class MockInputMethodManager : public InputMethodManager {
virtual bool EnableInputMethod(
const std::string& new_active_input_method_id) OVERRIDE;
virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
virtual void ActivateInputMethodProperty(const std::string& key) OVERRIDE;
virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
virtual void AddInputMethodExtension(
const std::string& id,
InputMethodEngineInterface* instance) OVERRIDE;
......@@ -57,10 +57,6 @@ class MockInputMethodManager : public InputMethodManager {
const ui::Accelerator& accelerator) OVERRIDE;
virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
virtual InputMethodPropertyList
GetCurrentInputMethodProperties() const OVERRIDE;
virtual void SetCurrentInputMethodProperties(
const InputMethodPropertyList& property_list) OVERRIDE;
virtual XKeyboard* GetXKeyboard() OVERRIDE;
virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE;
virtual ComponentExtensionIMEManager*
......
......@@ -92,11 +92,6 @@ void ModeIndicatorController::InputMethodChanged(InputMethodManager* manager,
ShowModeIndicator();
}
void ModeIndicatorController::InputMethodPropertyChanged(
InputMethodManager* manager) {
// Do nothing.
}
void ModeIndicatorController::ShowModeIndicator() {
// TODO(komatsu): When this is permanently enabled by defalut,
// delete command_line.h and chromeos_switches.h from the header
......
......@@ -48,7 +48,6 @@ class ModeIndicatorController
// InputMethodManager::Observer implementation.
virtual void InputMethodChanged(InputMethodManager* manager,
bool show_message) OVERRIDE;
virtual void InputMethodPropertyChanged(InputMethodManager* manager) OVERRIDE;
// Show the mode inidicator with the current ime's short name if all
// the conditions are cleared.
......
......@@ -11,6 +11,8 @@
#include "ash/ash_switches.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/ime/input_method_menu_item.h"
#include "ash/ime/input_method_menu_manager.h"
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/session_state_delegate.h"
#include "ash/session_state_observer.h"
......@@ -297,6 +299,7 @@ void SystemTrayDelegateChromeOS::Initialize() {
DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
input_method::InputMethodManager::Get()->AddObserver(this);
ash::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
UpdateClockType();
if (SystemKeyEventListener::GetInstance())
......@@ -357,6 +360,7 @@ SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
input_method::InputMethodManager::Get()->RemoveObserver(this);
ash::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
if (SystemKeyEventListener::GetInstance())
SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this);
bluetooth_adapter_->RemoveObserver(this);
......@@ -766,15 +770,14 @@ void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList* list) {
void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
ash::IMEPropertyInfoList* list) {
input_method::InputMethodManager* manager =
input_method::InputMethodManager::Get();
input_method::InputMethodPropertyList properties =
manager->GetCurrentInputMethodProperties();
for (size_t i = 0; i < properties.size(); ++i) {
ash::ime::InputMethodMenuItemList menu_list =
ash::ime::InputMethodMenuManager::GetInstance()->
GetCurrentInputMethodMenuItemList();
for (size_t i = 0; i < menu_list.size(); ++i) {
ash::IMEPropertyInfo property;
property.key = properties[i].key;
property.name = base::UTF8ToUTF16(properties[i].label);
property.selected = properties[i].is_selection_item_checked;
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);
}
}
......@@ -784,7 +787,7 @@ void SystemTrayDelegateChromeOS::SwitchIME(const std::string& ime_id) {
}
void SystemTrayDelegateChromeOS::ActivateIMEProperty(const std::string& key) {
input_method::InputMethodManager::Get()->ActivateInputMethodProperty(key);
input_method::InputMethodManager::Get()->ActivateInputMethodMenuItem(key);
}
void SystemTrayDelegateChromeOS::CancelDriveOperation(int32 operation_id) {
......@@ -1201,8 +1204,9 @@ void SystemTrayDelegateChromeOS::InputMethodChanged(
GetSystemTrayNotifier()->NotifyRefreshIME(show_message);
}
void SystemTrayDelegateChromeOS::InputMethodPropertyChanged(
input_method::InputMethodManager* manager) {
// Overridden from InputMethodMenuManager::Observer.
void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged(
ash::ime::InputMethodMenuManager* manager) {
GetSystemTrayNotifier()->NotifyRefreshIME(false);
}
......
......@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_
#define CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_
#include "ash/ime/input_method_menu_manager.h"
#include "ash/session_state_observer.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
......@@ -30,7 +31,8 @@
namespace chromeos {
class SystemTrayDelegateChromeOS
: public ash::SystemTrayDelegate,
: public ash::ime::InputMethodMenuManager::Observer,
public ash::SystemTrayDelegate,
public SessionManagerClient::Observer,
public drive::JobListObserver,
public content::NotificationObserver,
......@@ -180,8 +182,9 @@ class SystemTrayDelegateChromeOS
virtual void InputMethodChanged(input_method::InputMethodManager* manager,
bool show_message) OVERRIDE;
virtual void InputMethodPropertyChanged(
input_method::InputMethodManager* manager) OVERRIDE;
// Overridden from InputMethodMenuManager::Observer.
virtual void InputMethodMenuItemChanged(
ash::ime::InputMethodMenuManager* manager) OVERRIDE;
// drive::JobListObserver overrides.
virtual void OnJobAdded(const drive::JobInfo& job_info) OVERRIDE;
......
......@@ -228,8 +228,6 @@
'ime/input_method_descriptor.h',
'ime/input_method_manager.cc',
'ime/input_method_manager.h',
'ime/input_method_property.cc',
'ime/input_method_property.h',
'ime/input_method_whitelist.cc',
'ime/input_method_whitelist.h',
'ime/xkeyboard.cc',
......@@ -491,7 +489,6 @@
'ime/extension_ime_util_unittest.cc',
'ime/composition_text_unittest.cc',
'ime/input_method_manager.h',
'ime/input_method_property_unittest.cc',
'ime/input_method_whitelist_unittest.cc',
'ime/xkeyboard_unittest.cc',
'login/login_state_unittest.cc',
......
......@@ -12,7 +12,6 @@
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/ime/input_method_descriptor.h"
#include "chromeos/ime/input_method_property.h"
namespace ui {
class Accelerator;
......@@ -44,8 +43,6 @@ class CHROMEOS_EXPORT InputMethodManager {
// indicates whether the user should be notified of this change.
virtual void InputMethodChanged(InputMethodManager* manager,
bool show_message) = 0;
// Called when the list of properties is changed.
virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0;
};
// CandidateWindowObserver is notified of events related to the candidate
......@@ -126,7 +123,7 @@ class CHROMEOS_EXPORT InputMethodManager {
const std::string& initial_layout) = 0;
// Activates the input method property specified by the |key|.
virtual void ActivateInputMethodProperty(const std::string& key) = 0;
virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
// Updates the list of active input method IDs, and then starts or stops the
// system input method framework as needed.
......@@ -159,13 +156,6 @@ class CHROMEOS_EXPORT InputMethodManager {
// Gets the descriptor of the input method which is currently selected.
virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
// Gets the list of input method properties. The list could be empty().
virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0;
// Sets the list of input method properties. The list could be empty().
virtual void SetCurrentInputMethodProperties(
const InputMethodPropertyList& property_list) = 0;
// Returns an X keyboard object which could be used to change the current XKB
// layout, change the caps lock status, and set the auto repeat rate/interval.
virtual XKeyboard* GetXKeyboard() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment