| 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/wm/widget_finder.h" | 7 #include "ash/wm/widget_finder.h" |
| 8 #include "ash/wm/window_state.h" | 8 #include "ash/wm/window_state.h" |
| 9 #include "ash/wm/window_state_aura.h" | 9 #include "ash/wm/window_state_aura.h" |
| 10 #include "ash/wm_window.h" | 10 #include "ash/wm_window.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 while (!layers.empty()) { | 25 while (!layers.empty()) { |
| 26 for (auto* child : layers.front()->children()) | 26 for (auto* child : layers.front()->children()) |
| 27 layers.push_back(child); | 27 layers.push_back(child); |
| 28 layers.front()->SetVisible(true); | 28 layers.front()->SetVisible(true); |
| 29 layers.pop_front(); | 29 layers.pop_front(); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 WindowMirrorView::WindowMirrorView(WmWindow* window) : target_(window) { | 35 WindowMirrorView::WindowMirrorView(aura::Window* window) : target_(window) { |
| 36 DCHECK(window); | 36 DCHECK(window); |
| 37 } | 37 } |
| 38 | 38 |
| 39 WindowMirrorView::~WindowMirrorView() { | 39 WindowMirrorView::~WindowMirrorView() { |
| 40 // Make sure |target_| has outlived |this|. See crbug.com/681207 | 40 // Make sure |target_| has outlived |this|. See crbug.com/681207 |
| 41 DCHECK(target_->aura_window()->layer()); | 41 DCHECK(target_->layer()); |
| 42 if (layer_owner_) | 42 if (layer_owner_) |
| 43 target_->aura_window()->ClearProperty(aura::client::kMirroringEnabledKey); | 43 target_->ClearProperty(aura::client::kMirroringEnabledKey); |
| 44 } | 44 } |
| 45 | 45 |
| 46 gfx::Size WindowMirrorView::GetPreferredSize() const { | 46 gfx::Size WindowMirrorView::GetPreferredSize() const { |
| 47 return GetClientAreaBounds().size(); | 47 return GetClientAreaBounds().size(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void WindowMirrorView::Layout() { | 50 void WindowMirrorView::Layout() { |
| 51 // If |layer_owner_| hasn't been initialized (|this| isn't on screen), no-op. | 51 // If |layer_owner_| hasn't been initialized (|this| isn't on screen), no-op. |
| 52 if (!layer_owner_) | 52 if (!layer_owner_) |
| 53 return; | 53 return; |
| 54 | 54 |
| 55 // Position at 0, 0. | 55 // Position at 0, 0. |
| 56 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); | 56 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); |
| 57 | 57 |
| 58 gfx::Transform transform; | 58 gfx::Transform transform; |
| 59 gfx::Rect client_area_bounds = GetClientAreaBounds(); | 59 gfx::Rect client_area_bounds = GetClientAreaBounds(); |
| 60 // Scale down if necessary. | 60 // Scale down if necessary. |
| 61 if (size() != target_->GetBounds().size()) { | 61 if (size() != target_->bounds().size()) { |
| 62 const float scale = | 62 const float scale = |
| 63 width() / static_cast<float>(client_area_bounds.width()); | 63 width() / static_cast<float>(client_area_bounds.width()); |
| 64 transform.Scale(scale, scale); | 64 transform.Scale(scale, scale); |
| 65 } | 65 } |
| 66 // Reposition such that the client area is the only part visible. | 66 // Reposition such that the client area is the only part visible. |
| 67 transform.Translate(-client_area_bounds.x(), -client_area_bounds.y()); | 67 transform.Translate(-client_area_bounds.x(), -client_area_bounds.y()); |
| 68 GetMirrorLayer()->SetTransform(transform); | 68 GetMirrorLayer()->SetTransform(transform); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool WindowMirrorView::GetNeedsNotificationWhenVisibleBoundsChange() const { | 71 bool WindowMirrorView::GetNeedsNotificationWhenVisibleBoundsChange() const { |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void WindowMirrorView::OnVisibleBoundsChanged() { | 75 void WindowMirrorView::OnVisibleBoundsChanged() { |
| 76 if (!layer_owner_ && !GetVisibleBounds().IsEmpty()) | 76 if (!layer_owner_ && !GetVisibleBounds().IsEmpty()) |
| 77 InitLayerOwner(); | 77 InitLayerOwner(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void WindowMirrorView::InitLayerOwner() { | 80 void WindowMirrorView::InitLayerOwner() { |
| 81 if (!layer_owner_) { | 81 if (!layer_owner_) |
| 82 target_->aura_window()->SetProperty(aura::client::kMirroringEnabledKey, | 82 target_->SetProperty(aura::client::kMirroringEnabledKey, true); |
| 83 true); | |
| 84 } | |
| 85 | 83 |
| 86 layer_owner_ = | 84 layer_owner_ = ::wm::MirrorLayers(target_, false /* sync_bounds */); |
| 87 ::wm::MirrorLayers(target_->aura_window(), false /* sync_bounds */); | |
| 88 | 85 |
| 89 SetPaintToLayer(); | 86 SetPaintToLayer(); |
| 90 layer()->Add(GetMirrorLayer()); | 87 layer()->Add(GetMirrorLayer()); |
| 91 // 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. |
| 92 layer()->SetMasksToBounds(true); | 89 layer()->SetMasksToBounds(true); |
| 93 | 90 |
| 94 // Some extra work is needed when the target window is minimized. | 91 // Some extra work is needed when the target window is minimized. |
| 95 if (target_->GetWindowState()->IsMinimized()) { | 92 if (wm::GetWindowState(target_)->IsMinimized()) { |
| 96 GetMirrorLayer()->SetOpacity(1); | 93 GetMirrorLayer()->SetOpacity(1); |
| 97 EnsureAllChildrenAreVisible(GetMirrorLayer()); | 94 EnsureAllChildrenAreVisible(GetMirrorLayer()); |
| 98 } | 95 } |
| 99 | 96 |
| 100 Layout(); | 97 Layout(); |
| 101 } | 98 } |
| 102 | 99 |
| 103 ui::Layer* WindowMirrorView::GetMirrorLayer() { | 100 ui::Layer* WindowMirrorView::GetMirrorLayer() { |
| 104 return layer_owner_->root(); | 101 return layer_owner_->root(); |
| 105 } | 102 } |
| 106 | 103 |
| 107 gfx::Rect WindowMirrorView::GetClientAreaBounds() const { | 104 gfx::Rect WindowMirrorView::GetClientAreaBounds() const { |
| 108 int insets = target_->aura_window()->GetProperty(aura::client::kTopViewInset); | 105 int insets = target_->GetProperty(aura::client::kTopViewInset); |
| 109 if (insets > 0) { | 106 if (insets > 0) { |
| 110 gfx::Rect bounds(target_->GetBounds().size()); | 107 gfx::Rect bounds(target_->bounds().size()); |
| 111 bounds.Inset(0, insets, 0, 0); | 108 bounds.Inset(0, insets, 0, 0); |
| 112 return bounds; | 109 return bounds; |
| 113 } | 110 } |
| 114 // The target window may not have a widget in unit tests. | 111 // The target window may not have a widget in unit tests. |
| 115 views::Widget* widget = GetInternalWidgetForWindow(target_->aura_window()); | 112 views::Widget* widget = GetInternalWidgetForWindow(target_); |
| 116 if (!widget) | 113 if (!widget) |
| 117 return gfx::Rect(); | 114 return gfx::Rect(); |
| 118 views::View* client_view = widget->client_view(); | 115 views::View* client_view = widget->client_view(); |
| 119 return client_view->ConvertRectToWidget(client_view->GetLocalBounds()); | 116 return client_view->ConvertRectToWidget(client_view->GetLocalBounds()); |
| 120 } | 117 } |
| 121 | 118 |
| 122 } // namespace wm | 119 } // namespace wm |
| 123 } // namespace ash | 120 } // namespace ash |
| OLD | NEW |