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

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

Issue 2287453002: Change UI of settings button on IME menu. (Closed)
Patch Set: Addressed nits. 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_chromeos_strings.grdp ('k') | no next file » | 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_image_view.h"
12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 13 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
13 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
14 #include "ash/common/system/tray/system_tray_notifier.h" 15 #include "ash/common/system/tray/system_tray_notifier.h"
15 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
16 #include "ash/common/system/tray/tray_popup_header_button.h" 17 #include "ash/common/system/tray/tray_popup_header_button.h"
17 #include "ash/common/system/tray/tray_utils.h" 18 #include "ash/common/system/tray/tray_utils.h"
18 #include "ash/common/wm_lookup.h" 19 #include "ash/common/wm_lookup.h"
19 #include "ash/common/wm_root_window_controller.h" 20 #include "ash/common/wm_root_window_controller.h"
20 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
21 #include "ash/common/wm_window.h" 22 #include "ash/common/wm_window.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/views/controls/label.h" 28 #include "ui/views/controls/label.h"
27 #include "ui/views/layout/box_layout.h" 29 #include "ui/views/layout/box_layout.h"
28 30
29 namespace ash { 31 namespace ash {
30 32
31 namespace { 33 namespace {
32 34
33 // Returns the max height of ImeListView. 35 // Returns the max height of ImeListView.
34 int GetImeListViewMaxHeight() { 36 int GetImeListViewMaxHeight() {
35 const int max_items = 7; 37 const int max_items = 7;
36 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items; 38 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * max_items;
37 } 39 }
38 40
41 // Shows language and input settings page.
42 void ShowIMESettings() {
43 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
44 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
45 delegate->ShowIMESettings();
46 }
47
39 class ImeMenuLabel : public views::Label { 48 class ImeMenuLabel : public views::Label {
40 public: 49 public:
41 ImeMenuLabel() {} 50 ImeMenuLabel() {}
42 ~ImeMenuLabel() override {} 51 ~ImeMenuLabel() override {}
43 52
44 // views:Label: 53 // views:Label:
45 gfx::Size GetPreferredSize() const override { 54 gfx::Size GetPreferredSize() const override {
46 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); 55 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize);
47 } 56 }
48 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; } 57 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; }
(...skipping 13 matching lines...) Expand all
62 TrayPopupHeaderButton* button = new ash::TrayPopupHeaderButton( 71 TrayPopupHeaderButton* button = new ash::TrayPopupHeaderButton(
63 listener, enabled_resource_id, disabled_resource_id, 72 listener, enabled_resource_id, disabled_resource_id,
64 enabled_resource_id_hover, disabled_resource_id_hover, 73 enabled_resource_id_hover, disabled_resource_id_hover,
65 accessible_name_id); 74 accessible_name_id);
66 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); 75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id));
67 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, 76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border,
68 kBorderDarkColor)); 77 kBorderDarkColor));
69 return button; 78 return button;
70 } 79 }
71 80
81 // The IME menu settings view when there's only one button on the menu. It shows
82 // the setting gear left-aligned with label.
83 class ImeSettingButtonView : public ActionableView {
84 public:
85 ImeSettingButtonView() {
86 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
87 kTrayPopupPaddingHorizontal, 0,
88 kTrayPopupPaddingBetweenItems));
89
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
91 views::ImageView* icon =
92 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
93 icon->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
94 AddChildView(icon);
95
96 base::string16 text =
97 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_INPUT_SETTINGS);
98 views::Label* label = new views::Label(text);
99 AddChildView(label);
100 SetAccessibleName(text);
101 }
102
103 ~ImeSettingButtonView() override {}
104
105 // ActionableView.
106 bool PerformAction(const ui::Event& event) override {
107 ShowIMESettings();
108 return true;
109 }
110
111 private:
112 DISALLOW_COPY_AND_ASSIGN(ImeSettingButtonView);
113 };
114
72 class ImeButtonsView : public views::View, public views::ButtonListener { 115 class ImeButtonsView : public views::View, public views::ButtonListener {
73 public: 116 public:
74 ImeButtonsView(bool show_emoji_button, 117 ImeButtonsView(bool show_emoji_button,
75 bool show_voice_button, 118 bool show_voice_button,
76 bool show_handwriting_button, 119 bool show_handwriting_button,
77 bool show_settings_button) { 120 bool show_settings_button) {
78 set_background( 121 set_background(
79 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); 122 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
80 SetBorder( 123 SetBorder(
81 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); 124 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor));
(...skipping 10 matching lines...) Expand all
92 135
93 if (show_voice_button) { 136 if (show_voice_button) {
94 // TODO(azurewei): Creates the proper button with icons. 137 // TODO(azurewei): Creates the proper button with icons.
95 } 138 }
96 139
97 if (show_handwriting_button) { 140 if (show_handwriting_button) {
98 // TODO(azurewei): Creates the proper button with icons. 141 // TODO(azurewei): Creates the proper button with icons.
99 } 142 }
100 143
101 if (show_settings_button) { 144 if (show_settings_button) {
102 settings_button_ = CreateImeMenuButton( 145 // If there's only one button, we show the gear icon with text. Otherwise,
103 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 146 // just show the icon.
104 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 147 if (!show_emoji_button && !show_voice_button &&
105 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); 148 !show_handwriting_button) {
106 AddChildView(settings_button_); 149 settings_button_with_text_ = new ImeSettingButtonView();
150 AddChildView(settings_button_with_text_);
151 } else {
152 settings_button_ = CreateImeMenuButton(
153 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
154 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
155 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0);
156 AddChildView(settings_button_);
157 }
107 } 158 }
108 } 159 }
109 160
110 ~ImeButtonsView() override {} 161 ~ImeButtonsView() override {}
111 162
112 // views::View: 163 // views::View:
113 gfx::Size GetPreferredSize() const override { 164 gfx::Size GetPreferredSize() const override {
114 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 165 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
115 return gfx::Size(size, size); 166 return gfx::Size(size, size);
116 } 167 }
117 int GetHeightForWidth(int width) const override { 168 int GetHeightForWidth(int width) const override {
118 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 169 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
119 } 170 }
120 171
121 // views::ButtonListener: 172 // views::ButtonListener:
122 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 173 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
123 if (emoji_button_ && sender == emoji_button_) { 174 if (emoji_button_ && sender == emoji_button_) {
124 // TODO(azurewei): Opens emoji palette. 175 // TODO(azurewei): Opens emoji palette.
125 } else if (voice_button_ && sender == voice_button_) { 176 } else if (voice_button_ && sender == voice_button_) {
126 // TODO(azurewei): Brings virtual keyboard for emoji input. 177 // TODO(azurewei): Brings virtual keyboard for emoji input.
127 } else if (handwriting_button_ && sender == handwriting_button_) { 178 } else if (handwriting_button_ && sender == handwriting_button_) {
128 // TODO(azurewei): Brings virtual keyboard for handwriting input. 179 // TODO(azurewei): Brings virtual keyboard for handwriting input.
129 } else if (settings_button_ && sender == settings_button_) { 180 } else if (settings_button_ && sender == settings_button_) {
130 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 181 ShowIMESettings();
131 WmShell::Get()->RecordUserMetricsAction(
132 UMA_STATUS_AREA_IME_SHOW_DETAILED);
133 delegate->ShowIMESettings();
134 } 182 }
135 } 183 }
136 184
137 private: 185 private:
138 TrayPopupHeaderButton* emoji_button_; 186 TrayPopupHeaderButton* emoji_button_;
139 TrayPopupHeaderButton* voice_button_; 187 TrayPopupHeaderButton* voice_button_;
140 TrayPopupHeaderButton* handwriting_button_; 188 TrayPopupHeaderButton* handwriting_button_;
141 TrayPopupHeaderButton* settings_button_; 189 TrayPopupHeaderButton* settings_button_;
190 ImeSettingButtonView* settings_button_with_text_;
142 191
143 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
144 }; 193 };
145 194
146 } // namespace 195 } // namespace
147 196
148 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 197 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
149 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { 198 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) {
150 SetupLabelForTray(label_); 199 SetupLabelForTray(label_);
151 tray_container()->AddChildView(label_); 200 tray_container()->AddChildView(label_);
152 SetContentsBackground(); 201 SetContentsBackground();
153 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); 202 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this);
154 } 203 }
155 204
156 ImeMenuTray::~ImeMenuTray() { 205 ImeMenuTray::~ImeMenuTray() {
157 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); 206 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this);
158 } 207 }
159 208
160 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { 209 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) {
161 TrayBackgroundView::SetShelfAlignment(alignment); 210 TrayBackgroundView::SetShelfAlignment(alignment);
162 if (!ash::MaterialDesignController::IsShelfMaterial()) 211 if (!MaterialDesignController::IsShelfMaterial())
163 tray_container()->SetBorder(views::Border::NullBorder()); 212 tray_container()->SetBorder(views::Border::NullBorder());
164 } 213 }
165 214
166 base::string16 ImeMenuTray::GetAccessibleNameForTray() { 215 base::string16 ImeMenuTray::GetAccessibleNameForTray() {
167 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); 216 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
168 } 217 }
169 218
170 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { 219 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
171 if (bubble_->bubble_view() == bubble_view) 220 if (bubble_->bubble_view() == bubble_view)
172 HideImeMenuBubble(); 221 HideImeMenuBubble();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); 335 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view));
287 SetDrawBackgroundAsActive(true); 336 SetDrawBackgroundAsActive(true);
288 } 337 }
289 338
290 void ImeMenuTray::HideImeMenuBubble() { 339 void ImeMenuTray::HideImeMenuBubble() {
291 bubble_.reset(); 340 bubble_.reset();
292 SetDrawBackgroundAsActive(false); 341 SetDrawBackgroundAsActive(false);
293 } 342 }
294 343
295 } // namespace ash 344 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_chromeos_strings.grdp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698