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