| Index: chrome/browser/resources/pdf/viewport.js
|
| diff --git a/chrome/browser/resources/pdf/viewport.js b/chrome/browser/resources/pdf/viewport.js
|
| index 607f70ed90745e88c8186d10fc24b715a302a7cb..7b223c40f88109c98bd9df67161b0e99441b8092 100644
|
| --- a/chrome/browser/resources/pdf/viewport.js
|
| +++ b/chrome/browser/resources/pdf/viewport.js
|
| @@ -9,9 +9,9 @@
|
| * @return {number} the height of the intersection of the rects
|
| */
|
| function getIntersectionHeight(rect1, rect2) {
|
| - return Math.max(0,
|
| - Math.min(rect1.y + rect1.height, rect2.y + rect2.height) -
|
| - Math.max(rect1.y, rect2.y));
|
| + return Math.max(
|
| + 0, Math.min(rect1.y + rect1.height, rect2.y + rect2.height) -
|
| + Math.max(rect1.y, rect2.y));
|
| }
|
|
|
| /**
|
| @@ -30,10 +30,7 @@ function clampScale(scale) {
|
| * @return {!Object} The vector.
|
| */
|
| function vectorDelta(p1, p2) {
|
| - return {
|
| - x: p2.x - p1.x,
|
| - y: p2.y - p1.y
|
| - };
|
| + return {x: p2.x - p1.x, y: p2.y - p1.y};
|
| }
|
|
|
| function frameToPluginCoordinate(coordinateInFrame) {
|
| @@ -58,14 +55,9 @@ function frameToPluginCoordinate(coordinateInFrame) {
|
| * @param {number} topToolbarHeight The number of pixels that should initially
|
| * be left blank above the document for the toolbar.
|
| */
|
| -function Viewport(window,
|
| - sizer,
|
| - viewportChangedCallback,
|
| - beforeZoomCallback,
|
| - afterZoomCallback,
|
| - scrollbarWidth,
|
| - defaultZoom,
|
| - topToolbarHeight) {
|
| +function Viewport(
|
| + window, sizer, viewportChangedCallback, beforeZoomCallback,
|
| + afterZoomCallback, scrollbarWidth, defaultZoom, topToolbarHeight) {
|
| this.window_ = window;
|
| this.sizer_ = sizer;
|
| this.viewportChangedCallback_ = viewportChangedCallback;
|
| @@ -127,8 +119,10 @@ Viewport.SCROLL_INCREMENT = 40;
|
| * components/ui/zoom/page_zoom_constants.h and
|
| * chrome/browser/resources/settings/appearance_page/appearance_page.js
|
| */
|
| -Viewport.ZOOM_FACTORS = [0.25, 1 / 3, 0.5, 2 / 3, 0.75, 0.8, 0.9,
|
| - 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5];
|
| +Viewport.ZOOM_FACTORS = [
|
| + 0.25, 1 / 3, 0.5, 2 / 3, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3,
|
| + 4, 5
|
| +];
|
|
|
| /**
|
| * The minimum and maximum range to be used to clip zoom factor.
|
| @@ -141,7 +135,12 @@ Viewport.ZOOM_FACTOR_RANGE = {
|
| /**
|
| * The width of the page shadow around pages in pixels.
|
| */
|
| -Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5};
|
| +Viewport.PAGE_SHADOW = {
|
| + top: 3,
|
| + bottom: 7,
|
| + left: 5,
|
| + right: 5
|
| +};
|
|
|
| Viewport.prototype = {
|
| /**
|
| @@ -173,10 +172,7 @@ Viewport.prototype = {
|
| documentNeedsScrollbars_: function(zoom) {
|
| var zoomedDimensions = this.getZoomedDocumentDimensions_(zoom);
|
| if (!zoomedDimensions) {
|
| - return {
|
| - horizontal: false,
|
| - vertical: false
|
| - };
|
| + return {horizontal: false, vertical: false};
|
| }
|
|
|
| // If scrollbars are required for one direction, expand the document in the
|
| @@ -211,8 +207,8 @@ Viewport.prototype = {
|
| var zoomedDimensions = this.getZoomedDocumentDimensions_(this.zoom);
|
| if (zoomedDimensions) {
|
| this.sizer_.style.width = zoomedDimensions.width + 'px';
|
| - this.sizer_.style.height = zoomedDimensions.height +
|
| - this.topToolbarHeight_ + 'px';
|
| + this.sizer_.style.height =
|
| + zoomedDimensions.height + this.topToolbarHeight_ + 'px';
|
| }
|
| },
|
|
|
| @@ -329,7 +325,7 @@ Viewport.prototype = {
|
| setZoomInternal_: function(newZoom) {
|
| if (!this.allowedToChangeZoom_) {
|
| throw 'Called Viewport.setZoomInternal_ without calling ' +
|
| - 'Viewport.mightZoom_.';
|
| + 'Viewport.mightZoom_.';
|
| }
|
| // Record the scroll position (relative to the top-left of the window).
|
| var currentScrollPos = {
|
| @@ -353,9 +349,10 @@ Viewport.prototype = {
|
| * @param {!Object} center The pinch center in content coordinates.
|
| */
|
| setPinchZoomInternal_: function(scaleDelta, center) {
|
| - assert(this.allowedToChangeZoom_,
|
| + assert(
|
| + this.allowedToChangeZoom_,
|
| 'Called Viewport.setPinchZoomInternal_ without calling ' +
|
| - 'Viewport.mightZoom_.');
|
| + 'Viewport.mightZoom_.');
|
| this.internalZoom_ = clampScale(this.internalZoom_ * scaleDelta);
|
|
|
| var newCenterInContent = this.frameToContent(center);
|
| @@ -372,10 +369,7 @@ Viewport.prototype = {
|
|
|
| this.contentSizeChanged_();
|
| // Scroll to the scaled scroll position.
|
| - this.position = {
|
| - x: currentScrollPos.x,
|
| - y: currentScrollPos.y
|
| - };
|
| + this.position = {x: currentScrollPos.x, y: currentScrollPos.y};
|
| },
|
|
|
| /**
|
| @@ -399,8 +393,9 @@ Viewport.prototype = {
|
| */
|
| setZoom: function(newZoom) {
|
| this.fittingType_ = Viewport.FittingType.NONE;
|
| - newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min,
|
| - Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max));
|
| + newZoom = Math.max(
|
| + Viewport.ZOOM_FACTOR_RANGE.min,
|
| + Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max));
|
| this.mightZoom_(function() {
|
| this.setZoomInternal_(newZoom);
|
| this.updateViewport_();
|
| @@ -461,8 +456,8 @@ Viewport.prototype = {
|
| top = this.pageDimensions_[page - 1].y +
|
| this.pageDimensions_[page - 1].height;
|
| }
|
| - var bottom = this.pageDimensions_[page].y +
|
| - this.pageDimensions_[page].height;
|
| + var bottom =
|
| + this.pageDimensions_[page].y + this.pageDimensions_[page].height;
|
|
|
| if (top <= y && bottom > y)
|
| return page;
|
| @@ -490,11 +485,13 @@ Viewport.prototype = {
|
| width: this.size.width / this.zoom,
|
| height: this.size.height / this.zoom
|
| };
|
| - var firstVisiblePageVisibility = getIntersectionHeight(
|
| - this.pageDimensions_[firstVisiblePage], viewportRect) /
|
| + var firstVisiblePageVisibility =
|
| + getIntersectionHeight(
|
| + this.pageDimensions_[firstVisiblePage], viewportRect) /
|
| this.pageDimensions_[firstVisiblePage].height;
|
| - var nextPageVisibility = getIntersectionHeight(
|
| - this.pageDimensions_[firstVisiblePage + 1], viewportRect) /
|
| + var nextPageVisibility =
|
| + getIntersectionHeight(
|
| + this.pageDimensions_[firstVisiblePage + 1], viewportRect) /
|
| this.pageDimensions_[firstVisiblePage + 1].height;
|
| if (nextPageVisibility > firstVisiblePageVisibility)
|
| return firstVisiblePage + 1;
|
| @@ -573,8 +570,8 @@ Viewport.prototype = {
|
| return;
|
| // When computing fit-to-width, the maximum width of a page in the
|
| // document is used, which is equal to the size of the document width.
|
| - this.setZoomInternal_(this.computeFittingZoom_(this.documentDimensions_,
|
| - true));
|
| + this.setZoomInternal_(
|
| + this.computeFittingZoom_(this.documentDimensions_, true));
|
| var page = this.getMostVisiblePage();
|
| this.updateViewport_();
|
| }.bind(this));
|
| @@ -600,10 +597,7 @@ Viewport.prototype = {
|
| };
|
| this.setZoomInternal_(this.computeFittingZoom_(dimensions, false));
|
| if (scrollToTopOfPage) {
|
| - this.position = {
|
| - x: 0,
|
| - y: this.pageDimensions_[page].y * this.zoom
|
| - };
|
| + this.position = {x: 0, y: this.pageDimensions_[page].y * this.zoom};
|
| }
|
| this.updateViewport_();
|
| }.bind(this));
|
| @@ -656,15 +650,15 @@ Viewport.prototype = {
|
| pinchZoom: function(e) {
|
| this.mightZoom_(function() {
|
| this.pinchPhase_ = e.direction == 'out' ?
|
| - Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT :
|
| - Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN;
|
| + Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT :
|
| + Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN;
|
|
|
| var scaleDelta = e.startScaleRatio / this.prevScale_;
|
| this.pinchPanVector_ =
|
| vectorDelta(e.center, this.firstPinchCenterInFrame_);
|
|
|
| - var needsScrollbars = this.documentNeedsScrollbars_(
|
| - this.zoomManager_.applyBrowserZoom(
|
| + var needsScrollbars =
|
| + this.documentNeedsScrollbars_(this.zoomManager_.applyBrowserZoom(
|
| clampScale(this.internalZoom_ * scaleDelta)));
|
|
|
| this.pinchCenter_ = e.center;
|
| @@ -686,8 +680,7 @@ Viewport.prototype = {
|
| this.keepContentCentered_ = false;
|
| }
|
|
|
| - this.setPinchZoomInternal_(
|
| - scaleDelta, frameToPluginCoordinate(e.center));
|
| + this.setPinchZoomInternal_(scaleDelta, frameToPluginCoordinate(e.center));
|
| this.updateViewport_();
|
| this.prevScale_ = e.startScaleRatio;
|
| }.bind(this));
|
| @@ -712,8 +705,7 @@ Viewport.prototype = {
|
| var scaleDelta = e.startScaleRatio / this.prevScale_;
|
| this.pinchCenter_ = e.center;
|
|
|
| - this.setPinchZoomInternal_(
|
| - scaleDelta, frameToPluginCoordinate(e.center));
|
| + this.setPinchZoomInternal_(scaleDelta, frameToPluginCoordinate(e.center));
|
| this.updateViewport_();
|
| }.bind(this));
|
|
|
| @@ -760,13 +752,10 @@ Viewport.prototype = {
|
| this.documentDimensions_ = documentDimensions;
|
| this.pageDimensions_ = this.documentDimensions_.pageDimensions;
|
| if (initialDimensions) {
|
| - this.setZoomInternal_(
|
| - Math.min(this.defaultZoom_,
|
| - this.computeFittingZoom_(this.documentDimensions_, true)));
|
| - this.position = {
|
| - x: 0,
|
| - y: -this.topToolbarHeight_
|
| - };
|
| + this.setZoomInternal_(Math.min(
|
| + this.defaultZoom_,
|
| + this.computeFittingZoom_(this.documentDimensions_, true)));
|
| + this.position = {x: 0, y: -this.topToolbarHeight_};
|
| }
|
| this.contentSizeChanged_();
|
| this.resize_();
|
| @@ -781,12 +770,7 @@ Viewport.prototype = {
|
| */
|
| getPageScreenRect: function(page) {
|
| if (!this.documentDimensions_) {
|
| - return {
|
| - x: 0,
|
| - y: 0,
|
| - width: 0,
|
| - height: 0
|
| - };
|
| + return {x: 0, y: 0, width: 0, height: 0};
|
| }
|
| if (page >= this.pageDimensions_.length)
|
| page = this.pageDimensions_.length - 1;
|
| @@ -810,8 +794,8 @@ Viewport.prototype = {
|
| Viewport.PAGE_SHADOW.left;
|
| // Compute the space on the left of the document if the document fits
|
| // completely in the screen.
|
| - var spaceOnLeft = (this.size.width -
|
| - this.documentDimensions_.width * this.zoom) / 2;
|
| + var spaceOnLeft =
|
| + (this.size.width - this.documentDimensions_.width * this.zoom) / 2;
|
| spaceOnLeft = Math.max(spaceOnLeft, 0);
|
|
|
| return {
|
|
|