[geary/geary-0.12] Ensure web view zoom level is always within a reasonable bounds.



commit 8919e9811adaf1ac15530360fda687b3fd2fd94f
Author: Michael James Gratton <mike vee net>
Date:   Tue Jun 12 11:49:06 2018 +1000

    Ensure web view zoom level is always within a reasonable bounds.
    
    Fixes Bug 773440 and addresses part of issue #1.

 src/client/components/client-web-view.vala | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index 01185fe2..44949aab 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -33,6 +33,8 @@ public class ClientWebView : WebKit.WebView, Geary.BaseInterface {
 
     private const double ZOOM_DEFAULT = 1.0;
     private const double ZOOM_FACTOR = 0.1;
+    private const double ZOOM_MAX = 2.0;
+    private const double ZOOM_MIN = 0.5;
 
 
     // Workaround WK binding ctor not accepting any args
@@ -308,8 +310,13 @@ public class ClientWebView : WebKit.WebView, Geary.BaseInterface {
             SELECTION_CHANGED, on_selection_changed
         );
 
-        // Manage zoom level
+        // Manage zoom level, ensure it's sane
         config.bind(Configuration.CONVERSATION_VIEWER_ZOOM_KEY, this, "zoom_level");
+        if (this.zoom_level < ZOOM_MIN) {
+            this.zoom_level = ZOOM_MIN;
+        } else if (this.zoom_level > ZOOM_MAX) {
+            this.zoom_level = ZOOM_MAX;
+        }
         this.scroll_event.connect(on_scroll_event);
 
         // Watch desktop font settings
@@ -403,11 +410,19 @@ public class ClientWebView : WebKit.WebView, Geary.BaseInterface {
     }
 
     public void zoom_in() {
-        this.zoom_level += (this.zoom_level * ZOOM_FACTOR);
+        double new_zoom = this.zoom_level += (this.zoom_level * ZOOM_FACTOR);
+        if (new_zoom > ZOOM_MAX) {
+            new_zoom = ZOOM_MAX;
+        }
+        this.zoom_level = new_zoom;
     }
 
     public void zoom_out() {
-        this.zoom_level -= (this.zoom_level * ZOOM_FACTOR);
+        double new_zoom = this.zoom_level -= (this.zoom_level * ZOOM_FACTOR);
+        if (new_zoom < ZOOM_MIN) {
+            new_zoom = ZOOM_MIN;
+        }
+        this.zoom_level = new_zoom;
     }
 
     /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]