Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/chromeos/status/input_method_menu.cc

Issue 7720012: Moves ownership of MenuItemView to MenuRunner as well as responbility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "content/browser/user_metrics.h" 20 #include "content/browser/user_metrics.h"
21 #include "content/common/notification_service.h" 21 #include "content/common/notification_service.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/models/simple_menu_model.h" 25 #include "ui/base/models/simple_menu_model.h"
26 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
27 #include "views/controls/menu/menu_model_adapter.h" 27 #include "views/controls/menu/menu_model_adapter.h"
28 #include "views/controls/menu/menu_runner.h"
28 #include "views/controls/menu/submenu_view.h" 29 #include "views/controls/menu/submenu_view.h"
29 #include "views/widget/widget.h" 30 #include "views/widget/widget.h"
30 31
31 // The language menu consists of 3 parts (in this order): 32 // The language menu consists of 3 parts (in this order):
32 // 33 //
33 // (1) input method names. The size of the list is always >= 1. 34 // (1) input method names. The size of the list is always >= 1.
34 // (2) input method properties. This list might be empty. 35 // (2) input method properties. This list might be empty.
35 // (3) "Customize language and input..." button. 36 // (3) "Customize language and input..." button.
36 // 37 //
37 // Example of the menu (Japanese): 38 // Example of the menu (Japanese):
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 InputMethodMenu::InputMethodMenu(PrefService* pref_service, 133 InputMethodMenu::InputMethodMenu(PrefService* pref_service,
133 StatusAreaHost::ScreenMode screen_mode, 134 StatusAreaHost::ScreenMode screen_mode,
134 bool for_out_of_box_experience_dialog) 135 bool for_out_of_box_experience_dialog)
135 : input_method_descriptors_(InputMethodManager::GetInstance()-> 136 : input_method_descriptors_(InputMethodManager::GetInstance()->
136 GetActiveInputMethods()), 137 GetActiveInputMethods()),
137 model_(new ui::SimpleMenuModel(NULL)), 138 model_(new ui::SimpleMenuModel(NULL)),
138 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_( 139 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_(
139 new views::MenuModelAdapter(this))), 140 new views::MenuModelAdapter(this))),
140 input_method_menu_( 141 input_method_menu_(
141 new views::MenuItemView(input_method_menu_delegate_.get())), 142 new views::MenuItemView(input_method_menu_delegate_.get())),
143 input_method_menu_runner_(new views::MenuRunner(input_method_menu_)),
142 minimum_input_method_menu_width_(0), 144 minimum_input_method_menu_width_(0),
143 menu_alignment_(views::MenuItemView::TOPRIGHT), 145 menu_alignment_(views::MenuItemView::TOPRIGHT),
144 pref_service_(pref_service), 146 pref_service_(pref_service),
145 screen_mode_(screen_mode), 147 screen_mode_(screen_mode),
146 for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) { 148 for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) {
147 DCHECK(input_method_descriptors_.get() && 149 DCHECK(input_method_descriptors_.get() &&
148 !input_method_descriptors_->empty()); 150 !input_method_descriptors_->empty());
149 151
150 // Sync current and previous input methods on Chrome prefs with ibus-daemon. 152 // Sync current and previous input methods on Chrome prefs with ibus-daemon.
151 if (pref_service_ && (screen_mode_ == StatusAreaHost::kBrowserMode)) { 153 if (pref_service_ && (screen_mode_ == StatusAreaHost::kBrowserMode)) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 383
382 if (minimum_input_method_menu_width_ > 0) { 384 if (minimum_input_method_menu_width_ > 0) {
383 DCHECK(input_method_menu_->HasSubmenu()); 385 DCHECK(input_method_menu_->HasSubmenu());
384 views::SubmenuView* submenu = input_method_menu_->GetSubmenu(); 386 views::SubmenuView* submenu = input_method_menu_->GetSubmenu();
385 submenu->set_minimum_preferred_width(minimum_input_method_menu_width_); 387 submenu->set_minimum_preferred_width(minimum_input_method_menu_width_);
386 } 388 }
387 389
388 gfx::Point screen_location; 390 gfx::Point screen_location;
389 views::View::ConvertPointToScreen(source, &screen_location); 391 views::View::ConvertPointToScreen(source, &screen_location);
390 gfx::Rect bounds(screen_location, source->size()); 392 gfx::Rect bounds(screen_location, source->size());
391 input_method_menu_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), 393 if (input_method_menu_runner_->RunMenuAt(
392 NULL, bounds, menu_alignment_, true); 394 source->GetWidget()->GetTopLevelWidget(), NULL, bounds,
395 menu_alignment_, views::MenuRunner::HAS_MNEMONICS) ==
396 views::MenuRunner::MENU_DELETED)
397 return;
393 } 398 }
394 399
395 //////////////////////////////////////////////////////////////////////////////// 400 ////////////////////////////////////////////////////////////////////////////////
396 // InputMethodManager::Observer implementation: 401 // InputMethodManager::Observer implementation:
397 402
398 void InputMethodMenu::InputMethodChanged( 403 void InputMethodMenu::InputMethodChanged(
399 InputMethodManager* manager, 404 InputMethodManager* manager,
400 const input_method::InputMethodDescriptor& current_input_method, 405 const input_method::InputMethodDescriptor& current_input_method,
401 size_t num_active_input_methods) { 406 size_t num_active_input_methods) {
402 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); 407 UpdateUIFromInputMethod(current_input_method, num_active_input_methods);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 // Note: We use AddSeparator() for separators, and AddRadioItem() for all 534 // Note: We use AddSeparator() for separators, and AddRadioItem() for all
530 // other items even if an item is not actually a radio item. 535 // other items even if an item is not actually a radio item.
531 if (need_separator) { 536 if (need_separator) {
532 model_->AddSeparator(); 537 model_->AddSeparator();
533 } 538 }
534 model_->AddRadioItem(COMMAND_ID_CUSTOMIZE_LANGUAGE, dummy_label, 539 model_->AddRadioItem(COMMAND_ID_CUSTOMIZE_LANGUAGE, dummy_label,
535 0 /* dummy */); 540 0 /* dummy */);
536 } 541 }
537 542
538 // Rebuild the menu from the model. 543 // Rebuild the menu from the model.
539 input_method_menu_delegate_->BuildMenu(input_method_menu_.get()); 544 input_method_menu_delegate_->BuildMenu(input_method_menu_);
540 } 545 }
541 546
542 bool InputMethodMenu::IndexIsInInputMethodList(int index) const { 547 bool InputMethodMenu::IndexIsInInputMethodList(int index) const {
543 DCHECK_GE(index, 0); 548 DCHECK_GE(index, 0);
544 DCHECK(model_.get()); 549 DCHECK(model_.get());
545 if (index >= model_->GetItemCount()) { 550 if (index >= model_->GetItemCount()) {
546 return false; 551 return false;
547 } 552 }
548 553
549 return ((model_->GetTypeAt(index) == ui::MenuModel::TYPE_RADIO) && 554 return ((model_->GetTypeAt(index) == ui::MenuModel::TYPE_RADIO) &&
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 InputMethodManager::GetInstance()->RemoveObserver(this); 685 InputMethodManager::GetInstance()->RemoveObserver(this);
681 } 686 }
682 } 687 }
683 688
684 void InputMethodMenu::SetMinimumWidth(int width) { 689 void InputMethodMenu::SetMinimumWidth(int width) {
685 // On the OOBE network selection screen, fixed width menu would be preferable. 690 // On the OOBE network selection screen, fixed width menu would be preferable.
686 minimum_input_method_menu_width_ = width; 691 minimum_input_method_menu_width_ = width;
687 } 692 }
688 693
689 } // namespace chromeos 694 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698