summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/android/ScrollableLayerAndroid.cpp
blob: ca8f03ca7c1e9d09f0f379530a921336dfed2a47 (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
#include "config.h"
#include "ScrollableLayerAndroid.h"

#if USE(ACCELERATED_COMPOSITING)

namespace WebCore {

bool ScrollableLayerAndroid::scrollTo(int x, int y)
{
    SkIRect scrollBounds;
    getScrollRect(&scrollBounds);
    if (!scrollBounds.fRight && !scrollBounds.fBottom)
        return false;

    SkScalar newX = SkScalarPin(x, 0, scrollBounds.fRight);
    SkScalar newY = SkScalarPin(y, 0, scrollBounds.fBottom);
    // Check for no change.
    if (newX == scrollBounds.fLeft && newY == scrollBounds.fTop)
        return false;

    SkScalar diffX = newX - scrollBounds.fLeft;
    SkScalar diffY = newY - scrollBounds.fTop;
    const SkPoint& pos = getPosition();
    setPosition(pos.fX - diffX, pos.fY - diffY);
    return true;
}

void ScrollableLayerAndroid::getScrollRect(SkIRect* out) const
{
    const SkPoint& pos = getPosition();
    out->fLeft = m_scrollLimits.fLeft - pos.fX;
    out->fTop = m_scrollLimits.fTop - pos.fY;
    out->fRight = getSize().width() - m_scrollLimits.width();
    out->fBottom = getSize().height() - m_scrollLimits.height();
}

} // namespace WebCore

#endif // USE(ACCELERATED_COMPOSITING)