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

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: 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 // Ensure the layer owner exists, but only if |this| is actually visible.
44 if (!layer_owner_) {
45 if (!GetVisibleBounds().IsEmpty()) {
46 InitLayerOwner();
47 } else {
48 // If |this| isn't on screen, no-op. We call InvalidateLayout() so
49 // Layout() will get called again next time even if the bounds haven't
50 // changed.
51 InvalidateLayout();
sky 2016/08/01 20:55:57 Are you sure you want that and not overriding GetN
Evan Stade 2016/08/01 22:11:14 a) We don't really want notifications after the in
sky 2016/08/02 16:21:27 That's no different than the if (!layer_owner_) he
Evan Stade 2016/08/02 18:22:55 OK, I'll try it the other way because it's easier
52 return;
53 }
54 }
55
58 // Position at 0, 0. 56 // Position at 0, 0.
59 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size())); 57 GetMirrorLayer()->SetBounds(gfx::Rect(GetMirrorLayer()->bounds().size()));
60 58
61 // Scale down if necessary. 59 // Scale down if necessary.
62 gfx::Transform mirror_transform; 60 gfx::Transform mirror_transform;
63 if (size() != target_->GetBounds().size()) { 61 if (size() != target_->GetBounds().size()) {
64 const float scale = 62 const float scale =
65 width() / static_cast<float>(target_->GetBounds().width()); 63 width() / static_cast<float>(target_->GetBounds().width());
66 mirror_transform.Scale(scale, scale); 64 mirror_transform.Scale(scale, scale);
67 } 65 }
68 GetMirrorLayer()->SetTransform(mirror_transform); 66 GetMirrorLayer()->SetTransform(mirror_transform);
69 } 67 }
70 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
81 ui::Layer* WindowMirrorView::GetMirrorLayer() { 95 ui::Layer* WindowMirrorView::GetMirrorLayer() {
82 return layer_owner_->root(); 96 return layer_owner_->root();
83 } 97 }
84 98
85 } // namespace wm 99 } // namespace wm
86 } // namespace ash 100 } // 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