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

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: 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 explicit ImeSettingButtonView() {
James Cook 2016/08/26 16:09:24 no explicit. Only do this with single-parameter c
Azure Wei 2016/08/26 22:09:57 Done.
86 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
87 ash::kTrayPopupPaddingHorizontal, 0,
James Cook 2016/08/26 16:09:24 no ash::
Azure Wei 2016/08/26 22:09:57 Done.
88 ash::kTrayPopupPaddingBetweenItems));
89
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
91 views::ImageView* icon = new ash::FixedSizedImageView(
James Cook 2016/08/26 16:09:24 no ash::
Azure Wei 2016/08/26 22:09:57 Done.
92 0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
93 icon->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
94 icon->set_id(test::kSettingsTrayItemViewId);
James Cook 2016/08/26 16:09:24 Do you have tests that need to look things up with
Azure Wei 2016/08/26 22:09:57 Removed.
95 AddChildView(icon);
96
97 base::string16 text =
98 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_INPUT_SETTINGS);
99 views::Label* label = new views::Label(text);
100 AddChildView(label);
101 SetAccessibleName(text);
102 }
103
104 ~ImeSettingButtonView() override {}
105
106 // ash::ActionableView.
James Cook 2016/08/26 16:09:24 Just "ActionableView:"
Azure Wei 2016/08/26 22:09:56 Done.
107 bool PerformAction(const ui::Event& event) override {
108 ShowIMESettings();
109 return true;
110 }
111
112 private:
113 DISALLOW_COPY_AND_ASSIGN(ImeSettingButtonView);
114 };
115
72 class ImeButtonsView : public views::View, public views::ButtonListener { 116 class ImeButtonsView : public views::View, public views::ButtonListener {
73 public: 117 public:
74 ImeButtonsView(bool show_emoji_button, 118 ImeButtonsView(bool show_emoji_button,
75 bool show_voice_button, 119 bool show_voice_button,
76 bool show_handwriting_button, 120 bool show_handwriting_button,
77 bool show_settings_button) { 121 bool show_settings_button) {
78 set_background( 122 set_background(
79 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); 123 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
80 SetBorder( 124 SetBorder(
81 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); 125 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor));
(...skipping 10 matching lines...) Expand all
92 136
93 if (show_voice_button) { 137 if (show_voice_button) {
94 // TODO(azurewei): Creates the proper button with icons. 138 // TODO(azurewei): Creates the proper button with icons.
95 } 139 }
96 140
97 if (show_handwriting_button) { 141 if (show_handwriting_button) {
98 // TODO(azurewei): Creates the proper button with icons. 142 // TODO(azurewei): Creates the proper button with icons.
99 } 143 }
100 144
101 if (show_settings_button) { 145 if (show_settings_button) {
102 settings_button_ = CreateImeMenuButton( 146 // 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, 147 // just show the icon.
104 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, 148 if (!show_emoji_button && !show_voice_button &&
105 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); 149 !show_handwriting_button) {
106 AddChildView(settings_button_); 150 settings_button_with_text_ = new ImeSettingButtonView();
151 AddChildView(settings_button_with_text_);
152 } else {
153 settings_button_ = CreateImeMenuButton(
154 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
155 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS,
156 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0);
157 AddChildView(settings_button_);
158 }
107 } 159 }
108 } 160 }
109 161
110 ~ImeButtonsView() override {} 162 ~ImeButtonsView() override {}
111 163
112 // views::View: 164 // views::View:
113 gfx::Size GetPreferredSize() const override { 165 gfx::Size GetPreferredSize() const override {
114 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 166 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
115 return gfx::Size(size, size); 167 return gfx::Size(size, size);
116 } 168 }
117 int GetHeightForWidth(int width) const override { 169 int GetHeightForWidth(int width) const override {
118 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 170 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
119 } 171 }
120 172
121 // views::ButtonListener: 173 // views::ButtonListener:
122 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 174 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
123 if (emoji_button_ && sender == emoji_button_) { 175 if (emoji_button_ && sender == emoji_button_) {
124 // TODO(azurewei): Opens emoji palette. 176 // TODO(azurewei): Opens emoji palette.
125 } else if (voice_button_ && sender == voice_button_) { 177 } else if (voice_button_ && sender == voice_button_) {
126 // TODO(azurewei): Brings virtual keyboard for emoji input. 178 // TODO(azurewei): Brings virtual keyboard for emoji input.
127 } else if (handwriting_button_ && sender == handwriting_button_) { 179 } else if (handwriting_button_ && sender == handwriting_button_) {
128 // TODO(azurewei): Brings virtual keyboard for handwriting input. 180 // TODO(azurewei): Brings virtual keyboard for handwriting input.
129 } else if (settings_button_ && sender == settings_button_) { 181 } else if (settings_button_ && sender == settings_button_) {
130 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 182 ShowIMESettings();
131 WmShell::Get()->RecordUserMetricsAction(
132 UMA_STATUS_AREA_IME_SHOW_DETAILED);
133 delegate->ShowIMESettings();
134 } 183 }
135 } 184 }
136 185
137 private: 186 private:
138 TrayPopupHeaderButton* emoji_button_; 187 TrayPopupHeaderButton* emoji_button_;
139 TrayPopupHeaderButton* voice_button_; 188 TrayPopupHeaderButton* voice_button_;
140 TrayPopupHeaderButton* handwriting_button_; 189 TrayPopupHeaderButton* handwriting_button_;
141 TrayPopupHeaderButton* settings_button_; 190 TrayPopupHeaderButton* settings_button_;
191 ImeSettingButtonView* settings_button_with_text_;
142 192
143 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 193 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
144 }; 194 };
145 195
146 } // namespace 196 } // namespace
147 197
148 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 198 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
149 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { 199 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) {
150 SetupLabelForTray(label_); 200 SetupLabelForTray(label_);
151 tray_container()->AddChildView(label_); 201 tray_container()->AddChildView(label_);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); 336 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view));
287 SetDrawBackgroundAsActive(true); 337 SetDrawBackgroundAsActive(true);
288 } 338 }
289 339
290 void ImeMenuTray::HideImeMenuBubble() { 340 void ImeMenuTray::HideImeMenuBubble() {
291 bubble_.reset(); 341 bubble_.reset();
292 SetDrawBackgroundAsActive(false); 342 SetDrawBackgroundAsActive(false);
293 } 343 }
294 344
295 } // namespace ash 345 } // 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