mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
avoid useless priority parsing in CSSStyleDeclaration
This commit is contained in:
@@ -46,8 +46,7 @@ pub fn init(element: ?*Element, is_computed: bool, page: *Page) !*CSSStyleDeclar
|
||||
if (el.getAttributeSafe(comptime .wrap("style"))) |attr_value| {
|
||||
var it = CssParser.parseDeclarationsList(attr_value);
|
||||
while (it.next()) |declaration| {
|
||||
const priority: ?[]const u8 = if (declaration.important) "important" else null;
|
||||
try self.setPropertyImpl(declaration.name, declaration.value, priority, page);
|
||||
try self.setPropertyImpl(declaration.name, declaration.value, declaration.important, page);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,20 +92,8 @@ pub fn getPropertyPriority(self: *const CSSStyleDeclaration, property_name: []co
|
||||
}
|
||||
|
||||
pub fn setProperty(self: *CSSStyleDeclaration, property_name: []const u8, value: []const u8, priority_: ?[]const u8, page: *Page) !void {
|
||||
try self.setPropertyImpl(property_name, value, priority_, page);
|
||||
try self.syncStyleAttribute(page);
|
||||
}
|
||||
|
||||
fn setPropertyImpl(self: *CSSStyleDeclaration, property_name: []const u8, value: []const u8, priority_: ?[]const u8, page: *Page) !void {
|
||||
if (value.len == 0) {
|
||||
_ = try self.removePropertyImpl(property_name, page);
|
||||
return;
|
||||
}
|
||||
|
||||
const normalized = normalizePropertyName(property_name, &page.buf);
|
||||
const priority = priority_ orelse "";
|
||||
|
||||
// Validate priority
|
||||
const priority = priority_ orelse "";
|
||||
const important = if (priority.len > 0) blk: {
|
||||
if (!std.ascii.eqlIgnoreCase(priority, "important")) {
|
||||
return;
|
||||
@@ -114,6 +101,19 @@ fn setPropertyImpl(self: *CSSStyleDeclaration, property_name: []const u8, value:
|
||||
break :blk true;
|
||||
} else false;
|
||||
|
||||
try self.setPropertyImpl(property_name, value, important, page);
|
||||
|
||||
try self.syncStyleAttribute(page);
|
||||
}
|
||||
|
||||
fn setPropertyImpl(self: *CSSStyleDeclaration, property_name: []const u8, value: []const u8, important: bool, page: *Page) !void {
|
||||
if (value.len == 0) {
|
||||
_ = try self.removePropertyImpl(property_name, page);
|
||||
return;
|
||||
}
|
||||
|
||||
const normalized = normalizePropertyName(property_name, &page.buf);
|
||||
|
||||
// Find existing property
|
||||
if (self.findProperty(normalized)) |existing| {
|
||||
existing._value = try String.init(page.arena, value, .{});
|
||||
@@ -162,7 +162,8 @@ pub fn getFloat(self: *const CSSStyleDeclaration, page: *Page) []const u8 {
|
||||
}
|
||||
|
||||
pub fn setFloat(self: *CSSStyleDeclaration, value_: ?[]const u8, page: *Page) !void {
|
||||
return self.setProperty("float", value_ orelse "", null, page);
|
||||
try self.setPropertyImpl("float", value_ orelse "", false, page);
|
||||
try self.syncStyleAttribute(page);
|
||||
}
|
||||
|
||||
pub fn getCssText(self: *const CSSStyleDeclaration, page: *Page) ![]const u8 {
|
||||
@@ -189,8 +190,7 @@ pub fn setCssText(self: *CSSStyleDeclaration, text: []const u8, page: *Page) !vo
|
||||
// Parse and set new properties
|
||||
var it = CssParser.parseDeclarationsList(text);
|
||||
while (it.next()) |declaration| {
|
||||
const priority: ?[]const u8 = if (declaration.important) "important" else null;
|
||||
try self.setPropertyImpl(declaration.name, declaration.value, priority, page);
|
||||
try self.setPropertyImpl(declaration.name, declaration.value, declaration.important, page);
|
||||
}
|
||||
try self.syncStyleAttribute(page);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user