File: trigger-scope-add.tentative.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (182 lines) | stat: -rw-r--r-- 6,577 bytes parent folder | download
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
178
179
180
181
182
<!DOCTYPE html>
<html>
  <head>
    <link rel="help" src="https://drafts.csswg.org/css-animations-2/#trigger-scope">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/web-animations/testcommon.js"></script>
    <script src="/dom/events/scrolling/scroll_support.js"></script>
    <script src="support/support.js"></script>
    <script src="support/trigger-scope-support.js"></script>
  </head>
  <body>
    <style>
      @keyframes expand {
        from { transform: scaleX(1) }
        to { transform: scaleX(2) }
      }
      #outerscroller {
        position: relative;
        overflow-y: scroll;
        border: solid 1px;
        height: 400px;
        width: 400px;
      }
      #innerscroller {
        position: relative;
        overflow-y: scroll;
        height: 200px;
        width: 200px;
        border: solid 1px;
        display: block;
      }
      #source {
        position: absolute;
        top: 100%;
        height: 100px;
        width: 100px;
        background-color: blue;
        timeline-trigger: --trigger view() contain;
      }
      .target {
        background-color: red;
        height: 100px;
        width: 100px;
        animation: expand linear 1s both;
        animation-trigger: --trigger play-forwards;
      }

      #inner_target {
        /* Let's it be in view when the trigger source comes into view */
        margin-top: 50%;
      }

      .long {
        width: 50%;
        height: 100%;
      }
    </style>
    <div id="outerscroller">
      <div id="innerscroller">
        <div id="inner_target" class="target">In-scope Target</div>
        <div class="long"></div>
        <div class="long"></div>
      </div>
      <div id="source">SOURCE</div>
      <div id="outer_target" class="target">
        Out-of-scope Target
      </div>
      <div class="long"></div>
      <div class="long"></div>
    </div>

    <script>
      let inner_target = document.getElementById("inner_target");
      let outer_target = document.getElementById("outer_target");
      let source = document.getElementById("source");

      let current_scroller = outerscroller;

      async function scrollToTrigger() {
        return runAndWaitForFrameUpdate(() => {
          source.scrollIntoView({block: "center"});
        });
      }

      async function resetScrollPositionAndElements(test) {
        return waitForScrollReset(test, current_scroller).then(() => {
          // Reset the animations, so we can detect when they trigger again.
          inner_target.getAnimations()[0].pause();
          inner_target.getAnimations()[0].currentTime = 0;

          outer_target.getAnimations()[0].pause();
          outer_target.getAnimations()[0].currentTime = 0;

          // Both inner and outer animations should once again be paused.
          assert_element_animation_state(inner_target, "paused");
          assert_element_animation_state(outer_target, "paused");
          assert_equals(current_scroller.scrollTop, 0, "scroll position reset");
        });
      }

      async function scrollAndAssert(inner_play_state, outer_play_state) {
        return scrollToTrigger().then(() => {
          assert_greater_than(current_scroller.scrollTop, 0, "did scroll");

          // Both the inner and outer targets should be triggered as there is no
          // scope and they are both attached to the trigger.
          assert_element_animation_state(inner_target, inner_play_state);
          assert_element_animation_state(outer_target, outer_play_state);
        });
      }

      promise_test(async(test) => {
        assert_equals(getComputedStyle(innerscroller).triggerScope, "none");
        assert_element_animation_state(inner_target, "paused");
        assert_element_animation_state(outer_target, "paused");

        // Scroll to make the trigger fire.
        // Both the inner and outer targets should be triggered as there is no
        // scope and they are both attached to the trigger.
        await scrollAndAssert(/*inner=*/"running", /*outer=*/"running");

        // Now, insert a scope.
        innerscroller.style.triggerScope = "--trigger";

        await resetScrollPositionAndElements(test);

        // Scroll to make the trigger fire again.
        // Only the outer animation should be triggered as the inner is
        // prevented from seeing the trigger sue to the scope.
        await scrollAndAssert(/*inner=*/"paused", /*outer=*/"running");

        // Now, remove the scope.
        innerscroller.style.triggerScope = "initial";

        await resetScrollPositionAndElements(test);

        // Scroll to make the trigger fire again.
        // Both the inner and outer targets should be triggered as there is no
        // scope and they are both attached to the trigger.
        await scrollAndAssert(/*inner=*/"running", /*outer=*/"running");
      }, "Added scope prevents subtree from searching for external trigger");

      promise_test(async(test) => {
        // Move the source within the scope so that inner_target sees the
        // trigger when the scope is inserted. And set the scroller to watch to
        // innerscroller.
        outerscroller.removeChild(source);
        innerscroller.append(source);
        current_scroller = innerscroller;

        await resetScrollPositionAndElements(test);

        // Scroll to make the trigger fire.
        // Both the inner and outer targets should be triggered as there is no
        // scope and they are both attached to the trigger.
        await scrollAndAssert(/*inner=*/"running", /*outer=*/"running");

        // Now, insert a scope.
        innerscroller.style.triggerScope = "--trigger";

        await resetScrollPositionAndElements(test);

        // Scroll to make the trigger fire again.
        // Only the inner animation should be triggered as the outer is
        // prevented from seeing the trigger due to the scope.
        await scrollAndAssert(/*inner=*/"running", /*outer=*/"paused");

        // Now, remove the scope.
        innerscroller.style.triggerScope = "initial";

        await resetScrollPositionAndElements(test);

        // Scroll to make the trigger fire again.
        // Both the inner and outer targets should be triggered as there is no
        // scope and they are both attached to the trigger.
        await scrollAndAssert(/*inner=*/"running", /*outer=*/"running");
      }, "Added scope prevents external references from finding trigger " +
         "within scope.");
    </script>
  </body>
</html>