| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Returns the area of the intersection of two rectangles. | 6 * Returns the area of the intersection of two rectangles. |
| 7 * @param {Object} rect1 the first rect | 7 * @param {Object} rect1 the first rect |
| 8 * @param {Object} rect2 the second rect | 8 * @param {Object} rect2 the second rect |
| 9 * @return {number} the area of the intersection of the rects | 9 * @return {number} the area of the intersection of the rects |
| 10 */ | 10 */ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Predefined zoom factors to be used when zooming in/out. These are in | 72 * Predefined zoom factors to be used when zooming in/out. These are in |
| 73 * ascending order. This should match the list in | 73 * ascending order. This should match the list in |
| 74 * chrome/browser/chrome_page_zoom_constants.cc. | 74 * chrome/browser/chrome_page_zoom_constants.cc. |
| 75 */ | 75 */ |
| 76 Viewport.ZOOM_FACTORS = [0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1, | 76 Viewport.ZOOM_FACTORS = [0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1, |
| 77 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5]; | 77 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5]; |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * The minimum and maximum range to be used to clip zoom factor. |
| 81 */ |
| 82 Viewport.ZOOM_FACTOR_RANGE = { |
| 83 min: Viewport.ZOOM_FACTORS[0], |
| 84 max: Viewport.ZOOM_FACTORS[Viewport.ZOOM_FACTORS.length - 1] |
| 85 }; |
| 86 |
| 87 /** |
| 80 * The width of the page shadow around pages in pixels. | 88 * The width of the page shadow around pages in pixels. |
| 81 */ | 89 */ |
| 82 Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5}; | 90 Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5}; |
| 83 | 91 |
| 84 Viewport.prototype = { | 92 Viewport.prototype = { |
| 85 /** | 93 /** |
| 86 * @private | 94 * @private |
| 87 * Returns true if the document needs scrollbars at the given zoom level. | 95 * Returns true if the document needs scrollbars at the given zoom level. |
| 88 * @param {number} zoom compute whether scrollbars are needed at this zoom | 96 * @param {number} zoom compute whether scrollbars are needed at this zoom |
| 89 * @return {Object} with 'horizontal' and 'vertical' keys which map to bool | 97 * @return {Object} with 'horizontal' and 'vertical' keys which map to bool |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 this.window_.scrollTo( | 232 this.window_.scrollTo( |
| 225 currentScrollPos[0] * newZoom - this.window_.innerWidth / 2, | 233 currentScrollPos[0] * newZoom - this.window_.innerWidth / 2, |
| 226 currentScrollPos[1] * newZoom - this.window_.innerHeight / 2); | 234 currentScrollPos[1] * newZoom - this.window_.innerHeight / 2); |
| 227 }, | 235 }, |
| 228 | 236 |
| 229 /** | 237 /** |
| 230 * Sets the zoom to the given zoom level. | 238 * Sets the zoom to the given zoom level. |
| 231 * @param {number} newZoom the zoom level to zoom to. | 239 * @param {number} newZoom the zoom level to zoom to. |
| 232 */ | 240 */ |
| 233 setZoom: function(newZoom) { | 241 setZoom: function(newZoom) { |
| 242 newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min, |
| 243 Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max)); |
| 234 this.mightZoom_(function() { | 244 this.mightZoom_(function() { |
| 235 this.setZoomInternal_(newZoom); | 245 this.setZoomInternal_(newZoom); |
| 236 this.updateViewport_(); | 246 this.updateViewport_(); |
| 237 }.bind(this)); | 247 }.bind(this)); |
| 238 }, | 248 }, |
| 239 | 249 |
| 240 /** | 250 /** |
| 241 * @type {number} the width of scrollbars in the viewport in pixels. | 251 * @type {number} the width of scrollbars in the viewport in pixels. |
| 242 */ | 252 */ |
| 243 get scrollbarWidth() { | 253 get scrollbarWidth() { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 spaceOnLeft = Math.max(spaceOnLeft, 0); | 540 spaceOnLeft = Math.max(spaceOnLeft, 0); |
| 531 | 541 |
| 532 return { | 542 return { |
| 533 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, | 543 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, |
| 534 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, | 544 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, |
| 535 width: insetDimensions.width * this.zoom_, | 545 width: insetDimensions.width * this.zoom_, |
| 536 height: insetDimensions.height * this.zoom_ | 546 height: insetDimensions.height * this.zoom_ |
| 537 }; | 547 }; |
| 538 } | 548 } |
| 539 }; | 549 }; |
| OLD | NEW |