@@ -1174,6 +1174,7 @@ pub enum WebviewMessage {
11741174 SetSize ( Size ) ,
11751175 SetFocus ,
11761176 Reparent ( WindowId ) ,
1177+ SetAutoResize ( bool ) ,
11771178 // Getters
11781179 Url ( Sender < Url > ) ,
11791180 Position ( Sender < PhysicalPosition < i32 > > ) ,
@@ -1384,6 +1385,17 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
13841385 Ok ( ( ) )
13851386 }
13861387
1388+ fn set_auto_resize ( & self , auto_resize : bool ) -> Result < ( ) > {
1389+ send_user_message (
1390+ & self . context ,
1391+ Message :: Webview (
1392+ * self . window_id . lock ( ) . unwrap ( ) ,
1393+ self . webview_id ,
1394+ WebviewMessage :: SetAutoResize ( auto_resize) ,
1395+ ) ,
1396+ )
1397+ }
1398+
13871399 #[ cfg( all( feature = "tracing" , not( target_os = "android" ) ) ) ]
13881400 fn eval_script < S : Into < String > > ( & self , script : S ) -> Result < ( ) > {
13891401 // use a channel so the EvaluateScript task uses the current span as parent
@@ -1883,7 +1895,7 @@ pub struct WebviewWrapper {
18831895 webview_event_listeners : WebviewEventListeners ,
18841896 // the key of the WebContext if it's not shared
18851897 context_key : Option < PathBuf > ,
1886- bounds : Option < Arc < Mutex < WebviewBounds > > > ,
1898+ bounds : Arc < Mutex < Option < WebviewBounds > > > ,
18871899}
18881900
18891901impl Deref for WebviewWrapper {
@@ -2824,11 +2836,10 @@ fn handle_user_message<T: UserEvent>(
28242836 bounds. width = size. width ;
28252837 bounds. height = size. height ;
28262838
2827- if let Some ( b) = & webview. bounds {
2839+ if let Some ( b) = & mut * webview. bounds . lock ( ) . unwrap ( ) {
28282840 let window_size = window. inner_size ( ) . to_logical :: < f32 > ( window. scale_factor ( ) ) ;
2829- let mut bounds = b. lock ( ) . unwrap ( ) ;
2830- bounds. width_rate = size. width as f32 / window_size. width ;
2831- bounds. height_rate = size. height as f32 / window_size. height ;
2841+ b. width_rate = size. width as f32 / window_size. width ;
2842+ b. height_rate = size. height as f32 / window_size. height ;
28322843 }
28332844
28342845 webview. set_bounds ( bounds) ;
@@ -2839,12 +2850,10 @@ fn handle_user_message<T: UserEvent>(
28392850 bounds. x = position. x ;
28402851 bounds. y = position. y ;
28412852
2842- if let Some ( b) = & webview. bounds {
2853+ if let Some ( b) = & mut * webview. bounds . lock ( ) . unwrap ( ) {
28432854 let window_size = window. inner_size ( ) . to_logical :: < f32 > ( window. scale_factor ( ) ) ;
2844- let mut bounds = b. lock ( ) . unwrap ( ) ;
2845-
2846- bounds. x_rate = position. x as f32 / window_size. width ;
2847- bounds. y_rate = position. y as f32 / window_size. height ;
2855+ b. x_rate = position. x as f32 / window_size. width ;
2856+ b. y_rate = position. y as f32 / window_size. height ;
28482857 }
28492858
28502859 webview. set_bounds ( bounds) ;
@@ -2868,6 +2877,20 @@ fn handle_user_message<T: UserEvent>(
28682877 WebviewMessage :: SetFocus => {
28692878 webview. focus ( ) ;
28702879 }
2880+ WebviewMessage :: SetAutoResize ( auto_resize) => {
2881+ let bounds = webview. bounds ( ) ;
2882+ let window_size = window. inner_size ( ) . to_logical :: < f32 > ( window. scale_factor ( ) ) ;
2883+ * webview. bounds . lock ( ) . unwrap ( ) = if auto_resize {
2884+ Some ( WebviewBounds {
2885+ x_rate : ( bounds. x as f32 ) / window_size. width ,
2886+ y_rate : ( bounds. y as f32 ) / window_size. height ,
2887+ width_rate : ( bounds. width as f32 ) / window_size. width ,
2888+ height_rate : ( bounds. height as f32 ) / window_size. height ,
2889+ } )
2890+ } else {
2891+ None
2892+ } ;
2893+ }
28712894 WebviewMessage :: WithWebview ( f) => {
28722895 #[ cfg( any(
28732896 target_os = "linux" ,
@@ -3186,8 +3209,7 @@ fn handle_event_loop<T: UserEvent>(
31863209 {
31873210 let size = size. to_logical :: < f32 > ( window. scale_factor ( ) ) ;
31883211 for webview in webviews {
3189- if let Some ( bounds) = & webview. bounds {
3190- let b = bounds. lock ( ) . unwrap ( ) ;
3212+ if let Some ( b) = & * webview. bounds . lock ( ) . unwrap ( ) {
31913213 webview. set_bounds ( wry:: Rect {
31923214 x : ( size. width * b. x_rate ) as i32 ,
31933215 y : ( size. height * b. y_rate ) as i32 ,
@@ -3427,6 +3449,9 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
34273449
34283450 if let Some ( webview) = webview {
34293451 webviews. push ( create_webview (
3452+ #[ cfg( feature = "unstable" ) ]
3453+ WebviewKind :: WindowChild ,
3454+ #[ cfg( not( feature = "unstable" ) ) ]
34303455 WebviewKind :: WindowContent ,
34313456 & window,
34323457 Arc :: new ( Mutex :: new ( window_id) ) ,
@@ -3622,6 +3647,24 @@ fn create_webview<T: UserEvent>(
36223647 None
36233648 }
36243649 } else {
3650+ #[ cfg( feature = "unstable" ) ]
3651+ {
3652+ let window_size = window. inner_size ( ) . to_logical :: < u32 > ( window. scale_factor ( ) ) ;
3653+
3654+ webview_builder = webview_builder. with_bounds ( wry:: Rect {
3655+ x : 0 ,
3656+ y : 0 ,
3657+ width : window_size. width ,
3658+ height : window_size. height ,
3659+ } ) ;
3660+ Some ( WebviewBounds {
3661+ x_rate : 0. ,
3662+ y_rate : 0. ,
3663+ width_rate : 1. ,
3664+ height_rate : 1. ,
3665+ } )
3666+ }
3667+ #[ cfg( not( feature = "unstable" ) ) ]
36253668 None
36263669 } ;
36273670
@@ -3829,7 +3872,7 @@ fn create_webview<T: UserEvent>(
38293872 } else {
38303873 web_context_key
38313874 } ,
3832- bounds : webview_bounds . map ( |b| Arc :: new ( Mutex :: new ( b ) ) ) ,
3875+ bounds : Arc :: new ( Mutex :: new ( webview_bounds ) ) ,
38333876 } )
38343877}
38353878
0 commit comments