| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 15 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 16 #include "chrome/browser/chromeos/language_preferences.h" | 16 #include "chrome/browser/chromeos/language_preferences.h" |
| 17 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | 17 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "content/browser/user_metrics.h" | |
| 22 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/user_metrics.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/models/simple_menu_model.h" | 26 #include "ui/base/models/simple_menu_model.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/views/controls/menu/menu_model_adapter.h" | 28 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 29 #include "ui/views/controls/menu/menu_runner.h" | 29 #include "ui/views/controls/menu/menu_runner.h" |
| 30 #include "ui/views/controls/menu/submenu_view.h" | 30 #include "ui/views/controls/menu/submenu_view.h" |
| 31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 32 | 32 |
| 33 using content::UserMetricsAction; |
| 34 |
| 33 // The language menu consists of 3 parts (in this order): | 35 // The language menu consists of 3 parts (in this order): |
| 34 // | 36 // |
| 35 // (1) input method names. The size of the list is always >= 1. | 37 // (1) input method names. The size of the list is always >= 1. |
| 36 // (2) input method properties. This list might be empty. | 38 // (2) input method properties. This list might be empty. |
| 37 // (3) "Customize language and input..." button. | 39 // (3) "Customize language and input..." button. |
| 38 // | 40 // |
| 39 // Example of the menu (Japanese): | 41 // Example of the menu (Japanese): |
| 40 // | 42 // |
| 41 // ============================== (border of the popup window) | 43 // ============================== (border of the popup window) |
| 42 // [ ] English (|index| in the following functions is 0) | 44 // [ ] English (|index| in the following functions is 0) |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 OpenConfigUI(); | 349 OpenConfigUI(); |
| 348 return; | 350 return; |
| 349 } | 351 } |
| 350 | 352 |
| 351 if (IndexIsInInputMethodList(index)) { | 353 if (IndexIsInInputMethodList(index)) { |
| 352 // Inter-IME switching. | 354 // Inter-IME switching. |
| 353 const input_method::InputMethodDescriptor& input_method | 355 const input_method::InputMethodDescriptor& input_method |
| 354 = input_method_descriptors_->at(index); | 356 = input_method_descriptors_->at(index); |
| 355 InputMethodManager::GetInstance()->ChangeInputMethod( | 357 InputMethodManager::GetInstance()->ChangeInputMethod( |
| 356 input_method.id()); | 358 input_method.id()); |
| 357 UserMetrics::RecordAction( | 359 content::RecordAction( |
| 358 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); | 360 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); |
| 359 return; | 361 return; |
| 360 } | 362 } |
| 361 | 363 |
| 362 if (GetPropertyIndex(index, &index)) { | 364 if (GetPropertyIndex(index, &index)) { |
| 363 // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). | 365 // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). |
| 364 const input_method::ImePropertyList& property_list | 366 const input_method::ImePropertyList& property_list |
| 365 = InputMethodManager::GetInstance()->current_ime_properties(); | 367 = InputMethodManager::GetInstance()->current_ime_properties(); |
| 366 const std::string key = property_list.at(index).key; | 368 const std::string key = property_list.at(index).key; |
| 367 if (property_list.at(index).is_selection_item) { | 369 if (property_list.at(index).is_selection_item) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 483 } |
| 482 const std::string current_input_method_id = | 484 const std::string current_input_method_id = |
| 483 current_input_method_pref_.GetValue(); | 485 current_input_method_pref_.GetValue(); |
| 484 if (!current_input_method_id.empty()) { | 486 if (!current_input_method_id.empty()) { |
| 485 manager->ChangeInputMethod(current_input_method_id); | 487 manager->ChangeInputMethod(current_input_method_id); |
| 486 } | 488 } |
| 487 } | 489 } |
| 488 } | 490 } |
| 489 | 491 |
| 490 void InputMethodMenu::PrepareForMenuOpen() { | 492 void InputMethodMenu::PrepareForMenuOpen() { |
| 491 UserMetrics::RecordAction(UserMetricsAction("LanguageMenuButton_Open")); | 493 content::RecordAction(UserMetricsAction("LanguageMenuButton_Open")); |
| 492 PrepareMenuModel(); | 494 PrepareMenuModel(); |
| 493 } | 495 } |
| 494 | 496 |
| 495 void InputMethodMenu::PrepareMenuModel() { | 497 void InputMethodMenu::PrepareMenuModel() { |
| 496 input_method_descriptors_.reset(InputMethodManager::GetInstance()-> | 498 input_method_descriptors_.reset(InputMethodManager::GetInstance()-> |
| 497 GetActiveInputMethods()); | 499 GetActiveInputMethods()); |
| 498 RebuildModel(); | 500 RebuildModel(); |
| 499 } | 501 } |
| 500 | 502 |
| 501 void InputMethodMenu::ActiveInputMethodsChanged( | 503 void InputMethodMenu::ActiveInputMethodsChanged( |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 } | 745 } |
| 744 | 746 |
| 745 void InputMethodMenu::InitializePrefMembers() { | 747 void InputMethodMenu::InitializePrefMembers() { |
| 746 previous_input_method_pref_.Init( | 748 previous_input_method_pref_.Init( |
| 747 prefs::kLanguagePreviousInputMethod, pref_service_, this); | 749 prefs::kLanguagePreviousInputMethod, pref_service_, this); |
| 748 current_input_method_pref_.Init( | 750 current_input_method_pref_.Init( |
| 749 prefs::kLanguageCurrentInputMethod, pref_service_, this); | 751 prefs::kLanguageCurrentInputMethod, pref_service_, this); |
| 750 } | 752 } |
| 751 | 753 |
| 752 } // namespace chromeos | 754 } // namespace chromeos |
| OLD | NEW |