Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(dialog): apply modal UA styles and top-layer state

ldm001f5ee6e46f0
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs
index e2bd648b3..39e604da4 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs
@@ -354,6 +354,109 @@ fn popover_user_agent_display_tracks_open_state() {
assert_eq!(result, "none|block|none");
}
+#[test]
+fn dialog_user_agent_colors_follow_its_color_scheme() {
+ let mut vm = new_parsed_test_vm(
+ "https://dialog-user-agent-colors.test/",
+ r#"<!doctype html>
+<style>:root { color: CanvasText; background-color: Canvas }</style>
+<dialog id="default" open></dialog>
+<dialog id="light" open style="color-scheme: only light"></dialog>
+<dialog id="dark" open style="color-scheme: only dark"></dialog>"#,
+ );
+
+ let result = vm
+ .eval(
+ r#"
+(() => {
+ const root = getComputedStyle(document.documentElement);
+ const fallback = getComputedStyle(document.getElementById('default'));
+ const light = getComputedStyle(document.getElementById('light'));
+ const dark = getComputedStyle(document.getElementById('dark'));
+ return JSON.stringify({
+ defaultMatchesRoot:
+ fallback.color === root.color && fallback.backgroundColor === root.backgroundColor,
+ schemesDiffer:
+ light.color !== dark.color && light.backgroundColor !== dark.backgroundColor
+ });
+})()
+"#,
+ )
+ .expect("dialog user-agent colors should evaluate");
+
+ assert_eq!(
+ result,
+ r#"{"defaultMatchesRoot":true,"schemesDiffer":true}"#
+ );
+}
+
+#[test]
+fn modal_dialog_user_agent_visibility_overrides_inheritance() {
+ let mut vm = new_parsed_test_vm(
+ "https://modal-dialog-user-agent-visibility.test/",
+ r#"<!doctype html>
+<div style="visibility: hidden"><dialog id="target">Dialog</dialog></div>"#,
+ );
+
+ let result = vm
+ .eval(
+ r#"
+(() => {
+ const dialog = document.getElementById('target');
+ dialog.show();
+ const values = [getComputedStyle(dialog).visibility];
+ dialog.close();
+
+ dialog.showModal();
+ values.push(getComputedStyle(dialog).visibility);
+ dialog.close();
+
+ dialog.style.visibility = 'hidden';
+ dialog.showModal();
+ values.push(getComputedStyle(dialog).visibility);
+ return values.join('|');
+})()
+"#,
+ )
+ .expect("modal dialog user-agent visibility should evaluate");
+
+ assert_eq!(result, "hidden|visible|hidden");
+}
+
+#[test]
+fn modal_dialog_top_layer_adjusts_non_absolute_positions() {
+ let mut vm = new_parsed_test_vm(
+ "https://modal-dialog-top-layer-position.test/",
+ r#"<!doctype html><dialog id="target"></dialog>"#,
+ );
+
+ let result = vm
+ .eval(
+ r#"
+(() => {
+ const dialog = document.getElementById('target');
+ const values = [];
+ for (const position of ['static', 'relative', 'sticky', 'absolute', 'fixed']) {
+ dialog.style.position = position;
+ values.push(getComputedStyle(dialog).position);
+ dialog.showModal();
+ values.push(getComputedStyle(dialog).position);
+ dialog.close();
+ values.push(getComputedStyle(dialog).position);
+ }
+ return values.join('|');
+})()
+"#,
+ )
+ .expect("modal dialog top-layer position should evaluate");
+
+ assert_eq!(
+ result,
+ "static|absolute|static|relative|absolute|relative|sticky|absolute|sticky|\
+ absolute|absolute|absolute|fixed|fixed|fixed"
+ );
+}
+
#[test]
fn semantic_text_decoration_uses_user_agent_defaults() {
let mut vm = new_parsed_test_vm(
diff --git a/moli-renderer-v8/src/style_engine/ua/html.css b/moli-renderer-v8/src/style_engine/ua/html.css
index f8cca6ec4..f51c1f272 100644
--- a/moli-renderer-v8/src/style_engine/ua/html.css
+++ b/moli-renderer-v8/src/style_engine/ua/html.css
@@ -524,6 +524,11 @@ slot {
display: contents;
}
+dialog {
+ color: CanvasText;
+ background-color: Canvas;
+}
+
dialog:not([open]), [popover]:where(:not(:popover-open)) {
display: none;
}
@@ -532,6 +537,11 @@ dialog[open], [popover]:popover-open {
display: block;
}
+dialog:modal {
+ -servo-top-layer: top;
+ visibility: visible;
+}
+
u, ins {
text-decoration: underline;
}