summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/android/ScrollableLayerAndroid.cpp
blob: 7b40b8daa4987796919673e4aa2517942422ce8f (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
#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 == 0 && scrollBounds.fBottom == 0)
        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)