mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Add adoptedStyleSheets property to ShadowRoot, just like Document
Used in github.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<div id="host2"></div>
|
||||
<div id="host3"></div>
|
||||
|
||||
<!-- <script id="attachShadow_open">
|
||||
<script id="attachShadow_open">
|
||||
{
|
||||
const host = $('#host1');
|
||||
const shadow = host.attachShadow({ mode: 'open' });
|
||||
@@ -140,7 +140,7 @@
|
||||
shadow.replaceChildren('New content');
|
||||
testing.expectEqual('New content', shadow.innerHTML);
|
||||
}
|
||||
</script> -->
|
||||
</script>
|
||||
|
||||
<script id="getElementById">
|
||||
{
|
||||
@@ -154,3 +154,16 @@
|
||||
testing.expectEqual(null, shadow.getElementById('nonexistent'));
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<script id=adoptedStyleSheets>
|
||||
{
|
||||
const host = document.createElement('div');
|
||||
const shadow = host.attachShadow({ mode: 'open' });
|
||||
|
||||
const acss = shadow.adoptedStyleSheets;
|
||||
testing.expectEqual(0, acss.length);
|
||||
acss.push(new CSSStyleSheet());
|
||||
testing.expectEqual(1, acss.length);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -40,6 +40,7 @@ _mode: Mode,
|
||||
_host: *Element,
|
||||
_elements_by_id: std.StringHashMapUnmanaged(*Element) = .{},
|
||||
_removed_ids: std.StringHashMapUnmanaged(void) = .{},
|
||||
_adopted_style_sheets: ?js.Object.Global = null,
|
||||
|
||||
pub fn init(host: *Element, mode: Mode, page: *Page) !*ShadowRoot {
|
||||
return page._factory.documentFragment(ShadowRoot{
|
||||
@@ -99,6 +100,20 @@ pub fn getElementById(self: *ShadowRoot, id: []const u8, page: *Page) ?*Element
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn getAdoptedStyleSheets(self: *ShadowRoot, page: *Page) !js.Object.Global {
|
||||
if (self._adopted_style_sheets) |ass| {
|
||||
return ass;
|
||||
}
|
||||
const js_arr = page.js.local.?.newArray(0);
|
||||
const js_obj = js_arr.toObject();
|
||||
self._adopted_style_sheets = try js_obj.persist();
|
||||
return self._adopted_style_sheets.?;
|
||||
}
|
||||
|
||||
pub fn setAdoptedStyleSheets(self: *ShadowRoot, sheets: js.Object) !void {
|
||||
self._adopted_style_sheets = try sheets.persist();
|
||||
}
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(ShadowRoot);
|
||||
|
||||
@@ -121,6 +136,7 @@ pub const JsApi = struct {
|
||||
}
|
||||
return self.getElementById(try value.toZig([]const u8), page);
|
||||
}
|
||||
pub const adoptedStyleSheets = bridge.accessor(ShadowRoot.getAdoptedStyleSheets, ShadowRoot.setAdoptedStyleSheets, .{});
|
||||
};
|
||||
|
||||
const testing = @import("../../testing.zig");
|
||||
|
||||
Reference in New Issue
Block a user