summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/touchadjustment/scroll-offset.html
blob: ca720d162aede71456c3442bd108cf95743f5a8a (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
<!DOCTYPE html>
<html>
<head>
    <title>Touch Adjustment : Adjust correctly for scroll offset - bug 86205</title>
    <script src="../resources/js-test.js"></script>
    <script src="resources/touchadjustment.js"></script>
    <style>
        #scrolloffsetcontainer {
            position: absolute;
            top: 500px;
            height: 1000px;
        }
        body {
            margin: 0px;
        }
        #div0 { margin-left: 20px; height: 100px; box-sizing: border-box; }
        #div1 { margin-left: 10px; height: 100px; box-sizing: border-box; }
    </style>
</head>
<body>

<div id=scrolloffsetcontainer>
    <div id=div0>
        <a id=a0 href="#div0">Link 0</a>
    </div>
    <div id=div1>
        <a id=a1 href="#div1">Link 1</a>
    </div>
</div>

<p id='description'></p>
<div id='console'></div>

<script>
    var adjustedNode;
    var adjustedPoint;
    // Set up shortcut access to elements
    var e = {};
    ['scrolloffsetcontainer', 'div0', 'div1', 'a0', 'a1'].forEach(function(a) {
        e[a] = document.getElementById(a);
    });

    function adjustedPointAtTouch(x, y, radius)
    {
        var x = x - radius;
        var y = y - radius;
        var width = radius * 2;
        var height = radius * 2;
        var position = internals.touchPositionAdjustedToBestClickableNode(x, y, width, height, document);
        return position;
    }

    function testDirectTouches()
    {
        testTouchPoint(touchPoint(40, 130, 50), e.a0);
        testTouchPoint(touchPoint(30, 230, 50), e.a1);
    }
    function testAdjustedTouches()
    {
        adjustedPoint = adjustedPointAtTouch(10, 120, 80);
        shouldBeNonNull('adjustedPoint');
        adjustedNode = document.elementFromPoint(adjustedPoint.x, adjustedPoint.y);
        shouldBe('adjustedNode', 'e.a0');

        adjustedPoint = adjustedPointAtTouch(5, 220, 80);
        shouldBeNonNull('adjustedPoint');
        adjustedNode = document.elementFromPoint(adjustedPoint.x, adjustedPoint.y);
        shouldBe('adjustedNode', 'e.a1');
    }

    function runTests()
    {
        if (window.testRunner && window.internals && internals.touchNodeAdjustedToBestClickableNode) {
            description('Test touch adjustment when main frame is scroll offset.');
            window.scrollBy(0,400);
            testDirectTouches();
            testAdjustedTouches();
            e.scrolloffsetcontainer.style.display = 'none';
        }
    }
    runTests();
</script>


</body>
</html>