@@ -112,11 +112,9 @@ pub const HTMLElement = struct {
112112 pub const prototype = * Element ;
113113 pub const subtype = .node ;
114114
115- style : CSSStyleDeclaration = .empty ,
116-
117115 pub fn get_style (e : * parser.ElementHTML , page : * Page ) ! * CSSStyleDeclaration {
118- const self = try page .getOrCreateNodeWrapper ( HTMLElement , @ptrCast (e ));
119- return & self .style ;
116+ const state = try page .getOrCreateNodeState ( @ptrCast (e ));
117+ return & state .style ;
120118 }
121119
122120 pub fn get_innerText (e : * parser.ElementHTML ) ! []const u8 {
@@ -159,16 +157,9 @@ pub const HTMLElement = struct {
159157 return ;
160158 }
161159
162- const root_node = try parser .nodeGetRootNode (@ptrCast (e ));
163-
164160 const Document = @import ("../dom/document.zig" ).Document ;
165- const document = try page .getOrCreateNodeWrapper (Document , @ptrCast (root_node ));
166-
167- // TODO: some elements can't be focused, like if they're disabled
168- // but there doesn't seem to be a generic way to check this. For example
169- // we could look for the "disabled" attribute, but that's only meaningful
170- // on certain types, and libdom's vtable doesn't seem to expose this.
171- document .active_element = @ptrCast (e );
161+ const root_node = try parser .nodeGetRootNode (@ptrCast (e ));
162+ try Document .setFocus (@ptrCast (root_node ), e , page );
172163 }
173164};
174165
@@ -852,9 +843,6 @@ pub const HTMLScriptElement = struct {
852843 pub const prototype = * HTMLElement ;
853844 pub const subtype = .node ;
854845
855- onload : ? Env.Function = null ,
856- onerror : ? Env.Function = null ,
857-
858846 pub fn get_src (self : * parser.Script ) ! ? []const u8 {
859847 return try parser .elementGetAttribute (
860848 parser .scriptToElt (self ),
@@ -964,24 +952,24 @@ pub const HTMLScriptElement = struct {
964952 return try parser .elementRemoveAttribute (parser .scriptToElt (self ), "nomodule" );
965953 }
966954
967- pub fn get_onload (script : * parser.Script , page : * Page ) ! ? Env.Function {
968- const self = page .getNodeWrapper ( HTMLScriptElement , @ptrCast (script )) orelse return null ;
969- return self .onload ;
955+ pub fn get_onload (self : * parser.Script , page : * Page ) ! ? Env.Function {
956+ const state = page .getNodeState ( @ptrCast (self )) orelse return null ;
957+ return state .onload ;
970958 }
971959
972- pub fn set_onload (script : * parser.Script , function : ? Env.Function , page : * Page ) ! void {
973- const self = try page .getOrCreateNodeWrapper ( HTMLScriptElement , @ptrCast (script ));
974- self .onload = function ;
960+ pub fn set_onload (self : * parser.Script , function : ? Env.Function , page : * Page ) ! void {
961+ const state = try page .getOrCreateNodeState ( @ptrCast (self ));
962+ state .onload = function ;
975963 }
976964
977- pub fn get_onerror (script : * parser.Script , page : * Page ) ! ? Env.Function {
978- const self = page .getNodeWrapper ( HTMLScriptElement , @ptrCast (script )) orelse return null ;
979- return self .onerror ;
965+ pub fn get_onerror (self : * parser.Script , page : * Page ) ! ? Env.Function {
966+ const state = page .getNodeState ( @ptrCast (self )) orelse return null ;
967+ return state .onerror ;
980968 }
981969
982- pub fn set_onerror (script : * parser.Script , function : ? Env.Function , page : * Page ) ! void {
983- const self = try page .getOrCreateNodeWrapper ( HTMLScriptElement , @ptrCast (script ));
984- self .onerror = function ;
970+ pub fn set_onerror (self : * parser.Script , function : ? Env.Function , page : * Page ) ! void {
971+ const state = try page .getOrCreateNodeState ( @ptrCast (self ));
972+ state .onerror = function ;
985973 }
986974};
987975
0 commit comments