Chromium Code Reviews| 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/system/tray_accessibility.h" | 5 #include "ash/system/tray_accessibility.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
| 9 #include "ash/system/tray/system_tray.h" | |
| 10 #include "ash/system/tray/system_tray_delegate.h" | |
| 9 #include "ash/system/tray/tray_constants.h" | 11 #include "ash/system/tray/tray_constants.h" |
| 12 #include "ash/system/tray/tray_details_view.h" | |
| 13 #include "ash/system/tray/tray_item_more.h" | |
| 10 #include "ash/system/tray/tray_views.h" | 14 #include "ash/system/tray/tray_views.h" |
| 11 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
| 12 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 15 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 16 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
| 18 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 19 | 23 |
| 20 namespace ash { | 24 namespace ash { |
| 21 namespace internal { | 25 namespace internal { |
| 22 | 26 |
| 23 class DefaultAccessibilityView : public ActionableView { | 27 namespace { |
| 28 const int kPaddingAroundBottomRow = 5; | |
| 29 | |
| 30 bool IsAnyAccessibilityFeatureEnabled() { | |
| 31 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); | |
| 32 return shell_delegate && | |
| 33 (shell_delegate->IsSpokenFeedbackEnabled() || | |
| 34 shell_delegate->IsHighContrastEnabled() || | |
| 35 shell_delegate->GetMagnifierType() != ash::MAGNIFIER_OFF); | |
| 36 } | |
| 37 | |
| 38 user::LoginStatus GetCurrentLoginStatus() { | |
| 39 SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate(); | |
|
stevenjb
2012/11/26 19:32:11
tray_delegate() is safe to call outside of destruc
yoshiki
2012/11/28 12:35:29
Done.
| |
| 40 return tray_delegate ? | |
| 41 tray_delegate->GetUserLoginStatus() : | |
| 42 user::LOGGED_IN_NONE; | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 namespace tray { | |
| 48 | |
| 49 class DefaultAccessibilityView : public TrayItemMore { | |
| 24 public: | 50 public: |
| 25 DefaultAccessibilityView() { | 51 explicit DefaultAccessibilityView(SystemTrayItem* owner) |
| 52 : TrayItemMore(owner, true) { | |
| 26 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 53 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 27 kTrayPopupPaddingHorizontal, | 54 kTrayPopupPaddingHorizontal, |
| 28 0, | 55 0, |
| 29 kTrayPopupPaddingBetweenItems)); | 56 kTrayPopupPaddingBetweenItems)); |
| 30 | 57 |
| 31 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 58 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 32 FixedSizedImageView* image = | 59 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). |
| 33 new FixedSizedImageView(0, kTrayPopupItemHeight); | 60 ToImageSkia()); |
| 61 string16 label = bundle.GetLocalizedString( | |
| 62 IDS_ASH_STATUS_TRAY_ACCESSIBILITY); | |
| 63 SetLabel(label); | |
| 64 SetAccessibleName(label); | |
| 65 } | |
| 66 | |
| 67 virtual ~DefaultAccessibilityView() {} | |
| 68 | |
| 69 private: | |
| 70 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); | |
| 71 }; | |
| 72 | |
| 73 class AccessibilityDetailedView : public TrayDetailsView, | |
| 74 public ViewClickListener, | |
| 75 public views::ButtonListener, | |
| 76 public ShellObserver { | |
| 77 public: | |
| 78 explicit AccessibilityDetailedView(SystemTrayItem* owner, | |
| 79 user::LoginStatus login) : | |
| 80 TrayDetailsView(owner), | |
| 81 spoken_feedback_view_(NULL), | |
| 82 high_contrast_view_(NULL), | |
| 83 screen_magnifier_view_(NULL), | |
| 84 help_view_(NULL) { | |
| 85 login_ = login; | |
|
stevenjb
2012/11/26 19:32:11
login_(login)
yoshiki
2012/11/28 12:35:29
Done.
| |
| 86 | |
| 87 Reset(); | |
| 88 | |
| 89 AppendAccessibilityList(); | |
| 90 AppendHelpEntries(); | |
| 91 CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this); | |
| 92 | |
| 93 Layout(); | |
| 94 } | |
| 95 | |
| 96 virtual ~AccessibilityDetailedView() { | |
| 97 } | |
|
stevenjb
2012/11/26 19:32:11
Make WS consistent with ~DefaultAccessibilityView(
yoshiki
2012/11/28 12:35:29
Done. (WS means curly brackets, right?)
| |
| 98 | |
| 99 private: | |
| 100 // Add the accessibility feature list. | |
| 101 void AppendAccessibilityList() { | |
| 102 CreateScrollableList(); | |
| 103 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 104 | |
| 105 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); | |
| 106 bool spoken_feedback_enabled = shell_delegate->IsSpokenFeedbackEnabled(); | |
| 107 spoken_feedback_view_ = AddScrollListItem( | |
| 108 bundle.GetLocalizedString( | |
| 109 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK), | |
| 110 spoken_feedback_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL, | |
| 111 spoken_feedback_enabled); | |
| 112 bool high_contrast_mode_enabled = shell_delegate->IsHighContrastEnabled(); | |
| 113 high_contrast_view_ = AddScrollListItem( | |
| 114 bundle.GetLocalizedString( | |
| 115 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE), | |
| 116 high_contrast_mode_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL, | |
| 117 high_contrast_mode_enabled); | |
| 118 bool screen_magnifier_enabled = | |
| 119 shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL; | |
| 120 screen_magnifier_view_ = AddScrollListItem( | |
| 121 bundle.GetLocalizedString( | |
| 122 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER), | |
| 123 screen_magnifier_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL, | |
| 124 screen_magnifier_enabled); | |
| 125 } | |
| 126 | |
| 127 // Add help entries. | |
| 128 void AppendHelpEntries() { | |
| 129 // Currently the help page requires a browser window. | |
| 130 // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286 | |
| 131 if (login_ == user::LOGGED_IN_NONE || | |
| 132 login_ == user::LOGGED_IN_LOCKED) | |
| 133 return; | |
| 134 | |
| 135 views::BoxLayout* layout = new | |
| 136 views::BoxLayout(views::BoxLayout::kHorizontal, | |
| 137 kPaddingAroundBottomRow, | |
| 138 kPaddingAroundBottomRow, | |
| 139 -1); | |
|
stevenjb
2012/11/26 19:32:11
Comment -1 or use an appropriately named const
yoshiki
2012/11/28 12:35:29
Done. And changed network_list_detailed_view_base.
| |
| 140 layout->set_spread_blank_space(true); | |
| 141 views::View* bottom_row = new View(); | |
|
stevenjb
2012/11/26 19:32:11
nit: Construct bottom_row before layout (makes the
yoshiki
2012/11/28 12:35:29
Done.
| |
| 142 bottom_row->SetLayoutManager(layout); | |
| 143 | |
| 144 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 145 | |
| 146 TrayPopupLabelButton* help = new TrayPopupLabelButton( | |
| 147 this, | |
| 148 bundle.GetLocalizedString( | |
| 149 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE)); | |
| 150 bottom_row->AddChildView(help); | |
| 151 help_view_ = help; | |
| 152 | |
| 153 // TODO(yoshiki): Add "Customize accessibility" button when the customize is | |
| 154 // available. crbug.com/158281 | |
| 155 | |
| 156 AddChildView(bottom_row); | |
| 157 } | |
| 158 | |
| 159 HoverHighlightView* AddScrollListItem(const string16& text, | |
| 160 gfx::Font::FontStyle style, | |
| 161 bool checked) { | |
| 162 HoverHighlightView* container = new HoverHighlightView(this); | |
| 163 container->set_fixed_height(kTrayPopupItemHeight); | |
| 164 container->AddCheckableLabel(text, style, checked); | |
| 165 scroll_content()->AddChildView(container); | |
| 166 return container; | |
| 167 } | |
| 168 | |
| 169 // Overridden from ViewClickListener. | |
| 170 virtual void ClickedOn(views::View* sender) OVERRIDE { | |
| 171 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); | |
| 172 if (sender == footer()->content()) { | |
| 173 Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
|
stevenjb
2012/11/26 19:32:11
Use owner->system_tray() instead of Shell::GetInst
yoshiki
2012/11/28 12:35:29
Done.
| |
| 174 } else if (sender == spoken_feedback_view_) { | |
| 175 shell_delegate->ToggleSpokenFeedback(); | |
| 176 } else if (sender == high_contrast_view_) { | |
| 177 shell_delegate->ToggleHighContrast(); | |
| 178 } else if (sender == screen_magnifier_view_) { | |
| 179 bool screen_magnifier_enabled = | |
| 180 shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL; | |
| 181 shell_delegate->SetScreenMagnifier( | |
| 182 screen_magnifier_enabled ? ash::MAGNIFIER_OFF : ash::MAGNIFIER_FULL); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 // Overridden from ButtonListener. | |
| 187 virtual void ButtonPressed(views::Button* sender, | |
| 188 const ui::Event& event) OVERRIDE { | |
| 189 SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate(); | |
| 190 if (sender == help_view_) { | |
| 191 tray_delegate->ShowAccessibilityHelp(); | |
| 192 } | |
|
stevenjb
2012/11/26 19:32:11
nit: {} unnecessary
yoshiki
2012/11/28 12:35:29
Done.
| |
| 193 } | |
| 194 | |
| 195 views::View* spoken_feedback_view_; | |
| 196 views::View* high_contrast_view_; | |
| 197 views::View* screen_magnifier_view_;; | |
| 198 views::View* help_view_; | |
| 199 user::LoginStatus login_; | |
| 200 | |
| 201 DISALLOW_COPY_AND_ASSIGN(AccessibilityDetailedView); | |
| 202 }; | |
| 203 | |
| 204 class AccessibilityPopupView : public views::View { | |
| 205 public: | |
| 206 AccessibilityPopupView() { | |
| 207 SetLayoutManager( | |
| 208 new views::BoxLayout(views::BoxLayout::kHorizontal, | |
| 209 kTrayPopupPaddingHorizontal, | |
| 210 10, | |
|
stevenjb
2012/11/26 19:32:11
Use a const for 10
yoshiki
2012/11/28 12:35:29
I removed this part by using TrayNotificationView.
| |
| 211 kTrayPopupPaddingBetweenItems)); | |
| 212 | |
| 213 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 214 views::ImageView* image = new views::ImageView; | |
| 34 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). | 215 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). |
| 35 ToImageSkia()); | 216 ToImageSkia()); |
| 36 | |
| 37 AddChildView(image); | 217 AddChildView(image); |
| 38 string16 label = bundle.GetLocalizedString( | 218 |
| 39 IDS_ASH_STATUS_TRAY_DISABLE_SPOKEN_FEEDBACK); | 219 AddChildView(new views::Label(bundle.GetLocalizedString( |
| 40 AddChildView(new views::Label(label)); | 220 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE))); |
| 41 SetAccessibleName(label); | 221 |
| 42 } | |
| 43 | |
| 44 virtual ~DefaultAccessibilityView() {} | |
| 45 | |
| 46 protected: | |
| 47 // Overridden from ActionableView. | |
| 48 virtual bool PerformAction(const ui::Event& event) OVERRIDE { | |
| 49 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) | |
| 50 Shell::GetInstance()->delegate()->ToggleSpokenFeedback(); | |
| 51 GetWidget()->Close(); | |
| 52 return true; | |
| 53 } | 222 } |
| 54 | 223 |
| 55 private: | 224 private: |
| 56 | 225 DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView); |
| 57 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); | |
| 58 }; | 226 }; |
| 59 | 227 |
| 228 } // namespace tray | |
| 229 | |
| 230 | |
| 60 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) | 231 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) |
| 61 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), | 232 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), |
| 62 default_(NULL), | 233 default_(NULL), |
| 63 detailed_(NULL) { | 234 detailed_(NULL), |
| 64 } | 235 request_popup_view_(false), |
| 65 | 236 accessibility_previously_enabled_(IsAnyAccessibilityFeatureEnabled()), |
| 66 TrayAccessibility::~TrayAccessibility() {} | 237 login_(GetCurrentLoginStatus()) { |
| 238 DCHECK(Shell::GetInstance()->delegate()); | |
| 239 DCHECK(system_tray); | |
| 240 | |
| 241 // This class and related classes use Shell::system_tray() instead of the | |
| 242 // given system_tray. They should be same. | |
| 243 DCHECK(system_tray == Shell::GetInstance()->system_tray()); | |
|
stevenjb
2012/11/26 19:32:11
We are planning to deprecate Shell::GetInstance()-
yoshiki
2012/11/28 12:35:29
Done.
| |
| 244 | |
| 245 Shell::GetInstance()->AddShellObserver(this); | |
| 246 } | |
| 247 | |
| 248 TrayAccessibility::~TrayAccessibility() { | |
| 249 Shell::GetInstance()->RemoveShellObserver(this); | |
| 250 } | |
| 67 | 251 |
| 68 bool TrayAccessibility::GetInitialVisibility() { | 252 bool TrayAccessibility::GetInitialVisibility() { |
| 69 return Shell::GetInstance()->delegate() && | 253 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 70 Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled(); | 254 // Always shows this on the login screen. |
| 255 if (login_ == user::LOGGED_IN_NONE) | |
| 256 return true; | |
| 257 | |
| 258 if (delegate->ShouldAlwaysShowAccessibilityMenu() || | |
| 259 IsAnyAccessibilityFeatureEnabled()) { | |
| 260 return true; | |
| 261 } | |
| 262 | |
| 263 return false; | |
| 71 } | 264 } |
| 72 | 265 |
| 73 views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) { | 266 views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) { |
| 74 if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) | 267 CHECK(default_ == NULL); |
| 268 | |
| 269 login_ = status; | |
| 270 | |
| 271 if (!GetInitialVisibility()) | |
| 75 return NULL; | 272 return NULL; |
| 76 | 273 |
| 77 CHECK(default_ == NULL); | 274 CHECK(default_ == NULL); |
| 78 default_ = new DefaultAccessibilityView(); | 275 default_ = new tray::DefaultAccessibilityView(this); |
| 79 | 276 |
| 80 return default_; | 277 return default_; |
| 81 } | 278 } |
| 82 | 279 |
| 83 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { | 280 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { |
| 84 CHECK(detailed_ == NULL); | 281 CHECK(detailed_ == NULL); |
| 85 detailed_ = new views::View; | 282 |
| 86 | 283 login_ = status; |
| 87 detailed_->SetLayoutManager(new | 284 |
| 88 views::BoxLayout(views::BoxLayout::kHorizontal, | 285 if (request_popup_view_) { |
| 89 kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); | 286 detailed_ = new tray::AccessibilityPopupView(); |
| 90 | 287 request_popup_view_ = false; |
| 91 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 288 } else { |
| 92 views::ImageView* image = new views::ImageView; | 289 detailed_ = new tray::AccessibilityDetailedView(this, status); |
| 93 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). | 290 } |
| 94 ToImageSkia()); | |
| 95 | |
| 96 detailed_->AddChildView(image); | |
| 97 detailed_->AddChildView(new views::Label(bundle.GetLocalizedString( | |
| 98 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE))); | |
| 99 | 291 |
| 100 return detailed_; | 292 return detailed_; |
| 101 } | 293 } |
| 102 | 294 |
| 103 void TrayAccessibility::DestroyDefaultView() { | 295 void TrayAccessibility::DestroyDefaultView() { |
| 104 default_ = NULL; | 296 default_ = NULL; |
| 105 } | 297 } |
| 106 | 298 |
| 107 void TrayAccessibility::DestroyDetailedView() { | 299 void TrayAccessibility::DestroyDetailedView() { |
| 108 detailed_ = NULL; | 300 detailed_ = NULL; |
| 109 } | 301 } |
| 110 | 302 |
| 111 void TrayAccessibility::OnAccessibilityModeChanged(bool enabled) { | 303 void TrayAccessibility::OnLoginStateChanged(user::LoginStatus status) { |
| 304 login_ = status; | |
| 305 | |
| 112 if (tray_view()) | 306 if (tray_view()) |
| 113 tray_view()->SetVisible(enabled); | 307 tray_view()->SetVisible(GetInitialVisibility()); |
| 308 } | |
| 114 | 309 |
| 115 if (enabled) { | 310 void TrayAccessibility::OnAccessibilityModeChanged() { |
| 311 if (tray_view()) | |
| 312 tray_view()->SetVisible(GetInitialVisibility()); | |
| 313 | |
| 314 bool current_accessibility_status = IsAnyAccessibilityFeatureEnabled(); | |
|
Daniel Erat
2012/11/26 18:11:39
nit: rename to accessibility_enabled?
yoshiki
2012/11/28 12:35:29
Done.
| |
| 315 if (!accessibility_previously_enabled_ && current_accessibility_status) { | |
| 316 // Show popup if the accessibily status is being changed to true from false. | |
|
Daniel Erat
2012/11/26 18:11:39
nit: accessibility
yoshiki
2012/11/28 12:35:29
Done.
| |
| 317 request_popup_view_ = true; | |
| 116 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 318 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| 117 } else if (detailed_) { | 319 } else if (detailed_) { |
| 118 detailed_->GetWidget()->Close(); | 320 detailed_->GetWidget()->Close(); |
| 119 } | 321 } |
| 322 | |
| 323 accessibility_previously_enabled_ = current_accessibility_status; | |
| 120 } | 324 } |
| 121 | 325 |
| 122 } // namespace internal | 326 } // namespace internal |
| 123 } // namespace ash | 327 } // namespace ash |
| OLD | NEW |