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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Test: scroll tracking for ::scroll-markers when scroll containers has large padding </title>
<link rel="help" href="https://drafts.csswg.org/css-overflow-5/#scroll-marker-pseudo">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="support/scroll-marker-support.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
</head>
<body>
<style>
.wrapper {
display: grid;
justify-content: center;
}
.carousel {
display: grid;
grid-auto-flow: column;
width: 1600px;
height: 512px;
overflow-x: scroll;
scroll-snap-type: x mandatory;
list-style-type: none;
scroll-behavior: smooth;
border: solid 2px grey;
padding-top: 10%;
text-align: center;
counter-set: markeridx;
&>.item {
scroll-snap-align: center;
height: 80%;
width: 318px;
border: 1px solid;
place-content: center;
&::scroll-marker {
content: counter(markeridx);
counter-increment: markeridx;
align-content: center;
text-align: center;
width: 35px;
height: 35px;
border: 3px solid gray;
border-radius: 50%;
margin: 3px;
background-color: red;
}
&::scroll-marker:target-current {
background-color: green;
}
}
&>.padding {
width: 1600px;
height: 90%;
border: solid 1px green;
}
scroll-marker-group: after;
&::scroll-marker-group {
height: 45px;
display: flex;
align-items: center;
justify-content: center;
border: solid 1px black;
border-radius: 30px;
}
}
</style>
<div class="wrapper">
<div class="carousel" id="carousel">
<div class="padding"></div>
<div class="item" tabindex=0>1</div>
<div class="item" tabindex=0>2</div>
<div class="item" tabindex=0>3</div>
<div class="item" tabindex=0>4</div>
<div class="item" tabindex=0>5</div>
<div class="item" tabindex=0>6</div>
<div class="item" tabindex=0>7</div>
<div class="item" tabindex=0>8</div>
<div class="item" tabindex=0>9</div>
<div class="item" tabindex=0>10</div>
<div class="item" tabindex=0>11</div>
<div class="item" tabindex=0>12</div>
<div class="item" tabindex=0>13</div>
<div class="item" tabindex=0>14</div>
<div class="item" tabindex=0>15</div>
<div class="item" tabindex=0>16</div>
<div class="padding"></div>
</div>
</div>
<script>
const carousel = document.getElementById("carousel");
const items = carousel.querySelectorAll(".item");
RED = "rgb(255, 0, 0)";
GREEN = "rgb(0, 128, 0)";
let current_expected_marker_idx = null;
let current_request_id = null;
function watchFrames() {
current_request_id = requestAnimationFrame(() => {
if (current_expected_marker_idx !== null) {
verifySelectedMarker(current_expected_marker_idx, items, GREEN, RED);
}
current_request_id = requestAnimationFrame(watchFrames);
});
}
// The distribute range[1] is a portion of the scroll range in which we
// determine the active scroll-marker in a way that accounts for unreachable
// scroll targets[2].
// This tests what happens when we scroll into the distribute range in a
// layout scenario where (because of the padding) there is no scroll target
// in the distribute range.
// [1] https://drafts.csswg.org/css-overflow-5/#:~:text=distribute%20range
// [2] https://github.com/w3c/csswg-drafts/issues/11165
async function scroll_test(t, scrollAmount) {
await waitForCompositorCommit();
const initial_offset = carousel.scrollLeft;
// Watch every frame, verifying the selected marker.
watchFrames();
const scrollend_promise =
waitForScrollEndFallbackToDelayWithoutScrollEvent(carousel);
const actions_promise = new test_driver.Actions().scroll(0, 0,
scrollAmount, 0, { origin: carousel }).send();
await Promise.all([actions_promise, scrollend_promise]);
assert_equals(carousel.scrollLeft, initial_offset,
"carousel is snapped back to initial position.");
cancelAnimationFrame(current_request_id);
current_expected_marker_idx = null;
current_request_id = null;
}
promise_test(async (t) => {
await waitForCompositorCommit();
current_expected_marker_idx = 0;
// Scroll left padding into view.
const scrollAmount = -carousel.clientWidth;
await scroll_test(t, scrollAmount);
verifySelectedMarker(0, items, GREEN, RED);
}, "scroll-marker selection at left edge with padding");
promise_test(async (t) => {
await waitForCompositorCommit();
await waitForScrollReset(t, carousel, carousel.scrollWidth, 0);
current_expected_marker_idx = 15;
// Scroll right padding into view.
const scrollAmount = carousel.clientWidth;
await scroll_test(t, scrollAmount);
verifySelectedMarker(15, items, GREEN, RED);
}, "scroll-marker selection at right edge with padding");
</script>
</body>
</html>
|