OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/login/keyboard_switch_menu.h" | |
6 | |
7 #include "base/i18n/rtl.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | |
10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | |
11 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | |
12 #include "grit/generated_resources.h" | |
13 #include "ui/base/l10n/l10n_util.h" | |
14 #include "views/controls/button/menu_button.h" | |
15 #include "views/widget/widget.h" | |
16 | |
17 namespace chromeos { | |
18 | |
19 KeyboardSwitchMenu::KeyboardSwitchMenu() | |
20 : InputMethodMenu(NULL /* pref_service */, | |
21 StatusAreaViewChromeos::LOGIN_MODE_VIEWS, | |
22 true /* for_out_of_box_experience_dialog */) { | |
23 } | |
24 | |
25 //////////////////////////////////////////////////////////////////////////////// | |
26 // InputMethodMenu::InputMethodMenuHost implementation. | |
27 void KeyboardSwitchMenu::UpdateUI(const std::string& input_method_id, | |
28 const string16& name, | |
29 const string16& tooltip, | |
30 size_t num_active_input_methods) { | |
31 // Update all view hierarchies so that the new input method name is shown in | |
32 // the menu button. | |
33 views::Widget::NotifyLocaleChanged(); | |
34 } | |
35 | |
36 bool KeyboardSwitchMenu::ShouldSupportConfigUI() { | |
37 return false; | |
38 } | |
39 | |
40 //////////////////////////////////////////////////////////////////////////////// | |
41 // views::ViewMenuDelegate implementation. | |
42 void KeyboardSwitchMenu::RunMenu(views::View* source, const gfx::Point& pt) { | |
43 gfx::Point new_pt(pt); | |
44 views::MenuButton* button = static_cast<views::MenuButton*>(source); | |
45 // Keyboard switch menu is aligned on left by default. MenuButton passes | |
46 // in pt the lower left corner for RTL and the lower right corner for | |
47 // non-RTL (with menu_offset applied). | |
48 int reverse_offset = button->width() + button->menu_offset().x() * 2; | |
49 if (base::i18n::IsRTL()) { | |
50 new_pt.set_x(pt.x() + reverse_offset); | |
51 } else { | |
52 new_pt.set_x(pt.x() - reverse_offset); | |
53 } | |
54 | |
55 set_menu_alignment(views::MenuItemView::TOPLEFT); | |
56 InputMethodMenu::RunMenu(source, new_pt); | |
57 } | |
58 | |
59 string16 KeyboardSwitchMenu::GetCurrentKeyboardName() const { | |
60 const int count = GetItemCount(); | |
61 for (int i = 0; i < count; ++i) { | |
62 if (IsItemCheckedAt(i)) | |
63 return GetLabelAt(i); | |
64 } | |
65 VLOG(1) << "The input method menu is not ready yet. Show the display " | |
66 << "name of the current input method"; | |
67 input_method::InputMethodManager* manager = | |
68 input_method::InputMethodManager::GetInstance(); | |
69 return UTF8ToUTF16( | |
70 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId( | |
71 manager->current_input_method().id())); | |
72 } | |
73 | |
74 } // namespace chromeos | |
OLD | NEW |