Avoid calling scrollingElement() during CSSScrollTimeline constructor

CSSScrollTimelines are created during style updates. It is therefore
a bit uncomfortable that we're calling Document::scrollingElement
via CSSScrollTimeline -> ScrollTimeline -> ResolveScrollSource, since
Document::scrollingElement itself updates style/layout-tree.

Even if it's technically non-fatal, I would like to avoid this call
for sanity purposes. It makes it easier to reason about ScrollTimeline
and container query interaction in subsequent CLs.

For (JS)ScrollTimelines it is still correct to update style and
layout tree, hence we still do that update on the (JS)ScrollTimeline
path.

ScrollTimeline() now accepts an absl::optional<Element*> instead of
a plain Element pointer. When absl::nullopt is passed, this indicates
that the source is "missing" (per [1]) and will be defaulted to
the scrolling element. This change is just to reduce the number of
calls to scrollingElement() / ScrollingElementNoLayout().

The test added in this CL is just to improve test coverage. It does
not represent a bug that's fixed: the test already passed. It will
however fail if the call to UpdateStyleAndLayoutTree in
ScrollTimeline::Create is accidentally removed in the future.

There should be no behavior change in this CL. It is a refactor to make
future work on ScrollTimeline/@container easier.

[1] https://drafts.csswg.org/scroll-animations-1/#dom-scrolltimeline-scrolltimeline

Bug: 1180159,1189101
Change-Id: I55b47b3866dca83a87eb373351875d0fae613b4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2910780
Reviewed-by: Kevin Ellis <kevers@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#887805}
diff --git a/scroll-animations/source-quirks-mode.html b/scroll-animations/source-quirks-mode.html
new file mode 100644
index 0000000..0614509
--- /dev/null
+++ b/scroll-animations/source-quirks-mode.html
@@ -0,0 +1,36 @@
+<!-- Quirks mode -->
+<html>
+<head>
+  <title>ScrollTimeline default source in quirks mode</title>
+  <link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#dom-scrolltimeline-scrolltimeline">
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <style>
+    /* This is just to make it possible for #body1 to be
+       "potentially scrollable".
+
+       https://drafts.csswg.org/cssom-view/#potentially-scrollable */
+    html {
+      overflow: hidden;
+    }
+  </style>
+</head>
+<body id=body1></body>
+<script>
+test(() => {
+  try {
+    assert_equals(document.scrollingElement.id, 'body1');
+    assert_equals(new ScrollTimeline({}).scrollSource, body1);
+
+    // Make #body1 "potentially scrollable". This causes the scrollingElement
+    // of the document to become null.
+    //
+    // https://drafts.csswg.org/cssom-view/#dom-document-scrollingelement
+    body1.style = 'overflow:scroll';
+    assert_equals(new ScrollTimeline({}).scrollSource, null);
+  } finally {
+    body1.style = '';
+  }
+}, 'Style of <body> is reflected in scrollSource attribute in quirks mode');
+</script>
+</html>