Lightpanda: the headless browser designed for AI and automation
update style_version change on:
Karl Seguin482d63e89e83
diff --git a/src/browser/EventManager.zig b/src/browser/EventManager.zigindex d4a19cbb4..1049a5102 100644--- a/src/browser/EventManager.zig+++ b/src/browser/EventManager.zig@@ -772,6 +772,9 @@ const ActivationState = struct {prev_radio._checked = true;prev_radio._checked_dirty = true;}+ // Listeners ran between setChecked and here, so `:checked` state+ // built during dispatch has to be stamped as stale.+ frame.styleChanged();return;}diff --git a/src/browser/Frame.zig b/src/browser/Frame.zigindex cb2442a29..41acc3d86 100644--- a/src/browser/Frame.zig+++ b/src/browser/Frame.zig@@ -1052,6 +1052,9 @@ fn scheduleNavigationWithArena(originator: *Frame, arena: *lp.Arena, request_urltry session.navigation.updateEntries(target.url, opts.kind, target, true);}+ // `:target` matches off the fragment, which just changed.+ target.styleChanged();+try target.queueHashChange(old_url, target.url);// don't defer this, the caller is responsible for freeing it on error@@ -2745,7 +2748,7 @@ pub fn removeNode(self: *Frame, parent: *Node, child: *Node, opts: RemoveNodeOpt// so ask it directly whether it's still in the document.if (self.document._active_element) |active| {if (active.asNode().isConnected() == false) {- self.document._active_element = null;+ self.document.setActiveElement(null, self);}}diff --git a/src/browser/tests/element/check_visibility.html b/src/browser/tests/element/check_visibility.htmlindex 8027ec2d1..b9c8b2dd1 100644--- a/src/browser/tests/element/check_visibility.html+++ b/src/browser/tests/element/check_visibility.html@@ -662,3 +662,78 @@shown.remove();}</script>++<script id="memo_focus">+ {+ const style = document.createElement("style");+ style.textContent = "#memo_focus_input:focus + span { display: none; }";+ document.head.appendChild(style);++ const wrap = document.createElement("div");+ wrap.innerHTML = '<input id="memo_focus_input"><span>s</span>';+ document.body.appendChild(wrap);+ const input = wrap.querySelector("input");+ const span = wrap.querySelector("span");++ testing.expectEqual(true, span.checkVisibility());+ input.focus();+ testing.expectEqual(false, span.checkVisibility());+ input.blur();+ testing.expectEqual(true, span.checkVisibility());++ wrap.remove();+ style.remove();+ }+</script>++<script id="memo_checked_rollback">+ {+ const style = document.createElement("style");+ style.textContent = "#memo_checked_input:checked + span { display: none; }";+ document.head.appendChild(style);++ const wrap = document.createElement("div");+ wrap.innerHTML = '<input type="checkbox" id="memo_checked_input"><span>s</span>';+ document.body.appendChild(wrap);+ const input = wrap.querySelector("input");+ const span = wrap.querySelector("span");++ let during = null;+ input.addEventListener("click", (e) => {+ during = span.checkVisibility();+ e.preventDefault();+ });++ testing.expectEqual(true, span.checkVisibility());+ input.click();+ // the toggle is visible to listeners, then rolled back by preventDefault+ testing.expectEqual(false, during);+ testing.expectEqual(false, input.checked);+ testing.expectEqual(true, span.checkVisibility());++ wrap.remove();+ style.remove();+ }+</script>++<script id="memo_target">+ {+ const style = document.createElement("style");+ style.textContent = "#memo_target_anchor:target + span { display: none; }";+ document.head.appendChild(style);++ const wrap = document.createElement("div");+ wrap.innerHTML = '<div id="memo_target_anchor"></div><span>s</span>';+ document.body.appendChild(wrap);+ const span = wrap.querySelector("span");++ testing.expectEqual(true, span.checkVisibility());+ location.hash = "#memo_target_anchor";+ testing.expectEqual(false, span.checkVisibility());+ location.hash = "#memo_target_other";+ testing.expectEqual(true, span.checkVisibility());++ wrap.remove();+ style.remove();+ }+</script>diff --git a/src/browser/webapi/Document.zig b/src/browser/webapi/Document.zigindex 81385c763..5da2405de 100644--- a/src/browser/webapi/Document.zig+++ b/src/browser/webapi/Document.zig@@ -764,6 +764,16 @@ pub fn getActiveElement(self: *Document) ?*Element {return self.getDocumentElement();}+/// Focus takes part in the cascade (`:focus`, `:focus-within`), so every write+/// to `_active_element` has to go through here to stamp the style version.+pub fn setActiveElement(self: *Document, element: ?*Element, frame: *Frame) void {+ if (self._active_element == element) {+ return;+ }+ self._active_element = element;+ frame.styleChanged();+}+pub fn getStyleSheets(self: *Document, frame: *Frame) !*StyleSheetList {if (self._style_sheets) |sheets| {return sheets;@@ -1166,7 +1176,7 @@ pub fn open(self: *Document, call_frame: *Frame) !*Document {// reset the documentself._elements_by_id.clearAndFree(frame.arena);- self._active_element = null;+ self.setActiveElement(null, frame);self._open_popovers = .empty;self._style_sheets = null;self._implementation = null;diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zigindex f19fc75f1..eb74f5f64 100644--- a/src/browser/webapi/Element.zig+++ b/src/browser/webapi/Element.zig@@ -1171,7 +1171,7 @@ pub fn focus(self: *Element, frame: *Frame) !void {const new_target = self.asEventTarget();const doc = self.asNode().ownerDocument(frame) orelse frame.document;const old_active = doc._active_element;- doc._active_element = self;+ doc.setActiveElement(self, frame);if (old_active) |old| {if (old == self) {@@ -1204,7 +1204,7 @@ pub fn blur(self: *Element, frame: *Frame) !void {const doc = self.asNode().ownerDocument(frame) orelse frame.document;if (doc._active_element != self) return;- doc._active_element = null;+ doc.setActiveElement(null, frame);const FocusEvent = @import("event/FocusEvent.zig");const old_target = self.asEventTarget();diff --git a/src/browser/webapi/History.zig b/src/browser/webapi/History.zigindex 25bc81cdf..267595c95 100644--- a/src/browser/webapi/History.zig+++ b/src/browser/webapi/History.zig@@ -64,6 +64,8 @@ pub fn pushState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8frame.url = url;// setHref == reinitializing.try frame.window._location._url.setHref(url, &frame.js.execution);+ // `:target` matches off the fragment, which the new URL can change.+ frame.styleChanged();session.notification.dispatch(.frame_navigated_within_document, &.{.url = url,@@ -86,6 +88,8 @@ pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]constframe.url = url;// setHref == reinitializing.try frame.window._location._url.setHref(url, &frame.js.execution);+ // `:target` matches off the fragment, which the new URL can change.+ frame.styleChanged();session.notification.dispatch(.frame_navigated_within_document, &.{.url = url,