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