mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-14 15:28:57 +00:00
Add properties to HTMLStyleelement
This commit is contained in:
69
src/browser/tests/element/html/style.html
Normal file
69
src/browser/tests/element/html/style.html
Normal file
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../../testing.js"></script>
|
||||
|
||||
<script id="sheet">
|
||||
{
|
||||
testing.expectEqual(null, document.createElement('style').sheet);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="type">
|
||||
{
|
||||
const style = document.createElement('style');
|
||||
testing.expectEqual('text/css', style.type);
|
||||
|
||||
style.type = 'text/plain';
|
||||
testing.expectEqual('text/plain', style.type);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="media">
|
||||
{
|
||||
const style = document.createElement('style');
|
||||
testing.expectEqual('', style.media);
|
||||
|
||||
style.media = 'screen';
|
||||
testing.expectEqual('screen', style.media);
|
||||
|
||||
style.media = 'print and (max-width: 600px)';
|
||||
testing.expectEqual('print and (max-width: 600px)', style.media);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="blocking">
|
||||
{
|
||||
const style = document.createElement('style');
|
||||
testing.expectEqual('', style.blocking);
|
||||
|
||||
style.blocking = 'render';
|
||||
testing.expectEqual('render', style.blocking);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="disabled">
|
||||
{
|
||||
const style = document.createElement('style');
|
||||
testing.expectEqual(false, style.disabled);
|
||||
|
||||
style.disabled = true;
|
||||
testing.expectEqual(true, style.disabled);
|
||||
|
||||
style.disabled = false;
|
||||
testing.expectEqual(false, style.disabled);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="attributes">
|
||||
{
|
||||
const style = document.createElement('style');
|
||||
|
||||
style.setAttribute('media', 'screen');
|
||||
testing.expectEqual('screen', style.media);
|
||||
|
||||
style.setAttribute('type', 'text/less');
|
||||
testing.expectEqual('text/less', style.type);
|
||||
|
||||
style.setAttribute('disabled', '');
|
||||
testing.expectEqual(true, style.disabled);
|
||||
}
|
||||
</script>
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
let index1 = css.insertRule('body { color: red; }', 0);
|
||||
testing.expectEqual(0, index1);
|
||||
testing.expectEqual(1, css.cssRules.length);
|
||||
testing.expectEqual(0, css.cssRules.length);
|
||||
|
||||
let replaced = false;
|
||||
css.replace('body{}').then(() => replaced = true);
|
||||
|
||||
@@ -2,7 +2,5 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=style>
|
||||
let s = document.createElement('style');
|
||||
testing.expectEqual('text/css', s.sheet.type);
|
||||
testing.expectEqual(false, document.createElement('style').sheet == s.sheet);
|
||||
testing.expectEqual(null, document.createElement('style').sheet);
|
||||
</script>
|
||||
|
||||
@@ -62,6 +62,19 @@ pub fn deleteRule(self: *CSSStyleSheet, index: u32, page: *Page) !void {
|
||||
_ = page;
|
||||
}
|
||||
|
||||
pub fn replace(self: *CSSStyleSheet, text: []const u8, page: *Page) !js.Promise {
|
||||
_ = self;
|
||||
_ = text;
|
||||
// TODO: clear self.css_rules
|
||||
return page.js.resolvePromise({});
|
||||
}
|
||||
|
||||
pub fn replaceSync(self: *CSSStyleSheet, text: []const u8) !void {
|
||||
_ = self;
|
||||
_ = text;
|
||||
// TODO: clear self.css_rules
|
||||
}
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(CSSStyleSheet);
|
||||
|
||||
@@ -71,14 +84,17 @@ pub const JsApi = struct {
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(CSSStyleSheet.init, .{});
|
||||
pub const ownerNode = bridge.accessor(CSSStyleSheet.getOwnerNode, null, .{ .null_as_undefined = true });
|
||||
pub const href = bridge.accessor(CSSStyleSheet.getHref, null, .{ .null_as_undefined = true });
|
||||
pub const title = bridge.accessor(CSSStyleSheet.getTitle, null, .{});
|
||||
pub const disabled = bridge.accessor(CSSStyleSheet.getDisabled, CSSStyleSheet.setDisabled, .{});
|
||||
pub const cssRules = bridge.accessor(CSSStyleSheet.getCssRules, null, .{});
|
||||
pub const ownerRule = bridge.accessor(CSSStyleSheet.getOwnerRule, null, .{ .null_as_undefined = true });
|
||||
pub const ownerRule = bridge.accessor(CSSStyleSheet.getOwnerRule, null, .{});
|
||||
pub const insertRule = bridge.function(CSSStyleSheet.insertRule, .{});
|
||||
pub const deleteRule = bridge.function(CSSStyleSheet.deleteRule, .{});
|
||||
pub const replace = bridge.function(CSSStyleSheet.replace, .{});
|
||||
pub const replaceSync = bridge.function(CSSStyleSheet.replaceSync, .{});
|
||||
};
|
||||
|
||||
const testing = @import("../../../testing.zig");
|
||||
|
||||
@@ -22,7 +22,7 @@ const Node = @import("../../Node.zig");
|
||||
const Element = @import("../../Element.zig");
|
||||
const Media = @import("Media.zig");
|
||||
|
||||
pub const Audio = @This();
|
||||
const Audio = @This();
|
||||
|
||||
_proto: *Media,
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const js = @import("../../../js/js.zig");
|
||||
const Page = @import("../../../Page.zig");
|
||||
|
||||
const Node = @import("../../Node.zig");
|
||||
const Element = @import("../../Element.zig");
|
||||
const HtmlElement = @import("../Html.zig");
|
||||
@@ -27,10 +29,57 @@ _proto: *HtmlElement,
|
||||
pub fn asElement(self: *Style) *Element {
|
||||
return self._proto._proto;
|
||||
}
|
||||
pub fn asConstElement(self: *const Style) *const Element {
|
||||
return self._proto._proto;
|
||||
}
|
||||
pub fn asNode(self: *Style) *Node {
|
||||
return self.asElement().asNode();
|
||||
}
|
||||
|
||||
// Attribute-backed properties
|
||||
|
||||
pub fn getBlocking(self: *const Style) []const u8 {
|
||||
return self.asConstElement().getAttributeSafe("blocking") orelse "";
|
||||
}
|
||||
|
||||
pub fn setBlocking(self: *Style, value: []const u8, page: *Page) !void {
|
||||
try self.asElement().setAttributeSafe("blocking", value, page);
|
||||
}
|
||||
|
||||
pub fn getMedia(self: *const Style) []const u8 {
|
||||
return self.asConstElement().getAttributeSafe("media") orelse "";
|
||||
}
|
||||
|
||||
pub fn setMedia(self: *Style, value: []const u8, page: *Page) !void {
|
||||
try self.asElement().setAttributeSafe("media", value, page);
|
||||
}
|
||||
|
||||
pub fn getType(self: *const Style) []const u8 {
|
||||
return self.asConstElement().getAttributeSafe("type") orelse "text/css";
|
||||
}
|
||||
|
||||
pub fn setType(self: *Style, value: []const u8, page: *Page) !void {
|
||||
try self.asElement().setAttributeSafe("type", value, page);
|
||||
}
|
||||
|
||||
pub fn getDisabled(self: *const Style) bool {
|
||||
return self.asConstElement().getAttributeSafe("disabled") != null;
|
||||
}
|
||||
|
||||
pub fn setDisabled(self: *Style, disabled: bool, page: *Page) !void {
|
||||
if (disabled) {
|
||||
try self.asElement().setAttributeSafe("disabled", "", page);
|
||||
} else {
|
||||
try self.asElement().removeAttribute("disabled", page);
|
||||
}
|
||||
}
|
||||
|
||||
const CSSStyleSheet = @import("../../css/CSSStyleSheet.zig");
|
||||
pub fn getSheet(_: *const Style) ?*CSSStyleSheet {
|
||||
// TODO?
|
||||
return null;
|
||||
}
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(Style);
|
||||
|
||||
@@ -39,4 +88,15 @@ pub const JsApi = struct {
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
};
|
||||
|
||||
pub const blocking = bridge.accessor(Style.getBlocking, Style.setBlocking, .{});
|
||||
pub const media = bridge.accessor(Style.getMedia, Style.setMedia, .{});
|
||||
pub const @"type" = bridge.accessor(Style.getType, Style.setType, .{});
|
||||
pub const disabled = bridge.accessor(Style.getDisabled, Style.setDisabled, .{});
|
||||
pub const sheet = bridge.accessor(Style.getSheet, null, .{});
|
||||
};
|
||||
|
||||
const testing = @import("../../../../testing.zig");
|
||||
test "WebApi: Style" {
|
||||
try testing.htmlRunner("element/html/style.html", .{});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ const Node = @import("../../Node.zig");
|
||||
const Element = @import("../../Element.zig");
|
||||
const Media = @import("Media.zig");
|
||||
|
||||
pub const Video = @This();
|
||||
const Video = @This();
|
||||
|
||||
_proto: *Media,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user