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/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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 | 204 |
204 // Since user avatar is on the right hand side of System tray of a | 205 // 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 | 206 // horizontal shelf and that is sufficient to indicate separation, no |
206 // separator is required. | 207 // separator is required. |
207 set_separator_visibility(false); | 208 set_separator_visibility(false); |
208 } | 209 } |
209 | 210 |
210 SystemTray::~SystemTray() { | 211 SystemTray::~SystemTray() { |
211 // Destroy any child views that might have back pointers before ~View(). | 212 // Destroy any child views that might have back pointers before ~View(). |
212 activation_observer_.reset(); | 213 activation_observer_.reset(); |
213 key_event_watcher_.reset(); | |
214 system_bubble_.reset(); | 214 system_bubble_.reset(); |
215 for (const auto& item : items_) | 215 for (const auto& item : items_) |
216 item->OnTrayViewDestroyed(); | 216 item->OnTrayViewDestroyed(); |
217 } | 217 } |
218 | 218 |
219 void SystemTray::InitializeTrayItems( | 219 void SystemTray::InitializeTrayItems( |
220 SystemTrayDelegate* delegate, | 220 SystemTrayDelegate* delegate, |
221 WebNotificationTray* web_notification_tray) { | 221 WebNotificationTray* web_notification_tray) { |
222 DCHECK(web_notification_tray); | 222 DCHECK(web_notification_tray); |
223 web_notification_tray_ = web_notification_tray; | 223 web_notification_tray_ = web_notification_tray; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 if (Shell::Get()->session_controller()->IsKioskSession()) | 429 if (Shell::Get()->session_controller()->IsKioskSession()) |
430 return; | 430 return; |
431 | 431 |
432 // Destroy any existing bubble and create a new one. | 432 // Destroy any existing bubble and create a new one. |
433 SystemTrayBubble::BubbleType bubble_type = | 433 SystemTrayBubble::BubbleType bubble_type = |
434 detailed ? SystemTrayBubble::BUBBLE_TYPE_DETAILED | 434 detailed ? SystemTrayBubble::BUBBLE_TYPE_DETAILED |
435 : SystemTrayBubble::BUBBLE_TYPE_DEFAULT; | 435 : SystemTrayBubble::BUBBLE_TYPE_DEFAULT; |
436 | 436 |
437 if (system_bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { | 437 if (system_bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { |
438 system_bubble_->bubble()->UpdateView(items, bubble_type); | 438 system_bubble_->bubble()->UpdateView(items, bubble_type); |
439 // If ChromeVox is enabled, focus the default item if no item is focused. | 439 // If ChromeVox is enabled, focus the default item if no item is focused. |
James Cook
2017/06/09 16:06:13
Is this comment still needed?
yawano
2017/06/12 09:11:03
No longer necessary. Deleted.
| |
440 if (Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled()) | |
441 system_bubble_->bubble()->FocusDefaultIfNeeded(); | |
442 } else { | 440 } else { |
443 // Cleanup the existing bubble before showing a new one. Otherwise, it's | 441 // Cleanup the existing bubble before showing a new one. Otherwise, it's |
444 // possible to confuse the new system bubble with the old one during | 442 // possible to confuse the new system bubble with the old one during |
445 // destruction, leading to subtle errors/crashes such as crbug.com/545166. | 443 // destruction, leading to subtle errors/crashes such as crbug.com/545166. |
446 DestroySystemBubble(); | 444 DestroySystemBubble(); |
447 | 445 |
448 // Remember if the menu is a single property (like e.g. volume) or the | 446 // Remember if the menu is a single property (like e.g. volume) or the |
449 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case | 447 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case |
450 // above, |full_system_tray_menu_| does not get changed since the fact that | 448 // above, |full_system_tray_menu_| does not get changed since the fact that |
451 // the menu is full (or not) doesn't change even if a "single property" | 449 // the menu is full (or not) doesn't change even if a "single property" |
(...skipping 27 matching lines...) Expand all Loading... | |
479 : new ActivationObserver(this)); | 477 : new ActivationObserver(this)); |
480 | 478 |
481 // Record metrics for the system menu when the default view is invoked. | 479 // Record metrics for the system menu when the default view is invoked. |
482 if (!detailed) | 480 if (!detailed) |
483 RecordSystemMenuMetrics(); | 481 RecordSystemMenuMetrics(); |
484 } | 482 } |
485 // Save height of default view for creating detailed views directly. | 483 // Save height of default view for creating detailed views directly. |
486 if (!detailed) | 484 if (!detailed) |
487 default_bubble_height_ = system_bubble_->bubble_view()->height(); | 485 default_bubble_height_ = system_bubble_->bubble_view()->height(); |
488 | 486 |
489 key_event_watcher_.reset(); | |
490 if (can_activate) | |
491 CreateKeyEventWatcher(); | |
492 | |
493 if (detailed && items.size() > 0) | 487 if (detailed && items.size() > 0) |
494 detailed_item_ = items[0]; | 488 detailed_item_ = items[0]; |
495 else | 489 else |
496 detailed_item_ = NULL; | 490 detailed_item_ = NULL; |
497 | 491 |
498 UpdateWebNotifications(); | 492 UpdateWebNotifications(); |
499 shelf()->UpdateAutoHideState(); | 493 shelf()->UpdateAutoHideState(); |
500 | 494 |
501 // When we show the system menu in our alternate shelf layout, we need to | 495 // When we show the system menu in our alternate shelf layout, we need to |
502 // tint the background. | 496 // tint the background. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 void SystemTray::OnMouseEnteredView() { | 567 void SystemTray::OnMouseEnteredView() { |
574 if (system_bubble_) | 568 if (system_bubble_) |
575 system_bubble_->bubble()->StopAutoCloseTimer(); | 569 system_bubble_->bubble()->StopAutoCloseTimer(); |
576 } | 570 } |
577 | 571 |
578 void SystemTray::OnMouseExitedView() { | 572 void SystemTray::OnMouseExitedView() { |
579 if (system_bubble_) | 573 if (system_bubble_) |
580 system_bubble_->bubble()->RestartAutoCloseTimer(); | 574 system_bubble_->bubble()->RestartAutoCloseTimer(); |
581 } | 575 } |
582 | 576 |
577 void SystemTray::RegisterAccelerators( | |
578 const std::vector<ui::Accelerator>& accelerators, | |
579 views::TrayBubbleView* tray_bubble_view) { | |
580 Shell::Get()->accelerator_controller()->Register(accelerators, | |
581 tray_bubble_view); | |
582 } | |
583 | |
584 void SystemTray::UnregisterAllAccelerators( | |
585 views::TrayBubbleView* tray_bubble_view) { | |
586 Shell::Get()->accelerator_controller()->UnregisterAll(tray_bubble_view); | |
587 } | |
588 | |
583 base::string16 SystemTray::GetAccessibleNameForBubble() { | 589 base::string16 SystemTray::GetAccessibleNameForBubble() { |
584 return GetAccessibleNameForTray(); | 590 return GetAccessibleNameForTray(); |
585 } | 591 } |
586 | 592 |
593 bool SystemTray::ShouldEnableExtraKeyboardAccessibility() { | |
594 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); | |
595 } | |
596 | |
587 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { | 597 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { |
588 HideBubbleWithView(bubble_view); | 598 HideBubbleWithView(bubble_view); |
589 } | 599 } |
590 | 600 |
591 TrayCast* SystemTray::GetTrayCastForTesting() const { | 601 TrayCast* SystemTray::GetTrayCastForTesting() const { |
592 return tray_cast_; | 602 return tray_cast_; |
593 } | 603 } |
594 | 604 |
595 TrayEnterprise* SystemTray::GetTrayEnterpriseForTesting() const { | 605 TrayEnterprise* SystemTray::GetTrayEnterpriseForTesting() const { |
596 return tray_enterprise_; | 606 return tray_enterprise_; |
(...skipping 21 matching lines...) Expand all Loading... | |
618 | 628 |
619 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { | 629 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { |
620 if (!system_bubble_) | 630 if (!system_bubble_) |
621 return; | 631 return; |
622 ActivateBubble(); | 632 ActivateBubble(); |
623 | 633 |
624 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); | 634 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); |
625 widget->GetFocusManager()->OnKeyEvent(key_event); | 635 widget->GetFocusManager()->OnKeyEvent(key_event); |
626 } | 636 } |
627 | 637 |
628 void SystemTray::CreateKeyEventWatcher() { | |
629 key_event_watcher_ = ShellPort::Get()->CreateKeyEventWatcher(); | |
630 // mustash does not yet support KeyEventWatcher. http://crbug.com/649600. | |
631 if (!key_event_watcher_) | |
632 return; | |
633 key_event_watcher_->AddKeyEventCallback( | |
634 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE), | |
635 base::Bind(&SystemTray::CloseBubble, base::Unretained(this))); | |
636 key_event_watcher_->AddKeyEventCallback( | |
637 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE), | |
638 base::Bind(&SystemTray::ActivateAndStartNavigation, | |
639 base::Unretained(this))); | |
640 key_event_watcher_->AddKeyEventCallback( | |
641 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN), | |
642 base::Bind(&SystemTray::ActivateAndStartNavigation, | |
643 base::Unretained(this))); | |
644 } | |
645 | |
646 void SystemTray::ActivateBubble() { | 638 void SystemTray::ActivateBubble() { |
647 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); | 639 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); |
648 // If system tray bubble is in the process of closing, do not try to activate | 640 // If system tray bubble is in the process of closing, do not try to activate |
649 // bubble. | 641 // bubble. |
650 if (bubble_view->GetWidget()->IsClosed()) | 642 if (bubble_view->GetWidget()->IsClosed()) |
651 return; | 643 return; |
652 bubble_view->set_can_activate(true); | 644 bubble_view->set_can_activate(true); |
653 bubble_view->GetWidget()->Activate(); | 645 bubble_view->GetWidget()->Activate(); |
654 } | 646 } |
655 | 647 |
656 bool SystemTray::PerformAction(const ui::Event& event) { | 648 bool SystemTray::PerformAction(const ui::Event& event) { |
657 // If we're already showing the default view or detailed view in system menu, | 649 // If we're already showing the default view or detailed view in system menu, |
658 // hide it; otherwise, show it (and hide any popup that's currently shown). | 650 // hide it; otherwise, show it (and hide any popup that's currently shown). |
659 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT) || | 651 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT) || |
660 (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED) && | 652 (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED) && |
661 full_system_tray_menu_)) { | 653 full_system_tray_menu_)) { |
662 system_bubble_->bubble()->Close(); | 654 system_bubble_->bubble()->Close(); |
663 } else { | 655 } else { |
664 ShowDefaultView(BUBBLE_CREATE_NEW); | 656 ShowDefaultView(BUBBLE_CREATE_NEW); |
665 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | 657 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) |
666 ActivateBubble(); | 658 ActivateBubble(); |
667 } | 659 } |
668 return true; | 660 return true; |
669 } | 661 } |
670 | 662 |
671 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 663 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
672 activation_observer_.reset(); | 664 activation_observer_.reset(); |
673 key_event_watcher_.reset(); | |
674 system_bubble_.reset(); | 665 system_bubble_.reset(); |
675 // When closing a system bubble with the alternate shelf layout, we need to | 666 // When closing a system bubble with the alternate shelf layout, we need to |
676 // turn off the active tinting of the shelf. | 667 // turn off the active tinting of the shelf. |
677 if (full_system_tray_menu_) { | 668 if (full_system_tray_menu_) { |
678 SetIsActive(false); | 669 SetIsActive(false); |
679 full_system_tray_menu_ = false; | 670 full_system_tray_menu_ = false; |
680 } | 671 } |
681 } | 672 } |
682 | 673 |
683 void SystemTray::RecordSystemMenuMetrics() { | 674 void SystemTray::RecordSystemMenuMetrics() { |
(...skipping 17 matching lines...) Expand all Loading... | |
701 .work_area() | 692 .work_area() |
702 .height(); | 693 .height(); |
703 if (work_area_height > 0) { | 694 if (work_area_height > 0) { |
704 UMA_HISTOGRAM_CUSTOM_COUNTS( | 695 UMA_HISTOGRAM_CUSTOM_COUNTS( |
705 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 696 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
706 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 697 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
707 } | 698 } |
708 } | 699 } |
709 | 700 |
710 } // namespace ash | 701 } // namespace ash |
OLD | NEW |