| 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.h" | 5 #include "chrome/browser/chromeos/status/input_method_menu.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" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 371 |
| 372 void InputMethodMenu::RunMenu( | 372 void InputMethodMenu::RunMenu( |
| 373 views::View* unused_source, const gfx::Point& pt) { | 373 views::View* unused_source, const gfx::Point& pt) { |
| 374 PrepareForMenuOpen(); | 374 PrepareForMenuOpen(); |
| 375 input_method_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 375 input_method_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
| 376 } | 376 } |
| 377 | 377 |
| 378 //////////////////////////////////////////////////////////////////////////////// | 378 //////////////////////////////////////////////////////////////////////////////// |
| 379 // InputMethodLibrary::Observer implementation: | 379 // InputMethodLibrary::Observer implementation: |
| 380 | 380 |
| 381 void InputMethodMenu::InputMethodChanged(InputMethodLibrary* obj) { | 381 void InputMethodMenu::InputMethodChanged( |
| 382 InputMethodLibrary* obj, |
| 383 const InputMethodDescriptor& previous_input_method, |
| 384 const InputMethodDescriptor& current_input_method, |
| 385 size_t num_active_input_methods) { |
| 382 UserMetrics::RecordAction( | 386 UserMetrics::RecordAction( |
| 383 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); | 387 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); |
| 388 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); |
| 389 } |
| 384 | 390 |
| 385 const InputMethodDescriptor& previous_input_method = | 391 void InputMethodMenu::PreferenceUpdateNeeded( |
| 386 obj->previous_input_method(); | 392 InputMethodLibrary* obj, |
| 387 const InputMethodDescriptor& current_input_method = | 393 const InputMethodDescriptor& previous_input_method, |
| 388 obj->current_input_method(); | 394 const InputMethodDescriptor& current_input_method) { |
| 389 UpdateUIFromInputMethod(current_input_method); | |
| 390 // Update Chrome prefs as well. | |
| 391 if (is_browser_mode_) { | 395 if (is_browser_mode_) { |
| 392 if (pref_service_) { // make sure we're not in unit tests. | 396 if (pref_service_) { // make sure we're not in unit tests. |
| 393 // Sometimes (e.g. initial boot) |previous_input_method.id| is empty. | 397 // Sometimes (e.g. initial boot) |previous_input_method.id| is empty. |
| 394 previous_input_method_pref_.SetValue(previous_input_method.id); | 398 previous_input_method_pref_.SetValue(previous_input_method.id); |
| 395 current_input_method_pref_.SetValue(current_input_method.id); | 399 current_input_method_pref_.SetValue(current_input_method.id); |
| 396 } | 400 } |
| 397 } else { | 401 } else { |
| 398 // We're in the login screen (i.e. not in the normal browser mode nor screen | 402 // We're in the login screen (i.e. not in the normal browser mode nor screen |
| 399 // locker mode). If a user has already logged in, we should not update the | 403 // locker mode). If a user has already logged in, we should not update the |
| 400 // local state since a profile for the user might be loaded before the | 404 // local state since a profile for the user might be loaded before the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 411 UserMetrics::RecordAction(UserMetricsAction("LanguageMenuButton_Open")); | 415 UserMetrics::RecordAction(UserMetricsAction("LanguageMenuButton_Open")); |
| 412 input_method_descriptors_.reset(CrosLibrary::Get()->GetInputMethodLibrary()-> | 416 input_method_descriptors_.reset(CrosLibrary::Get()->GetInputMethodLibrary()-> |
| 413 GetActiveInputMethods()); | 417 GetActiveInputMethods()); |
| 414 RebuildModel(); | 418 RebuildModel(); |
| 415 input_method_menu_.Rebuild(); | 419 input_method_menu_.Rebuild(); |
| 416 if (minimum_input_method_menu_width_ > 0) { | 420 if (minimum_input_method_menu_width_ > 0) { |
| 417 input_method_menu_.SetMinimumWidth(minimum_input_method_menu_width_); | 421 input_method_menu_.SetMinimumWidth(minimum_input_method_menu_width_); |
| 418 } | 422 } |
| 419 } | 423 } |
| 420 | 424 |
| 421 void InputMethodMenu::ActiveInputMethodsChanged(InputMethodLibrary* obj) { | 425 void InputMethodMenu::ActiveInputMethodsChanged( |
| 426 InputMethodLibrary* obj, |
| 427 const InputMethodDescriptor& current_input_method, |
| 428 size_t num_active_input_methods) { |
| 422 // Update the icon if active input methods are changed. See also | 429 // Update the icon if active input methods are changed. See also |
| 423 // comments in UpdateUI() | 430 // comments in UpdateUI() in input_method_menu_button.cc. |
| 424 UpdateUIFromInputMethod(obj->current_input_method()); | 431 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); |
| 425 } | |
| 426 | |
| 427 void InputMethodMenu::ImePropertiesChanged(InputMethodLibrary* obj) { | |
| 428 } | 432 } |
| 429 | 433 |
| 430 void InputMethodMenu::UpdateUIFromInputMethod( | 434 void InputMethodMenu::UpdateUIFromInputMethod( |
| 431 const InputMethodDescriptor& input_method) { | 435 const InputMethodDescriptor& input_method, |
| 436 size_t num_active_input_methods) { |
| 432 const std::wstring name = GetTextForIndicator(input_method); | 437 const std::wstring name = GetTextForIndicator(input_method); |
| 433 const std::wstring tooltip = GetTextForMenu(input_method); | 438 const std::wstring tooltip = GetTextForMenu(input_method); |
| 434 UpdateUI(name, tooltip); | 439 UpdateUI(input_method.id, name, tooltip, num_active_input_methods); |
| 435 } | 440 } |
| 436 | 441 |
| 437 void InputMethodMenu::RebuildModel() { | 442 void InputMethodMenu::RebuildModel() { |
| 438 model_.reset(new menus::SimpleMenuModel(NULL)); | 443 model_.reset(new menus::SimpleMenuModel(NULL)); |
| 439 string16 dummy_label = UTF8ToUTF16(""); | 444 string16 dummy_label = UTF8ToUTF16(""); |
| 440 // Indicates if separator's needed before each section. | 445 // Indicates if separator's needed before each section. |
| 441 bool need_separator = false; | 446 bool need_separator = false; |
| 442 | 447 |
| 443 if (!input_method_descriptors_->empty()) { | 448 if (!input_method_descriptors_->empty()) { |
| 444 // We "abuse" the command_id and group_id arguments of AddRadioItem method. | 449 // We "abuse" the command_id and group_id arguments of AddRadioItem method. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 logged_in_ = true; | 611 logged_in_ = true; |
| 607 } | 612 } |
| 608 } | 613 } |
| 609 | 614 |
| 610 void InputMethodMenu::SetMinimumWidth(int width) { | 615 void InputMethodMenu::SetMinimumWidth(int width) { |
| 611 // On the OOBE network selection screen, fixed width menu would be preferable. | 616 // On the OOBE network selection screen, fixed width menu would be preferable. |
| 612 minimum_input_method_menu_width_ = width; | 617 minimum_input_method_menu_width_ = width; |
| 613 } | 618 } |
| 614 | 619 |
| 615 } // namespace chromeos | 620 } // namespace chromeos |
| OLD | NEW |