blob: 865960338109875ce708056ba471b541584df32e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/host/transformer_helper.h"
#include "ash/host/ash_window_tree_host.h"
#include "ash/host/root_window_transformer.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/compositor/dip_util.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/transform.h"
namespace ash {
namespace {
// A simple RootWindowTransformer without host insets.
class SimpleRootWindowTransformer : public RootWindowTransformer {
public:
SimpleRootWindowTransformer(const aura::Window* root_window,
const gfx::Transform& transform)
: root_window_(root_window), transform_(transform) {}
// RootWindowTransformer overrides:
gfx::Transform GetTransform() const override { return transform_; }
gfx::Transform GetInverseTransform() const override {
gfx::Transform invert;
if (!transform_.GetInverse(&invert))
return transform_;
return invert;
}
gfx::Rect GetRootWindowBounds(const gfx::Size& host_size) const override {
gfx::Rect bounds(host_size);
gfx::RectF new_bounds(ui::ConvertRectToDIP(root_window_->layer(), bounds));
transform_.TransformRect(&new_bounds);
return gfx::Rect(gfx::ToFlooredSize(new_bounds.size()));
}
gfx::Insets GetHostInsets() const override { return gfx::Insets(); }
private:
~SimpleRootWindowTransformer() override {}
const aura::Window* root_window_;
const gfx::Transform transform_;
DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer);
};
} // namespace
TransformerHelper::TransformerHelper(AshWindowTreeHost* ash_host)
: ash_host_(ash_host) {
SetTransform(gfx::Transform());
}
TransformerHelper::~TransformerHelper() {}
gfx::Insets TransformerHelper::GetHostInsets() const {
return transformer_->GetHostInsets();
}
void TransformerHelper::SetTransform(const gfx::Transform& transform) {
scoped_ptr<RootWindowTransformer> transformer(new SimpleRootWindowTransformer(
ash_host_->AsWindowTreeHost()->window(), transform));
SetRootWindowTransformer(transformer.Pass());
}
void TransformerHelper::SetRootWindowTransformer(
scoped_ptr<RootWindowTransformer> transformer) {
transformer_ = transformer.Pass();
aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost();
aura::Window* window = host->window();
window->SetTransform(transformer_->GetTransform());
// If the layer is not animating, then we need to update the root window
// size immediately.
if (!window->layer()->GetAnimator()->is_animating())
host->UpdateRootWindowSize(host->GetBounds().size());
}
gfx::Transform TransformerHelper::GetTransform() const {
float scale = ui::GetDeviceScaleFactor(
ash_host_->AsWindowTreeHost()->window()->layer());
gfx::Transform transform;
transform.Scale(scale, scale);
transform *= transformer_->GetTransform();
return transform;
}
gfx::Transform TransformerHelper::GetInverseTransform() const {
float scale = ui::GetDeviceScaleFactor(
ash_host_->AsWindowTreeHost()->window()->layer());
gfx::Transform transform;
transform.Scale(1.0f / scale, 1.0f / scale);
return transformer_->GetInverseTransform() * transform;
}
void TransformerHelper::UpdateWindowSize(const gfx::Size& host_size) {
ash_host_->AsWindowTreeHost()->window()->SetBounds(
transformer_->GetRootWindowBounds(host_size));
}
} // namespace ash
|