| 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" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 13 #include "ui/compositor/layer_tree_owner.h" | 13 #include "ui/compositor/layer_tree_owner.h" |
| 14 #include "ui/views/widget/widget.h" |
| 14 | 15 |
| 15 namespace ash { | 16 namespace ash { |
| 16 namespace wm { | 17 namespace wm { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 void EnsureAllChildrenAreVisible(ui::Layer* layer) { | 20 void EnsureAllChildrenAreVisible(ui::Layer* layer) { |
| 20 std::list<ui::Layer*> layers; | 21 std::list<ui::Layer*> layers; |
| 21 layers.push_back(layer); | 22 layers.push_back(layer); |
| 22 while (!layers.empty()) { | 23 while (!layers.empty()) { |
| 23 for (auto* child : layers.front()->children()) | 24 for (auto* child : layers.front()->children()) |
| 24 layers.push_back(child); | 25 layers.push_back(child); |
| 25 layers.front()->SetVisible(true); | 26 layers.front()->SetVisible(true); |
| 26 layers.pop_front(); | 27 layers.pop_front(); |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 WindowMirrorView::WindowMirrorView(WmWindowAura* window) : target_(window) { | 33 WindowMirrorView::WindowMirrorView(WmWindowAura* window) : target_(window) { |
| 33 DCHECK(window); | 34 DCHECK(window); |
| 34 } | 35 } |
| 35 WindowMirrorView::~WindowMirrorView() {} | 36 WindowMirrorView::~WindowMirrorView() {} |
| 36 | 37 |
| 37 void WindowMirrorView::Init() { | |
| 38 SetPaintToLayer(true); | |
| 39 | |
| 40 layer_owner_ = ::wm::RecreateLayers(target_->aura_window(), this); | |
| 41 | |
| 42 GetMirrorLayer()->parent()->Remove(GetMirrorLayer()); | |
| 43 layer()->Add(GetMirrorLayer()); | |
| 44 | |
| 45 // Some extra work is needed when the target window is minimized. | |
| 46 if (target_->GetWindowState()->IsMinimized()) { | |
| 47 GetMirrorLayer()->SetVisible(true); | |
| 48 GetMirrorLayer()->SetOpacity(1); | |
| 49 EnsureAllChildrenAreVisible(GetMirrorLayer()); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 gfx::Size WindowMirrorView::GetPreferredSize() const { | 38 gfx::Size WindowMirrorView::GetPreferredSize() const { |
| 54 return target_->GetBounds().size(); | 39 return target_->GetBounds().size(); |
| 55 } | 40 } |
| 56 | 41 |
| 57 void WindowMirrorView::Layout() { | 42 void WindowMirrorView::Layout() { |
| 43 // If |layer_owner_| hasn't been initialized (|this| isn't on screen), no-op. |
| 44 if (!layer_owner_) |
| 45 return; |
| 46 |
| 58 // Position at 0, 0. | 47 // Position at 0, 0. |
| 59 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); | 48 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); |
| 60 | 49 |
| 61 // Scale down if necessary. | 50 // Scale down if necessary. |
| 62 gfx::Transform mirror_transform; | 51 gfx::Transform mirror_transform; |
| 63 if (size() != target_->GetBounds().size()) { | 52 if (size() != target_->GetBounds().size()) { |
| 64 const float scale = | 53 const float scale = |
| 65 width() / static_cast<float>(target_->GetBounds().width()); | 54 width() / static_cast<float>(target_->GetBounds().width()); |
| 66 mirror_transform.Scale(scale, scale); | 55 mirror_transform.Scale(scale, scale); |
| 67 } | 56 } |
| 68 GetMirrorLayer()->SetTransform(mirror_transform); | 57 GetMirrorLayer()->SetTransform(mirror_transform); |
| 69 } | 58 } |
| 70 | 59 |
| 60 bool WindowMirrorView::GetNeedsNotificationWhenVisibleBoundsChange() const { |
| 61 return true; |
| 62 } |
| 63 |
| 64 void WindowMirrorView::OnVisibleBoundsChanged() { |
| 65 if (!layer_owner_ && !GetVisibleBounds().IsEmpty()) |
| 66 InitLayerOwner(); |
| 67 } |
| 68 |
| 71 ui::LayerDelegate* WindowMirrorView::CreateDelegate( | 69 ui::LayerDelegate* WindowMirrorView::CreateDelegate( |
| 72 ui::LayerDelegate* delegate) { | 70 ui::LayerDelegate* delegate) { |
| 73 if (!delegate) | 71 if (!delegate) |
| 74 return nullptr; | 72 return nullptr; |
| 75 delegates_.push_back( | 73 delegates_.push_back( |
| 76 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate))); | 74 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate))); |
| 77 | 75 |
| 78 return delegates_.back().get(); | 76 return delegates_.back().get(); |
| 79 } | 77 } |
| 80 | 78 |
| 79 void WindowMirrorView::InitLayerOwner() { |
| 80 SetPaintToLayer(true); |
| 81 |
| 82 layer_owner_ = ::wm::RecreateLayers(target_->aura_window(), this); |
| 83 |
| 84 GetMirrorLayer()->parent()->Remove(GetMirrorLayer()); |
| 85 layer()->Add(GetMirrorLayer()); |
| 86 |
| 87 // Some extra work is needed when the target window is minimized. |
| 88 if (target_->GetWindowState()->IsMinimized()) { |
| 89 GetMirrorLayer()->SetVisible(true); |
| 90 GetMirrorLayer()->SetOpacity(1); |
| 91 EnsureAllChildrenAreVisible(GetMirrorLayer()); |
| 92 } |
| 93 |
| 94 Layout(); |
| 95 } |
| 96 |
| 81 ui::Layer* WindowMirrorView::GetMirrorLayer() { | 97 ui::Layer* WindowMirrorView::GetMirrorLayer() { |
| 82 return layer_owner_->root(); | 98 return layer_owner_->root(); |
| 83 } | 99 } |
| 84 | 100 |
| 85 } // namespace wm | 101 } // namespace wm |
| 86 } // namespace ash | 102 } // namespace ash |
| OLD | NEW |