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

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

Issue 2287953002: Update the UI of setting button on IME menu. (Closed)
Patch Set: Add class comments. 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"
13 #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"
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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 TrayPopupHeaderButton* button = 71 TrayPopupHeaderButton* button =
72 new TrayPopupHeaderButton(listener, enabled_resource_id, 72 new TrayPopupHeaderButton(listener, enabled_resource_id,
73 disabled_resource_id, enabled_resource_id_hover, 73 disabled_resource_id, enabled_resource_id_hover,
74 disabled_resource_id_hover, accessible_name_id); 74 disabled_resource_id_hover, accessible_name_id);
75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); 75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id));
76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, 76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border,
77 kBorderDarkColor)); 77 kBorderDarkColor));
78 return button; 78 return button;
79 } 79 }
80 80
81 // The IME menu settings view when there's only one button on the menu. It shows 81 // The view that contains buttons shown on the bottom of IME menu.
82 // the setting gear left-aligned with label. 82 class ImeButtonsView : public views::View,
83 class ImeSettingButtonView : public ActionableView { 83 public views::ButtonListener,
84 public: 84 public ViewClickListener {
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
115 class ImeButtonsView : public views::View, public views::ButtonListener {
116 public: 85 public:
117 ImeButtonsView(bool show_emoji_button, 86 ImeButtonsView(bool show_emoji_button,
118 bool show_voice_button, 87 bool show_voice_button,
119 bool show_handwriting_button, 88 bool show_handwriting_button,
120 bool show_settings_button) { 89 bool show_settings_button) {
121 set_background(
122 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
123 SetBorder( 90 SetBorder(
124 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); 91 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor));
125 92
126 auto* box_layout = new views::BoxLayout( 93 // If there's only one settings button, the bottom should be a label with
127 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding, 94 // normal background. Otherwise, show button icons with header background.
128 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); 95 if (show_settings_button && !show_emoji_button && !show_voice_button &&
129 box_layout->SetDefaultFlex(1); 96 !show_handwriting_button) {
130 SetLayoutManager(box_layout); 97 ShowOneSettingButton();
131 98 } else {
132 if (show_emoji_button) { 99 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button,
133 // TODO(azurewei): Creates the proper button with icons. 100 show_settings_button);
134 } 101 }
135 102 // TODO(azurewei): Add logic of switching between the two states when the
136 if (show_voice_button) { 103 // menu is shown.
137 // TODO(azurewei): Creates the proper button with icons.
138 }
139
140 if (show_handwriting_button) {
141 // TODO(azurewei): Creates the proper button with icons.
142 }
143
144 if (show_settings_button) {
145 // If there's only one button, we show the gear icon with text. Otherwise,
146 // just show the icon.
147 if (!show_emoji_button && !show_voice_button &&
148 !show_handwriting_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 }
158 }
159 } 104 }
160 105
161 ~ImeButtonsView() override {} 106 ~ImeButtonsView() override {}
162 107
163 // views::View: 108 // views::View:
164 gfx::Size GetPreferredSize() const override { 109 gfx::Size GetPreferredSize() const override {
165 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 110 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
166 return gfx::Size(size, size); 111 return gfx::Size(size, size);
167 } 112 }
168 int GetHeightForWidth(int width) const override { 113 int GetHeightForWidth(int width) const override {
169 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); 114 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT);
170 } 115 }
171 116
172 // views::ButtonListener: 117 // views::ButtonListener:
173 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 118 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
174 if (emoji_button_ && sender == emoji_button_) { 119 if (emoji_button_ && sender == emoji_button_) {
175 // TODO(azurewei): Opens emoji palette. 120 // TODO(azurewei): Opens emoji palette.
176 } else if (voice_button_ && sender == voice_button_) { 121 } else if (voice_button_ && sender == voice_button_) {
177 // TODO(azurewei): Brings virtual keyboard for emoji input. 122 // TODO(azurewei): Brings virtual keyboard for emoji input.
178 } else if (handwriting_button_ && sender == handwriting_button_) { 123 } else if (handwriting_button_ && sender == handwriting_button_) {
179 // TODO(azurewei): Brings virtual keyboard for handwriting input. 124 // TODO(azurewei): Brings virtual keyboard for handwriting input.
180 } else if (settings_button_ && sender == settings_button_) { 125 } else if (settings_button_ && sender == settings_button_) {
181 ShowIMESettings(); 126 ShowIMESettings();
182 } 127 }
183 } 128 }
184 129
130 // ViewClickListener:
131 void OnViewClicked(views::View* sender) override {
132 if (one_settings_button_view_ && sender == one_settings_button_view_) {
133 ShowIMESettings();
134 }
135 }
136
185 private: 137 private:
138 // Shows the UI of one settings button.
139 void ShowOneSettingButton() {
140 auto* box_layout =
141 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
142 box_layout->SetDefaultFlex(1);
143 SetLayoutManager(box_layout);
144 one_settings_button_view_ = new HoverHighlightView(this);
145 one_settings_button_view_->AddLabel(
146 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
147 IDS_ASH_STATUS_TRAY_IME_SETTINGS),
148 gfx::ALIGN_LEFT, false /* highlight */);
149 AddChildView(one_settings_button_view_);
150 }
151
152 // Shows the UI of more than one buttons.
153 void ShowButtons(bool show_emoji_button,
154 bool show_voice_button,
155 bool show_handwriting_button,
156 bool show_settings_button) {
157 set_background(
158 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
159 auto* box_layout = new views::BoxLayout(
160 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding,
161 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems);
162 box_layout->SetDefaultFlex(1);
163 SetLayoutManager(box_layout);
164
165 if (show_emoji_button) {
166 // TODO(azurewei): Creates the proper button with icons.
167 }
168
169 if (show_voice_button) {
170 // TODO(azurewei): Creates the proper button with icons.
171 }
172
173 if (show_handwriting_button) {
174 // TODO(azurewei): Creates the proper button with icons.
175 }
176
177 if (show_settings_button) {
178 settings_button_ = CreateImeMenuButton(
179 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_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 }
184 }
185
186 TrayPopupHeaderButton* emoji_button_; 186 TrayPopupHeaderButton* emoji_button_;
187 TrayPopupHeaderButton* voice_button_; 187 TrayPopupHeaderButton* voice_button_;
188 TrayPopupHeaderButton* handwriting_button_; 188 TrayPopupHeaderButton* handwriting_button_;
189 TrayPopupHeaderButton* settings_button_; 189 TrayPopupHeaderButton* settings_button_;
190 ImeSettingButtonView* settings_button_with_text_; 190 HoverHighlightView* one_settings_button_view_;
191 191
192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
193 }; 193 };
194 194
195 } // namespace 195 } // namespace
196 196
197 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 197 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
198 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { 198 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) {
199 SetupLabelForTray(label_); 199 SetupLabelForTray(label_);
200 tray_container()->AddChildView(label_); 200 tray_container()->AddChildView(label_);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 label_->SetText(current_ime_.short_name); 350 label_->SetText(current_ime_.short_name);
351 } 351 }
352 352
353 void ImeMenuTray::HideImeMenuBubble() { 353 void ImeMenuTray::HideImeMenuBubble() {
354 bubble_.reset(); 354 bubble_.reset();
355 ime_list_view_ = nullptr; 355 ime_list_view_ = nullptr;
356 SetDrawBackgroundAsActive(false); 356 SetDrawBackgroundAsActive(false);
357 } 357 }
358 358
359 } // namespace ash 359 } // 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