| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/language_menu_button.h" | 5 #include "chrome/browser/chromeos/status/language_menu_button.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 14 #include "chrome/browser/chromeos/status/language_menu_l10n_util.h" | 15 #include "chrome/browser/chromeos/status/language_menu_l10n_util.h" |
| 15 #include "chrome/browser/chromeos/status/status_area_host.h" | 16 #include "chrome/browser/chromeos/status/status_area_host.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 18 | 19 |
| 19 // The language menu consists of 3 parts (in this order): | 20 // The language menu consists of 3 parts (in this order): |
| 20 // | 21 // |
| 21 // (1) XKB layout names and IME languages names. The size of the list is | 22 // (1) XKB layout names and IME languages names. The size of the list is |
| 22 // always >= 1. | 23 // always >= 1. |
| 23 // (2) IME properties. This list might be empty. | 24 // (2) IME properties. This list might be empty. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 } // namespace | 118 } // namespace |
| 118 | 119 |
| 119 namespace chromeos { | 120 namespace chromeos { |
| 120 | 121 |
| 121 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
| 122 // LanguageMenuButton | 123 // LanguageMenuButton |
| 123 | 124 |
| 124 LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host) | 125 LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host) |
| 125 : MenuButton(NULL, std::wstring(), this, false), | 126 : MenuButton(NULL, std::wstring(), this, false), |
| 126 language_list_(LanguageLibrary::Get()->GetActiveLanguages()), | 127 language_list_(CrosLibrary::Get()->GetLanguageLibrary()-> |
| 128 GetActiveLanguages()), |
| 127 model_(NULL), | 129 model_(NULL), |
| 128 // Be aware that the constructor of |language_menu_| calls GetItemCount() | 130 // Be aware that the constructor of |language_menu_| calls GetItemCount() |
| 129 // in this class. Therefore, GetItemCount() have to return 0 when | 131 // in this class. Therefore, GetItemCount() have to return 0 when |
| 130 // |model_| is NULL. | 132 // |model_| is NULL. |
| 131 ALLOW_THIS_IN_INITIALIZER_LIST(language_menu_(this)), | 133 ALLOW_THIS_IN_INITIALIZER_LIST(language_menu_(this)), |
| 132 host_(host) { | 134 host_(host) { |
| 133 DCHECK(language_list_.get() && !language_list_->empty()); | 135 DCHECK(language_list_.get() && !language_list_->empty()); |
| 134 // Update the model | 136 // Update the model |
| 135 RebuildModel(); | 137 RebuildModel(); |
| 136 // Grab the real estate. | 138 // Grab the real estate. |
| 137 UpdateIcon(kSpacer); | 139 UpdateIcon(kSpacer); |
| 138 // Display the default XKB name (usually "US"). | 140 // Display the default XKB name (usually "US"). |
| 139 const std::wstring name = FormatInputLanguage(language_list_->at(0), false); | 141 const std::wstring name = FormatInputLanguage(language_list_->at(0), false); |
| 140 UpdateIcon(name); | 142 UpdateIcon(name); |
| 141 LanguageLibrary::Get()->AddObserver(this); | 143 CrosLibrary::Get()->GetLanguageLibrary()->AddObserver(this); |
| 142 } | 144 } |
| 143 | 145 |
| 144 LanguageMenuButton::~LanguageMenuButton() { | 146 LanguageMenuButton::~LanguageMenuButton() { |
| 145 LanguageLibrary::Get()->RemoveObserver(this); | 147 CrosLibrary::Get()->GetLanguageLibrary()->RemoveObserver(this); |
| 146 } | 148 } |
| 147 | 149 |
| 148 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
| 149 // LanguageMenuButton, menus::MenuModel implementation: | 151 // LanguageMenuButton, menus::MenuModel implementation: |
| 150 | 152 |
| 151 int LanguageMenuButton::GetCommandIdAt(int index) const { | 153 int LanguageMenuButton::GetCommandIdAt(int index) const { |
| 152 return 0; // dummy | 154 return 0; // dummy |
| 153 } | 155 } |
| 154 | 156 |
| 155 bool LanguageMenuButton::IsLabelDynamicAt(int index) const { | 157 bool LanguageMenuButton::IsLabelDynamicAt(int index) const { |
| 156 // Menu content for the language button could change time by time. | 158 // Menu content for the language button could change time by time. |
| 157 return true; | 159 return true; |
| 158 } | 160 } |
| 159 | 161 |
| 160 bool LanguageMenuButton::GetAcceleratorAt( | 162 bool LanguageMenuButton::GetAcceleratorAt( |
| 161 int index, menus::Accelerator* accelerator) const { | 163 int index, menus::Accelerator* accelerator) const { |
| 162 // Views for Chromium OS does not support accelerators yet. | 164 // Views for Chromium OS does not support accelerators yet. |
| 163 return false; | 165 return false; |
| 164 } | 166 } |
| 165 | 167 |
| 166 bool LanguageMenuButton::IsItemCheckedAt(int index) const { | 168 bool LanguageMenuButton::IsItemCheckedAt(int index) const { |
| 167 DCHECK_GE(index, 0); | 169 DCHECK_GE(index, 0); |
| 168 DCHECK(language_list_.get()); | 170 DCHECK(language_list_.get()); |
| 169 | 171 |
| 170 if (IndexIsInLanguageList(index)) { | 172 if (IndexIsInLanguageList(index)) { |
| 171 const InputLanguage& language = language_list_->at(index); | 173 const InputLanguage& language = language_list_->at(index); |
| 172 return language == LanguageLibrary::Get()->current_language(); | 174 return language == CrosLibrary::Get()->GetLanguageLibrary()-> |
| 175 current_language(); |
| 173 } | 176 } |
| 174 | 177 |
| 175 if (GetPropertyIndex(index, &index)) { | 178 if (GetPropertyIndex(index, &index)) { |
| 176 const ImePropertyList& property_list | 179 const ImePropertyList& property_list |
| 177 = LanguageLibrary::Get()->current_ime_properties(); | 180 = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); |
| 178 return property_list.at(index).is_selection_item_checked; | 181 return property_list.at(index).is_selection_item_checked; |
| 179 } | 182 } |
| 180 | 183 |
| 181 // Separator(s) or the "Configure IME" button. | 184 // Separator(s) or the "Configure IME" button. |
| 182 return false; | 185 return false; |
| 183 } | 186 } |
| 184 | 187 |
| 185 int LanguageMenuButton::GetGroupIdAt(int index) const { | 188 int LanguageMenuButton::GetGroupIdAt(int index) const { |
| 186 DCHECK_GE(index, 0); | 189 DCHECK_GE(index, 0); |
| 187 | 190 |
| 188 if (IndexIsInLanguageList(index)) { | 191 if (IndexIsInLanguageList(index)) { |
| 189 return kRadioGroupLanguage; | 192 return kRadioGroupLanguage; |
| 190 } | 193 } |
| 191 | 194 |
| 192 if (GetPropertyIndex(index, &index)) { | 195 if (GetPropertyIndex(index, &index)) { |
| 193 const ImePropertyList& property_list | 196 const ImePropertyList& property_list |
| 194 = LanguageLibrary::Get()->current_ime_properties(); | 197 = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); |
| 195 return property_list.at(index).selection_item_id; | 198 return property_list.at(index).selection_item_id; |
| 196 } | 199 } |
| 197 | 200 |
| 198 return kRadioGroupNone; | 201 return kRadioGroupNone; |
| 199 } | 202 } |
| 200 | 203 |
| 201 bool LanguageMenuButton::HasIcons() const { | 204 bool LanguageMenuButton::HasIcons() const { |
| 202 // We don't support IME nor keyboard icons on Chrome OS. | 205 // We don't support IME nor keyboard icons on Chrome OS. |
| 203 return false; | 206 return false; |
| 204 } | 207 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 if (IndexPointsToConfigureImeMenuItem(index)) { | 244 if (IndexPointsToConfigureImeMenuItem(index)) { |
| 242 return menus::MenuModel::TYPE_COMMAND; // "Configure IME" | 245 return menus::MenuModel::TYPE_COMMAND; // "Configure IME" |
| 243 } | 246 } |
| 244 | 247 |
| 245 if (IndexIsInLanguageList(index)) { | 248 if (IndexIsInLanguageList(index)) { |
| 246 return menus::MenuModel::TYPE_RADIO; | 249 return menus::MenuModel::TYPE_RADIO; |
| 247 } | 250 } |
| 248 | 251 |
| 249 if (GetPropertyIndex(index, &index)) { | 252 if (GetPropertyIndex(index, &index)) { |
| 250 const ImePropertyList& property_list | 253 const ImePropertyList& property_list |
| 251 = LanguageLibrary::Get()->current_ime_properties(); | 254 = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); |
| 252 if (property_list.at(index).is_selection_item) { | 255 if (property_list.at(index).is_selection_item) { |
| 253 return menus::MenuModel::TYPE_RADIO; | 256 return menus::MenuModel::TYPE_RADIO; |
| 254 } | 257 } |
| 255 return menus::MenuModel::TYPE_COMMAND; | 258 return menus::MenuModel::TYPE_COMMAND; |
| 256 } | 259 } |
| 257 | 260 |
| 258 return menus::MenuModel::TYPE_SEPARATOR; | 261 return menus::MenuModel::TYPE_SEPARATOR; |
| 259 } | 262 } |
| 260 | 263 |
| 261 string16 LanguageMenuButton::GetLabelAt(int index) const { | 264 string16 LanguageMenuButton::GetLabelAt(int index) const { |
| 262 DCHECK_GE(index, 0); | 265 DCHECK_GE(index, 0); |
| 263 DCHECK(language_list_.get()); | 266 DCHECK(language_list_.get()); |
| 264 | 267 |
| 265 if (IndexPointsToConfigureImeMenuItem(index)) { | 268 if (IndexPointsToConfigureImeMenuItem(index)) { |
| 266 return l10n_util::GetStringUTF16(IDS_STATUSBAR_IME_CONFIGURE); | 269 return l10n_util::GetStringUTF16(IDS_STATUSBAR_IME_CONFIGURE); |
| 267 } | 270 } |
| 268 | 271 |
| 269 std::wstring name; | 272 std::wstring name; |
| 270 if (IndexIsInLanguageList(index)) { | 273 if (IndexIsInLanguageList(index)) { |
| 271 name = FormatInputLanguage(language_list_->at(index), true); | 274 name = FormatInputLanguage(language_list_->at(index), true); |
| 272 } else if (GetPropertyIndex(index, &index)) { | 275 } else if (GetPropertyIndex(index, &index)) { |
| 273 const ImePropertyList& property_list | 276 const ImePropertyList& property_list |
| 274 = LanguageLibrary::Get()->current_ime_properties(); | 277 = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); |
| 275 return LanguageMenuL10nUtil::GetStringUTF16( | 278 return LanguageMenuL10nUtil::GetStringUTF16( |
| 276 property_list.at(index).label); | 279 property_list.at(index).label); |
| 277 } | 280 } |
| 278 | 281 |
| 279 return WideToUTF16(name); | 282 return WideToUTF16(name); |
| 280 } | 283 } |
| 281 | 284 |
| 282 void LanguageMenuButton::ActivatedAt(int index) { | 285 void LanguageMenuButton::ActivatedAt(int index) { |
| 283 DCHECK_GE(index, 0); | 286 DCHECK_GE(index, 0); |
| 284 DCHECK(language_list_.get()); | 287 DCHECK(language_list_.get()); |
| 285 | 288 |
| 286 if (IndexPointsToConfigureImeMenuItem(index)) { | 289 if (IndexPointsToConfigureImeMenuItem(index)) { |
| 287 host_->OpenButtonOptions(this); | 290 host_->OpenButtonOptions(this); |
| 288 return; | 291 return; |
| 289 } | 292 } |
| 290 | 293 |
| 291 if (IndexIsInLanguageList(index)) { | 294 if (IndexIsInLanguageList(index)) { |
| 292 // Inter-IME switching or IME-XKB switching. | 295 // Inter-IME switching or IME-XKB switching. |
| 293 const InputLanguage& language = language_list_->at(index); | 296 const InputLanguage& language = language_list_->at(index); |
| 294 LanguageLibrary::Get()->ChangeLanguage(language.category, language.id); | 297 CrosLibrary::Get()->GetLanguageLibrary()->ChangeLanguage(language.category, |
| 298 language.id); |
| 295 return; | 299 return; |
| 296 } | 300 } |
| 297 | 301 |
| 298 if (GetPropertyIndex(index, &index)) { | 302 if (GetPropertyIndex(index, &index)) { |
| 299 // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). | 303 // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). |
| 300 const ImePropertyList& property_list | 304 const ImePropertyList& property_list |
| 301 = LanguageLibrary::Get()->current_ime_properties(); | 305 = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); |
| 302 const std::string key = property_list.at(index).key; | 306 const std::string key = property_list.at(index).key; |
| 303 if (property_list.at(index).is_selection_item) { | 307 if (property_list.at(index).is_selection_item) { |
| 304 // Radio button is clicked. | 308 // Radio button is clicked. |
| 305 const int id = property_list.at(index).selection_item_id; | 309 const int id = property_list.at(index).selection_item_id; |
| 306 // First, deactivate all other properties in the same radio group. | 310 // First, deactivate all other properties in the same radio group. |
| 307 for (int i = 0; i < static_cast<int>(property_list.size()); ++i) { | 311 for (int i = 0; i < static_cast<int>(property_list.size()); ++i) { |
| 308 if (i != index && id == property_list.at(i).selection_item_id) { | 312 if (i != index && id == property_list.at(i).selection_item_id) { |
| 309 LanguageLibrary::Get()->DeactivateImeProperty( | 313 CrosLibrary::Get()->GetLanguageLibrary()->DeactivateImeProperty( |
| 310 property_list.at(i).key); | 314 property_list.at(i).key); |
| 311 } | 315 } |
| 312 } | 316 } |
| 313 // Then, activate the property clicked. | 317 // Then, activate the property clicked. |
| 314 LanguageLibrary::Get()->ActivateImeProperty(key); | 318 CrosLibrary::Get()->GetLanguageLibrary()->ActivateImeProperty(key); |
| 315 } else { | 319 } else { |
| 316 // Command button like "Switch to half punctuation mode" is clicked. | 320 // Command button like "Switch to half punctuation mode" is clicked. |
| 317 // We can always use "Deactivate" for command buttons. | 321 // We can always use "Deactivate" for command buttons. |
| 318 LanguageLibrary::Get()->DeactivateImeProperty(key); | 322 CrosLibrary::Get()->GetLanguageLibrary()->DeactivateImeProperty(key); |
| 319 } | 323 } |
| 320 return; | 324 return; |
| 321 } | 325 } |
| 322 | 326 |
| 323 // Separators are not clickable. | 327 // Separators are not clickable. |
| 324 NOTREACHED(); | 328 NOTREACHED(); |
| 325 } | 329 } |
| 326 | 330 |
| 327 //////////////////////////////////////////////////////////////////////////////// | 331 //////////////////////////////////////////////////////////////////////////////// |
| 328 // LanguageMenuButton, views::ViewMenuDelegate implementation: | 332 // LanguageMenuButton, views::ViewMenuDelegate implementation: |
| 329 | 333 |
| 330 void LanguageMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 334 void LanguageMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| 331 language_list_.reset(LanguageLibrary::Get()->GetActiveLanguages()); | 335 language_list_.reset(CrosLibrary::Get()->GetLanguageLibrary()-> |
| 336 GetActiveLanguages()); |
| 332 RebuildModel(); | 337 RebuildModel(); |
| 333 language_menu_.Rebuild(); | 338 language_menu_.Rebuild(); |
| 334 language_menu_.UpdateStates(); | 339 language_menu_.UpdateStates(); |
| 335 language_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 340 language_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
| 336 } | 341 } |
| 337 | 342 |
| 338 //////////////////////////////////////////////////////////////////////////////// | 343 //////////////////////////////////////////////////////////////////////////////// |
| 339 // LanguageLibrary::Observer implementation: | 344 // LanguageLibrary::Observer implementation: |
| 340 | 345 |
| 341 void LanguageMenuButton::LanguageChanged(LanguageLibrary* obj) { | 346 void LanguageMenuButton::LanguageChanged(LanguageLibrary* obj) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 372 // We "abuse" the command_id and group_id arguments of AddRadioItem method. | 377 // We "abuse" the command_id and group_id arguments of AddRadioItem method. |
| 373 // A COMMAND_ID_XXX enum value is passed as command_id, and array index of | 378 // A COMMAND_ID_XXX enum value is passed as command_id, and array index of |
| 374 // |language_list_| or |property_list| is passed as group_id. | 379 // |language_list_| or |property_list| is passed as group_id. |
| 375 for (size_t i = 0; i < language_list_->size(); ++i) { | 380 for (size_t i = 0; i < language_list_->size(); ++i) { |
| 376 model_->AddRadioItem(COMMAND_ID_LANGUAGES, dummy_label, i); | 381 model_->AddRadioItem(COMMAND_ID_LANGUAGES, dummy_label, i); |
| 377 } | 382 } |
| 378 need_separator = true; | 383 need_separator = true; |
| 379 } | 384 } |
| 380 | 385 |
| 381 const ImePropertyList& property_list | 386 const ImePropertyList& property_list |
| 382 = LanguageLibrary::Get()->current_ime_properties(); | 387 = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); |
| 383 const InputLanguage& current_language | 388 const InputLanguage& current_language |
| 384 = LanguageLibrary::Get()->current_language(); | 389 = CrosLibrary::Get()->GetLanguageLibrary()->current_language(); |
| 385 if ((!property_list.empty()) && | 390 if ((!property_list.empty()) && |
| 386 (current_language.category == chromeos::LANGUAGE_CATEGORY_IME)) { | 391 (current_language.category == chromeos::LANGUAGE_CATEGORY_IME)) { |
| 387 if (need_separator) | 392 if (need_separator) |
| 388 model_->AddSeparator(); | 393 model_->AddSeparator(); |
| 389 for (size_t i = 0; i < property_list.size(); ++i) { | 394 for (size_t i = 0; i < property_list.size(); ++i) { |
| 390 model_->AddRadioItem(COMMAND_ID_IME_PROPERTIES, dummy_label, i); | 395 model_->AddRadioItem(COMMAND_ID_IME_PROPERTIES, dummy_label, i); |
| 391 } | 396 } |
| 392 need_separator = true; | 397 need_separator = true; |
| 393 } | 398 } |
| 394 | 399 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 DCHECK_GE(index, 0); | 432 DCHECK_GE(index, 0); |
| 428 DCHECK(model_.get()); | 433 DCHECK(model_.get()); |
| 429 | 434 |
| 430 return ((model_->GetTypeAt(index) == menus::MenuModel::TYPE_RADIO) && | 435 return ((model_->GetTypeAt(index) == menus::MenuModel::TYPE_RADIO) && |
| 431 (model_->GetCommandIdAt(index) == COMMAND_ID_CONFIGURE_IME)); | 436 (model_->GetCommandIdAt(index) == COMMAND_ID_CONFIGURE_IME)); |
| 432 } | 437 } |
| 433 | 438 |
| 434 // TODO(yusukes): Register and handle hotkeys for IME and XKB switching? | 439 // TODO(yusukes): Register and handle hotkeys for IME and XKB switching? |
| 435 | 440 |
| 436 } // namespace chromeos | 441 } // namespace chromeos |
| OLD | NEW |