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" | |
9 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
10 #include "ash/wm/window_state_aura.h" | 9 #include "ash/wm/window_state_aura.h" |
11 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
13 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_tree_owner.h" | 13 #include "ui/compositor/layer_tree_owner.h" |
15 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 15 #include "ui/wm/core/window_util.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 namespace wm { | 18 namespace wm { |
19 namespace { | 19 namespace { |
20 | 20 |
21 void EnsureAllChildrenAreVisible(ui::Layer* layer) { | 21 void EnsureAllChildrenAreVisible(ui::Layer* layer) { |
22 std::list<ui::Layer*> layers; | 22 std::list<ui::Layer*> layers; |
23 layers.push_back(layer); | 23 layers.push_back(layer); |
24 while (!layers.empty()) { | 24 while (!layers.empty()) { |
25 for (auto* child : layers.front()->children()) | 25 for (auto* child : layers.front()->children()) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 bool WindowMirrorView::GetNeedsNotificationWhenVisibleBoundsChange() const { | 68 bool WindowMirrorView::GetNeedsNotificationWhenVisibleBoundsChange() const { |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 void WindowMirrorView::OnVisibleBoundsChanged() { | 72 void WindowMirrorView::OnVisibleBoundsChanged() { |
73 if (!layer_owner_ && !GetVisibleBounds().IsEmpty()) | 73 if (!layer_owner_ && !GetVisibleBounds().IsEmpty()) |
74 InitLayerOwner(); | 74 InitLayerOwner(); |
75 } | 75 } |
76 | 76 |
77 ui::LayerDelegate* WindowMirrorView::CreateDelegate(ui::Layer* new_layer, | |
78 ui::Layer* old_layer) { | |
79 if (!old_layer || !old_layer->delegate()) | |
80 return nullptr; | |
81 delegates_.push_back( | |
82 base::MakeUnique<ForwardingLayerDelegate>(new_layer, old_layer)); | |
83 return delegates_.back().get(); | |
84 } | |
85 | |
86 void WindowMirrorView::InitLayerOwner() { | 77 void WindowMirrorView::InitLayerOwner() { |
87 if (!layer_owner_) { | 78 if (!layer_owner_) { |
88 target_->aura_window()->SetProperty(aura::client::kMirroringEnabledKey, | 79 target_->aura_window()->SetProperty(aura::client::kMirroringEnabledKey, |
89 true); | 80 true); |
90 } | 81 } |
91 | 82 |
92 layer_owner_ = ::wm::RecreateLayers(target_->aura_window(), this); | 83 layer_owner_ = |
| 84 ::wm::MirrorLayers(target_->aura_window(), false /* sync_bounds */); |
93 | 85 |
94 GetMirrorLayer()->parent()->Remove(GetMirrorLayer()); | |
95 SetPaintToLayer(true); | 86 SetPaintToLayer(true); |
96 layer()->Add(GetMirrorLayer()); | 87 layer()->Add(GetMirrorLayer()); |
97 // This causes us to clip the non-client areas of the window. | 88 // This causes us to clip the non-client areas of the window. |
98 layer()->SetMasksToBounds(true); | 89 layer()->SetMasksToBounds(true); |
99 | 90 |
100 // Some extra work is needed when the target window is minimized. | 91 // Some extra work is needed when the target window is minimized. |
101 if (target_->GetWindowState()->IsMinimized()) { | 92 if (target_->GetWindowState()->IsMinimized()) { |
102 GetMirrorLayer()->SetOpacity(1); | 93 GetMirrorLayer()->SetOpacity(1); |
103 EnsureAllChildrenAreVisible(GetMirrorLayer()); | 94 EnsureAllChildrenAreVisible(GetMirrorLayer()); |
104 } | 95 } |
105 | 96 |
106 Layout(); | 97 Layout(); |
107 } | 98 } |
108 | 99 |
109 ui::Layer* WindowMirrorView::GetMirrorLayer() { | 100 ui::Layer* WindowMirrorView::GetMirrorLayer() { |
110 return layer_owner_->root(); | 101 return layer_owner_->root(); |
111 } | 102 } |
112 | 103 |
113 gfx::Rect WindowMirrorView::GetClientAreaBounds() const { | 104 gfx::Rect WindowMirrorView::GetClientAreaBounds() const { |
114 // The target window may not have a widget in unit tests. | 105 // The target window may not have a widget in unit tests. |
115 if (!target_->GetInternalWidget()) | 106 if (!target_->GetInternalWidget()) |
116 return gfx::Rect(); | 107 return gfx::Rect(); |
117 views::View* client_view = target_->GetInternalWidget()->client_view(); | 108 views::View* client_view = target_->GetInternalWidget()->client_view(); |
118 return client_view->ConvertRectToWidget(client_view->GetLocalBounds()); | 109 return client_view->ConvertRectToWidget(client_view->GetLocalBounds()); |
119 } | 110 } |
120 | 111 |
121 } // namespace wm | 112 } // namespace wm |
122 } // namespace ash | 113 } // namespace ash |
OLD | NEW |