Make dialog user-agent styles apply while in top layer

This makes it so that while the dialog element is doing an exit
animation, its positioning etc. styles from the user-agent stylesheet
still apply so it doesnt jump to a different spot while animating out.
The :modal class is removed during this time which is why it was a
problem before. We also can't just make all dialog elements always have
these styles applied, because then they would also apply to non-modal
dialogs.

Spec: https://github.com/whatwg/html/pull/9387

Fixed: 1451910
Change-Id: I4d2b240ab17879d6cf08f94f32d7c7577e9f53ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4739784
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1179848}
diff --git a/css/css-position/overlay/overlay-transition-dialog-ref.html b/css/css-position/overlay/overlay-transition-dialog-ref.html
new file mode 100644
index 0000000..b0b8d52
--- /dev/null
+++ b/css/css-position/overlay/overlay-transition-dialog-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<dialog>dialog</dialog>
+<script>
+document.querySelector('dialog').showModal();
+document.activeElement.blur();
+</script>
diff --git a/css/css-position/overlay/overlay-transition-dialog.html b/css/css-position/overlay/overlay-transition-dialog.html
new file mode 100644
index 0000000..0e1297c
--- /dev/null
+++ b/css/css-position/overlay/overlay-transition-dialog.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<link rel=author href="mailto:jarhar@chromium.org">
+<link rel=help href="https://drafts.csswg.org/css-position-4/#overlay">
+<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=1451910">
+<link rel=help href="https://github.com/whatwg/html/pull/9387">
+<link rel=match href="overlay-transition-dialog-ref.html">
+
+<dialog>dialog</dialog>
+
+<style>
+dialog.animate {
+  transition: overlay 2s allow-discrete, display 2s allow-discrete;
+}
+</style>
+
+<script>
+const dialog = document.querySelector('dialog');
+dialog.showModal();
+dialog.classList.add('animate');
+dialog.close();
+requestAnimationFrame(() => {
+  requestAnimationFrame(() => {
+    document.documentElement.classList.remove('reftest-wait');
+  });
+});
+</script>