Skip to content

Commit c237d7f

Browse files
authored
Merge pull request #1188 from MicrosoftEdge/api-pinch-zoom
API Review: IsPinchZoomEnabled.md
2 parents 19098ac + db75039 commit c237d7f

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

specs/IsPinchZoomEnabled.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Background
2+
3+
There are two types of zoom in Chromium: Browser Zoom and Pinch-Zoom:
4+
- Browser zoom, referred to as “Page Zoom” or “Zoom” more generally, is what we get by using Ctrl + +(plus) or – (minus) or Ctrl + Mousewheel. This changes the size of a CSS pixel relative to a device independent pixel and so it will cause page layout to change. End developers can programmatically change browser Zoom properties including [IsZoomControlEnabled](https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.774.44#get_iszoomcontrolenabled) and [ZoomFactor](https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2controller?view=webview2-1.0.774.44#get_zoomfactor). Setting ZoomFactor property causes the layout to change and enables scroll bar which lets users interact with the zoomed in content using mouse.
5+
- Pinch-zoom, referred to as “Page Scale” zoom, is performed as a post-rendering step, it changes the page scale factor property and scales the surface the web page is rendered onto when user perfoms a pinch zooming action. It does not change the layout but rather changes the viewport and clips the web content, the content outside of the viewport isn't visible onscreen and users can't reach this content using mouse.
6+
7+
Currently, the first type of zoom control is supported in WebView2 and modifying it has no effect on page scale zoom.
8+
9+
In response to customer requests to be able to change the current functionality of page scale zoom in WebView2, the WebView2 team has introduced this Pinch Zoom API which allows end developers to disable or enable page scale zoom control via a setting.
10+
11+
In this document we describe the new setting. We'd appreciate your feedback.
12+
13+
14+
# Description
15+
The default value for `IsPinchZoomEnabled` is `true`.
16+
When this setting is set to `false`, it disables the ability of the end users to use pinching motions on touch input enabled devices to scale the web content in the WebView2 and users cannot pinch zoom.
17+
Disabling/Enabling `IsPinchZoomEnabled` does not take effect until the next navigation, it only affects the end user's ability to use pinch motions and does not change the page scale factor.
18+
19+
20+
# Examples
21+
```cpp
22+
wil::com_ptr<ICoreWebView2> webView;
23+
void SettingsComponent::TogglePinchZooomEnabled()
24+
{
25+
// Get webView's current settings
26+
wil::com_ptr<ICoreWebView2Settings> coreWebView2Settings;
27+
CHECK_FAILURE(webView->get_Settings(&coreWebView2Settings));
28+
wil::com_ptr<ICoreWebView2Settings4> coreWebView2Settings4;
29+
coreWebView2Settings4 = coreWebView2Settings.try_query<ICoreWebView2Settings4>();
30+
if(coreWebView2Settings4)
31+
{
32+
BOOL enabled;
33+
CHECK_FAILURE(coreWebView2Settings4->get_IsPinchZoomEnabled(&enabled));
34+
CHECK_FAILURE(coreWebView2Settings4->put_IsPinchZoomEnabled(enabled ? FALSE : TRUE));
35+
}
36+
}
37+
```
38+
39+
```c#
40+
private WebView2 _webView;
41+
void TogglePinchZoomEnabled()
42+
{
43+
var coreWebView2Settings = _webView.CoreWebView2.Settings;
44+
coreWebView2Settings.IsPinchZoomEnabled = !coreWebView2Settings.IsPinchZoomEnabled;
45+
}
46+
```
47+
48+
# Remarks
49+
When `IsPinchZoomEnabled` is set to `false`, pinch zooming is disabled in WebView. This however doesn't modify the underlying page scale factor of page scale zoom.
50+
51+
# API Notes
52+
53+
See [API Details](#api-details) section below for API reference.
54+
55+
# API Details
56+
57+
## Win32 C++
58+
```cpp
59+
[uuid(B625A89E-368F-43F5-BCBA-39AA6234CCF8), object, pointer_default(unique)]
60+
interface ICoreWebView2Settings4 : ICoreWebView2Settings3 {
61+
/// The IsPinchZoomEnabled property enables or disables the ability of
62+
/// the end user to use a pinching motion on touch input enabled devices
63+
/// to scale the web content in the WebView2. It defaults to TRUE.
64+
/// When set to FALSE, the end user cannot pinch zoom.
65+
/// This API only affects the Page Scale zoom and has no effect on the
66+
/// existing browser zoom properties (IsZoomControlEnabled and ZoomFactor)
67+
/// or other end user mechanisms for zooming.
68+
///
69+
/// \snippet SettingsComponent.cpp TogglePinchZooomEnabled
70+
[propget] HRESULT IsPinchZoomEnabled([out, retval] BOOL* enabled);
71+
/// Set the IsPinchZoomEnabled property
72+
[propput] HRESULT IsPinchZoomEnabled([in] BOOL enabled);
73+
}
74+
```
75+
76+
## .NET and WinRT
77+
78+
```c#
79+
namespace Microsoft.Web.WebView2.Core
80+
{
81+
public partial class CoreWebView2Settings
82+
{
83+
///
84+
public bool IsPinchZoomEnabled { get; set; };
85+
86+
}
87+
}
88+
89+
```

0 commit comments

Comments
 (0)