Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / pdf / viewport.js
index 418ad44..7a225da 100644 (file)
@@ -70,12 +70,21 @@ Viewport.SCROLL_INCREMENT = 40;
 
 /**
  * Predefined zoom factors to be used when zooming in/out. These are in
- * ascending order.
+ * ascending order. This should match the list in
+ * chrome/browser/chrome_page_zoom_constants.cc.
  */
 Viewport.ZOOM_FACTORS = [0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1,
                          1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5];
 
 /**
+ * The minimum and maximum range to be used to clip zoom factor.
+ */
+Viewport.ZOOM_FACTOR_RANGE = {
+  min: Viewport.ZOOM_FACTORS[0],
+  max: Viewport.ZOOM_FACTORS[Viewport.ZOOM_FACTORS.length - 1]
+};
+
+/**
  * The width of the page shadow around pages in pixels.
  */
 Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5};
@@ -230,6 +239,8 @@ Viewport.prototype = {
    * @param {number} newZoom the zoom level to zoom to.
    */
   setZoom: function(newZoom) {
+    newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min,
+                       Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max));
     this.mightZoom_(function() {
       this.setZoomInternal_(newZoom);
       this.updateViewport_();
@@ -449,7 +460,7 @@ Viewport.prototype = {
 
   /**
    * Go to the given page index.
-   * @param {number} page the index of the page to go to.
+   * @param {number} page the index of the page to go to. zero-based.
    */
   goToPage: function(page) {
     this.mightZoom_(function() {