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

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

Issue 2948223002: Revert of Do not activate TrayBubbleView by default (Closed)
Patch Set: Created 3 years, 6 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/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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/accelerators/accelerator_controller.h"
12 #include "ash/key_event_watcher.h" 11 #include "ash/key_event_watcher.h"
13 #include "ash/login_status.h" 12 #include "ash/login_status.h"
14 #include "ash/public/cpp/config.h" 13 #include "ash/public/cpp/config.h"
15 #include "ash/public/cpp/shell_window_ids.h" 14 #include "ash/public/cpp/shell_window_ids.h"
16 #include "ash/root_window_controller.h" 15 #include "ash/root_window_controller.h"
17 #include "ash/session/session_controller.h" 16 #include "ash/session/session_controller.h"
18 #include "ash/shelf/shelf.h" 17 #include "ash/shelf/shelf.h"
19 #include "ash/shell.h" 18 #include "ash/shell.h"
20 #include "ash/shell_port.h" 19 #include "ash/shell_port.h"
21 #include "ash/strings/grit/ash_strings.h" 20 #include "ash/strings/grit/ash_strings.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 explicit SystemBubbleWrapper(SystemTrayBubble* bubble) 111 explicit SystemBubbleWrapper(SystemTrayBubble* bubble)
113 : bubble_(bubble), is_persistent_(false) {} 112 : bubble_(bubble), is_persistent_(false) {}
114 113
115 // Initializes the bubble view and creates |bubble_wrapper_|. 114 // Initializes the bubble view and creates |bubble_wrapper_|.
116 void InitView(TrayBackgroundView* tray, 115 void InitView(TrayBackgroundView* tray,
117 views::View* anchor, 116 views::View* anchor,
118 const gfx::Insets& anchor_insets, 117 const gfx::Insets& anchor_insets,
119 TrayBubbleView::InitParams* init_params, 118 TrayBubbleView::InitParams* init_params,
120 bool is_persistent) { 119 bool is_persistent) {
121 DCHECK(anchor); 120 DCHECK(anchor);
122
123 is_persistent_ = is_persistent;
124
125 const LoginStatus login_status = 121 const LoginStatus login_status =
126 Shell::Get()->session_controller()->login_status(); 122 Shell::Get()->session_controller()->login_status();
127 bubble_->InitView(anchor, login_status, init_params); 123 bubble_->InitView(anchor, login_status, init_params);
128 bubble_->bubble_view()->set_anchor_view_insets(anchor_insets); 124 bubble_->bubble_view()->set_anchor_view_insets(anchor_insets);
129 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_->bubble_view())); 125 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_->bubble_view()));
126 is_persistent_ = is_persistent;
127
128 // If ChromeVox is enabled, focus the default item if no item is focused and
129 // there isn't a delayed close.
130 if (Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled() &&
131 !is_persistent) {
132 bubble_->FocusDefaultIfNeeded();
133 }
130 } 134 }
131 135
132 // Convenience accessors: 136 // Convenience accessors:
133 SystemTrayBubble* bubble() const { return bubble_.get(); } 137 SystemTrayBubble* bubble() const { return bubble_.get(); }
134 SystemTrayBubble::BubbleType bubble_type() const { 138 SystemTrayBubble::BubbleType bubble_type() const {
135 return bubble_->bubble_type(); 139 return bubble_->bubble_type();
136 } 140 }
137 TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } 141 TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); }
138 bool is_persistent() const { return is_persistent_; } 142 bool is_persistent() const { return is_persistent_; }
139 143
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 203
200 // Since user avatar is on the right hand side of System tray of a 204 // Since user avatar is on the right hand side of System tray of a
201 // horizontal shelf and that is sufficient to indicate separation, no 205 // horizontal shelf and that is sufficient to indicate separation, no
202 // separator is required. 206 // separator is required.
203 set_separator_visibility(false); 207 set_separator_visibility(false);
204 } 208 }
205 209
206 SystemTray::~SystemTray() { 210 SystemTray::~SystemTray() {
207 // Destroy any child views that might have back pointers before ~View(). 211 // Destroy any child views that might have back pointers before ~View().
208 activation_observer_.reset(); 212 activation_observer_.reset();
213 key_event_watcher_.reset();
209 system_bubble_.reset(); 214 system_bubble_.reset();
210 for (const auto& item : items_) 215 for (const auto& item : items_)
211 item->OnTrayViewDestroyed(); 216 item->OnTrayViewDestroyed();
212 } 217 }
213 218
214 void SystemTray::InitializeTrayItems( 219 void SystemTray::InitializeTrayItems(
215 SystemTrayDelegate* delegate, 220 SystemTrayDelegate* delegate,
216 WebNotificationTray* web_notification_tray) { 221 WebNotificationTray* web_notification_tray) {
217 DCHECK(web_notification_tray); 222 DCHECK(web_notification_tray);
218 web_notification_tray_ = web_notification_tray; 223 web_notification_tray_ = web_notification_tray;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if (Shell::Get()->session_controller()->IsKioskSession()) 430 if (Shell::Get()->session_controller()->IsKioskSession())
426 return; 431 return;
427 432
428 // Destroy any existing bubble and create a new one. 433 // Destroy any existing bubble and create a new one.
429 SystemTrayBubble::BubbleType bubble_type = 434 SystemTrayBubble::BubbleType bubble_type =
430 detailed ? SystemTrayBubble::BUBBLE_TYPE_DETAILED 435 detailed ? SystemTrayBubble::BUBBLE_TYPE_DETAILED
431 : SystemTrayBubble::BUBBLE_TYPE_DEFAULT; 436 : SystemTrayBubble::BUBBLE_TYPE_DEFAULT;
432 437
433 if (system_bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { 438 if (system_bubble_.get() && creation_type == BUBBLE_USE_EXISTING) {
434 system_bubble_->bubble()->UpdateView(items, bubble_type); 439 system_bubble_->bubble()->UpdateView(items, bubble_type);
440 // If ChromeVox is enabled, focus the default item if no item is focused.
441 if (Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled())
442 system_bubble_->bubble()->FocusDefaultIfNeeded();
435 } else { 443 } else {
436 // Cleanup the existing bubble before showing a new one. Otherwise, it's 444 // Cleanup the existing bubble before showing a new one. Otherwise, it's
437 // possible to confuse the new system bubble with the old one during 445 // possible to confuse the new system bubble with the old one during
438 // destruction, leading to subtle errors/crashes such as crbug.com/545166. 446 // destruction, leading to subtle errors/crashes such as crbug.com/545166.
439 DestroySystemBubble(); 447 DestroySystemBubble();
440 448
441 // Remember if the menu is a single property (like e.g. volume) or the 449 // Remember if the menu is a single property (like e.g. volume) or the
442 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case 450 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case
443 // above, |full_system_tray_menu_| does not get changed since the fact that 451 // above, |full_system_tray_menu_| does not get changed since the fact that
444 // the menu is full (or not) doesn't change even if a "single property" 452 // the menu is full (or not) doesn't change even if a "single property"
445 // (like network) replaces most of the menu. 453 // (like network) replaces most of the menu.
446 full_system_tray_menu_ = items.size() > 1; 454 full_system_tray_menu_ = items.size() > 1;
447 455
448 TrayBubbleView::InitParams init_params; 456 TrayBubbleView::InitParams init_params;
449 init_params.anchor_alignment = GetAnchorAlignment(); 457 init_params.anchor_alignment = GetAnchorAlignment();
450 init_params.min_width = kTrayMenuMinimumWidth; 458 init_params.min_width = kTrayMenuMinimumWidth;
451 init_params.max_width = kTrayPopupMaxWidth; 459 init_params.max_width = kTrayPopupMaxWidth;
460 // TODO(oshima): Change TrayBubbleView itself.
461 init_params.can_activate = false;
452 // The bubble is not initially activatable, but will become activatable if 462 // The bubble is not initially activatable, but will become activatable if
453 // the user presses Tab. For behavioral consistency with the non-activatable 463 // the user presses Tab. For behavioral consistency with the non-activatable
454 // scenario, don't close on deactivation after Tab either. 464 // scenario, don't close on deactivation after Tab either.
455 init_params.close_on_deactivate = false; 465 init_params.close_on_deactivate = false;
456 if (detailed) { 466 if (detailed) {
457 // This is the case where a volume control or brightness control bubble 467 // This is the case where a volume control or brightness control bubble
458 // is created. 468 // is created.
459 init_params.max_height = default_bubble_height_; 469 init_params.max_height = default_bubble_height_;
460 } else { 470 } else {
461 init_params.bg_color = kHeaderBackgroundColor; 471 init_params.bg_color = kHeaderBackgroundColor;
462 } 472 }
463 SystemTrayBubble* bubble = new SystemTrayBubble(this, items, bubble_type); 473 SystemTrayBubble* bubble = new SystemTrayBubble(this, items, bubble_type);
464 474
465 system_bubble_.reset(new SystemBubbleWrapper(bubble)); 475 system_bubble_.reset(new SystemBubbleWrapper(bubble));
466 system_bubble_->InitView(this, GetBubbleAnchor(), GetBubbleAnchorInsets(), 476 system_bubble_->InitView(this, GetBubbleAnchor(), GetBubbleAnchorInsets(),
467 &init_params, persistent); 477 &init_params, persistent);
468 478
469 activation_observer_.reset(persistent ? nullptr 479 activation_observer_.reset(persistent ? nullptr
470 : new ActivationObserver(this)); 480 : new ActivationObserver(this));
471 481
472 // Record metrics for the system menu when the default view is invoked. 482 // Record metrics for the system menu when the default view is invoked.
473 if (!detailed) 483 if (!detailed)
474 RecordSystemMenuMetrics(); 484 RecordSystemMenuMetrics();
475 } 485 }
476 // Save height of default view for creating detailed views directly. 486 // Save height of default view for creating detailed views directly.
477 if (!detailed) 487 if (!detailed)
478 default_bubble_height_ = system_bubble_->bubble_view()->height(); 488 default_bubble_height_ = system_bubble_->bubble_view()->height();
479 489
490 key_event_watcher_.reset();
491 if (can_activate)
492 CreateKeyEventWatcher();
493
480 if (detailed && items.size() > 0) 494 if (detailed && items.size() > 0)
481 detailed_item_ = items[0]; 495 detailed_item_ = items[0];
482 else 496 else
483 detailed_item_ = NULL; 497 detailed_item_ = NULL;
484 498
485 UpdateWebNotifications(); 499 UpdateWebNotifications();
486 shelf()->UpdateAutoHideState(); 500 shelf()->UpdateAutoHideState();
487 501
488 // When we show the system menu in our alternate shelf layout, we need to 502 // When we show the system menu in our alternate shelf layout, we need to
489 // tint the background. 503 // tint the background.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 void SystemTray::OnMouseEnteredView() { 574 void SystemTray::OnMouseEnteredView() {
561 if (system_bubble_) 575 if (system_bubble_)
562 system_bubble_->bubble()->StopAutoCloseTimer(); 576 system_bubble_->bubble()->StopAutoCloseTimer();
563 } 577 }
564 578
565 void SystemTray::OnMouseExitedView() { 579 void SystemTray::OnMouseExitedView() {
566 if (system_bubble_) 580 if (system_bubble_)
567 system_bubble_->bubble()->RestartAutoCloseTimer(); 581 system_bubble_->bubble()->RestartAutoCloseTimer();
568 } 582 }
569 583
570 void SystemTray::RegisterAccelerators(
571 const std::vector<ui::Accelerator>& accelerators,
572 views::TrayBubbleView* tray_bubble_view) {
573 Shell::Get()->accelerator_controller()->Register(accelerators,
574 tray_bubble_view);
575 }
576
577 void SystemTray::UnregisterAllAccelerators(
578 views::TrayBubbleView* tray_bubble_view) {
579 Shell::Get()->accelerator_controller()->UnregisterAll(tray_bubble_view);
580 }
581
582 base::string16 SystemTray::GetAccessibleNameForBubble() { 584 base::string16 SystemTray::GetAccessibleNameForBubble() {
583 return GetAccessibleNameForTray(); 585 return GetAccessibleNameForTray();
584 } 586 }
585 587
586 bool SystemTray::ShouldEnableExtraKeyboardAccessibility() {
587 // Do not enable extra keyboard accessibility for persistent system bubble.
588 // e.g. volume slider. Persistent system bubble is a bubble which is not
589 // closed even if user clicks outside of the bubble.
590 return system_bubble_ && !system_bubble_->is_persistent() &&
591 Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled();
592 }
593
594 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { 588 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) {
595 HideBubbleWithView(bubble_view); 589 HideBubbleWithView(bubble_view);
596 } 590 }
597 591
598 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { 592 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) {
599 CloseSystemBubble(); 593 CloseSystemBubble();
600 } 594 }
601 595
602 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { 596 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) {
603 if (!system_bubble_) 597 if (!system_bubble_)
604 return; 598 return;
605 ActivateBubble(); 599 ActivateBubble();
606 600
607 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); 601 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget();
608 widget->GetFocusManager()->OnKeyEvent(key_event); 602 widget->GetFocusManager()->OnKeyEvent(key_event);
609 } 603 }
610 604
605 void SystemTray::CreateKeyEventWatcher() {
606 key_event_watcher_ = ShellPort::Get()->CreateKeyEventWatcher();
607 // mustash does not yet support KeyEventWatcher. http://crbug.com/649600.
608 if (!key_event_watcher_)
609 return;
610 key_event_watcher_->AddKeyEventCallback(
611 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE),
612 base::Bind(&SystemTray::CloseBubble, base::Unretained(this)));
613 key_event_watcher_->AddKeyEventCallback(
614 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE),
615 base::Bind(&SystemTray::ActivateAndStartNavigation,
616 base::Unretained(this)));
617 key_event_watcher_->AddKeyEventCallback(
618 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN),
619 base::Bind(&SystemTray::ActivateAndStartNavigation,
620 base::Unretained(this)));
621 }
622
611 void SystemTray::ActivateBubble() { 623 void SystemTray::ActivateBubble() {
612 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); 624 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view();
613 // If system tray bubble is in the process of closing, do not try to activate 625 // If system tray bubble is in the process of closing, do not try to activate
614 // bubble. 626 // bubble.
615 if (bubble_view->GetWidget()->IsClosed()) 627 if (bubble_view->GetWidget()->IsClosed())
616 return; 628 return;
617 bubble_view->set_can_activate(true); 629 bubble_view->set_can_activate(true);
618 bubble_view->GetWidget()->Activate(); 630 bubble_view->GetWidget()->Activate();
619 } 631 }
620 632
621 bool SystemTray::PerformAction(const ui::Event& event) { 633 bool SystemTray::PerformAction(const ui::Event& event) {
622 // If we're already showing the default view or detailed view in system menu, 634 // If we're already showing the default view or detailed view in system menu,
623 // hide it; otherwise, show it (and hide any popup that's currently shown). 635 // hide it; otherwise, show it (and hide any popup that's currently shown).
624 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT) || 636 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT) ||
625 (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED) && 637 (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED) &&
626 full_system_tray_menu_)) { 638 full_system_tray_menu_)) {
627 system_bubble_->bubble()->Close(); 639 system_bubble_->bubble()->Close();
628 } else { 640 } else {
629 ShowDefaultView(BUBBLE_CREATE_NEW); 641 ShowDefaultView(BUBBLE_CREATE_NEW);
630 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) 642 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY))
631 ActivateBubble(); 643 ActivateBubble();
632 } 644 }
633 return true; 645 return true;
634 } 646 }
635 647
636 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 648 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
637 activation_observer_.reset(); 649 activation_observer_.reset();
650 key_event_watcher_.reset();
638 system_bubble_.reset(); 651 system_bubble_.reset();
639 // When closing a system bubble with the alternate shelf layout, we need to 652 // When closing a system bubble with the alternate shelf layout, we need to
640 // turn off the active tinting of the shelf. 653 // turn off the active tinting of the shelf.
641 if (full_system_tray_menu_) { 654 if (full_system_tray_menu_) {
642 SetIsActive(false); 655 SetIsActive(false);
643 full_system_tray_menu_ = false; 656 full_system_tray_menu_ = false;
644 } 657 }
645 } 658 }
646 659
647 void SystemTray::RecordSystemMenuMetrics() { 660 void SystemTray::RecordSystemMenuMetrics() {
(...skipping 17 matching lines...) Expand all
665 .work_area() 678 .work_area()
666 .height(); 679 .height();
667 if (work_area_height > 0) { 680 if (work_area_height > 0) {
668 UMA_HISTOGRAM_CUSTOM_COUNTS( 681 UMA_HISTOGRAM_CUSTOM_COUNTS(
669 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 682 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
670 100 * bubble_view->height() / work_area_height, 1, 300, 100); 683 100 * bubble_view->height() / work_area_height, 1, 300, 100);
671 } 684 }
672 } 685 }
673 686
674 } // namespace ash 687 } // 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