summaryrefslogtreecommitdiffstats
path: root/cc/CCScrollbarAnimationController.cpp
blob: 2146c25064e1736d869c6a412211866d34da4588 (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
// 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.

#include "config.h"

#include "CCScrollbarAnimationController.h"

#include "CCScrollbarLayerImpl.h"
#include <wtf/CurrentTime.h>

#if OS(ANDROID)
#include "CCScrollbarAnimationControllerLinearFade.h"
#endif

namespace cc {

#if OS(ANDROID)
PassOwnPtr<CCScrollbarAnimationController> CCScrollbarAnimationController::create(CCLayerImpl* scrollLayer)
{
    static const double fadeoutDelay = 0.3;
    static const double fadeoutLength = 0.3;
    return CCScrollbarAnimationControllerLinearFade::create(scrollLayer, fadeoutDelay, fadeoutLength);
}
#else
PassOwnPtr<CCScrollbarAnimationController> CCScrollbarAnimationController::create(CCLayerImpl* scrollLayer)
{
    return adoptPtr(new CCScrollbarAnimationController(scrollLayer));
}
#endif

CCScrollbarAnimationController::CCScrollbarAnimationController(CCLayerImpl* scrollLayer)
    : m_horizontalScrollbarLayer(0)
    , m_verticalScrollbarLayer(0)
{
    CCScrollbarAnimationController::updateScrollOffsetAtTime(scrollLayer, 0);
}

CCScrollbarAnimationController::~CCScrollbarAnimationController()
{
}

void CCScrollbarAnimationController::didPinchGestureBegin()
{
    didPinchGestureBeginAtTime(monotonicallyIncreasingTime());
}

void CCScrollbarAnimationController::didPinchGestureUpdate()
{
    didPinchGestureUpdateAtTime(monotonicallyIncreasingTime());
}

void CCScrollbarAnimationController::didPinchGestureEnd()
{
    didPinchGestureEndAtTime(monotonicallyIncreasingTime());
}

void CCScrollbarAnimationController::updateScrollOffset(CCLayerImpl* scrollLayer)
{
    updateScrollOffsetAtTime(scrollLayer, monotonicallyIncreasingTime());
}

IntSize CCScrollbarAnimationController::getScrollLayerBounds(const CCLayerImpl* scrollLayer)
{
    if (!scrollLayer->children().size())
        return IntSize();
    // Copy & paste from CCLayerTreeHostImpl...
    // FIXME: Hardcoding the first child here is weird. Think of
    // a cleaner way to get the contentBounds on the Impl side.
    return scrollLayer->children()[0]->bounds();
}

void CCScrollbarAnimationController::updateScrollOffsetAtTime(CCLayerImpl* scrollLayer, double)
{
    m_currentPos = scrollLayer->scrollPosition() + scrollLayer->scrollDelta();
    m_totalSize = getScrollLayerBounds(scrollLayer);
    m_maximum = scrollLayer->maxScrollPosition();

    if (m_horizontalScrollbarLayer) {
        m_horizontalScrollbarLayer->setCurrentPos(m_currentPos.x());
        m_horizontalScrollbarLayer->setTotalSize(m_totalSize.width());
        m_horizontalScrollbarLayer->setMaximum(m_maximum.width());
    }

    if (m_verticalScrollbarLayer) {
        m_verticalScrollbarLayer->setCurrentPos(m_currentPos.y());
        m_verticalScrollbarLayer->setTotalSize(m_totalSize.height());
        m_verticalScrollbarLayer->setMaximum(m_maximum.height());
    }
}

} // namespace cc