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 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 explicit ImeButtonsView(ImeMenuTray* ime_menu_tray, |
|
James Cook
2017/06/26 17:21:19
nit: no explicit
Azure Wei
2017/06/27 14:27:14
Done.
| |
| 180 : ime_menu_tray_(ime_menu_tray) { | 180 bool show_emoji, |
| 181 bool show_handwriting, | |
| 182 bool show_voice) | |
| 183 : ime_menu_tray_(ime_menu_tray), | |
| 184 show_emoji_(show_emoji), | |
|
James Cook
2017/06/26 17:21:19
Do you need member variables for these? How about
Azure Wei
2017/06/27 14:27:14
These are unnecessary. Passed them with Init().
| |
| 185 show_handwriting_(show_handwriting), | |
| 186 show_voice_(show_voice) { | |
| 181 DCHECK(ime_menu_tray_); | 187 DCHECK(ime_menu_tray_); |
| 182 | 188 |
| 183 Init(); | 189 Init(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 ~ImeButtonsView() override {} | 192 ~ImeButtonsView() override {} |
| 187 | 193 |
| 188 // views::ButtonListener: | 194 // views::ButtonListener: |
| 189 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 195 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 190 if (sender == settings_button_) { | 196 if (sender == settings_button_) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 218 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal); | 224 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal); |
| 219 box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); | 225 box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); |
| 220 SetLayoutManager(box_layout); | 226 SetLayoutManager(box_layout); |
| 221 SetBorder(views::CreatePaddedBorder( | 227 SetBorder(views::CreatePaddedBorder( |
| 222 views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0, | 228 views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0, |
| 223 kMenuSeparatorColor), | 229 kMenuSeparatorColor), |
| 224 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, | 230 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, |
| 225 kMenuExtraMarginFromLeftEdge))); | 231 kMenuExtraMarginFromLeftEdge))); |
| 226 | 232 |
| 227 const int right_border = 1; | 233 const int right_border = 1; |
| 228 emoji_button_ = | 234 if (show_emoji_) { |
| 229 CreateImeMenuButton(this, kImeMenuEmoticonIcon, | 235 emoji_button_ = |
| 230 IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border); | 236 CreateImeMenuButton(this, kImeMenuEmoticonIcon, |
| 231 AddChildView(emoji_button_); | 237 IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border); |
| 238 AddChildView(emoji_button_); | |
| 239 } | |
| 232 | 240 |
| 233 handwriting_button_ = | 241 if (show_handwriting_) { |
| 234 CreateImeMenuButton(this, kImeMenuWriteIcon, | 242 handwriting_button_ = CreateImeMenuButton( |
| 235 IDS_ASH_STATUS_TRAY_IME_HANDWRITING, right_border); | 243 this, kImeMenuWriteIcon, IDS_ASH_STATUS_TRAY_IME_HANDWRITING, |
| 236 AddChildView(handwriting_button_); | 244 right_border); |
| 245 AddChildView(handwriting_button_); | |
| 246 } | |
| 237 | 247 |
| 238 voice_button_ = | 248 if (show_voice_) { |
| 239 CreateImeMenuButton(this, kImeMenuMicrophoneIcon, | 249 voice_button_ = |
| 240 IDS_ASH_STATUS_TRAY_IME_VOICE, right_border); | 250 CreateImeMenuButton(this, kImeMenuMicrophoneIcon, |
| 241 AddChildView(voice_button_); | 251 IDS_ASH_STATUS_TRAY_IME_VOICE, right_border); |
| 252 AddChildView(voice_button_); | |
| 253 } | |
| 242 | 254 |
| 243 settings_button_ = CreateImeMenuButton(this, kSystemMenuSettingsIcon, | 255 settings_button_ = CreateImeMenuButton(this, kSystemMenuSettingsIcon, |
| 244 IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0); | 256 IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0); |
| 245 AddChildView(settings_button_); | 257 AddChildView(settings_button_); |
| 246 if (!TrayPopupUtils::CanOpenWebUISettings()) | 258 if (!TrayPopupUtils::CanOpenWebUISettings()) |
| 247 settings_button_->SetEnabled(false); | 259 settings_button_->SetEnabled(false); |
| 248 } | 260 } |
| 249 | 261 |
| 250 ImeMenuTray* ime_menu_tray_; | 262 ImeMenuTray* ime_menu_tray_; |
| 263 bool show_emoji_; | |
| 264 bool show_handwriting_; | |
| 265 bool show_voice_; | |
| 251 SystemMenuButton* emoji_button_; | 266 SystemMenuButton* emoji_button_; |
| 252 SystemMenuButton* handwriting_button_; | 267 SystemMenuButton* handwriting_button_; |
| 253 SystemMenuButton* voice_button_; | 268 SystemMenuButton* voice_button_; |
| 254 SystemMenuButton* settings_button_; | 269 SystemMenuButton* settings_button_; |
| 255 | 270 |
| 256 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); | 271 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); |
| 257 }; | 272 }; |
| 258 | 273 |
| 259 // A list of available IMEs shown in the opt-in IME menu, which has a different | 274 // A list of available IMEs shown in the opt-in IME menu, which has a different |
| 260 // height depending on the number of IMEs in the list. | 275 // height depending on the number of IMEs in the list. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 init_params.anchor_view = GetBubbleAnchor(); | 344 init_params.anchor_view = GetBubbleAnchor(); |
| 330 init_params.anchor_alignment = GetAnchorAlignment(); | 345 init_params.anchor_alignment = GetAnchorAlignment(); |
| 331 init_params.min_width = kTrayMenuMinimumWidth; | 346 init_params.min_width = kTrayMenuMinimumWidth; |
| 332 init_params.max_width = kTrayMenuMinimumWidth; | 347 init_params.max_width = kTrayMenuMinimumWidth; |
| 333 init_params.close_on_deactivate = true; | 348 init_params.close_on_deactivate = true; |
| 334 | 349 |
| 335 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); | 350 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); |
| 336 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); | 351 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); |
| 337 | 352 |
| 338 // Add a title item with a separator on the top of the IME menu. | 353 // Add a title item with a separator on the top of the IME menu. |
| 339 bubble_view->AddChildView( | 354 bool show_bottom_buttons, show_emoji, show_handwriting, show_voice; |
| 340 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons())); | 355 show_bottom_buttons = |
| 356 ShouldShowBottomButtons(show_emoji, show_handwriting, show_voice); | |
| 357 bubble_view->AddChildView(new ImeTitleView(!show_bottom_buttons)); | |
| 341 | 358 |
| 342 // Adds IME list to the bubble. | 359 // Adds IME list to the bubble. |
| 343 ime_list_view_ = new ImeMenuListView(nullptr); | 360 ime_list_view_ = new ImeMenuListView(nullptr); |
| 344 ime_list_view_->Init(ShouldShowKeyboardToggle(), | 361 ime_list_view_->Init(ShouldShowKeyboardToggle(), |
| 345 ImeListView::SHOW_SINGLE_IME); | 362 ImeListView::SHOW_SINGLE_IME); |
| 346 bubble_view->AddChildView(ime_list_view_); | 363 bubble_view->AddChildView(ime_list_view_); |
| 347 | 364 |
| 348 if (ShouldShowEmojiHandwritingVoiceButtons()) | 365 if (show_bottom_buttons) |
| 349 bubble_view->AddChildView(new ImeButtonsView(this)); | 366 bubble_view->AddChildView( |
| 367 new ImeButtonsView(this, show_emoji, show_handwriting, show_voice)); | |
| 350 | 368 |
| 351 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); | 369 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); |
| 352 SetIsActive(true); | 370 SetIsActive(true); |
| 353 } | 371 } |
| 354 | 372 |
| 355 void ImeMenuTray::HideImeMenuBubble() { | 373 void ImeMenuTray::HideImeMenuBubble() { |
| 356 bubble_.reset(); | 374 bubble_.reset(); |
| 357 ime_list_view_ = nullptr; | 375 ime_list_view_ = nullptr; |
| 358 SetIsActive(false); | 376 SetIsActive(false); |
| 359 shelf()->UpdateAutoHideState(); | 377 shelf()->UpdateAutoHideState(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 // keyboard for one time. | 415 // keyboard for one time. |
| 398 force_show_keyboard_ = true; | 416 force_show_keyboard_ = true; |
| 399 accessibility_delegate->SetVirtualKeyboardEnabled(true); | 417 accessibility_delegate->SetVirtualKeyboardEnabled(true); |
| 400 keyboard_controller = keyboard::KeyboardController::GetInstance(); | 418 keyboard_controller = keyboard::KeyboardController::GetInstance(); |
| 401 if (keyboard_controller) { | 419 if (keyboard_controller) { |
| 402 keyboard_controller->AddObserver(this); | 420 keyboard_controller->AddObserver(this); |
| 403 keyboard_controller->ShowKeyboard(false); | 421 keyboard_controller->ShowKeyboard(false); |
| 404 } | 422 } |
| 405 } | 423 } |
| 406 | 424 |
| 407 bool ImeMenuTray::ShouldShowEmojiHandwritingVoiceButtons() const { | 425 bool ImeMenuTray::ShouldShowBottomButtons(bool& emoji, |
| 426 bool& handwriting, | |
| 427 bool& voice) const { | |
| 408 // Emoji, handwriting and voice input is not supported for these cases: | 428 // Emoji, handwriting and voice input is not supported for these cases: |
| 409 // 1) features::kEHVInputOnImeMenu is not enabled. | 429 // 1) features::kEHVInputOnImeMenu is not enabled. |
| 410 // 2) third party IME extensions. | 430 // 2) third party IME extensions. |
| 411 // 3) login/lock screen. | 431 // 3) login/lock screen. |
| 412 // 4) password input client. | 432 // 4) password input client. |
| 413 return InputMethodManager::Get() && | 433 InputMethodManager* input_method_manager = InputMethodManager::Get(); |
| 414 InputMethodManager::Get()->IsEmojiHandwritingVoiceOnImeMenuEnabled() && | 434 bool should_show_buttom_buttoms = |
| 415 !ime_controller_->current_ime().third_party && | 435 input_method_manager && |
| 416 !IsInLoginOrLockScreen() && !IsInPasswordInputContext(); | 436 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled() && |
| 437 !ime_controller_->current_ime().third_party && !IsInLoginOrLockScreen() && | |
| 438 !IsInPasswordInputContext(); | |
| 439 | |
| 440 if (!should_show_buttom_buttoms) { | |
| 441 emoji = handwriting = voice = false; | |
| 442 return false; | |
| 443 } | |
| 444 | |
| 445 uint32_t features_restricted_state = | |
| 446 input_method_manager->GetFeaturesRestrictedState(); | |
|
James Cook
2017/06/26 17:21:19
Instead of having a global IsEmojiHandwritingVoice
Azure Wei
2017/06/27 14:27:14
Done.
James Cook
2017/06/27 16:31:10
This is not what I meant. See new comment on Input
| |
| 447 emoji = !(features_restricted_state & | |
| 448 InputMethodManager::FeaturesRestrictedState::RESTRICTED_EMOJI); | |
| 449 handwriting = | |
| 450 !(features_restricted_state & | |
| 451 InputMethodManager::FeaturesRestrictedState::RESTRICTED_HANDWRITING); | |
| 452 voice = !(features_restricted_state & | |
| 453 InputMethodManager::FeaturesRestrictedState::RESTRICTED_VOICE); | |
| 454 return emoji || handwriting || voice; | |
| 417 } | 455 } |
| 418 | 456 |
| 419 bool ImeMenuTray::ShouldShowKeyboardToggle() const { | 457 bool ImeMenuTray::ShouldShowKeyboardToggle() const { |
| 420 return keyboard_suppressed_ && | 458 return keyboard_suppressed_ && |
| 421 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); | 459 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); |
| 422 } | 460 } |
| 423 | 461 |
| 424 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | 462 base::string16 ImeMenuTray::GetAccessibleNameForTray() { |
| 425 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 463 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
| 426 } | 464 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 else | 595 else |
| 558 label_->SetText(current_ime.short_name); | 596 label_->SetText(current_ime.short_name); |
| 559 } | 597 } |
| 560 | 598 |
| 561 void ImeMenuTray::DisableVirtualKeyboard() { | 599 void ImeMenuTray::DisableVirtualKeyboard() { |
| 562 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); | 600 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); |
| 563 force_show_keyboard_ = false; | 601 force_show_keyboard_ = false; |
| 564 } | 602 } |
| 565 | 603 |
| 566 } // namespace ash | 604 } // namespace ash |
| OLD | NEW |