Commit afba4e4b authored by dstockwell's avatar dstockwell Committed by Commit Bot

pdf: enable eslint checks for no-var and prefer-const

Most of this change was automated by running `eslint --fix` but a
few cases were resolved manually (in particular global definitions
and typedefs).

Bug: 792774
Change-Id: Iea4e373a088d7d276975bf946a738bc9d81772c3
Reviewed-on: https://chromium-review.googlesource.com/c/1355302
Commit-Queue: dstockwell <dstockwell@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612985}
parent a87dcc51
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module.exports = {
env: {
'browser': true,
'es6': true,
},
rules: {
'no-var': 'error',
'prefer-const': 'error',
},
};
......@@ -142,7 +142,7 @@ class BrowserApi {
return;
chrome.tabs.onZoomChange.addListener(info => {
var zoomChangeInfo =
const zoomChangeInfo =
/** @type {{tabId: number, newZoomFactor: number}} */ (info);
if (zoomChangeInfo.tabId != this.streamInfo_.tabId)
return;
......@@ -172,7 +172,7 @@ function createBrowserApiForMimeHandlerView() {
chrome.mimeHandlerPrivate.getStreamInfo(resolve);
})
.then(function(streamInfo) {
let promises = [];
const promises = [];
let zoomBehavior = BrowserApi.ZoomBehavior.NONE;
if (streamInfo.tabId != -1) {
zoomBehavior = streamInfo.embedded ?
......@@ -204,8 +204,8 @@ function createBrowserApiForMimeHandlerView() {
* from the URL.
*/
function createBrowserApiForPrintPreview() {
let url = window.location.search.substring(1);
let streamInfo = {
const url = window.location.search.substring(1);
const streamInfo = {
streamUrl: url,
originalUrl: url,
responseHeaders: {},
......
......@@ -21,11 +21,11 @@
* children: !Array<!Bookmark>
* }}
*/
var Bookmark;
let Bookmark;
(function() {
/** Amount that each level of bookmarks is indented by (px). */
var BOOKMARK_INDENT = 20;
const BOOKMARK_INDENT = 20;
Polymer({
is: 'viewer-bookmark',
......
......@@ -18,7 +18,7 @@ Polymer({
/** @override */
ready: function() {
var callback = this.fadeIn.bind(this, 2000);
const callback = this.fadeIn.bind(this, 2000);
window.addEventListener('scroll', function() {
requestAnimationFrame(callback);
});
......@@ -30,7 +30,7 @@ Polymer({
/** @param {number} displayTime */
fadeIn: function(displayTime) {
var percent = window.scrollY /
const percent = window.scrollY /
(document.scrollingElement.scrollHeight -
document.documentElement.clientHeight);
this.style.top =
......
......@@ -30,7 +30,7 @@ Polymer({
},
pageNoCommitted: function() {
var page = parseInt(this.pageSelector.value, 10);
const page = parseInt(this.pageSelector.value, 10);
if (!isNaN(page) && page <= this.docLength && page > 0)
this.fire('change-page', {page: page - 1, origin: 'pageselector'});
......@@ -41,7 +41,7 @@ Polymer({
/** @private */
docLengthChanged_: function() {
var numDigits = this.docLength.toString().length;
const numDigits = this.docLength.toString().length;
this.pageSelector.style.width = numDigits + 'ch';
// Set both sides of the slash to the same width, so that the layout is
// exactly centered.
......
......@@ -25,7 +25,7 @@ Polymer({
},
deny: function() {
var password = /** @type {!CrInputElement} */ (this.$.password);
const password = /** @type {!CrInputElement} */ (this.$.password);
password.disabled = false;
this.$.submit.disabled = false;
this.invalid = true;
......@@ -33,7 +33,7 @@ Polymer({
},
submit: function() {
var password = /** @type {!CrInputElement} */ (this.$.password);
const password = /** @type {!CrInputElement} */ (this.$.password);
if (password.value.length == 0)
return;
password.disabled = true;
......
......@@ -6,13 +6,13 @@
/**
* Size of additional padding in the inner scrollable section of the dropdown.
*/
var DROPDOWN_INNER_PADDING = 12;
const DROPDOWN_INNER_PADDING = 12;
/** Size of vertical padding on the outer #dropdown element. */
var DROPDOWN_OUTER_PADDING = 2;
const DROPDOWN_OUTER_PADDING = 2;
/** Minimum height of toolbar dropdowns (px). */
var MIN_DROPDOWN_HEIGHT = 200;
const MIN_DROPDOWN_HEIGHT = 200;
Polymer({
is: 'viewer-toolbar-dropdown',
......@@ -76,8 +76,8 @@ Polymer({
},
updateMaxHeight: function() {
var scrollContainer = this.$['scroll-container'];
var height = this.lowerBound - scrollContainer.getBoundingClientRect().top -
const scrollContainer = this.$['scroll-container'];
let height = this.lowerBound - scrollContainer.getBoundingClientRect().top -
DROPDOWN_INNER_PADDING;
height = Math.max(height, MIN_DROPDOWN_HEIGHT);
scrollContainer.style.maxHeight = height + 'px';
......@@ -100,7 +100,7 @@ Polymer({
},
animateEntry_: function() {
var maxHeight =
let maxHeight =
this.$.dropdown.getBoundingClientRect().height - DROPDOWN_OUTER_PADDING;
if (maxHeight < 0)
......
......@@ -4,8 +4,8 @@
(function() {
var FIT_TO_PAGE_BUTTON_STATE = 0;
var FIT_TO_WIDTH_BUTTON_STATE = 1;
const FIT_TO_PAGE_BUTTON_STATE = 0;
const FIT_TO_WIDTH_BUTTON_STATE = 1;
Polymer({
is: 'viewer-zoom-toolbar',
......@@ -49,7 +49,7 @@ Polymer({
this.fitToggle();
// Toggle the button state since there was no mouse click.
var button = this.$['fit-button'];
const button = this.$['fit-button'];
button.activeIndex =
(button.activeIndex == FIT_TO_WIDTH_BUTTON_STATE ?
FIT_TO_PAGE_BUTTON_STATE :
......@@ -64,7 +64,7 @@ Polymer({
this.fireFitToChangedEvent_(fittingType, false);
// Set the button state since there was no mouse click.
var nextButtonState =
const nextButtonState =
(fittingType == FittingType.FIT_TO_WIDTH ? FIT_TO_PAGE_BUTTON_STATE :
FIT_TO_WIDTH_BUTTON_STATE);
this.$['fit-button'].activeIndex = nextButtonState;
......@@ -115,5 +115,4 @@ Polymer({
}
},
});
})();
......@@ -21,7 +21,7 @@ class GestureDetector {
/** @type {function(!Event)} */ (this.onTouchStart_.bind(this)),
{passive: true});
let boundOnTouch =
const boundOnTouch =
/** @type {function(!Event)} */ (this.onTouch_.bind(this));
this.element_.addEventListener('touchmove', boundOnTouch, {passive: true});
this.element_.addEventListener('touchend', boundOnTouch, {passive: true});
......@@ -85,9 +85,9 @@ class GestureDetector {
* @private
*/
notify_(pinchEvent) {
let listeners = this.listeners_.get(pinchEvent.type);
const listeners = this.listeners_.get(pinchEvent.type);
for (let l of listeners)
for (const l of listeners)
l(pinchEvent);
}
......@@ -117,15 +117,15 @@ class GestureDetector {
if (!this.pinchStartEvent_)
return;
let lastEvent = /** @type {!TouchEvent} */ (this.lastEvent_);
const lastEvent = /** @type {!TouchEvent} */ (this.lastEvent_);
// Check if the pinch ends with the current event.
if (event.touches.length < 2 ||
lastEvent.touches.length !== event.touches.length) {
let startScaleRatio =
const startScaleRatio =
GestureDetector.pinchScaleRatio_(lastEvent, this.pinchStartEvent_);
let center = GestureDetector.center_(lastEvent);
let endEvent = {
const center = GestureDetector.center_(lastEvent);
const endEvent = {
type: 'pinchend',
startScaleRatio: startScaleRatio,
center: center
......@@ -136,10 +136,10 @@ class GestureDetector {
return;
}
let scaleRatio = GestureDetector.pinchScaleRatio_(event, lastEvent);
let startScaleRatio =
const scaleRatio = GestureDetector.pinchScaleRatio_(event, lastEvent);
const startScaleRatio =
GestureDetector.pinchScaleRatio_(event, this.pinchStartEvent_);
let center = GestureDetector.center_(event);
const center = GestureDetector.center_(event);
this.notify_({
type: 'pinchupdate',
scaleRatio: scaleRatio,
......@@ -169,11 +169,11 @@ class GestureDetector {
event.preventDefault();
let wheelScale = Math.exp(-event.deltaY / 100);
const wheelScale = Math.exp(-event.deltaY / 100);
// Clamp scale changes from the wheel event as they can be
// quite dramatic for non-synthetic ctrl-wheels.
let scale = Math.min(1.25, Math.max(0.75, wheelScale));
let position = {x: event.clientX, y: event.clientY};
const scale = Math.min(1.25, Math.max(0.75, wheelScale));
const position = {x: event.clientX, y: event.clientY};
if (this.accumulatedWheelScale_ == null) {
this.accumulatedWheelScale_ = 1.0;
......@@ -196,8 +196,8 @@ class GestureDetector {
window.clearTimeout(this.wheelEndTimeout_);
this.wheelEndTimeout_ = null;
}
let gestureEndDelayMs = 100;
let endEvent = {
const gestureEndDelayMs = 100;
const endEvent = {
type: 'pinchend',
startScaleRatio: this.accumulatedWheelScale_,
center: position
......@@ -220,8 +220,8 @@ class GestureDetector {
* @private
*/
static pinchScaleRatio_(event, prevEvent) {
let distance1 = GestureDetector.distance_(prevEvent);
let distance2 = GestureDetector.distance_(event);
const distance1 = GestureDetector.distance_(prevEvent);
const distance2 = GestureDetector.distance_(event);
return distance1 === 0 ? null : distance2 / distance1;
}
......@@ -233,10 +233,10 @@ class GestureDetector {
* @private
*/
static distance_(event) {
let touch1 = event.touches[0];
let touch2 = event.touches[1];
let dx = touch1.clientX - touch2.clientX;
let dy = touch1.clientY - touch2.clientY;
const touch1 = event.touches[0];
const touch2 = event.touches[1];
const dx = touch1.clientX - touch2.clientX;
const dy = touch1.clientY - touch2.clientY;
return Math.sqrt(dx * dx + dy * dy);
}
......@@ -248,8 +248,8 @@ class GestureDetector {
* @private
*/
static center_(event) {
let touch1 = event.touches[0];
let touch2 = event.touches[1];
const touch1 = event.touches[0];
const touch2 = event.touches[1];
return {
x: (touch1.clientX + touch2.clientX) / 2,
y: (touch1.clientY + touch2.clientY) / 2
......
......@@ -9,7 +9,7 @@
*
* @type Object
*/
var viewer;
window.viewer = null;
(function() {
......@@ -19,7 +19,7 @@ var viewer;
*
* @type Array
*/
var pendingMessages = [];
const pendingMessages = [];
/**
* Handles events that are received prior to the PDFViewer being created.
......@@ -72,7 +72,7 @@ function main() {
// Set up an event listener to catch scripting messages which are sent prior
// to the PDFViewer being created.
window.addEventListener('message', handleScriptingMessage, false);
var chain = createBrowserApi();
let chain = createBrowserApi();
// Content settings may not be present in test environments.
if (chrome.contentSettings)
......
......@@ -111,7 +111,7 @@ Navigator.prototype = {
if (url.charAt(0) == '#') {
// if '#' is already present in |originalUrl| then remove old fragment
// and add new url fragment.
var hashIndex = this.originalUrl_.search('#');
const hashIndex = this.originalUrl_.search('#');
if (hashIndex != -1)
url = this.originalUrl_.substring(0, hashIndex) + url;
else
......@@ -158,17 +158,17 @@ Navigator.prototype = {
* @private
*/
onViewportReceived_: function(viewportPosition) {
var originalUrl = this.originalUrl_;
var hashIndex = originalUrl.search('#');
let originalUrl = this.originalUrl_;
let hashIndex = originalUrl.search('#');
if (hashIndex != -1)
originalUrl = originalUrl.substring(0, hashIndex);
var newUrl = viewportPosition.url;
let newUrl = viewportPosition.url;
hashIndex = newUrl.search('#');
if (hashIndex != -1)
newUrl = newUrl.substring(0, hashIndex);
var pageNumber = viewportPosition.page;
const pageNumber = viewportPosition.page;
if (pageNumber != undefined && originalUrl == newUrl)
this.viewport_.goToPage(pageNumber);
else
......@@ -224,16 +224,17 @@ Navigator.prototype = {
// Check for absolute paths.
if (url.startsWith('/')) {
var schemeEndIndex = this.originalUrl_.indexOf('://');
var firstSlash = this.originalUrl_.indexOf('/', schemeEndIndex + 3);
const schemeEndIndex = this.originalUrl_.indexOf('://');
const firstSlash = this.originalUrl_.indexOf('/', schemeEndIndex + 3);
// e.g. http://www.foo.com/bar -> http://www.foo.com
var domain = firstSlash != -1 ? this.originalUrl_.substr(0, firstSlash) :
this.originalUrl_;
const domain = firstSlash != -1 ?
this.originalUrl_.substr(0, firstSlash) :
this.originalUrl_;
return domain + url;
}
// Check for obvious relative paths.
var isRelative = false;
let isRelative = false;
if (url.startsWith('.') || url.startsWith('\\'))
isRelative = true;
......@@ -244,19 +245,19 @@ Navigator.prototype = {
// www.foo.com/bar -> http
// foo.com/bar -> relative link
if (!isRelative) {
var domainSeparatorIndex = url.indexOf('/');
var domainName = domainSeparatorIndex == -1 ?
const domainSeparatorIndex = url.indexOf('/');
const domainName = domainSeparatorIndex == -1 ?
url :
url.substr(0, domainSeparatorIndex);
var domainDotCount = (domainName.match(/\./g) || []).length;
const domainDotCount = (domainName.match(/\./g) || []).length;
if (domainDotCount < 2)
isRelative = true;
}
if (isRelative) {
var slashIndex = this.originalUrl_.lastIndexOf('/');
var path = slashIndex != -1 ? this.originalUrl_.substr(0, slashIndex) :
this.originalUrl_;
const slashIndex = this.originalUrl_.lastIndexOf('/');
const path = slashIndex != -1 ? this.originalUrl_.substr(0, slashIndex) :
this.originalUrl_;
return path + '/' + url;
}
......
......@@ -114,7 +114,7 @@ window.OpenPDFParamsParser = class {
return params;
}
for (let paramToken of paramTokens) {
for (const paramToken of paramTokens) {
const keyValueSplit = paramToken.split('=');
if (keyValueSplit.length != 2)
continue;
......
......@@ -8,7 +8,7 @@
* Enumeration of page fitting types.
* @enum {string}
*/
var FittingType = {
const FittingType = {
NONE: 'none',
FIT_TO_PAGE: 'fit-to-page',
FIT_TO_WIDTH: 'fit-to-width',
......
......@@ -9,7 +9,7 @@
* @return {Event} A key event.
*/
function DeserializeKeyEvent(dict) {
var e = document.createEvent('Event');
const e = document.createEvent('Event');
e.initEvent('keydown', true, true);
e.keyCode = dict.keyCode;
e.code = dict.code;
......@@ -43,7 +43,11 @@ function SerializeKeyEvent(event) {
* has finished loading or failed to load.
* @enum {string}
*/
var LoadState = {LOADING: 'loading', SUCCESS: 'success', FAILED: 'failed'};
const LoadState = {
LOADING: 'loading',
SUCCESS: 'success',
FAILED: 'failed'
};
/**
* Create a new PDFScriptingAPI. This provides a scripting interface to
......@@ -76,25 +80,27 @@ function PDFScriptingAPI(window, plugin) {
* viewportHeight: number
* }}
*/
var viewportData = event.data;
const viewportData = event.data;
if (this.viewportChangedCallback_)
this.viewportChangedCallback_(
viewportData.pageX, viewportData.pageY, viewportData.pageWidth,
viewportData.viewportWidth, viewportData.viewportHeight);
break;
case 'documentLoaded':
var data = /** @type {{load_state: LoadState}} */ (event.data);
case 'documentLoaded': {
const data = /** @type {{load_state: LoadState}} */ (event.data);
this.loadState_ = data.load_state;
if (this.loadCallback_)
this.loadCallback_(this.loadState_ == LoadState.SUCCESS);
break;
case 'getSelectedTextReply':
var data = /** @type {{selectedText: string}} */ (event.data);
}
case 'getSelectedTextReply': {
const data = /** @type {{selectedText: string}} */ (event.data);
if (this.selectedTextCallback_) {
this.selectedTextCallback_(data.selectedText);
this.selectedTextCallback_ = null;
}
break;
}
case 'sendKeyEvent':
if (this.keyEventCallback_)
this.keyEventCallback_(DeserializeKeyEvent(event.data.keyEvent));
......@@ -257,8 +263,8 @@ PDFScriptingAPI.prototype = {
* @return {HTMLIFrameElement} the iframe element containing the PDF viewer.
*/
function PDFCreateOutOfProcessPlugin(src, baseUrl) {
var client = new PDFScriptingAPI(window, null);
var iframe = assertInstanceof(
const client = new PDFScriptingAPI(window, null);
const iframe = assertInstanceof(
window.document.createElement('iframe'), HTMLIFrameElement);
iframe.setAttribute('src', baseUrl + '/index.html?' + src);
// Prevent the frame from being tab-focusable.
......
......@@ -17,14 +17,14 @@ let SaveDataMessageData;
* @return {number} Width of a scrollbar in pixels
*/
function getScrollbarWidth() {
var div = document.createElement('div');
const div = document.createElement('div');
div.style.visibility = 'hidden';
div.style.overflow = 'scroll';
div.style.width = '50px';
div.style.height = '50px';
div.style.position = 'absolute';
document.body.appendChild(div);
var result = div.offsetWidth - div.clientWidth;
const result = div.offsetWidth - div.clientWidth;
div.parentNode.removeChild(div);
return result;
}
......@@ -37,9 +37,9 @@ function getScrollbarWidth() {
*/
function getFilenameFromURL(url) {
// Ignore the query and fragment.
var mainUrl = url.split(/#|\?/)[0];
var components = mainUrl.split(/\/|\\/);
var filename = components[components.length - 1];
const mainUrl = url.split(/#|\?/)[0];
const components = mainUrl.split(/\/|\\/);
const filename = components[components.length - 1];
try {
return decodeURIComponent(filename);
} catch (e) {
......@@ -142,7 +142,7 @@ function PDFViewer(browserApi) {
// Parse open pdf parameters.
this.paramsParser_ = new OpenPDFParamsParser(this.postMessage_.bind(this));
var toolbarEnabled =
const toolbarEnabled =
this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar &&
!this.isPrintPreview_;
......@@ -164,10 +164,10 @@ function PDFViewer(browserApi) {
}
// Create the viewport.
var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT;
var topToolbarHeight =
const shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT;
const topToolbarHeight =
(toolbarEnabled) ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0;
var defaultZoom =
const defaultZoom =
this.browserApi_.getZoomBehavior() == BrowserApi.ZoomBehavior.MANAGE ?
this.browserApi_.getDefaultZoom() :
1.0;
......@@ -199,14 +199,14 @@ function PDFViewer(browserApi) {
this.plugin_.setAttribute('src', this.originalUrl_);
this.plugin_.setAttribute(
'stream-url', this.browserApi_.getStreamInfo().streamUrl);
var headers = '';
for (var header in this.browserApi_.getStreamInfo().responseHeaders) {
let headers = '';
for (const header in this.browserApi_.getStreamInfo().responseHeaders) {
headers += header + ': ' +
this.browserApi_.getStreamInfo().responseHeaders[header] + '\n';
}
this.plugin_.setAttribute('headers', headers);
var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR;
const backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR;
this.plugin_.setAttribute('background-color', backgroundColor);
this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight);
this.plugin_.setAttribute('javascript', this.javascript_);
......@@ -266,7 +266,7 @@ function PDFViewer(browserApi) {
});
document.body.addEventListener('navigate', e => {
var disposition = e.detail.newtab ?
const disposition = e.detail.newtab ?
Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB :
Navigator.WindowOpenDisposition.CURRENT_TAB;
this.navigator_.navigate(e.detail.uri, disposition);
......@@ -296,7 +296,7 @@ function PDFViewer(browserApi) {
document.addEventListener(
'contextmenu', this.handleContextMenuEvent_.bind(this));
var tabId = this.browserApi_.getStreamInfo().tabId;
const tabId = this.browserApi_.getStreamInfo().tabId;
this.navigator_ = new Navigator(
this.originalUrl_, this.viewport_, this.paramsParser_,
new NavigatorDelegate(tabId));
......@@ -316,16 +316,16 @@ PDFViewer.prototype = {
* @private
*/
handleKeyEvent_: function(e) {
var position = this.viewport_.position;
const position = this.viewport_.position;
// Certain scroll events may be sent from outside of the extension.
var fromScriptingAPI = e.fromScriptingAPI;
const fromScriptingAPI = e.fromScriptingAPI;
if (shouldIgnoreKeyEvents(document.activeElement) || e.defaultPrevented)
return;
this.toolbarManager_.hideToolbarsAfterTimeout(e);
var pageUpHandler = () => {
const pageUpHandler = () => {
// Go to the previous page if we are fit-to-page or fit-to-height.
if (this.viewport_.isPagedMode()) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
......@@ -336,7 +336,7 @@ PDFViewer.prototype = {
this.viewport.position = position;
}
};
var pageDownHandler = () => {
const pageDownHandler = () => {
// Go to the next page if we are fit-to-page or fit-to-height.
if (this.viewport_.isPagedMode()) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
......@@ -569,8 +569,8 @@ PDFViewer.prototype = {
this.isUserInitiatedEvent_ = false;
this.zoomToolbar_.forceFit(params.view);
if (params.viewPosition) {
var zoomedPositionShift = params.viewPosition * this.viewport_.zoom;
var currentViewportPosition = this.viewport_.position;
const zoomedPositionShift = params.viewPosition * this.viewport_.zoom;
const currentViewportPosition = this.viewport_.position;
if (params.view == FittingType.FIT_TO_WIDTH)
currentViewportPosition.y += zoomedPositionShift;
else if (params.view == FittingType.FIT_TO_HEIGHT)
......@@ -708,7 +708,7 @@ PDFViewer.prototype = {
}
break;
case 'email':
var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
const href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
'&bcc=' + message.data.bcc + '&subject=' + message.data.subject +
'&body=' + message.data.body;
window.location.href = href;
......@@ -837,9 +837,9 @@ PDFViewer.prototype = {
this.postMessage_({type: 'stopScrolling'});
if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) {
var position = this.viewport_.position;
var zoom = this.viewport_.zoom;
var pinchPhase = this.viewport_.pinchPhase;
const position = this.viewport_.position;
const zoom = this.viewport_.zoom;
const pinchPhase = this.viewport_.pinchPhase;
this.postMessage_({
type: 'viewport',
userInitiated: true,
......@@ -858,11 +858,11 @@ PDFViewer.prototype = {
* @private
*/
afterZoom_: function() {
var position = this.viewport_.position;
var zoom = this.viewport_.zoom;
var pinchVector = this.viewport_.pinchPanVector || {x: 0, y: 0};
var pinchCenter = this.viewport_.pinchCenter || {x: 0, y: 0};
var pinchPhase = this.viewport_.pinchPhase;
const position = this.viewport_.position;
const zoom = this.viewport_.zoom;
const pinchVector = this.viewport_.pinchPanVector || {x: 0, y: 0};
const pinchCenter = this.viewport_.pinchCenter || {x: 0, y: 0};
const pinchPhase = this.viewport_.pinchPhase;
this.postMessage_({
type: 'viewport',
......@@ -947,10 +947,10 @@ PDFViewer.prototype = {
return;
// Offset the toolbar position so that it doesn't move if scrollbars appear.
var hasScrollbars = this.viewport_.documentHasScrollbars();
var scrollbarWidth = this.viewport_.scrollbarWidth;
var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
var horizontalScrollbarWidth =
const hasScrollbars = this.viewport_.documentHasScrollbars();
const scrollbarWidth = this.viewport_.scrollbarWidth;
const verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
const horizontalScrollbarWidth =
hasScrollbars.horizontal ? scrollbarWidth : 0;
// Shift the zoom toolbar to the left by half a scrollbar width. This
......@@ -970,7 +970,7 @@ PDFViewer.prototype = {
this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px';
// Update the page indicator.
var visiblePage = this.viewport_.getMostVisiblePage();
const visiblePage = this.viewport_.getMostVisiblePage();
if (this.toolbar_)
this.toolbar_.pageNo = visiblePage + 1;
......@@ -986,8 +986,8 @@ PDFViewer.prototype = {
}
}
var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage);
var size = this.viewport_.size;
const visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage);
const size = this.viewport_.size;
this.sendScriptingMessage_({
type: 'viewport',
pageX: visiblePageDimensions.x,
......@@ -1062,10 +1062,10 @@ PDFViewer.prototype = {
this.lastViewportPosition_ = this.viewport_.position;
// TODO(raymes): Disable these properly in the plugin.
var printButton = $('print-button');
const printButton = $('print-button');
if (printButton)
printButton.parentNode.removeChild(printButton);
var saveButton = $('save-button');
const saveButton = $('save-button');
if (saveButton)
saveButton.parentNode.removeChild(saveButton);
......@@ -1085,7 +1085,7 @@ PDFViewer.prototype = {
this.handleKeyEvent_(DeserializeKeyEvent(message.data.keyEvent));
return true;
case 'scrollPosition':
var position = this.viewport_.position;
const position = this.viewport_.position;
position.y += message.data.y;
position.x += message.data.x;
this.viewport.position = position;
......@@ -1104,7 +1104,7 @@ PDFViewer.prototype = {
*/
sendScriptingMessage_: function(message) {
if (this.parentWindow_ && this.parentOrigin_) {
var targetOrigin;
let targetOrigin;
// Only send data back to the embedder if it is from the same origin,
// unless we're sending it to ourselves (which could happen in the case
// of tests). We also allow documentLoaded messages through as this won't
......
......@@ -5,20 +5,20 @@
'use strict';
/** Idle time in ms before the UI is hidden. */
var HIDE_TIMEOUT = 2000;
const HIDE_TIMEOUT = 2000;
/** Time in ms after force hide before toolbar is shown again. */
var FORCE_HIDE_TIMEOUT = 1000;
const FORCE_HIDE_TIMEOUT = 1000;
/**
* Velocity required in a mousemove to reveal the UI (pixels/ms). This is
* intended to be high enough that a fast flick of the mouse is required to
* reach it.
*/
var SHOW_VELOCITY = 10;
const SHOW_VELOCITY = 10;
/** Distance from the top of the screen required to reveal the toolbars. */
var TOP_TOOLBAR_REVEAL_DISTANCE = 100;
const TOP_TOOLBAR_REVEAL_DISTANCE = 100;
/** Distance from the bottom-right of the screen required to reveal toolbars. */
var SIDE_TOOLBAR_REVEAL_DISTANCE_RIGHT = 150;
var SIDE_TOOLBAR_REVEAL_DISTANCE_BOTTOM = 250;
const SIDE_TOOLBAR_REVEAL_DISTANCE_RIGHT = 150;
const SIDE_TOOLBAR_REVEAL_DISTANCE_BOTTOM = 250;
......@@ -37,10 +37,11 @@ function isMouseNearTopToolbar(e) {
* screen.
*/
function isMouseNearSideToolbar(e, window) {
var atSide = e.x > window.innerWidth - SIDE_TOOLBAR_REVEAL_DISTANCE_RIGHT;
let atSide = e.x > window.innerWidth - SIDE_TOOLBAR_REVEAL_DISTANCE_RIGHT;
if (isRTL())
atSide = e.x < SIDE_TOOLBAR_REVEAL_DISTANCE_RIGHT;
var atBottom = e.y > window.innerHeight - SIDE_TOOLBAR_REVEAL_DISTANCE_BOTTOM;
const atBottom =
e.y > window.innerHeight - SIDE_TOOLBAR_REVEAL_DISTANCE_BOTTOM;
return atSide && atBottom;
}
......@@ -80,7 +81,7 @@ ToolbarManager.prototype = {
this.isMouseNearSideToolbar_ = isMouseNearSideToolbar(e, this.window_);
this.keyboardNavigationActive = false;
var touchInteractionActive =
const touchInteractionActive =
(e.sourceCapabilities && e.sourceCapabilities.firesTouchEvents);
// Allow the top toolbar to be shown if the mouse moves away from the side
......@@ -123,10 +124,10 @@ ToolbarManager.prototype = {
if (this.lastMovementTimestamp == null) {
this.lastMovementTimestamp = this.getCurrentTimestamp_();
} else {
var movement =
const movement =
Math.sqrt(e.movementX * e.movementX + e.movementY * e.movementY);
var newTime = this.getCurrentTimestamp_();
var interval = newTime - this.lastMovementTimestamp;
const newTime = this.getCurrentTimestamp_();
const interval = newTime - this.lastMovementTimestamp;
this.lastMovementTimestamp = newTime;
if (interval != 0)
......@@ -250,7 +251,8 @@ ToolbarManager.prototype = {
resizeDropdowns_: function() {
if (!this.toolbar_)
return;
var lowerBound = this.window_.innerHeight - this.zoomToolbar_.clientHeight;
const lowerBound =
this.window_.innerHeight - this.zoomToolbar_.clientHeight;
this.toolbar_.setDropdownLowerBound(lowerBound);
}
};
......@@ -54,7 +54,7 @@ function vectorDelta(p1, p2) {
}
function frameToPluginCoordinate(coordinateInFrame) {
var container = $('plugin');
const container = $('plugin');
return {
x: coordinateInFrame.x - container.getBoundingClientRect().left,
y: coordinateInFrame.y - container.getBoundingClientRect().top
......@@ -263,7 +263,7 @@ Viewport.prototype = {
* @private
*/
documentNeedsScrollbars_: function(zoom) {
var zoomedDimensions = this.getZoomedDocumentDimensions_(zoom);
const zoomedDimensions = this.getZoomedDocumentDimensions_(zoom);
if (!zoomedDimensions) {
return {horizontal: false, vertical: false};
}
......@@ -299,7 +299,7 @@ Viewport.prototype = {
* @private
*/
contentSizeChanged_: function() {
var zoomedDimensions = this.getZoomedDocumentDimensions_(this.zoom);
const zoomedDimensions = this.getZoomedDocumentDimensions_(this.zoom);
if (zoomedDimensions) {
this.sizer_.style.width = zoomedDimensions.width + 'px';
this.sizer_.style.height =
......@@ -368,9 +368,10 @@ Viewport.prototype = {
* @type {Object} the size of the viewport excluding scrollbars.
*/
get size() {
var needsScrollbars = this.documentNeedsScrollbars_(this.zoom);
var scrollbarWidth = needsScrollbars.vertical ? this.scrollbarWidth_ : 0;
var scrollbarHeight = needsScrollbars.horizontal ? this.scrollbarWidth_ : 0;
const needsScrollbars = this.documentNeedsScrollbars_(this.zoom);
const scrollbarWidth = needsScrollbars.vertical ? this.scrollbarWidth_ : 0;
const scrollbarHeight =
needsScrollbars.horizontal ? this.scrollbarWidth_ : 0;
return {
width: this.window_.innerWidth - scrollbarWidth,
height: this.window_.innerHeight - scrollbarHeight
......@@ -446,7 +447,7 @@ Viewport.prototype = {
'Viewport.mightZoom_.');
}
// Record the scroll position (relative to the top-left of the window).
var currentScrollPos = {
const currentScrollPos = {
x: this.position.x / this.zoom,
y: this.position.y / this.zoom
};
......@@ -475,14 +476,14 @@ Viewport.prototype = {
'Viewport.mightZoom_.');
this.internalZoom_ = Viewport.clampZoom(this.internalZoom_ * scaleDelta);
var newCenterInContent = this.frameToContent(center);
var delta = {
const newCenterInContent = this.frameToContent(center);
const delta = {
x: (newCenterInContent.x - this.oldCenterInContent.x),
y: (newCenterInContent.y - this.oldCenterInContent.y)
};
// Record the scroll position (relative to the pinch center).
var currentScrollPos = {
const currentScrollPos = {
x: this.position.x - delta.x * this.zoom,
y: this.position.y - delta.y * this.zoom
};
......@@ -530,8 +531,8 @@ Viewport.prototype = {
updateZoomFromBrowserChange: function(oldBrowserZoom) {
this.mightZoom_(() => {
// Record the scroll position (relative to the top-left of the window).
var oldZoom = oldBrowserZoom * this.internalZoom_;
var currentScrollPos = {
const oldZoom = oldBrowserZoom * this.internalZoom_;
const currentScrollPos = {
x: this.position.x / oldZoom,
y: this.position.y / oldZoom
};
......@@ -567,18 +568,18 @@ Viewport.prototype = {
* @private
*/
getPageAtY_: function(y) {
var min = 0;
var max = this.pageDimensions_.length - 1;
let min = 0;
let max = this.pageDimensions_.length - 1;
while (max >= min) {
var page = Math.floor(min + ((max - min) / 2));
const page = Math.floor(min + ((max - min) / 2));
// There might be a gap between the pages, in which case use the bottom
// of the previous page as the top for finding the page.
var top = 0;
let top = 0;
if (page > 0) {
top = this.pageDimensions_[page - 1].y +
this.pageDimensions_[page - 1].height;
}
var bottom =
const bottom =
this.pageDimensions_[page].y + this.pageDimensions_[page].height;
if (top <= y && bottom > y)
......@@ -599,21 +600,21 @@ Viewport.prototype = {
* @return {number} the index of the most visible page.
*/
getMostVisiblePage: function() {
var firstVisiblePage = this.getPageAtY_(this.position.y / this.zoom);
const firstVisiblePage = this.getPageAtY_(this.position.y / this.zoom);
if (firstVisiblePage == this.pageDimensions_.length - 1)
return firstVisiblePage;
var viewportRect = {
const viewportRect = {
x: this.position.x / this.zoom,
y: this.position.y / this.zoom,
width: this.size.width / this.zoom,
height: this.size.height / this.zoom
};
var firstVisiblePageVisibility =
const firstVisiblePageVisibility =
getIntersectionHeight(
this.pageDimensions_[firstVisiblePage], viewportRect) /
this.pageDimensions_[firstVisiblePage].height;
var nextPageVisibility =
const nextPageVisibility =
getIntersectionHeight(
this.pageDimensions_[firstVisiblePage + 1], viewportRect) /
this.pageDimensions_[firstVisiblePage + 1].height;
......@@ -642,21 +643,21 @@ Viewport.prototype = {
'true.');
// First compute the zoom without scrollbars.
var zoom = this.computeFittingZoomGivenDimensions_(
let zoom = this.computeFittingZoomGivenDimensions_(
fitWidth, fitHeight, this.window_.innerWidth, this.window_.innerHeight,
pageDimensions.width, pageDimensions.height);
// Check if there needs to be any scrollbars.
var needsScrollbars = this.documentNeedsScrollbars_(zoom);
const needsScrollbars = this.documentNeedsScrollbars_(zoom);
// If the document fits, just return the zoom.
if (!needsScrollbars.horizontal && !needsScrollbars.vertical)
return zoom;
var zoomedDimensions = this.getZoomedDocumentDimensions_(zoom);
const zoomedDimensions = this.getZoomedDocumentDimensions_(zoom);
// Check if adding a scrollbar will result in needing the other scrollbar.
var scrollbarWidth = this.scrollbarWidth_;
const scrollbarWidth = this.scrollbarWidth_;
if (needsScrollbars.horizontal &&
zoomedDimensions.height > this.window_.innerHeight - scrollbarWidth) {
needsScrollbars.vertical = true;
......@@ -667,7 +668,7 @@ Viewport.prototype = {
}
// Compute available window space.
var windowWithScrollbars = {
const windowWithScrollbars = {
width: this.window_.innerWidth,
height: this.window_.innerHeight
};
......@@ -703,8 +704,8 @@ Viewport.prototype = {
computeFittingZoomGivenDimensions_: function(
fitWidth, fitHeight, windowWidth, windowHeight, pageWidth, pageHeight) {
// Assumes at least one of {fitWidth, fitHeight} is set.
var zoomWidth;
var zoomHeight;
let zoomWidth;
let zoomHeight;
if (fitWidth)
zoomWidth = windowWidth / pageWidth;
......@@ -712,7 +713,7 @@ Viewport.prototype = {
if (fitHeight)
zoomHeight = windowHeight / pageHeight;
var zoom;
let zoom;
if (!fitWidth && fitHeight) {
zoom = zoomHeight;
} else if (fitWidth && !fitHeight) {
......@@ -754,10 +755,10 @@ Viewport.prototype = {
this.fittingType_ = FittingType.FIT_TO_HEIGHT;
if (!this.documentDimensions_)
return;
var page = this.getMostVisiblePage();
const page = this.getMostVisiblePage();
// When computing fit-to-height, the maximum height of the current page
// is used.
var dimensions = {
const dimensions = {
width: 0,
height: this.pageDimensions_[page].height,
};
......@@ -789,9 +790,9 @@ Viewport.prototype = {
this.fittingType_ = FittingType.FIT_TO_PAGE;
if (!this.documentDimensions_)
return;
var page = this.getMostVisiblePage();
const page = this.getMostVisiblePage();
// Fit to the current page's height and the widest page's width.
var dimensions = {
const dimensions = {
width: this.documentDimensions_.width,
height: this.pageDimensions_[page].height,
};
......@@ -832,8 +833,8 @@ Viewport.prototype = {
zoomOut: function() {
this.mightZoom_(() => {
this.fittingType_ = FittingType.NONE;
var nextZoom = Viewport.ZOOM_FACTORS[0];
for (var i = 0; i < Viewport.ZOOM_FACTORS.length; i++) {
let nextZoom = Viewport.ZOOM_FACTORS[0];
for (let i = 0; i < Viewport.ZOOM_FACTORS.length; i++) {
if (Viewport.ZOOM_FACTORS[i] < this.internalZoom_)
nextZoom = Viewport.ZOOM_FACTORS[i];
}
......@@ -848,8 +849,8 @@ Viewport.prototype = {
zoomIn: function() {
this.mightZoom_(() => {
this.fittingType_ = FittingType.NONE;
var nextZoom = Viewport.ZOOM_FACTORS[Viewport.ZOOM_FACTORS.length - 1];
for (var i = Viewport.ZOOM_FACTORS.length - 1; i >= 0; i--) {
let nextZoom = Viewport.ZOOM_FACTORS[Viewport.ZOOM_FACTORS.length - 1];
for (let i = Viewport.ZOOM_FACTORS.length - 1; i >= 0; i--) {
if (Viewport.ZOOM_FACTORS[i] > this.internalZoom_)
nextZoom = Viewport.ZOOM_FACTORS[i];
}
......@@ -869,11 +870,11 @@ Viewport.prototype = {
Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT :
Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN;
var scaleDelta = e.startScaleRatio / this.prevScale_;
const scaleDelta = e.startScaleRatio / this.prevScale_;
this.pinchPanVector_ =
vectorDelta(e.center, this.firstPinchCenterInFrame_);
var needsScrollbars =
const needsScrollbars =
this.documentNeedsScrollbars_(this.zoomManager_.applyBrowserZoom(
Viewport.clampZoom(this.internalZoom_ * scaleDelta)));
......@@ -908,7 +909,7 @@ Viewport.prototype = {
this.oldCenterInContent =
this.frameToContent(frameToPluginCoordinate(e.center));
var needsScrollbars = this.documentNeedsScrollbars_(this.zoom);
const needsScrollbars = this.documentNeedsScrollbars_(this.zoom);
this.keepContentCentered_ = !needsScrollbars.horizontal;
// We keep track of begining of the pinch.
// By doing so we will be able to compute the pan distance.
......@@ -918,7 +919,7 @@ Viewport.prototype = {
pinchZoomEnd: function(e) {
this.mightZoom_(() => {
this.pinchPhase_ = Viewport.PinchPhase.PINCH_END;
var scaleDelta = e.startScaleRatio / this.prevScale_;
const scaleDelta = e.startScaleRatio / this.prevScale_;
this.pinchCenter_ = e.center;
this.setPinchZoomInternal_(scaleDelta, frameToPluginCoordinate(e.center));
......@@ -955,8 +956,8 @@ Viewport.prototype = {
page = 0;
if (page >= this.pageDimensions_.length)
page = this.pageDimensions_.length - 1;
var dimensions = this.pageDimensions_[page];
var toolbarOffset = 0;
const dimensions = this.pageDimensions_[page];
let toolbarOffset = 0;
// Unless we're in fit to page or fit to height mode, scroll above the
// page by |this.topToolbarHeight_| so that the toolbar isn't covering it
// initially.
......@@ -977,7 +978,7 @@ Viewport.prototype = {
*/
setDocumentDimensions: function(documentDimensions) {
this.mightZoom_(() => {
var initialDimensions = !this.documentDimensions_;
const initialDimensions = !this.documentDimensions_;
this.documentDimensions_ = documentDimensions;
this.pageDimensions_ = this.documentDimensions_.pageDimensions;
if (initialDimensions) {
......@@ -1020,19 +1021,19 @@ Viewport.prototype = {
if (page >= this.pageDimensions_.length)
page = this.pageDimensions_.length - 1;
var pageDimensions = this.pageDimensions_[page];
const pageDimensions = this.pageDimensions_[page];
// Compute the page dimensions minus the shadows.
var insetDimensions = this.getPageInsetDimensions(page);
const insetDimensions = this.getPageInsetDimensions(page);
// Compute the x-coordinate of the page within the document.
// TODO(raymes): This should really be set when the PDF plugin passes the
// page coordinates, but it isn't yet.
var x = (this.documentDimensions_.width - pageDimensions.width) / 2 +
const x = (this.documentDimensions_.width - pageDimensions.width) / 2 +
Viewport.PAGE_SHADOW.left;
// Compute the space on the left of the document if the document fits
// completely in the screen.
var spaceOnLeft =
let spaceOnLeft =
(this.size.width - this.documentDimensions_.width * this.zoom) / 2;
spaceOnLeft = Math.max(spaceOnLeft, 0);
......
......@@ -74,9 +74,9 @@ ViewportScroller.prototype = {
* @private
*/
dragScrollPage_: function() {
var position = this.viewport_.position;
var currentFrameTime = Date.now();
var timeAdjustment = (currentFrameTime - this.lastFrameTime_) /
const position = this.viewport_.position;
const currentFrameTime = Date.now();
const timeAdjustment = (currentFrameTime - this.lastFrameTime_) /
ViewportScroller.DRAG_TIMER_INTERVAL_MS_;
position.y += (this.scrollVelocity_.y * timeAdjustment);
position.x += (this.scrollVelocity_.x * timeAdjustment);
......@@ -93,13 +93,13 @@ ViewportScroller.prototype = {
* @private
*/
calculateVelocity_: function(event) {
var x =
const x =
Math.min(
Math.max(
-event.offsetX, event.offsetX - this.plugin_.offsetWidth, 0),
ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) *
Math.sign(event.offsetX);
var y =
const y =
Math.min(
Math.max(
-event.offsetY, event.offsetY - this.plugin_.offsetHeight, 0),
......
......@@ -84,7 +84,7 @@ class ZoomManager {
* @param {number} b The second number.
*/
floatingPointEquals(a, b) {
let MIN_ZOOM_DELTA = 0.01;
const MIN_ZOOM_DELTA = 0.01;
// If the zoom level is close enough to the current zoom level, don't
// change it. This avoids us getting into an infinite loop of zoom changes
// due to floating point error.
......@@ -147,7 +147,7 @@ class ActiveZoomManager extends ZoomManager {
if (this.changingBrowserZoom_)
return;
let zoom = this.viewport_.zoom;
const zoom = this.viewport_.zoom;
if (this.floatingPointEquals(this.browserZoom_, zoom))
return;
......@@ -200,7 +200,7 @@ class EmbeddedZoomManager extends ZoomManager {
* @param {number} newZoom the new browser zoom level.
*/
onBrowserZoomChange(newZoom) {
let oldZoom = this.browserZoom_;
const oldZoom = this.browserZoom_;
this.browserZoom_ = newZoom;
this.viewport_.updateZoomFromBrowserChange(oldZoom);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment