| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/wm/window_dimmer.h" | 5 #include "ash/common/wm/window_dimmer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/common/wm_window.h" | 10 #include "ash/common/wm_window.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/wm/core/visibility_controller.h" |
| 14 #include "ui/wm/core/window_animations.h" | 15 #include "ui/wm/core/window_animations.h" |
| 15 | 16 |
| 16 namespace ash { | 17 namespace ash { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const int kDefaultDimAnimationDurationMs = 200; | 20 const int kDefaultDimAnimationDurationMs = 200; |
| 20 | 21 |
| 21 const float kDefaultDimOpacity = 0.5f; | 22 const float kDefaultDimOpacity = 0.5f; |
| 22 | 23 |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 WindowDimmer::WindowDimmer(WmWindow* parent) | 26 WindowDimmer::WindowDimmer(aura::Window* parent) |
| 26 : parent_(parent), | 27 : parent_(parent), |
| 27 window_(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, | 28 window_(WmShell::Get() |
| 28 ui::LAYER_SOLID_COLOR)) { | 29 ->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, ui::LAYER_SOLID_COLOR) |
| 29 window_->SetVisibilityChangesAnimated(); | 30 ->aura_window()) { |
| 30 window_->SetVisibilityAnimationType( | 31 ::wm::SetWindowVisibilityChangesAnimated(window_.get()); |
| 31 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 32 ::wm::SetWindowVisibilityAnimationType( |
| 32 window_->SetVisibilityAnimationDuration( | 33 window_.get(), ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 34 ::wm::SetWindowVisibilityAnimationDuration( |
| 35 window_.get(), |
| 33 base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs)); | 36 base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs)); |
| 34 window_->aura_window()->AddObserver(this); | 37 window_->AddObserver(this); |
| 35 | 38 |
| 36 SetDimOpacity(kDefaultDimOpacity); | 39 SetDimOpacity(kDefaultDimOpacity); |
| 37 | 40 |
| 38 parent->AddChild(window_); | 41 parent->AddChild(window_.get()); |
| 39 parent->aura_window()->AddObserver(this); | 42 parent->AddObserver(this); |
| 40 parent->StackChildAtTop(window_); | 43 parent->StackChildAtTop(window_.get()); |
| 41 | 44 |
| 42 window_->SetBounds(gfx::Rect(parent_->GetBounds().size())); | 45 window_->SetBounds(gfx::Rect(parent_->bounds().size())); |
| 43 } | 46 } |
| 44 | 47 |
| 45 WindowDimmer::~WindowDimmer() { | 48 WindowDimmer::~WindowDimmer() { |
| 46 if (parent_) | 49 if (parent_) |
| 47 parent_->aura_window()->RemoveObserver(this); | 50 parent_->RemoveObserver(this); |
| 48 if (window_) { | 51 if (window_) { |
| 49 window_->aura_window()->RemoveObserver(this); | 52 window_->RemoveObserver(this); |
| 50 window_->Destroy(); | 53 window_.reset(); |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 | 56 |
| 54 void WindowDimmer::SetDimOpacity(float target_opacity) { | 57 void WindowDimmer::SetDimOpacity(float target_opacity) { |
| 55 DCHECK(window_); | 58 DCHECK(window_); |
| 56 window_->GetLayer()->SetColor( | 59 window_->layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity)); |
| 57 SkColorSetA(SK_ColorBLACK, 255 * target_opacity)); | |
| 58 } | 60 } |
| 59 | 61 |
| 60 void WindowDimmer::OnWindowBoundsChanged(aura::Window* window, | 62 void WindowDimmer::OnWindowBoundsChanged(aura::Window* window, |
| 61 const gfx::Rect& old_bounds, | 63 const gfx::Rect& old_bounds, |
| 62 const gfx::Rect& new_bounds) { | 64 const gfx::Rect& new_bounds) { |
| 63 if (WmWindow::Get(window) == parent_) | 65 if (window == parent_) |
| 64 window_->SetBounds(gfx::Rect(new_bounds.size())); | 66 window_->SetBounds(gfx::Rect(new_bounds.size())); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void WindowDimmer::OnWindowDestroying(aura::Window* window) { | 69 void WindowDimmer::OnWindowDestroying(aura::Window* window) { |
| 68 if (WmWindow::Get(window) == parent_) { | 70 if (window == parent_) { |
| 69 parent_->aura_window()->RemoveObserver(this); | 71 parent_->RemoveObserver(this); |
| 70 parent_ = nullptr; | 72 parent_ = nullptr; |
| 71 } else { | 73 } else { |
| 72 DCHECK_EQ(window_, WmWindow::Get(window)); | 74 DCHECK_EQ(window_.get(), window); |
| 73 window_->aura_window()->RemoveObserver(this); | 75 window_->RemoveObserver(this); |
| 74 window_ = nullptr; | 76 window_.release(); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 void WindowDimmer::OnWindowHierarchyChanging( | 80 void WindowDimmer::OnWindowHierarchyChanging( |
| 79 const HierarchyChangeParams& params) { | 81 const HierarchyChangeParams& params) { |
| 80 if (WmWindow::Get(params.receiver) == window_ && | 82 if (params.receiver == window_.get() && params.target == params.receiver) { |
| 81 params.target == params.receiver) { | |
| 82 // This may happen on a display change or some unexpected condition. Hide | 83 // This may happen on a display change or some unexpected condition. Hide |
| 83 // the window to ensure it isn't obscuring the wrong thing. | 84 // the window to ensure it isn't obscuring the wrong thing. |
| 84 window_->Hide(); | 85 window_->Hide(); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace ash | 89 } // namespace ash |
| OLD | NEW |