| 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/common/shell_window_ids.h" |
| 7 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 8 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
| 8 #include "ash/wm/window_animations.h" | 9 #include "ash/common/wm_lookup.h" |
| 9 #include "ash/wm/window_util.h" | 10 #include "ash/common/wm_root_window_controller.h" |
| 11 #include "ash/common/wm_window.h" |
| 12 #include "ash/common/wm_window_observer.h" |
| 10 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 11 #include "ui/aura/window.h" | |
| 12 #include "ui/aura/window_observer.h" | |
| 13 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
| 14 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 15 #include "ui/views/background.h" | 16 #include "ui/views/background.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 #include "ui/wm/core/window_animations.h" | 18 #include "ui/wm/core/window_animations.h" |
| 18 #include "ui/wm/core/window_util.h" | 19 #include "ui/wm/core/window_util.h" |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // The opacity of the backdrop. | 24 // The opacity of the backdrop. |
| 24 const float kBackdropOpacity = 0.5f; | 25 const float kBackdropOpacity = 0.5f; |
| 25 | 26 |
| 26 } // namespace | 27 } // namespace |
| 27 | 28 |
| 28 class WorkspaceBackdropDelegate::WindowObserverImpl | 29 class WorkspaceBackdropDelegate::WindowObserverImpl : public WmWindowObserver { |
| 29 : public aura::WindowObserver { | |
| 30 public: | 30 public: |
| 31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate) | 31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate) |
| 32 : delegate_(delegate) {} | 32 : delegate_(delegate) {} |
| 33 ~WindowObserverImpl() override {} | 33 ~WindowObserverImpl() override {} |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // WindowObserver overrides: | 36 // WmWindowObserver overrides: |
| 37 void OnWindowBoundsChanged(aura::Window* window, | 37 void OnWindowBoundsChanged(WmWindow* window, |
| 38 const gfx::Rect& old_bounds, | 38 const gfx::Rect& old_bounds, |
| 39 const gfx::Rect& new_bounds) override { | 39 const gfx::Rect& new_bounds) override { |
| 40 // The container size has changed and the layer needs to be adapt to it. | 40 // The container size has changed and the layer needs to be adapt to it. |
| 41 delegate_->AdjustToContainerBounds(); | 41 delegate_->AdjustToContainerBounds(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 WorkspaceBackdropDelegate* delegate_; | 44 WorkspaceBackdropDelegate* delegate_; |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl); | 46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(aura::Window* container) | 49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container) |
| 50 : container_observer_(new WindowObserverImpl(this)), | 50 : container_observer_(new WindowObserverImpl(this)), |
| 51 background_(nullptr), | |
| 52 container_(container), | 51 container_(container), |
| 53 in_restacking_(false) { | 52 in_restacking_(false) { |
| 54 background_ = new views::Widget; | 53 background_ = new views::Widget; |
| 55 views::Widget::InitParams params( | 54 views::Widget::InitParams params( |
| 56 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 55 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 57 params.parent = container_; | |
| 58 params.bounds = container_->GetBoundsInScreen(); | 56 params.bounds = container_->GetBoundsInScreen(); |
| 59 params.layer_type = ui::LAYER_SOLID_COLOR; | 57 params.layer_type = ui::LAYER_SOLID_COLOR; |
| 58 params.name = "WorkspaceBackdropDelegate"; |
| 60 // To disallow the MRU list from picking this window up it should not be | 59 // To disallow the MRU list from picking this window up it should not be |
| 61 // activateable. | 60 // activateable. |
| 62 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 61 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 62 DCHECK_NE(kShellWindowId_Invalid, container_->GetShellWindowId()); |
| 63 container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
| 64 background_, container_->GetShellWindowId(), ¶ms); |
| 63 background_->Init(params); | 65 background_->Init(params); |
| 66 background_window_ = WmLookup::Get()->GetWindowForWidget(background_); |
| 64 // Do not use the animation system. We don't want the bounds animation and | 67 // Do not use the animation system. We don't want the bounds animation and |
| 65 // opacity needs to get set to |kBackdropOpacity|. | 68 // opacity needs to get set to |kBackdropOpacity|. |
| 66 ::wm::SetWindowVisibilityAnimationTransition(background_->GetNativeView(), | 69 background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); |
| 67 ::wm::ANIMATE_NONE); | 70 background_window_->GetLayer()->SetColor(SK_ColorBLACK); |
| 68 background_->GetNativeView()->SetName("WorkspaceBackdropDelegate"); | |
| 69 background_->GetNativeView()->layer()->SetColor(SK_ColorBLACK); | |
| 70 // Make sure that the layer covers visibly everything - including the shelf. | 71 // Make sure that the layer covers visibly everything - including the shelf. |
| 71 background_->GetNativeView()->layer()->SetBounds(params.bounds); | 72 background_window_->GetLayer()->SetBounds(params.bounds); |
| 73 DCHECK(background_window_->GetBounds() == params.bounds); |
| 72 Show(); | 74 Show(); |
| 73 RestackBackdrop(); | 75 RestackBackdrop(); |
| 74 container_->AddObserver(container_observer_.get()); | 76 container_->AddObserver(container_observer_.get()); |
| 75 } | 77 } |
| 76 | 78 |
| 77 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { | 79 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { |
| 78 container_->RemoveObserver(container_observer_.get()); | 80 container_->RemoveObserver(container_observer_.get()); |
| 81 // TODO: animations won't work right with mus: http://crbug.com/548396. |
| 79 ::wm::ScopedHidingAnimationSettings hiding_settings( | 82 ::wm::ScopedHidingAnimationSettings hiding_settings( |
| 80 background_->GetNativeView()); | 83 background_->GetNativeView()); |
| 81 background_->Close(); | 84 background_->Close(); |
| 82 background_->GetNativeView()->layer()->SetOpacity(0.0f); | 85 background_window_->GetLayer()->SetOpacity(0.0f); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) { | 88 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) { |
| 86 RestackBackdrop(); | 89 RestackBackdrop(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) { | 92 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) { |
| 90 RestackBackdrop(); | 93 RestackBackdrop(); |
| 91 } | 94 } |
| 92 | 95 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 | 110 |
| 108 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() { | 111 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() { |
| 109 AdjustToContainerBounds(); | 112 AdjustToContainerBounds(); |
| 110 } | 113 } |
| 111 | 114 |
| 112 void WorkspaceBackdropDelegate::RestackBackdrop() { | 115 void WorkspaceBackdropDelegate::RestackBackdrop() { |
| 113 // Avoid recursive calls. | 116 // Avoid recursive calls. |
| 114 if (in_restacking_) | 117 if (in_restacking_) |
| 115 return; | 118 return; |
| 116 | 119 |
| 117 aura::Window* window = GetCurrentTopWindow(); | 120 WmWindow* window = GetCurrentTopWindow(); |
| 118 if (!window) { | 121 if (!window) { |
| 119 // Hide backdrop since no suitable window was found. | 122 // Hide backdrop since no suitable window was found. |
| 120 background_->Hide(); | 123 background_->Hide(); |
| 121 return; | 124 return; |
| 122 } | 125 } |
| 123 if (window == background_->GetNativeWindow() && background_->IsVisible()) { | 126 if (window == background_window_ && background_->IsVisible()) |
| 124 return; | 127 return; |
| 125 } | 128 if (window->GetRootWindow() != background_window_->GetRootWindow()) |
| 126 if (window->GetRootWindow() != | |
| 127 background_->GetNativeWindow()->GetRootWindow()) { | |
| 128 return; | 129 return; |
| 129 } | |
| 130 // We are changing the order of windows which will cause recursion. | 130 // We are changing the order of windows which will cause recursion. |
| 131 base::AutoReset<bool> lock(&in_restacking_, true); | 131 base::AutoReset<bool> lock(&in_restacking_, true); |
| 132 if (!background_->IsVisible()) | 132 if (!background_->IsVisible()) |
| 133 Show(); | 133 Show(); |
| 134 // Since the backdrop needs to be immediately behind the window and the | 134 // Since the backdrop needs to be immediately behind the window and the |
| 135 // stacking functions only guarantee a "it's above or below", we need | 135 // stacking functions only guarantee a "it's above or below", we need |
| 136 // to re-arrange the two windows twice. | 136 // to re-arrange the two windows twice. |
| 137 container_->StackChildAbove(background_->GetNativeView(), window); | 137 container_->StackChildAbove(background_window_, window); |
| 138 container_->StackChildAbove(window, background_->GetNativeView()); | 138 container_->StackChildAbove(window, background_window_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 aura::Window* WorkspaceBackdropDelegate::GetCurrentTopWindow() { | 141 WmWindow* WorkspaceBackdropDelegate::GetCurrentTopWindow() { |
| 142 const aura::Window::Windows& windows = container_->children(); | 142 const WmWindow::Windows windows = container_->GetChildren(); |
| 143 for (aura::Window::Windows::const_reverse_iterator window_iter = | 143 for (auto window_iter = windows.rbegin(); window_iter != windows.rend(); |
| 144 windows.rbegin(); | 144 ++window_iter) { |
| 145 window_iter != windows.rend(); ++window_iter) { | 145 WmWindow* window = *window_iter; |
| 146 aura::Window* window = *window_iter; | 146 if (window->GetTargetVisibility() && |
| 147 if (window->TargetVisibility() && | 147 window->GetType() == ui::wm::WINDOW_TYPE_NORMAL && |
| 148 window->type() == ui::wm::WINDOW_TYPE_NORMAL && | 148 window->CanActivate()) |
| 149 ash::wm::CanActivateWindow(window)) | |
| 150 return window; | 149 return window; |
| 151 } | 150 } |
| 152 return NULL; | 151 return nullptr; |
| 153 } | 152 } |
| 154 | 153 |
| 155 void WorkspaceBackdropDelegate::AdjustToContainerBounds() { | 154 void WorkspaceBackdropDelegate::AdjustToContainerBounds() { |
| 156 // Cover the entire container window. | 155 // Cover the entire container window. |
| 157 gfx::Rect target_rect(gfx::Point(0, 0), container_->bounds().size()); | 156 gfx::Rect target_rect(gfx::Point(0, 0), container_->GetBounds().size()); |
| 158 if (target_rect != background_->GetNativeWindow()->bounds()) { | 157 if (target_rect != background_window_->GetBounds()) { |
| 158 // TODO: this won't work right with mus: http://crbug.com/548396. |
| 159 // This needs to be instant. | 159 // This needs to be instant. |
| 160 ui::ScopedLayerAnimationSettings settings( | 160 ui::ScopedLayerAnimationSettings settings( |
| 161 background_->GetNativeView()->layer()->GetAnimator()); | 161 background_window_->GetLayer()->GetAnimator()); |
| 162 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0)); | 162 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0)); |
| 163 background_->GetNativeWindow()->SetBounds(target_rect); | 163 background_window_->SetBounds(target_rect); |
| 164 if (!background_->IsVisible()) | 164 if (!background_->IsVisible()) |
| 165 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity); | 165 background_window_->GetLayer()->SetOpacity(kBackdropOpacity); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 void WorkspaceBackdropDelegate::Show() { | 169 void WorkspaceBackdropDelegate::Show() { |
| 170 background_->GetNativeView()->layer()->SetOpacity(0.0f); | 170 background_window_->GetLayer()->SetOpacity(0.0f); |
| 171 background_->Show(); | 171 background_->Show(); |
| 172 ui::ScopedLayerAnimationSettings settings( | 172 ui::ScopedLayerAnimationSettings settings( |
| 173 background_->GetNativeView()->layer()->GetAnimator()); | 173 background_window_->GetLayer()->GetAnimator()); |
| 174 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity); | 174 background_window_->GetLayer()->SetOpacity(kBackdropOpacity); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace ash | 177 } // namespace ash |
| OLD | NEW |