diff --git a/components/compositing/webview_renderer.rs b/components/compositing/webview_renderer.rs index 6e216582f3b..38f3195fdc6 100644 --- a/components/compositing/webview_renderer.rs +++ b/components/compositing/webview_renderer.rs @@ -44,8 +44,8 @@ struct ScrollEvent { enum ScrollZoomEvent { /// A pinch zoom event that magnifies the view by the given factor. PinchZoom(f32), - /// A zoom event that magnifies the view by the factor parsed from meta tag. - ViewportZoom(f32), + /// A zoom event that establishes the initial zoom from the viewport meta tag. + InitialViewportZoom(f32), /// A scroll event that scrolls the scroll node at the given location by the /// given amount. Scroll(ScrollEvent), @@ -799,13 +799,16 @@ impl WebViewRenderer { // Batch up all scroll events into one, or else we'll do way too much painting. let mut combined_scroll_event: Option = None; + let mut base_page_zoom = self.pinch_zoom_level().get(); let mut combined_magnification = 1.0; for scroll_event in self.pending_scroll_zoom_events.drain(..) { match scroll_event { - ScrollZoomEvent::PinchZoom(magnification) | - ScrollZoomEvent::ViewportZoom(magnification) => { + ScrollZoomEvent::PinchZoom(magnification) => { combined_magnification *= magnification }, + ScrollZoomEvent::InitialViewportZoom(magnification) => { + base_page_zoom = magnification + }, ScrollZoomEvent::Scroll(scroll_event_info) => { let combined_event = match combined_scroll_event.as_mut() { None => { @@ -862,12 +865,11 @@ impl WebViewRenderer { ); } - let pinch_zoom_result = match self - .set_pinch_zoom_level(self.pinch_zoom_level().get() * combined_magnification) - { - true => PinchZoomResult::DidPinchZoom, - false => PinchZoomResult::DidNotPinchZoom, - }; + let pinch_zoom_result = + match self.set_pinch_zoom_level(base_page_zoom * combined_magnification) { + true => PinchZoomResult::DidPinchZoom, + false => PinchZoomResult::DidNotPinchZoom, + }; (pinch_zoom_result, scroll_result) } @@ -1035,7 +1037,7 @@ impl WebViewRenderer { pub fn set_viewport_description(&mut self, viewport_description: ViewportDescription) { self.pending_scroll_zoom_events - .push(ScrollZoomEvent::ViewportZoom( + .push(ScrollZoomEvent::InitialViewportZoom( viewport_description .clone() .clamp_zoom(viewport_description.initial_scale.get()), diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 9162a9dedd3..b3e00b003b4 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -373460,6 +373460,21 @@ } } }, + "visual-viewport": { + "viewport-apply-initial-scale-after-navigation.html": [ + "ec03c380d6d27ed0b486a26203d441dc101fd39f", + [ + null, + [ + [ + "/visual-viewport/viewport-apply-initial-scale-after-navigation-ref.html", + "==" + ] + ], + {} + ] + ] + }, "web-animations": { "animation-model": { "keyframe-effects": { @@ -522286,6 +522301,16 @@ "c036b16ec87bc7e562c4040ad1923c5a8b483cec", [] ], + "resource": { + "viewport-apply-initial-scale-after-navigation-inner.html": [ + "edbf5dbb70aa916363ff32eab847f2d03562d4f5", + [] + ] + }, + "viewport-apply-initial-scale-after-navigation-ref.html": [ + "904d370d6b464ef526b79e3974532d3f2c57d13b", + [] + ], "viewport_support.js": [ "a82bd2b028010e053199e55bd7bb357361581e6f", [] diff --git a/tests/wpt/tests/visual-viewport/resource/viewport-apply-initial-scale-after-navigation-inner.html b/tests/wpt/tests/visual-viewport/resource/viewport-apply-initial-scale-after-navigation-inner.html new file mode 100644 index 00000000000..edbf5dbb70a --- /dev/null +++ b/tests/wpt/tests/visual-viewport/resource/viewport-apply-initial-scale-after-navigation-inner.html @@ -0,0 +1,16 @@ + + + + Viewport: Apply initial-scale after Navigation + + + + + + +

Viewport: Apply initial-scale after Navigation

+

Test passes if page opens with own initial-scale of 1.0

+ + diff --git a/tests/wpt/tests/visual-viewport/viewport-apply-initial-scale-after-navigation-ref.html b/tests/wpt/tests/visual-viewport/viewport-apply-initial-scale-after-navigation-ref.html new file mode 100644 index 00000000000..904d370d6b4 --- /dev/null +++ b/tests/wpt/tests/visual-viewport/viewport-apply-initial-scale-after-navigation-ref.html @@ -0,0 +1,12 @@ + + + + Viewport: Apply initial-scale after Navigation + + + + +

Viewport: Apply initial-scale after Navigation

+

Test passes if page opens with own initial-scale of 1.0

+ + diff --git a/tests/wpt/tests/visual-viewport/viewport-apply-initial-scale-after-navigation.html b/tests/wpt/tests/visual-viewport/viewport-apply-initial-scale-after-navigation.html new file mode 100644 index 00000000000..ec03c380d6d --- /dev/null +++ b/tests/wpt/tests/visual-viewport/viewport-apply-initial-scale-after-navigation.html @@ -0,0 +1,17 @@ + + + + Viewport: Apply initial-scale after Navigation + + + + + + +