Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/status/input_method_menu_button.h" | 5 #include "chrome/browser/chromeos/status/input_method_menu_button.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 11 #include "chrome/browser/chromeos/cros/keyboard_library.h" | 12 #include "chrome/browser/chromeos/cros/keyboard_library.h" |
| 12 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 13 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 13 #include "chrome/browser/chromeos/status/status_area_host.h" | 14 #include "chrome/browser/chromeos/status/status_area_host.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Returns PrefService object associated with |host|. Returns NULL if we are NOT | 20 // Returns PrefService object associated with |host|. Returns NULL if we are NOT |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 47 host_(host) { | 48 host_(host) { |
| 48 set_border(NULL); | 49 set_border(NULL); |
| 49 set_use_menu_button_paint(true); | 50 set_use_menu_button_paint(true); |
| 50 SetFont(ResourceBundle::GetSharedInstance().GetFont( | 51 SetFont(ResourceBundle::GetSharedInstance().GetFont( |
| 51 ResourceBundle::BaseFont).DeriveFont(kFontSizeDelta)); | 52 ResourceBundle::BaseFont).DeriveFont(kFontSizeDelta)); |
| 52 SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha | 53 SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha |
| 53 SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible) | 54 SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible) |
| 54 SetShowMultipleIconStates(false); | 55 SetShowMultipleIconStates(false); |
| 55 set_alignment(TextButton::ALIGN_CENTER); | 56 set_alignment(TextButton::ALIGN_CENTER); |
| 56 | 57 |
| 58 chromeos::KeyboardLibrary* keyboard_library = | |
| 59 chromeos::CrosLibrary::Get()->GetKeyboardLibrary(); | |
| 60 const std::string hardware_keyboard_id = // e.g. "xkb:us::eng" | |
| 61 keyboard_library->GetHardwareKeyboardLayoutName(); | |
| 62 | |
| 57 // Draw the default indicator "US". The default indicator "US" is used when | 63 // Draw the default indicator "US". The default indicator "US" is used when |
| 58 // |pref_service| is not available (for example, unit tests) or |pref_service| | 64 // |pref_service| is not available (for example, unit tests) or |pref_service| |
| 59 // is available, but Chrome preferences are not available (for example, | 65 // is available, but Chrome preferences are not available (for example, |
| 60 // initial OS boot). | 66 // initial OS boot). |
| 61 InputMethodMenuButton::UpdateUI(L"US", L""); | 67 InputMethodMenuButton::UpdateUI(hardware_keyboard_id, L"US", L"", 1); |
| 62 } | 68 } |
| 63 | 69 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 65 // views::View implementation: | 71 // views::View implementation: |
| 66 | 72 |
| 67 gfx::Size InputMethodMenuButton::GetPreferredSize() { | 73 gfx::Size InputMethodMenuButton::GetPreferredSize() { |
| 68 // If not enabled, then hide this button. | 74 // If not enabled, then hide this button. |
| 69 if (!IsEnabled()) { | 75 if (!IsEnabled()) { |
| 70 return gfx::Size(0, 0); | 76 return gfx::Size(0, 0); |
| 71 } | 77 } |
| 72 return StatusAreaButton::GetPreferredSize(); | 78 return StatusAreaButton::GetPreferredSize(); |
| 73 } | 79 } |
| 74 | 80 |
| 75 void InputMethodMenuButton::OnLocaleChanged() { | 81 void InputMethodMenuButton::OnLocaleChanged() { |
| 76 input_method::OnLocaleChanged(); | 82 input_method::OnLocaleChanged(); |
| 83 | |
| 84 chromeos::InputMethodLibrary* input_method_library = | |
| 85 chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); | |
| 77 const InputMethodDescriptor& input_method = | 86 const InputMethodDescriptor& input_method = |
| 78 CrosLibrary::Get()->GetInputMethodLibrary()->current_input_method(); | 87 input_method_library->current_input_method(); |
| 79 UpdateUIFromInputMethod(input_method); | 88 |
| 89 // In general, we should not call an ibus-daemon API in the input method | |
|
satorux1
2010/12/01 06:40:18
ibus-daemon -> input method ?
Yusuke Sato
2010/12/01 07:36:41
Done.
| |
| 90 // button classes (status/input_menu_button*.cc) for performance reasons (see | |
| 91 // http://crosbug.com/8284). However, since OnLocaleChanged is called only in | |
| 92 // OOBE/Login screen which does not have two or more Chrome windows, it's okay | |
| 93 // to call GetNumActiveInputMethods here. | |
| 94 const size_t num_active_input_methods = | |
| 95 input_method_library->GetNumActiveInputMethods(); | |
| 96 | |
| 97 UpdateUIFromInputMethod(input_method, num_active_input_methods); | |
| 80 Layout(); | 98 Layout(); |
| 81 SchedulePaint(); | 99 SchedulePaint(); |
| 82 } | 100 } |
| 83 | 101 |
| 84 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
| 85 // InputMethodMenu::InputMethodMenuHost implementation: | 103 // InputMethodMenu::InputMethodMenuHost implementation: |
| 86 | 104 |
| 87 void InputMethodMenuButton::UpdateUI( | 105 void InputMethodMenuButton::UpdateUI(const std::string& id, |
| 88 const std::wstring& name, const std::wstring& tooltip) { | 106 const std::wstring& name, |
| 107 const std::wstring& tooltip, | |
| 108 size_t num_active_input_methods) { | |
| 89 // Hide the button only if there is only one input method, and the input | 109 // Hide the button only if there is only one input method, and the input |
| 90 // method is a XKB keyboard layout. We don't hide the button for other | 110 // method is a XKB keyboard layout. We don't hide the button for other |
| 91 // types of input methods as these might have intra input method modes, | 111 // types of input methods as these might have intra input method modes, |
| 92 // like Hiragana and Katakana modes in Japanese input methods. | 112 // like Hiragana and Katakana modes in Japanese input methods. |
| 93 scoped_ptr<InputMethodDescriptors> active_input_methods( | 113 if (num_active_input_methods == 1 && |
| 94 CrosLibrary::Get()->GetInputMethodLibrary()->GetActiveInputMethods()); | 114 input_method::IsKeyboardLayout(id) && |
| 95 if (active_input_methods->size() == 1 && | |
| 96 input_method::IsKeyboardLayout(active_input_methods->at(0).id) && | |
| 97 host_->IsBrowserMode()) { | 115 host_->IsBrowserMode()) { |
| 98 // As the disabled color is set to invisible, disabling makes the | 116 // As the disabled color is set to invisible, disabling makes the |
| 99 // button disappear. | 117 // button disappear. |
| 100 SetEnabled(false); | 118 SetEnabled(false); |
| 101 SetTooltipText(L""); // remove tooltip | 119 SetTooltipText(L""); // remove tooltip |
| 102 } else { | 120 } else { |
| 103 SetEnabled(true); | 121 SetEnabled(true); |
| 104 SetTooltipText(tooltip); | 122 SetTooltipText(tooltip); |
| 105 } | 123 } |
| 106 SetText(name); | 124 SetText(name); |
| 107 SchedulePaint(); | 125 SchedulePaint(); |
| 108 } | 126 } |
| 109 | 127 |
| 110 void InputMethodMenuButton::OpenConfigUI() { | 128 void InputMethodMenuButton::OpenConfigUI() { |
| 111 host_->OpenButtonOptions(this); // ask browser to open the DOMUI page. | 129 host_->OpenButtonOptions(this); // ask browser to open the DOMUI page. |
| 112 } | 130 } |
| 113 | 131 |
| 114 bool InputMethodMenuButton::ShouldSupportConfigUI() { | 132 bool InputMethodMenuButton::ShouldSupportConfigUI() { |
| 115 return host_->ShouldOpenButtonOptions(this); | 133 return host_->ShouldOpenButtonOptions(this); |
| 116 } | 134 } |
| 117 | 135 |
| 118 } // namespace chromeos | 136 } // namespace chromeos |
| OLD | NEW |