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

Side by Side Diff: ash/common/system/ime/tray_ime_chromeos.cc

Issue 2781793002: Remove non-MD code for IME tray and tray menu. (Closed)
Patch Set: actual rebase Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/system/ime/tray_ime_chromeos.h" 5 #include "ash/common/system/ime/tray_ime_chromeos.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/system/tray/hover_highlight_view.h"
12 #include "ash/common/system/tray/system_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
13 #include "ash/common/system/tray/system_tray_controller.h" 11 #include "ash/common/system/tray/system_tray_controller.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 12 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/system_tray_notifier.h" 13 #include "ash/common/system/tray/system_tray_notifier.h"
16 #include "ash/common/system/tray/tray_constants.h" 14 #include "ash/common/system/tray/tray_constants.h"
17 #include "ash/common/system/tray/tray_details_view.h" 15 #include "ash/common/system/tray/tray_details_view.h"
18 #include "ash/common/system/tray/tray_item_more.h" 16 #include "ash/common/system/tray/tray_item_more.h"
19 #include "ash/common/system/tray/tray_item_view.h" 17 #include "ash/common/system/tray/tray_item_view.h"
20 #include "ash/common/system/tray/tray_popup_item_style.h" 18 #include "ash/common/system/tray/tray_popup_item_style.h"
21 #include "ash/common/system/tray/tray_popup_utils.h" 19 #include "ash/common/system/tray/tray_popup_utils.h"
22 #include "ash/common/system/tray/tray_utils.h" 20 #include "ash/common/system/tray/tray_utils.h"
23 #include "ash/common/system/tray/tri_view.h" 21 #include "ash/common/system/tray/tri_view.h"
24 #include "ash/common/system/tray_accessibility.h" 22 #include "ash/common/system/tray_accessibility.h"
25 #include "ash/common/wm_shell.h" 23 #include "ash/common/wm_shell.h"
26 #include "ash/resources/grit/ash_resources.h"
27 #include "ash/resources/vector_icons/vector_icons.h" 24 #include "ash/resources/vector_icons/vector_icons.h"
28 #include "ash/shell.h" 25 #include "ash/shell.h"
29 #include "ash/strings/grit/ash_strings.h" 26 #include "ash/strings/grit/ash_strings.h"
30 #include "base/logging.h" 27 #include "base/logging.h"
31 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
32 #include "ui/accessibility/ax_enums.h" 29 #include "ui/accessibility/ax_enums.h"
33 #include "ui/accessibility/ax_node_data.h" 30 #include "ui/accessibility/ax_node_data.h"
34 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/font.h" 32 #include "ui/gfx/font.h"
37 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
38 #include "ui/gfx/paint_vector_icon.h" 34 #include "ui/gfx/paint_vector_icon.h"
39 #include "ui/keyboard/keyboard_util.h" 35 #include "ui/keyboard/keyboard_util.h"
40 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
41 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
42 #include "ui/views/layout/box_layout.h" 38 #include "ui/views/layout/box_layout.h"
43 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
44 40
45 namespace ash { 41 namespace ash {
46 namespace tray { 42 namespace tray {
47 43
48 // A |HoverHighlightView| that uses bold or normal font depending on whether
49 // it is selected. This view exposes itself as a checkbox to the accessibility
50 // framework.
51 class SelectableHoverHighlightView : public HoverHighlightView {
52 public:
53 SelectableHoverHighlightView(ViewClickListener* listener,
54 const base::string16& label,
55 bool selected)
56 : HoverHighlightView(listener), selected_(selected) {
57 AddLabel(label, gfx::ALIGN_LEFT, selected);
58 }
59
60 ~SelectableHoverHighlightView() override {}
61
62 protected:
63 // Overridden from views::View.
64 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
65 HoverHighlightView::GetAccessibleNodeData(node_data);
66 node_data->role = ui::AX_ROLE_CHECK_BOX;
67 if (selected_)
68 node_data->AddStateFlag(ui::AX_STATE_CHECKED);
69 }
70
71 private:
72 bool selected_;
73
74 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView);
75 };
76
77 class IMEDefaultView : public TrayItemMore { 44 class IMEDefaultView : public TrayItemMore {
78 public: 45 public:
79 IMEDefaultView(SystemTrayItem* owner, const base::string16& label) 46 IMEDefaultView(SystemTrayItem* owner, const base::string16& label)
80 : TrayItemMore(owner) { 47 : TrayItemMore(owner) {
81 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 48 SetImage(gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, kMenuIconColor));
82 SetImage(gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, kMenuIconColor));
83 } else {
84 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
85 SetImage(*bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME).ToImageSkia());
86 }
87 UpdateLabel(label); 49 UpdateLabel(label);
88 } 50 }
89 51
90 ~IMEDefaultView() override {} 52 ~IMEDefaultView() override {}
91 53
92 void UpdateLabel(const base::string16& label) { 54 void UpdateLabel(const base::string16& label) {
93 SetLabel(label); 55 SetLabel(label);
94 SetAccessibleName(label); 56 SetAccessibleName(label);
95 } 57 }
96 58
97 protected: 59 protected:
98 // TrayItemMore: 60 // TrayItemMore:
99 void UpdateStyle() override { 61 void UpdateStyle() override {
100 TrayItemMore::UpdateStyle(); 62 TrayItemMore::UpdateStyle();
101 63
102 if (!MaterialDesignController::IsSystemTrayMenuMaterial())
103 return;
104
105 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 64 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
106 SetImage( 65 SetImage(
107 gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, style->GetIconColor())); 66 gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, style->GetIconColor()));
108 } 67 }
109 68
110 private: 69 private:
111 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); 70 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView);
112 }; 71 };
113 72
114 class IMEDetailedView : public ImeListView { 73 class IMEDetailedView : public ImeListView {
115 public: 74 public:
116 IMEDetailedView(SystemTrayItem* owner, LoginStatus login) 75 IMEDetailedView(SystemTrayItem* owner, LoginStatus login)
117 : ImeListView(owner), 76 : ImeListView(owner), login_(login), settings_button_(nullptr) {}
118 login_(login),
119 settings_(nullptr),
120 settings_button_(nullptr) {}
121 77
122 ~IMEDetailedView() override {} 78 ~IMEDetailedView() override {}
123 79
124 void SetImeManagedMessage(base::string16 ime_managed_message) { 80 void SetImeManagedMessage(base::string16 ime_managed_message) {
125 ime_managed_message_ = ime_managed_message; 81 ime_managed_message_ = ime_managed_message;
126 } 82 }
127 83
128 void Update(const IMEInfoList& list, 84 void Update(const IMEInfoList& list,
129 const IMEPropertyInfoList& property_list, 85 const IMEPropertyInfoList& property_list,
130 bool show_keyboard_toggle, 86 bool show_keyboard_toggle,
131 SingleImeBehavior single_ime_behavior) override { 87 SingleImeBehavior single_ime_behavior) override {
132 ImeListView::Update(list, property_list, show_keyboard_toggle, 88 ImeListView::Update(list, property_list, show_keyboard_toggle,
133 single_ime_behavior); 89 single_ime_behavior);
134 if (!MaterialDesignController::IsSystemTrayMenuMaterial() &&
135 TrayPopupUtils::CanOpenWebUISettings(login_)) {
136 AppendSettings();
137 }
138
139 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME); 90 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME);
140 } 91 }
141 92
142 private: 93 private:
143 // ImeListView: 94 // ImeListView:
144 void HandleViewClicked(views::View* view) override {
145 ImeListView::HandleViewClicked(view);
146 if (view == settings_)
147 ShowSettings();
148 }
149
150 void ResetImeListView() override { 95 void ResetImeListView() override {
151 ImeListView::ResetImeListView(); 96 ImeListView::ResetImeListView();
152 settings_button_ = nullptr; 97 settings_button_ = nullptr;
153 controlled_setting_icon_ = nullptr; 98 controlled_setting_icon_ = nullptr;
154 } 99 }
155 100
156 void HandleButtonPressed(views::Button* sender, 101 void HandleButtonPressed(views::Button* sender,
157 const ui::Event& event) override { 102 const ui::Event& event) override {
158 ImeListView::HandleButtonPressed(sender, event); 103 ImeListView::HandleButtonPressed(sender, event);
159 if (sender == settings_button_) 104 if (sender == settings_button_)
160 ShowSettings(); 105 ShowSettings();
161 } 106 }
162 107
163 void CreateExtraTitleRowButtons() override { 108 void CreateExtraTitleRowButtons() override {
164 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 109 if (!ime_managed_message_.empty()) {
165 if (!ime_managed_message_.empty()) { 110 controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView();
166 controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView(); 111 controlled_setting_icon_->SetImage(
167 controlled_setting_icon_->SetImage( 112 gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor));
168 gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor)); 113 controlled_setting_icon_->SetTooltipText(ime_managed_message_);
169 controlled_setting_icon_->SetTooltipText(ime_managed_message_); 114 tri_view()->AddView(TriView::Container::END, controlled_setting_icon_);
170 tri_view()->AddView(TriView::Container::END, controlled_setting_icon_); 115 }
171 }
172 116
173 tri_view()->SetContainerVisible(TriView::Container::END, true); 117 tri_view()->SetContainerVisible(TriView::Container::END, true);
174 settings_button_ = 118 settings_button_ =
175 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_IME_SETTINGS); 119 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_IME_SETTINGS);
176 tri_view()->AddView(TriView::Container::END, settings_button_); 120 tri_view()->AddView(TriView::Container::END, settings_button_);
177 }
178 }
179
180 void AppendSettings() {
181 HoverHighlightView* container = new HoverHighlightView(this);
182 container->AddLabel(
183 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
184 IDS_ASH_STATUS_TRAY_IME_SETTINGS),
185 gfx::ALIGN_LEFT, false /* highlight */);
186 AddChildView(container);
187 settings_ = container;
188 } 121 }
189 122
190 void ShowSettings() { 123 void ShowSettings() {
191 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED); 124 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
192 Shell::Get()->system_tray_controller()->ShowIMESettings(); 125 Shell::Get()->system_tray_controller()->ShowIMESettings();
193 if (owner()->system_tray()) 126 if (owner()->system_tray())
194 owner()->system_tray()->CloseSystemBubble(); 127 owner()->system_tray()->CloseSystemBubble();
195 } 128 }
196 129
197 LoginStatus login_; 130 LoginStatus login_;
198 131
199 // Not used in material design.
200 views::View* settings_;
201
202 // Only used in material design.
203 views::Button* settings_button_; 132 views::Button* settings_button_;
204 133
205 // This icon says that the IMEs are managed by policy. 134 // This icon says that the IMEs are managed by policy.
206 views::ImageView* controlled_setting_icon_; 135 views::ImageView* controlled_setting_icon_;
207 // If non-empty, a controlled setting icon should be displayed with this 136 // If non-empty, a controlled setting icon should be displayed with this
208 // string as tooltip. 137 // string as tooltip.
209 base::string16 ime_managed_message_; 138 base::string16 ime_managed_message_;
210 139
211 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); 140 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView);
212 }; 141 };
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) { 211 base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) {
283 if (show_ime_label) { 212 if (show_ime_label) {
284 IMEInfo current; 213 IMEInfo current;
285 Shell::Get()->system_tray_delegate()->GetCurrentIME(&current); 214 Shell::Get()->system_tray_delegate()->GetCurrentIME(&current);
286 return current.name; 215 return current.name;
287 } else { 216 } else {
288 // Display virtual keyboard status instead. 217 // Display virtual keyboard status instead.
289 int id = keyboard::IsKeyboardEnabled() 218 int id = keyboard::IsKeyboardEnabled()
290 ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED 219 ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED
291 : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED; 220 : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED;
292 return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id); 221 return l10n_util::GetStringUTF16(id);
293 } 222 }
294 } 223 }
295 224
296 views::View* TrayIME::CreateTrayView(LoginStatus status) { 225 views::View* TrayIME::CreateTrayView(LoginStatus status) {
297 CHECK(tray_label_ == NULL); 226 CHECK(tray_label_ == NULL);
298 tray_label_ = new TrayItemView(this); 227 tray_label_ = new TrayItemView(this);
299 tray_label_->CreateLabel(); 228 tray_label_->CreateLabel();
300 SetupLabelForTray(tray_label_->label()); 229 SetupLabelForTray(tray_label_->label());
301 // Hide IME tray when it is created, it will be updated when it is notified 230 // Hide IME tray when it is created, it will be updated when it is notified
302 // of the IME refresh event. 231 // of the IME refresh event.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return ime_count >= threshold; 299 return ime_count >= threshold;
371 } 300 }
372 301
373 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() { 302 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() {
374 // If managed, we also want to show a single IME. 303 // If managed, we also want to show a single IME.
375 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME 304 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME
376 : ImeListView::HIDE_SINGLE_IME; 305 : ImeListView::HIDE_SINGLE_IME;
377 } 306 }
378 307
379 } // namespace ash 308 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_menu_tray.cc ('k') | ash/common/system/tray/system_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698