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

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: 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/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 "ash/resources/vector_icons/vector_icons.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "grit/ash_resources.h" 25 #include "grit/ash_resources.h"
25 #include "grit/ash_strings.h" 26 #include "grit/ash_strings.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/paint_vector_icon.h"
30 #include "ui/gfx/vector_icons_public.h"
tdanderson 2016/09/20 13:11:12 nit: this is not needed since you're including vec
Azure Wei 2016/09/20 14:43:57 This is needed by settings button.
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 additional space between the child view area and the host button view
38 // border in dp.
39 // TODO(tdanderson): Move this to tray_constants.
40 const int kButtonInsideBorderSpacing = 4;
34 41
35 // Returns the max height of ImeListView. 42 // Returns the max height of ImeListView.
36 int GetImeListViewMaxHeight() { 43 int GetImeListViewMaxHeight() {
37 const int max_items = 7; 44 const int max_items = 7;
38 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items; 45 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items;
39 } 46 }
40 47
41 // Shows language and input settings page. 48 // Shows language and input settings page.
42 void ShowIMESettings() { 49 void ShowIMESettings() {
43 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 50 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
44 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED); 51 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
45 delegate->ShowIMESettings(); 52 delegate->ShowIMESettings();
46 } 53 }
47 54
48 class ImeMenuLabel : public views::Label { 55 class ImeMenuLabel : public views::Label {
49 public: 56 public:
50 ImeMenuLabel() {} 57 ImeMenuLabel() {}
51 ~ImeMenuLabel() override {} 58 ~ImeMenuLabel() override {}
52 59
53 // views:Label: 60 // views:Label:
54 gfx::Size GetPreferredSize() const override { 61 gfx::Size GetPreferredSize() const override {
55 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); 62 const int tray_constant = GetTrayConstant(TRAY_IME_MENU_ICON);
63 return gfx::Size(tray_constant, tray_constant);
56 } 64 }
57 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; } 65 int GetHeightForWidth(int width) const override {
66 return GetTrayConstant(TRAY_IME_MENU_ICON);
67 }
58 68
59 private: 69 private:
60 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); 70 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel);
61 }; 71 };
62 72
63 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener, 73 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener,
64 int enabled_resource_id, 74 const gfx::ImageSkia& image,
65 int disabled_resource_id,
66 int enabled_resource_id_hover,
67 int disabled_resource_id_hover,
68 int accessible_name_id, 75 int accessible_name_id,
69 int message_id,
70 int right_border) { 76 int right_border) {
71 TrayPopupHeaderButton* button = 77 TrayPopupHeaderButton* button =
72 new TrayPopupHeaderButton(listener, enabled_resource_id, 78 new TrayPopupHeaderButton(listener, image, accessible_name_id);
73 disabled_resource_id, enabled_resource_id_hover, 79 button->SetTooltipText(l10n_util::GetStringUTF16(accessible_name_id));
74 disabled_resource_id_hover, accessible_name_id); 80 if (!MaterialDesignController::IsShelfMaterial()) {
75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); 81 button->SetBorder(views::Border::CreateSolidSidedBorder(
76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, 82 0, 0, 0, right_border, kBorderDarkColor));
77 kBorderDarkColor)); 83 }
78 return button; 84 return button;
79 } 85 }
80 86
81 // The view that contains buttons shown on the bottom of IME menu. 87 // The view that contains buttons shown on the bottom of IME menu.
82 class ImeButtonsView : public views::View, 88 class ImeButtonsView : public views::View,
83 public views::ButtonListener, 89 public views::ButtonListener,
84 public ViewClickListener { 90 public ViewClickListener {
85 public: 91 public:
86 ImeButtonsView(bool show_emoji_button, 92 ImeButtonsView(bool show_emoji_button,
93 bool show_handwriting_button,
87 bool show_voice_button, 94 bool show_voice_button,
88 bool show_handwriting_button,
89 bool show_settings_button) { 95 bool show_settings_button) {
90 SetBorder( 96 SetBorder(
91 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); 97 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor));
92 98
93 // If there's only one settings button, the bottom should be a label with 99 // If there's only one settings button, the bottom should be a label with
94 // normal background. Otherwise, show button icons with header background. 100 // normal background. Otherwise, show button icons with header background.
95 if (show_settings_button && !show_emoji_button && !show_voice_button && 101 if (show_settings_button && !show_emoji_button &&
96 !show_handwriting_button) { 102 !show_handwriting_button && !show_voice_button) {
97 ShowOneSettingButton(); 103 ShowOneSettingButton();
98 } else { 104 } else {
99 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button, 105 ShowButtons(show_emoji_button, show_handwriting_button, show_voice_button,
100 show_settings_button); 106 show_settings_button);
101 } 107 }
102 // TODO(azurewei): Add logic of switching between the two states when the
103 // menu is shown.
104 } 108 }
105 109
106 ~ImeButtonsView() override {} 110 ~ImeButtonsView() override {}
107 111
108 // views::View: 112 // views::View:
109 gfx::Size GetPreferredSize() const override {
110 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
111 return gfx::Size(size, size);
112 }
113 int GetHeightForWidth(int width) const override { 113 int GetHeightForWidth(int width) const override {
114 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 114 return kMenuButtonSize + 2 * kButtonInsideBorderSpacing;
115 } 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.
(...skipping 19 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, 160 if (!MaterialDesignController::IsShelfMaterial()) {
tdanderson 2016/09/20 13:11:12 Since the changes here are for the buttons inside
Azure Wei 2016/09/20 14:43:57 Done.
161 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); 161 set_background(
162 box_layout->SetDefaultFlex(1); 162 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
163 box_layout->SetDefaultFlex(1);
164 }
163 SetLayoutManager(box_layout); 165 SetLayoutManager(box_layout);
164 166
167 const int right_border = 1;
165 if (show_emoji_button) { 168 if (show_emoji_button) {
166 // TODO(azurewei): Creates the proper button with icons. 169 emoji_button_ = CreateImeMenuButton(
170 this, CreateVectorIcon(kImeMenuEmoticonIcon, kMenuIconColor),
171 IDS_ASH_STATUS_TRAY_IME_EMOJI, right_border);
172 AddChildView(emoji_button_);
173 }
174
175 if (show_handwriting_button) {
176 handwriting_button_ = CreateImeMenuButton(
177 this, CreateVectorIcon(kImeMenuWriteIcon, kMenuIconColor),
178 IDS_ASH_STATUS_TRAY_IME_HANDWRITING, right_border);
179 AddChildView(handwriting_button_);
167 } 180 }
168 181
169 if (show_voice_button) { 182 if (show_voice_button) {
170 // TODO(azurewei): Creates the proper button with icons. 183 voice_button_ = CreateImeMenuButton(
171 } 184 this, CreateVectorIcon(kImeMenuMicrophoneIcon, kMenuIconColor),
172 185 IDS_ASH_STATUS_TRAY_IME_VOICE, right_border);
173 if (show_handwriting_button) { 186 AddChildView(voice_button_);
174 // TODO(azurewei): Creates the proper button with icons.
175 } 187 }
176 188
177 if (show_settings_button) { 189 if (show_settings_button) {
190 // TODO(tdanderson): update this settings icon.
178 settings_button_ = CreateImeMenuButton( 191 settings_button_ = CreateImeMenuButton(
179 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 192 this, CreateVectorIcon(gfx::VectorIconId::SETTINGS, kMenuIconSize,
180 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 193 kMenuIconColor),
181 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); 194 IDS_ASH_STATUS_TRAY_IME_SETTINGS, 0);
182 AddChildView(settings_button_); 195 AddChildView(settings_button_);
183 } 196 }
184 } 197 }
185 198
186 TrayPopupHeaderButton* emoji_button_; 199 TrayPopupHeaderButton* emoji_button_;
200 TrayPopupHeaderButton* handwriting_button_;
187 TrayPopupHeaderButton* voice_button_; 201 TrayPopupHeaderButton* voice_button_;
188 TrayPopupHeaderButton* handwriting_button_;
189 TrayPopupHeaderButton* settings_button_; 202 TrayPopupHeaderButton* settings_button_;
190 HoverHighlightView* one_settings_button_view_; 203 HoverHighlightView* one_settings_button_view_;
191 204
192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 205 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
193 }; 206 };
194 207
195 } // namespace 208 } // namespace
196 209
197 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 210 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
198 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { 211 : 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); 363 label_->SetText(current_ime_.short_name);
351 } 364 }
352 365
353 void ImeMenuTray::HideImeMenuBubble() { 366 void ImeMenuTray::HideImeMenuBubble() {
354 bubble_.reset(); 367 bubble_.reset();
355 ime_list_view_ = nullptr; 368 ime_list_view_ = nullptr;
356 SetDrawBackgroundAsActive(false); 369 SetDrawBackgroundAsActive(false);
357 } 370 }
358 371
359 } // namespace ash 372 } // 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