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" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/shell_port.h" | 12 #include "ash/shell_port.h" |
13 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
15 #include "ash/system/tray/system_tray_item.h" | 15 #include "ash/system/tray/system_tray_item.h" |
16 #include "ash/system/tray/tray_bubble_wrapper.h" | 16 #include "ash/system/tray/tray_bubble_wrapper.h" |
17 #include "ash/system/tray/tray_constants.h" | 17 #include "ash/system/tray/tray_constants.h" |
18 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
19 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
21 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
22 #include "ui/compositor/layer_animation_observer.h" | 21 #include "ui/compositor/layer_animation_observer.h" |
23 #include "ui/compositor/scoped_layer_animation_settings.h" | 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
24 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
25 #include "ui/views/border.h" | 24 #include "ui/views/border.h" |
26 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
27 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
28 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 } | 61 } |
63 | 62 |
64 private: | 63 private: |
65 std::unique_ptr<ui::Layer> layer_; | 64 std::unique_ptr<ui::Layer> layer_; |
66 | 65 |
67 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); | 66 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); |
68 }; | 67 }; |
69 | 68 |
70 } // namespace | 69 } // namespace |
71 | 70 |
72 // CloseBubbleObserver is used to delay closing the system tray bubble until the | |
73 // animation completes. | |
74 class CloseBubbleObserver : public ui::ImplicitAnimationObserver { | |
75 public: | |
76 explicit CloseBubbleObserver(SystemTrayBubble* system_tray_bubble) | |
77 : system_tray_bubble_(system_tray_bubble) {} | |
78 | |
79 ~CloseBubbleObserver() override {} | |
80 | |
81 void OnImplicitAnimationsCompleted() override { | |
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 | |
92 // SystemTrayBubble | 71 // SystemTrayBubble |
93 | 72 |
94 SystemTrayBubble::SystemTrayBubble( | 73 SystemTrayBubble::SystemTrayBubble( |
95 ash::SystemTray* tray, | 74 ash::SystemTray* tray, |
96 const std::vector<ash::SystemTrayItem*>& items, | 75 const std::vector<ash::SystemTrayItem*>& items, |
97 BubbleType bubble_type) | 76 BubbleType bubble_type) |
98 : tray_(tray), | 77 : tray_(tray), |
99 bubble_view_(nullptr), | 78 bubble_view_(nullptr), |
100 items_(items), | 79 items_(items), |
101 bubble_type_(bubble_type), | 80 bubble_type_(bubble_type), |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 TrayBubbleView::InitParams* init_params) { | 193 TrayBubbleView::InitParams* init_params) { |
215 DCHECK(anchor); | 194 DCHECK(anchor); |
216 DCHECK(!bubble_view_); | 195 DCHECK(!bubble_view_); |
217 | 196 |
218 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | 197 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
219 init_params->max_height < GetDetailedBubbleMaxHeight()) { | 198 init_params->max_height < GetDetailedBubbleMaxHeight()) { |
220 init_params->max_height = GetDetailedBubbleMaxHeight(); | 199 init_params->max_height = GetDetailedBubbleMaxHeight(); |
221 } | 200 } |
222 | 201 |
223 init_params->delegate = tray_; | 202 init_params->delegate = tray_; |
224 // Place the bubble on same display as this system tray if it is not on | 203 // Place the bubble on same display as this system tray if it is not on |
msw
2017/07/12 05:04:51
Update this comment here and move some relevant bi
minch1
2017/07/13 19:10:35
Done.
| |
225 // maximize mode. Otherwise, create an clipping window to hold the system | 204 // maximize mode. Otherwise, create an clipping window to hold the system |
226 // bubble. And place the clipping window on the same display as the system | 205 // bubble. And place the clipping window on the same display as the system |
227 // tray. | 206 // tray. |
228 if (Shell::Get() | 207 init_params->parent_window = tray_->GetBubbleWindowContainer(); |
229 ->maximize_mode_controller() | |
230 ->IsMaximizeModeWindowManagerEnabled()) { | |
231 if (!clipping_window_.get()) { | |
232 clipping_window_ = | |
233 std::unique_ptr<aura::Window>(new aura::Window(nullptr)); | |
234 clipping_window_->Init(ui::LAYER_NOT_DRAWN); | |
235 clipping_window_->layer()->SetMasksToBounds(true); | |
236 tray_->GetBubbleWindowContainer()->AddChild(clipping_window_.get()); | |
237 clipping_window_->Show(); | |
238 } | |
239 clipping_window_->SetBounds(tray_->GetWorkAreaBoundsInScreen()); | |
240 init_params->parent_window = clipping_window_.get(); | |
241 } else { | |
242 init_params->parent_window = tray_->GetBubbleWindowContainer(); | |
243 } | |
244 | 208 |
245 init_params->anchor_view = anchor; | 209 init_params->anchor_view = anchor; |
246 bubble_view_ = new TrayBubbleView(*init_params); | 210 bubble_view_ = new TrayBubbleView(*init_params); |
247 UpdateBottomPadding(); | 211 UpdateBottomPadding(); |
248 bubble_view_->set_adjust_if_offscreen(false); | 212 bubble_view_->set_adjust_if_offscreen(false); |
249 CreateItemViews(login_status); | 213 CreateItemViews(login_status); |
250 | 214 |
251 if (bubble_view_->CanActivate()) { | 215 if (bubble_view_->CanActivate()) { |
252 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 216 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
253 } | 217 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : | 287 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : |
324 tray_item_view_map_) { | 288 tray_item_view_map_) { |
325 if (pair.second->visible() && | 289 if (pair.second->visible() && |
326 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { | 290 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { |
327 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", | 291 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", |
328 pair.first, SystemTrayItem::UMA_COUNT); | 292 pair.first, SystemTrayItem::UMA_COUNT); |
329 } | 293 } |
330 } | 294 } |
331 } | 295 } |
332 | 296 |
333 void SystemTrayBubble::AnimateToTargetBounds(const gfx::Rect& target_bounds, | |
334 bool close_bubble) { | |
335 const int kAnimationDurationMS = 200; | |
336 | |
337 ui::ScopedLayerAnimationSettings settings( | |
338 bubble_view()->GetWidget()->GetNativeView()->layer()->GetAnimator()); | |
339 settings.SetTransitionDuration( | |
340 base::TimeDelta::FromMilliseconds(kAnimationDurationMS)); | |
341 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
342 settings.SetPreemptionStrategy( | |
343 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
344 if (close_bubble) | |
345 settings.AddObserver(new CloseBubbleObserver(this)); | |
346 bubble_view()->GetWidget()->SetBounds(target_bounds); | |
347 } | |
348 | |
349 void SystemTrayBubble::UpdateBottomPadding() { | 297 void SystemTrayBubble::UpdateBottomPadding() { |
350 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) | 298 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) |
351 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); | 299 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); |
352 else | 300 else |
353 bubble_view_->SetBottomPadding(0); | 301 bubble_view_->SetBottomPadding(0); |
354 } | 302 } |
355 | 303 |
356 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 304 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
357 tray_item_view_map_.clear(); | 305 tray_item_view_map_.clear(); |
358 | 306 |
(...skipping 23 matching lines...) Expand all Loading... | |
382 } | 330 } |
383 } | 331 } |
384 | 332 |
385 if (focus_view) { | 333 if (focus_view) { |
386 tray_->ActivateBubble(); | 334 tray_->ActivateBubble(); |
387 focus_view->RequestFocus(); | 335 focus_view->RequestFocus(); |
388 } | 336 } |
389 } | 337 } |
390 | 338 |
391 } // namespace ash | 339 } // namespace ash |
OLD | NEW |