| 12
 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
 
 | <!DOCTYPE html>
<title>position-area to include current scroll position at first layout</title>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#scroll">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-common.js"></script>
<style>
  .pos {
    position: absolute;
    box-sizing: border-box;
    border: solid;
    position-anchor: --anchor;
    width: 50%;
    height: 50%;
    background: cyan;
  }
  #container.thicker > .pos {
    border-width: thick;
  }
</style>
<div id="scrollable" style="position:relative; overflow:hidden; width:500px; height:500px;">
  <div style="width:1000px; height:1000px;">
    <div id="container">
      <div style="height:200px;"></div>
      <div style="anchor-name:--anchor; margin-left:200px; width:100px; height:100px; background:gray;"></div>
      <div id="e1" class="pos" style="position-area:top left;"></div>
      <div id="e2" class="pos" style="position-area:top center;"></div>
      <div id="e3" class="pos" style="position-area:top right;"></div>
      <div id="e4" class="pos" style="position-area:center left;"></div>
      <div id="e5" class="pos" style="position-area:center center;"></div>
      <div id="e6" class="pos" style="position-area:center right;"></div>
      <div id="e7" class="pos" style="position-area:bottom left;"></div>
      <div id="e8" class="pos" style="position-area:bottom center;"></div>
      <div id="e9" class="pos" style="position-area:bottom right;"></div>
    </div>
  </div>
</div>
<script>
  function assert_rects_equal(elm, x, y, width, height) {
    assert_equals(elm.offsetLeft, x, (elm.id + " x"));
    assert_equals(elm.offsetTop, y, (elm.id + " y"));
    assert_equals(elm.offsetWidth, width, (elm.id + " width"));
    assert_equals(elm.offsetHeight, height, (elm.id + " height"));
  }
  function assert_at_initial() {
    assert_rects_equal(e1, 100, 100, 100, 100);
    assert_rects_equal(e2, 225, 100, 50, 100);
    assert_rects_equal(e3, 300, 100, 100, 100);
    assert_rects_equal(e4, 100, 225, 100, 50);
    assert_rects_equal(e5, 225, 225, 50, 50);
    assert_rects_equal(e6, 300, 225, 100, 50);
    assert_rects_equal(e7, 100, 300, 100, 100);
    assert_rects_equal(e8, 225, 300, 50, 100);
    assert_rects_equal(e9, 300, 300, 100, 100);
  }
  function assert_at_40_60() {
    assert_rects_equal(e1, 120, 130, 80, 70);
    assert_rects_equal(e2, 225, 130, 50, 70);
    assert_rects_equal(e3, 300, 130, 120, 70);
    assert_rects_equal(e4, 120, 225, 80, 50);
    assert_rects_equal(e5, 225, 225, 50, 50);
    assert_rects_equal(e6, 300, 225, 120, 50);
    assert_rects_equal(e7, 120, 300, 80, 130);
    assert_rects_equal(e8, 225, 300, 50, 130);
    assert_rects_equal(e9, 300, 300, 120, 130);
  }
  promise_test(async() => {
    assert_at_initial();
  }, "Initial scroll position");
  promise_test(async() => {
    await waitUntilNextAnimationFrame();
    await waitUntilNextAnimationFrame();
    scrollable.scrollTo(40, 60);
    await waitUntilNextAnimationFrame();
    await waitUntilNextAnimationFrame();
    assert_at_initial();
  }, "Scroll to 40,60");
  promise_test(async() => {
    // As long as we're within the same animation frame (and therefore haven't
    // run ResizeObserver events), there will be no anchor recalculation point.
    container.style.display = "flow-root";
    assert_at_initial();
    container.style.display = "none";
    document.body.offsetTop;
    container.style.display = "block";
    assert_at_initial();
  }, "Reattach at 40,60");
  promise_test(async() => {
    container.style.display = "none";
    await waitUntilNextAnimationFrame();
    await waitUntilNextAnimationFrame();
    container.style.display = "block";
    await waitUntilNextAnimationFrame();
    await waitUntilNextAnimationFrame();
    assert_at_40_60();
  }, "Redisplay at 40,60");
  promise_test(async() => {
    scrollable.scrollTo(0, 0);
    container.className = "thicker";
    container.style.display = "block";
    await waitUntilNextAnimationFrame();
    await waitUntilNextAnimationFrame();
    assert_at_40_60();
  }, "Scroll to 0,0 and relayout");
  promise_test(async() => {
    container.style.display = "none";
    await waitUntilNextAnimationFrame();
    container.style.display = "block";
    await waitUntilNextAnimationFrame();
    await waitUntilNextAnimationFrame();
    assert_at_initial();
  }, "Redisplay at 0,0");
</script>
 |