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_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/session/session_controller.h" | 10 #include "ash/session/session_controller.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 std::unique_ptr<ui::Layer> layer_; | 64 std::unique_ptr<ui::Layer> layer_; |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); | 66 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); |
67 }; | 67 }; |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 // CloseBubbleObserver is used to delay closing the system tray bubble until the | |
72 // animation completes. | |
73 class CloseBubbleObserver : public ui::ImplicitAnimationObserver { | |
74 public: | |
75 explicit CloseBubbleObserver(SystemTrayBubble* system_tray_bubble) | |
76 : system_tray_bubble_(system_tray_bubble) {} | |
77 | |
78 ~CloseBubbleObserver() override {} | |
79 | |
80 void OnImplicitAnimationsCompleted() override { | |
81 if (system_tray_bubble_) | |
xiyuan
2017/06/16 17:33:42
What if |system_tray_bubble_| go away before the a
minch1
2017/06/16 22:11:51
Verified that OnImplicitAnimationsCompleted() will
xiyuan
2017/06/16 23:09:13
Ack. Thanks.
| |
82 system_tray_bubble_->Close(); | |
83 delete this; | |
84 } | |
85 | |
86 private: | |
87 SystemTrayBubble* system_tray_bubble_ = nullptr; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(CloseBubbleObserver); | |
90 }; | |
91 | |
71 // SystemTrayBubble | 92 // SystemTrayBubble |
72 | 93 |
73 SystemTrayBubble::SystemTrayBubble( | 94 SystemTrayBubble::SystemTrayBubble( |
74 ash::SystemTray* tray, | 95 ash::SystemTray* tray, |
75 const std::vector<ash::SystemTrayItem*>& items, | 96 const std::vector<ash::SystemTrayItem*>& items, |
76 BubbleType bubble_type) | 97 BubbleType bubble_type) |
77 : tray_(tray), | 98 : tray_(tray), |
78 bubble_view_(nullptr), | 99 bubble_view_(nullptr), |
79 items_(items), | 100 items_(items), |
80 bubble_type_(bubble_type), | 101 bubble_type_(bubble_type), |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 TrayBubbleView::InitParams* init_params) { | 211 TrayBubbleView::InitParams* init_params) { |
191 DCHECK(anchor); | 212 DCHECK(anchor); |
192 DCHECK(!bubble_view_); | 213 DCHECK(!bubble_view_); |
193 | 214 |
194 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | 215 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
195 init_params->max_height < GetDetailedBubbleMaxHeight()) { | 216 init_params->max_height < GetDetailedBubbleMaxHeight()) { |
196 init_params->max_height = GetDetailedBubbleMaxHeight(); | 217 init_params->max_height = GetDetailedBubbleMaxHeight(); |
197 } | 218 } |
198 | 219 |
199 init_params->delegate = tray_; | 220 init_params->delegate = tray_; |
200 // Place the bubble on same display as this system tray. | 221 // Place the bubble on same display as this system tray if it is not on |
201 init_params->parent_window = tray_->GetBubbleWindowContainer(); | 222 // maximize mode. Otherwise, create an clipping window to hold the system |
223 // bubble. And place the clipping window on the same display as the system | |
224 // tray. | |
225 if (tray_->in_maximize_mode()) { | |
226 if (!clipping_window_) | |
227 clipping_window_ = new aura::Window(nullptr); | |
xiyuan
2017/06/16 17:33:43
When would |clipping_window_| be released?
We pro
minch1
2017/06/16 22:11:51
Done.
| |
228 clipping_window_->Init(ui::LAYER_NOT_DRAWN); | |
229 clipping_window_->layer()->SetMasksToBounds(true); | |
230 clipping_window_->SetBounds(tray_->GetWorkAreaBoundsInScreen()); | |
231 tray_->GetBubbleWindowContainer()->AddChild(clipping_window_); | |
232 clipping_window_->Show(); | |
xiyuan
2017/06/16 17:33:43
Line 228-232 (except line 230 that updates bounds
minch1
2017/06/16 22:11:51
Done.
| |
233 init_params->parent_window = clipping_window_; | |
234 } else { | |
235 init_params->parent_window = tray_->GetBubbleWindowContainer(); | |
236 } | |
237 | |
202 init_params->anchor_view = anchor; | 238 init_params->anchor_view = anchor; |
203 bubble_view_ = new TrayBubbleView(*init_params); | 239 bubble_view_ = new TrayBubbleView(*init_params); |
204 UpdateBottomPadding(); | 240 UpdateBottomPadding(); |
205 bubble_view_->set_adjust_if_offscreen(false); | 241 bubble_view_->set_adjust_if_offscreen(false); |
206 CreateItemViews(login_status); | 242 CreateItemViews(login_status); |
207 | 243 |
208 if (bubble_view_->CanActivate()) { | 244 if (bubble_view_->CanActivate()) { |
209 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 245 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
210 } | 246 } |
211 } | 247 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : | 327 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : |
292 tray_item_view_map_) { | 328 tray_item_view_map_) { |
293 if (pair.second->visible() && | 329 if (pair.second->visible() && |
294 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { | 330 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { |
295 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", | 331 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", |
296 pair.first, SystemTrayItem::UMA_COUNT); | 332 pair.first, SystemTrayItem::UMA_COUNT); |
297 } | 333 } |
298 } | 334 } |
299 } | 335 } |
300 | 336 |
337 void SystemTrayBubble::UpdateBounds(const gfx::Rect& target_bounds, | |
338 bool close_bubble) { | |
339 const int kAnimationDurationMS = 200; | |
340 | |
341 ui::ScopedLayerAnimationSettings settings( | |
342 bubble_view()->GetWidget()->GetNativeView()->layer()->GetAnimator()); | |
343 settings.SetTransitionDuration( | |
344 base::TimeDelta::FromMilliseconds(kAnimationDurationMS)); | |
345 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
346 settings.SetPreemptionStrategy( | |
347 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
348 if (close_bubble) | |
349 settings.AddObserver(new CloseBubbleObserver(this)); | |
350 bubble_view()->GetWidget()->SetBounds(target_bounds); | |
351 } | |
352 | |
301 void SystemTrayBubble::UpdateBottomPadding() { | 353 void SystemTrayBubble::UpdateBottomPadding() { |
302 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) | 354 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) |
303 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); | 355 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); |
304 else | 356 else |
305 bubble_view_->SetBottomPadding(0); | 357 bubble_view_->SetBottomPadding(0); |
306 } | 358 } |
307 | 359 |
308 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 360 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
309 tray_item_view_map_.clear(); | 361 tray_item_view_map_.clear(); |
310 | 362 |
(...skipping 23 matching lines...) Expand all Loading... | |
334 } | 386 } |
335 } | 387 } |
336 | 388 |
337 if (focus_view) { | 389 if (focus_view) { |
338 tray_->ActivateBubble(); | 390 tray_->ActivateBubble(); |
339 focus_view->RequestFocus(); | 391 focus_view->RequestFocus(); |
340 } | 392 } |
341 } | 393 } |
342 | 394 |
343 } // namespace ash | 395 } // namespace ash |
OLD | NEW |