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

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: 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 fa6a839484760c410a0dc4e9eec4c0fb25a2603b..0ae8d5ec0f25a0ff2ca0308d626df08e1ceb9f76 100644
--- a/ash/system/ime_menu/ime_menu_tray.cc
+++ b/ash/system/ime_menu/ime_menu_tray.cc
@@ -177,11 +177,13 @@ 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) {
+ ImeButtonsView(ImeMenuTray* ime_menu_tray,
+ bool show_emoji,
+ bool show_handwriting,
+ bool show_voice) {
DCHECK(ime_menu_tray_);
- Init();
+ Init(show_emoji, show_handwriting, show_voice);
}
~ImeButtonsView() override {}
@@ -215,7 +217,7 @@ class ImeButtonsView : public views::View, public views::ButtonListener {
}
private:
- void Init() {
+ void Init(bool show_emoji, bool show_handwriting, bool show_voice) {
auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal);
box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight);
SetLayoutManager(box_layout);
@@ -226,20 +228,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);
@@ -287,6 +295,9 @@ ImeMenuTray::ImeMenuTray(Shelf* shelf)
force_show_keyboard_(false),
keyboard_suppressed_(false),
show_bubble_after_keyboard_hidden_(false),
+ emoji_enabled_(false),
+ handwriting_enabled_(false),
+ voice_enabled_(false),
weak_ptr_factory_(this) {
DCHECK(ime_controller_);
SetInkDropMode(InkDropMode::ON);
@@ -337,8 +348,8 @@ 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 = ShouldShowBottomButtons();
+ bubble_view->AddChildView(new ImeTitleView(!show_bottom_buttons));
// Adds IME list to the bubble.
ime_list_view_ = new ImeMenuListView(nullptr);
@@ -346,8 +357,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)
James Cook 2017/06/27 16:31:11 nit: add {}
Azure Wei 2017/06/29 16:37:02 Done.
+ bubble_view->AddChildView(new ImeButtonsView(
+ this, emoji_enabled_, handwriting_enabled_, voice_enabled_));
bubble_.reset(new TrayBubbleWrapper(this, bubble_view));
SetIsActive(true);
@@ -405,16 +417,31 @@ void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) {
}
}
-bool ImeMenuTray::ShouldShowEmojiHandwritingVoiceButtons() const {
+bool ImeMenuTray::ShouldShowBottomButtons() {
// 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_enabled_ = handwriting_enabled_ = voice_enabled_ = false;
+ return false;
+ }
+
+ emoji_enabled_ = !input_method_manager->GetFeaturesRestricted(
+ InputMethodManager::FeaturesRestricted::EMOJI);
+ handwriting_enabled_ = !input_method_manager->GetFeaturesRestricted(
+ InputMethodManager::FeaturesRestricted::HANDWRITING);
+ voice_enabled_ = !input_method_manager->GetFeaturesRestricted(
+ InputMethodManager::FeaturesRestricted::VOICE);
+ return emoji_enabled_ || handwriting_enabled_ || voice_enabled_;
}
bool ImeMenuTray::ShouldShowKeyboardToggle() const {

Powered by Google App Engine
This is Rietveld 408576698