| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 class IMEDetailedView : public ImeListView { | 113 class IMEDetailedView : public ImeListView { |
| 113 public: | 114 public: |
| 114 IMEDetailedView(SystemTrayItem* owner, LoginStatus login) | 115 IMEDetailedView(SystemTrayItem* owner, LoginStatus login) |
| 115 : ImeListView(owner), | 116 : ImeListView(owner), |
| 116 login_(login), | 117 login_(login), |
| 117 settings_(nullptr), | 118 settings_(nullptr), |
| 118 settings_button_(nullptr) {} | 119 settings_button_(nullptr) {} |
| 119 | 120 |
| 120 ~IMEDetailedView() override {} | 121 ~IMEDetailedView() override {} |
| 121 | 122 |
| 123 void SetImeManagedMessage(base::string16 ime_managed_message) { |
| 124 ime_managed_message_ = ime_managed_message; |
| 125 } |
| 126 |
| 122 void Update(const IMEInfoList& list, | 127 void Update(const IMEInfoList& list, |
| 123 const IMEPropertyInfoList& property_list, | 128 const IMEPropertyInfoList& property_list, |
| 124 bool show_keyboard_toggle, | 129 bool show_keyboard_toggle, |
| 125 SingleImeBehavior single_ime_behavior) override { | 130 SingleImeBehavior single_ime_behavior) override { |
| 126 ImeListView::Update(list, property_list, show_keyboard_toggle, | 131 ImeListView::Update(list, property_list, show_keyboard_toggle, |
| 127 single_ime_behavior); | 132 single_ime_behavior); |
| 128 if (!MaterialDesignController::IsSystemTrayMenuMaterial() && | 133 if (!MaterialDesignController::IsSystemTrayMenuMaterial() && |
| 129 TrayPopupUtils::CanOpenWebUISettings(login_)) { | 134 TrayPopupUtils::CanOpenWebUISettings(login_)) { |
| 130 AppendSettings(); | 135 AppendSettings(); |
| 131 } | 136 } |
| 132 | 137 |
| 133 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME); | 138 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME); |
| 134 } | 139 } |
| 135 | 140 |
| 136 private: | 141 private: |
| 137 // ImeListView: | 142 // ImeListView: |
| 138 void HandleViewClicked(views::View* view) override { | 143 void HandleViewClicked(views::View* view) override { |
| 139 ImeListView::HandleViewClicked(view); | 144 ImeListView::HandleViewClicked(view); |
| 140 if (view == settings_) | 145 if (view == settings_) |
| 141 ShowSettings(); | 146 ShowSettings(); |
| 142 } | 147 } |
| 143 | 148 |
| 144 void ResetImeListView() override { | 149 void ResetImeListView() override { |
| 145 ImeListView::ResetImeListView(); | 150 ImeListView::ResetImeListView(); |
| 146 settings_button_ = nullptr; | 151 settings_button_ = nullptr; |
| 152 controlled_setting_icon_ = nullptr; |
| 147 } | 153 } |
| 148 | 154 |
| 149 void HandleButtonPressed(views::Button* sender, | 155 void HandleButtonPressed(views::Button* sender, |
| 150 const ui::Event& event) override { | 156 const ui::Event& event) override { |
| 151 ImeListView::HandleButtonPressed(sender, event); | 157 ImeListView::HandleButtonPressed(sender, event); |
| 152 if (sender == settings_button_) | 158 if (sender == settings_button_) |
| 153 ShowSettings(); | 159 ShowSettings(); |
| 154 } | 160 } |
| 155 | 161 |
| 156 void CreateExtraTitleRowButtons() override { | 162 void CreateExtraTitleRowButtons() override { |
| 157 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 163 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 164 if (!ime_managed_message_.empty()) { |
| 165 controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView(); |
| 166 controlled_setting_icon_->SetImage( |
| 167 gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor)); |
| 168 controlled_setting_icon_->SetTooltipText(ime_managed_message_); |
| 169 tri_view()->AddView(TriView::Container::END, controlled_setting_icon_); |
| 170 } |
| 171 |
| 158 tri_view()->SetContainerVisible(TriView::Container::END, true); | 172 tri_view()->SetContainerVisible(TriView::Container::END, true); |
| 159 settings_button_ = CreateSettingsButton(login_); | 173 settings_button_ = CreateSettingsButton(login_); |
| 160 tri_view()->AddView(TriView::Container::END, settings_button_); | 174 tri_view()->AddView(TriView::Container::END, settings_button_); |
| 161 } | 175 } |
| 162 } | 176 } |
| 163 | 177 |
| 164 void AppendSettings() { | 178 void AppendSettings() { |
| 165 HoverHighlightView* container = new HoverHighlightView(this); | 179 HoverHighlightView* container = new HoverHighlightView(this); |
| 166 container->AddLabel( | 180 container->AddLabel( |
| 167 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 181 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 } | 193 } |
| 180 | 194 |
| 181 LoginStatus login_; | 195 LoginStatus login_; |
| 182 | 196 |
| 183 // Not used in material design. | 197 // Not used in material design. |
| 184 views::View* settings_; | 198 views::View* settings_; |
| 185 | 199 |
| 186 // Only used in material design. | 200 // Only used in material design. |
| 187 views::Button* settings_button_; | 201 views::Button* settings_button_; |
| 188 | 202 |
| 203 // This icon says that the IMEs are managed by policy. |
| 204 views::ImageView* controlled_setting_icon_; |
| 205 // If non-empty, a controlled setting icon should be displayed with this |
| 206 // string as tooltip. |
| 207 base::string16 ime_managed_message_; |
| 208 |
| 189 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 209 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
| 190 }; | 210 }; |
| 191 | 211 |
| 192 } // namespace tray | 212 } // namespace tray |
| 193 | 213 |
| 194 TrayIME::TrayIME(SystemTray* system_tray) | 214 TrayIME::TrayIME(SystemTray* system_tray) |
| 195 : SystemTrayItem(system_tray, UMA_IME), | 215 : SystemTrayItem(system_tray, UMA_IME), |
| 196 tray_label_(NULL), | 216 tray_label_(NULL), |
| 197 default_(NULL), | 217 default_(NULL), |
| 198 detailed_(NULL), | 218 detailed_(NULL), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 220 AccessibilityNotificationVisibility notify) { | 240 AccessibilityNotificationVisibility notify) { |
| 221 Update(); | 241 Update(); |
| 222 } | 242 } |
| 223 | 243 |
| 224 void TrayIME::Update() { | 244 void TrayIME::Update() { |
| 225 UpdateTrayLabel(current_ime_, ime_list_.size()); | 245 UpdateTrayLabel(current_ime_, ime_list_.size()); |
| 226 if (default_) { | 246 if (default_) { |
| 227 default_->SetVisible(ShouldDefaultViewBeVisible()); | 247 default_->SetVisible(ShouldDefaultViewBeVisible()); |
| 228 default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1)); | 248 default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1)); |
| 229 } | 249 } |
| 230 if (detailed_) | 250 if (detailed_) { |
| 251 detailed_->SetImeManagedMessage(ime_managed_message_); |
| 231 detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle(), | 252 detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle(), |
| 232 ImeListView::HIDE_SINGLE_IME); | 253 GetSingleImeBehavior()); |
| 254 } |
| 233 } | 255 } |
| 234 | 256 |
| 235 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 257 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
| 236 if (tray_label_) { | 258 if (tray_label_) { |
| 237 bool visible = count > 1 && is_visible_; | 259 bool visible = ShouldShowImeTrayItem(count) && is_visible_; |
| 238 tray_label_->SetVisible(visible); | 260 tray_label_->SetVisible(visible); |
| 239 // Do not change label before hiding because this change is noticeable. | 261 // Do not change label before hiding because this change is noticeable. |
| 240 if (!visible) | 262 if (!visible) |
| 241 return; | 263 return; |
| 242 if (current.third_party) { | 264 if (current.third_party) { |
| 243 tray_label_->label()->SetText(current.short_name + | 265 tray_label_->label()->SetText(current.short_name + |
| 244 base::UTF8ToUTF16("*")); | 266 base::UTF8ToUTF16("*")); |
| 245 } else { | 267 } else { |
| 246 tray_label_->label()->SetText(current.short_name); | 268 tray_label_->label()->SetText(current.short_name); |
| 247 } | 269 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 275 tray_label_->CreateLabel(); | 297 tray_label_->CreateLabel(); |
| 276 SetupLabelForTray(tray_label_->label()); | 298 SetupLabelForTray(tray_label_->label()); |
| 277 // Hide IME tray when it is created, it will be updated when it is notified | 299 // Hide IME tray when it is created, it will be updated when it is notified |
| 278 // of the IME refresh event. | 300 // of the IME refresh event. |
| 279 tray_label_->SetVisible(false); | 301 tray_label_->SetVisible(false); |
| 280 return tray_label_; | 302 return tray_label_; |
| 281 } | 303 } |
| 282 | 304 |
| 283 views::View* TrayIME::CreateDefaultView(LoginStatus status) { | 305 views::View* TrayIME::CreateDefaultView(LoginStatus status) { |
| 284 CHECK(default_ == NULL); | 306 CHECK(default_ == NULL); |
| 285 default_ = | 307 default_ = new tray::IMEDefaultView( |
| 286 new tray::IMEDefaultView(this, GetDefaultViewLabel(ime_list_.size() > 1)); | 308 this, GetDefaultViewLabel(ShouldShowImeTrayItem(ime_list_.size()))); |
| 287 default_->SetVisible(ShouldDefaultViewBeVisible()); | 309 default_->SetVisible(ShouldDefaultViewBeVisible()); |
| 288 return default_; | 310 return default_; |
| 289 } | 311 } |
| 290 | 312 |
| 291 views::View* TrayIME::CreateDetailedView(LoginStatus status) { | 313 views::View* TrayIME::CreateDetailedView(LoginStatus status) { |
| 292 CHECK(detailed_ == NULL); | 314 CHECK(detailed_ == NULL); |
| 293 detailed_ = new tray::IMEDetailedView(this, status); | 315 detailed_ = new tray::IMEDetailedView(this, status); |
| 294 detailed_->Init(ShouldShowKeyboardToggle(), ImeListView::HIDE_SINGLE_IME); | 316 detailed_->SetImeManagedMessage(ime_managed_message_); |
| 317 detailed_->Init(ShouldShowKeyboardToggle(), GetSingleImeBehavior()); |
| 295 return detailed_; | 318 return detailed_; |
| 296 } | 319 } |
| 297 | 320 |
| 298 void TrayIME::DestroyTrayView() { | 321 void TrayIME::DestroyTrayView() { |
| 299 tray_label_ = NULL; | 322 tray_label_ = NULL; |
| 300 } | 323 } |
| 301 | 324 |
| 302 void TrayIME::DestroyDefaultView() { | 325 void TrayIME::DestroyDefaultView() { |
| 303 default_ = NULL; | 326 default_ = NULL; |
| 304 } | 327 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 315 } | 338 } |
| 316 | 339 |
| 317 void TrayIME::OnIMERefresh() { | 340 void TrayIME::OnIMERefresh() { |
| 318 // Caches the current ime state. | 341 // Caches the current ime state. |
| 319 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 342 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 320 ime_list_.clear(); | 343 ime_list_.clear(); |
| 321 property_list_.clear(); | 344 property_list_.clear(); |
| 322 delegate->GetCurrentIME(¤t_ime_); | 345 delegate->GetCurrentIME(¤t_ime_); |
| 323 delegate->GetAvailableIMEList(&ime_list_); | 346 delegate->GetAvailableIMEList(&ime_list_); |
| 324 delegate->GetCurrentIMEProperties(&property_list_); | 347 delegate->GetCurrentIMEProperties(&property_list_); |
| 348 ime_managed_message_ = delegate->GetIMEManagedMessage(); |
| 325 | 349 |
| 326 Update(); | 350 Update(); |
| 327 } | 351 } |
| 328 | 352 |
| 329 void TrayIME::OnIMEMenuActivationChanged(bool is_active) { | 353 void TrayIME::OnIMEMenuActivationChanged(bool is_active) { |
| 330 is_visible_ = !is_active; | 354 is_visible_ = !is_active; |
| 331 if (is_visible_) | 355 if (is_visible_) |
| 332 OnIMERefresh(); | 356 OnIMERefresh(); |
| 333 else | 357 else |
| 334 Update(); | 358 Update(); |
| 335 } | 359 } |
| 336 | 360 |
| 361 bool TrayIME::IsIMEManaged() { |
| 362 return !ime_managed_message_.empty(); |
| 363 } |
| 364 |
| 337 bool TrayIME::ShouldDefaultViewBeVisible() { | 365 bool TrayIME::ShouldDefaultViewBeVisible() { |
| 338 return is_visible_ && (ime_list_.size() > 1 || property_list_.size() > 1 || | 366 return is_visible_ && |
| 339 ShouldShowKeyboardToggle()); | 367 (ShouldShowImeTrayItem(ime_list_.size()) || |
| 368 property_list_.size() > 1 || ShouldShowKeyboardToggle()); |
| 369 } |
| 370 |
| 371 bool TrayIME::ShouldShowImeTrayItem(size_t ime_count) { |
| 372 // If managed, we want to show the tray icon even if there's only one input |
| 373 // method to choose from. |
| 374 size_t threshold = IsIMEManaged() ? 1 : 2; |
| 375 return ime_count >= threshold; |
| 376 } |
| 377 |
| 378 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() { |
| 379 // If managed, we also want to show a single IME. |
| 380 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME |
| 381 : ImeListView::HIDE_SINGLE_IME; |
| 340 } | 382 } |
| 341 | 383 |
| 342 } // namespace ash | 384 } // namespace ash |
| OLD | NEW |