diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 05:06:35 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 05:06:35 +0000 |
commit | f3964ad144ead73929d06441910a26994879377f (patch) | |
tree | 27d3d07165bf075c117b68875f56c518fef08036 /chrome/browser/chromeos | |
parent | 57b26b167e12b0ef1b98adba77ce4622962a4c8e (diff) | |
download | chromium_src-f3964ad144ead73929d06441910a26994879377f.zip chromium_src-f3964ad144ead73929d06441910a26994879377f.tar.gz chromium_src-f3964ad144ead73929d06441910a26994879377f.tar.bz2 |
Remove multiple inheritance from input_method_menu_button.h.
Currently chromeos::InputMethodMenuButton is derived from both StatusAreaButton and InputMethodMenu, which violates the Chrome coding guideline. This change removes the multiple inheritance by adding InputMethodMenu object to InputMethodMenuButton as a member variable.
BUG=chromium-os:7572
TEST=manually & try bot
Review URL: http://codereview.chromium.org/6262012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72467 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
5 files changed, 53 insertions, 13 deletions
diff --git a/chrome/browser/chromeos/login/keyboard_switch_menu.cc b/chrome/browser/chromeos/login/keyboard_switch_menu.cc index 278d578..5e29ce5 100644 --- a/chrome/browser/chromeos/login/keyboard_switch_menu.cc +++ b/chrome/browser/chromeos/login/keyboard_switch_menu.cc @@ -12,6 +12,7 @@ #include "chrome/browser/chromeos/status/status_area_host.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +#include "views/controls/button/menu_button.h" #include "views/widget/widget_gtk.h" namespace chromeos { diff --git a/chrome/browser/chromeos/login/keyboard_switch_menu.h b/chrome/browser/chromeos/login/keyboard_switch_menu.h index d2692fc..ed261f8 100644 --- a/chrome/browser/chromeos/login/keyboard_switch_menu.h +++ b/chrome/browser/chromeos/login/keyboard_switch_menu.h @@ -9,7 +9,7 @@ #include <string> #include "base/scoped_ptr.h" -#include "chrome/browser/chromeos/status/input_method_menu_button.h" +#include "chrome/browser/chromeos/status/input_method_menu.h" #include "chrome/browser/chromeos/status/status_area_host.h" namespace chromeos { diff --git a/chrome/browser/chromeos/status/input_method_menu.h b/chrome/browser/chromeos/status/input_method_menu.h index 4045293..6227abf 100644 --- a/chrome/browser/chromeos/status/input_method_menu.h +++ b/chrome/browser/chromeos/status/input_method_menu.h @@ -97,10 +97,6 @@ class InputMethodMenu : public views::ViewMenuDelegate, static std::wstring GetTextForMenu(const InputMethodDescriptor& input_method); protected: - // Parses |input_method| and then calls UpdateUI(). - void UpdateUIFromInputMethod(const InputMethodDescriptor& input_method, - size_t num_active_input_methods); - // Rebuilds model and menu2 objects in preparetion to open the menu. void PrepareForMenuOpen(); @@ -126,6 +122,10 @@ class InputMethodMenu : public views::ViewMenuDelegate, // customizing languages and input. virtual void OpenConfigUI() = 0; + // Parses |input_method| and then calls UpdateUI(). + void UpdateUIFromInputMethod(const InputMethodDescriptor& input_method, + size_t num_active_input_methods); + // Rebuilds |model_|. This function should be called whenever // |input_method_descriptors_| is updated, or ImePropertiesChanged() is // called. diff --git a/chrome/browser/chromeos/status/input_method_menu_button.cc b/chrome/browser/chromeos/status/input_method_menu_button.cc index ff4db96..1767b49 100644 --- a/chrome/browser/chromeos/status/input_method_menu_button.cc +++ b/chrome/browser/chromeos/status/input_method_menu_button.cc @@ -32,6 +32,35 @@ const int kFontSizeDelta = 0; const int kFontSizeDelta = 1; #endif +// A class which implements interfaces of chromeos::InputMethodMenu. This class +// is just for avoiding multiple inheritance. +class MenuImpl : public chromeos::InputMethodMenu { + public: + MenuImpl(chromeos::InputMethodMenuButton* button, + PrefService* pref_service, + chromeos::StatusAreaHost::ScreenMode screen_mode) + : InputMethodMenu(pref_service, screen_mode, false), button_(button) {} + + private: + // InputMethodMenu implementation. + virtual void UpdateUI(const std::string& input_method_id, + const std::wstring& name, + const std::wstring& tooltip, + size_t num_active_input_methods) { + button_->UpdateUI(input_method_id, name, tooltip, num_active_input_methods); + } + virtual bool ShouldSupportConfigUI() { + return button_->ShouldSupportConfigUI(); + } + virtual void OpenConfigUI() { + button_->OpenConfigUI(); + } + // The UI (views button) to which this class delegates all requests. + chromeos::InputMethodMenuButton* button_; + + DISALLOW_COPY_AND_ASSIGN(MenuImpl); +}; + } // namespace namespace chromeos { @@ -41,9 +70,7 @@ namespace chromeos { InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host) : StatusAreaButton(this), - InputMethodMenu(GetPrefService(host), - host->GetScreenMode(), - false /* for_out_of_box_experience_dialog */), + menu_(new MenuImpl(this, GetPrefService(host), host->GetScreenMode())), host_(host) { set_border(NULL); set_use_menu_button_paint(true); @@ -63,7 +90,7 @@ InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host) // |pref_service| is not available (for example, unit tests) or |pref_service| // is available, but Chrome preferences are not available (for example, // initial OS boot). - InputMethodMenuButton::UpdateUI(hardware_keyboard_id, L"US", L"", 1); + UpdateUI(hardware_keyboard_id, L"US", L"", 1); } //////////////////////////////////////////////////////////////////////////////// @@ -84,6 +111,8 @@ void InputMethodMenuButton::OnLocaleChanged() { chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); const InputMethodDescriptor& input_method = input_method_library->current_input_method(); + const std::wstring name = InputMethodMenu::GetTextForIndicator(input_method); + const std::wstring tooltip = InputMethodMenu::GetTextForMenu(input_method); // In general, we should not call an input method API in the input method // button classes (status/input_menu_button*.cc) for performance reasons (see @@ -92,14 +121,19 @@ void InputMethodMenuButton::OnLocaleChanged() { // to call GetNumActiveInputMethods here. const size_t num_active_input_methods = input_method_library->GetNumActiveInputMethods(); + UpdateUI(input_method.id, name, tooltip, num_active_input_methods); - UpdateUIFromInputMethod(input_method, num_active_input_methods); Layout(); SchedulePaint(); } //////////////////////////////////////////////////////////////////////////////// -// InputMethodMenu::InputMethodMenuHost implementation: +// views::ViewMenuDelegate implementation: + +void InputMethodMenuButton::RunMenu(views::View* unused_source, + const gfx::Point& pt) { + menu_->RunMenu(unused_source, pt); +} void InputMethodMenuButton::UpdateUI(const std::string& input_method_id, const std::wstring& name, diff --git a/chrome/browser/chromeos/status/input_method_menu_button.h b/chrome/browser/chromeos/status/input_method_menu_button.h index 3a232eb..325b63b 100644 --- a/chrome/browser/chromeos/status/input_method_menu_button.h +++ b/chrome/browser/chromeos/status/input_method_menu_button.h @@ -10,6 +10,7 @@ #include "chrome/browser/chromeos/status/input_method_menu.h" #include "chrome/browser/chromeos/status/status_area_button.h" +#include "views/controls/menu/view_menu_delegate.h" namespace chromeos { @@ -18,7 +19,7 @@ class StatusAreaHost; // A class for the button in the status area which expands the dropdown menu for // switching input method and keyboard layout. class InputMethodMenuButton : public StatusAreaButton, - public InputMethodMenu { + public views::ViewMenuDelegate { public: explicit InputMethodMenuButton(StatusAreaHost* host); virtual ~InputMethodMenuButton() {} @@ -27,7 +28,9 @@ class InputMethodMenuButton : public StatusAreaButton, virtual gfx::Size GetPreferredSize(); virtual void OnLocaleChanged(); - private: + // views::ViewMenuDelegate implementation. + virtual void RunMenu(views::View* unused_source, const gfx::Point& pt); + // InputMethodMenu implementation. virtual void UpdateUI(const std::string& input_method_id, const std::wstring& name, @@ -36,6 +39,8 @@ class InputMethodMenuButton : public StatusAreaButton, virtual bool ShouldSupportConfigUI(); virtual void OpenConfigUI(); + private: + scoped_ptr<InputMethodMenu> menu_; StatusAreaHost* host_; DISALLOW_COPY_AND_ASSIGN(InputMethodMenuButton); |