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

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 10836227: Fix status area accessability issues. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/system/status_area_widget.h" 7 #include "ash/system/status_area_widget.h"
8 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/tray_bubble_view.h" 9 #include "ash/system/tray/tray_bubble_view.h"
10 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
11 #include "ash/system/tray/tray_views.h" 11 #include "ash/system/tray/tray_views.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
18 #include "grit/ui_resources.h" 18 #include "grit/ui_resources.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/models/simple_menu_model.h" 21 #include "ui/base/models/simple_menu_model.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image_skia_operations.h" 23 #include "ui/gfx/image/image_skia_operations.h"
24 #include "ui/gfx/screen.h"
24 #include "ui/views/controls/button/button.h" 25 #include "ui/views/controls/button/button.h"
25 #include "ui/views/controls/button/menu_button.h" 26 #include "ui/views/controls/button/menu_button.h"
26 #include "ui/views/controls/button/menu_button_listener.h" 27 #include "ui/views/controls/button/menu_button_listener.h"
27 #include "ui/views/controls/label.h" 28 #include "ui/views/controls/label.h"
28 #include "ui/views/controls/menu/menu_model_adapter.h" 29 #include "ui/views/controls/menu/menu_model_adapter.h"
29 #include "ui/views/controls/menu/menu_runner.h" 30 #include "ui/views/controls/menu/menu_runner.h"
30 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/layout/fill_layout.h" 32 #include "ui/views/layout/fill_layout.h"
32 #include "ui/views/layout/grid_layout.h" 33 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/painter.h" 34 #include "ui/views/painter.h"
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 bubble_view_(NULL), 707 bubble_view_(NULL),
707 bubble_widget_(NULL), 708 bubble_widget_(NULL),
708 contents_view_(NULL), 709 contents_view_(NULL),
709 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 710 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
710 views::View* anchor = tray->tray_container(); 711 views::View* anchor = tray->tray_container();
711 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, 712 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY,
712 tray->shelf_alignment()); 713 tray->shelf_alignment());
713 init_params.bubble_width = kWebNotificationWidth; 714 init_params.bubble_width = kWebNotificationWidth;
714 if (bubble_type == BUBBLE_TYPE_MESAGE_CENTER) { 715 if (bubble_type == BUBBLE_TYPE_MESAGE_CENTER) {
715 init_params.max_height = kWebNotificationBubbleMaxHeight; 716 init_params.max_height = kWebNotificationBubbleMaxHeight;
717 init_params.can_activate = true;
716 } else { 718 } else {
717 init_params.arrow_color = kBackgroundColor; 719 init_params.arrow_color = kBackgroundColor;
718 init_params.close_on_deactivate = false; 720 init_params.close_on_deactivate = false;
719 } 721 }
720 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { 722 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
721 gfx::Point bounds(anchor->width() / 2, 0); 723 gfx::Point bounds(anchor->width() / 2, 0);
722 ConvertPointToWidget(anchor, &bounds); 724 ConvertPointToWidget(anchor, &bounds);
723 init_params.arrow_offset = bounds.x(); 725 init_params.arrow_offset = bounds.x();
724 } 726 }
725 bubble_view_ = TrayBubbleView::Create(anchor, this, init_params); 727 bubble_view_ = TrayBubbleView::Create(anchor, this, init_params);
(...skipping 25 matching lines...) Expand all
751 StartAutoCloseTimer(); 753 StartAutoCloseTimer();
752 754
753 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. 755 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update.
754 MessageLoop::current()->PostDelayedTask( 756 MessageLoop::current()->PostDelayedTask(
755 FROM_HERE, 757 FROM_HERE,
756 base::Bind(&WebNotificationTray::Bubble::UpdateBubbleView, 758 base::Bind(&WebNotificationTray::Bubble::UpdateBubbleView,
757 weak_ptr_factory_.GetWeakPtr()), 759 weak_ptr_factory_.GetWeakPtr()),
758 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); 760 base::TimeDelta::FromMilliseconds(kUpdateDelayMs));
759 } 761 }
760 762
763 bool IsVisible() const {
764 return bubble_widget_ && bubble_widget_->IsVisible();
765 }
766
761 views::Widget* bubble_widget() const { return bubble_widget_; } 767 views::Widget* bubble_widget() const { return bubble_widget_; }
768 TrayBubbleView* bubble_view() const { return bubble_view_; }
762 769
763 // Overridden from TrayBubbleView::Host. 770 // Overridden from TrayBubbleView::Host.
764 virtual void BubbleViewDestroyed() OVERRIDE { 771 virtual void BubbleViewDestroyed() OVERRIDE {
765 bubble_view_ = NULL; 772 bubble_view_ = NULL;
766 contents_view_ = NULL; 773 contents_view_ = NULL;
767 } 774 }
768 775
769 virtual void OnMouseEnteredView() OVERRIDE { 776 virtual void OnMouseEnteredView() OVERRIDE {
770 StopAutoCloseTimer(); 777 StopAutoCloseTimer();
778 tray_->UpdateShouldShowLauncher();
771 } 779 }
772 780
773 virtual void OnMouseExitedView() OVERRIDE { 781 virtual void OnMouseExitedView() OVERRIDE {
774 StartAutoCloseTimer(); 782 StartAutoCloseTimer();
783 tray_->UpdateShouldShowLauncher();
775 } 784 }
776 785
777 virtual void OnClickedOutsideView() OVERRIDE { 786 virtual void OnClickedOutsideView() OVERRIDE {
778 // May delete |this|. 787 // May delete |this|.
779 tray_->HideMessageCenterBubble(); 788 tray_->HideMessageCenterBubble();
780 } 789 }
781 790
791 virtual string16 GetAccessibleName() OVERRIDE {
792 return tray_->GetAccessibleName();
793 }
794
782 // Overridden from views::WidgetObserver: 795 // Overridden from views::WidgetObserver:
783 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { 796 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE {
784 CHECK_EQ(bubble_widget_, widget); 797 CHECK_EQ(bubble_widget_, widget);
785 bubble_widget_ = NULL; 798 bubble_widget_ = NULL;
786 tray_->HideBubble(this); // Will destroy |this|. 799 tray_->HideBubble(this); // Will destroy |this|.
787 } 800 }
788 801
789 private: 802 private:
790 void UpdateBubbleView() { 803 void UpdateBubbleView() {
791 const WebNotificationList::Notifications& notifications = 804 const WebNotificationList::Notifications& notifications =
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 if (message_center_bubble()) { 909 if (message_center_bubble()) {
897 UpdateTray(); 910 UpdateTray();
898 return; 911 return;
899 } 912 }
900 notification_list_->SetIsVisible(true); // clears notification count 913 notification_list_->SetIsVisible(true); // clears notification count
901 UpdateTray(); 914 UpdateTray();
902 HideNotificationBubble(); 915 HideNotificationBubble();
903 message_center_bubble_.reset( 916 message_center_bubble_.reset(
904 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); 917 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER));
905 status_area_widget()->SetHideSystemNotifications(true); 918 status_area_widget()->SetHideSystemNotifications(true);
919 UpdateShouldShowLauncher();
906 } 920 }
907 921
908 void WebNotificationTray::HideMessageCenterBubble() { 922 void WebNotificationTray::HideMessageCenterBubble() {
909 if (!message_center_bubble()) 923 if (!message_center_bubble())
910 return; 924 return;
911 message_center_bubble_.reset(); 925 message_center_bubble_.reset();
912 show_message_center_on_unlock_ = false; 926 show_message_center_on_unlock_ = false;
913 notification_list_->SetIsVisible(false); 927 notification_list_->SetIsVisible(false);
914 status_area_widget()->SetHideSystemNotifications(false); 928 status_area_widget()->SetHideSystemNotifications(false);
929 UpdateShouldShowLauncher();
915 } 930 }
916 931
917 void WebNotificationTray::ShowNotificationBubble() { 932 void WebNotificationTray::ShowNotificationBubble() {
918 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 933 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
919 return; 934 return;
920 if (message_center_bubble()) 935 if (message_center_bubble())
921 return; 936 return;
922 if (!status_area_widget()->ShouldShowNonSystemNotifications()) 937 if (!status_area_widget()->ShouldShowNonSystemNotifications())
923 return; 938 return;
924 UpdateTray(); 939 UpdateTray();
(...skipping 18 matching lines...) Expand all
943 } 958 }
944 HideNotificationBubble(); 959 HideNotificationBubble();
945 } else { 960 } else {
946 if (show_message_center_on_unlock_) 961 if (show_message_center_on_unlock_)
947 ShowMessageCenterBubble(); 962 ShowMessageCenterBubble();
948 show_message_center_on_unlock_ = false; 963 show_message_center_on_unlock_ = false;
949 } 964 }
950 UpdateTray(); 965 UpdateTray();
951 } 966 }
952 967
968 bool WebNotificationTray::IsMessageCenterBubbleVisible() const {
969 return (message_center_bubble() && message_center_bubble_->IsVisible());
970 }
971
972 bool WebNotificationTray::IsMouseInNotificationBubble() const {
973 if (!notification_bubble())
974 return false;
975 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains(
976 gfx::Screen::GetCursorScreenPoint());
977 }
978
953 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { 979 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
954 if (alignment == shelf_alignment()) 980 if (alignment == shelf_alignment())
955 return; 981 return;
956 internal::TrayBackgroundView::SetShelfAlignment(alignment); 982 internal::TrayBackgroundView::SetShelfAlignment(alignment);
957 if (alignment == SHELF_ALIGNMENT_BOTTOM) 983 if (alignment == SHELF_ALIGNMENT_BOTTOM)
958 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); 984 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
959 else 985 else
960 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); 986 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight));
961 // Destroy any existing bubble so that it will be rebuilt correctly. 987 // Destroy any existing bubble so that it will be rebuilt correctly.
962 HideMessageCenterBubble(); 988 HideMessageCenterBubble();
963 HideNotificationBubble(); 989 HideNotificationBubble();
964 } 990 }
965 991
992 void WebNotificationTray::AnchorUpdated() {
993 if (notification_bubble_.get()) {
994 notification_bubble_->bubble_view()->UpdateBubble();
995 // Ensure that the notification buble is above the launcher/status area.
996 notification_bubble_->bubble_view()->GetWidget()->StackAtTop();
997 }
998 if (message_center_bubble_.get())
999 message_center_bubble_->bubble_view()->UpdateBubble();
1000 }
1001
1002 string16 WebNotificationTray::GetAccessibleName() {
1003 return l10n_util::GetStringUTF16(
1004 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME);
1005 }
1006
966 // Protected methods (invoked only from Bubble and its child classes) 1007 // Protected methods (invoked only from Bubble and its child classes)
967 1008
968 void WebNotificationTray::SendRemoveNotification(const std::string& id) { 1009 void WebNotificationTray::SendRemoveNotification(const std::string& id) {
969 // If this is the only notification in the list, close the bubble. 1010 // If this is the only notification in the list, close the bubble.
970 if (notification_list_->notifications().size() == 1 && 1011 if (notification_list_->notifications().size() == 1 &&
971 id == notification_list_->GetFirstId()) { 1012 id == notification_list_->GetFirstId()) {
972 HideMessageCenterBubble(); 1013 HideMessageCenterBubble();
973 } 1014 }
974 if (delegate_) 1015 if (delegate_)
975 delegate_->NotificationRemoved(id); 1016 delegate_->NotificationRemoved(id);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1072
1032 // Private methods 1073 // Private methods
1033 1074
1034 void WebNotificationTray::UpdateTray() { 1075 void WebNotificationTray::UpdateTray() {
1035 count_label_->SetText(UTF8ToUTF16( 1076 count_label_->SetText(UTF8ToUTF16(
1036 GetNotificationText(notification_list()->unread_count()))); 1077 GetNotificationText(notification_list()->unread_count())));
1037 // Dim the message count text only if the message center is empty. 1078 // Dim the message count text only if the message center is empty.
1038 count_label_->SetEnabledColor( 1079 count_label_->SetEnabledColor(
1039 (notification_list()->notifications().size() == 0) ? 1080 (notification_list()->notifications().size() == 0) ?
1040 kMessageCountDimmedColor : kMessageCountColor); 1081 kMessageCountDimmedColor : kMessageCountColor);
1041 SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE)); 1082 bool is_visible =
1083 (status_area_widget()->login_status() != user::LOGGED_IN_NONE) &&
1084 (status_area_widget()->login_status() != user::LOGGED_IN_LOCKED);
1085 SetVisible(is_visible);
1042 Layout(); 1086 Layout();
1043 SchedulePaint(); 1087 SchedulePaint();
1044 } 1088 }
1045 1089
1046 void WebNotificationTray::UpdateTrayAndBubble() { 1090 void WebNotificationTray::UpdateTrayAndBubble() {
1047 UpdateTray(); 1091 UpdateTray();
1048 1092
1049 if (message_center_bubble()) 1093 if (message_center_bubble())
1050 message_center_bubble()->ScheduleUpdate(); 1094 message_center_bubble()->ScheduleUpdate();
1051 1095
(...skipping 11 matching lines...) Expand all
1063 } else if (bubble == notification_bubble()) { 1107 } else if (bubble == notification_bubble()) {
1064 HideNotificationBubble(); 1108 HideNotificationBubble();
1065 } 1109 }
1066 } 1110 }
1067 1111
1068 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { 1112 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const {
1069 return notification_list_->HasNotification(id); 1113 return notification_list_->HasNotification(id);
1070 } 1114 }
1071 1115
1072 } // namespace ash 1116 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698