Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: ash/wm/window_mirror_view.cc

Issue 2190963002: Ash window cycle ui: don't create mirrored layers for previews until (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use OnVisibleBoundsChanged Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/window_mirror_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // We call InvalidateLayout() so Layout() will get called again next time even
45 // if the bounds haven't changed.
46 if (!layer_owner_) {
47 InvalidateLayout();
sky 2016/08/08 19:12:40 The main thing I don't particularly like about eit
48 return;
49 }
50
58 // Position at 0, 0. 51 // Position at 0, 0.
59 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); 52 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size()));
60 53
61 // Scale down if necessary. 54 // Scale down if necessary.
62 gfx::Transform mirror_transform; 55 gfx::Transform mirror_transform;
63 if (size() != target_->GetBounds().size()) { 56 if (size() != target_->GetBounds().size()) {
64 const float scale = 57 const float scale =
65 width() / static_cast<float>(target_->GetBounds().width()); 58 width() / static_cast<float>(target_->GetBounds().width());
66 mirror_transform.Scale(scale, scale); 59 mirror_transform.Scale(scale, scale);
67 } 60 }
68 GetMirrorLayer()->SetTransform(mirror_transform); 61 GetMirrorLayer()->SetTransform(mirror_transform);
69 } 62 }
70 63
64 bool WindowMirrorView::GetNeedsNotificationWhenVisibleBoundsChange() const {
65 return true;
66 }
67
68 void WindowMirrorView::OnVisibleBoundsChanged() {
69 if (!layer_owner_ && !GetVisibleBounds().IsEmpty())
70 InitLayerOwner();
71 }
72
71 ui::LayerDelegate* WindowMirrorView::CreateDelegate( 73 ui::LayerDelegate* WindowMirrorView::CreateDelegate(
72 ui::LayerDelegate* delegate) { 74 ui::LayerDelegate* delegate) {
73 if (!delegate) 75 if (!delegate)
74 return nullptr; 76 return nullptr;
75 delegates_.push_back( 77 delegates_.push_back(
76 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate))); 78 base::WrapUnique(new ForwardingLayerDelegate(target_, delegate)));
77 79
78 return delegates_.back().get(); 80 return delegates_.back().get();
79 } 81 }
80 82
83 void WindowMirrorView::InitLayerOwner() {
84 SetPaintToLayer(true);
85
86 layer_owner_ = ::wm::RecreateLayers(target_->aura_window(), this);
87
88 GetMirrorLayer()->parent()->Remove(GetMirrorLayer());
89 layer()->Add(GetMirrorLayer());
90
91 // Some extra work is needed when the target window is minimized.
92 if (target_->GetWindowState()->IsMinimized()) {
93 GetMirrorLayer()->SetVisible(true);
94 GetMirrorLayer()->SetOpacity(1);
95 EnsureAllChildrenAreVisible(GetMirrorLayer());
96 }
97 }
98
81 ui::Layer* WindowMirrorView::GetMirrorLayer() { 99 ui::Layer* WindowMirrorView::GetMirrorLayer() {
82 return layer_owner_->root(); 100 return layer_owner_->root();
83 } 101 }
84 102
85 } // namespace wm 103 } // namespace wm
86 } // namespace ash 104 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_mirror_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698