Removed unused icon resources from app_list.
[chromium-blink-merge.git] / ash / host / transformer_helper.cc
blob865960338109875ce708056ba471b541584df32e
1 // Copyright 2014 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.
5 #include "ash/host/transformer_helper.h"
7 #include "ash/host/ash_window_tree_host.h"
8 #include "ash/host/root_window_transformer.h"
9 #include "ui/aura/window.h"
10 #include "ui/aura/window_tree_host.h"
11 #include "ui/compositor/dip_util.h"
12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/rect_f.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/size_conversions.h"
17 #include "ui/gfx/transform.h"
19 namespace ash {
20 namespace {
22 // A simple RootWindowTransformer without host insets.
23 class SimpleRootWindowTransformer : public RootWindowTransformer {
24 public:
25 SimpleRootWindowTransformer(const aura::Window* root_window,
26 const gfx::Transform& transform)
27 : root_window_(root_window), transform_(transform) {}
29 // RootWindowTransformer overrides:
30 gfx::Transform GetTransform() const override { return transform_; }
32 gfx::Transform GetInverseTransform() const override {
33 gfx::Transform invert;
34 if (!transform_.GetInverse(&invert))
35 return transform_;
36 return invert;
39 gfx::Rect GetRootWindowBounds(const gfx::Size& host_size) const override {
40 gfx::Rect bounds(host_size);
41 gfx::RectF new_bounds(ui::ConvertRectToDIP(root_window_->layer(), bounds));
42 transform_.TransformRect(&new_bounds);
43 return gfx::Rect(gfx::ToFlooredSize(new_bounds.size()));
46 gfx::Insets GetHostInsets() const override { return gfx::Insets(); }
48 private:
49 ~SimpleRootWindowTransformer() override {}
51 const aura::Window* root_window_;
52 const gfx::Transform transform_;
54 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer);
57 } // namespace
59 TransformerHelper::TransformerHelper(AshWindowTreeHost* ash_host)
60 : ash_host_(ash_host) {
61 SetTransform(gfx::Transform());
64 TransformerHelper::~TransformerHelper() {}
66 gfx::Insets TransformerHelper::GetHostInsets() const {
67 return transformer_->GetHostInsets();
70 void TransformerHelper::SetTransform(const gfx::Transform& transform) {
71 scoped_ptr<RootWindowTransformer> transformer(new SimpleRootWindowTransformer(
72 ash_host_->AsWindowTreeHost()->window(), transform));
73 SetRootWindowTransformer(transformer.Pass());
76 void TransformerHelper::SetRootWindowTransformer(
77 scoped_ptr<RootWindowTransformer> transformer) {
78 transformer_ = transformer.Pass();
79 aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost();
80 aura::Window* window = host->window();
81 window->SetTransform(transformer_->GetTransform());
82 // If the layer is not animating, then we need to update the root window
83 // size immediately.
84 if (!window->layer()->GetAnimator()->is_animating())
85 host->UpdateRootWindowSize(host->GetBounds().size());
88 gfx::Transform TransformerHelper::GetTransform() const {
89 float scale = ui::GetDeviceScaleFactor(
90 ash_host_->AsWindowTreeHost()->window()->layer());
91 gfx::Transform transform;
92 transform.Scale(scale, scale);
93 transform *= transformer_->GetTransform();
94 return transform;
97 gfx::Transform TransformerHelper::GetInverseTransform() const {
98 float scale = ui::GetDeviceScaleFactor(
99 ash_host_->AsWindowTreeHost()->window()->layer());
100 gfx::Transform transform;
101 transform.Scale(1.0f / scale, 1.0f / scale);
102 return transformer_->GetInverseTransform() * transform;
105 void TransformerHelper::UpdateWindowSize(const gfx::Size& host_size) {
106 ash_host_->AsWindowTreeHost()->window()->SetBounds(
107 transformer_->GetRootWindowBounds(host_size));
110 } // namespace ash