OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tray_accessibility.h" | 5 #include "ash/common/system/tray_accessibility.h" |
6 | 6 |
7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
8 #include "ash/common/accessibility_types.h" | 8 #include "ash/common/accessibility_types.h" |
9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
11 #include "ash/common/system/tray/hover_highlight_view.h" | 11 #include "ash/common/system/tray/hover_highlight_view.h" |
12 #include "ash/common/system/tray/system_tray.h" | 12 #include "ash/common/system/tray/system_tray.h" |
13 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
14 #include "ash/common/system/tray/system_tray_notifier.h" | 14 #include "ash/common/system/tray/system_tray_notifier.h" |
15 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
16 #include "ash/common/system/tray/tray_details_view.h" | 16 #include "ash/common/system/tray/tray_details_view.h" |
17 #include "ash/common/system/tray/tray_item_more.h" | 17 #include "ash/common/system/tray/tray_item_more.h" |
18 #include "ash/common/system/tray/tray_popup_label_button.h" | 18 #include "ash/common/system/tray/tray_popup_label_button.h" |
19 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
20 #include "ash/resources/vector_icons/vector_icons.h" | 20 #include "ash/resources/vector_icons/vector_icons.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
23 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/color_palette.h" | |
26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
27 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
29 #include "ui/gfx/vector_icon_types.h" | |
tdanderson
2016/09/19 23:32:27
I don't think you need this #include (#including p
yiyix
2016/09/21 17:10:48
you are right!
| |
30 #include "ui/gfx/vector_icons_public.h" | |
28 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
29 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
30 #include "ui/views/layout/box_layout.h" | 33 #include "ui/views/layout/box_layout.h" |
31 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
32 | 35 |
33 namespace ash { | 36 namespace ash { |
34 namespace { | 37 namespace { |
35 | 38 |
36 enum AccessibilityState { | 39 enum AccessibilityState { |
37 A11Y_NONE = 0, | 40 A11Y_NONE = 0, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 spoken_feedback_enabled_(false), | 147 spoken_feedback_enabled_(false), |
145 high_contrast_enabled_(false), | 148 high_contrast_enabled_(false), |
146 screen_magnifier_enabled_(false), | 149 screen_magnifier_enabled_(false), |
147 large_cursor_enabled_(false), | 150 large_cursor_enabled_(false), |
148 autoclick_enabled_(false), | 151 autoclick_enabled_(false), |
149 virtual_keyboard_enabled_(false), | 152 virtual_keyboard_enabled_(false), |
150 login_(login) { | 153 login_(login) { |
151 Reset(); | 154 Reset(); |
152 | 155 |
153 AppendAccessibilityList(); | 156 AppendAccessibilityList(); |
154 AppendHelpEntries(); | 157 |
158 if (!ash::MaterialDesignController::IsSystemTrayMenuMaterial()) | |
tdanderson
2016/09/19 23:32:27
nit: ash:: not needed (here and elsewhere in this
yiyix
2016/09/21 17:10:48
I know MaterialDesignController exists in UI space
tdanderson
2016/09/21 17:59:32
As discussed in person, top-chrome MDC calls are i
| |
159 AppendHelpEntries(); | |
160 | |
155 CreateTitleRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE); | 161 CreateTitleRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE); |
156 | 162 |
157 Layout(); | 163 Layout(); |
158 } | 164 } |
159 | 165 |
160 void AccessibilityDetailedView::AppendAccessibilityList() { | 166 void AccessibilityDetailedView::AppendAccessibilityList() { |
161 CreateScrollableList(); | 167 CreateScrollableList(); |
162 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 168 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
163 | 169 |
170 // Generate entries in Accessibility detailed view menu for MD and non-MD, | |
171 // respectively. | |
164 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); | 172 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); |
165 spoken_feedback_enabled_ = delegate->IsSpokenFeedbackEnabled(); | 173 spoken_feedback_enabled_ = delegate->IsSpokenFeedbackEnabled(); |
166 spoken_feedback_view_ = | 174 spoken_feedback_view_ = |
167 AddScrollListItem(bundle.GetLocalizedString( | 175 AddScrollListItem(bundle.GetLocalizedString( |
168 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK), | 176 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK), |
169 spoken_feedback_enabled_, spoken_feedback_enabled_); | 177 spoken_feedback_enabled_, spoken_feedback_enabled_, |
178 kSystemMenuAccessibilityChromevoxIcon); | |
170 | 179 |
171 // Large Cursor item is shown only in Login screen. | 180 // Large Cursor item is shown only in Login screen. |
172 if (login_ == LoginStatus::NOT_LOGGED_IN) { | 181 if (login_ == LoginStatus::NOT_LOGGED_IN) { |
173 large_cursor_enabled_ = delegate->IsLargeCursorEnabled(); | 182 large_cursor_enabled_ = delegate->IsLargeCursorEnabled(); |
174 large_cursor_view_ = | 183 large_cursor_view_ = |
175 AddScrollListItem(bundle.GetLocalizedString( | 184 AddScrollListItem(bundle.GetLocalizedString( |
176 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LARGE_CURSOR), | 185 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LARGE_CURSOR), |
177 large_cursor_enabled_, large_cursor_enabled_); | 186 large_cursor_enabled_, large_cursor_enabled_, |
187 kSystemMenuAccessibilityLargeCursorIcon); | |
178 } | 188 } |
179 | 189 |
180 high_contrast_enabled_ = delegate->IsHighContrastEnabled(); | 190 high_contrast_enabled_ = delegate->IsHighContrastEnabled(); |
181 high_contrast_view_ = AddScrollListItem( | 191 high_contrast_view_ = AddScrollListItem( |
182 bundle.GetLocalizedString( | 192 bundle.GetLocalizedString( |
183 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE), | 193 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE), |
184 high_contrast_enabled_, high_contrast_enabled_); | 194 high_contrast_enabled_, high_contrast_enabled_, |
195 kSystemMenuAccessibilityContrastIcon); | |
185 screen_magnifier_enabled_ = delegate->IsMagnifierEnabled(); | 196 screen_magnifier_enabled_ = delegate->IsMagnifierEnabled(); |
186 screen_magnifier_view_ = | 197 screen_magnifier_view_ = |
187 AddScrollListItem(bundle.GetLocalizedString( | 198 AddScrollListItem(bundle.GetLocalizedString( |
188 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER), | 199 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER), |
189 screen_magnifier_enabled_, screen_magnifier_enabled_); | 200 screen_magnifier_enabled_, screen_magnifier_enabled_, |
201 kSystemMenuAccessibilityScreenMagnifierIcon); | |
190 | 202 |
191 // Don't show autoclick option at login screen. | 203 // Don't show autoclick option at login screen. |
192 if (login_ != LoginStatus::NOT_LOGGED_IN) { | 204 if (login_ != LoginStatus::NOT_LOGGED_IN) { |
193 autoclick_enabled_ = delegate->IsAutoclickEnabled(); | 205 autoclick_enabled_ = delegate->IsAutoclickEnabled(); |
194 autoclick_view_ = AddScrollListItem( | 206 autoclick_view_ = AddScrollListItem( |
195 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_AUTOCLICK), | 207 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_AUTOCLICK), |
196 autoclick_enabled_, autoclick_enabled_); | 208 autoclick_enabled_, autoclick_enabled_, |
209 kSystemMenuAccessibilityAutoClickIcon); | |
197 } | 210 } |
198 | 211 |
199 virtual_keyboard_enabled_ = delegate->IsVirtualKeyboardEnabled(); | 212 virtual_keyboard_enabled_ = delegate->IsVirtualKeyboardEnabled(); |
200 virtual_keyboard_view_ = | 213 virtual_keyboard_view_ = |
201 AddScrollListItem(bundle.GetLocalizedString( | 214 AddScrollListItem(bundle.GetLocalizedString( |
202 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD), | 215 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD), |
203 virtual_keyboard_enabled_, virtual_keyboard_enabled_); | 216 virtual_keyboard_enabled_, virtual_keyboard_enabled_, |
217 kSystemMenuKeyboardIcon); | |
204 } | 218 } |
205 | 219 |
206 void AccessibilityDetailedView::AppendHelpEntries() { | 220 void AccessibilityDetailedView::AppendHelpEntries() { |
207 // Currently the help page requires a browser window. | 221 // Currently the help page requires a browser window. |
208 // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286 | 222 // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286 |
209 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || | 223 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || |
210 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) | 224 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) |
211 return; | 225 return; |
212 | 226 |
213 views::View* bottom_row = new View(); | 227 views::View* bottom_row = new View(); |
(...skipping 16 matching lines...) Expand all Loading... | |
230 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SETTINGS)); | 244 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SETTINGS)); |
231 bottom_row->AddChildView(settings); | 245 bottom_row->AddChildView(settings); |
232 settings_view_ = settings; | 246 settings_view_ = settings; |
233 | 247 |
234 AddChildView(bottom_row); | 248 AddChildView(bottom_row); |
235 } | 249 } |
236 | 250 |
237 HoverHighlightView* AccessibilityDetailedView::AddScrollListItem( | 251 HoverHighlightView* AccessibilityDetailedView::AddScrollListItem( |
238 const base::string16& text, | 252 const base::string16& text, |
239 bool highlight, | 253 bool highlight, |
240 bool checked) { | 254 bool checked, |
255 const gfx::VectorIcon& icon) { | |
241 HoverHighlightView* container = new HoverHighlightView(this); | 256 HoverHighlightView* container = new HoverHighlightView(this); |
242 container->AddCheckableLabel(text, highlight, checked); | 257 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { |
258 gfx::ImageSkia image = CreateVectorIcon(icon, kMenuIconColor); | |
259 const int padding = (kMenuButtonSize - image.width()) / 2; | |
260 container->AddIconAndLabelCustomSize(image, text, highlight, | |
261 image.width() + kMenuIconMargin * 2, | |
262 padding, padding); | |
263 gfx::ImageSkia check_mark = | |
264 CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700); | |
265 container->AddRightIcon(check_mark, check_mark.width()); | |
266 container->SetRightIconVisible(checked); | |
267 } else { | |
268 container->AddCheckableLabel(text, highlight, checked); | |
269 } | |
243 scroll_content()->AddChildView(container); | 270 scroll_content()->AddChildView(container); |
244 return container; | 271 return container; |
245 } | 272 } |
246 | 273 |
247 void AccessibilityDetailedView::HandleViewClicked(views::View* view) { | 274 void AccessibilityDetailedView::HandleViewClicked(views::View* view) { |
248 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); | 275 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); |
276 UserMetricsAction user_action; | |
tdanderson
2016/09/19 23:32:27
Nice.
yiyix
2016/09/21 17:10:48
Thanks :)
| |
249 if (view == spoken_feedback_view_) { | 277 if (view == spoken_feedback_view_) { |
250 WmShell::Get()->RecordUserMetricsAction( | 278 user_action = delegate->IsSpokenFeedbackEnabled() |
251 delegate->IsSpokenFeedbackEnabled() | 279 ? ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK |
252 ? ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK | 280 : ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK; |
253 : ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK); | |
254 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 281 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
255 } else if (view == high_contrast_view_) { | 282 } else if (view == high_contrast_view_) { |
256 WmShell::Get()->RecordUserMetricsAction( | 283 user_action = delegate->IsHighContrastEnabled() |
257 delegate->IsHighContrastEnabled() | 284 ? ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST |
258 ? ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST | 285 : ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST; |
259 : ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST); | |
260 delegate->ToggleHighContrast(); | 286 delegate->ToggleHighContrast(); |
261 } else if (view == screen_magnifier_view_) { | 287 } else if (view == screen_magnifier_view_) { |
262 WmShell::Get()->RecordUserMetricsAction( | 288 user_action = delegate->IsMagnifierEnabled() |
263 delegate->IsMagnifierEnabled() ? ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER | 289 ? ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER |
264 : ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER); | 290 : ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER; |
265 delegate->SetMagnifierEnabled(!delegate->IsMagnifierEnabled()); | 291 delegate->SetMagnifierEnabled(!delegate->IsMagnifierEnabled()); |
266 } else if (large_cursor_view_ && view == large_cursor_view_) { | 292 } else if (large_cursor_view_ && view == large_cursor_view_) { |
267 WmShell::Get()->RecordUserMetricsAction( | 293 user_action = delegate->IsLargeCursorEnabled() |
268 delegate->IsLargeCursorEnabled() | 294 ? ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR |
269 ? ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR | 295 : ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR; |
270 : ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR); | |
271 delegate->SetLargeCursorEnabled(!delegate->IsLargeCursorEnabled()); | 296 delegate->SetLargeCursorEnabled(!delegate->IsLargeCursorEnabled()); |
272 } else if (autoclick_view_ && view == autoclick_view_) { | 297 } else if (autoclick_view_ && view == autoclick_view_) { |
273 WmShell::Get()->RecordUserMetricsAction( | 298 user_action = delegate->IsAutoclickEnabled() |
274 delegate->IsAutoclickEnabled() | 299 ? ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK |
275 ? ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK | 300 : ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK; |
276 : ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK); | |
277 delegate->SetAutoclickEnabled(!delegate->IsAutoclickEnabled()); | 301 delegate->SetAutoclickEnabled(!delegate->IsAutoclickEnabled()); |
278 } else if (virtual_keyboard_view_ && view == virtual_keyboard_view_) { | 302 } else if (virtual_keyboard_view_ && view == virtual_keyboard_view_) { |
279 WmShell::Get()->RecordUserMetricsAction( | 303 user_action = delegate->IsVirtualKeyboardEnabled() |
280 delegate->IsVirtualKeyboardEnabled() | 304 ? ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD |
281 ? ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD | 305 : ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD; |
282 : ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD); | |
283 delegate->SetVirtualKeyboardEnabled(!delegate->IsVirtualKeyboardEnabled()); | 306 delegate->SetVirtualKeyboardEnabled(!delegate->IsVirtualKeyboardEnabled()); |
307 } else { | |
308 return; | |
tdanderson
2016/09/19 23:32:27
An early return at the top of the function would b
| |
284 } | 309 } |
310 WmShell::Get()->RecordUserMetricsAction(user_action); | |
285 } | 311 } |
286 | 312 |
287 void AccessibilityDetailedView::HandleButtonPressed(views::Button* sender, | 313 void AccessibilityDetailedView::HandleButtonPressed(views::Button* sender, |
288 const ui::Event& event) { | 314 const ui::Event& event) { |
289 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate(); | 315 // Since this row is not initialized in MD, this function should be called for |
tdanderson
2016/09/19 23:32:27
I suggest removing this comment, since in the very
yiyix
2016/09/21 17:10:48
Done.
| |
290 if (sender == help_view_) | 316 // non-MD only. |
291 tray_delegate->ShowAccessibilityHelp(); | 317 if (!MaterialDesignController::UseMaterialDesignSystemIcons()) { |
tdanderson
2016/09/19 23:32:27
To avoid indenting the whole function, it would be
yiyix
2016/09/21 17:10:48
Done.
| |
292 else if (sender == settings_view_) | 318 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate(); |
293 tray_delegate->ShowAccessibilitySettings(); | 319 if (sender == help_view_) |
320 tray_delegate->ShowAccessibilityHelp(); | |
321 else if (sender == settings_view_) | |
322 tray_delegate->ShowAccessibilitySettings(); | |
323 } | |
294 } | 324 } |
295 | 325 |
296 } // namespace tray | 326 } // namespace tray |
297 | 327 |
298 //////////////////////////////////////////////////////////////////////////////// | 328 //////////////////////////////////////////////////////////////////////////////// |
299 // ash::TrayAccessibility | 329 // ash::TrayAccessibility |
300 | 330 |
301 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) | 331 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) |
302 : TrayImageItem(system_tray, | 332 : TrayImageItem(system_tray, |
303 IDR_AURA_UBER_TRAY_ACCESSIBILITY, | 333 IDR_AURA_UBER_TRAY_ACCESSIBILITY, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 if (detailed_popup_) | 445 if (detailed_popup_) |
416 detailed_popup_->GetWidget()->Close(); | 446 detailed_popup_->GetWidget()->Close(); |
417 if (detailed_menu_) | 447 if (detailed_menu_) |
418 detailed_menu_->GetWidget()->Close(); | 448 detailed_menu_->GetWidget()->Close(); |
419 } | 449 } |
420 | 450 |
421 previous_accessibility_state_ = accessibility_state; | 451 previous_accessibility_state_ = accessibility_state; |
422 } | 452 } |
423 | 453 |
424 } // namespace ash | 454 } // namespace ash |
OLD | NEW |