Skip to content

Commit d00084d

Browse files
committed
import html_element
1 parent f12e9b6 commit d00084d

File tree

10 files changed

+42
-40
lines changed

10 files changed

+42
-40
lines changed

src/browser/dom/character_data.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub const CharacterData = struct {
101101
// netsurf's CharacterData (text, comment) doesn't implement the
102102
// dom_node_get_attributes and thus will crash if we try to call nodeIsEqualNode.
103103
pub fn _isEqualNode(self: *parser.CharacterData, other_node: *parser.Node) !bool {
104-
if (try parser.nodeType(@ptrCast(self)) != try parser.nodeType(other_node)) {
104+
if (try parser.nodeType(@alignCast(@ptrCast(self))) != try parser.nodeType(other_node)) {
105105
return false;
106106
}
107107

src/browser/dom/document.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ pub const Document = struct {
244244
}
245245

246246
pub fn get_activeElement(self: *parser.Document, page: *Page) !?ElementUnion {
247-
const state = try page.getOrCreateNodeState(@ptrCast(self));
247+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
248248
if (state.active_element) |ae| {
249249
return try Element.toInterface(ae);
250250
}
251251

252252
if (try parser.documentHTMLBody(page.window.document)) |body| {
253-
return try Element.toInterface(@ptrCast(body));
253+
return try Element.toInterface(@alignCast(@ptrCast(body)));
254254
}
255255

256256
return get_documentElement(self);
@@ -261,7 +261,7 @@ pub const Document = struct {
261261
// we could look for the "disabled" attribute, but that's only meaningful
262262
// on certain types, and libdom's vtable doesn't seem to expose this.
263263
pub fn setFocus(self: *parser.Document, e: *parser.ElementHTML, page: *Page) !void {
264-
const state = try page.getOrCreateNodeState(@ptrCast(self));
264+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
265265
state.active_element = @ptrCast(e);
266266
}
267267
};

src/browser/dom/node.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub const Node = struct {
496496
fn toNode(self: NodeOrText, doc: *parser.Document) !*parser.Node {
497497
return switch (self) {
498498
.node => |n| n,
499-
.text => |txt| @ptrCast(try parser.documentCreateTextNode(doc, txt)),
499+
.text => |txt| @alignCast(@ptrCast(try parser.documentCreateTextNode(doc, txt))),
500500
};
501501
}
502502

src/browser/html/document.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub const HTMLDocument = struct {
184184
}
185185

186186
pub fn get_readyState(self: *parser.DocumentHTML, page: *Page) ![]const u8 {
187-
const state = try page.getOrCreateNodeState(@ptrCast(self));
187+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
188188
return @tagName(state.ready_state);
189189
}
190190

@@ -263,7 +263,7 @@ pub const HTMLDocument = struct {
263263
}
264264

265265
pub fn documentIsLoaded(self: *parser.DocumentHTML, page: *Page) !void {
266-
const state = try page.getOrCreateNodeState(@ptrCast(self));
266+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
267267
state.ready_state = .interactive;
268268

269269
const evt = try parser.eventCreate();
@@ -278,7 +278,7 @@ pub const HTMLDocument = struct {
278278
}
279279

280280
pub fn documentIsComplete(self: *parser.DocumentHTML, page: *Page) !void {
281-
const state = try page.getOrCreateNodeState(@ptrCast(self));
281+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
282282
state.ready_state = .complete;
283283
}
284284
};

src/browser/html/elements.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub const HTMLElement = struct {
133133
try Node.removeChildren(n);
134134

135135
// attach the text node.
136-
_ = try parser.nodeAppendChild(n, @as(*parser.Node, @ptrCast(t)));
136+
_ = try parser.nodeAppendChild(n, @as(*parser.Node, @alignCast(@ptrCast(t))));
137137
}
138138

139139
pub fn _click(e: *parser.ElementHTML) !void {
@@ -245,7 +245,7 @@ pub const HTMLAnchorElement = struct {
245245
}
246246

247247
inline fn url(self: *parser.Anchor, page: *Page) !URL {
248-
return URL.constructor(.{ .element = @ptrCast(self) }, null, page); // TODO inject base url
248+
return URL.constructor(.{ .element = @alignCast(@ptrCast(self)) }, null, page); // TODO inject base url
249249
}
250250

251251
// TODO return a disposable string
@@ -945,22 +945,22 @@ pub const HTMLScriptElement = struct {
945945
}
946946

947947
pub fn get_onload(self: *parser.Script, page: *Page) !?Env.Function {
948-
const state = page.getNodeState(@ptrCast(self)) orelse return null;
948+
const state = page.getNodeState(@alignCast(@ptrCast(self))) orelse return null;
949949
return state.onload;
950950
}
951951

952952
pub fn set_onload(self: *parser.Script, function: ?Env.Function, page: *Page) !void {
953-
const state = try page.getOrCreateNodeState(@ptrCast(self));
953+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
954954
state.onload = function;
955955
}
956956

957957
pub fn get_onerror(self: *parser.Script, page: *Page) !?Env.Function {
958-
const state = page.getNodeState(@ptrCast(self)) orelse return null;
958+
const state = page.getNodeState(@alignCast(@ptrCast(self))) orelse return null;
959959
return state.onerror;
960960
}
961961

962962
pub fn set_onerror(self: *parser.Script, function: ?Env.Function, page: *Page) !void {
963-
const state = try page.getOrCreateNodeState(@ptrCast(self));
963+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
964964
state.onerror = function;
965965
}
966966
};

src/browser/html/select.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub const HTMLSelectElement = struct {
5656
}
5757

5858
pub fn get_selectedIndex(select: *parser.Select, page: *Page) !i32 {
59-
const state = try page.getOrCreateNodeState(@ptrCast(select));
59+
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(select)));
6060
const selected_index = try parser.selectGetSelectedIndex(select);
6161

6262
// See the explicit_index_set field documentation
@@ -75,7 +75,7 @@ pub const HTMLSelectElement = struct {
7575
// Libdom's dom_html_select_select_set_selected_index will crash if index
7676
// is out of range, and it doesn't properly unset options
7777
pub fn set_selectedIndex(select: *parser.Select, index: i32, page: *Page) !void {
78-
var state = try page.getOrCreateNodeState(@ptrCast(select));
78+
var state = try page.getOrCreateNodeState(@alignCast(@ptrCast(select)));
7979
state.explicit_index_set = true;
8080

8181
const options = try parser.selectGetOptions(select);

src/browser/netsurf.zig

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const c = @cImport({
2626
@cInclude("events/event.h");
2727
@cInclude("events/mouse_event.h");
2828
@cInclude("utils/validate.h");
29+
@cInclude("html/html_element.h");
30+
@cInclude("html/html_document.h");
2931
});
3032

3133
const mimalloc = @import("mimalloc.zig");
@@ -550,7 +552,7 @@ pub fn mutationEventRelatedNode(evt: *MutationEvent) !?*Node {
550552
const err = c._dom_mutation_event_get_related_node(evt, &n);
551553
try DOMErr(err);
552554
if (n == null) return null;
553-
return @as(*Node, @ptrCast(n));
555+
return @as(*Node, @alignCast(@ptrCast(n)));
554556
}
555557

556558
// EventListener
@@ -565,7 +567,7 @@ fn eventListenerGetData(lst: *EventListener) ?*anyopaque {
565567
pub const EventTarget = c.dom_event_target;
566568

567569
pub fn eventTargetToNode(et: *EventTarget) *Node {
568-
return @as(*Node, @ptrCast(et));
570+
return @as(*Node, @alignCast(@ptrCast(et)));
569571
}
570572

571573
fn eventTargetVtable(et: *EventTarget) c.dom_event_target_vtable {
@@ -894,7 +896,7 @@ pub fn nodeListItem(nodeList: *NodeList, index: u32) !?*Node {
894896
const err = c._dom_nodelist_item(nodeList, index, &n);
895897
try DOMErr(err);
896898
if (n == null) return null;
897-
return @as(*Node, @ptrCast(n));
899+
return @as(*Node, @alignCast(@ptrCast(n)));
898900
}
899901

900902
// NodeExternal is the libdom public representation of a Node.
@@ -1323,7 +1325,7 @@ fn characterDataVtable(data: *CharacterData) c.dom_characterdata_vtable {
13231325
}
13241326

13251327
pub inline fn characterDataToNode(cdata: *CharacterData) *Node {
1326-
return @as(*Node, @ptrCast(cdata));
1328+
return @as(*Node, @alignCast(@ptrCast(cdata)));
13271329
}
13281330

13291331
pub fn characterDataData(cdata: *CharacterData) ![]const u8 {
@@ -1408,7 +1410,7 @@ pub const ProcessingInstruction = c.dom_processing_instruction;
14081410

14091411
// processingInstructionToNode is an helper to convert an ProcessingInstruction to a node.
14101412
pub inline fn processingInstructionToNode(pi: *ProcessingInstruction) *Node {
1411-
return @as(*Node, @ptrCast(pi));
1413+
return @as(*Node, @alignCast(@ptrCast(pi)));
14121414
}
14131415

14141416
pub fn processInstructionCopy(pi: *ProcessingInstruction) !*ProcessingInstruction {
@@ -1463,7 +1465,7 @@ pub fn attributeGetOwnerElement(a: *Attribute) !?*Element {
14631465

14641466
// attributeToNode is an helper to convert an attribute to a node.
14651467
pub inline fn attributeToNode(a: *Attribute) *Node {
1466-
return @as(*Node, @ptrCast(a));
1468+
return @as(*Node, @alignCast(@ptrCast(a)));
14671469
}
14681470

14691471
// Element
@@ -1601,7 +1603,7 @@ pub fn elementHasClass(elem: *Element, class: []const u8) !bool {
16011603

16021604
// elementToNode is an helper to convert an element to a node.
16031605
pub inline fn elementToNode(e: *Element) *Node {
1604-
return @as(*Node, @ptrCast(e));
1606+
return @as(*Node, @alignCast(@ptrCast(e)));
16051607
}
16061608

16071609
// TokenList
@@ -1685,14 +1687,14 @@ pub fn elementHTMLGetTagType(elem_html: *ElementHTML) !Tag {
16851687

16861688
// scriptToElt is an helper to convert an script to an element.
16871689
pub inline fn scriptToElt(s: *Script) *Element {
1688-
return @as(*Element, @ptrCast(s));
1690+
return @as(*Element, @alignCast(@ptrCast(s)));
16891691
}
16901692

16911693
// HTMLAnchorElement
16921694

16931695
// anchorToNode is an helper to convert an anchor to a node.
16941696
pub inline fn anchorToNode(a: *Anchor) *Node {
1695-
return @as(*Node, @ptrCast(a));
1697+
return @as(*Node, @alignCast(@ptrCast(a)));
16961698
}
16971699

16981700
pub fn anchorGetTarget(a: *Anchor) ![]const u8 {
@@ -1837,7 +1839,7 @@ pub const OptionCollection = c.dom_html_options_collection;
18371839
pub const DocumentFragment = c.dom_document_fragment;
18381840

18391841
pub inline fn documentFragmentToNode(doc: *DocumentFragment) *Node {
1840-
return @as(*Node, @ptrCast(doc));
1842+
return @as(*Node, @alignCast(@ptrCast(doc)));
18411843
}
18421844

18431845
pub fn documentFragmentBodyChildren(doc: *DocumentFragment) !?*NodeList {
@@ -1947,7 +1949,7 @@ pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) !*Document
19471949
if (title) |t| {
19481950
const htitle = try documentCreateElement(doc, "title");
19491951
const txt = try documentCreateTextNode(doc, t);
1950-
_ = try nodeAppendChild(elementToNode(htitle), @as(*Node, @ptrCast(txt)));
1952+
_ = try nodeAppendChild(elementToNode(htitle), @as(*Node, @alignCast(@ptrCast(txt))));
19511953
_ = try nodeAppendChild(elementToNode(head), elementToNode(htitle));
19521954
}
19531955

@@ -1965,7 +1967,7 @@ fn documentVtable(doc: *Document) c.dom_document_vtable {
19651967
}
19661968

19671969
pub inline fn documentToNode(doc: *Document) *Node {
1968-
return @as(*Node, @ptrCast(doc));
1970+
return @as(*Node, @alignCast(@ptrCast(doc)));
19691971
}
19701972

19711973
pub inline fn documentGetElementById(doc: *Document, id: []const u8) !?*Element {
@@ -2103,15 +2105,15 @@ pub inline fn documentImportNode(doc: *Document, node: *Node, deep: bool) !*Node
21032105
const nodeext = toNodeExternal(Node, node);
21042106
const err = documentVtable(doc).dom_document_import_node.?(doc, nodeext, deep, &res);
21052107
try DOMErr(err);
2106-
return @as(*Node, @ptrCast(res));
2108+
return @as(*Node, @alignCast(@ptrCast(res)));
21072109
}
21082110

21092111
pub inline fn documentAdoptNode(doc: *Document, node: *Node) !*Node {
21102112
var res: NodeExternal = undefined;
21112113
const nodeext = toNodeExternal(Node, node);
21122114
const err = documentVtable(doc).dom_document_adopt_node.?(doc, nodeext, &res);
21132115
try DOMErr(err);
2114-
return @as(*Node, @ptrCast(res));
2116+
return @as(*Node, @alignCast(@ptrCast(res)));
21152117
}
21162118

21172119
pub inline fn documentCreateAttribute(doc: *Document, name: []const u8) !*Attribute {
@@ -2146,7 +2148,7 @@ pub const DocumentHTML = c.dom_html_document;
21462148

21472149
// documentHTMLToNode is an helper to convert a documentHTML to an node.
21482150
pub inline fn documentHTMLToNode(doc: *DocumentHTML) *Node {
2149-
return @as(*Node, @ptrCast(doc));
2151+
return @as(*Node, @alignCast(@ptrCast(doc)));
21502152
}
21512153

21522154
fn documentHTMLVtable(doc_html: *DocumentHTML) c.dom_html_document_vtable {
@@ -2291,7 +2293,7 @@ pub inline fn documentHTMLBody(doc_html: *DocumentHTML) !?*Body {
22912293
}
22922294

22932295
pub inline fn bodyToElement(body: *Body) *Element {
2294-
return @as(*Element, @ptrCast(body));
2296+
return @as(*Element, @alignCast(@ptrCast(body)));
22952297
}
22962298

22972299
pub inline fn documentHTMLSetBody(doc_html: *DocumentHTML, elt: ?*ElementHTML) !void {
@@ -2330,7 +2332,7 @@ pub inline fn documentHTMLSetTitle(doc: *DocumentHTML, v: []const u8) !void {
23302332

23312333
pub fn documentHTMLSetCurrentScript(doc: *DocumentHTML, script: ?*Script) !void {
23322334
var s: ?*ElementHTML = null;
2333-
if (script != null) s = @ptrCast(script.?);
2335+
if (script != null) s = @alignCast(@ptrCast(script.?));
23342336
const err = documentHTMLVtable(doc).set_current_script.?(doc, s);
23352337
try DOMErr(err);
23362338
}
@@ -2759,7 +2761,7 @@ pub fn inputSetType(input: *Input, type_: []const u8) !void {
27592761
}
27602762
}
27612763
const new_type = if (found) type_ else "text";
2762-
try elementSetAttribute(@ptrCast(input), "type", new_type);
2764+
try elementSetAttribute(@alignCast(@ptrCast(input)), "type", new_type);
27632765
}
27642766

27652767
pub fn inputGetValue(input: *Input) ![]const u8 {

src/browser/page.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,13 @@ pub const Page = struct {
633633
const transfer_arena = self.session.transfer_arena;
634634
var form_data = try FormData.fromForm(form, submitter, self);
635635

636-
const encoding = try parser.elementGetAttribute(@ptrCast(form), "enctype");
636+
const encoding = try parser.elementGetAttribute(@alignCast(@ptrCast(form)), "enctype");
637637

638638
var buf: std.ArrayListUnmanaged(u8) = .empty;
639639
try form_data.write(encoding, buf.writer(transfer_arena));
640640

641-
const method = try parser.elementGetAttribute(@ptrCast(form), "method") orelse "";
642-
var action = try parser.elementGetAttribute(@ptrCast(form), "action") orelse self.url.raw;
641+
const method = try parser.elementGetAttribute(@alignCast(@ptrCast(form)), "method") orelse "";
642+
var action = try parser.elementGetAttribute(@alignCast(@ptrCast(form)), "action") orelse self.url.raw;
643643

644644
var opts = NavigateOpts{
645645
.reason = .form,

src/browser/xhr/form_data.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn collectSelectValues(arena: Allocator, select: *parser.Select, name: []const u
216216
if (is_multiple == false) {
217217
const option = try parser.optionCollectionItem(options, @intCast(selected_index));
218218

219-
if (try parser.elementGetAttribute(@ptrCast(option), "disabled") != null) {
219+
if (try parser.elementGetAttribute(@alignCast(@ptrCast(option)), "disabled") != null) {
220220
return;
221221
}
222222
const value = try parser.optionGetValue(option);
@@ -228,7 +228,7 @@ fn collectSelectValues(arena: Allocator, select: *parser.Select, name: []const u
228228
// we can go directly to the first one
229229
for (@intCast(selected_index)..len) |i| {
230230
const option = try parser.optionCollectionItem(options, @intCast(i));
231-
if (try parser.elementGetAttribute(@ptrCast(option), "disabled") != null) {
231+
if (try parser.elementGetAttribute(@alignCast(@ptrCast(option)), "disabled") != null) {
232232
continue;
233233
}
234234

src/cdp/domains/dom.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn getNode(arena: Allocator, browser_context: anytype, node_id: ?Node.Id, backen
368368
if (object_id) |object_id_| {
369369
// Retrieve the object from which ever context it is in.
370370
const parser_node = try browser_context.inspector.getNodePtr(arena, object_id_);
371-
return try browser_context.node_registry.register(@ptrCast(parser_node));
371+
return try browser_context.node_registry.register(@alignCast(@ptrCast(parser_node)));
372372
}
373373
return error.MissingParams;
374374
}

0 commit comments

Comments
 (0)