| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/ime_menu/ime_menu_tray.h" | 5 #include "ash/system/ime_menu/ime_menu_tray.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/ime/ime_controller.h" | 10 #include "ash/ime/ime_controller.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Settings button that is only used if the emoji, handwriting and voice | 169 // Settings button that is only used if the emoji, handwriting and voice |
| 170 // buttons are not available. | 170 // buttons are not available. |
| 171 SystemMenuButton* settings_button_; | 171 SystemMenuButton* settings_button_; |
| 172 | 172 |
| 173 DISALLOW_COPY_AND_ASSIGN(ImeTitleView); | 173 DISALLOW_COPY_AND_ASSIGN(ImeTitleView); |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 // The view that contains buttons shown on the bottom of IME menu. | 176 // The view that contains buttons shown on the bottom of IME menu. |
| 177 class ImeButtonsView : public views::View, public views::ButtonListener { | 177 class ImeButtonsView : public views::View, public views::ButtonListener { |
| 178 public: | 178 public: |
| 179 explicit ImeButtonsView(ImeMenuTray* ime_menu_tray) | 179 ImeButtonsView(ImeMenuTray* ime_menu_tray, |
| 180 : ime_menu_tray_(ime_menu_tray) { | 180 bool show_emoji, |
| 181 bool show_handwriting, |
| 182 bool show_voice) { |
| 181 DCHECK(ime_menu_tray_); | 183 DCHECK(ime_menu_tray_); |
| 182 | 184 |
| 183 Init(); | 185 Init(show_emoji, show_handwriting, show_voice); |
| 184 } | 186 } |
| 185 | 187 |
| 186 ~ImeButtonsView() override {} | 188 ~ImeButtonsView() override {} |
| 187 | 189 |
| 188 // views::ButtonListener: | 190 // views::ButtonListener: |
| 189 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 191 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 190 if (sender == settings_button_) { | 192 if (sender == settings_button_) { |
| 191 ime_menu_tray_->HideImeMenuBubble(); | 193 ime_menu_tray_->HideImeMenuBubble(); |
| 192 ShowIMESettings(); | 194 ShowIMESettings(); |
| 193 return; | 195 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 keyset = "hwt"; | 209 keyset = "hwt"; |
| 208 RecordButtonsClicked(keyset); | 210 RecordButtonsClicked(keyset); |
| 209 } else { | 211 } else { |
| 210 NOTREACHED(); | 212 NOTREACHED(); |
| 211 } | 213 } |
| 212 | 214 |
| 213 ime_menu_tray_->ShowKeyboardWithKeyset(keyset); | 215 ime_menu_tray_->ShowKeyboardWithKeyset(keyset); |
| 214 } | 216 } |
| 215 | 217 |
| 216 private: | 218 private: |
| 217 void Init() { | 219 void Init(bool show_emoji, bool show_handwriting, bool show_voice) { |
| 218 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal); | 220 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal); |
| 219 box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); | 221 box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); |
| 220 SetLayoutManager(box_layout); | 222 SetLayoutManager(box_layout); |
| 221 SetBorder(views::CreatePaddedBorder( | 223 SetBorder(views::CreatePaddedBorder( |
| 222 views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0, | 224 views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0, |
| 223 kMenuSeparatorColor), | 225 kMenuSeparatorColor), |
| 224 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, | 226 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, |
| 225 kMenuExtraMarginFromLeftEdge))); | 227 kMenuExtraMarginFromLeftEdge))); |
| 226 | 228 |
| 227 const int right_border = 1; | 229 const int right_border = 1; |
| 228 emoji_button_ = | 230 if (show_emoji) { |
| 229 CreateImeMenuButton(this, kImeMenuEmoticonIcon, | 231 emoji_button_ = |
| 230 IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border); | 232 CreateImeMenuButton(this, kImeMenuEmoticonIcon, |
| 231 AddChildView(emoji_button_); | 233 IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border); |
| 234 AddChildView(emoji_button_); |
| 235 } |
| 232 | 236 |
| 233 handwriting_button_ = | 237 if (show_handwriting) { |
| 234 CreateImeMenuButton(this, kImeMenuWriteIcon, | 238 handwriting_button_ = CreateImeMenuButton( |
| 235 IDS_ASH_STATUS_TRAY_IME_HANDWRITING, right_border); | 239 this, kImeMenuWriteIcon, IDS_ASH_STATUS_TRAY_IME_HANDWRITING, |
| 236 AddChildView(handwriting_button_); | 240 right_border); |
| 241 AddChildView(handwriting_button_); |
| 242 } |
| 237 | 243 |
| 238 voice_button_ = | 244 if (show_voice) { |
| 239 CreateImeMenuButton(this, kImeMenuMicrophoneIcon, | 245 voice_button_ = |
| 240 IDS_ASH_STATUS_TRAY_IME_VOICE, right_border); | 246 CreateImeMenuButton(this, kImeMenuMicrophoneIcon, |
| 241 AddChildView(voice_button_); | 247 IDS_ASH_STATUS_TRAY_IME_VOICE, right_border); |
| 248 AddChildView(voice_button_); |
| 249 } |
| 242 | 250 |
| 243 settings_button_ = CreateImeMenuButton(this, kSystemMenuSettingsIcon, | 251 settings_button_ = CreateImeMenuButton(this, kSystemMenuSettingsIcon, |
| 244 IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0); | 252 IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0); |
| 245 AddChildView(settings_button_); | 253 AddChildView(settings_button_); |
| 246 if (!TrayPopupUtils::CanOpenWebUISettings()) | 254 if (!TrayPopupUtils::CanOpenWebUISettings()) |
| 247 settings_button_->SetEnabled(false); | 255 settings_button_->SetEnabled(false); |
| 248 } | 256 } |
| 249 | 257 |
| 250 ImeMenuTray* ime_menu_tray_; | 258 ImeMenuTray* ime_menu_tray_; |
| 251 SystemMenuButton* emoji_button_; | 259 SystemMenuButton* emoji_button_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 279 } // namespace | 287 } // namespace |
| 280 | 288 |
| 281 ImeMenuTray::ImeMenuTray(Shelf* shelf) | 289 ImeMenuTray::ImeMenuTray(Shelf* shelf) |
| 282 : TrayBackgroundView(shelf), | 290 : TrayBackgroundView(shelf), |
| 283 ime_controller_(Shell::Get()->ime_controller()), | 291 ime_controller_(Shell::Get()->ime_controller()), |
| 284 label_(new ImeMenuLabel()), | 292 label_(new ImeMenuLabel()), |
| 285 show_keyboard_(false), | 293 show_keyboard_(false), |
| 286 force_show_keyboard_(false), | 294 force_show_keyboard_(false), |
| 287 keyboard_suppressed_(false), | 295 keyboard_suppressed_(false), |
| 288 show_bubble_after_keyboard_hidden_(false), | 296 show_bubble_after_keyboard_hidden_(false), |
| 297 emoji_enabled_(false), |
| 298 handwriting_enabled_(false), |
| 299 voice_enabled_(false), |
| 289 weak_ptr_factory_(this) { | 300 weak_ptr_factory_(this) { |
| 290 DCHECK(ime_controller_); | 301 DCHECK(ime_controller_); |
| 291 SetInkDropMode(InkDropMode::ON); | 302 SetInkDropMode(InkDropMode::ON); |
| 292 SetupLabelForTray(label_); | 303 SetupLabelForTray(label_); |
| 293 label_->SetElideBehavior(gfx::TRUNCATE); | 304 label_->SetElideBehavior(gfx::TRUNCATE); |
| 294 tray_container()->AddChildView(label_); | 305 tray_container()->AddChildView(label_); |
| 295 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); | 306 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); |
| 296 tray_notifier->AddIMEObserver(this); | 307 tray_notifier->AddIMEObserver(this); |
| 297 tray_notifier->AddVirtualKeyboardObserver(this); | 308 tray_notifier->AddVirtualKeyboardObserver(this); |
| 298 } | 309 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 329 init_params.anchor_view = GetBubbleAnchor(); | 340 init_params.anchor_view = GetBubbleAnchor(); |
| 330 init_params.anchor_alignment = GetAnchorAlignment(); | 341 init_params.anchor_alignment = GetAnchorAlignment(); |
| 331 init_params.min_width = kTrayMenuMinimumWidth; | 342 init_params.min_width = kTrayMenuMinimumWidth; |
| 332 init_params.max_width = kTrayMenuMinimumWidth; | 343 init_params.max_width = kTrayMenuMinimumWidth; |
| 333 init_params.close_on_deactivate = true; | 344 init_params.close_on_deactivate = true; |
| 334 | 345 |
| 335 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); | 346 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); |
| 336 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); | 347 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); |
| 337 | 348 |
| 338 // Add a title item with a separator on the top of the IME menu. | 349 // Add a title item with a separator on the top of the IME menu. |
| 339 bubble_view->AddChildView( | 350 bool show_bottom_buttons = ShouldShowBottomButtons(); |
| 340 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons())); | 351 bubble_view->AddChildView(new ImeTitleView(!show_bottom_buttons)); |
| 341 | 352 |
| 342 // Adds IME list to the bubble. | 353 // Adds IME list to the bubble. |
| 343 ime_list_view_ = new ImeMenuListView(nullptr); | 354 ime_list_view_ = new ImeMenuListView(nullptr); |
| 344 ime_list_view_->Init(ShouldShowKeyboardToggle(), | 355 ime_list_view_->Init(ShouldShowKeyboardToggle(), |
| 345 ImeListView::SHOW_SINGLE_IME); | 356 ImeListView::SHOW_SINGLE_IME); |
| 346 bubble_view->AddChildView(ime_list_view_); | 357 bubble_view->AddChildView(ime_list_view_); |
| 347 | 358 |
| 348 if (ShouldShowEmojiHandwritingVoiceButtons()) | 359 if (show_bottom_buttons) { |
| 349 bubble_view->AddChildView(new ImeButtonsView(this)); | 360 bubble_view->AddChildView(new ImeButtonsView( |
| 361 this, emoji_enabled_, handwriting_enabled_, voice_enabled_)); |
| 362 } |
| 350 | 363 |
| 351 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); | 364 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); |
| 352 SetIsActive(true); | 365 SetIsActive(true); |
| 353 } | 366 } |
| 354 | 367 |
| 355 void ImeMenuTray::HideImeMenuBubble() { | 368 void ImeMenuTray::HideImeMenuBubble() { |
| 356 bubble_.reset(); | 369 bubble_.reset(); |
| 357 ime_list_view_ = nullptr; | 370 ime_list_view_ = nullptr; |
| 358 SetIsActive(false); | 371 SetIsActive(false); |
| 359 shelf()->UpdateAutoHideState(); | 372 shelf()->UpdateAutoHideState(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // keyboard for one time. | 410 // keyboard for one time. |
| 398 force_show_keyboard_ = true; | 411 force_show_keyboard_ = true; |
| 399 accessibility_delegate->SetVirtualKeyboardEnabled(true); | 412 accessibility_delegate->SetVirtualKeyboardEnabled(true); |
| 400 keyboard_controller = keyboard::KeyboardController::GetInstance(); | 413 keyboard_controller = keyboard::KeyboardController::GetInstance(); |
| 401 if (keyboard_controller) { | 414 if (keyboard_controller) { |
| 402 keyboard_controller->AddObserver(this); | 415 keyboard_controller->AddObserver(this); |
| 403 keyboard_controller->ShowKeyboard(false); | 416 keyboard_controller->ShowKeyboard(false); |
| 404 } | 417 } |
| 405 } | 418 } |
| 406 | 419 |
| 407 bool ImeMenuTray::ShouldShowEmojiHandwritingVoiceButtons() const { | 420 bool ImeMenuTray::ShouldShowBottomButtons() { |
| 408 // Emoji, handwriting and voice input is not supported for these cases: | 421 // Emoji, handwriting and voice input is not supported for these cases: |
| 409 // 1) features::kEHVInputOnImeMenu is not enabled. | 422 // 1) features::kEHVInputOnImeMenu is not enabled. |
| 410 // 2) third party IME extensions. | 423 // 2) third party IME extensions. |
| 411 // 3) login/lock screen. | 424 // 3) login/lock screen. |
| 412 // 4) password input client. | 425 // 4) password input client. |
| 413 return InputMethodManager::Get() && | 426 InputMethodManager* input_method_manager = InputMethodManager::Get(); |
| 414 InputMethodManager::Get()->IsEmojiHandwritingVoiceOnImeMenuEnabled() && | 427 bool should_show_buttom_buttoms = |
| 415 !ime_controller_->current_ime().third_party && | 428 input_method_manager && |
| 416 !IsInLoginOrLockScreen() && !IsInPasswordInputContext(); | 429 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled() && |
| 430 !ime_controller_->current_ime().third_party && !IsInLoginOrLockScreen() && |
| 431 !IsInPasswordInputContext(); |
| 432 |
| 433 if (!should_show_buttom_buttoms) { |
| 434 emoji_enabled_ = handwriting_enabled_ = voice_enabled_ = false; |
| 435 return false; |
| 436 } |
| 437 |
| 438 emoji_enabled_ = input_method_manager->GetImeMenuFeatureEnabled( |
| 439 InputMethodManager::FEATURE_EMOJI); |
| 440 handwriting_enabled_ = input_method_manager->GetImeMenuFeatureEnabled( |
| 441 InputMethodManager::FEATURE_HANDWRITING); |
| 442 voice_enabled_ = input_method_manager->GetImeMenuFeatureEnabled( |
| 443 InputMethodManager::FEATURE_VOICE); |
| 444 return emoji_enabled_ || handwriting_enabled_ || voice_enabled_; |
| 417 } | 445 } |
| 418 | 446 |
| 419 bool ImeMenuTray::ShouldShowKeyboardToggle() const { | 447 bool ImeMenuTray::ShouldShowKeyboardToggle() const { |
| 420 return keyboard_suppressed_ && | 448 return keyboard_suppressed_ && |
| 421 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); | 449 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); |
| 422 } | 450 } |
| 423 | 451 |
| 424 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | 452 base::string16 ImeMenuTray::GetAccessibleNameForTray() { |
| 425 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 453 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
| 426 } | 454 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 else | 585 else |
| 558 label_->SetText(current_ime.short_name); | 586 label_->SetText(current_ime.short_name); |
| 559 } | 587 } |
| 560 | 588 |
| 561 void ImeMenuTray::DisableVirtualKeyboard() { | 589 void ImeMenuTray::DisableVirtualKeyboard() { |
| 562 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); | 590 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); |
| 563 force_show_keyboard_ = false; | 591 force_show_keyboard_ = false; |
| 564 } | 592 } |
| 565 | 593 |
| 566 } // namespace ash | 594 } // namespace ash |
| OLD | NEW |