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