Chromium Code Reviews| 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 = {min: 0.1, max: 10.0}; | |
|
raymes
2014/08/22 01:02:23
could we set min to Viewport.ZOOM_FACTORS[0] and m
Nikhil
2014/08/22 03:07:42
Hmm, I've set min to 0.1 and max to 10.0 based on
Nikhil
2014/08/22 04:59:04
Done.
| |
| 83 | |
| 84 /** | |
| 80 * The width of the page shadow around pages in pixels. | 85 * The width of the page shadow around pages in pixels. |
| 81 */ | 86 */ |
| 82 Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5}; | 87 Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5}; |
| 83 | 88 |
| 84 Viewport.prototype = { | 89 Viewport.prototype = { |
| 85 /** | 90 /** |
| 86 * @private | 91 * @private |
| 87 * Returns true if the document needs scrollbars at the given zoom level. | 92 * Returns true if the document needs scrollbars at the given zoom level. |
| 88 * @param {number} zoom compute whether scrollbars are needed at this zoom | 93 * @param {number} zoom compute whether scrollbars are needed at this zoom |
| 89 * @return {Object} with 'horizontal' and 'vertical' keys which map to bool | 94 * @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( | 229 this.window_.scrollTo( |
| 225 currentScrollPos[0] * newZoom - this.window_.innerWidth / 2, | 230 currentScrollPos[0] * newZoom - this.window_.innerWidth / 2, |
| 226 currentScrollPos[1] * newZoom - this.window_.innerHeight / 2); | 231 currentScrollPos[1] * newZoom - this.window_.innerHeight / 2); |
| 227 }, | 232 }, |
| 228 | 233 |
| 229 /** | 234 /** |
| 230 * Sets the zoom to the given zoom level. | 235 * Sets the zoom to the given zoom level. |
| 231 * @param {number} newZoom the zoom level to zoom to. | 236 * @param {number} newZoom the zoom level to zoom to. |
| 232 */ | 237 */ |
| 233 setZoom: function(newZoom) { | 238 setZoom: function(newZoom) { |
| 239 newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min, | |
| 240 Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max)); | |
| 234 this.mightZoom_(function() { | 241 this.mightZoom_(function() { |
| 235 this.setZoomInternal_(newZoom); | 242 this.setZoomInternal_(newZoom); |
| 236 this.updateViewport_(); | 243 this.updateViewport_(); |
| 237 }.bind(this)); | 244 }.bind(this)); |
| 238 }, | 245 }, |
| 239 | 246 |
| 240 /** | 247 /** |
| 241 * @type {number} the width of scrollbars in the viewport in pixels. | 248 * @type {number} the width of scrollbars in the viewport in pixels. |
| 242 */ | 249 */ |
| 243 get scrollbarWidth() { | 250 get scrollbarWidth() { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 spaceOnLeft = Math.max(spaceOnLeft, 0); | 537 spaceOnLeft = Math.max(spaceOnLeft, 0); |
| 531 | 538 |
| 532 return { | 539 return { |
| 533 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, | 540 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, |
| 534 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, | 541 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, |
| 535 width: insetDimensions.width * this.zoom_, | 542 width: insetDimensions.width * this.zoom_, |
| 536 height: insetDimensions.height * this.zoom_ | 543 height: insetDimensions.height * this.zoom_ |
| 537 }; | 544 }; |
| 538 } | 545 } |
| 539 }; | 546 }; |
| OLD | NEW |