@@ -22,6 +22,8 @@ const parser = @import("../netsurf.zig");
2222const NodeFilter = @import ("node_filter.zig" );
2323const Env = @import ("../env.zig" ).Env ;
2424const Page = @import ("../page.zig" ).Page ;
25+ const Node = @import ("node.zig" ).Node ;
26+ const NodeUnion = @import ("node.zig" ).Union ;
2527
2628// https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
2729pub const TreeWalker = struct {
@@ -55,12 +57,12 @@ pub const TreeWalker = struct {
5557 };
5658 }
5759
58- pub fn get_root (self : * TreeWalker ) * parser.Node {
59- return self .root ;
60+ pub fn get_root (self : * TreeWalker ) ! NodeUnion {
61+ return try Node . toInterface ( self .root ) ;
6062 }
6163
62- pub fn get_currentNode (self : * TreeWalker ) * parser.Node {
63- return self .current_node ;
64+ pub fn get_currentNode (self : * TreeWalker ) ! NodeUnion {
65+ return try Node . toInterface ( self .current_node ) ;
6466 }
6567
6668 pub fn get_whatToShow (self : * TreeWalker ) u32 {
@@ -157,35 +159,35 @@ pub const TreeWalker = struct {
157159 }
158160 }
159161
160- pub fn _firstChild (self : * TreeWalker ) ! ? * parser.Node {
162+ pub fn _firstChild (self : * TreeWalker ) ! ? NodeUnion {
161163 if (try self .firstChild (self .current_node )) | child | {
162164 self .current_node = child ;
163- return child ;
165+ return try Node . toInterface ( child ) ;
164166 }
165167
166168 return null ;
167169 }
168170
169- pub fn _lastChild (self : * TreeWalker ) ! ? * parser.Node {
171+ pub fn _lastChild (self : * TreeWalker ) ! ? NodeUnion {
170172 if (try self .lastChild (self .current_node )) | child | {
171173 self .current_node = child ;
172- return child ;
174+ return try Node . toInterface ( child ) ;
173175 }
174176
175177 return null ;
176178 }
177179
178- pub fn _nextNode (self : * TreeWalker ) ! ? * parser.Node {
180+ pub fn _nextNode (self : * TreeWalker ) ! ? NodeUnion {
179181 if (try self .firstChild (self .current_node )) | child | {
180182 self .current_node = child ;
181- return child ;
183+ return try Node . toInterface ( child ) ;
182184 }
183185
184186 var current = self .current_node ;
185187 while (current != self .root ) {
186188 if (try self .nextSibling (current )) | sibling | {
187189 self .current_node = sibling ;
188- return sibling ;
190+ return try Node . toInterface ( sibling ) ;
189191 }
190192
191193 current = (try parser .nodeParentNode (current )) orelse break ;
@@ -194,25 +196,25 @@ pub const TreeWalker = struct {
194196 return null ;
195197 }
196198
197- pub fn _nextSibling (self : * TreeWalker ) ! ? * parser.Node {
199+ pub fn _nextSibling (self : * TreeWalker ) ! ? NodeUnion {
198200 if (try self .nextSibling (self .current_node )) | sibling | {
199201 self .current_node = sibling ;
200- return sibling ;
202+ return try Node . toInterface ( sibling ) ;
201203 }
202204
203205 return null ;
204206 }
205207
206- pub fn _parentNode (self : * TreeWalker ) ! ? * parser.Node {
208+ pub fn _parentNode (self : * TreeWalker ) ! ? NodeUnion {
207209 if (try self .parentNode (self .current_node )) | parent | {
208210 self .current_node = parent ;
209- return parent ;
211+ return try Node . toInterface ( parent ) ;
210212 }
211213
212214 return null ;
213215 }
214216
215- pub fn _previousNode (self : * TreeWalker ) ! ? * parser.Node {
217+ pub fn _previousNode (self : * TreeWalker ) ! ? NodeUnion {
216218 if (self .current_node == self .root ) return null ;
217219
218220 var current = self .current_node ;
@@ -224,19 +226,19 @@ pub const TreeWalker = struct {
224226 // Get last child if it has one.
225227 if (try self .lastChild (current )) | child | {
226228 self .current_node = child ;
227- return child ;
229+ return try Node . toInterface ( child ) ;
228230 }
229231
230232 // Otherwise, this node is our previous one.
231233 self .current_node = current ;
232- return current ;
234+ return try Node . toInterface ( current ) ;
233235 },
234236 .reject = > continue ,
235237 .skip = > {
236238 // Get last child if it has one.
237239 if (try self .lastChild (current )) | child | {
238240 self .current_node = child ;
239- return child ;
241+ return try Node . toInterface ( child ) ;
240242 }
241243 },
242244 }
@@ -245,17 +247,17 @@ pub const TreeWalker = struct {
245247 if (current != self .root ) {
246248 if (try self .parentNode (current )) | parent | {
247249 self .current_node = parent ;
248- return parent ;
250+ return try Node . toInterface ( parent ) ;
249251 }
250252 }
251253
252254 return null ;
253255 }
254256
255- pub fn _previousSibling (self : * TreeWalker ) ! ? * parser.Node {
257+ pub fn _previousSibling (self : * TreeWalker ) ! ? NodeUnion {
256258 if (try self .previousSibling (self .current_node )) | sibling | {
257259 self .current_node = sibling ;
258- return sibling ;
260+ return try Node . toInterface ( sibling ) ;
259261 }
260262
261263 return null ;
0 commit comments