1
- use blitz_traits:: { HitResult , MouseEventButtons } ;
1
+ use blitz_traits:: { navigation :: NavigationOptions , HitResult , MouseEventButtons } ;
2
2
use markup5ever:: local_name;
3
3
4
4
use crate :: { node:: NodeSpecificData , util:: resolve_url, BaseDocument , Node } ;
@@ -99,10 +99,14 @@ pub(crate) fn handle_click(doc: &mut BaseDocument, _target: usize, x: f32, y: f3
99
99
let mut maybe_hit = doc. hit ( x, y) ;
100
100
101
101
while let Some ( hit) = maybe_hit {
102
- let node = & mut doc. nodes [ hit. node_id ] ;
102
+ let node_id = hit. node_id ;
103
+ let maybe_element = {
104
+ let node = & mut doc. nodes [ node_id] ;
105
+ node. data . downcast_element_mut ( )
106
+ } ;
103
107
104
- let Some ( el) = node . data . downcast_element_mut ( ) else {
105
- maybe_hit = parent_hit ( node , x, y) ;
108
+ let Some ( el) = maybe_element else {
109
+ maybe_hit = parent_hit ( & doc . nodes [ node_id ] , x, y) ;
106
110
continue ;
107
111
} ;
108
112
@@ -117,20 +121,18 @@ pub(crate) fn handle_click(doc: &mut BaseDocument, _target: usize, x: f32, y: f3
117
121
&& matches ! ( el. attr( local_name!( "type" ) ) , Some ( "checkbox" ) )
118
122
{
119
123
BaseDocument :: toggle_checkbox ( el) ;
120
- doc. set_focus_to ( hit . node_id ) ;
124
+ doc. set_focus_to ( node_id) ;
121
125
return ;
122
126
} else if el. name . local == local_name ! ( "input" )
123
127
&& matches ! ( el. attr( local_name!( "type" ) ) , Some ( "radio" ) )
124
128
{
125
- let node_id = node. id ;
126
129
let radio_set = el. attr ( local_name ! ( "name" ) ) . unwrap ( ) . to_string ( ) ;
127
130
BaseDocument :: toggle_radio ( doc, radio_set, node_id) ;
128
- BaseDocument :: set_focus_to ( doc, hit . node_id ) ;
131
+ BaseDocument :: set_focus_to ( doc, node_id) ;
129
132
return ;
130
133
}
131
134
// Clicking labels triggers click, and possibly input event, of associated input
132
135
else if el. name . local == local_name ! ( "label" ) {
133
- let node_id = node. id ;
134
136
if let Some ( target_node_id) = doc
135
137
. label_bound_input_elements ( node_id)
136
138
. first ( )
@@ -146,7 +148,8 @@ pub(crate) fn handle_click(doc: &mut BaseDocument, _target: usize, x: f32, y: f3
146
148
} else if el. name . local == local_name ! ( "a" ) {
147
149
if let Some ( href) = el. attr ( local_name ! ( "href" ) ) {
148
150
if let Some ( url) = resolve_url ( & doc. base_url , href) {
149
- doc. navigation_provider . navigate_new_page ( url. into ( ) ) ;
151
+ doc. navigation_provider
152
+ . navigate_to ( NavigationOptions :: new ( url, doc. id ( ) ) ) ;
150
153
} else {
151
154
println ! (
152
155
"{href} is not parseable as a url. : {base_url:?}" ,
@@ -157,10 +160,17 @@ pub(crate) fn handle_click(doc: &mut BaseDocument, _target: usize, x: f32, y: f3
157
160
} else {
158
161
println ! ( "Clicked link without href: {:?}" , el. attrs( ) ) ;
159
162
}
163
+ } else if el. name . local == local_name ! ( "input" )
164
+ && el. attr ( local_name ! ( "type" ) ) == Some ( "submit" )
165
+ || el. name . local == local_name ! ( "button" )
166
+ {
167
+ if let Some ( form_owner) = doc. controls_to_form . get ( & node_id) {
168
+ doc. submit_form ( * form_owner, node_id) ;
169
+ }
160
170
}
161
171
162
172
// No match. Recurse up to parent.
163
- maybe_hit = parent_hit ( & doc. nodes [ hit . node_id ] , x, y)
173
+ maybe_hit = parent_hit ( & doc. nodes [ node_id] , x, y)
164
174
}
165
175
166
176
// If nothing is matched then clear focus
0 commit comments