OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/maximize_mode/workspace_backdrop_delegate.h" | 5 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" |
6 | 6 |
7 #include "ash/wm/window_animations.h" | 7 #include "ash/wm/window_animations.h" |
8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
| 9 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
9 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
10 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_observer.h" |
11 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
12 #include "ui/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
13 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
14 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
15 #include "ui/wm/core/window_animations.h" | 17 #include "ui/wm/core/window_animations.h" |
16 #include "ui/wm/core/window_util.h" | 18 #include "ui/wm/core/window_util.h" |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 namespace { | 21 namespace { |
20 | 22 |
21 // The opacity of the backdrop. | 23 // The opacity of the backdrop. |
22 const float kBackdropOpacity = 0.5f; | 24 const float kBackdropOpacity = 0.5f; |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
| 28 class WorkspaceBackdropDelegate::WindowObserverImpl |
| 29 : public aura::WindowObserver { |
| 30 public: |
| 31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate) |
| 32 : delegate_(delegate) {} |
| 33 ~WindowObserverImpl() override {} |
| 34 |
| 35 private: |
| 36 // WindowObserver overrides: |
| 37 void OnWindowBoundsChanged(aura::Window* window, |
| 38 const gfx::Rect& old_bounds, |
| 39 const gfx::Rect& new_bounds) override { |
| 40 // The container size has changed and the layer needs to be adapt to it. |
| 41 delegate_->AdjustToContainerBounds(); |
| 42 } |
| 43 |
| 44 WorkspaceBackdropDelegate* delegate_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl); |
| 47 }; |
| 48 |
26 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(aura::Window* container) | 49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(aura::Window* container) |
27 : background_(NULL), | 50 : container_observer_(new WindowObserverImpl(this)), |
| 51 background_(nullptr), |
28 container_(container), | 52 container_(container), |
29 in_restacking_(false) { | 53 in_restacking_(false) { |
30 background_ = new views::Widget; | 54 background_ = new views::Widget; |
31 views::Widget::InitParams params( | 55 views::Widget::InitParams params( |
32 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 56 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
33 params.parent = container_; | 57 params.parent = container_; |
34 params.bounds = container_->GetBoundsInScreen(); | 58 params.bounds = container_->GetBoundsInScreen(); |
35 params.layer_type = ui::LAYER_SOLID_COLOR; | 59 params.layer_type = ui::LAYER_SOLID_COLOR; |
36 // To disallow the MRU list from picking this window up it should not be | 60 // To disallow the MRU list from picking this window up it should not be |
37 // activateable. | 61 // activateable. |
38 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 62 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
39 background_->Init(params); | 63 background_->Init(params); |
40 // Do not use the animation system. We don't want the bounds animation and | 64 // Do not use the animation system. We don't want the bounds animation and |
41 // opacity needs to get set to |kBackdropOpacity|. | 65 // opacity needs to get set to |kBackdropOpacity|. |
42 ::wm::SetWindowVisibilityAnimationTransition( | 66 ::wm::SetWindowVisibilityAnimationTransition( |
43 background_->GetNativeView(), | 67 background_->GetNativeView(), |
44 ::wm::ANIMATE_NONE); | 68 ::wm::ANIMATE_NONE); |
45 background_->GetNativeView()->SetName("WorkspaceBackdropDelegate"); | 69 background_->GetNativeView()->SetName("WorkspaceBackdropDelegate"); |
46 background_->GetNativeView()->layer()->SetColor(SK_ColorBLACK); | 70 background_->GetNativeView()->layer()->SetColor(SK_ColorBLACK); |
47 // Make sure that the layer covers visibly everything - including the shelf. | 71 // Make sure that the layer covers visibly everything - including the shelf. |
48 background_->GetNativeView()->layer()->SetBounds(params.bounds); | 72 background_->GetNativeView()->layer()->SetBounds(params.bounds); |
49 Show(); | 73 Show(); |
50 RestackBackdrop(); | 74 RestackBackdrop(); |
51 container_->AddObserver(this); | 75 container_->AddObserver(container_observer_.get()); |
52 } | 76 } |
53 | 77 |
54 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { | 78 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { |
55 container_->RemoveObserver(this); | 79 container_->RemoveObserver(container_observer_.get()); |
56 ::wm::ScopedHidingAnimationSettings hiding_settings( | 80 ::wm::ScopedHidingAnimationSettings hiding_settings( |
57 background_->GetNativeView()); | 81 background_->GetNativeView()); |
58 background_->Close(); | 82 background_->Close(); |
59 background_->GetNativeView()->layer()->SetOpacity(0.0f); | 83 background_->GetNativeView()->layer()->SetOpacity(0.0f); |
60 } | 84 } |
61 | 85 |
62 void WorkspaceBackdropDelegate::OnWindowBoundsChanged( | 86 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(wm::WmWindow* child) { |
63 aura::Window* window, | |
64 const gfx::Rect& old_bounds, | |
65 const gfx::Rect& new_bounds) { | |
66 // The container size has changed and the layer needs to be adapt to it. | |
67 AdjustToContainerBounds(); | |
68 } | |
69 | |
70 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(aura::Window* child) { | |
71 RestackBackdrop(); | 87 RestackBackdrop(); |
72 } | 88 } |
73 | 89 |
74 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(aura::Window* child) { | 90 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(wm::WmWindow* child) { |
75 RestackBackdrop(); | 91 RestackBackdrop(); |
76 } | 92 } |
77 | 93 |
78 void WorkspaceBackdropDelegate::OnChildWindowVisibilityChanged( | 94 void WorkspaceBackdropDelegate::OnChildWindowVisibilityChanged( |
79 aura::Window* child, | 95 wm::WmWindow* child, |
80 bool visible) { | 96 bool visible) { |
81 RestackBackdrop(); | 97 RestackBackdrop(); |
82 } | 98 } |
83 | 99 |
84 void WorkspaceBackdropDelegate::OnWindowStackingChanged(aura::Window* window) { | 100 void WorkspaceBackdropDelegate::OnWindowStackingChanged(wm::WmWindow* window) { |
85 RestackBackdrop(); | 101 RestackBackdrop(); |
86 } | 102 } |
87 | 103 |
88 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange( | 104 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange( |
89 wm::WindowState* window_state, | 105 wm::WindowState* window_state, |
90 wm::WindowStateType old_type) { | 106 wm::WindowStateType old_type) { |
91 RestackBackdrop(); | 107 RestackBackdrop(); |
92 } | 108 } |
93 | 109 |
94 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() { | 110 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 171 |
156 void WorkspaceBackdropDelegate::Show() { | 172 void WorkspaceBackdropDelegate::Show() { |
157 background_->GetNativeView()->layer()->SetOpacity(0.0f); | 173 background_->GetNativeView()->layer()->SetOpacity(0.0f); |
158 background_->Show(); | 174 background_->Show(); |
159 ui::ScopedLayerAnimationSettings settings( | 175 ui::ScopedLayerAnimationSettings settings( |
160 background_->GetNativeView()->layer()->GetAnimator()); | 176 background_->GetNativeView()->layer()->GetAnimator()); |
161 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity); | 177 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity); |
162 } | 178 } |
163 | 179 |
164 } // namespace ash | 180 } // namespace ash |
OLD | NEW |