OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/window_mirror_view.h" | 5 #include "ash/wm/window_mirror_view.h" |
6 | 6 |
7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
8 #include "ash/common/wm/forwarding_layer_delegate.h" | 8 #include "ash/common/wm/forwarding_layer_delegate.h" |
9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
10 #include "ash/wm/window_state_aura.h" | 10 #include "ash/wm/window_state_aura.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 while (!layers.empty()) { | 23 while (!layers.empty()) { |
24 for (auto* child : layers.front()->children()) | 24 for (auto* child : layers.front()->children()) |
25 layers.push_back(child); | 25 layers.push_back(child); |
26 layers.front()->SetVisible(true); | 26 layers.front()->SetVisible(true); |
27 layers.pop_front(); | 27 layers.pop_front(); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 WindowMirrorView::WindowMirrorView(WmWindowAura* window) : target_(window) { | 33 WindowMirrorView::WindowMirrorView(WmWindowAura* window) |
| 34 : target_(window), scoped_observer_(this) { |
34 DCHECK(window); | 35 DCHECK(window); |
35 } | 36 } |
| 37 |
36 WindowMirrorView::~WindowMirrorView() {} | 38 WindowMirrorView::~WindowMirrorView() {} |
37 | 39 |
38 gfx::Size WindowMirrorView::GetPreferredSize() const { | 40 gfx::Size WindowMirrorView::GetPreferredSize() const { |
39 return GetClientAreaBounds().size(); | 41 return GetClientAreaBounds().size(); |
40 } | 42 } |
41 | 43 |
42 void WindowMirrorView::Layout() { | 44 void WindowMirrorView::Layout() { |
43 // If |layer_owner_| hasn't been initialized (|this| isn't on screen), no-op. | 45 // If |layer_owner_| hasn't been initialized (|this| isn't on screen), no-op. |
44 if (!layer_owner_) | 46 if (!layer_owner_) |
45 return; | 47 return; |
(...skipping 26 matching lines...) Expand all Loading... |
72 ui::LayerDelegate* WindowMirrorView::CreateDelegate( | 74 ui::LayerDelegate* WindowMirrorView::CreateDelegate( |
73 ui::LayerDelegate* delegate) { | 75 ui::LayerDelegate* delegate) { |
74 if (!delegate) | 76 if (!delegate) |
75 return nullptr; | 77 return nullptr; |
76 delegates_.push_back( | 78 delegates_.push_back( |
77 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate))); | 79 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate))); |
78 | 80 |
79 return delegates_.back().get(); | 81 return delegates_.back().get(); |
80 } | 82 } |
81 | 83 |
| 84 void WindowMirrorView::OnDelegatedFrameDamageInTree() { |
| 85 layer_owner_.reset(); |
| 86 if (!GetVisibleBounds().IsEmpty()) |
| 87 InitLayerOwner(); |
| 88 } |
| 89 |
| 90 void WindowMirrorView::OnLayerDestroyed(ui::Layer* layer) { |
| 91 scoped_observer_.Remove(layer); |
| 92 } |
| 93 |
82 void WindowMirrorView::InitLayerOwner() { | 94 void WindowMirrorView::InitLayerOwner() { |
83 SetPaintToLayer(true); | 95 SetPaintToLayer(true); |
84 | 96 |
| 97 scoped_observer_.RemoveAll(); |
85 layer_owner_ = ::wm::RecreateLayers(target_->aura_window(), this); | 98 layer_owner_ = ::wm::RecreateLayers(target_->aura_window(), this); |
| 99 scoped_observer_.Add(target_->aura_window()->layer()); |
86 | 100 |
87 GetMirrorLayer()->parent()->Remove(GetMirrorLayer()); | 101 GetMirrorLayer()->parent()->Remove(GetMirrorLayer()); |
88 layer()->Add(GetMirrorLayer()); | 102 layer()->Add(GetMirrorLayer()); |
89 // This causes us to clip the non-client areas of the window. | 103 // This causes us to clip the non-client areas of the window. |
90 layer()->SetMasksToBounds(true); | 104 layer()->SetMasksToBounds(true); |
91 | 105 |
92 // Some extra work is needed when the target window is minimized. | 106 // Some extra work is needed when the target window is minimized. |
93 if (target_->GetWindowState()->IsMinimized()) { | 107 if (target_->GetWindowState()->IsMinimized()) { |
94 GetMirrorLayer()->SetVisible(true); | 108 GetMirrorLayer()->SetVisible(true); |
95 GetMirrorLayer()->SetOpacity(1); | 109 GetMirrorLayer()->SetOpacity(1); |
(...skipping 10 matching lines...) Expand all Loading... |
106 gfx::Rect WindowMirrorView::GetClientAreaBounds() const { | 120 gfx::Rect WindowMirrorView::GetClientAreaBounds() const { |
107 // The target window may not have a widget in unit tests. | 121 // The target window may not have a widget in unit tests. |
108 if (!target_->GetInternalWidget()) | 122 if (!target_->GetInternalWidget()) |
109 return gfx::Rect(); | 123 return gfx::Rect(); |
110 views::View* client_view = target_->GetInternalWidget()->client_view(); | 124 views::View* client_view = target_->GetInternalWidget()->client_view(); |
111 return client_view->ConvertRectToWidget(client_view->GetLocalBounds()); | 125 return client_view->ConvertRectToWidget(client_view->GetLocalBounds()); |
112 } | 126 } |
113 | 127 |
114 } // namespace wm | 128 } // namespace wm |
115 } // namespace ash | 129 } // namespace ash |
OLD | NEW |