summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_hittest_pointerevents_svg.html
blob: 3b8a7cef3ed3ebb343623d78427ebcf29fd1fd26 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE HTML>
<html>
<head>
  <title>Hit-testing a scrollframe covered by nonrectangular and pointer-events:none things</title>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <meta name="viewport" content="width=device-width"/>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
    .scroller {
        overflow: scroll;
        width: 100px;
        height: 100px;
    }

    .scroller > div {
        height: 200px;
        background-image: linear-gradient(#fff,#000);
    }
</style>
</head>
<body>
<div id="testcase1">
  <div style="width: 100px;height: 50px;display: inline-block;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
      <circle cx="80" cy="50" r="50"></circle>
    </svg>
  </div>
  <div class="scroller" style="display: inline-block;"><div></div></div>
  <div style="width: 100px; height: 100px; display: inline-block; position:relative;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
      <circle cx="20" cy="50" r="50"></circle>
    </svg>
  </div>
</div>

<div id="testcase2" style="position:relative; height: 110px;">
  <div style="width: 100px;height: 100px;position:absolute;pointer-events:none;left: 25px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
      <circle cx="75" cy="50" r="50" style="pointer-events: auto;"></circle>
    </svg>
  </div>
  <div class="scroller" style="position: absolute; left: 100px;"><div></div></div>
  <div style="width: 100px;height: 100px; position:absolute;pointer-events:none;left: 175px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
      <circle cx="45" cy="50" r="50" style="pointer-events: auto;"></circle>
    </svg>
  </div>
</div>

<div id="testcase3">
  <div style="width: 100px;height: 50px;display: inline-block;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
      <rect x="25" y="25" width="100" height="50"></rect>
    </svg>
  </div>
  <div class="scroller" style="display: inline-block;"><div></div></div>
  <div style="width: 100px; height: 100px; display: inline-block; position:relative;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
      <rect x="-30" y="25" width="100" height="50"></rect>
    </svg>
  </div>
</div>

<div id="testcase4" style="position:relative; height: 110px;">
  <div style="width: 100px;height: 100px;position:absolute;pointer-events:none;left: 25px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
      <rect x="25" y="25" width="100" height="50" style="pointer-events: auto;"></rect>
    </svg>
  </div>
  <div class="scroller" style="position: absolute; left: 100px;"><div></div></div>
  <div style="width: 100px;height: 100px; position:absolute;pointer-events:none;left: 175px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
      <rect x="-25" y="25" width="100" height="50" style="pointer-events: auto;"></rect>
    </svg>
  </div>
</div>

<div style="width: 40em;">
  Each of the gradients should be scrollable, except where the black stuff on the right cover them.
  The brown square should not prevent scrolling. Similarly, the content on the left (which goes
  underneath the scroller) shouldn't matter.
</div>
<script>

async function test() {
  var config = getHitTestConfig();
  var utils = config.utils;

  // layerize the scrollable frames
  for (var scroller of document.querySelectorAll(".scroller")) {
    utils.setDisplayPortForElement(0, 0, 100, 200, scroller, 1);
  }
  await promiseApzFlushedRepaints();

  var rootViewId = utils.getViewId(document.scrollingElement);
  for (var testId = 1; testId <= 4; testId++) {
    var target = document.querySelector(`#testcase${testId} .scroller`);
    var scrollerViewId = utils.getViewId(target);
    checkHitResult(hitTest(centerOf(target)),
                   APZHitResultFlags.VISIBLE,
                   scrollerViewId,
                   utils.getLayersId(),
                   `center of scroller in testcase ${testId}`);

    var bounds = target.getBoundingClientRect();
    var verticalScrollbarWidth = bounds.width - target.clientWidth;
    var horizontalScrollbarHeight = bounds.height - target.clientHeight;

    // these points should all hit the target scroller
    checkHitResult(hitTest({x: bounds.x + 1, y: bounds.y + 1}),
                   APZHitResultFlags.VISIBLE,
                   scrollerViewId,
                   utils.getLayersId(),
                   `top left of scroller in testcase ${testId}`);
    checkHitResult(hitTest({x: bounds.x + 1, y: bounds.y + (bounds.height / 2)}),
                   APZHitResultFlags.VISIBLE,
                   scrollerViewId,
                   utils.getLayersId(),
                   `middle left of scroller in testcase ${testId}`);
    checkHitResult(hitTest({x: bounds.x + 1, y: bounds.bottom - horizontalScrollbarHeight - 1}),
                   APZHitResultFlags.VISIBLE,
                   scrollerViewId,
                   utils.getLayersId(),
                   `bottom left (excluding scrollbar) of scroller in testcase ${testId}`);
    if (horizontalScrollbarHeight > 0) {
      checkHitResult(hitTest({x: bounds.x + 1, y: bounds.bottom - 1}),
                     APZHitResultFlags.VISIBLE | APZHitResultFlags.SCROLLBAR,
                     scrollerViewId,
                     utils.getLayersId(),
                     `bottom left of scroller in testcase ${testId}`);
    }

    // With the first two cases (circle masks) WebRender emits dispatch-to-content
    // regions for the right side, so for now we just test for that.
    // Eventually WebRender should be able to stop emitting DTC
    // and we can update this test to be more precise.
    // For the two rectangular test cases we get precise results rather than
    // dispatch-to-content.
    if (testId == 1 || testId == 2) {
      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.y + 1}),
                     APZHitResultFlags.VISIBLE | APZHitResultFlags.IRREGULAR_AREA,
                     rootViewId,
                     utils.getLayersId(),
                     `top right of scroller in testcase ${testId}`);
      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.bottom - horizontalScrollbarHeight - 1}),
                     APZHitResultFlags.VISIBLE | APZHitResultFlags.IRREGULAR_AREA,
                     rootViewId,
                     utils.getLayersId(),
                     `bottom right of scroller in testcase ${testId}`);
    } else {
      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.y + 1}),
                     APZHitResultFlags.VISIBLE,
                     scrollerViewId,
                     utils.getLayersId(),
                     `top right of scroller in testcase ${testId}`);
      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.bottom - horizontalScrollbarHeight - 1}),
                     APZHitResultFlags.VISIBLE,
                     scrollerViewId,
                     utils.getLayersId(),
                     `bottom right of scroller in testcase ${testId}`);
    }

    checkHitResult(hitTest({x: bounds.right - 1, y: bounds.y + (bounds.height / 2)}),
                   APZHitResultFlags.VISIBLE | APZHitResultFlags.IRREGULAR_AREA,
                   rootViewId,
                   utils.getLayersId(),
                   `middle right of scroller in testcase ${testId}`);
  }
}

waitUntilApzStable()
    .then(test)
    .then(subtestDone, subtestFailed);
</script>
</body></html>