diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 92dc77b984896..db18467b1bb89 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1066,11 +1066,13 @@ Returns `Boolean` - Whether audio is currently playing. #### `contents.setZoomFactor(factor)` -* `factor` Number - Zoom factor. +* `factor` Double - Zoom factor; default is 1.0. Changes the zoom factor to the specified factor. Zoom factor is zoom percent divided by 100, so 300% = 3.0. +The factor must be greater than 0.0. + **[Deprecated](modernization/property-updates.md)** #### `contents.getZoomFactor()` diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index 712aca43965f5..e88fecbf3fd31 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -22,11 +22,13 @@ The `WebFrame` class has the following instance methods: ### `webFrame.setZoomFactor(factor)` -* `factor` Number - Zoom factor. +* `factor` Double - Zoom factor; default is 1.0. Changes the zoom factor to the specified factor. Zoom factor is zoom percent divided by 100, so 300% = 3.0. +The factor must be greater than 0.0. + ### `webFrame.getZoomFactor()` Returns `Number` - The current zoom factor. diff --git a/shell/browser/api/atom_api_web_contents.cc b/shell/browser/api/atom_api_web_contents.cc index dce6106414c71..f2f8af84d89d4 100644 --- a/shell/browser/api/atom_api_web_contents.cc +++ b/shell/browser/api/atom_api_web_contents.cc @@ -4,6 +4,7 @@ #include "shell/browser/api/atom_api_web_contents.h" +#include #include #include #include @@ -2321,7 +2322,12 @@ double WebContents::GetZoomLevel() const { return zoom_controller_->GetZoomLevel(); } -void WebContents::SetZoomFactor(double factor) { +void WebContents::SetZoomFactor(mate::Arguments* args, double factor) { + if (factor < std::numeric_limits::epsilon()) { + args->ThrowError("'zoomFactor' must be a double greater than 0.0"); + return; + } + auto level = content::ZoomFactorToZoomLevel(factor); SetZoomLevel(level); } diff --git a/shell/browser/api/atom_api_web_contents.h b/shell/browser/api/atom_api_web_contents.h index a25bc1ef63d98..d0ccc848ee0a2 100644 --- a/shell/browser/api/atom_api_web_contents.h +++ b/shell/browser/api/atom_api_web_contents.h @@ -281,7 +281,7 @@ class WebContents : public mate::TrackableObject, // Methods for zoom handling. void SetZoomLevel(double level); double GetZoomLevel() const; - void SetZoomFactor(double factor); + void SetZoomFactor(mate::Arguments* args, double factor); double GetZoomFactor() const; // Callback triggered on permission response. diff --git a/shell/renderer/api/atom_api_web_frame.cc b/shell/renderer/api/atom_api_web_frame.cc index ac6ca330e15a3..c1f9466e8cc52 100644 --- a/shell/renderer/api/atom_api_web_frame.cc +++ b/shell/renderer/api/atom_api_web_frame.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. +#include #include #include #include @@ -250,7 +251,14 @@ double GetZoomLevel(v8::Local window) { return result; } -void SetZoomFactor(v8::Local window, double factor) { +void SetZoomFactor(mate::Arguments* args, + v8::Local window, + double factor) { + if (factor < std::numeric_limits::epsilon()) { + args->ThrowError("'zoomFactor' must be a double greater than 0.0"); + return; + } + SetZoomLevel(window, blink::WebView::ZoomFactorToZoomLevel(factor)); }