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

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: Updated with vectorized icons. 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
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/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 9 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/shell_window_ids.h" 10 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" 11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h"
12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 12 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
13 #include "ash/common/system/tray/hover_highlight_view.h" 13 #include "ash/common/system/tray/hover_highlight_view.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/system_tray_notifier.h" 15 #include "ash/common/system/tray/system_tray_notifier.h"
16 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
17 #include "ash/common/system/tray/tray_popup_header_button.h" 17 #include "ash/common/system/tray/tray_popup_header_button.h"
18 #include "ash/common/system/tray/tray_utils.h" 18 #include "ash/common/system/tray/tray_utils.h"
19 #include "ash/common/wm_lookup.h" 19 #include "ash/common/wm_lookup.h"
20 #include "ash/common/wm_root_window_controller.h" 20 #include "ash/common/wm_root_window_controller.h"
21 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
22 #include "ash/common/wm_window.h" 22 #include "ash/common/wm_window.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
25 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/color_palette.h"
29 #include "ui/gfx/paint_vector_icon.h"
30 #include "ui/gfx/vector_icons_public.h"
28 #include "ui/views/controls/label.h" 31 #include "ui/views/controls/label.h"
29 #include "ui/views/layout/box_layout.h" 32 #include "ui/views/layout/box_layout.h"
30 33
31 namespace ash { 34 namespace ash {
32 35
33 namespace { 36 namespace {
37 // The button icon size in dp.
38 const int kButtonIconSize = 20;
tdanderson 2016/09/19 15:44:34 There is already a constant kMenuIconSize in tray_
Azure Wei 2016/09/20 01:05:45 Done.
39
40 // The height of the button view in dp.
41 const int kButtonViewHeight = 56;
tdanderson 2016/09/19 15:44:34 I have a CL in progress that will be adding kMenuB
Azure Wei 2016/09/20 01:05:44 Done.
42
43 // The additional space between the child view area and the host button view
44 // border in dp.
45 const int kButtonInsideBorderSpacing = 4;
tdanderson 2016/09/19 15:44:34 This padding constant of 4 will be seen a lot in A
Azure Wei 2016/09/20 01:05:45 Done.
34 46
35 // Returns the max height of ImeListView. 47 // Returns the max height of ImeListView.
36 int GetImeListViewMaxHeight() { 48 int GetImeListViewMaxHeight() {
37 const int max_items = 7; 49 const int max_items = 7;
38 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items; 50 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items;
39 } 51 }
40 52
41 // Shows language and input settings page. 53 // Shows language and input settings page.
42 void ShowIMESettings() { 54 void ShowIMESettings() {
43 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 55 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
44 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED); 56 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
45 delegate->ShowIMESettings(); 57 delegate->ShowIMESettings();
46 } 58 }
47 59
48 class ImeMenuLabel : public views::Label { 60 class ImeMenuLabel : public views::Label {
49 public: 61 public:
50 ImeMenuLabel() {} 62 ImeMenuLabel() {}
51 ~ImeMenuLabel() override {} 63 ~ImeMenuLabel() override {}
52 64
53 // views:Label: 65 // views:Label:
54 gfx::Size GetPreferredSize() const override { 66 gfx::Size GetPreferredSize() const override {
55 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); 67 const int tray_constant = GetTrayConstant(TRAY_IME_MENU_ICON);
68 return gfx::Size(tray_constant, tray_constant);
56 } 69 }
57 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; } 70 int GetHeightForWidth(int width) const override {
71 return GetTrayConstant(TRAY_IME_MENU_ICON);
72 }
58 73
59 private: 74 private:
60 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); 75 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel);
61 }; 76 };
62 77
63 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener, 78 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener,
64 int enabled_resource_id, 79 gfx::VectorIconId vector_id,
65 int disabled_resource_id, 80 int accessible_name_id) {
66 int enabled_resource_id_hover, 81 TrayPopupHeaderButton* button = new TrayPopupHeaderButton(
67 int disabled_resource_id_hover, 82 listener,
68 int accessible_name_id, 83 CreateVectorIcon(vector_id, kButtonIconSize, gfx::kChromeIconGrey),
tdanderson 2016/09/19 15:44:34 Please use kMenuIconColor (found in tray_constants
Azure Wei 2016/09/20 01:05:45 Done.
69 int message_id, 84 accessible_name_id);
70 int right_border) { 85 button->SetTooltipText(l10n_util::GetStringUTF16(accessible_name_id));
71 TrayPopupHeaderButton* button =
72 new TrayPopupHeaderButton(listener, enabled_resource_id,
73 disabled_resource_id, enabled_resource_id_hover,
74 disabled_resource_id_hover, accessible_name_id);
75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id));
76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border,
77 kBorderDarkColor));
78 return button; 86 return button;
79 } 87 }
80 88
81 // The view that contains buttons shown on the bottom of IME menu. 89 // The view that contains buttons shown on the bottom of IME menu.
82 class ImeButtonsView : public views::View, 90 class ImeButtonsView : public views::View,
83 public views::ButtonListener, 91 public views::ButtonListener,
84 public ViewClickListener { 92 public ViewClickListener {
85 public: 93 public:
86 ImeButtonsView(bool show_emoji_button, 94 ImeButtonsView(bool show_emoji_button,
95 bool show_handwriting_button,
87 bool show_voice_button, 96 bool show_voice_button,
88 bool show_handwriting_button,
89 bool show_settings_button) { 97 bool show_settings_button) {
90 SetBorder( 98 SetBorder(
91 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); 99 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor));
92 100
93 // If there's only one settings button, the bottom should be a label with 101 // If there's only one settings button, the bottom should be a label with
94 // normal background. Otherwise, show button icons with header background. 102 // normal background. Otherwise, show button icons with header background.
95 if (show_settings_button && !show_emoji_button && !show_voice_button && 103 if (show_settings_button && !show_emoji_button &&
96 !show_handwriting_button) { 104 !show_handwriting_button && !show_voice_button) {
97 ShowOneSettingButton(); 105 ShowOneSettingButton();
98 } else { 106 } else {
99 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button, 107 ShowButtons(show_emoji_button, show_handwriting_button, show_voice_button,
100 show_settings_button); 108 show_settings_button);
101 } 109 }
102 // TODO(azurewei): Add logic of switching between the two states when the
103 // menu is shown.
104 } 110 }
105 111
106 ~ImeButtonsView() override {} 112 ~ImeButtonsView() override {}
107 113
108 // views::View: 114 // views::View:
109 gfx::Size GetPreferredSize() const override { 115 int GetHeightForWidth(int width) const override { return kButtonViewHeight; }
110 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
111 return gfx::Size(size, size);
112 }
113 int GetHeightForWidth(int width) const override {
114 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
115 }
116 116
117 // views::ButtonListener: 117 // views::ButtonListener:
118 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 118 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
119 if (emoji_button_ && sender == emoji_button_) { 119 if (emoji_button_ && sender == emoji_button_) {
120 // TODO(azurewei): Opens emoji palette. 120 // TODO(azurewei): Opens emoji palette.
121 } else if (voice_button_ && sender == voice_button_) { 121 } else if (voice_button_ && sender == voice_button_) {
122 // TODO(azurewei): Brings virtual keyboard for emoji input. 122 // TODO(azurewei): Brings virtual keyboard for emoji input.
123 } else if (handwriting_button_ && sender == handwriting_button_) { 123 } else if (handwriting_button_ && sender == handwriting_button_) {
124 // TODO(azurewei): Brings virtual keyboard for handwriting input. 124 // TODO(azurewei): Brings virtual keyboard for handwriting input.
125 } else if (settings_button_ && sender == settings_button_) { 125 } else if (settings_button_ && sender == settings_button_) {
(...skipping 18 matching lines...) Expand all
144 one_settings_button_view_ = new HoverHighlightView(this); 144 one_settings_button_view_ = new HoverHighlightView(this);
145 one_settings_button_view_->AddLabel( 145 one_settings_button_view_->AddLabel(
146 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 146 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
147 IDS_ASH_STATUS_TRAY_IME_SETTINGS), 147 IDS_ASH_STATUS_TRAY_IME_SETTINGS),
148 gfx::ALIGN_LEFT, false /* highlight */); 148 gfx::ALIGN_LEFT, false /* highlight */);
149 AddChildView(one_settings_button_view_); 149 AddChildView(one_settings_button_view_);
150 } 150 }
151 151
152 // Shows the UI of more than one buttons. 152 // Shows the UI of more than one buttons.
153 void ShowButtons(bool show_emoji_button, 153 void ShowButtons(bool show_emoji_button,
154 bool show_handwriting_button,
154 bool show_voice_button, 155 bool show_voice_button,
155 bool show_handwriting_button,
156 bool show_settings_button) { 156 bool show_settings_button) {
157 set_background( 157 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
158 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); 158 kButtonInsideBorderSpacing,
159 auto* box_layout = new views::BoxLayout( 159 kButtonInsideBorderSpacing, 0);
160 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding,
161 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems);
162 box_layout->SetDefaultFlex(1);
163 SetLayoutManager(box_layout); 160 SetLayoutManager(box_layout);
164 161
165 if (show_emoji_button) { 162 if (show_emoji_button) {
166 // TODO(azurewei): Creates the proper button with icons. 163 emoji_button_ = CreateImeMenuButton(this, gfx::VectorIconId::EMOTICON,
164 IDS_ASH_STATUS_TRAY_IME_EMOJI);
165 AddChildView(emoji_button_);
166 }
167
168 if (show_handwriting_button) {
169 handwriting_button_ = CreateImeMenuButton(
170 this, gfx::VectorIconId::WRITE, IDS_ASH_STATUS_TRAY_IME_HANDWRITING);
171 AddChildView(handwriting_button_);
167 } 172 }
168 173
169 if (show_voice_button) { 174 if (show_voice_button) {
170 // TODO(azurewei): Creates the proper button with icons. 175 voice_button_ = CreateImeMenuButton(this, gfx::VectorIconId::MICROPHONE,
171 } 176 IDS_ASH_STATUS_TRAY_IME_VOICE);
172 177 AddChildView(voice_button_);
173 if (show_handwriting_button) {
174 // TODO(azurewei): Creates the proper button with icons.
175 } 178 }
176 179
177 if (show_settings_button) { 180 if (show_settings_button) {
178 settings_button_ = CreateImeMenuButton( 181 settings_button_ = CreateImeMenuButton(this, gfx::VectorIconId::SETTINGS,
tdanderson 2016/09/19 15:44:34 The preexisting settings icon actually doesn't loo
Azure Wei 2016/09/20 01:05:45 Done.
179 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 182 IDS_ASH_STATUS_TRAY_IME_SETTINGS);
180 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
181 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0);
182 AddChildView(settings_button_); 183 AddChildView(settings_button_);
183 } 184 }
184 } 185 }
185 186
186 TrayPopupHeaderButton* emoji_button_; 187 TrayPopupHeaderButton* emoji_button_;
188 TrayPopupHeaderButton* handwriting_button_;
187 TrayPopupHeaderButton* voice_button_; 189 TrayPopupHeaderButton* voice_button_;
188 TrayPopupHeaderButton* handwriting_button_;
189 TrayPopupHeaderButton* settings_button_; 190 TrayPopupHeaderButton* settings_button_;
190 HoverHighlightView* one_settings_button_view_; 191 HoverHighlightView* one_settings_button_view_;
191 192
192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 193 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
193 }; 194 };
194 195
195 } // namespace 196 } // namespace
196 197
197 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 198 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
198 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { 199 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 label_->SetText(current_ime_.short_name); 351 label_->SetText(current_ime_.short_name);
351 } 352 }
352 353
353 void ImeMenuTray::HideImeMenuBubble() { 354 void ImeMenuTray::HideImeMenuBubble() {
354 bubble_.reset(); 355 bubble_.reset();
355 ime_list_view_ = nullptr; 356 ime_list_view_ = nullptr;
356 SetDrawBackgroundAsActive(false); 357 SetDrawBackgroundAsActive(false);
357 } 358 }
358 359
359 } // namespace ash 360 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698