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/common/system/tray/system_tray_bubble.h" | 5 #include "ash/common/system/tray/system_tray_bubble.h" |
6 | 6 |
7 #include "ash/common/system/tray/system_tray_delegate.h" | 7 #include "ash/common/system/tray/system_tray_delegate.h" |
8 #include "ash/common/system/tray/system_tray_item.h" | 8 #include "ash/common/system/tray/system_tray_item.h" |
9 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 9 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; | 34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
35 | 35 |
36 // Duration of swipe animation used when transitioning from a default to | 36 // Duration of swipe animation used when transitioning from a default to |
37 // detailed view or vice versa. | 37 // detailed view or vice versa. |
38 const int kSwipeDelayMS = 150; | 38 const int kSwipeDelayMS = 150; |
39 | 39 |
40 // Implicit animation observer that deletes itself and the layer at the end of | 40 // Implicit animation observer that deletes itself and the layer at the end of |
41 // the animation. | 41 // the animation. |
42 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { | 42 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { |
43 public: | 43 public: |
44 explicit AnimationObserverDeleteLayer(ui::Layer* layer) | 44 explicit AnimationObserverDeleteLayer(ui::Layer* layer) : layer_(layer) {} |
45 : layer_(layer) { | |
46 } | |
47 | 45 |
48 ~AnimationObserverDeleteLayer() override {} | 46 ~AnimationObserverDeleteLayer() override {} |
49 | 47 |
50 void OnImplicitAnimationsCompleted() override { | 48 void OnImplicitAnimationsCompleted() override { |
51 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 49 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
52 } | 50 } |
53 | 51 |
54 private: | 52 private: |
55 std::unique_ptr<ui::Layer> layer_; | 53 std::unique_ptr<ui::Layer> layer_; |
56 | 54 |
57 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); | 55 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); |
58 }; | 56 }; |
59 | 57 |
60 } // namespace | 58 } // namespace |
61 | 59 |
62 // SystemTrayBubble | 60 // SystemTrayBubble |
63 | 61 |
64 SystemTrayBubble::SystemTrayBubble( | 62 SystemTrayBubble::SystemTrayBubble( |
65 ash::SystemTray* tray, | 63 ash::SystemTray* tray, |
66 const std::vector<ash::SystemTrayItem*>& items, | 64 const std::vector<ash::SystemTrayItem*>& items, |
67 BubbleType bubble_type) | 65 BubbleType bubble_type) |
68 : tray_(tray), | 66 : tray_(tray), |
69 bubble_view_(NULL), | 67 bubble_view_(NULL), |
70 items_(items), | 68 items_(items), |
71 bubble_type_(bubble_type), | 69 bubble_type_(bubble_type), |
72 autoclose_delay_(0) { | 70 autoclose_delay_(0) {} |
73 } | |
74 | 71 |
75 SystemTrayBubble::~SystemTrayBubble() { | 72 SystemTrayBubble::~SystemTrayBubble() { |
76 DestroyItemViews(); | 73 DestroyItemViews(); |
77 // Reset the host pointer in bubble_view_ in case its destruction is deferred. | 74 // Reset the host pointer in bubble_view_ in case its destruction is deferred. |
78 if (bubble_view_) | 75 if (bubble_view_) |
79 bubble_view_->reset_delegate(); | 76 bubble_view_->reset_delegate(); |
80 } | 77 } |
81 | 78 |
82 void SystemTrayBubble::UpdateView( | 79 void SystemTrayBubble::UpdateView( |
83 const std::vector<ash::SystemTrayItem*>& items, | 80 const std::vector<ash::SystemTrayItem*>& items, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } else if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) { | 187 } else if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) { |
191 init_params->close_on_deactivate = false; | 188 init_params->close_on_deactivate = false; |
192 } | 189 } |
193 // The TrayBubbleView will use |anchor| and |tray_| to determine the parent | 190 // The TrayBubbleView will use |anchor| and |tray_| to determine the parent |
194 // container for the bubble. | 191 // container for the bubble. |
195 bubble_view_ = TrayBubbleView::Create(anchor, tray_, init_params); | 192 bubble_view_ = TrayBubbleView::Create(anchor, tray_, init_params); |
196 bubble_view_->set_adjust_if_offscreen(false); | 193 bubble_view_->set_adjust_if_offscreen(false); |
197 CreateItemViews(login_status); | 194 CreateItemViews(login_status); |
198 | 195 |
199 if (bubble_view_->CanActivate()) { | 196 if (bubble_view_->CanActivate()) { |
200 bubble_view_->NotifyAccessibilityEvent( | 197 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
201 ui::AX_EVENT_ALERT, true); | |
202 } | 198 } |
203 } | 199 } |
204 | 200 |
205 void SystemTrayBubble::FocusDefaultIfNeeded() { | 201 void SystemTrayBubble::FocusDefaultIfNeeded() { |
206 views::FocusManager* manager = bubble_view_->GetFocusManager(); | 202 views::FocusManager* manager = bubble_view_->GetFocusManager(); |
207 if (!manager || manager->GetFocusedView()) | 203 if (!manager || manager->GetFocusedView()) |
208 return; | 204 return; |
209 | 205 |
210 views::View* view = manager->GetNextFocusableView(NULL, NULL, false, false); | 206 views::View* view = manager->GetNextFocusableView(NULL, NULL, false, false); |
211 if (view) | 207 if (view) |
212 view->RequestFocus(); | 208 view->RequestFocus(); |
213 } | 209 } |
214 | 210 |
215 void SystemTrayBubble::DestroyItemViews() { | 211 void SystemTrayBubble::DestroyItemViews() { |
216 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); | 212 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
217 it != items_.end(); | 213 it != items_.end(); ++it) { |
218 ++it) { | |
219 switch (bubble_type_) { | 214 switch (bubble_type_) { |
220 case BUBBLE_TYPE_DEFAULT: | 215 case BUBBLE_TYPE_DEFAULT: |
221 (*it)->DestroyDefaultView(); | 216 (*it)->DestroyDefaultView(); |
222 break; | 217 break; |
223 case BUBBLE_TYPE_DETAILED: | 218 case BUBBLE_TYPE_DETAILED: |
224 (*it)->DestroyDetailedView(); | 219 (*it)->DestroyDetailedView(); |
225 break; | 220 break; |
226 case BUBBLE_TYPE_NOTIFICATION: | 221 case BUBBLE_TYPE_NOTIFICATION: |
227 (*it)->DestroyNotificationView(); | 222 (*it)->DestroyNotificationView(); |
228 break; | 223 break; |
229 } | 224 } |
230 } | 225 } |
231 } | 226 } |
232 | 227 |
233 void SystemTrayBubble::BubbleViewDestroyed() { | 228 void SystemTrayBubble::BubbleViewDestroyed() { |
234 bubble_view_ = NULL; | 229 bubble_view_ = NULL; |
235 } | 230 } |
236 | 231 |
237 void SystemTrayBubble::StartAutoCloseTimer(int seconds) { | 232 void SystemTrayBubble::StartAutoCloseTimer(int seconds) { |
238 autoclose_.Stop(); | 233 autoclose_.Stop(); |
239 autoclose_delay_ = seconds; | 234 autoclose_delay_ = seconds; |
240 if (autoclose_delay_) { | 235 if (autoclose_delay_) { |
241 autoclose_.Start(FROM_HERE, | 236 autoclose_.Start(FROM_HERE, base::TimeDelta::FromSeconds(autoclose_delay_), |
242 base::TimeDelta::FromSeconds(autoclose_delay_), | |
243 this, &SystemTrayBubble::Close); | 237 this, &SystemTrayBubble::Close); |
244 } | 238 } |
245 } | 239 } |
246 | 240 |
247 void SystemTrayBubble::StopAutoCloseTimer() { | 241 void SystemTrayBubble::StopAutoCloseTimer() { |
248 autoclose_.Stop(); | 242 autoclose_.Stop(); |
249 } | 243 } |
250 | 244 |
251 void SystemTrayBubble::RestartAutoCloseTimer() { | 245 void SystemTrayBubble::RestartAutoCloseTimer() { |
252 if (autoclose_delay_) | 246 if (autoclose_delay_) |
(...skipping 13 matching lines...) Expand all Loading... |
266 else | 260 else |
267 bubble_widget->Hide(); | 261 bubble_widget->Hide(); |
268 } | 262 } |
269 | 263 |
270 bool SystemTrayBubble::IsVisible() { | 264 bool SystemTrayBubble::IsVisible() { |
271 return bubble_view() && bubble_view()->GetWidget()->IsVisible(); | 265 return bubble_view() && bubble_view()->GetWidget()->IsVisible(); |
272 } | 266 } |
273 | 267 |
274 bool SystemTrayBubble::ShouldShowShelf() const { | 268 bool SystemTrayBubble::ShouldShowShelf() const { |
275 for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); | 269 for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); |
276 it != items_.end(); | 270 it != items_.end(); ++it) { |
277 ++it) { | |
278 if ((*it)->ShouldShowShelf()) | 271 if ((*it)->ShouldShowShelf()) |
279 return true; | 272 return true; |
280 } | 273 } |
281 return false; | 274 return false; |
282 } | 275 } |
283 | 276 |
284 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 277 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
285 std::vector<views::View*> item_views; | 278 std::vector<views::View*> item_views; |
286 // If a system modal dialog is present, create the same tray as | 279 // If a system modal dialog is present, create the same tray as |
287 // in locked state. | 280 // in locked state. |
(...skipping 28 matching lines...) Expand all Loading... |
316 // 2 items, which are the bottom header row and the one just above it. | 309 // 2 items, which are the bottom header row and the one just above it. |
317 bubble_view_->AddChildView(new TrayPopupItemContainer( | 310 bubble_view_->AddChildView(new TrayPopupItemContainer( |
318 item_views[i], is_default_bubble, | 311 item_views[i], is_default_bubble, |
319 is_default_bubble && (i < item_views.size() - 2))); | 312 is_default_bubble && (i < item_views.size() - 2))); |
320 } | 313 } |
321 if (focus_view) | 314 if (focus_view) |
322 focus_view->RequestFocus(); | 315 focus_view->RequestFocus(); |
323 } | 316 } |
324 | 317 |
325 } // namespace ash | 318 } // namespace ash |
OLD | NEW |