Repository navigation
feat(webview): add pinch zoom and explicit loads - #233
Conversation
4bcb9bc to
324544d
Compare
324544d to
ba4d502
Compare
…hZoom on Android and Windows touchpads Android numbered WebLoad 7, WebSendInput's number, while Go writes it as 8 with three strings, so a load desynchronized the batch stream; Protocol.java now matches the driver, which a test holds it to. Backends no longer overwrite their config's Source with the loaded one: a later change of another setting reloaded the configured source on Apple, Linux and Windows. Each loads Ref.Load's source with the load the source uses, keeping the configured one, so the next source, script or header change loads it again and messages keep coming by default from its origin. The web keeps the page shown when only frame settings change. A Load Access refuses now reports OnError and sends nothing, where it sent an empty source that showed about:blank on Windows and a blank frame on the web. PinchZoom turns on Android's built-in zoom with its buttons hidden, and on Windows also sets IsZoomControlEnabled, as a precision touchpad's pinch reaches the window as Ctrl with the wheel. The gallery's Home loads the docs page the browser starts at rather than go.dev, and nsgotest exports WebLoad.
…iled WebView2 ends a navigation StopLoading cuts short with CONNECTION_ABORTED, which reached OnError, and reported every failure at the page still shown, which for a load that never committed is the one before it. The view now drops the failure of a navigation it stopped and reports the URL NavigationStarting gave. Checked on Windows 11: a stopped load reports nothing and an unreachable host reports its own URL.
…o a download WebView2 ends a navigation as CONNECTION_ABORTED when StopLoading stops it, when a new source, Ref.Load, Reload or a history step replaces it, when the page navigates elsewhere, and when its response becomes a download. Only the StopLoading case was dropped, so typing an address while a page loaded, or clicking a link OnDownload saves, reached OnError. The backend now tracks NavigationId: a failure of a navigation that is not the last one started, or that the app cut short, is dropped. WebView2 raises the failure before the next NavigationStarting or DownloadStarting, so a CONNECTION_ABORTED of the last navigation waits half a second and is dropped if either arrives.
… cancellations 0.1.0 has shipped, so the change gets its Unreleased entries, including the Windows Ctrl+wheel zoom that now follows PinchZoom.
ba4d502 to
1134c74
Compare
|
Reviewed. Read the full diff against main and #202's Acceptance. Ref.Load goes through the same Access check as Source (a refused source reaches OnError and sends nothing), every backend routes driver.WebLoad and keeps its configured source, Android's WEB_LOAD (8) matches the driver and its Java reads the three strings Go writes, Apple drops NSURLErrorCancelled and WebKit 102, and Windows tracks NavigationId with the cut marker and the 500 ms hold for CONNECTION_ABORTED. No unrelated changes or attribution; no hard-wrapped comments in the PR's own code. Rebased onto v0.1.0 (main 7c8423a). The only conflicts were classes.dex and classes.jar, rebuilt with build.sh at both commits that change Java; a rebuild at the head reproduces them byte for byte. Since 0.1.0 has shipped, I added the PR's two Unreleased entries to CHANGELOG.md in a separate commit, including the Windows Ctrl+wheel zoom default that now follows PinchZoom. Builds and tests:
Device checks, using a probe app with a local HTTP server that ran a scripted sequence and logged OnLoadStart, OnLoad, OnError and OnDownload:
Not checked here: Linux and Android devices (WebKitGTK already dropped its cancellation errors; Android's protocol is covered by TestWebCommandsMatchJava), real pinch gestures, and iOS, whose only change is the shared Apple cancellation filter checked on macOS. |
What changed
Fixes #202.
WebView.PinchZoom, off by default, lets a pinch magnify the page: macOS setsWKWebView.allowsMagnification; Windows sets WebView2'sIsPinchZoomEnabled(touch screens) andIsZoomControlEnabled, because a precision touchpad's pinch reaches the window as Ctrl+wheel, which also turns off Ctrl+wheel and Ctrl+/- zoom unlessPinchZoomis on (WebView2 zoomed on these by default before); Android turns onWebSettings' built-in zoom with its buttons hidden. iOS follows the page's viewport. WebKitGTK and the browser have no switch for this and keep their own handling.Ref.Load(WebSource)loads a source the way a newSourcewould, even when it equals the current one. It goes through the sameAccesscheck: a refused source reachesOnErrorand sends nothing. It uses the view'sHeaders. It navigates the view the way a link does and leaves the configured source alone, so the next change ofSource/SourceFuncloads again, even to the valueLoadloaded, and messages still come from the source's origin by default. Every backend routesdriver.WebLoad(Apple, Windows, Linux, Android, web).WebErrorcarries the platform'sDomainandCode(driver.WebFailureinEvent.Data): NSError on Apple, the GError domain name on Linux,COREWEBVIEW2_WEB_ERROR_STATUS(orHRESULTfor a refused navigate call) on Windows. Both are empty for access refusals and on Android (roadmap row added).OnError: stopped, replaced by a new source,Ref.Load, a reload or history step, replaced by the page navigating elsewhere, or turned into a download. Apple dropsNSURLErrorCancelled(-999) andWebKitErrorFrameLoadInterruptedByPolicyChange(102). WebView2 ends all of these asCONNECTION_ABORTED, so Windows tracksNavigationId: it drops the failure of a navigation that is not the last one started or that the app stopped or replaced, and because WebView2 raises the failure before the nextNavigationStartingorDownloadStarting, aCONNECTION_ABORTEDof the last navigation waits 500 ms and is dropped if either arrives. Windows now reports the URL that failed instead of the page still shown.Ref.Loadon the docs page it starts at.nsgotestrecords web command data and exportsWebLoadandWebSource.Verification
go build ./.... Vets: windows amd64/386/arm64, linux, android/arm64, js/wasm.go tool nsgo check -target allpassed on macOS (Studio).go tool nsgo test ./core(549 passed),./internal/platform/android(incl. newTestWebCommandsMatchJava),./internal/platform/apple(54 passed),./nsgotest,-run TestMedia ./examples/gallery(Home sendsWebLoadwith the docs URL),-run 'Layer|Skills|Doc' ..Ref.Loadof the current source reloads it. ASourceFuncchange to the valueLoadloaded reloads it. An unreachable host reportsNSURLErrorDomain/-1003 on macOS,g-resolver-error-quark/0 on Linux andCOREWEBVIEW2_WEB_ERROR_STATUS/0 on Windows.StopLoadingduring a load reports nothing on all three.OnErrorforRef.Loador aSourceFuncchange while a slow page loads,StopLoading, a linkOnDownloadsaves,Ref.Loadof a download URL, or a page that navigates elsewhere while its own navigation loads; an unreachable host still reports its error. The raw event log confirmed WebView2 raises the abortedNavigationCompletedbefore the replacingNavigationStartingand beforeDownloadStarting.devicePixelRatioat 1 withPinchZoomoff and raised it to 1.5 with it on.Ref.Loadloads a new page and then the same page again.