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

Side by Side Diff: ash/common/system/chromeos/ime_menu/ime_menu_tray.cc

Issue 2271523002: Adds emoji/handwriting/vocie buttons on opt-in IME menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and sync. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « ash/ash_strings.grd ('k') | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/system/chromeos/ime_menu/ime_menu_tray.h" 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h"
6 6
7 #include "ash/common/accessibility_delegate.h" 7 #include "ash/common/accessibility_delegate.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
11 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
12 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" 12 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h"
13 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 13 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
14 #include "ash/common/system/tray/hover_highlight_view.h" 14 #include "ash/common/system/tray/hover_highlight_view.h"
15 #include "ash/common/system/tray/system_tray_delegate.h" 15 #include "ash/common/system/tray/system_tray_delegate.h"
16 #include "ash/common/system/tray/system_tray_notifier.h" 16 #include "ash/common/system/tray/system_tray_notifier.h"
17 #include "ash/common/system/tray/tray_constants.h" 17 #include "ash/common/system/tray/tray_constants.h"
18 #include "ash/common/system/tray/tray_popup_header_button.h" 18 #include "ash/common/system/tray/tray_popup_header_button.h"
19 #include "ash/common/system/tray/tray_utils.h" 19 #include "ash/common/system/tray/tray_utils.h"
20 #include "ash/common/wm_lookup.h" 20 #include "ash/common/wm_lookup.h"
21 #include "ash/common/wm_root_window_controller.h" 21 #include "ash/common/wm_root_window_controller.h"
22 #include "ash/common/wm_shell.h" 22 #include "ash/common/wm_shell.h"
23 #include "ash/common/wm_window.h" 23 #include "ash/common/wm_window.h"
24 #include "ash/resources/vector_icons/vector_icons.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
25 #include "grit/ash_resources.h" 26 #include "grit/ash_resources.h"
26 #include "grit/ash_strings.h" 27 #include "grit/ash_strings.h"
27 #include "ui/base/ime/chromeos/input_method_manager.h" 28 #include "ui/base/ime/chromeos/input_method_manager.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/paint_vector_icon.h"
32 #include "ui/gfx/vector_icons_public.h"
30 #include "ui/keyboard/keyboard_controller.h" 33 #include "ui/keyboard/keyboard_controller.h"
31 #include "ui/keyboard/keyboard_util.h" 34 #include "ui/keyboard/keyboard_util.h"
32 #include "ui/views/controls/label.h" 35 #include "ui/views/controls/label.h"
33 #include "ui/views/layout/box_layout.h" 36 #include "ui/views/layout/box_layout.h"
34 37
35 using chromeos::input_method::InputMethodManager; 38 using chromeos::input_method::InputMethodManager;
36 39
37 namespace ash { 40 namespace ash {
38 41
39 namespace { 42 namespace {
40 43 // The additional space between the child view area and the host button view
41 // The border width between buttons. 44 // border in dp.
42 const int kButtonRightBorder = 1; 45 // TODO(tdanderson): Move this to tray_constants.
46 const int kButtonInsideBorderSpacing = 4;
43 47
44 // Returns the max height of ImeListView. 48 // Returns the max height of ImeListView.
45 int GetImeListViewMaxHeight() { 49 int GetImeListViewMaxHeight() {
46 const int max_items = 7; 50 const int max_items = 7;
47 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items; 51 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items;
48 } 52 }
49 53
50 // Shows language and input settings page. 54 // Shows language and input settings page.
51 void ShowIMESettings() { 55 void ShowIMESettings() {
52 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 56 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
53 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED); 57 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
54 delegate->ShowIMESettings(); 58 delegate->ShowIMESettings();
55 } 59 }
56 60
57 class ImeMenuLabel : public views::Label { 61 class ImeMenuLabel : public views::Label {
58 public: 62 public:
59 ImeMenuLabel() {} 63 ImeMenuLabel() {}
60 ~ImeMenuLabel() override {} 64 ~ImeMenuLabel() override {}
61 65
62 // views:Label: 66 // views:Label:
63 gfx::Size GetPreferredSize() const override { 67 gfx::Size GetPreferredSize() const override {
64 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); 68 const int tray_constant = GetTrayConstant(TRAY_IME_MENU_ICON);
69 return gfx::Size(tray_constant, tray_constant);
65 } 70 }
66 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; } 71 int GetHeightForWidth(int width) const override {
72 return GetTrayConstant(TRAY_IME_MENU_ICON);
73 }
67 74
68 private: 75 private:
69 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); 76 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel);
70 }; 77 };
71 78
72 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener, 79 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener,
73 int enabled_resource_id, 80 const gfx::ImageSkia& image,
74 int disabled_resource_id,
75 int enabled_resource_id_hover,
76 int disabled_resource_id_hover,
77 int accessible_name_id, 81 int accessible_name_id,
78 int message_id,
79 int right_border) { 82 int right_border) {
80 TrayPopupHeaderButton* button = 83 TrayPopupHeaderButton* button =
81 new TrayPopupHeaderButton(listener, enabled_resource_id, 84 new TrayPopupHeaderButton(listener, image, accessible_name_id);
82 disabled_resource_id, enabled_resource_id_hover, 85 button->SetTooltipText(l10n_util::GetStringUTF16(accessible_name_id));
83 disabled_resource_id_hover, accessible_name_id); 86 if (!MaterialDesignController::IsShelfMaterial()) {
84 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); 87 button->SetBorder(views::Border::CreateSolidSidedBorder(
85 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, 88 0, 0, 0, right_border, kBorderDarkColor));
86 kBorderDarkColor)); 89 }
87 return button; 90 return button;
88 } 91 }
89 92
90 // The view that contains buttons shown on the bottom of IME menu. 93 // The view that contains buttons shown on the bottom of IME menu.
91 class ImeButtonsView : public views::View, 94 class ImeButtonsView : public views::View,
92 public views::ButtonListener, 95 public views::ButtonListener,
93 public ViewClickListener { 96 public ViewClickListener {
94 public: 97 public:
95 ImeButtonsView(ImeMenuTray* ime_menu_tray, 98 ImeButtonsView(ImeMenuTray* ime_menu_tray,
96 bool show_emoji_button, 99 bool show_emoji_button,
97 bool show_voice_button, 100 bool show_voice_button,
98 bool show_handwriting_button, 101 bool show_handwriting_button,
99 bool show_settings_button) 102 bool show_settings_button)
100 : ime_menu_tray_(ime_menu_tray) { 103 : ime_menu_tray_(ime_menu_tray) {
101 DCHECK(ime_menu_tray_); 104 DCHECK(ime_menu_tray_);
102 105
103 SetBorder( 106 SetBorder(
104 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); 107 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor));
105 108
106 // If there's only one settings button, the bottom should be a label with 109 // If there's only one settings button, the bottom should be a label with
107 // normal background. Otherwise, show button icons with header background. 110 // normal background. Otherwise, show button icons with header background.
108 if (show_settings_button && !show_emoji_button && !show_voice_button && 111 if (show_settings_button && !show_emoji_button &&
109 !show_handwriting_button) { 112 !show_handwriting_button && !show_voice_button) {
110 ShowOneSettingButton(); 113 ShowOneSettingButton();
111 } else { 114 } else {
112 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button, 115 ShowButtons(show_emoji_button, show_handwriting_button, show_voice_button,
113 show_settings_button); 116 show_settings_button);
114 } 117 }
115 // TODO(azurewei): Add logic of switching between the two states when the
116 // menu is shown.
117 } 118 }
118 119
119 ~ImeButtonsView() override {} 120 ~ImeButtonsView() override {}
120 121
121 // views::View: 122 // views::View:
122 gfx::Size GetPreferredSize() const override {
123 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
124 return gfx::Size(size, size);
125 }
126 int GetHeightForWidth(int width) const override { 123 int GetHeightForWidth(int width) const override {
127 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 124 return kMenuButtonSize + 2 * kButtonInsideBorderSpacing;
128 } 125 }
129 126
130 // views::ButtonListener: 127 // views::ButtonListener:
131 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 128 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
132 if (sender == settings_button_) { 129 if (sender == settings_button_) {
133 ime_menu_tray_->HideImeMenuBubble(); 130 ime_menu_tray_->HideImeMenuBubble();
134 ShowIMESettings(); 131 ShowIMESettings();
135 return; 132 return;
136 } 133 }
137 134
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 one_settings_button_view_ = new HoverHighlightView(this); 166 one_settings_button_view_ = new HoverHighlightView(this);
170 one_settings_button_view_->AddLabel( 167 one_settings_button_view_->AddLabel(
171 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 168 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
172 IDS_ASH_STATUS_TRAY_IME_SETTINGS), 169 IDS_ASH_STATUS_TRAY_IME_SETTINGS),
173 gfx::ALIGN_LEFT, false /* highlight */); 170 gfx::ALIGN_LEFT, false /* highlight */);
174 AddChildView(one_settings_button_view_); 171 AddChildView(one_settings_button_view_);
175 } 172 }
176 173
177 // Shows the UI of more than one buttons. 174 // Shows the UI of more than one buttons.
178 void ShowButtons(bool show_emoji_button, 175 void ShowButtons(bool show_emoji_button,
176 bool show_handwriting_button,
179 bool show_voice_button, 177 bool show_voice_button,
180 bool show_handwriting_button,
181 bool show_settings_button) { 178 bool show_settings_button) {
182 set_background( 179 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
183 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); 180 kButtonInsideBorderSpacing,
184 auto* box_layout = new views::BoxLayout( 181 kButtonInsideBorderSpacing, 0);
185 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding, 182 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) {
186 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); 183 set_background(
187 box_layout->SetDefaultFlex(1); 184 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
185 box_layout->SetDefaultFlex(1);
186 }
188 SetLayoutManager(box_layout); 187 SetLayoutManager(box_layout);
189 188
189 const int right_border = 1;
190 if (show_emoji_button) { 190 if (show_emoji_button) {
191 // TODO(azurewei): Creates the proper button with icons.
192 emoji_button_ = CreateImeMenuButton( 191 emoji_button_ = CreateImeMenuButton(
193 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 192 this, CreateVectorIcon(kImeMenuEmoticonIcon, kMenuIconColor),
194 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 193 IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border);
195 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS,
196 kButtonRightBorder);
197 AddChildView(emoji_button_); 194 AddChildView(emoji_button_);
198 } 195 }
199 196
197 if (show_handwriting_button) {
198 handwriting_button_ = CreateImeMenuButton(
199 this, CreateVectorIcon(kImeMenuWriteIcon, kMenuIconColor),
200 IDS_ASH_STATUS_TRAY_IME_HANDWRITING, right_border);
201 AddChildView(handwriting_button_);
202 }
203
200 if (show_voice_button) { 204 if (show_voice_button) {
201 // TODO(azurewei): Creates the proper button with icons.
202 voice_button_ = CreateImeMenuButton( 205 voice_button_ = CreateImeMenuButton(
203 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 206 this, CreateVectorIcon(kImeMenuMicrophoneIcon, kMenuIconColor),
204 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 207 IDS_ASH_STATUS_TRAY_IME_VOICE, right_border);
205 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS,
206 kButtonRightBorder);
207 AddChildView(voice_button_); 208 AddChildView(voice_button_);
208 } 209 }
209 210
210 if (show_handwriting_button) {
211 // TODO(azurewei): Creates the proper button with icons.
212 handwriting_button_ = CreateImeMenuButton(
213 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
214 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
215 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS,
216 kButtonRightBorder);
217 AddChildView(handwriting_button_);
218 }
219
220 if (show_settings_button) { 211 if (show_settings_button) {
212 // TODO(tdanderson): update this settings icon.
221 settings_button_ = CreateImeMenuButton( 213 settings_button_ = CreateImeMenuButton(
222 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 214 this, CreateVectorIcon(gfx::VectorIconId::SETTINGS, kMenuIconSize,
223 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 215 kMenuIconColor),
224 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); 216 IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0);
225 AddChildView(settings_button_); 217 AddChildView(settings_button_);
226 } 218 }
227 } 219 }
228 220
229 ImeMenuTray* ime_menu_tray_; 221 ImeMenuTray* ime_menu_tray_;
230 TrayPopupHeaderButton* emoji_button_; 222 TrayPopupHeaderButton* emoji_button_;
223 TrayPopupHeaderButton* handwriting_button_;
231 TrayPopupHeaderButton* voice_button_; 224 TrayPopupHeaderButton* voice_button_;
232 TrayPopupHeaderButton* handwriting_button_;
233 TrayPopupHeaderButton* settings_button_; 225 TrayPopupHeaderButton* settings_button_;
234 HoverHighlightView* one_settings_button_view_; 226 HoverHighlightView* one_settings_button_view_;
235 227
236 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 228 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
237 }; 229 };
238 230
239 } // namespace 231 } // namespace
240 232
241 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 233 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
242 : TrayBackgroundView(wm_shelf), 234 : TrayBackgroundView(wm_shelf),
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_); 465 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_);
474 466
475 // Updates the tray label based on the current input method. 467 // Updates the tray label based on the current input method.
476 if (current_ime_.third_party) 468 if (current_ime_.third_party)
477 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); 469 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*"));
478 else 470 else
479 label_->SetText(current_ime_.short_name); 471 label_->SetText(current_ime_.short_name);
480 } 472 }
481 473
482 } // namespace ash 474 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_strings.grd ('k') | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698