Skip to content

Lightpanda: the headless browser designed for AI and automation

dom: skip the text-transform cascade on pages that never declare it

Navid EMAD49b3eee30290
diff --git a/src/browser/StyleManager.zig b/src/browser/StyleManager.zig
index 33ec9efec..94162f177 100644
--- a/src/browser/StyleManager.zig
+++ b/src/browser/StyleManager.zig
@@ -695,6 +695,10 @@ pub fn textTransform(self: *StyleManager, el: *Element) TextTransform {
/// For tree walks that already know the parent's value.
pub fn ownTextTransform(self: *StyleManager, el: *Element) TextTransform {
self.rebuildIfDirty() catch return .inherit;
+ // Most pages declare no text-transform: skip the cascade and the memo.
+ if (!self.text.hasRules() and !el._flags.has_inline_style) {
+ return .inherit;
+ }
return self.text.ownProps(self.arena.allocator(), el, self.frame).text_transform;
}
@@ -809,6 +813,11 @@ fn Group(comptime Spec: type) type {
// inheritedProps' scratch, kept so each walk doesn't reallocate
path: std.ArrayList(struct { el: *Element, own: Cascaded }) = .empty,
+ fn hasRules(self: *const Self) bool {
+ return self.id_rules.count() != 0 or self.class_rules.count() != 0 or
+ self.tag_rules.count() != 0 or self.other_rules.len != 0;
+ }
+
fn capacities(self: *const Self) Capacities {
return .{
.id_rules = self.id_rules.count(),
@@ -2000,6 +2009,25 @@ test "StyleManager: text-transform" {
try testing.htmlRunner("css/text_transform.html", .{});
}
+test "StyleManager: text-transform without rules skips the memo" {
+ const frame = try testing.createFrame();
+ defer testing.test_session.closeAllPages();
+ const sm = &frame._style_manager;
+
+ const div = try frame.window._document.createElement("div", null, frame);
+ try Frame.parse.htmlAsChildren(frame, div.asNode(),
+ \\<p style="text-transform: uppercase"><b><i></i></b></p>
+ );
+ const p = div.asNode().firstChild().?.as(Element);
+ const b = p.asNode().firstChild().?.as(Element);
+ const i = b.asNode().firstChild().?.as(Element);
+
+ // Inherited from the inline declaration; only <p> needs the cascade.
+ try testing.expectEqual(TextTransform.uppercase, sm.textTransform(i));
+ try testing.expectEqual(1, sm.text.memo.count());
+ try testing.expectEqual(TextTransform.none, sm.textTransform(div));
+}
+
test "StyleManager: computeSpecificity: element selector" {
// div -> (0, 0, 1)
const selector = Selector.Selector{