@@ -28,7 +28,7 @@ use embedder_traits::{
28
28
WebDriverJSError , WebDriverJSResult , WebDriverJSValue , WebDriverLoadStatus , WebDriverMessageId ,
29
29
WebDriverScriptCommand ,
30
30
} ;
31
- use euclid:: { Rect , Size2D } ;
31
+ use euclid:: { Point2D , Rect , Size2D } ;
32
32
use http:: method:: Method ;
33
33
use image:: { DynamicImage , ImageFormat , RgbaImage } ;
34
34
use ipc_channel:: ipc:: { self , IpcReceiver , IpcSender } ;
@@ -41,6 +41,7 @@ use serde::ser::Serializer;
41
41
use serde:: { Deserialize , Serialize } ;
42
42
use serde_json:: { Value , json} ;
43
43
use servo_config:: prefs:: { self , PrefValue , Preferences } ;
44
+ use servo_geometry:: DeviceIndependentIntRect ;
44
45
use servo_url:: ServoUrl ;
45
46
use style_traits:: CSSPixel ;
46
47
use uuid:: Uuid ;
@@ -889,7 +890,7 @@ impl Handler {
889
890
}
890
891
891
892
/// <https://w3c.github.io/webdriver/#set-window-rect>
892
- fn handle_set_window_size (
893
+ fn handle_set_window_rect (
893
894
& self ,
894
895
params : & WindowRectParameters ,
895
896
) -> WebDriverResult < WebDriverResponse > {
@@ -908,18 +909,10 @@ impl Handler {
908
909
// Step 13. Handle any user prompt.
909
910
self . handle_any_user_prompts ( webview_id) ?;
910
911
911
- // We don't current allow modifying the window x/y positions, so we can just
912
- // return the current window rectangle if not changing dimension.
913
- if params. width . is_none ( ) && params. height . is_none ( ) {
914
- return self . handle_window_rect ( VerifyBrowsingContextIsOpen :: No ) ;
915
- }
916
912
// (TODO) Step 14. Fully exit fullscreen.
917
913
// (TODO) Step 15. Restore the window.
918
914
let ( sender, receiver) = ipc:: channel ( ) . unwrap ( ) ;
919
915
920
- // Step 16 - 17. Set the width/height in CSS pixels.
921
- // This should be done as long as one of width/height is not null.
922
-
923
916
let current = LazyCell :: new ( || {
924
917
let WebDriverResponse :: WindowRect ( current) = self
925
918
. handle_window_rect ( VerifyBrowsingContextIsOpen :: No )
@@ -930,24 +923,34 @@ impl Handler {
930
923
current
931
924
} ) ;
932
925
933
- let ( width, height) = (
926
+ let ( x, y, width, height) = (
927
+ params. x . unwrap_or_else ( || current. x ) ,
928
+ params. y . unwrap_or_else ( || current. y ) ,
934
929
params. width . unwrap_or_else ( || current. width ) ,
935
930
params. height . unwrap_or_else ( || current. height ) ,
936
931
) ;
937
932
938
- self . send_message_to_embedder ( WebDriverCommandMsg :: SetWindowSize (
933
+ // Step 16 - 17. Set the width/height in CSS pixels.
934
+ // This should be done as long as one of width/height is not null.
935
+
936
+ // Step 18 - 19. Set the screen x/y in CSS pixels.
937
+ // This should be done as long as one of width/height is not null.
938
+ self . send_message_to_embedder ( WebDriverCommandMsg :: SetWindowRect (
939
939
webview_id,
940
- Size2D :: new ( width, height) ,
940
+ DeviceIndependentIntRect :: from_origin_and_size (
941
+ Point2D :: new ( x, y) ,
942
+ Size2D :: new ( width, height) ,
943
+ ) ,
941
944
sender. clone ( ) ,
942
945
) ) ?;
943
946
944
- let window_size = wait_for_script_response ( receiver) ?;
945
- debug ! ( "window_size after resizing : {window_size :?}" ) ;
947
+ let window_rect = wait_for_script_response ( receiver) ?;
948
+ debug ! ( "Result window_rect : {window_rect :?}" ) ;
946
949
let window_size_response = WindowRectResponse {
947
- x : 0 ,
948
- y : 0 ,
949
- width : window_size . width ,
950
- height : window_size . height ,
950
+ x : window_rect . min . x ,
951
+ y : window_rect . min . y ,
952
+ width : window_rect . width ( ) ,
953
+ height : window_rect . height ( ) ,
951
954
} ;
952
955
Ok ( WebDriverResponse :: WindowRect ( window_size_response) )
953
956
}
@@ -2449,7 +2452,7 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
2449
2452
WebDriverCommand :: GetWindowRect => {
2450
2453
self . handle_window_rect ( VerifyBrowsingContextIsOpen :: Yes )
2451
2454
} ,
2452
- WebDriverCommand :: SetWindowRect ( ref size) => self . handle_set_window_size ( size) ,
2455
+ WebDriverCommand :: SetWindowRect ( ref size) => self . handle_set_window_rect ( size) ,
2453
2456
WebDriverCommand :: IsEnabled ( ref element) => self . handle_is_enabled ( element) ,
2454
2457
WebDriverCommand :: IsSelected ( ref element) => self . handle_is_selected ( element) ,
2455
2458
WebDriverCommand :: GoBack => self . handle_go_back ( ) ,
0 commit comments