| 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * @type {Viewport.FittingType} the fitting type the viewport is currently in. | 441 * @type {Viewport.FittingType} the fitting type the viewport is currently in. |
| 442 */ | 442 */ |
| 443 get fittingType() { | 443 get fittingType() { |
| 444 return this.fittingType_; | 444 return this.fittingType_; |
| 445 }, | 445 }, |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * @private | 448 * @private |
| 449 * @param {integer} y the y-coordinate to get the page at. | 449 * @param {number} y the y-coordinate to get the page at. |
| 450 * @return {integer} the index of a page overlapping the given y-coordinate. | 450 * @return {number} the index of a page overlapping the given y-coordinate. |
| 451 */ | 451 */ |
| 452 getPageAtY_: function(y) { | 452 getPageAtY_: function(y) { |
| 453 var min = 0; | 453 var min = 0; |
| 454 var max = this.pageDimensions_.length - 1; | 454 var max = this.pageDimensions_.length - 1; |
| 455 while (max >= min) { | 455 while (max >= min) { |
| 456 var page = Math.floor(min + ((max - min) / 2)); | 456 var page = Math.floor(min + ((max - min) / 2)); |
| 457 // There might be a gap between the pages, in which case use the bottom | 457 // There might be a gap between the pages, in which case use the bottom |
| 458 // of the previous page as the top for finding the page. | 458 // of the previous page as the top for finding the page. |
| 459 var top = 0; | 459 var top = 0; |
| 460 if (page > 0) { | 460 if (page > 0) { |
| 461 top = this.pageDimensions_[page - 1].y + | 461 top = this.pageDimensions_[page - 1].y + |
| 462 this.pageDimensions_[page - 1].height; | 462 this.pageDimensions_[page - 1].height; |
| 463 } | 463 } |
| 464 var bottom = this.pageDimensions_[page].y + | 464 var bottom = this.pageDimensions_[page].y + |
| 465 this.pageDimensions_[page].height; | 465 this.pageDimensions_[page].height; |
| 466 | 466 |
| 467 if (top <= y && bottom > y) | 467 if (top <= y && bottom > y) |
| 468 return page; | 468 return page; |
| 469 else if (top > y) | 469 else if (top > y) |
| 470 max = page - 1; | 470 max = page - 1; |
| 471 else | 471 else |
| 472 min = page + 1; | 472 min = page + 1; |
| 473 } | 473 } |
| 474 return 0; | 474 return 0; |
| 475 }, | 475 }, |
| 476 | 476 |
| 477 /** | 477 /** |
| 478 * Returns the page with the greatest proportion of its height in the current | 478 * Returns the page with the greatest proportion of its height in the current |
| 479 * viewport. | 479 * viewport. |
| 480 * @return {int} the index of the most visible page. | 480 * @return {number} the index of the most visible page. |
| 481 */ | 481 */ |
| 482 getMostVisiblePage: function() { | 482 getMostVisiblePage: function() { |
| 483 var firstVisiblePage = this.getPageAtY_(this.position.y / this.zoom); | 483 var firstVisiblePage = this.getPageAtY_(this.position.y / this.zoom); |
| 484 if (firstVisiblePage == this.pageDimensions_.length - 1) | 484 if (firstVisiblePage == this.pageDimensions_.length - 1) |
| 485 return firstVisiblePage; | 485 return firstVisiblePage; |
| 486 | 486 |
| 487 var viewportRect = { | 487 var viewportRect = { |
| 488 x: this.position.x / this.zoom, | 488 x: this.position.x / this.zoom, |
| 489 y: this.position.y / this.zoom, | 489 y: this.position.y / this.zoom, |
| 490 width: this.size.width / this.zoom, | 490 width: this.size.width / this.zoom, |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 spaceOnLeft = Math.max(spaceOnLeft, 0); | 815 spaceOnLeft = Math.max(spaceOnLeft, 0); |
| 816 | 816 |
| 817 return { | 817 return { |
| 818 x: x * this.zoom + spaceOnLeft - this.window_.pageXOffset, | 818 x: x * this.zoom + spaceOnLeft - this.window_.pageXOffset, |
| 819 y: insetDimensions.y * this.zoom - this.window_.pageYOffset, | 819 y: insetDimensions.y * this.zoom - this.window_.pageYOffset, |
| 820 width: insetDimensions.width * this.zoom, | 820 width: insetDimensions.width * this.zoom, |
| 821 height: insetDimensions.height * this.zoom | 821 height: insetDimensions.height * this.zoom |
| 822 }; | 822 }; |
| 823 } | 823 } |
| 824 }; | 824 }; |
| OLD | NEW |