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