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

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

Issue 2157393002: Moves WindowCycleList/Controller to ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback and std::move Created 4 years, 5 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
(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
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