summaryrefslogtreecommitdiffstats
path: root/cc/scrollbar_animation_controller.h
blob: eaf291373f24c3c560acb6e0516b1a8358191ed1 (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
// Copyright 2012 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.

#ifndef CC_SCROLLBAR_ANIMATION_CONTROLLER_H_
#define CC_SCROLLBAR_ANIMATION_CONTROLLER_H_

#include "base/memory/scoped_ptr.h"
#include "cc/cc_export.h"
#include "ui/gfx/size.h"
#include "ui/gfx/vector2d.h"
#include "ui/gfx/vector2d_f.h"

namespace cc {

class LayerImpl;
class ScrollbarLayerImpl;

// This abstract class represents the compositor-side analogy of ScrollbarAnimator.
// Individual platforms should subclass it to provide specialized implementation.
class CC_EXPORT ScrollbarAnimationController {
public:
    static scoped_ptr<ScrollbarAnimationController> create(LayerImpl* scrollLayer);

    virtual ~ScrollbarAnimationController();

    virtual bool animate(double monotonicTime);
    void didPinchGestureBegin();
    void didPinchGestureUpdate();
    void didPinchGestureEnd();
    void updateScrollOffset(LayerImpl* scrollLayer);

    void setHorizontalScrollbarLayer(ScrollbarLayerImpl* layer) { m_horizontalScrollbarLayer = layer; }
    ScrollbarLayerImpl* horizontalScrollbarLayer() const { return m_horizontalScrollbarLayer; }

    void setVerticalScrollbarLayer(ScrollbarLayerImpl* layer) { m_verticalScrollbarLayer = layer; }
    ScrollbarLayerImpl* verticalScrollbarLayer() const { return m_verticalScrollbarLayer; }

    gfx::Vector2dF currentOffset() const { return m_currentOffset; }
    gfx::Size totalSize() const { return m_totalSize; }
    gfx::Vector2d maximum() const { return m_maximum; }

    virtual void didPinchGestureBeginAtTime(double monotonicTime) { }
    virtual void didPinchGestureUpdateAtTime(double monotonicTime) { }
    virtual void didPinchGestureEndAtTime(double monotonicTime) { }
    virtual void updateScrollOffsetAtTime(LayerImpl* scrollLayer, double monotonicTime);

protected:
    explicit ScrollbarAnimationController(LayerImpl* scrollLayer);

private:
    static gfx::Size getScrollLayerBounds(const LayerImpl*);

    // Beware of dangling pointer. Always update these during tree synchronization.
    ScrollbarLayerImpl* m_horizontalScrollbarLayer;
    ScrollbarLayerImpl* m_verticalScrollbarLayer;

    gfx::Vector2dF m_currentOffset;
    gfx::Size m_totalSize;
    gfx::Vector2d m_maximum;
};

} // namespace cc

#endif  // CC_SCROLLBAR_ANIMATION_CONTROLLER_H_