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

Side by Side Diff: ash/system/tray/system_tray.cc

Issue 10836227: Fix status area accessability issues. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ash/system/tray/system_tray.h ('k') | ash/system/tray/system_tray_bubble.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell/panel_window.h" 8 #include "ash/shell/panel_window.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/audio/tray_volume.h" 10 #include "ash/system/audio/tray_volume.h"
(...skipping 12 matching lines...) Expand all
23 #include "ash/system/status_area_widget.h" 23 #include "ash/system/status_area_widget.h"
24 #include "ash/system/tray/system_tray_bubble.h" 24 #include "ash/system/tray/system_tray_bubble.h"
25 #include "ash/system/tray/system_tray_delegate.h" 25 #include "ash/system/tray/system_tray_delegate.h"
26 #include "ash/system/tray/system_tray_item.h" 26 #include "ash/system/tray/system_tray_item.h"
27 #include "ash/system/tray/tray_constants.h" 27 #include "ash/system/tray/tray_constants.h"
28 #include "ash/system/tray_accessibility.h" 28 #include "ash/system/tray_accessibility.h"
29 #include "ash/system/tray_caps_lock.h" 29 #include "ash/system/tray_caps_lock.h"
30 #include "ash/system/tray_update.h" 30 #include "ash/system/tray_update.h"
31 #include "ash/system/user/login_status.h" 31 #include "ash/system/user/login_status.h"
32 #include "ash/system/user/tray_user.h" 32 #include "ash/system/user/tray_user.h"
33 #include "ash/wm/shelf_layout_manager.h"
34 #include "base/logging.h" 33 #include "base/logging.h"
35 #include "base/timer.h" 34 #include "base/timer.h"
36 #include "base/utf_string_conversions.h" 35 #include "base/utf_string_conversions.h"
37 #include "grit/ash_strings.h" 36 #include "grit/ash_strings.h"
38 #include "ui/aura/root_window.h" 37 #include "ui/aura/root_window.h"
39 #include "ui/base/accessibility/accessible_view_state.h"
40 #include "ui/base/events.h" 38 #include "ui/base/events.h"
41 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
42 #include "ui/compositor/layer.h" 40 #include "ui/compositor/layer.h"
43 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
44 #include "ui/gfx/screen.h" 42 #include "ui/gfx/screen.h"
45 #include "ui/gfx/skia_util.h" 43 #include "ui/gfx/skia_util.h"
46 #include "ui/views/border.h" 44 #include "ui/views/border.h"
47 #include "ui/views/controls/label.h" 45 #include "ui/views/controls/label.h"
48 #include "ui/views/layout/box_layout.h" 46 #include "ui/views/layout/box_layout.h"
49 #include "ui/views/layout/fill_layout.h" 47 #include "ui/views/layout/fill_layout.h"
50 #include "ui/views/view.h" 48 #include "ui/views/view.h"
51 49
52 namespace ash { 50 namespace ash {
53 51
54 namespace internal {
55
56 // Observe the tray layer animation and update the anchor when it changes.
57 // TODO(stevenjb): Observe or mirror the actual animation, not just the start
58 // and end points.
59 class SystemTrayLayerAnimationObserver : public ui::LayerAnimationObserver {
60 public:
61 explicit SystemTrayLayerAnimationObserver(SystemTray* host) : host_(host) {}
62
63 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) {
64 host_->UpdateNotificationAnchor();
65 }
66
67 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) {
68 host_->UpdateNotificationAnchor();
69 }
70
71 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) {
72 host_->UpdateNotificationAnchor();
73 }
74
75 private:
76 SystemTray* host_;
77
78 DISALLOW_COPY_AND_ASSIGN(SystemTrayLayerAnimationObserver);
79 };
80
81 } // namespace internal
82
83 // SystemTray 52 // SystemTray
84 53
85 using internal::SystemTrayBubble; 54 using internal::SystemTrayBubble;
86 using internal::SystemTrayLayerAnimationObserver;
87 using internal::TrayBubbleView; 55 using internal::TrayBubbleView;
88 56
89 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) 57 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget)
90 : internal::TrayBackgroundView(status_area_widget), 58 : internal::TrayBackgroundView(status_area_widget),
91 items_(), 59 items_(),
92 accessibility_observer_(NULL), 60 accessibility_observer_(NULL),
93 audio_observer_(NULL), 61 audio_observer_(NULL),
94 bluetooth_observer_(NULL), 62 bluetooth_observer_(NULL),
95 brightness_observer_(NULL), 63 brightness_observer_(NULL),
96 caps_lock_observer_(NULL), 64 caps_lock_observer_(NULL),
97 clock_observer_(NULL), 65 clock_observer_(NULL),
98 drive_observer_(NULL), 66 drive_observer_(NULL),
99 ime_observer_(NULL), 67 ime_observer_(NULL),
100 locale_observer_(NULL), 68 locale_observer_(NULL),
101 network_observer_(NULL), 69 network_observer_(NULL),
102 update_observer_(NULL), 70 update_observer_(NULL),
103 user_observer_(NULL), 71 user_observer_(NULL),
104 should_show_launcher_(false),
105 default_bubble_height_(0), 72 default_bubble_height_(0),
106 hide_notifications_(false) { 73 hide_notifications_(false) {
107 } 74 }
108 75
109 SystemTray::~SystemTray() { 76 SystemTray::~SystemTray() {
110 bubble_.reset(); 77 bubble_.reset();
111 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); 78 for (std::vector<SystemTrayItem*>::iterator it = items_.begin();
112 it != items_.end(); 79 it != items_.end();
113 ++it) { 80 ++it) {
114 (*it)->DestroyTrayView(); 81 (*it)->DestroyTrayView();
115 } 82 }
116 GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver(
117 layer_animation_observer_.get());
118 }
119
120 void SystemTray::Initialize() {
121 layer_animation_observer_.reset(new SystemTrayLayerAnimationObserver(this));
122 GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver(
123 layer_animation_observer_.get());
124 } 83 }
125 84
126 void SystemTray::CreateItems() { 85 void SystemTray::CreateItems() {
127 internal::TrayVolume* tray_volume = new internal::TrayVolume(); 86 internal::TrayVolume* tray_volume = new internal::TrayVolume();
128 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); 87 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth();
129 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); 88 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness();
130 internal::TrayDate* tray_date = new internal::TrayDate(); 89 internal::TrayDate* tray_date = new internal::TrayDate();
131 internal::TrayPower* tray_power = new internal::TrayPower(); 90 internal::TrayPower* tray_power = new internal::TrayPower();
132 internal::TrayNetwork* tray_network = new internal::TrayNetwork; 91 internal::TrayNetwork* tray_network = new internal::TrayNetwork;
133 internal::TraySms* tray_sms = new internal::TraySms(); 92 internal::TraySms* tray_sms = new internal::TraySms();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 AddTrayItem(tray_date); 133 AddTrayItem(tray_date);
175 SetVisible(ash::Shell::GetInstance()->tray_delegate()-> 134 SetVisible(ash::Shell::GetInstance()->tray_delegate()->
176 GetTrayVisibilityOnStartup()); 135 GetTrayVisibilityOnStartup());
177 } 136 }
178 137
179 void SystemTray::AddTrayItem(SystemTrayItem* item) { 138 void SystemTray::AddTrayItem(SystemTrayItem* item) {
180 items_.push_back(item); 139 items_.push_back(item);
181 140
182 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); 141 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate();
183 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); 142 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus());
184 item->UpdateAfterShelfAlignmentChange( 143 item->UpdateAfterShelfAlignmentChange(shelf_alignment());
185 ash::Shell::GetInstance()->system_tray()->shelf_alignment());
186 144
187 if (tray_item) { 145 if (tray_item) {
188 tray_container()->AddChildViewAt(tray_item, 0); 146 tray_container()->AddChildViewAt(tray_item, 0);
189 PreferredSizeChanged(); 147 PreferredSizeChanged();
190 tray_item_map_[item] = tray_item; 148 tray_item_map_[item] = tray_item;
191 } 149 }
192 } 150 }
193 151
194 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { 152 void SystemTray::RemoveTrayItem(SystemTrayItem* item) {
195 NOTIMPLEMENTED(); 153 NOTIMPLEMENTED();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 (*it)->UpdateAfterShelfAlignmentChange(alignment); 220 (*it)->UpdateAfterShelfAlignmentChange(alignment);
263 } 221 }
264 } 222 }
265 223
266 void SystemTray::SetHideNotifications(bool hide_notifications) { 224 void SystemTray::SetHideNotifications(bool hide_notifications) {
267 if (notification_bubble_.get()) 225 if (notification_bubble_.get())
268 notification_bubble_->SetVisible(!hide_notifications); 226 notification_bubble_->SetVisible(!hide_notifications);
269 hide_notifications_ = hide_notifications; 227 hide_notifications_ = hide_notifications;
270 } 228 }
271 229
230 bool SystemTray::IsSystemBubbleVisible() const {
231 return (bubble_.get() && bubble_->IsVisible());
232 }
233
272 bool SystemTray::IsAnyBubbleVisible() const { 234 bool SystemTray::IsAnyBubbleVisible() const {
273 if (bubble_.get() && bubble_->IsVisible()) 235 if (bubble_.get() && bubble_->IsVisible())
274 return true; 236 return true;
275 if (notification_bubble_.get() && notification_bubble_->IsVisible()) 237 if (notification_bubble_.get() && notification_bubble_->IsVisible())
276 return true; 238 return true;
277 return false; 239 return false;
278 } 240 }
279 241
242 bool SystemTray::IsMouseInNotificationBubble() const {
243 if (!notification_bubble_.get())
244 return false;
245 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains(
246 gfx::Screen::GetCursorScreenPoint());
247 }
248
280 bool SystemTray::CloseBubbleForTest() const { 249 bool SystemTray::CloseBubbleForTest() const {
281 if (!bubble_.get()) 250 if (!bubble_.get())
282 return false; 251 return false;
283 bubble_->Close(); 252 bubble_->Close();
284 return true; 253 return true;
285 } 254 }
286 255
287 // Private methods. 256 // Private methods.
288 257
289 void SystemTray::DestroyBubble() { 258 void SystemTray::DestroyBubble() {
290 bubble_.reset(); 259 bubble_.reset();
291 detailed_item_ = NULL; 260 detailed_item_ = NULL;
292 } 261 }
293 262
294 void SystemTray::RemoveBubble(SystemTrayBubble* bubble) { 263 void SystemTray::RemoveBubble(SystemTrayBubble* bubble) {
295 if (bubble == bubble_.get()) { 264 if (bubble == bubble_.get()) {
296 DestroyBubble(); 265 DestroyBubble();
297 UpdateNotificationBubble(); // State changed, re-create notifications. 266 UpdateNotificationBubble(); // State changed, re-create notifications.
298 if (should_show_launcher_) { 267 UpdateShouldShowLauncher();
299 // No need to show the launcher if the mouse isn't over the status area
300 // anymore.
301 should_show_launcher_ = GetWidget()->GetWindowBoundsInScreen().Contains(
302 gfx::Screen::GetCursorScreenPoint());
303 if (!should_show_launcher_)
304 Shell::GetInstance()->shelf()->UpdateAutoHideState();
305 }
306 } else if (bubble == notification_bubble_) { 268 } else if (bubble == notification_bubble_) {
307 notification_bubble_.reset(); 269 notification_bubble_.reset();
308 } else { 270 } else {
309 NOTREACHED(); 271 NOTREACHED();
310 } 272 }
311 } 273 }
312 274
313 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { 275 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const {
314 // Don't attempt to align the arrow if the shelf is on the left or right. 276 // Don't attempt to align the arrow if the shelf is on the left or right.
315 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) 277 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 334 }
373 // Save height of default view for creating detailed views directly. 335 // Save height of default view for creating detailed views directly.
374 if (!detailed) 336 if (!detailed)
375 default_bubble_height_ = bubble_->bubble_view()->height(); 337 default_bubble_height_ = bubble_->bubble_view()->height();
376 338
377 if (detailed && items.size() > 0) 339 if (detailed && items.size() > 0)
378 detailed_item_ = items[0]; 340 detailed_item_ = items[0];
379 else 341 else
380 detailed_item_ = NULL; 342 detailed_item_ = NULL;
381 343
382 // If we have focus the shelf should be visible and we need to continue
383 // showing the shelf when the popup is shown.
384 if (GetWidget()->IsActive())
385 should_show_launcher_ = true;
386
387 UpdateNotificationBubble(); // State changed, re-create notifications. 344 UpdateNotificationBubble(); // State changed, re-create notifications.
388 status_area_widget()->HideNonSystemNotifications(); 345 status_area_widget()->HideNonSystemNotifications();
346 UpdateShouldShowLauncher();
389 } 347 }
390 348
391 void SystemTray::UpdateNotificationBubble() { 349 void SystemTray::UpdateNotificationBubble() {
392 // Only show the notification buble if we have notifications and we are not 350 // Only show the notification buble if we have notifications and we are not
393 // showing the default bubble. 351 // showing the default bubble.
394 if (notification_items_.empty() || 352 if (notification_items_.empty() ||
395 (bubble_.get() && 353 (bubble_.get() &&
396 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 354 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
397 notification_bubble_.reset(); 355 notification_bubble_.reset();
398 return; 356 return;
(...skipping 29 matching lines...) Expand all
428 init_params.arrow_color = kBackgroundColor; 386 init_params.arrow_color = kBackgroundColor;
429 user::LoginStatus login_status = 387 user::LoginStatus login_status =
430 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); 388 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus();
431 notification_bubble_->InitView(anchor, init_params, login_status); 389 notification_bubble_->InitView(anchor, init_params, login_status);
432 if (hide_notifications_) 390 if (hide_notifications_)
433 notification_bubble_->SetVisible(false); 391 notification_bubble_->SetVisible(false);
434 else 392 else
435 status_area_widget()->HideNonSystemNotifications(); 393 status_area_widget()->HideNonSystemNotifications();
436 } 394 }
437 395
438 void SystemTray::UpdateNotificationAnchor() { 396 void SystemTray::Initialize() {
439 if (!notification_bubble_.get()) 397 internal::TrayBackgroundView::Initialize();
440 return; 398 CreateItems();
441 notification_bubble_->bubble_view()->UpdateBubble();
442 // Ensure that the notification buble is above the launcher/status area.
443 notification_bubble_->bubble_view()->GetWidget()->StackAtTop();
444 } 399 }
445 400
446 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { 401 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) {
447 if (alignment == shelf_alignment()) 402 if (alignment == shelf_alignment())
448 return; 403 return;
449 internal::TrayBackgroundView::SetShelfAlignment(alignment); 404 internal::TrayBackgroundView::SetShelfAlignment(alignment);
450 UpdateAfterShelfAlignmentChange(alignment); 405 UpdateAfterShelfAlignmentChange(alignment);
451 // Destroy any existing bubble so that it is rebuilt correctly. 406 // Destroy any existing bubble so that it is rebuilt correctly.
452 bubble_.reset(); 407 bubble_.reset();
453 // Rebuild any notification bubble. 408 // Rebuild any notification bubble.
454 if (notification_bubble_.get()) { 409 if (notification_bubble_.get()) {
455 notification_bubble_.reset(); 410 notification_bubble_.reset();
456 UpdateNotificationBubble(); 411 UpdateNotificationBubble();
457 } 412 }
458 } 413 }
459 414
415 void SystemTray::AnchorUpdated() {
416 if (notification_bubble_.get()) {
417 notification_bubble_->bubble_view()->UpdateBubble();
418 // Ensure that the notification buble is above the launcher/status area.
419 notification_bubble_->bubble_view()->GetWidget()->StackAtTop();
420 }
421 if (bubble_.get())
422 bubble_->bubble_view()->UpdateBubble();
423 }
424
425 string16 SystemTray::GetAccessibleName() {
426 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME);
427 }
428
460 bool SystemTray::PerformAction(const ui::Event& event) { 429 bool SystemTray::PerformAction(const ui::Event& event) {
461 // If we're already showing the default view, hide it; otherwise, show it 430 // If we're already showing the default view, hide it; otherwise, show it
462 // (and hide any popup that's currently shown). 431 // (and hide any popup that's currently shown).
463 if (bubble_.get() && 432 if (bubble_.get() &&
464 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { 433 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) {
465 bubble_->Close(); 434 bubble_->Close();
466 } else { 435 } else {
467 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; 436 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset;
468 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { 437 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) {
469 const ui::LocatedEvent& located_event = 438 const ui::LocatedEvent& located_event =
470 static_cast<const ui::LocatedEvent&>(event); 439 static_cast<const ui::LocatedEvent&>(event);
471 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { 440 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
472 gfx::Point point(located_event.x(), 0); 441 gfx::Point point(located_event.x(), 0);
473 ConvertPointToWidget(this, &point); 442 ConvertPointToWidget(this, &point);
474 arrow_offset = point.x(); 443 arrow_offset = point.x();
475 } 444 }
476 } 445 }
477 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); 446 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset);
478 } 447 }
479 return true; 448 return true;
480 } 449 }
481 450
482 void SystemTray::OnMouseEntered(const ui::MouseEvent& event) {
483 TrayBackgroundView::OnMouseEntered(event);
484 should_show_launcher_ = true;
485 }
486
487 void SystemTray::OnMouseExited(const ui::MouseEvent& event) {
488 TrayBackgroundView::OnMouseExited(event);
489 // When the popup closes we'll update |should_show_launcher_|.
490 if (!bubble_.get())
491 should_show_launcher_ = false;
492 }
493
494 void SystemTray::AboutToRequestFocusFromTabTraversal(bool reverse) {
495 views::View* v = GetNextFocusableView();
496 if (v)
497 v->AboutToRequestFocusFromTabTraversal(reverse);
498 }
499
500 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) {
501 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
502 state->name = l10n_util::GetStringUTF16(
503 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME);
504 }
505
506 void SystemTray::OnPaintFocusBorder(gfx::Canvas* canvas) {
507 // The tray itself expands to the right and bottom edge of the screen to make
508 // sure clicking on the edges brings up the popup. However, the focus border
509 // should be only around the container.
510 if (GetWidget() && GetWidget()->IsActive())
511 DrawBorder(canvas, GetContentsBounds());
512 }
513
514 } // namespace ash 451 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray.h ('k') | ash/system/tray/system_tray_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698