summaryrefslogtreecommitdiffstats
path: root/ui/android/edge_effect_base.cc
blob: 2572754174aeb28321da1172b32261b410944ca9 (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
// Copyright 2015 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 "ui/android/edge_effect_base.h"

namespace ui {

// static
gfx::Transform EdgeEffectBase::ComputeTransform(Edge edge,
                                                const gfx::SizeF& viewport_size,
                                                float offset) {
  // Transforms assume the edge layers are anchored to their *top center point*.
  switch (edge) {
    case EDGE_TOP:
      return gfx::Transform(1, 0, 0, 1, 0, offset);
    case EDGE_LEFT:
      return gfx::Transform(0, 1, -1, 0, -viewport_size.height() / 2.f + offset,
                            viewport_size.height() / 2.f);
    case EDGE_BOTTOM:
      return gfx::Transform(-1, 0, 0, -1, 0, viewport_size.height() + offset);
    case EDGE_RIGHT:
      return gfx::Transform(0, -1, 1, 0, -viewport_size.height() / 2.f +
                                             viewport_size.width() + offset,
                            viewport_size.height() / 2.f);
    default:
      NOTREACHED() << "Invalid edge: " << edge;
      return gfx::Transform();
  };
}

// static
gfx::SizeF EdgeEffectBase::ComputeOrientedSize(
    Edge edge,
    const gfx::SizeF& viewport_size) {
  switch (edge) {
    case EDGE_TOP:
    case EDGE_BOTTOM:
      return viewport_size;
    case EDGE_LEFT:
    case EDGE_RIGHT:
      return gfx::SizeF(viewport_size.height(), viewport_size.width());
    default:
      NOTREACHED() << "Invalid edge: " << edge;
      return gfx::SizeF();
  };
}

}  // namespace ui