| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/window_mirror_view.h" |
| 6 |
| 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" |
| 10 #include "ash/wm/window_state_aura.h" |
| 11 #include "ui/aura/window.h" |
| 12 #include "ui/compositor/layer.h" |
| 13 #include "ui/compositor/layer_tree_owner.h" |
| 14 |
| 15 namespace ash { |
| 16 namespace wm { |
| 17 namespace { |
| 18 |
| 19 void EnsureAllChildrenAreVisible(ui::Layer* layer) { |
| 20 std::list<ui::Layer*> layers; |
| 21 layers.push_back(layer); |
| 22 while (!layers.empty()) { |
| 23 for (auto child : layers.front()->children()) |
| 24 layers.push_back(child); |
| 25 layers.front()->SetVisible(true); |
| 26 layers.pop_front(); |
| 27 } |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
| 32 WindowMirrorView::WindowMirrorView(WmWindowAura* window) : target_(window) { |
| 33 DCHECK(window); |
| 34 } |
| 35 WindowMirrorView::~WindowMirrorView() {} |
| 36 |
| 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 { |
| 54 const int kMaxWidth = 512; |
| 55 const int kMaxHeight = 256; |
| 56 |
| 57 gfx::Size target_size = target_->GetBounds().size(); |
| 58 if (target_size.width() <= kMaxWidth && target_size.height() <= kMaxHeight) { |
| 59 return target_size; |
| 60 } |
| 61 |
| 62 float scale = std::min(kMaxWidth / static_cast<float>(target_size.width()), |
| 63 kMaxHeight / static_cast<float>(target_size.height())); |
| 64 return gfx::ScaleToCeiledSize(target_size, scale, scale); |
| 65 } |
| 66 |
| 67 void WindowMirrorView::Layout() { |
| 68 // Position at 0, 0. |
| 69 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); |
| 70 |
| 71 // Scale down if necessary. |
| 72 gfx::Transform mirror_transform; |
| 73 if (size() != target_->GetBounds().size()) { |
| 74 const float scale = |
| 75 width() / static_cast<float>(target_->GetBounds().width()); |
| 76 mirror_transform.Scale(scale, scale); |
| 77 } |
| 78 GetMirrorLayer()->SetTransform(mirror_transform); |
| 79 } |
| 80 |
| 81 ui::LayerDelegate* WindowMirrorView::CreateDelegate( |
| 82 ui::LayerDelegate* delegate) { |
| 83 if (!delegate) |
| 84 return nullptr; |
| 85 delegates_.push_back( |
| 86 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate))); |
| 87 |
| 88 return delegates_.back().get(); |
| 89 } |
| 90 |
| 91 ui::Layer* WindowMirrorView::GetMirrorLayer() { |
| 92 return layer_owner_->root(); |
| 93 } |
| 94 |
| 95 } // namespace wm |
| 96 } // namespace ash |
| OLD | NEW |