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

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

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