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/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/status_area_widget.h" | 9 #include "ash/system/status_area_widget.h" |
10 #include "ash/system/tray/tray_bubble_wrapper.h" | 10 #include "ash/system/tray/tray_bubble_wrapper.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | 76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; |
77 }; | 77 }; |
78 | 78 |
79 } // namespace internal | 79 } // namespace internal |
80 | 80 |
81 WebNotificationTray::WebNotificationTray( | 81 WebNotificationTray::WebNotificationTray( |
82 internal::StatusAreaWidget* status_area_widget) | 82 internal::StatusAreaWidget* status_area_widget) |
83 : internal::TrayBackgroundView(status_area_widget), | 83 : internal::TrayBackgroundView(status_area_widget), |
84 button_(NULL), | 84 button_(NULL), |
85 show_message_center_on_unlock_(false) { | 85 show_message_center_on_unlock_(false) { |
86 message_center_ = message_center::MessageCenter::GetInstance(); | 86 message_center_ = ash::Shell::GetInstance()->message_center(); |
87 message_center_->AddObserver(this); | 87 message_center_->AddObserver(this); |
88 button_ = new views::ImageButton(this); | 88 button_ = new views::ImageButton(this); |
89 button_->set_triggerable_event_flags( | 89 button_->set_triggerable_event_flags( |
90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
91 tray_container()->AddChildView(button_); | 91 tray_container()->AddChildView(button_); |
92 SetVisible(false); | 92 SetVisible(false); |
93 UpdateTray(); | 93 UpdateTray(); |
94 } | 94 } |
95 | 95 |
96 WebNotificationTray::~WebNotificationTray() { | 96 WebNotificationTray::~WebNotificationTray() { |
97 // Ensure the message center doesn't notify a destroyed object. | 97 // Ensure the message center doesn't notify an object under destruction. |
98 message_center_->RemoveObserver(this); | 98 message_center_->RemoveObserver(this); |
99 // Release any child views that might have back pointers before ~View(). | 99 // Release any child views that might have back pointers before ~View(). |
100 message_center_bubble_.reset(); | 100 message_center_bubble_.reset(); |
101 popup_bubble_.reset(); | 101 popup_bubble_.reset(); |
102 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 102 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
103 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); | 103 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); |
104 quiet_mode_bubble_.reset(); | 104 quiet_mode_bubble_.reset(); |
105 } | 105 } |
106 | 106 |
107 void WebNotificationTray::ShowMessageCenterBubble() { | 107 void WebNotificationTray::ShowMessageCenterBubble() { |
108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
109 return; | 109 return; |
110 if (quiet_mode_bubble()) | 110 if (quiet_mode_bubble()) |
111 quiet_mode_bubble_.reset(); | 111 quiet_mode_bubble_.reset(); |
112 if (message_center_bubble()) { | 112 if (message_center_bubble()) { |
113 UpdateTray(); | 113 UpdateTray(); |
114 return; | 114 return; |
115 } | 115 } |
116 // Indicate that the message center is visible. Clears the unread count. | 116 // Indicate that the message center is visible. Clears the unread count. |
117 message_center_->SetMessageCenterVisible(true); | 117 message_center_->SetMessageCenterVisible(true); |
118 UpdateTray(); | 118 UpdateTray(); |
119 HidePopupBubble(); | 119 HidePopupBubble(); |
120 message_center::MessageCenterBubble* bubble = | 120 message_center::MessageCenterBubble* bubble = |
121 new message_center::MessageCenterBubble(message_center_); | 121 new message_center::MessageCenterBubble(message_center_.get()); |
122 // Sets the maximum height of the bubble based on the screen. | 122 // Sets the maximum height of the bubble based on the screen. |
123 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe | 123 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe |
124 // to set the height of the popup. | 124 // to set the height of the popup. |
125 int max_height = 0; | 125 int max_height = 0; |
126 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 126 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
127 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); | 127 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); |
128 max_height = shelf_bounds.y(); | 128 max_height = shelf_bounds.y(); |
129 } else { | 129 } else { |
130 // Assume that the bottom line of the status area widget and the bubble are | 130 // Assume that the bottom line of the status area widget and the bubble are |
131 // aligned. | 131 // aligned. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return; | 165 return; |
166 if (!status_area_widget()->ShouldShowWebNotifications()) | 166 if (!status_area_widget()->ShouldShowWebNotifications()) |
167 return; | 167 return; |
168 UpdateTray(); | 168 UpdateTray(); |
169 if (popup_bubble()) { | 169 if (popup_bubble()) { |
170 popup_bubble()->bubble()->ScheduleUpdate(); | 170 popup_bubble()->bubble()->ScheduleUpdate(); |
171 } else if (message_center_->HasPopupNotifications()) { | 171 } else if (message_center_->HasPopupNotifications()) { |
172 popup_bubble_.reset( | 172 popup_bubble_.reset( |
173 new internal::WebNotificationBubbleWrapper( | 173 new internal::WebNotificationBubbleWrapper( |
174 this, new message_center::MessagePopupBubble( | 174 this, new message_center::MessagePopupBubble( |
175 message_center_))); | 175 message_center_.get()))); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void WebNotificationTray::HidePopupBubble() { | 179 void WebNotificationTray::HidePopupBubble() { |
180 popup_bubble_.reset(); | 180 popup_bubble_.reset(); |
181 } | 181 } |
182 | 182 |
183 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { | 183 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
184 // TODO(mukai): Add keyboard event handler. | 184 // TODO(mukai): Add keyboard event handler. |
185 if (!event.IsMouseEvent()) | 185 if (!event.IsMouseEvent()) |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 message_center::MessagePopupBubble* | 406 message_center::MessagePopupBubble* |
407 WebNotificationTray::GetPopupBubbleForTest() { | 407 WebNotificationTray::GetPopupBubbleForTest() { |
408 if (!popup_bubble_.get()) | 408 if (!popup_bubble_.get()) |
409 return NULL; | 409 return NULL; |
410 return static_cast<message_center::MessagePopupBubble*>( | 410 return static_cast<message_center::MessagePopupBubble*>( |
411 popup_bubble_->bubble()); | 411 popup_bubble_->bubble()); |
412 } | 412 } |
413 | 413 |
414 } // namespace ash | 414 } // namespace ash |
OLD | NEW |