summaryrefslogtreecommitdiffstats
path: root/views/layer_property_setter.cc
blob: 21b3501eb2a72985f54a0d88f310fa4ede886f2b (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
// Copyright (c) 2011 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 "views/layer_property_setter.h"

#include "base/scoped_ptr.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animator.h"

namespace views {

namespace {

// DefaultSetter ---------------------------------------------------------------

class DefaultSetter : public LayerPropertySetter {
 public:
  DefaultSetter();

  // LayerPropertySetter:
  virtual void Installed(ui::Layer* layer) OVERRIDE;
  virtual void Uninstalled(ui::Layer* layer) OVERRIDE;
  virtual void SetTransform(ui::Layer* layer,
                            const ui::Transform& transform) OVERRIDE;
  virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) OVERRIDE;

 private:
  DISALLOW_COPY_AND_ASSIGN(DefaultSetter);
};

DefaultSetter::DefaultSetter() {
}

void DefaultSetter::Installed(ui::Layer* layer) {
}

void DefaultSetter::Uninstalled(ui::Layer* layer) {
}

void DefaultSetter::SetTransform(ui::Layer* layer,
                                 const ui::Transform& transform) {
  layer->set_transform(transform);
}

void DefaultSetter::SetBounds(ui::Layer* layer, const gfx::Rect& bounds) {
  layer->set_bounds(bounds);
}

// AnimatingSetter -------------------------------------------------------------

class AnimatingSetter : public LayerPropertySetter {
 public:
  AnimatingSetter();

  // LayerPropertySetter:
  virtual void Installed(ui::Layer* layer) OVERRIDE;
  virtual void Uninstalled(ui::Layer* layer) OVERRIDE;
  virtual void SetTransform(ui::Layer* layer,
                            const ui::Transform& transform) OVERRIDE;
  virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) OVERRIDE;

 private:
  scoped_ptr<ui::LayerAnimator> animator_;

  DISALLOW_COPY_AND_ASSIGN(AnimatingSetter);
};

AnimatingSetter::AnimatingSetter() {
}

void AnimatingSetter::Installed(ui::Layer* layer) {
  animator_.reset(new ui::LayerAnimator(layer));
}

void AnimatingSetter::Uninstalled(ui::Layer* layer) {
  animator_.reset();
}

void AnimatingSetter::SetTransform(ui::Layer* layer,
                                   const ui::Transform& transform) {
  animator_->AnimateTransform(transform);
}

void AnimatingSetter::SetBounds(ui::Layer* layer, const gfx::Rect& bounds) {
  if (bounds.size() == animator_->layer()->bounds().size())
    animator_->AnimateToPoint(bounds.origin());
  else
    animator_->StopAnimatingToPoint();
}

}  // namespace

// LayerPropertySetter ---------------------------------------------------------

// static
LayerPropertySetter* LayerPropertySetter::CreateDefaultSetter() {
  return new DefaultSetter;
}

// static
LayerPropertySetter* LayerPropertySetter::CreateAnimatingSetter() {
  return new AnimatingSetter();
}

}  // namespace views