@@ -920,7 +920,7 @@ pub const Page = struct {
920920 fn windowClicked (node : * parser.EventNode , event : * parser.Event ) void {
921921 const self : * Page = @fieldParentPtr ("window_clicked_event_node" , node );
922922 self ._windowClicked (event ) catch | err | {
923- log .err (.browser , "click handler error" , .{ .err = err });
923+ log .err (.input , "click handler error" , .{ .err = err });
924924 };
925925 }
926926
@@ -932,18 +932,22 @@ pub const Page = struct {
932932 .a = > {
933933 const element : * parser.Element = @ptrCast (node );
934934 const href = (try parser .elementGetAttribute (element , "href" )) orelse return ;
935+ log .debug (.input , "window click on link" , .{ .tag = tag , .href = href });
935936 try self .navigateFromWebAPI (href , .{}, .{ .push = null });
937+ return ;
936938 },
937939 .input = > {
938940 const element : * parser.Element = @ptrCast (node );
939941 const input_type = try parser .inputGetType (@ptrCast (element ));
940942 if (std .ascii .eqlIgnoreCase (input_type , "submit" )) {
943+ log .debug (.input , "window click on submit input" , .{ .tag = tag });
941944 return self .elementSubmitForm (element );
942945 }
943946 },
944947 .button = > {
945948 const element : * parser.Element = @ptrCast (node );
946949 const button_type = try parser .buttonGetType (@ptrCast (element ));
950+ log .debug (.input , "window click on button" , .{ .tag = tag , .button_type = button_type });
947951 if (std .ascii .eqlIgnoreCase (button_type , "submit" )) {
948952 return self .elementSubmitForm (element );
949953 }
@@ -955,6 +959,12 @@ pub const Page = struct {
955959 },
956960 else = > {},
957961 }
962+ log .debug (.input , "window click on element" , .{ .tag = tag });
963+ // Set the focus on the clicked element.
964+ // Thanks to parser.nodeHTMLGetTagType, we know nod is an element.
965+ // We assume we have a ElementHTML.
966+ const Document = @import ("dom/document.zig" ).Document ;
967+ try Document .setFocus (@ptrCast (self .window .document ), @as (* parser .ElementHTML , @ptrCast (node )), self );
958968 }
959969
960970 pub const KeyboardEvent = struct {
@@ -997,7 +1007,7 @@ pub const Page = struct {
9971007 fn keydownCallback (node : * parser.EventNode , event : * parser.Event ) void {
9981008 const self : * Page = @fieldParentPtr ("keydown_event_node" , node );
9991009 self ._keydownCallback (event ) catch | err | {
1000- log .err (.browser , "keydown handler error" , .{ .err = err });
1010+ log .err (.input , "keydown handler error" , .{ .err = err });
10011011 };
10021012 }
10031013
@@ -1011,31 +1021,39 @@ pub const Page = struct {
10111021 if (std .mem .eql (u8 , new_key , "Dead" )) {
10121022 return ;
10131023 }
1014-
10151024 switch (tag ) {
10161025 .input = > {
10171026 const element : * parser.Element = @ptrCast (node );
10181027 const input_type = try parser .inputGetType (@ptrCast (element ));
1019- if ( std . mem . eql ( u8 , input_type , "text" )) {
1020- if (std .mem .eql (u8 , new_key , "Enter" )) {
1021- const form = (try self .formForElement (element )) orelse return ;
1022- return self .submitForm (@ptrCast (form ), null );
1023- }
1028+ log . debug ( .input , "key down on input" , .{ . tag = tag , . key = new_key , . input_type = input_type });
1029+ if (std .mem .eql (u8 , new_key , "Enter" )) {
1030+ const form = (try self .formForElement (element )) orelse return ;
1031+ return self .submitForm (@ptrCast (form ), null );
1032+ }
10241033
1025- const value = try parser .inputGetValue (@ptrCast (element ));
1026- const new_value = try std .mem .concat (self .arena , u8 , &.{ value , new_key });
1027- try parser .inputSetValue (@ptrCast (element ), new_value );
1034+ if (std .mem .eql (u8 , input_type , "radio" )) {
1035+ return ;
1036+ }
1037+ if (std .mem .eql (u8 , input_type , "checkbox" )) {
1038+ return ;
10281039 }
1040+
1041+ const value = try parser .inputGetValue (@ptrCast (element ));
1042+ const new_value = try std .mem .concat (self .arena , u8 , &.{ value , new_key });
1043+ try parser .inputSetValue (@ptrCast (element ), new_value );
10291044 },
10301045 .textarea = > {
1046+ log .debug (.input , "key down on textarea" , .{ .tag = tag , .key = new_key });
10311047 const value = try parser .textareaGetValue (@ptrCast (node ));
10321048 if (std .mem .eql (u8 , new_key , "Enter" )) {
10331049 new_key = "\n " ;
10341050 }
10351051 const new_value = try std .mem .concat (self .arena , u8 , &.{ value , new_key });
10361052 try parser .textareaSetValue (@ptrCast (node ), new_value );
10371053 },
1038- else = > {},
1054+ else = > {
1055+ log .debug (.input , "key down event" , .{ .tag = tag , .key = new_key });
1056+ },
10391057 }
10401058 }
10411059
0 commit comments