fix: deprecate setLayoutZoomLevelLimits (#21296)
This commit is contained in:
parent
c7cbc2e6b1
commit
9526c5584e
14 changed files with 24 additions and 110 deletions
|
@ -114,6 +114,14 @@ const { ipcRenderer } = require('electron')
|
|||
ipcRenderer.invoke('openDevTools', webview.getWebContentsId())
|
||||
```
|
||||
|
||||
### `webFrame.setLayoutZoomLevelLimits()`
|
||||
|
||||
Chromium has removed support for changing the layout zoom level limits, and it
|
||||
is beyond Electron's capacity to maintain it. The function will emit a warning
|
||||
in Electron 8.x, and cease to exist in Electron 9.x. The layout zoom level
|
||||
limits are now fixed at a minimum of 0.25 and a maximum of 5.0, as defined
|
||||
[here](https://chromium.googlesource.com/chromium/src/+/938b37a6d2886bf8335fc7db792f1eb46c65b2ae/third_party/blink/common/page/page_zoom.cc#11).
|
||||
|
||||
## Planned Breaking API Changes (7.0)
|
||||
|
||||
### Node Headers URL
|
||||
|
|
|
@ -1113,7 +1113,7 @@ Sets the maximum and minimum pinch-to-zoom level.
|
|||
> contents.setVisualZoomLevelLimits(1, 3)
|
||||
> ```
|
||||
|
||||
#### `contents.setLayoutZoomLevelLimits(minimumLevel, maximumLevel)`
|
||||
#### `contents.setLayoutZoomLevelLimits(minimumLevel, maximumLevel)` _Deprecated_
|
||||
|
||||
* `minimumLevel` Number
|
||||
* `maximumLevel` Number
|
||||
|
@ -1122,6 +1122,8 @@ Returns `Promise<void>`
|
|||
|
||||
Sets the maximum and minimum layout-based (i.e. non-visual) zoom level.
|
||||
|
||||
**Deprecated:** This API is no longer supported by Chromium.
|
||||
|
||||
#### `contents.undo()`
|
||||
|
||||
Executes the editing command `undo` in web page.
|
||||
|
|
|
@ -56,13 +56,15 @@ Sets the maximum and minimum pinch-to-zoom level.
|
|||
> webFrame.setVisualZoomLevelLimits(1, 3)
|
||||
> ```
|
||||
|
||||
### `webFrame.setLayoutZoomLevelLimits(minimumLevel, maximumLevel)`
|
||||
### `webFrame.setLayoutZoomLevelLimits(minimumLevel, maximumLevel)` _Deprecated_
|
||||
|
||||
* `minimumLevel` Number
|
||||
* `maximumLevel` Number
|
||||
|
||||
Sets the maximum and minimum layout-based (i.e. non-visual) zoom level.
|
||||
|
||||
**Deprecated:** This API is no longer supported by Chromium.
|
||||
|
||||
### `webFrame.setSpellCheckProvider(language, provider)`
|
||||
|
||||
* `language` String
|
||||
|
|
|
@ -635,7 +635,7 @@ Returns `Promise<void>`
|
|||
|
||||
Sets the maximum and minimum pinch-to-zoom level.
|
||||
|
||||
### `<webview>.setLayoutZoomLevelLimits(minimumLevel, maximumLevel)`
|
||||
### `<webview>.setLayoutZoomLevelLimits(minimumLevel, maximumLevel)` _Deprecated_
|
||||
|
||||
* `minimumLevel` Number
|
||||
* `maximumLevel` Number
|
||||
|
@ -644,6 +644,8 @@ Returns `Promise<void>`
|
|||
|
||||
Sets the maximum and minimum layout-based (i.e. non-visual) zoom level.
|
||||
|
||||
**Deprecated:** This API is no longer supported by Chromium.
|
||||
|
||||
### `<webview>.showDefinitionForSelection()` _macOS_
|
||||
|
||||
Shows pop-up dictionary that searches the selected word on the page.
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { EventEmitter } from 'events'
|
||||
import { deprecate } from 'electron'
|
||||
|
||||
const binding = process.electronBinding('web_frame')
|
||||
|
||||
const setLayoutZoomLevelLimitsWarning = deprecate.warnOnce('setLayoutZoomLevelLimits')
|
||||
|
||||
class WebFrame extends EventEmitter {
|
||||
constructor (public context: Window) {
|
||||
super()
|
||||
|
@ -45,6 +48,10 @@ class WebFrame extends EventEmitter {
|
|||
get routingId () {
|
||||
return binding._getRoutingId(this.context)
|
||||
}
|
||||
|
||||
setLayoutZoomLevelLimits () {
|
||||
setLayoutZoomLevelLimitsWarning()
|
||||
}
|
||||
}
|
||||
|
||||
// Populate the methods.
|
||||
|
|
|
@ -74,7 +74,6 @@ expose_setuseragent_on_networkcontext.patch
|
|||
feat_add_set_theme_source_to_allow_apps_to.patch
|
||||
revert_cleanup_remove_menu_subtitles_sublabels.patch
|
||||
export_fetchapi_mojo_traits_to_fix_component_build.patch
|
||||
add_zoom_limit_setters_to_webcontents.patch
|
||||
revert_remove_contentrendererclient_shouldfork.patch
|
||||
build_win_disable_zc_twophase.patch
|
||||
ignore_rc_check.patch
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: John Kleinschmidt <kleinschmidtorama@gmail.com>
|
||||
Date: Mon, 23 Sep 2019 17:07:53 -0400
|
||||
Subject: add zoom limit setters to webcontents
|
||||
|
||||
Allows minimum_zoom_percent_ and maximum_zoom_percent_ to be set on WebContents.
|
||||
This is needed by Electron to allow apps to limit how much an app can zoom in
|
||||
or out.
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index c13511e26189e68376e29f38c4ae2e1cc8fd3c57..a5c4162b3c69b534f843e1b6737392c867fc88ea 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -4124,10 +4124,18 @@ bool WebContentsImpl::GetClosedByUserGesture() {
|
||||
return closed_by_user_gesture_;
|
||||
}
|
||||
|
||||
+void WebContentsImpl::SetMinimumZoomPercent(int zoom_percent) {
|
||||
+ minimum_zoom_percent_ = zoom_percent;
|
||||
+}
|
||||
+
|
||||
int WebContentsImpl::GetMinimumZoomPercent() {
|
||||
return minimum_zoom_percent_;
|
||||
}
|
||||
|
||||
+void WebContentsImpl::SetMaximumZoomPercent(int zoom_percent) {
|
||||
+ maximum_zoom_percent_ = zoom_percent;
|
||||
+}
|
||||
+
|
||||
int WebContentsImpl::GetMaximumZoomPercent() {
|
||||
return maximum_zoom_percent_;
|
||||
}
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
|
||||
index ea1b3581ead984ac084fc9a2b9daf85f6756ea5c..b967e02b4052426855a2af88abbced2076b3e04a 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.h
|
||||
+++ b/content/browser/web_contents/web_contents_impl.h
|
||||
@@ -447,7 +447,9 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
|
||||
void SystemDragEnded(RenderWidgetHost* source_rwh) override;
|
||||
void SetClosedByUserGesture(bool value) override;
|
||||
bool GetClosedByUserGesture() override;
|
||||
+ void SetMinimumZoomPercent(int zoom_percent) override;
|
||||
int GetMinimumZoomPercent() override;
|
||||
+ void SetMaximumZoomPercent(int zoom_percent) override;
|
||||
int GetMaximumZoomPercent() override;
|
||||
void SetPageScale(float page_scale_factor) override;
|
||||
gfx::Size GetPreferredSize() override;
|
||||
@@ -1690,8 +1692,8 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
|
||||
bool closed_by_user_gesture_;
|
||||
|
||||
// Minimum/maximum zoom percent.
|
||||
- const int minimum_zoom_percent_;
|
||||
- const int maximum_zoom_percent_;
|
||||
+ int minimum_zoom_percent_;
|
||||
+ int maximum_zoom_percent_;
|
||||
|
||||
// Used to correctly handle integer zooming through a smooth scroll device.
|
||||
float zoom_scroll_remainder_;
|
||||
diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h
|
||||
index 750de66b8002ba66d0f2247d0075da1e51ac764c..1a57feeb1dfe08f8ce1113cb5d8c8ab57d761094 100644
|
||||
--- a/content/public/browser/web_contents.h
|
||||
+++ b/content/public/browser/web_contents.h
|
||||
@@ -812,8 +812,10 @@ class WebContents : public PageNavigator,
|
||||
virtual void SetClosedByUserGesture(bool value) = 0;
|
||||
virtual bool GetClosedByUserGesture() = 0;
|
||||
|
||||
- // Gets the minimum/maximum zoom percent.
|
||||
+ // Gets/sets the minimum/maximum zoom percent.
|
||||
+ virtual void SetMinimumZoomPercent(int zoom_percent) = 0;
|
||||
virtual int GetMinimumZoomPercent() = 0;
|
||||
+ virtual void SetMaximumZoomPercent(int zoom_percent) = 0;
|
||||
virtual int GetMaximumZoomPercent() = 0;
|
||||
|
||||
// Set the renderer's page scale to the given factor.
|
|
@ -2316,15 +2316,6 @@ double WebContents::GetZoomFactor() const {
|
|||
return blink::PageZoomLevelToZoomFactor(level);
|
||||
}
|
||||
|
||||
void WebContents::SetZoomLimits(double min_zoom, double max_zoom) {
|
||||
// Round the double to avoid returning incorrect minimum/maximum zoom
|
||||
// percentages.
|
||||
int minimum_percent = round(blink::PageZoomLevelToZoomFactor(min_zoom) * 100);
|
||||
int maximum_percent = round(blink::PageZoomLevelToZoomFactor(max_zoom) * 100);
|
||||
web_contents()->SetMinimumZoomPercent(minimum_percent);
|
||||
web_contents()->SetMaximumZoomPercent(maximum_percent);
|
||||
}
|
||||
|
||||
void WebContents::SetTemporaryZoomLevel(double level) {
|
||||
zoom_controller_->SetTemporaryZoomLevel(level);
|
||||
}
|
||||
|
|
|
@ -272,7 +272,6 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
|
|||
double GetZoomLevel() const;
|
||||
void SetZoomFactor(double factor);
|
||||
double GetZoomFactor() const;
|
||||
void SetZoomLimits(double min_zoom, double max_zoom) override;
|
||||
|
||||
// Callback triggered on permission response.
|
||||
void OnEnterFullscreenModeForTab(
|
||||
|
|
|
@ -90,8 +90,6 @@ interface ElectronBrowser {
|
|||
|
||||
SetTemporaryZoomLevel(double zoom_level);
|
||||
|
||||
SetZoomLimits(double min_zoom, double max_zoom);
|
||||
|
||||
[Sync]
|
||||
DoGetZoomLevel() => (double result);
|
||||
};
|
||||
|
|
|
@ -264,17 +264,6 @@ void SetVisualZoomLevelLimits(v8::Local<v8::Value> window,
|
|||
web_frame->View()->SetIgnoreViewportTagScaleLimits(true);
|
||||
}
|
||||
|
||||
void SetLayoutZoomLevelLimits(v8::Local<v8::Value> window,
|
||||
double min_level,
|
||||
double max_level) {
|
||||
content::RenderFrame* render_frame = GetRenderFrame(window);
|
||||
mojom::ElectronBrowserPtr browser_ptr;
|
||||
render_frame->GetRemoteInterfaces()->GetInterface(
|
||||
mojo::MakeRequest(&browser_ptr));
|
||||
|
||||
browser_ptr->SetZoomLimits(min_level, max_level);
|
||||
}
|
||||
|
||||
void AllowGuestViewElementDefinition(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> window,
|
||||
v8::Local<v8::Object> context,
|
||||
|
@ -580,7 +569,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
|||
dict.SetMethod("setZoomFactor", &SetZoomFactor);
|
||||
dict.SetMethod("getZoomFactor", &GetZoomFactor);
|
||||
dict.SetMethod("setVisualZoomLevelLimits", &SetVisualZoomLevelLimits);
|
||||
dict.SetMethod("setLayoutZoomLevelLimits", &SetLayoutZoomLevelLimits);
|
||||
dict.SetMethod("allowGuestViewElementDefinition",
|
||||
&AllowGuestViewElementDefinition);
|
||||
dict.SetMethod("getWebFrameId", &GetWebFrameId);
|
||||
|
|
|
@ -2,13 +2,6 @@ const { expect } = require('chai')
|
|||
const { webFrame } = require('electron')
|
||||
|
||||
describe('webFrame module', function () {
|
||||
it('supports setting the visual and layout zoom level limits', function () {
|
||||
expect(() => {
|
||||
webFrame.setVisualZoomLevelLimits(1, 50)
|
||||
webFrame.setLayoutZoomLevelLimits(0, 25)
|
||||
}).to.not.throw()
|
||||
})
|
||||
|
||||
it('top is self for top frame', () => {
|
||||
expect(webFrame.top.context).to.equal(webFrame.context)
|
||||
})
|
||||
|
|
|
@ -81,7 +81,6 @@ app.on('ready', () => {
|
|||
})
|
||||
|
||||
mainWindow.webContents.setVisualZoomLevelLimits(50, 200)
|
||||
mainWindow.webContents.setLayoutZoomLevelLimits(50, 200)
|
||||
|
||||
mainWindow.webContents.print({ silent: true, printBackground: false })
|
||||
mainWindow.webContents.print()
|
||||
|
|
|
@ -57,7 +57,6 @@ webFrame.setZoomLevel(200)
|
|||
console.log(webFrame.getZoomLevel())
|
||||
|
||||
webFrame.setVisualZoomLevelLimits(50, 200)
|
||||
webFrame.setLayoutZoomLevelLimits(50, 200)
|
||||
|
||||
webFrame.setSpellCheckProvider('en-US', {
|
||||
spellCheck (words, callback) {
|
||||
|
|
Loading…
Reference in a new issue