Browse Source

webContents: set zoom levels with HostZoomMap

deepak1556 8 years ago
parent
commit
b27c94368d

+ 23 - 0
atom/browser/api/atom_api_web_contents.cc

@@ -49,6 +49,7 @@
 #include "content/browser/web_contents/web_contents_impl.h"
 #include "content/common/view_messages.h"
 #include "content/public/browser/favicon_status.h"
+#include "content/public/browser/host_zoom_map.h"
 #include "content/public/browser/native_web_keyboard_event.h"
 #include "content/public/browser/navigation_details.h"
 #include "content/public/browser/navigation_entry.h"
@@ -1498,6 +1499,24 @@ void WebContents::Invalidate() {
     osr_rwhv->Invalidate();
 }
 
+void WebContents::SetZoomLevel(double level) {
+  content::HostZoomMap::SetZoomLevel(web_contents(), level);
+}
+
+double WebContents::GetZoomLevel() {
+  return content::HostZoomMap::GetZoomLevel(web_contents());
+}
+
+void WebContents::SetZoomFactor(double factor) {
+  auto level = content::ZoomFactorToZoomLevel(factor);
+  SetZoomLevel(level);
+}
+
+double WebContents::GetZoomFactor() {
+  auto level = GetZoomLevel();
+  return content::ZoomLevelToZoomFactor(level);
+}
+
 v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
   WebContentsPreferences* web_preferences =
       WebContentsPreferences::FromWebContents(web_contents());
@@ -1626,6 +1645,10 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setFrameRate", &WebContents::SetFrameRate)
       .SetMethod("getFrameRate", &WebContents::GetFrameRate)
       .SetMethod("invalidate", &WebContents::Invalidate)
+      .SetMethod("setZoomLevel", &WebContents::SetZoomLevel)
+      .SetMethod("getZoomLevel", &WebContents::GetZoomLevel)
+      .SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
+      .SetMethod("getZoomFactor", &WebContents::GetZoomFactor)
       .SetMethod("getType", &WebContents::GetType)
       .SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
       .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)

+ 6 - 0
atom/browser/api/atom_api_web_contents.h

@@ -174,6 +174,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
   int GetFrameRate() const;
   void Invalidate();
 
+  // Methods for zoom handling.
+  void SetZoomLevel(double level);
+  double GetZoomLevel();
+  void SetZoomFactor(double factor);
+  double GetZoomFactor();
+
   // Callback triggered on permission response.
   void OnEnterFullscreenModeForTab(content::WebContents* source,
                                    const GURL& origin,

+ 1 - 6
lib/browser/api/web-contents.js

@@ -105,15 +105,10 @@ const webFrameMethods = [
   'insertText',
   'setLayoutZoomLevelLimits',
   'setVisualZoomLevelLimits',
-  'setZoomFactor',
-  'setZoomLevel',
   // TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
   'setZoomLevelLimits'
 ]
-const webFrameMethodsWithResult = [
-  'getZoomFactor',
-  'getZoomLevel'
-]
+const webFrameMethodsWithResult = []
 
 const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
   return new Promise((resolve, reject) => {