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. | |
tdanderson
2017/06/19 16:19:38
When I build and try out this CL locally, I run in
minch1
2017/06/20 16:45:34
This is because tap elsewhere will dismiss the men
tdanderson
2017/06/20 22:42:20
Thanks, I do not see this crash locally with Patch
| |
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 system_tray_bubble_->Close(); | |
82 delete this; | |
83 } | |
84 | |
85 private: | |
86 SystemTrayBubble* system_tray_bubble_ = nullptr; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(CloseBubbleObserver); | |
89 }; | |
90 | |
71 // SystemTrayBubble | 91 // SystemTrayBubble |
72 | 92 |
73 SystemTrayBubble::SystemTrayBubble( | 93 SystemTrayBubble::SystemTrayBubble( |
74 ash::SystemTray* tray, | 94 ash::SystemTray* tray, |
75 const std::vector<ash::SystemTrayItem*>& items, | 95 const std::vector<ash::SystemTrayItem*>& items, |
76 BubbleType bubble_type) | 96 BubbleType bubble_type) |
77 : tray_(tray), | 97 : tray_(tray), |
78 bubble_view_(nullptr), | 98 bubble_view_(nullptr), |
79 items_(items), | 99 items_(items), |
80 bubble_type_(bubble_type), | 100 bubble_type_(bubble_type), |
81 autoclose_delay_(0) {} | 101 autoclose_delay_(0) {} |
82 | 102 |
83 SystemTrayBubble::~SystemTrayBubble() { | 103 SystemTrayBubble::~SystemTrayBubble() { |
84 DestroyItemViews(); | 104 DestroyItemViews(); |
85 // Reset the host pointer in bubble_view_ in case its destruction is deferred. | 105 // Reset the host pointer in bubble_view_ in case its destruction is deferred. |
86 if (bubble_view_) | 106 if (bubble_view_) |
87 bubble_view_->reset_delegate(); | 107 bubble_view_->reset_delegate(); |
108 if (clipping_window_) | |
tdanderson
2017/06/19 16:19:38
Have you considered making |clipping_window_| a un
minch1
2017/06/20 16:45:34
Done.
| |
109 delete clipping_window_; | |
88 } | 110 } |
89 | 111 |
90 void SystemTrayBubble::UpdateView( | 112 void SystemTrayBubble::UpdateView( |
91 const std::vector<ash::SystemTrayItem*>& items, | 113 const std::vector<ash::SystemTrayItem*>& items, |
92 BubbleType bubble_type) { | 114 BubbleType bubble_type) { |
93 std::unique_ptr<ui::Layer> scoped_layer; | 115 std::unique_ptr<ui::Layer> scoped_layer; |
94 if (bubble_type != bubble_type_) { | 116 if (bubble_type != bubble_type_) { |
95 base::TimeDelta swipe_duration = | 117 base::TimeDelta swipe_duration = |
96 base::TimeDelta::FromMilliseconds(kSwipeDelayMS); | 118 base::TimeDelta::FromMilliseconds(kSwipeDelayMS); |
97 scoped_layer = bubble_view_->RecreateLayer(); | 119 scoped_layer = bubble_view_->RecreateLayer(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 TrayBubbleView::InitParams* init_params) { | 212 TrayBubbleView::InitParams* init_params) { |
191 DCHECK(anchor); | 213 DCHECK(anchor); |
192 DCHECK(!bubble_view_); | 214 DCHECK(!bubble_view_); |
193 | 215 |
194 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | 216 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
195 init_params->max_height < GetDetailedBubbleMaxHeight()) { | 217 init_params->max_height < GetDetailedBubbleMaxHeight()) { |
196 init_params->max_height = GetDetailedBubbleMaxHeight(); | 218 init_params->max_height = GetDetailedBubbleMaxHeight(); |
197 } | 219 } |
198 | 220 |
199 init_params->delegate = tray_; | 221 init_params->delegate = tray_; |
200 // Place the bubble on same display as this system tray. | 222 // Place the bubble on same display as this system tray if it is not on |
201 init_params->parent_window = tray_->GetBubbleWindowContainer(); | 223 // maximize mode. Otherwise, create an clipping window to hold the system |
224 // bubble. And place the clipping window on the same display as the system | |
225 // tray. | |
226 if (tray_->in_maximize_mode()) { | |
227 if (!clipping_window_) { | |
228 clipping_window_ = new aura::Window(nullptr); | |
229 clipping_window_->Init(ui::LAYER_NOT_DRAWN); | |
230 clipping_window_->layer()->SetMasksToBounds(true); | |
231 tray_->GetBubbleWindowContainer()->AddChild(clipping_window_); | |
232 clipping_window_->Show(); | |
233 } | |
234 clipping_window_->SetBounds(tray_->GetWorkAreaBoundsInScreen()); | |
235 init_params->parent_window = clipping_window_; | |
236 } else { | |
237 init_params->parent_window = tray_->GetBubbleWindowContainer(); | |
238 } | |
239 | |
202 init_params->anchor_view = anchor; | 240 init_params->anchor_view = anchor; |
203 bubble_view_ = new TrayBubbleView(*init_params); | 241 bubble_view_ = new TrayBubbleView(*init_params); |
204 UpdateBottomPadding(); | 242 UpdateBottomPadding(); |
205 bubble_view_->set_adjust_if_offscreen(false); | 243 bubble_view_->set_adjust_if_offscreen(false); |
206 CreateItemViews(login_status); | 244 CreateItemViews(login_status); |
207 | 245 |
208 if (bubble_view_->CanActivate()) { | 246 if (bubble_view_->CanActivate()) { |
209 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 247 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
210 } | 248 } |
211 } | 249 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : | 329 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : |
292 tray_item_view_map_) { | 330 tray_item_view_map_) { |
293 if (pair.second->visible() && | 331 if (pair.second->visible() && |
294 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { | 332 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { |
295 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", | 333 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", |
296 pair.first, SystemTrayItem::UMA_COUNT); | 334 pair.first, SystemTrayItem::UMA_COUNT); |
297 } | 335 } |
298 } | 336 } |
299 } | 337 } |
300 | 338 |
339 void SystemTrayBubble::UpdateBounds(const gfx::Rect& target_bounds, | |
340 bool close_bubble) { | |
341 const int kAnimationDurationMS = 200; | |
342 | |
343 ui::ScopedLayerAnimationSettings settings( | |
344 bubble_view()->GetWidget()->GetNativeView()->layer()->GetAnimator()); | |
345 settings.SetTransitionDuration( | |
346 base::TimeDelta::FromMilliseconds(kAnimationDurationMS)); | |
347 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
348 settings.SetPreemptionStrategy( | |
349 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
350 if (close_bubble) | |
351 settings.AddObserver(new CloseBubbleObserver(this)); | |
352 bubble_view()->GetWidget()->SetBounds(target_bounds); | |
353 } | |
354 | |
301 void SystemTrayBubble::UpdateBottomPadding() { | 355 void SystemTrayBubble::UpdateBottomPadding() { |
302 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) | 356 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) |
303 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); | 357 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); |
304 else | 358 else |
305 bubble_view_->SetBottomPadding(0); | 359 bubble_view_->SetBottomPadding(0); |
306 } | 360 } |
307 | 361 |
308 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 362 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
309 tray_item_view_map_.clear(); | 363 tray_item_view_map_.clear(); |
310 | 364 |
(...skipping 23 matching lines...) Expand all Loading... | |
334 } | 388 } |
335 } | 389 } |
336 | 390 |
337 if (focus_view) { | 391 if (focus_view) { |
338 tray_->ActivateBubble(); | 392 tray_->ActivateBubble(); |
339 focus_view->RequestFocus(); | 393 focus_view->RequestFocus(); |
340 } | 394 } |
341 } | 395 } |
342 | 396 |
343 } // namespace ash | 397 } // namespace ash |
OLD | NEW |