Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Unified Diff: ash/system/ime_menu/ime_menu_tray.cc

Issue 2953033002: Hide handwriting and voice buttons when keyboard is in restricted state (Closed)
Patch Set: Add InputMethodManager::FeaturesRestrictedState Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/ime_menu/ime_menu_tray.cc
diff --git a/ash/system/ime_menu/ime_menu_tray.cc b/ash/system/ime_menu/ime_menu_tray.cc
index 10c3e97fbad9970ee921e2999273d35c45726f2d..3d3327f3b5a30ec5fc1b63beb748d93a1d25511a 100644
--- a/ash/system/ime_menu/ime_menu_tray.cc
+++ b/ash/system/ime_menu/ime_menu_tray.cc
@@ -176,8 +176,14 @@ class ImeTitleView : public views::View, public views::ButtonListener {
// The view that contains buttons shown on the bottom of IME menu.
class ImeButtonsView : public views::View, public views::ButtonListener {
public:
- explicit ImeButtonsView(ImeMenuTray* ime_menu_tray)
- : ime_menu_tray_(ime_menu_tray) {
+ 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.
+ bool show_emoji,
+ bool show_handwriting,
+ bool show_voice)
+ : ime_menu_tray_(ime_menu_tray),
+ 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().
+ show_handwriting_(show_handwriting),
+ show_voice_(show_voice) {
DCHECK(ime_menu_tray_);
Init();
@@ -225,20 +231,26 @@ class ImeButtonsView : public views::View, public views::ButtonListener {
kMenuExtraMarginFromLeftEdge)));
const int right_border = 1;
- emoji_button_ =
- CreateImeMenuButton(this, kImeMenuEmoticonIcon,
- IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border);
- AddChildView(emoji_button_);
+ if (show_emoji_) {
+ emoji_button_ =
+ CreateImeMenuButton(this, kImeMenuEmoticonIcon,
+ IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border);
+ AddChildView(emoji_button_);
+ }
- handwriting_button_ =
- CreateImeMenuButton(this, kImeMenuWriteIcon,
- IDS_ASH_STATUS_TRAY_IME_HANDWRITING, right_border);
- AddChildView(handwriting_button_);
+ if (show_handwriting_) {
+ handwriting_button_ = CreateImeMenuButton(
+ this, kImeMenuWriteIcon, IDS_ASH_STATUS_TRAY_IME_HANDWRITING,
+ right_border);
+ AddChildView(handwriting_button_);
+ }
- voice_button_ =
- CreateImeMenuButton(this, kImeMenuMicrophoneIcon,
- IDS_ASH_STATUS_TRAY_IME_VOICE, right_border);
- AddChildView(voice_button_);
+ if (show_voice_) {
+ voice_button_ =
+ CreateImeMenuButton(this, kImeMenuMicrophoneIcon,
+ IDS_ASH_STATUS_TRAY_IME_VOICE, right_border);
+ AddChildView(voice_button_);
+ }
settings_button_ = CreateImeMenuButton(this, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0);
@@ -248,6 +260,9 @@ class ImeButtonsView : public views::View, public views::ButtonListener {
}
ImeMenuTray* ime_menu_tray_;
+ bool show_emoji_;
+ bool show_handwriting_;
+ bool show_voice_;
SystemMenuButton* emoji_button_;
SystemMenuButton* handwriting_button_;
SystemMenuButton* voice_button_;
@@ -336,8 +351,10 @@ void ImeMenuTray::ShowImeMenuBubbleInternal() {
bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets());
// Add a title item with a separator on the top of the IME menu.
- bubble_view->AddChildView(
- new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons()));
+ bool show_bottom_buttons, show_emoji, show_handwriting, show_voice;
+ show_bottom_buttons =
+ ShouldShowBottomButtons(show_emoji, show_handwriting, show_voice);
+ bubble_view->AddChildView(new ImeTitleView(!show_bottom_buttons));
// Adds IME list to the bubble.
ime_list_view_ = new ImeMenuListView(nullptr);
@@ -345,8 +362,9 @@ void ImeMenuTray::ShowImeMenuBubbleInternal() {
ImeListView::SHOW_SINGLE_IME);
bubble_view->AddChildView(ime_list_view_);
- if (ShouldShowEmojiHandwritingVoiceButtons())
- bubble_view->AddChildView(new ImeButtonsView(this));
+ if (show_bottom_buttons)
+ bubble_view->AddChildView(
+ new ImeButtonsView(this, show_emoji, show_handwriting, show_voice));
bubble_.reset(new TrayBubbleWrapper(this, bubble_view));
SetIsActive(true);
@@ -404,16 +422,36 @@ void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) {
}
}
-bool ImeMenuTray::ShouldShowEmojiHandwritingVoiceButtons() const {
+bool ImeMenuTray::ShouldShowBottomButtons(bool& emoji,
+ bool& handwriting,
+ bool& voice) const {
// Emoji, handwriting and voice input is not supported for these cases:
// 1) features::kEHVInputOnImeMenu is not enabled.
// 2) third party IME extensions.
// 3) login/lock screen.
// 4) password input client.
- return InputMethodManager::Get() &&
- InputMethodManager::Get()->IsEmojiHandwritingVoiceOnImeMenuEnabled() &&
- !ime_controller_->current_ime().third_party &&
- !IsInLoginOrLockScreen() && !IsInPasswordInputContext();
+ InputMethodManager* input_method_manager = InputMethodManager::Get();
+ bool should_show_buttom_buttoms =
+ input_method_manager &&
+ input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled() &&
+ !ime_controller_->current_ime().third_party && !IsInLoginOrLockScreen() &&
+ !IsInPasswordInputContext();
+
+ if (!should_show_buttom_buttoms) {
+ emoji = handwriting = voice = false;
+ return false;
+ }
+
+ uint32_t features_restricted_state =
+ 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
+ emoji = !(features_restricted_state &
+ InputMethodManager::FeaturesRestrictedState::RESTRICTED_EMOJI);
+ handwriting =
+ !(features_restricted_state &
+ InputMethodManager::FeaturesRestrictedState::RESTRICTED_HANDWRITING);
+ voice = !(features_restricted_state &
+ InputMethodManager::FeaturesRestrictedState::RESTRICTED_VOICE);
+ return emoji || handwriting || voice;
}
bool ImeMenuTray::ShouldShowKeyboardToggle() const {

Powered by Google App Engine
This is Rietveld 408576698