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 height of the intersection of two rectangles. | 6 * Returns the height 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 height of the intersection of the rects | 9 * @return {number} the height of the intersection of the rects |
10 */ | 10 */ |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 updateViewport_: function() { | 148 updateViewport_: function() { |
149 this.viewportChangedCallback_(); | 149 this.viewportChangedCallback_(); |
150 }, | 150 }, |
151 | 151 |
152 /** | 152 /** |
153 * @private | 153 * @private |
154 * Called when the viewport size changes. | 154 * Called when the viewport size changes. |
155 */ | 155 */ |
156 resize_: function() { | 156 resize_: function() { |
157 if (this.fittingType_ == Viewport.FittingType.FIT_TO_PAGE) | 157 if (this.fittingType_ == Viewport.FittingType.FIT_TO_PAGE) |
158 this.fitToPage(); | 158 this.fitToPageAndScroll_(false); |
159 else if (this.fittingType_ == Viewport.FittingType.FIT_TO_WIDTH) | 159 else if (this.fittingType_ == Viewport.FittingType.FIT_TO_WIDTH) |
160 this.fitToWidth(); | 160 this.fitToWidth(); |
161 else | 161 else |
162 this.updateViewport_(); | 162 this.updateViewport_(); |
163 }, | 163 }, |
164 | 164 |
165 /** | 165 /** |
166 * @type {Object} the scroll position of the viewport. | 166 * @type {Object} the scroll position of the viewport. |
167 */ | 167 */ |
168 get position() { | 168 get position() { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 // document is used, which is equal to the size of the document width. | 400 // document is used, which is equal to the size of the document width. |
401 this.setZoomInternal_(this.computeFittingZoom_(this.documentDimensions_, | 401 this.setZoomInternal_(this.computeFittingZoom_(this.documentDimensions_, |
402 true)); | 402 true)); |
403 var page = this.getMostVisiblePage(); | 403 var page = this.getMostVisiblePage(); |
404 this.window_.scrollTo(0, oldY * this.zoom_); | 404 this.window_.scrollTo(0, oldY * this.zoom_); |
405 this.updateViewport_(); | 405 this.updateViewport_(); |
406 }.bind(this)); | 406 }.bind(this)); |
407 }, | 407 }, |
408 | 408 |
409 /** | 409 /** |
410 * Zoom the viewport so that a page consumes the entire viewport. Also scrolls | 410 * @private |
411 * to the top of the most visible page. | 411 * Zoom the viewport so that a page consumes the entire viewport. |
412 * @param {boolean} scrollToTopOfPage Set to true if the viewport should be | |
413 * scrolled to the top of the current page. Set to false if the viewport | |
414 * should remain at the current scroll position. | |
412 */ | 415 */ |
413 fitToPage: function() { | 416 fitToPageAndScroll_: function(scrollToTopOfPage) { |
Sam McNally
2015/02/17 03:42:21
This name suggests that it will always scroll some
raymes
2015/02/17 03:51:57
Done.
| |
414 this.mightZoom_(function() { | 417 this.mightZoom_(function() { |
415 this.fittingType_ = Viewport.FittingType.FIT_TO_PAGE; | 418 this.fittingType_ = Viewport.FittingType.FIT_TO_PAGE; |
416 if (!this.documentDimensions_) | 419 if (!this.documentDimensions_) |
417 return; | 420 return; |
418 var page = this.getMostVisiblePage(); | 421 var page = this.getMostVisiblePage(); |
419 // Fit to the current page's height and the widest page's width. | 422 // Fit to the current page's height and the widest page's width. |
420 var dimensions = { | 423 var dimensions = { |
421 width: this.documentDimensions_.width, | 424 width: this.documentDimensions_.width, |
422 height: this.pageDimensions_[page].height, | 425 height: this.pageDimensions_[page].height, |
423 }; | 426 }; |
427 // Track the last y-position to stay at the same position after zooming. | |
428 var oldY = this.window_.pageYOffset / this.zoom_; | |
424 this.setZoomInternal_(this.computeFittingZoom_(dimensions, false)); | 429 this.setZoomInternal_(this.computeFittingZoom_(dimensions, false)); |
425 this.window_.scrollTo(0, this.pageDimensions_[page].y * this.zoom_); | 430 if (scrollToTopOfPage) |
431 this.window_.scrollTo(0, this.pageDimensions_[page].y * this.zoom_); | |
432 else | |
433 this.window_.scrollTo(0, oldY * this.zoom_); | |
Sam McNally
2015/02/17 03:42:21
Shouldn't setZoomInternal_ do this?
raymes
2015/02/17 03:51:57
I guess the only difference is we want to scroll t
| |
426 this.updateViewport_(); | 434 this.updateViewport_(); |
427 }.bind(this)); | 435 }.bind(this)); |
428 }, | 436 }, |
429 | 437 |
430 /** | 438 /** |
439 * Zoom the viewport so that a page consumes the entire viewport. Also scrolls | |
440 * the viewport to the top of the current page. | |
441 */ | |
442 fitToPage: function() { | |
443 this.fitToPageAndScroll_(true); | |
444 }, | |
445 | |
446 /** | |
431 * Zoom out to the next predefined zoom level. | 447 * Zoom out to the next predefined zoom level. |
432 */ | 448 */ |
433 zoomOut: function() { | 449 zoomOut: function() { |
434 this.mightZoom_(function() { | 450 this.mightZoom_(function() { |
435 this.fittingType_ = Viewport.FittingType.NONE; | 451 this.fittingType_ = Viewport.FittingType.NONE; |
436 var nextZoom = Viewport.ZOOM_FACTORS[0]; | 452 var nextZoom = Viewport.ZOOM_FACTORS[0]; |
437 for (var i = 0; i < Viewport.ZOOM_FACTORS.length; i++) { | 453 for (var i = 0; i < Viewport.ZOOM_FACTORS.length; i++) { |
438 if (Viewport.ZOOM_FACTORS[i] < this.zoom_) | 454 if (Viewport.ZOOM_FACTORS[i] < this.zoom_) |
439 nextZoom = Viewport.ZOOM_FACTORS[i]; | 455 nextZoom = Viewport.ZOOM_FACTORS[i]; |
440 } | 456 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 spaceOnLeft = Math.max(spaceOnLeft, 0); | 557 spaceOnLeft = Math.max(spaceOnLeft, 0); |
542 | 558 |
543 return { | 559 return { |
544 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, | 560 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, |
545 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, | 561 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, |
546 width: insetDimensions.width * this.zoom_, | 562 width: insetDimensions.width * this.zoom_, |
547 height: insetDimensions.height * this.zoom_ | 563 height: insetDimensions.height * this.zoom_ |
548 }; | 564 }; |
549 } | 565 } |
550 }; | 566 }; |
OLD | NEW |