diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-14 22:44:17 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-14 22:44:17 +0000 |
commit | c284cca1fe42794e5f4366cc46a66a2287e6677e (patch) | |
tree | 71983f8eb183993f8f5739c82b7ae3f16c1753af /ash/ime | |
parent | d03d664a47a3a0ad32c529c231017d8a0e75f439 (diff) | |
download | chromium_src-c284cca1fe42794e5f4366cc46a66a2287e6677e.zip chromium_src-c284cca1fe42794e5f4366cc46a66a2287e6677e.tar.gz chromium_src-c284cca1fe42794e5f4366cc46a66a2287e6677e.tar.bz2 |
Revert 251327 "Reland of: Split out InputMethodMenuManager from ..."
> 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
TBR=uekawa@chromium.org
Review URL: https://codereview.chromium.org/167823002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251436 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/ime')
-rw-r--r-- | ash/ime/input_method_menu_item.cc | 54 | ||||
-rw-r--r-- | ash/ime/input_method_menu_item.h | 44 | ||||
-rw-r--r-- | ash/ime/input_method_menu_item_unittest.cc | 32 | ||||
-rw-r--r-- | ash/ime/input_method_menu_manager.cc | 57 | ||||
-rw-r--r-- | ash/ime/input_method_menu_manager.h | 65 | ||||
-rw-r--r-- | ash/ime/input_method_menu_manager_unittest.cc | 76 |
6 files changed, 0 insertions, 328 deletions
diff --git a/ash/ime/input_method_menu_item.cc b/ash/ime/input_method_menu_item.cc deleted file mode 100644 index 6337ec5..0000000 --- a/ash/ime/input_method_menu_item.cc +++ /dev/null @@ -1,54 +0,0 @@ -// 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 <sstream> - -#include "base/logging.h" - -namespace ash { -namespace ime { - -InputMethodMenuItem::InputMethodMenuItem(const std::string& in_key, - const std::string& in_label, - bool in_is_selection_item, - bool in_is_selection_item_checked) - : key(in_key), - label(in_label), - is_selection_item(in_is_selection_item), - is_selection_item_checked(in_is_selection_item_checked) { - DCHECK(!key.empty()); -} - -InputMethodMenuItem::InputMethodMenuItem() - : is_selection_item(false), - is_selection_item_checked(false) { -} - -InputMethodMenuItem::~InputMethodMenuItem() { -} - -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 InputMethodMenuItem::operator!=(const InputMethodMenuItem& other) const { - return !(*this == other); -} - -std::string InputMethodMenuItem::ToString() const { - std::stringstream stream; - stream << "key=" << key - << ", label=" << label - << ", is_selection_item=" << is_selection_item - << ", is_selection_item_checked=" << is_selection_item_checked; - return stream.str(); -} - -} // namespace ime -} // namespace ash diff --git a/ash/ime/input_method_menu_item.h b/ash/ime/input_method_menu_item.h deleted file mode 100644 index 1407d0a..0000000 --- a/ash/ime/input_method_menu_item.h +++ /dev/null @@ -1,44 +0,0 @@ -// 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 ASH_IME_INPUT_METHOD_MENU_ITEM_H_ -#define ASH_IME_INPUT_METHOD_MENU_ITEM_H_ - -#include <string> -#include <vector> -#include "ash/ash_export.h" - -namespace ash { -namespace ime { - -// A structure which represents a property for an input method engine. -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); - - InputMethodMenuItem(); - ~InputMethodMenuItem(); - - bool operator==(const InputMethodMenuItem& other) const; - bool operator!=(const InputMethodMenuItem& other) const; - - // Debug print function. - std::string ToString() const; - - std::string key; // A key which identifies the property. Non-empty string. - // (e.g. "InputMode.HalfWidthKatakana") - std::string label; // A description of the property. Non-empty string. - // (e.g. "Switch to full punctuation mode", "Hiragana") - bool is_selection_item; // true if the property is a selection item. - bool is_selection_item_checked; // true if |is_selection_item| is true and - // the selection_item is selected. -}; -typedef std::vector<InputMethodMenuItem> InputMethodMenuItemList; - -} // namespace ime -} // namespace ash - -#endif // ASH_IME_INPUT_METHOD_MENU_ITEM_H_ diff --git a/ash/ime/input_method_menu_item_unittest.cc b/ash/ime/input_method_menu_item_unittest.cc deleted file mode 100644 index 9ac7942..0000000 --- a/ash/ime/input_method_menu_item_unittest.cc +++ /dev/null @@ -1,32 +0,0 @@ -// 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 "testing/gtest/include/gtest/gtest.h" - -namespace ash { -namespace ime { - -TEST(InputMethodMenuItemTest, TestOperatorEqual) { - InputMethodMenuItem empty; - InputMethodMenuItem reference("key", "label", true, true); - - 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); - EXPECT_NE(reference, empty); - EXPECT_NE(reference, p1); - EXPECT_NE(reference, p2); - EXPECT_NE(reference, p3); - EXPECT_NE(reference, p4); -} - -} // namespace ime -} // namespace ash diff --git a/ash/ime/input_method_menu_manager.cc b/ash/ime/input_method_menu_manager.cc deleted file mode 100644 index ee75621..0000000 --- a/ash/ime/input_method_menu_manager.cc +++ /dev/null @@ -1,57 +0,0 @@ -// 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 diff --git a/ash/ime/input_method_menu_manager.h b/ash/ime/input_method_menu_manager.h deleted file mode 100644 index ffaeb480..0000000 --- a/ash/ime/input_method_menu_manager.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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_ diff --git a/ash/ime/input_method_menu_manager_unittest.cc b/ash/ime/input_method_menu_manager_unittest.cc deleted file mode 100644 index ba92001..0000000 --- a/ash/ime/input_method_menu_manager_unittest.cc +++ /dev/null @@ -1,76 +0,0 @@ -// 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 |