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" |
18 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
21 #include "ui/compositor/layer_animation_observer.h" | 22 #include "ui/compositor/layer_animation_observer.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
23 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
24 #include "ui/views/border.h" | 25 #include "ui/views/border.h" |
25 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 62 } |
62 | 63 |
63 private: | 64 private: |
64 std::unique_ptr<ui::Layer> layer_; | 65 std::unique_ptr<ui::Layer> layer_; |
65 | 66 |
66 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); | 67 DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); |
67 }; | 68 }; |
68 | 69 |
69 } // namespace | 70 } // namespace |
70 | 71 |
| 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 |
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 (Shell::Get() |
| 226 ->maximize_mode_controller() |
| 227 ->IsMaximizeModeWindowManagerEnabled()) { |
| 228 if (!clipping_window_.get()) { |
| 229 clipping_window_ = |
| 230 std::unique_ptr<aura::Window>(new aura::Window(nullptr)); |
| 231 clipping_window_->Init(ui::LAYER_NOT_DRAWN); |
| 232 clipping_window_->layer()->SetMasksToBounds(true); |
| 233 tray_->GetBubbleWindowContainer()->AddChild(clipping_window_.get()); |
| 234 clipping_window_->Show(); |
| 235 } |
| 236 clipping_window_->SetBounds(tray_->GetWorkAreaBoundsInScreen()); |
| 237 init_params->parent_window = clipping_window_.get(); |
| 238 } else { |
| 239 init_params->parent_window = tray_->GetBubbleWindowContainer(); |
| 240 } |
| 241 |
202 init_params->anchor_view = anchor; | 242 init_params->anchor_view = anchor; |
203 bubble_view_ = new TrayBubbleView(*init_params); | 243 bubble_view_ = new TrayBubbleView(*init_params); |
204 UpdateBottomPadding(); | 244 UpdateBottomPadding(); |
205 bubble_view_->set_adjust_if_offscreen(false); | 245 bubble_view_->set_adjust_if_offscreen(false); |
206 CreateItemViews(login_status); | 246 CreateItemViews(login_status); |
207 | 247 |
208 if (bubble_view_->CanActivate()) { | 248 if (bubble_view_->CanActivate()) { |
209 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 249 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
210 } | 250 } |
211 } | 251 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : | 331 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : |
292 tray_item_view_map_) { | 332 tray_item_view_map_) { |
293 if (pair.second->visible() && | 333 if (pair.second->visible() && |
294 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { | 334 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { |
295 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", | 335 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", |
296 pair.first, SystemTrayItem::UMA_COUNT); | 336 pair.first, SystemTrayItem::UMA_COUNT); |
297 } | 337 } |
298 } | 338 } |
299 } | 339 } |
300 | 340 |
| 341 void SystemTrayBubble::AnimateToTargetBounds(const gfx::Rect& target_bounds, |
| 342 bool close_bubble) { |
| 343 const int kAnimationDurationMS = 200; |
| 344 |
| 345 ui::ScopedLayerAnimationSettings settings( |
| 346 bubble_view()->GetWidget()->GetNativeView()->layer()->GetAnimator()); |
| 347 settings.SetTransitionDuration( |
| 348 base::TimeDelta::FromMilliseconds(kAnimationDurationMS)); |
| 349 settings.SetTweenType(gfx::Tween::EASE_OUT); |
| 350 settings.SetPreemptionStrategy( |
| 351 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 352 if (close_bubble) |
| 353 settings.AddObserver(new CloseBubbleObserver(this)); |
| 354 bubble_view()->GetWidget()->SetBounds(target_bounds); |
| 355 } |
| 356 |
301 void SystemTrayBubble::UpdateBottomPadding() { | 357 void SystemTrayBubble::UpdateBottomPadding() { |
302 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) | 358 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) |
303 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); | 359 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); |
304 else | 360 else |
305 bubble_view_->SetBottomPadding(0); | 361 bubble_view_->SetBottomPadding(0); |
306 } | 362 } |
307 | 363 |
308 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 364 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
309 tray_item_view_map_.clear(); | 365 tray_item_view_map_.clear(); |
310 | 366 |
(...skipping 23 matching lines...) Expand all Loading... |
334 } | 390 } |
335 } | 391 } |
336 | 392 |
337 if (focus_view) { | 393 if (focus_view) { |
338 tray_->ActivateBubble(); | 394 tray_->ActivateBubble(); |
339 focus_view->RequestFocus(); | 395 focus_view->RequestFocus(); |
340 } | 396 } |
341 } | 397 } |
342 | 398 |
343 } // namespace ash | 399 } // namespace ash |
OLD | NEW |