OLD | NEW |
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" | 9 #include "ash/common/material_design/material_design_controller.h" |
10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | |
12 #include "ash/common/system/tray/hover_highlight_view.h" | 11 #include "ash/common/system/tray/hover_highlight_view.h" |
13 #include "ash/common/system/tray/system_tray.h" | 12 #include "ash/common/system/tray/system_tray.h" |
14 #include "ash/common/system/tray/system_tray_controller.h" | 13 #include "ash/common/system/tray/system_tray_controller.h" |
15 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
16 #include "ash/common/system/tray/system_tray_notifier.h" | 15 #include "ash/common/system/tray/system_tray_notifier.h" |
17 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
18 #include "ash/common/system/tray/tray_details_view.h" | 17 #include "ash/common/system/tray/tray_details_view.h" |
19 #include "ash/common/system/tray/tray_item_more.h" | 18 #include "ash/common/system/tray/tray_item_more.h" |
20 #include "ash/common/system/tray/tray_item_view.h" | 19 #include "ash/common/system/tray/tray_item_view.h" |
21 #include "ash/common/system/tray/tray_popup_item_style.h" | 20 #include "ash/common/system/tray/tray_popup_item_style.h" |
22 #include "ash/common/system/tray/tray_popup_utils.h" | 21 #include "ash/common/system/tray/tray_popup_utils.h" |
23 #include "ash/common/system/tray/tray_utils.h" | 22 #include "ash/common/system/tray/tray_utils.h" |
24 #include "ash/common/system/tray/tri_view.h" | 23 #include "ash/common/system/tray/tri_view.h" |
25 #include "ash/common/system/tray_accessibility.h" | 24 #include "ash/common/system/tray_accessibility.h" |
26 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
27 #include "ash/resources/vector_icons/vector_icons.h" | 26 #include "ash/resources/vector_icons/vector_icons.h" |
28 #include "base/logging.h" | 27 #include "base/logging.h" |
29 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
30 #include "grit/ash_resources.h" | 29 #include "grit/ash_resources.h" |
31 #include "grit/ash_strings.h" | 30 #include "grit/ash_strings.h" |
32 #include "ui/accessibility/ax_enums.h" | 31 #include "ui/accessibility/ax_enums.h" |
33 #include "ui/accessibility/ax_node_data.h" | 32 #include "ui/accessibility/ax_node_data.h" |
| 33 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
35 #include "ui/gfx/font.h" | 35 #include "ui/gfx/font.h" |
36 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" |
37 #include "ui/gfx/paint_vector_icon.h" | 37 #include "ui/gfx/paint_vector_icon.h" |
38 #include "ui/keyboard/keyboard_util.h" | 38 #include "ui/keyboard/keyboard_util.h" |
| 39 #include "ui/views/controls/image_view.h" |
39 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
40 #include "ui/views/layout/box_layout.h" | 41 #include "ui/views/layout/box_layout.h" |
41 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
42 | 43 |
43 namespace ash { | 44 namespace ash { |
44 namespace tray { | 45 namespace tray { |
45 | 46 |
46 // A |HoverHighlightView| that uses bold or normal font depending on whether | 47 // A |HoverHighlightView| that uses bold or normal font depending on whether |
47 // it is selected. This view exposes itself as a checkbox to the accessibility | 48 // it is selected. This view exposes itself as a checkbox to the accessibility |
48 // framework. | 49 // framework. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 107 } |
107 | 108 |
108 private: | 109 private: |
109 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); | 110 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); |
110 }; | 111 }; |
111 | 112 |
112 class IMEDetailedView : public ImeListView { | 113 class IMEDetailedView : public ImeListView { |
113 public: | 114 public: |
114 IMEDetailedView(SystemTrayItem* owner, | 115 IMEDetailedView(SystemTrayItem* owner, |
115 LoginStatus login, | 116 LoginStatus login, |
116 bool show_keyboard_toggle) | 117 bool show_keyboard_toggle, |
117 : ImeListView(owner, show_keyboard_toggle, ImeListView::HIDE_SINGLE_IME), | 118 SingleImeBehavior single_ime_behavior, |
| 119 base::string16 ime_managed_message) |
| 120 : ImeListView(owner, show_keyboard_toggle, single_ime_behavior), |
118 login_(login), | 121 login_(login), |
119 settings_(nullptr), | 122 settings_(nullptr), |
120 settings_button_(nullptr) { | 123 settings_button_(nullptr) { |
121 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 124 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
122 IMEInfoList list; | 125 IMEInfoList list; |
123 delegate->GetAvailableIMEList(&list); | 126 delegate->GetAvailableIMEList(&list); |
124 IMEPropertyInfoList property_list; | 127 IMEPropertyInfoList property_list; |
125 delegate->GetCurrentIMEProperties(&property_list); | 128 delegate->GetCurrentIMEProperties(&property_list); |
126 Update(list, property_list, show_keyboard_toggle, | 129 Update(list, property_list, show_keyboard_toggle, single_ime_behavior, |
127 ImeListView::HIDE_SINGLE_IME); | 130 ime_managed_message); |
128 } | 131 } |
129 | 132 |
130 ~IMEDetailedView() override {} | 133 ~IMEDetailedView() override {} |
131 | 134 |
132 void Update(const IMEInfoList& list, | 135 void Update(const IMEInfoList& list, |
133 const IMEPropertyInfoList& property_list, | 136 const IMEPropertyInfoList& property_list, |
134 bool show_keyboard_toggle, | 137 bool show_keyboard_toggle, |
135 SingleImeBehavior single_ime_behavior) override { | 138 SingleImeBehavior single_ime_behavior) override { |
136 ImeListView::Update(list, property_list, show_keyboard_toggle, | 139 ImeListView::Update(list, property_list, show_keyboard_toggle, |
137 single_ime_behavior); | 140 single_ime_behavior); |
138 if (!MaterialDesignController::IsSystemTrayMenuMaterial() && | 141 if (!MaterialDesignController::IsSystemTrayMenuMaterial() && |
139 TrayPopupUtils::CanOpenWebUISettings(login_)) { | 142 TrayPopupUtils::CanOpenWebUISettings(login_)) { |
140 AppendSettings(); | 143 AppendSettings(); |
141 } | 144 } |
142 | 145 |
143 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME); | 146 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME); |
144 } | 147 } |
145 | 148 |
| 149 void Update(const IMEInfoList& list, |
| 150 const IMEPropertyInfoList& property_list, |
| 151 bool show_keyboard_toggle, |
| 152 SingleImeBehavior single_ime_behavior, |
| 153 base::string16 ime_managed_message) { |
| 154 ime_managed_message_ = ime_managed_message; |
| 155 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
| 156 } |
| 157 |
146 private: | 158 private: |
147 // ImeListView: | 159 // ImeListView: |
148 void HandleViewClicked(views::View* view) override { | 160 void HandleViewClicked(views::View* view) override { |
149 ImeListView::HandleViewClicked(view); | 161 ImeListView::HandleViewClicked(view); |
150 if (view == settings_) | 162 if (view == settings_) |
151 ShowSettings(); | 163 ShowSettings(); |
152 } | 164 } |
153 | 165 |
154 void ResetImeListView() override { | 166 void ResetImeListView() override { |
155 ImeListView::ResetImeListView(); | 167 ImeListView::ResetImeListView(); |
156 settings_button_ = nullptr; | 168 settings_button_ = nullptr; |
| 169 controlled_setting_icon_ = nullptr; |
157 } | 170 } |
158 | 171 |
159 void HandleButtonPressed(views::Button* sender, | 172 void HandleButtonPressed(views::Button* sender, |
160 const ui::Event& event) override { | 173 const ui::Event& event) override { |
161 ImeListView::HandleButtonPressed(sender, event); | 174 ImeListView::HandleButtonPressed(sender, event); |
162 if (sender == settings_button_) | 175 if (sender == settings_button_) |
163 ShowSettings(); | 176 ShowSettings(); |
164 } | 177 } |
165 | 178 |
166 void CreateExtraTitleRowButtons() override { | 179 void CreateExtraTitleRowButtons() override { |
167 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 180 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 181 if (!ime_managed_message_.empty()) { |
| 182 controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView(); |
| 183 controlled_setting_icon_->SetImage( |
| 184 gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor)); |
| 185 controlled_setting_icon_->SetTooltipText(ime_managed_message_); |
| 186 tri_view()->AddView(TriView::Container::END, controlled_setting_icon_); |
| 187 } |
| 188 |
168 tri_view()->SetContainerVisible(TriView::Container::END, true); | 189 tri_view()->SetContainerVisible(TriView::Container::END, true); |
169 settings_button_ = CreateSettingsButton(login_); | 190 settings_button_ = CreateSettingsButton(login_); |
170 tri_view()->AddView(TriView::Container::END, settings_button_); | 191 tri_view()->AddView(TriView::Container::END, settings_button_); |
171 } | 192 } |
172 } | 193 } |
173 | 194 |
174 void AppendSettings() { | 195 void AppendSettings() { |
175 HoverHighlightView* container = new HoverHighlightView(this); | 196 HoverHighlightView* container = new HoverHighlightView(this); |
176 container->AddLabel( | 197 container->AddLabel( |
177 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 198 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
(...skipping 11 matching lines...) Expand all Loading... |
189 } | 210 } |
190 | 211 |
191 LoginStatus login_; | 212 LoginStatus login_; |
192 | 213 |
193 // Not used in material design. | 214 // Not used in material design. |
194 views::View* settings_; | 215 views::View* settings_; |
195 | 216 |
196 // Only used in material design. | 217 // Only used in material design. |
197 views::Button* settings_button_; | 218 views::Button* settings_button_; |
198 | 219 |
| 220 // This icon says that the IMEs are managed by policy. |
| 221 views::ImageView* controlled_setting_icon_; |
| 222 // If non-empty, a controlled setting icon should be displayed with this |
| 223 // string as tooltip. |
| 224 base::string16 ime_managed_message_; |
| 225 |
199 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 226 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
200 }; | 227 }; |
201 | 228 |
202 } // namespace tray | 229 } // namespace tray |
203 | 230 |
204 TrayIME::TrayIME(SystemTray* system_tray) | 231 TrayIME::TrayIME(SystemTray* system_tray) |
205 : SystemTrayItem(system_tray, UMA_IME), | 232 : SystemTrayItem(system_tray, UMA_IME), |
206 tray_label_(NULL), | 233 tray_label_(NULL), |
207 default_(NULL), | 234 default_(NULL), |
208 detailed_(NULL), | 235 detailed_(NULL), |
(...skipping 23 matching lines...) Expand all Loading... |
232 } | 259 } |
233 | 260 |
234 void TrayIME::Update() { | 261 void TrayIME::Update() { |
235 UpdateTrayLabel(current_ime_, ime_list_.size()); | 262 UpdateTrayLabel(current_ime_, ime_list_.size()); |
236 if (default_) { | 263 if (default_) { |
237 default_->SetVisible(ShouldDefaultViewBeVisible()); | 264 default_->SetVisible(ShouldDefaultViewBeVisible()); |
238 default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1)); | 265 default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1)); |
239 } | 266 } |
240 if (detailed_) | 267 if (detailed_) |
241 detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle(), | 268 detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle(), |
242 ImeListView::HIDE_SINGLE_IME); | 269 GetSingleImeBehavior(), ime_managed_message_); |
243 } | 270 } |
244 | 271 |
245 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 272 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
246 if (tray_label_) { | 273 if (tray_label_) { |
247 bool visible = count > 1 && is_visible_; | 274 bool visible = ShouldShowImeTrayItem(count) && is_visible_; |
248 tray_label_->SetVisible(visible); | 275 tray_label_->SetVisible(visible); |
249 // Do not change label before hiding because this change is noticeable. | 276 // Do not change label before hiding because this change is noticeable. |
250 if (!visible) | 277 if (!visible) |
251 return; | 278 return; |
252 if (current.third_party) { | 279 if (current.third_party) { |
253 tray_label_->label()->SetText(current.short_name + | 280 tray_label_->label()->SetText(current.short_name + |
254 base::UTF8ToUTF16("*")); | 281 base::UTF8ToUTF16("*")); |
255 } else { | 282 } else { |
256 tray_label_->label()->SetText(current.short_name); | 283 tray_label_->label()->SetText(current.short_name); |
257 } | 284 } |
(...skipping 27 matching lines...) Expand all Loading... |
285 tray_label_->CreateLabel(); | 312 tray_label_->CreateLabel(); |
286 SetupLabelForTray(tray_label_->label()); | 313 SetupLabelForTray(tray_label_->label()); |
287 // Hide IME tray when it is created, it will be updated when it is notified | 314 // Hide IME tray when it is created, it will be updated when it is notified |
288 // of the IME refresh event. | 315 // of the IME refresh event. |
289 tray_label_->SetVisible(false); | 316 tray_label_->SetVisible(false); |
290 return tray_label_; | 317 return tray_label_; |
291 } | 318 } |
292 | 319 |
293 views::View* TrayIME::CreateDefaultView(LoginStatus status) { | 320 views::View* TrayIME::CreateDefaultView(LoginStatus status) { |
294 CHECK(default_ == NULL); | 321 CHECK(default_ == NULL); |
295 default_ = | 322 default_ = new tray::IMEDefaultView( |
296 new tray::IMEDefaultView(this, GetDefaultViewLabel(ime_list_.size() > 1)); | 323 this, GetDefaultViewLabel(ShouldShowImeTrayItem(ime_list_.size()))); |
297 default_->SetVisible(ShouldDefaultViewBeVisible()); | 324 default_->SetVisible(ShouldDefaultViewBeVisible()); |
298 return default_; | 325 return default_; |
299 } | 326 } |
300 | 327 |
301 views::View* TrayIME::CreateDetailedView(LoginStatus status) { | 328 views::View* TrayIME::CreateDetailedView(LoginStatus status) { |
302 CHECK(detailed_ == NULL); | 329 CHECK(detailed_ == NULL); |
303 detailed_ = | 330 detailed_ = |
304 new tray::IMEDetailedView(this, status, ShouldShowKeyboardToggle()); | 331 new tray::IMEDetailedView(this, status, ShouldShowKeyboardToggle(), |
| 332 GetSingleImeBehavior(), ime_managed_message_); |
305 return detailed_; | 333 return detailed_; |
306 } | 334 } |
307 | 335 |
308 void TrayIME::DestroyTrayView() { | 336 void TrayIME::DestroyTrayView() { |
309 tray_label_ = NULL; | 337 tray_label_ = NULL; |
310 } | 338 } |
311 | 339 |
312 void TrayIME::DestroyDefaultView() { | 340 void TrayIME::DestroyDefaultView() { |
313 default_ = NULL; | 341 default_ = NULL; |
314 } | 342 } |
(...skipping 10 matching lines...) Expand all Loading... |
325 } | 353 } |
326 | 354 |
327 void TrayIME::OnIMERefresh() { | 355 void TrayIME::OnIMERefresh() { |
328 // Caches the current ime state. | 356 // Caches the current ime state. |
329 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 357 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
330 ime_list_.clear(); | 358 ime_list_.clear(); |
331 property_list_.clear(); | 359 property_list_.clear(); |
332 delegate->GetCurrentIME(¤t_ime_); | 360 delegate->GetCurrentIME(¤t_ime_); |
333 delegate->GetAvailableIMEList(&ime_list_); | 361 delegate->GetAvailableIMEList(&ime_list_); |
334 delegate->GetCurrentIMEProperties(&property_list_); | 362 delegate->GetCurrentIMEProperties(&property_list_); |
| 363 ime_managed_message_ = delegate->GetIMEManagedMessage(); |
335 | 364 |
336 Update(); | 365 Update(); |
337 } | 366 } |
338 | 367 |
339 void TrayIME::OnIMEMenuActivationChanged(bool is_active) { | 368 void TrayIME::OnIMEMenuActivationChanged(bool is_active) { |
340 is_visible_ = !is_active; | 369 is_visible_ = !is_active; |
341 if (is_visible_) | 370 if (is_visible_) |
342 OnIMERefresh(); | 371 OnIMERefresh(); |
343 else | 372 else |
344 Update(); | 373 Update(); |
345 } | 374 } |
346 | 375 |
| 376 bool TrayIME::IsIMEManaged() { |
| 377 return !ime_managed_message_.empty(); |
| 378 } |
| 379 |
347 bool TrayIME::ShouldDefaultViewBeVisible() { | 380 bool TrayIME::ShouldDefaultViewBeVisible() { |
348 return is_visible_ && (ime_list_.size() > 1 || property_list_.size() > 1 || | 381 return is_visible_ && |
349 ShouldShowKeyboardToggle()); | 382 (ShouldShowImeTrayItem(ime_list_.size()) || |
| 383 property_list_.size() > 1 || ShouldShowKeyboardToggle()); |
| 384 } |
| 385 |
| 386 bool TrayIME::ShouldShowImeTrayItem(size_t ime_count) { |
| 387 // If managed, we want to show the tray icon even if there's only one input |
| 388 // method to choose from. |
| 389 size_t threshold = IsIMEManaged() ? 1 : 2; |
| 390 return ime_count >= threshold; |
| 391 } |
| 392 |
| 393 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() { |
| 394 // If managed, we also want to show a single IME. |
| 395 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME |
| 396 : ImeListView::HIDE_SINGLE_IME; |
350 } | 397 } |
351 | 398 |
352 } // namespace ash | 399 } // namespace ash |
OLD | NEW |