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