diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-18 14:34:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-04 11:15:27 +0000 |
commit | e6430e577f105ad8813c92e75c54660c4985026e (patch) | |
tree | 88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/chrome/browser/resources/pdf | |
parent | 53d399fe6415a96ea6986ec0d402a9c07da72453 (diff) |
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/chrome/browser/resources/pdf')
28 files changed, 766 insertions, 809 deletions
diff --git a/chromium/chrome/browser/resources/pdf/browser_api.js b/chromium/chrome/browser/resources/pdf/browser_api.js index c29559a55b9..85822de29c1 100644 --- a/chromium/chrome/browser/resources/pdf/browser_api.js +++ b/chromium/chrome/browser/resources/pdf/browser_api.js @@ -71,13 +71,12 @@ class BrowserApi { * @param {BrowserApi.ZoomBehavior} zoomBehavior How to manage zoom. */ static create(streamInfo, zoomBehavior) { - return Promise.all([ - lookupDefaultZoom(streamInfo), - lookupInitialZoom(streamInfo) - ]).then(function(zoomFactors) { - return new BrowserApi( - streamInfo, zoomFactors[0], zoomFactors[1], zoomBehavior); - }); + return Promise + .all([lookupDefaultZoom(streamInfo), lookupInitialZoom(streamInfo)]) + .then(function(zoomFactors) { + return new BrowserApi( + streamInfo, zoomFactors[0], zoomFactors[1], zoomBehavior); + }); } /** @@ -136,7 +135,7 @@ class BrowserApi { /** * Adds an event listener to be notified when the browser zoom changes. - * @param {function} listener The listener to be called with the new zoom + * @param {!Function} listener The listener to be called with the new zoom * factor. */ addZoomEventListener(listener) { @@ -144,7 +143,9 @@ class BrowserApi { this.zoomBehavior_ == BrowserApi.ZoomBehavior.PROPAGATE_PARENT)) return; - chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { + chrome.tabs.onZoomChange.addListener(function(info) { + var zoomChangeInfo = + /** @type {{tabId: number, newZoomFactor: number}} */ (info); if (zoomChangeInfo.tabId != this.streamInfo_.tabId) return; listener(zoomChangeInfo.newZoomFactor); @@ -169,30 +170,32 @@ BrowserApi.ZoomBehavior = { */ function createBrowserApiForMimeHandlerView() { return new Promise(function(resolve, reject) { - chrome.mimeHandlerPrivate.getStreamInfo(resolve); - }).then(function(streamInfo) { - let promises = []; - let zoomBehavior = BrowserApi.ZoomBehavior.NONE; - if (streamInfo.tabId != -1) { - zoomBehavior = streamInfo.embedded ? - BrowserApi.ZoomBehavior.PROPAGATE_PARENT : - BrowserApi.ZoomBehavior.MANAGE; - promises.push(new Promise(function(resolve) { - chrome.tabs.get(streamInfo.tabId, resolve); - }).then(function(tab) { - if (tab) - streamInfo.tabUrl = tab.url; - })); - } - if (zoomBehavior == BrowserApi.ZoomBehavior.MANAGE) { - promises.push(new Promise(function(resolve) { - chrome.tabs.setZoomSettings( - streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); - })); - } - return Promise.all(promises).then( - function() { return BrowserApi.create(streamInfo, zoomBehavior); }); - }); + chrome.mimeHandlerPrivate.getStreamInfo(resolve); + }) + .then(function(streamInfo) { + let promises = []; + let zoomBehavior = BrowserApi.ZoomBehavior.NONE; + if (streamInfo.tabId != -1) { + zoomBehavior = streamInfo.embedded ? + BrowserApi.ZoomBehavior.PROPAGATE_PARENT : + BrowserApi.ZoomBehavior.MANAGE; + promises.push(new Promise(function(resolve) { + chrome.tabs.get(streamInfo.tabId, resolve); + }).then(function(tab) { + if (tab) + streamInfo.tabUrl = tab.url; + })); + } + if (zoomBehavior == BrowserApi.ZoomBehavior.MANAGE) { + promises.push(new Promise(function(resolve) { + chrome.tabs.setZoomSettings( + streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); + })); + } + return Promise.all(promises).then(function() { + return BrowserApi.create(streamInfo, zoomBehavior); + }); + }); } /** @@ -210,18 +213,19 @@ function createBrowserApiForPrintPreview() { tabId: -1, }; return new Promise(function(resolve, reject) { - if (!chrome.tabs) { - resolve(); - return; - } - chrome.tabs.getCurrent(function(tab) { - streamInfo.tabId = tab.id; - streamInfo.tabUrl = tab.url; - resolve(); - }); - }).then(function() { - return BrowserApi.create(streamInfo, BrowserApi.ZoomBehavior.NONE); - }); + if (!chrome.tabs) { + resolve(); + return; + } + chrome.tabs.getCurrent(function(tab) { + streamInfo.tabId = tab.id; + streamInfo.tabUrl = tab.url; + resolve(); + }); + }) + .then(function() { + return BrowserApi.create(streamInfo, BrowserApi.ZoomBehavior.NONE); + }); } /** diff --git a/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp index a5d9dfe40b8..05a86018b37 100644 --- a/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp +++ b/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp @@ -6,6 +6,14 @@ { 'targets': [ { + 'target_name': 'browser_api', + 'dependencies': [ + '<(EXTERNS_GYP):chrome_extensions', + '<(EXTERNS_GYP):mime_handler_private', + ], + 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + { 'target_name': 'gesture_detector', 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], }, @@ -24,5 +32,16 @@ 'target_name': 'viewport_scroller', 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], }, + { + 'target_name': 'pdf_resources', + 'type': 'none', + 'dependencies': [ + 'elements/viewer-bookmark/compiled_resources2.gyp:*', + 'elements/viewer-error-screen/compiled_resources2.gyp:*', + 'elements/viewer-page-indicator/compiled_resources2.gyp:*', + 'elements/viewer-page-selector/compiled_resources2.gyp:*', + 'elements/viewer-password-screen/compiled_resources2.gyp:*', + ], + }, ], } diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/compiled_resources2.gyp new file mode 100644 index 00000000000..5df4148b621 --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/compiled_resources2.gyp @@ -0,0 +1,15 @@ +# Copyright 2017 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. + +{ + 'targets': [ + { + 'target_name': 'viewer-bookmark', + 'dependencies': [ + '<(DEPTH)/third_party/polymer/v1_0/components-chromium/iron-a11y-keys-behavior/compiled_resources2.gyp:iron-a11y-keys-behavior-extracted', + ], + 'includes': ['../../../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + ], +} diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js index 9d6399070e7..1e7164a333f 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js @@ -3,90 +3,75 @@ // found in the LICENSE file. (function() { - /** Amount that each level of bookmarks is indented by (px). */ - var BOOKMARK_INDENT = 20; +/** Amount that each level of bookmarks is indented by (px). */ +var BOOKMARK_INDENT = 20; - Polymer({ - is: 'viewer-bookmark', +Polymer({ + is: 'viewer-bookmark', - properties: { - /** - * A bookmark object, each containing a: - * - title - * - page (optional) - * - children (an array of bookmarks) - */ - bookmark: { - type: Object, - observer: 'bookmarkChanged_' - }, + properties: { + /** + * A bookmark object, each containing a: + * - title + * - page (optional) + * - children (an array of bookmarks) + */ + bookmark: {type: Object, observer: 'bookmarkChanged_'}, - depth: { - type: Number, - observer: 'depthChanged' - }, + depth: {type: Number, observer: 'depthChanged'}, - childDepth: Number, + childDepth: Number, - childrenShown: { - type: Boolean, - reflectToAttribute: true, - value: false - }, + childrenShown: {type: Boolean, reflectToAttribute: true, value: false}, - keyEventTarget: { - type: Object, - value: function() { - return this.$.item; - } + keyEventTarget: { + type: Object, + value: function() { + return this.$.item; } - }, - - behaviors: [ - Polymer.IronA11yKeysBehavior - ], + } + }, - keyBindings: { - 'enter': 'onEnter_', - 'space': 'onSpace_' - }, + behaviors: [Polymer.IronA11yKeysBehavior], - bookmarkChanged_: function() { - this.$.expand.style.visibility = - this.bookmark.children.length > 0 ? 'visible' : 'hidden'; - }, + keyBindings: {'enter': 'onEnter_', 'space': 'onSpace_'}, - depthChanged: function() { - this.childDepth = this.depth + 1; - this.$.item.style.webkitPaddingStart = - (this.depth * BOOKMARK_INDENT) + 'px'; - }, + bookmarkChanged_: function() { + this.$.expand.style.visibility = + this.bookmark.children.length > 0 ? 'visible' : 'hidden'; + }, - onClick: function() { - if (this.bookmark.hasOwnProperty('page')) - this.fire('change-page', {page: this.bookmark.page}); - else if (this.bookmark.hasOwnProperty('uri')) - this.fire('navigate', {uri: this.bookmark.uri, newtab: true}); - }, + depthChanged: function() { + this.childDepth = this.depth + 1; + this.$.item.style.webkitPaddingStart = + (this.depth * BOOKMARK_INDENT) + 'px'; + }, - onEnter_: function(e) { - // Don't allow events which have propagated up from the expand button to - // trigger a click. - if (e.detail.keyboardEvent.target != this.$.expand) - this.onClick(); - }, + onClick: function() { + if (this.bookmark.hasOwnProperty('page')) + this.fire('change-page', {page: this.bookmark.page}); + else if (this.bookmark.hasOwnProperty('uri')) + this.fire('navigate', {uri: this.bookmark.uri, newtab: true}); + }, - onSpace_: function(e) { - // paper-icon-button stops propagation of space events, so there's no need - // to check the event source here. + onEnter_: function(e) { + // Don't allow events which have propagated up from the expand button to + // trigger a click. + if (e.detail.keyboardEvent.target != this.$.expand) this.onClick(); - // Prevent default space scroll behavior. - e.detail.keyboardEvent.preventDefault(); - }, + }, - toggleChildren: function(e) { - this.childrenShown = !this.childrenShown; - e.stopPropagation(); // Prevent the above onClick handler from firing. - } - }); + onSpace_: function(e) { + // paper-icon-button stops propagation of space events, so there's no need + // to check the event source here. + this.onClick(); + // Prevent default space scroll behavior. + e.detail.keyboardEvent.preventDefault(); + }, + + toggleChildren: function(e) { + this.childrenShown = !this.childrenShown; + e.stopPropagation(); // Prevent the above onClick handler from firing. + } +}); })(); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmarks-content/viewer-bookmarks-content.js b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmarks-content/viewer-bookmarks-content.js index 1aa2b5cc232..32f3fd320d5 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmarks-content/viewer-bookmarks-content.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmarks-content/viewer-bookmarks-content.js @@ -2,6 +2,4 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -Polymer({ - is: 'viewer-bookmarks-content' -}); +Polymer({is: 'viewer-bookmarks-content'}); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/compiled_resources2.gyp new file mode 100644 index 00000000000..061a2d27a67 --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/compiled_resources2.gyp @@ -0,0 +1,15 @@ +# Copyright 2017 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. + +{ + 'targets': [ + { + 'target_name': 'viewer-error-screen', + 'dependencies': [ + '<(DEPTH)/ui/webui/resources/cr_elements/cr_dialog/compiled_resources2.gyp:cr_dialog', + ], + 'includes': ['../../../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + ], +} diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.html b/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.html index 3dccd91dc8b..10a850ee4d3 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.html +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.html @@ -7,13 +7,14 @@ <template> <style include="cr-shared-style"></style> <dialog is="cr-dialog" id="dialog" no-cancel> - <div class="title"> + <div class="title" slot="title"> [[strings.errorDialogTitle]] </div> - <div class="body"> + <div class="body" slot="body"> [[strings.pageLoadFailed]] </div> - <div class="button-container" hidden$="[[!reloadFn]]"> + <div class="button-container" slot="button-container" + hidden$="[[!reloadFn]]"> <paper-button class="action-button" on-click="reload"> [[strings.pageReload]] </paper-button> diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.js b/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.js index 29951a43c1b..017d4747c05 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-error-screen/viewer-error-screen.js @@ -5,13 +5,13 @@ Polymer({ is: 'viewer-error-screen', properties: { - reloadFn: Object, + reloadFn: Function, strings: Object, }, show: function() { - this.$.dialog.showModal(); + /** @type {!CrDialogElement} */ (this.$.dialog).showModal(); }, reload: function() { diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/compiled_resources2.gyp new file mode 100644 index 00000000000..f4c56ed7f9b --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/compiled_resources2.gyp @@ -0,0 +1,12 @@ +# Copyright 2017 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. + +{ + 'targets': [ + { + 'target_name': 'viewer-page-indicator', + 'includes': ['../../../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + ], +} diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/viewer-page-indicator.js b/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/viewer-page-indicator.js index 65b1be2ffc3..96f7f3d07f4 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/viewer-page-indicator.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-page-indicator/viewer-page-indicator.js @@ -6,25 +6,17 @@ Polymer({ is: 'viewer-page-indicator', properties: { - label: { - type: String, - value: '1' - }, + label: {type: String, value: '1'}, - index: { - type: Number, - observer: 'indexChanged' - }, + index: {type: Number, observer: 'indexChanged'}, - pageLabels: { - type: Array, - value: null, - observer: 'pageLabelsChanged' - } + pageLabels: {type: Array, value: null, observer: 'pageLabelsChanged'} }, + /** @type {number|undefined} */ timerId: undefined, + /** @override */ ready: function() { var callback = this.fadeIn.bind(this, 2000); window.addEventListener('scroll', function() { @@ -36,20 +28,22 @@ Polymer({ this.fadeIn(6000); }, + /** @param {number} displayTime */ fadeIn: function(displayTime) { var percent = window.scrollY / - (document.body.scrollHeight - + (document.scrollingElement.scrollHeight - document.documentElement.clientHeight); - this.style.top = percent * - (document.documentElement.clientHeight - this.offsetHeight) + 'px'; -// <if expr="is_macosx"> + this.style.top = + percent * (document.documentElement.clientHeight - this.offsetHeight) + + 'px'; + // <if expr="is_macosx"> // On the Mac, if overlay scrollbars are enabled, prevent them from // overlapping the triangle. - if (window.innerWidth == document.body.scrollWidth) + if (window.innerWidth == document.scrollingElement.scrollWidth) this.style.right = '16px'; else this.style.right = '0px'; -// </if> + // </if> this.style.opacity = 1; clearTimeout(this.timerId); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/compiled_resources2.gyp new file mode 100644 index 00000000000..00dd3695705 --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/compiled_resources2.gyp @@ -0,0 +1,12 @@ +# Copyright 2017 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. + +{ + 'targets': [ + { + 'target_name': 'viewer-page-selector', + 'includes': ['../../../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + ], +} diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js index ad344f60e13..198b551805a 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js @@ -9,27 +9,20 @@ Polymer({ /** * The number of pages the document contains. */ - docLength: { - type: Number, - value: 1, - observer: 'docLengthChanged' - }, + docLength: {type: Number, value: 1, observer: 'docLengthChanged_'}, /** * The current page being viewed (1-based). A change to pageNo is mirrored * immediately to the input field. A change to the input field is not * mirrored back until pageNoCommitted() is called and change-page is fired. */ - pageNo: { - type: Number, - value: 1 - }, + pageNo: {type: Number, value: 1}, strings: Object, }, pageNoCommitted: function() { - var page = parseInt(this.$.input.value); + var page = parseInt(this.$.input.value, 10); if (!isNaN(page) && page <= this.docLength && page > 0) this.fire('change-page', {page: page - 1}); @@ -38,7 +31,8 @@ Polymer({ this.$.input.blur(); }, - docLengthChanged: function() { + /** @private */ + docLengthChanged_: function() { var 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 diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/compiled_resources2.gyp new file mode 100644 index 00000000000..a26f57364b1 --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/compiled_resources2.gyp @@ -0,0 +1,15 @@ +# Copyright 2017 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. + +{ + 'targets': [ + { + 'target_name': 'viewer-password-screen', + 'dependencies': [ + '<(DEPTH)/third_party/polymer/v1_0/components-chromium/paper-input/compiled_resources2.gyp:paper-input-extracted' + ], + 'includes': ['../../../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + ], +} diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.html b/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.html index fe925120f94..76351c2eda9 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.html +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.html @@ -16,8 +16,8 @@ } </style> <dialog is="cr-dialog" id="dialog" no-cancel> - <div class="title">[[strings.passwordDialogTitle]]</div> - <div class="body"> + <div class="title" slot="title">[[strings.passwordDialogTitle]]</div> + <div class="body" slot="body"> <div id="message">[[strings.passwordPrompt]]</div> <paper-input id="password" type="password" @@ -27,7 +27,7 @@ autofocus> </paper-input> </div> - <div class="button-container"> + <div class="button-container" slot="button-container"> <paper-button id="submit" class="action-button" on-click="submit"> [[strings.passwordSubmit]] </paper-button> diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.js b/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.js index 0ca52a64a8e..ef1f1284a9f 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-password-screen/viewer-password-screen.js @@ -25,18 +25,20 @@ Polymer({ }, deny: function() { - this.$.password.disabled = false; + var password = /** @type {!PaperInputElement} */ (this.$.password); + password.disabled = false; this.$.submit.disabled = false; this.invalid = true; - this.$.password.focus(); - this.$.password.inputElement.select(); + password.focus(); + password.inputElement.select(); }, submit: function() { - if (this.$.password.value.length == 0) + var password = /** @type {!PaperInputElement} */ (this.$.password); + if (password.value.length == 0) return; - this.$.password.disabled = true; + password.disabled = true; this.$.submit.disabled = true; - this.fire('password-submitted', {password: this.$.password.value}); + this.fire('password-submitted', {password: password.value}); }, }); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.js b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.js index d4e8cbd6637..07b03909149 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.js @@ -2,145 +2,126 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. (function() { - Polymer({ - is: 'viewer-pdf-toolbar', - - behaviors: [ - Polymer.NeonAnimationRunnerBehavior - ], - - properties: { - /** - * The current loading progress of the PDF document (0 - 100). - */ - loadProgress: { - type: Number, - observer: 'loadProgressChanged' - }, - - /** - * The title of the PDF document. - */ - docTitle: String, - - /** - * The number of the page being viewed (1-based). - */ - pageNo: Number, - - /** - * Tree of PDF bookmarks (or null if the document has no bookmarks). - */ - bookmarks: { - type: Object, - value: null - }, - - /** - * The number of pages in the PDF document. - */ - docLength: Number, - - /** - * Whether the toolbar is opened and visible. - */ - opened: { - type: Boolean, - value: true - }, - - strings: Object, - - animationConfig: { - value: function() { - return { - 'entry': { - name: 'transform-animation', - node: this, - transformFrom: 'translateY(-100%)', - transformTo: 'translateY(0%)', - timing: { - easing: 'cubic-bezier(0, 0, 0.2, 1)', - duration: 250 - } - }, - 'exit': { - name: 'slide-up-animation', - node: this, - timing: { - easing: 'cubic-bezier(0.4, 0, 1, 1)', - duration: 250 - } - } - }; - } +Polymer({ + is: 'viewer-pdf-toolbar', + + behaviors: [Polymer.NeonAnimationRunnerBehavior], + + properties: { + /** + * The current loading progress of the PDF document (0 - 100). + */ + loadProgress: {type: Number, observer: 'loadProgressChanged'}, + + /** + * The title of the PDF document. + */ + docTitle: String, + + /** + * The number of the page being viewed (1-based). + */ + pageNo: Number, + + /** + * Tree of PDF bookmarks (or null if the document has no bookmarks). + */ + bookmarks: {type: Object, value: null}, + + /** + * The number of pages in the PDF document. + */ + docLength: Number, + + /** + * Whether the toolbar is opened and visible. + */ + opened: {type: Boolean, value: true}, + + strings: Object, + + animationConfig: { + value: function() { + return { + 'entry': { + name: 'transform-animation', + node: this, + transformFrom: 'translateY(-100%)', + transformTo: 'translateY(0%)', + timing: {easing: 'cubic-bezier(0, 0, 0.2, 1)', duration: 250} + }, + 'exit': { + name: 'slide-up-animation', + node: this, + timing: {easing: 'cubic-bezier(0.4, 0, 1, 1)', duration: 250} + } + }; } - }, + } + }, - listeners: { - 'neon-animation-finish': '_onAnimationFinished' - }, + listeners: {'neon-animation-finish': '_onAnimationFinished'}, - _onAnimationFinished: function() { - this.style.transform = this.opened ? 'none' : 'translateY(-100%)'; - }, + _onAnimationFinished: function() { + this.style.transform = this.opened ? 'none' : 'translateY(-100%)'; + }, - loadProgressChanged: function() { - if (this.loadProgress >= 100) { - this.$.pageselector.classList.toggle('invisible', false); - this.$.buttons.classList.toggle('invisible', false); - this.$.progress.style.opacity = 0; - } - }, + loadProgressChanged: function() { + if (this.loadProgress >= 100) { + this.$.pageselector.classList.toggle('invisible', false); + this.$.buttons.classList.toggle('invisible', false); + this.$.progress.style.opacity = 0; + } + }, - hide: function() { - if (this.opened) - this.toggleVisibility(); - }, + hide: function() { + if (this.opened) + this.toggleVisibility(); + }, - show: function() { - if (!this.opened) { - this.toggleVisibility(); - } - }, - - toggleVisibility: function() { - this.opened = !this.opened; - this.cancelAnimation(); - this.playAnimation(this.opened ? 'entry' : 'exit'); - }, - - selectPageNumber: function() { - this.$.pageselector.select(); - }, - - shouldKeepOpen: function() { - return this.$.bookmarks.dropdownOpen || this.loadProgress < 100 || - this.$.pageselector.isActive(); - }, - - hideDropdowns: function() { - if (this.$.bookmarks.dropdownOpen) { - this.$.bookmarks.toggleDropdown(); - return true; - } - return false; - }, + show: function() { + if (!this.opened) { + this.toggleVisibility(); + } + }, + + toggleVisibility: function() { + this.opened = !this.opened; + this.cancelAnimation(); + this.playAnimation(this.opened ? 'entry' : 'exit'); + }, + + selectPageNumber: function() { + this.$.pageselector.select(); + }, + + shouldKeepOpen: function() { + return this.$.bookmarks.dropdownOpen || this.loadProgress < 100 || + this.$.pageselector.isActive(); + }, + + hideDropdowns: function() { + if (this.$.bookmarks.dropdownOpen) { + this.$.bookmarks.toggleDropdown(); + return true; + } + return false; + }, - setDropdownLowerBound: function(lowerBound) { - this.$.bookmarks.lowerBound = lowerBound; - }, + setDropdownLowerBound: function(lowerBound) { + this.$.bookmarks.lowerBound = lowerBound; + }, - rotateRight: function() { - this.fire('rotate-right'); - }, + rotateRight: function() { + this.fire('rotate-right'); + }, - download: function() { - this.fire('save'); - }, + download: function() { + this.fire('save'); + }, - print: function() { - this.fire('print'); - } - }); + print: function() { + this.fire('print'); + } +}); })(); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js b/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js index 17a04c04d7b..53e9acc5318 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js @@ -3,136 +3,132 @@ // found in the LICENSE file. (function() { - /** - * Size of additional padding in the inner scrollable section of the dropdown. - */ - var DROPDOWN_INNER_PADDING = 12; - - /** Size of vertical padding on the outer #dropdown element. */ - var DROPDOWN_OUTER_PADDING = 2; - - /** Minimum height of toolbar dropdowns (px). */ - var MIN_DROPDOWN_HEIGHT = 200; - - Polymer({ - is: 'viewer-toolbar-dropdown', - - properties: { - /** String to be displayed at the top of the dropdown. */ - header: String, - - /** Icon to display when the dropdown is closed. */ - closedIcon: String, - - /** Icon to display when the dropdown is open. */ - openIcon: String, - - /** True if the dropdown is currently open. */ - dropdownOpen: { - type: Boolean, - reflectToAttribute: true, - value: false - }, - - /** Toolbar icon currently being displayed. */ - dropdownIcon: { - type: String, - computed: 'computeIcon_(dropdownOpen, closedIcon, openIcon)' - }, - - /** Lowest vertical point that the dropdown should occupy (px). */ - lowerBound: { - type: Number, - observer: 'lowerBoundChanged_' - }, - - /** - * True if the max-height CSS property for the dropdown scroll container - * is valid. If false, the height will be updated the next time the - * dropdown is visible. - */ - maxHeightValid_: false, - - /** Current animation being played, or null if there is none. */ - animation_: Object - }, +/** + * Size of additional padding in the inner scrollable section of the dropdown. + */ +var DROPDOWN_INNER_PADDING = 12; - computeIcon_: function(dropdownOpen, closedIcon, openIcon) { - return dropdownOpen ? openIcon : closedIcon; - }, +/** Size of vertical padding on the outer #dropdown element. */ +var DROPDOWN_OUTER_PADDING = 2; - lowerBoundChanged_: function() { - this.maxHeightValid_ = false; - if (this.dropdownOpen) - this.updateMaxHeight(); - }, +/** Minimum height of toolbar dropdowns (px). */ +var MIN_DROPDOWN_HEIGHT = 200; - toggleDropdown: function() { - this.dropdownOpen = !this.dropdownOpen; - if (this.dropdownOpen) { - this.$.dropdown.style.display = 'block'; - if (!this.maxHeightValid_) - this.updateMaxHeight(); - } - this.cancelAnimation_(); - this.playAnimation_(this.dropdownOpen); - }, +Polymer({ + is: 'viewer-toolbar-dropdown', - updateMaxHeight: function() { - var scrollContainer = this.$['scroll-container']; - var height = this.lowerBound - - scrollContainer.getBoundingClientRect().top - - DROPDOWN_INNER_PADDING; - height = Math.max(height, MIN_DROPDOWN_HEIGHT); - scrollContainer.style.maxHeight = height + 'px'; - this.maxHeightValid_ = true; - }, + properties: { + /** String to be displayed at the top of the dropdown. */ + header: String, - cancelAnimation_: function() { - if (this._animation) - this._animation.cancel(); - }, + /** Icon to display when the dropdown is closed. */ + closedIcon: String, - /** - * Start an animation on the dropdown. - * @param {boolean} isEntry True to play entry animation, false to play - * exit. - * @private - */ - playAnimation_: function(isEntry) { - this.animation_ = isEntry ? this.animateEntry_() : this.animateExit_(); - this.animation_.onfinish = function() { - this.animation_ = null; - if (!this.dropdownOpen) - this.$.dropdown.style.display = 'none'; - }.bind(this); - }, - - animateEntry_: function() { - var maxHeight = this.$.dropdown.getBoundingClientRect().height - - DROPDOWN_OUTER_PADDING; - - if (maxHeight < 0) - maxHeight = 0; + /** Icon to display when the dropdown is open. */ + openIcon: String, - var fade = new KeyframeEffect(this.$.dropdown, [ - {opacity: 0}, - {opacity: 1} - ], {duration: 150, easing: 'cubic-bezier(0, 0, 0.2, 1)'}); - var slide = new KeyframeEffect(this.$.dropdown, [ - {height: '20px', transform: 'translateY(-10px)'}, - {height: maxHeight + 'px', transform: 'translateY(0)'} - ], {duration: 250, easing: 'cubic-bezier(0, 0, 0.2, 1)'}); + /** True if the dropdown is currently open. */ + dropdownOpen: {type: Boolean, reflectToAttribute: true, value: false}, - return document.timeline.play(new GroupEffect([fade, slide])); + /** Toolbar icon currently being displayed. */ + dropdownIcon: { + type: String, + computed: 'computeIcon_(dropdownOpen, closedIcon, openIcon)' }, - animateExit_: function() { - return this.$.dropdown.animate([ - {transform: 'translateY(0)', opacity: 1}, - {transform: 'translateY(-5px)', opacity: 0} - ], {duration: 100, easing: 'cubic-bezier(0.4, 0, 1, 1)'}); + /** Lowest vertical point that the dropdown should occupy (px). */ + lowerBound: {type: Number, observer: 'lowerBoundChanged_'}, + + /** + * True if the max-height CSS property for the dropdown scroll container + * is valid. If false, the height will be updated the next time the + * dropdown is visible. + */ + maxHeightValid_: false, + + /** Current animation being played, or null if there is none. */ + animation_: Object + }, + + computeIcon_: function(dropdownOpen, closedIcon, openIcon) { + return dropdownOpen ? openIcon : closedIcon; + }, + + lowerBoundChanged_: function() { + this.maxHeightValid_ = false; + if (this.dropdownOpen) + this.updateMaxHeight(); + }, + + toggleDropdown: function() { + this.dropdownOpen = !this.dropdownOpen; + if (this.dropdownOpen) { + this.$.dropdown.style.display = 'block'; + if (!this.maxHeightValid_) + this.updateMaxHeight(); } - }); + this.cancelAnimation_(); + this.playAnimation_(this.dropdownOpen); + }, + + updateMaxHeight: function() { + var scrollContainer = this.$['scroll-container']; + var height = this.lowerBound - scrollContainer.getBoundingClientRect().top - + DROPDOWN_INNER_PADDING; + height = Math.max(height, MIN_DROPDOWN_HEIGHT); + scrollContainer.style.maxHeight = height + 'px'; + this.maxHeightValid_ = true; + }, + + cancelAnimation_: function() { + if (this._animation) + this._animation.cancel(); + }, + + /** + * Start an animation on the dropdown. + * @param {boolean} isEntry True to play entry animation, false to play + * exit. + * @private + */ + playAnimation_: function(isEntry) { + this.animation_ = isEntry ? this.animateEntry_() : this.animateExit_(); + this.animation_.onfinish = function() { + this.animation_ = null; + if (!this.dropdownOpen) + this.$.dropdown.style.display = 'none'; + }.bind(this); + }, + + animateEntry_: function() { + var maxHeight = + this.$.dropdown.getBoundingClientRect().height - DROPDOWN_OUTER_PADDING; + + if (maxHeight < 0) + maxHeight = 0; + + var fade = new KeyframeEffect( + this.$.dropdown, [{opacity: 0}, {opacity: 1}], + {duration: 150, easing: 'cubic-bezier(0, 0, 0.2, 1)'}); + var slide = new KeyframeEffect( + this.$.dropdown, + [ + {height: '20px', transform: 'translateY(-10px)'}, + {height: maxHeight + 'px', transform: 'translateY(0)'} + ], + {duration: 250, easing: 'cubic-bezier(0, 0, 0.2, 1)'}); + + return document.timeline.play(new GroupEffect([fade, slide])); + }, + + animateExit_: function() { + return this.$.dropdown.animate( + [ + {transform: 'translateY(0)', opacity: 1}, + {transform: 'translateY(-5px)', opacity: 0} + ], + {duration: 100, easing: 'cubic-bezier(0.4, 0, 1, 1)'}); + } +}); })(); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-button.js b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-button.js index df556aced28..6558c15d4a6 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-button.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-button.js @@ -18,41 +18,25 @@ Polymer({ * perform the conversion manually. * @private */ - icons_: { - type: Array, - value: [''], - computed: 'computeIconsArray_(icons)' - }, + icons_: {type: Array, value: [''], computed: 'computeIconsArray_(icons)'}, tooltips: Array, - closed: { - type: Boolean, - reflectToAttribute: true, - value: false - }, + closed: {type: Boolean, reflectToAttribute: true, value: false}, - delay: { - type: Number, - observer: 'delayChanged_' - }, + delay: {type: Number, observer: 'delayChanged_'}, /** * Index of the icon currently being displayed. */ - activeIndex: { - type: Number, - value: 0 - }, + activeIndex: {type: Number, value: 0}, /** * Icon currently being displayed on the FAB. * @private */ - visibleIcon_: { - type: String, - computed: 'computeVisibleIcon_(icons_, activeIndex)' - }, + visibleIcon_: + {type: String, computed: 'computeVisibleIcon_(icons_, activeIndex)'}, visibleTooltip_: { type: String, diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js index 3ade73b7174..6a4af8f4aa3 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js @@ -4,96 +4,88 @@ (function() { - var FIT_TO_PAGE = 0; - var FIT_TO_WIDTH = 1; +var FIT_TO_PAGE = 0; +var FIT_TO_WIDTH = 1; - Polymer({ - is: 'viewer-zoom-toolbar', +Polymer({ + is: 'viewer-zoom-toolbar', - properties: { - strings: { - type: Object, - observer: 'updateTooltips_' - }, + properties: { + strings: {type: Object, observer: 'updateTooltips_'}, - visible_: { - type: Boolean, - value: true - } - }, + visible_: {type: Boolean, value: true} + }, - isVisible: function() { - return this.visible_; - }, + isVisible: function() { + return this.visible_; + }, - /** - * @private - * Change button tooltips to match any changes to localized strings. - */ - updateTooltips_: function() { - this.$['fit-button'].tooltips = [ - this.strings.tooltipFitToPage, - this.strings.tooltipFitToWidth - ]; - this.$['zoom-in-button'].tooltips = [this.strings.tooltipZoomIn]; - this.$['zoom-out-button'].tooltips = [this.strings.tooltipZoomOut]; - }, + /** + * @private + * Change button tooltips to match any changes to localized strings. + */ + updateTooltips_: function() { + this.$['fit-button'].tooltips = + [this.strings.tooltipFitToPage, this.strings.tooltipFitToWidth]; + this.$['zoom-in-button'].tooltips = [this.strings.tooltipZoomIn]; + this.$['zoom-out-button'].tooltips = [this.strings.tooltipZoomOut]; + }, - /** - * Handle clicks of the fit-button. - */ - fitToggle: function() { - if (this.$['fit-button'].activeIndex == FIT_TO_WIDTH) - this.fire('fit-to-width'); - else - this.fire('fit-to-page'); - }, + /** + * Handle clicks of the fit-button. + */ + fitToggle: function() { + if (this.$['fit-button'].activeIndex == FIT_TO_WIDTH) + this.fire('fit-to-width'); + else + this.fire('fit-to-page'); + }, - /** - * Handle the keyboard shortcut equivalent of fit-button clicks. - */ - fitToggleFromHotKey: function() { - this.fitToggle(); + /** + * Handle the keyboard shortcut equivalent of fit-button clicks. + */ + fitToggleFromHotKey: function() { + this.fitToggle(); - // Toggle the button state since there was no mouse click. - var button = this.$['fit-button']; - if (button.activeIndex == FIT_TO_WIDTH) - button.activeIndex = FIT_TO_PAGE; - else - button.activeIndex = FIT_TO_WIDTH; - }, + // Toggle the button state since there was no mouse click. + var button = this.$['fit-button']; + if (button.activeIndex == FIT_TO_WIDTH) + button.activeIndex = FIT_TO_PAGE; + else + button.activeIndex = FIT_TO_WIDTH; + }, - /** - * Handle clicks of the zoom-in-button. - */ - zoomIn: function() { - this.fire('zoom-in'); - }, + /** + * Handle clicks of the zoom-in-button. + */ + zoomIn: function() { + this.fire('zoom-in'); + }, - /** - * Handle clicks of the zoom-out-button. - */ - zoomOut: function() { - this.fire('zoom-out'); - }, + /** + * Handle clicks of the zoom-out-button. + */ + zoomOut: function() { + this.fire('zoom-out'); + }, - show: function() { - if (!this.visible_) { - this.visible_ = true; - this.$['fit-button'].show(); - this.$['zoom-in-button'].show(); - this.$['zoom-out-button'].show(); - } - }, + show: function() { + if (!this.visible_) { + this.visible_ = true; + this.$['fit-button'].show(); + this.$['zoom-in-button'].show(); + this.$['zoom-out-button'].show(); + } + }, - hide: function() { - if (this.visible_) { - this.visible_ = false; - this.$['fit-button'].hide(); - this.$['zoom-in-button'].hide(); - this.$['zoom-out-button'].hide(); - } - }, - }); + hide: function() { + if (this.visible_) { + this.visible_ = false; + this.$['fit-button'].hide(); + this.$['zoom-in-button'].hide(); + this.$['zoom-out-button'].hide(); + } + }, +}); })(); diff --git a/chromium/chrome/browser/resources/pdf/gesture_detector.js b/chromium/chrome/browser/resources/pdf/gesture_detector.js index d73a85b7a3b..811bfe28b5b 100644 --- a/chromium/chrome/browser/resources/pdf/gesture_detector.js +++ b/chromium/chrome/browser/resources/pdf/gesture_detector.js @@ -20,20 +20,20 @@ class GestureDetector { this.element_.addEventListener( 'touchstart', /** @type {function(!Event)} */ (this.onTouchStart_.bind(this)), - { passive: true }); + {passive: true}); this.element_.addEventListener( 'touchmove', /** @type {function(!Event)} */ (this.onTouch_.bind(this)), - { passive: false }); + {passive: false}); this.element_.addEventListener( 'touchend', /** @type {function(!Event)} */ (this.onTouch_.bind(this)), - { passive: true }); + {passive: true}); this.element_.addEventListener( 'touchcancel', /** @type {function(!Event)} */ (this.onTouch_.bind(this)), - { passive: true }); + {passive: true}); this.pinchStartEvent_ = null; this.lastTouchTouchesCount_ = 0; @@ -42,11 +42,8 @@ class GestureDetector { this.lastEvent_ = null; /** @private {!Map<string, !Array<!Function>>} */ - this.listeners_ = new Map([ - ['pinchstart', []], - ['pinchupdate', []], - ['pinchend', []] - ]); + this.listeners_ = + new Map([['pinchstart', []], ['pinchupdate', []], ['pinchend', []]]); } /** @@ -92,10 +89,7 @@ class GestureDetector { this.pinchStartEvent_ = event; this.lastEvent_ = event; - this.notify_({ - type: 'pinchstart', - center: GestureDetector.center_(event) - }); + this.notify_({type: 'pinchstart', center: GestureDetector.center_(event)}); } /** @@ -112,8 +106,8 @@ class GestureDetector { // Check if the pinch ends with the current event. if (event.touches.length < 2 || lastEvent.touches.length !== event.touches.length) { - let startScaleRatio = GestureDetector.pinchScaleRatio_( - lastEvent, this.pinchStartEvent_); + let startScaleRatio = + GestureDetector.pinchScaleRatio_(lastEvent, this.pinchStartEvent_); let center = GestureDetector.center_(lastEvent); let endEvent = { type: 'pinchend', @@ -131,8 +125,8 @@ class GestureDetector { event.preventDefault(); let scaleRatio = GestureDetector.pinchScaleRatio_(event, lastEvent); - let startScaleRatio = GestureDetector.pinchScaleRatio_( - event, this.pinchStartEvent_); + let startScaleRatio = + GestureDetector.pinchScaleRatio_(event, this.pinchStartEvent_); let center = GestureDetector.center_(event); this.notify_({ type: 'pinchupdate', diff --git a/chromium/chrome/browser/resources/pdf/main.js b/chromium/chrome/browser/resources/pdf/main.js index 901b8e67074..6a1061c6535 100644 --- a/chromium/chrome/browser/resources/pdf/main.js +++ b/chromium/chrome/browser/resources/pdf/main.js @@ -12,44 +12,44 @@ var viewer; (function() { - /** - * Stores any pending messages received which should be passed to the - * PDFViewer when it is created. - * @type Array - */ - var pendingMessages = []; - - /** - * Handles events that are received prior to the PDFViewer being created. - * @param {Object} message A message event received. - */ - function handleScriptingMessage(message) { - pendingMessages.push(message); - } - - /** - * Initialize the global PDFViewer and pass any outstanding messages to it. - * @param {Object} browserApi An object providing an API to the browser. - */ - function initViewer(browserApi) { - // PDFViewer will handle any messages after it is created. - window.removeEventListener('message', handleScriptingMessage, false); - viewer = new PDFViewer(browserApi); - while (pendingMessages.length > 0) - viewer.handleScriptingMessage(pendingMessages.shift()); - } - - /** - * Entrypoint for starting the PDF viewer. This function obtains the browser - * API for the PDF and constructs a PDFViewer object with it. - */ - 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); - - createBrowserApi().then(initViewer); - } - - main(); +/** + * Stores any pending messages received which should be passed to the + * PDFViewer when it is created. + * @type Array + */ +var pendingMessages = []; + +/** + * Handles events that are received prior to the PDFViewer being created. + * @param {Object} message A message event received. + */ +function handleScriptingMessage(message) { + pendingMessages.push(message); +} + +/** + * Initialize the global PDFViewer and pass any outstanding messages to it. + * @param {Object} browserApi An object providing an API to the browser. + */ +function initViewer(browserApi) { + // PDFViewer will handle any messages after it is created. + window.removeEventListener('message', handleScriptingMessage, false); + viewer = new PDFViewer(browserApi); + while (pendingMessages.length > 0) + viewer.handleScriptingMessage(pendingMessages.shift()); +} + +/** + * Entrypoint for starting the PDF viewer. This function obtains the browser + * API for the PDF and constructs a PDFViewer object with it. + */ +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); + + createBrowserApi().then(initViewer); +} + +main(); })(); diff --git a/chromium/chrome/browser/resources/pdf/navigator.js b/chromium/chrome/browser/resources/pdf/navigator.js index d619c42a60b..ebc18db186e 100644 --- a/chromium/chrome/browser/resources/pdf/navigator.js +++ b/chromium/chrome/browser/resources/pdf/navigator.js @@ -179,10 +179,8 @@ Navigator.prototype = { */ isValidUrl_: function(url) { // Make sure |url| starts with a valid scheme. - if (!url.startsWith('http://') && - !url.startsWith('https://') && - !url.startsWith('ftp://') && - !url.startsWith('file://') && + if (!url.startsWith('http://') && !url.startsWith('https://') && + !url.startsWith('ftp://') && !url.startsWith('file://') && !url.startsWith('mailto:')) { return false; } @@ -193,11 +191,8 @@ Navigator.prototype = { // Make sure |url| is not only a scheme. - if (url == 'http://' || - url == 'https://' || - url == 'ftp://' || - url == 'file://' || - url == 'mailto:') { + if (url == 'http://' || url == 'https://' || url == 'ftp://' || + url == 'file://' || url == 'mailto:') { return false; } @@ -226,8 +221,8 @@ Navigator.prototype = { var schemeEndIndex = this.originalUrl_.indexOf('://'); var 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_; + var domain = firstSlash != -1 ? this.originalUrl_.substr(0, firstSlash) : + this.originalUrl_; return domain + url; } @@ -245,7 +240,8 @@ Navigator.prototype = { if (!isRelative) { var domainSeparatorIndex = url.indexOf('/'); var domainName = domainSeparatorIndex == -1 ? - url : url.substr(0, domainSeparatorIndex); + url : + url.substr(0, domainSeparatorIndex); var domainDotCount = (domainName.match(/\./g) || []).length; if (domainDotCount < 2) isRelative = true; @@ -253,8 +249,8 @@ Navigator.prototype = { if (isRelative) { var slashIndex = this.originalUrl_.lastIndexOf('/'); - var path = slashIndex != -1 ? - this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; + var path = slashIndex != -1 ? this.originalUrl_.substr(0, slashIndex) : + this.originalUrl_; return path + '/' + url; } diff --git a/chromium/chrome/browser/resources/pdf/open_pdf_params_parser.js b/chromium/chrome/browser/resources/pdf/open_pdf_params_parser.js index 8d1ac213e69..2eefdec662e 100644 --- a/chromium/chrome/browser/resources/pdf/open_pdf_params_parser.js +++ b/chromium/chrome/browser/resources/pdf/open_pdf_params_parser.js @@ -42,8 +42,10 @@ OpenPDFParamsParser.prototype = { } // Handle #zoom=scale,left,top. - var position = {x: parseFloat(paramValueSplit[1]), - y: parseFloat(paramValueSplit[2])}; + var position = { + x: parseFloat(paramValueSplit[1]), + y: parseFloat(paramValueSplit[2]) + }; viewportPosition['position'] = position; viewportPosition['zoom'] = zoomFactor; }, @@ -123,10 +125,8 @@ OpenPDFParamsParser.prototype = { if (viewportPosition.page === undefined && 'nameddest' in paramsDictionary) { - this.outstandingRequests_.push({ - callback: callback, - viewportPosition: viewportPosition - }); + this.outstandingRequests_.push( + {callback: callback, viewportPosition: viewportPosition}); this.getNamedDestinationsFunction_(paramsDictionary['nameddest']); } else { callback(viewportPosition); diff --git a/chromium/chrome/browser/resources/pdf/pdf.js b/chromium/chrome/browser/resources/pdf/pdf.js index 898935ef283..46c54bea404 100644 --- a/chromium/chrome/browser/resources/pdf/pdf.js +++ b/chromium/chrome/browser/resources/pdf/pdf.js @@ -51,9 +51,9 @@ function shouldIgnoreKeyEvents(activeElement) { activeElement = activeElement.shadowRoot.activeElement; } - return (activeElement.isContentEditable || - activeElement.tagName == 'INPUT' || - activeElement.tagName == 'TEXTAREA'); + return ( + activeElement.isContentEditable || activeElement.tagName == 'INPUT' || + activeElement.tagName == 'TEXTAREA'); } /** @@ -102,6 +102,7 @@ function PDFViewer(browserApi) { this.delayedScriptingMessages_ = []; this.isPrintPreview_ = location.origin === 'chrome://print'; + this.isPrintPreviewLoaded_ = false; // Parse open pdf parameters. this.paramsParser_ = @@ -117,8 +118,8 @@ function PDFViewer(browserApi) { if (this.isPrintPreview_) this.pageIndicator_ = $('page-indicator'); this.passwordScreen_ = $('password-screen'); - this.passwordScreen_.addEventListener('password-submitted', - this.onPasswordSubmitted_.bind(this)); + this.passwordScreen_.addEventListener( + 'password-submitted', this.onPasswordSubmitted_.bind(this)); this.errorScreen_ = $('error-screen'); // Can only reload if we are in a normal tab. if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) { @@ -133,15 +134,12 @@ function PDFViewer(browserApi) { (toolbarEnabled) ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0; var defaultZoom = this.browserApi_.getZoomBehavior() == BrowserApi.ZoomBehavior.MANAGE ? - this.browserApi_.getDefaultZoom() : 1.0; - this.viewport_ = new Viewport(window, - this.sizer_, - this.viewportChanged_.bind(this), - this.beforeZoom_.bind(this), - this.afterZoom_.bind(this), - getScrollbarWidth(), - defaultZoom, - topToolbarHeight); + this.browserApi_.getDefaultZoom() : + 1.0; + this.viewport_ = new Viewport( + window, this.sizer_, this.viewportChanged_.bind(this), + this.beforeZoom_.bind(this), this.afterZoom_.bind(this), + getScrollbarWidth(), defaultZoom, topToolbarHeight); // Create the plugin object dynamically so we can set its src. The plugin // element is sized to fill the entire window and is set to be fixed @@ -152,18 +150,18 @@ function PDFViewer(browserApi) { // chrome/renderer/printing/print_web_view_helper.cc actually references it. this.plugin_.id = 'plugin'; this.plugin_.type = 'application/x-google-chrome-pdf'; - this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), - false); + this.plugin_.addEventListener( + 'message', this.handlePluginMessage_.bind(this), false); // Handle scripting messages from outside the extension that wish to interact // with it. We also send a message indicating that extension has loaded and // is ready to receive messages. - window.addEventListener('message', this.handleScriptingMessage.bind(this), - false); + window.addEventListener( + 'message', this.handleScriptingMessage.bind(this), false); this.plugin_.setAttribute('src', this.originalUrl_); - this.plugin_.setAttribute('stream-url', - this.browserApi_.getStreamInfo().streamUrl); + this.plugin_.setAttribute( + 'stream-url', this.browserApi_.getStreamInfo().streamUrl); var headers = ''; for (var header in this.browserApi_.getStreamInfo().responseHeaders) { headers += header + ': ' + @@ -176,8 +174,8 @@ function PDFViewer(browserApi) { this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight); if (this.browserApi_.getStreamInfo().embedded) { - this.plugin_.setAttribute('top-level-url', - this.browserApi_.getStreamInfo().tabUrl); + this.plugin_.setAttribute( + 'top-level-url', this.browserApi_.getStreamInfo().tabUrl); } else { this.plugin_.setAttribute('full-frame', ''); } @@ -185,14 +183,13 @@ function PDFViewer(browserApi) { // Setup the button event listeners. this.zoomToolbar_ = $('zoom-toolbar'); - this.zoomToolbar_.addEventListener('fit-to-width', - this.viewport_.fitToWidth.bind(this.viewport_)); - this.zoomToolbar_.addEventListener('fit-to-page', - this.fitToPage_.bind(this)); - this.zoomToolbar_.addEventListener('zoom-in', - this.viewport_.zoomIn.bind(this.viewport_)); - this.zoomToolbar_.addEventListener('zoom-out', - this.viewport_.zoomOut.bind(this.viewport_)); + this.zoomToolbar_.addEventListener( + 'fit-to-width', this.viewport_.fitToWidth.bind(this.viewport_)); + this.zoomToolbar_.addEventListener('fit-to-page', this.fitToPage_.bind(this)); + this.zoomToolbar_.addEventListener( + 'zoom-in', this.viewport_.zoomIn.bind(this.viewport_)); + this.zoomToolbar_.addEventListener( + 'zoom-out', this.viewport_.zoomOut.bind(this.viewport_)); this.gestureDetector_ = new GestureDetector(this.plugin_); this.gestureDetector_.addEventListener( @@ -208,12 +205,12 @@ function PDFViewer(browserApi) { this.toolbar_.hidden = false; this.toolbar_.addEventListener('save', this.save_.bind(this)); this.toolbar_.addEventListener('print', this.print_.bind(this)); - this.toolbar_.addEventListener('rotate-right', - this.rotateClockwise_.bind(this)); + this.toolbar_.addEventListener( + 'rotate-right', this.rotateClockwise_.bind(this)); // Must attach to mouseup on the plugin element, since it eats mousedown // and click events. - this.plugin_.addEventListener('mouseup', - this.toolbar_.hideDropdowns.bind(this.toolbar_)); + this.plugin_.addEventListener( + 'mouseup', this.toolbar_.hideDropdowns.bind(this.toolbar_)); this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_); } @@ -223,9 +220,9 @@ function PDFViewer(browserApi) { }.bind(this)); document.body.addEventListener('navigate', function(e) { - var disposition = - e.detail.newtab ? Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB : - Navigator.WindowOpenDisposition.CURRENT_TAB; + var disposition = e.detail.newtab ? + Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB : + Navigator.WindowOpenDisposition.CURRENT_TAB; this.navigator_.navigate(e.detail.uri, disposition); }.bind(this)); @@ -245,8 +242,8 @@ function PDFViewer(browserApi) { document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); document.addEventListener('mouseout', this.handleMouseEvent_.bind(this)); - document.addEventListener('contextmenu', - this.handleContextMenuEvent_.bind(this)); + document.addEventListener( + 'contextmenu', this.handleContextMenuEvent_.bind(this)); var tabId = this.browserApi_.getStreamInfo().tabId; this.navigator_ = new Navigator( @@ -365,14 +362,12 @@ PDFViewer.prototype = { return; case 65: // 'a' key. if (e.ctrlKey || e.metaKey) { - this.plugin_.postMessage({ - type: 'selectAll' - }); + this.plugin_.postMessage({type: 'selectAll'}); // Since we do selection ourselves. e.preventDefault(); } return; - case 71: // 'g' key. + case 71: // 'g' key. if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { this.toolbarManager_.showToolbars(); this.toolbar_.selectPageNumber(); @@ -394,10 +389,8 @@ PDFViewer.prototype = { // Give print preview a chance to handle the key event. if (!fromScriptingAPI && this.isPrintPreview_) { - this.sendScriptingMessage_({ - type: 'sendKeyEvent', - keyEvent: SerializeKeyEvent(e) - }); + this.sendScriptingMessage_( + {type: 'sendKeyEvent', keyEvent: SerializeKeyEvent(e)}); } else { // Show toolbars as a fallback. if (!(e.shiftKey || e.ctrlKey || e.altKey)) @@ -428,9 +421,7 @@ PDFViewer.prototype = { * Rotate the plugin clockwise. */ rotateClockwise_: function() { - this.plugin_.postMessage({ - type: 'rotateClockwise' - }); + this.plugin_.postMessage({type: 'rotateClockwise'}); }, /** @@ -438,9 +429,7 @@ PDFViewer.prototype = { * Rotate the plugin counter-clockwise. */ rotateCounterClockwise_: function() { - this.plugin_.postMessage({ - type: 'rotateCounterclockwise' - }); + this.plugin_.postMessage({type: 'rotateCounterclockwise'}); }, /** @@ -457,9 +446,7 @@ PDFViewer.prototype = { * Notify the plugin to print. */ print_: function() { - this.plugin_.postMessage({ - type: 'print' - }); + this.plugin_.postMessage({type: 'print'}); }, /** @@ -467,9 +454,7 @@ PDFViewer.prototype = { * Notify the plugin to save. */ save_: function() { - this.plugin_.postMessage({ - type: 'save' - }); + this.plugin_.postMessage({type: 'save'}); }, /** @@ -478,10 +463,8 @@ PDFViewer.prototype = { * @param {string} name The namedDestination to fetch page number from plugin. */ getNamedDestination_: function(name) { - this.plugin_.postMessage({ - type: 'getNamedDestination', - namedDestination: name - }); + this.plugin_.postMessage( + {type: 'getNamedDestination', namedDestination: name}); }, /** @@ -492,10 +475,10 @@ PDFViewer.prototype = { sendDocumentLoadedMessage_: function() { if (this.loadState_ == LoadState.LOADING) return; - this.sendScriptingMessage_({ - type: 'documentLoaded', - load_state: this.loadState_ - }); + if (this.isPrintPreview_ && !this.isPrintPreviewLoaded_) + return; + this.sendScriptingMessage_( + {type: 'documentLoaded', load_state: this.loadState_}); }, /** @@ -545,8 +528,7 @@ PDFViewer.prototype = { if (this.lastViewportPosition_) this.viewport_.position = this.lastViewportPosition_; this.paramsParser_.getViewportFromUrlParams( - this.originalUrl_, - this.handleURLParams_.bind(this)); + this.originalUrl_, this.handleURLParams_.bind(this)); this.loadState_ = LoadState.SUCCESS; this.sendDocumentLoadedMessage_(); while (this.delayedScriptingMessages_.length > 0) @@ -579,10 +561,8 @@ PDFViewer.prototype = { * @param {Object} event a password-submitted event. */ onPasswordSubmitted_: function(event) { - this.plugin_.postMessage({ - type: 'getPasswordComplete', - password: event.detail.password - }); + this.plugin_.postMessage( + {type: 'getPasswordComplete', password: event.detail.password}); }, /** @@ -641,6 +621,10 @@ PDFViewer.prototype = { this.navigator_.navigate(message.data.url, message.data.disposition); } break; + case 'printPreviewLoaded': + this.isPrintPreviewLoaded_ = true; + this.sendDocumentLoadedMessage_(); + break; case 'setScrollPosition': var position = this.viewport_.position; if (message.data.x !== undefined) @@ -682,9 +666,7 @@ PDFViewer.prototype = { * reacting to scroll events while zoom is taking place to avoid flickering. */ beforeZoom_: function() { - this.plugin_.postMessage({ - type: 'stopScrolling' - }); + this.plugin_.postMessage({type: 'stopScrolling'}); if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { var position = this.viewport_.position; @@ -777,8 +759,8 @@ PDFViewer.prototype = { // than the spec. In RTL layout, the zoom toolbar is on the left side, but // the scrollbar is still on the right, so this is not necessary. if (!isRTL()) { - this.zoomToolbar_.style.right = -verticalScrollbarWidth + - (scrollbarWidth / 2) + 'px'; + this.zoomToolbar_.style.right = + -verticalScrollbarWidth + (scrollbarWidth / 2) + 'px'; } // Having a horizontal scrollbar is much rarer so we don't offset the // toolbar from the bottom any more than what the spec says. This means @@ -890,8 +872,8 @@ PDFViewer.prototype = { grayscale: message.data.grayscale, // If the PDF isn't modifiable we send 0 as the page count so that no // blank placeholder pages get appended to the PDF. - pageCount: (message.data.modifiable ? - message.data.pageNumbers.length : 0) + pageCount: + (message.data.modifiable ? message.data.pageNumbers.length : 0) }); return true; case 'sendKeyEvent': diff --git a/chromium/chrome/browser/resources/pdf/pdf_scripting_api.js b/chromium/chrome/browser/resources/pdf/pdf_scripting_api.js index 102130e1959..fd5e2e1559c 100644 --- a/chromium/chrome/browser/resources/pdf/pdf_scripting_api.js +++ b/chromium/chrome/browser/resources/pdf/pdf_scripting_api.js @@ -39,11 +39,7 @@ function SerializeKeyEvent(event) { * has finished loading or failed to load. * @enum {string} */ -var LoadState = { - LOADING: 'loading', - SUCCESS: 'success', - FAILED: 'failed' -}; +var LoadState = {LOADING: 'loading', SUCCESS: 'success', FAILED: 'failed'}; /** * Create a new PDFScriptingAPI. This provides a scripting interface to @@ -60,8 +56,8 @@ function PDFScriptingAPI(window, plugin) { window.addEventListener('message', function(event) { if (event.origin != 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai' && event.origin != 'chrome://print') { - console.error('Received message that was not from the extension: ' + - event); + console.error( + 'Received message that was not from the extension: ' + event); return; } switch (event.data.type) { @@ -77,11 +73,9 @@ function PDFScriptingAPI(window, plugin) { */ var viewportData = event.data; if (this.viewportChangedCallback_) - this.viewportChangedCallback_(viewportData.pageX, - viewportData.pageY, - viewportData.pageWidth, - viewportData.viewportWidth, - viewportData.viewportHeight); + this.viewportChangedCallback_( + viewportData.pageX, viewportData.pageY, viewportData.pageWidth, + viewportData.viewportWidth, viewportData.viewportHeight); break; case 'documentLoaded': var data = /** @type {{load_state: LoadState}} */ (event.data); @@ -119,20 +113,18 @@ PDFScriptingAPI.prototype = { this.pendingScriptingMessages_.push(message); }, - /** - * Sets the plugin element containing the PDF viewer. The element will usually - * be passed into the PDFScriptingAPI constructor but may also be set later. - * @param {Object} plugin the plugin element containing the PDF viewer. - */ + /** + * Sets the plugin element containing the PDF viewer. The element will usually + * be passed into the PDFScriptingAPI constructor but may also be set later. + * @param {Object} plugin the plugin element containing the PDF viewer. + */ setPlugin: function(plugin) { this.plugin_ = plugin; if (this.plugin_) { // Send a message to ensure the postMessage channel is initialized which // allows us to receive messages. - this.sendMessage_({ - type: 'initialize' - }); + this.sendMessage_({type: 'initialize'}); // Flush pending messages. while (this.pendingScriptingMessages_.length > 0) this.sendMessage_(this.pendingScriptingMessages_.shift()); @@ -190,11 +182,7 @@ PDFScriptingAPI.prototype = { * @param {number} index the index of the page to load. */ loadPreviewPage: function(url, index) { - this.sendMessage_({ - type: 'loadPreviewPage', - url: url, - index: index - }); + this.sendMessage_({type: 'loadPreviewPage', url: url, index: index}); }, /** @@ -202,9 +190,7 @@ PDFScriptingAPI.prototype = { * load. */ selectAll: function() { - this.sendMessage_({ - type: 'selectAll' - }); + this.sendMessage_({type: 'selectAll'}); }, /** @@ -218,9 +204,7 @@ PDFScriptingAPI.prototype = { if (this.selectedTextCallback_) return false; this.selectedTextCallback_ = callback; - this.sendMessage_({ - type: 'getSelectedText' - }); + this.sendMessage_({type: 'getSelectedText'}); return true; }, @@ -228,9 +212,7 @@ PDFScriptingAPI.prototype = { * Print the document. May only be called after document load. */ print: function() { - this.sendMessage_({ - type: 'print' - }); + this.sendMessage_({type: 'print'}); }, /** @@ -238,10 +220,8 @@ PDFScriptingAPI.prototype = { * @param {Event} keyEvent the key event to send to the extension. */ sendKeyEvent: function(keyEvent) { - this.sendMessage_({ - type: 'sendKeyEvent', - keyEvent: SerializeKeyEvent(keyEvent) - }); + this.sendMessage_( + {type: 'sendKeyEvent', keyEvent: SerializeKeyEvent(keyEvent)}); }, }; @@ -255,8 +235,8 @@ PDFScriptingAPI.prototype = { */ function PDFCreateOutOfProcessPlugin(src) { var client = new PDFScriptingAPI(window, null); - var iframe = assertInstanceof(window.document.createElement('iframe'), - HTMLIFrameElement); + var iframe = assertInstanceof( + window.document.createElement('iframe'), HTMLIFrameElement); iframe.setAttribute('src', 'pdf_preview.html?' + src); // Prevent the frame from being tab-focusable. iframe.setAttribute('tabindex', '-1'); diff --git a/chromium/chrome/browser/resources/pdf/viewport.js b/chromium/chrome/browser/resources/pdf/viewport.js index 6d027f1c8ee..54f166bc6d4 100644 --- a/chromium/chrome/browser/resources/pdf/viewport.js +++ b/chromium/chrome/browser/resources/pdf/viewport.js @@ -9,9 +9,10 @@ * @return {number} the height of the intersection of the rects */ function getIntersectionHeight(rect1, rect2) { - return Math.max(0, + return Math.max( + 0, Math.min(rect1.y + rect1.height, rect2.y + rect2.height) - - Math.max(rect1.y, rect2.y)); + Math.max(rect1.y, rect2.y)); } /** @@ -30,10 +31,7 @@ function clampScale(scale) { * @return {!Object} The vector. */ function vectorDelta(p1, p2) { - return { - x: p2.x - p1.x, - y: p2.y - p1.y - }; + return {x: p2.x - p1.x, y: p2.y - p1.y}; } function frameToPluginCoordinate(coordinateInFrame) { @@ -58,14 +56,9 @@ function frameToPluginCoordinate(coordinateInFrame) { * @param {number} topToolbarHeight The number of pixels that should initially * be left blank above the document for the toolbar. */ -function Viewport(window, - sizer, - viewportChangedCallback, - beforeZoomCallback, - afterZoomCallback, - scrollbarWidth, - defaultZoom, - topToolbarHeight) { +function Viewport( + window, sizer, viewportChangedCallback, beforeZoomCallback, + afterZoomCallback, scrollbarWidth, defaultZoom, topToolbarHeight) { this.window_ = window; this.sizer_ = sizer; this.viewportChangedCallback_ = viewportChangedCallback; @@ -127,8 +120,10 @@ Viewport.SCROLL_INCREMENT = 40; * components/ui/zoom/page_zoom_constants.h and * chrome/browser/resources/settings/appearance_page/appearance_page.js */ -Viewport.ZOOM_FACTORS = [0.25, 1 / 3, 0.5, 2 / 3, 0.75, 0.8, 0.9, - 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5]; +Viewport.ZOOM_FACTORS = [ + 0.25, 1 / 3, 0.5, 2 / 3, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, + 4, 5 +]; /** * The minimum and maximum range to be used to clip zoom factor. @@ -141,7 +136,12 @@ Viewport.ZOOM_FACTOR_RANGE = { /** * The width of the page shadow around pages in pixels. */ -Viewport.PAGE_SHADOW = {top: 3, bottom: 7, left: 5, right: 5}; +Viewport.PAGE_SHADOW = { + top: 3, + bottom: 7, + left: 5, + right: 5 +}; Viewport.prototype = { /** @@ -173,10 +173,7 @@ Viewport.prototype = { documentNeedsScrollbars_: function(zoom) { var zoomedDimensions = this.getZoomedDocumentDimensions_(zoom); if (!zoomedDimensions) { - return { - horizontal: false, - vertical: false - }; + return {horizontal: false, vertical: false}; } // If scrollbars are required for one direction, expand the document in the @@ -211,8 +208,8 @@ Viewport.prototype = { var zoomedDimensions = this.getZoomedDocumentDimensions_(this.zoom); if (zoomedDimensions) { this.sizer_.style.width = zoomedDimensions.width + 'px'; - this.sizer_.style.height = zoomedDimensions.height + - this.topToolbarHeight_ + 'px'; + this.sizer_.style.height = + zoomedDimensions.height + this.topToolbarHeight_ + 'px'; } }, @@ -329,7 +326,7 @@ Viewport.prototype = { setZoomInternal_: function(newZoom) { if (!this.allowedToChangeZoom_) { throw 'Called Viewport.setZoomInternal_ without calling ' + - 'Viewport.mightZoom_.'; + 'Viewport.mightZoom_.'; } // Record the scroll position (relative to the top-left of the window). var currentScrollPos = { @@ -353,9 +350,10 @@ Viewport.prototype = { * @param {!Object} center The pinch center in content coordinates. */ setPinchZoomInternal_: function(scaleDelta, center) { - assert(this.allowedToChangeZoom_, + assert( + this.allowedToChangeZoom_, 'Called Viewport.setPinchZoomInternal_ without calling ' + - 'Viewport.mightZoom_.'); + 'Viewport.mightZoom_.'); this.internalZoom_ = clampScale(this.internalZoom_ * scaleDelta); var newCenterInContent = this.frameToContent(center); @@ -372,10 +370,7 @@ Viewport.prototype = { this.contentSizeChanged_(); // Scroll to the scaled scroll position. - this.position = { - x: currentScrollPos.x, - y: currentScrollPos.y - }; + this.position = {x: currentScrollPos.x, y: currentScrollPos.y}; }, /** @@ -399,8 +394,9 @@ Viewport.prototype = { */ setZoom: function(newZoom) { this.fittingType_ = Viewport.FittingType.NONE; - newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min, - Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max)); + newZoom = Math.max( + Viewport.ZOOM_FACTOR_RANGE.min, + Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max)); this.mightZoom_(function() { this.setZoomInternal_(newZoom); this.updateViewport_(); @@ -461,8 +457,8 @@ Viewport.prototype = { top = this.pageDimensions_[page - 1].y + this.pageDimensions_[page - 1].height; } - var bottom = this.pageDimensions_[page].y + - this.pageDimensions_[page].height; + var bottom = + this.pageDimensions_[page].y + this.pageDimensions_[page].height; if (top <= y && bottom > y) return page; @@ -490,11 +486,13 @@ Viewport.prototype = { width: this.size.width / this.zoom, height: this.size.height / this.zoom }; - var firstVisiblePageVisibility = getIntersectionHeight( - this.pageDimensions_[firstVisiblePage], viewportRect) / + var firstVisiblePageVisibility = + getIntersectionHeight( + this.pageDimensions_[firstVisiblePage], viewportRect) / this.pageDimensions_[firstVisiblePage].height; - var nextPageVisibility = getIntersectionHeight( - this.pageDimensions_[firstVisiblePage + 1], viewportRect) / + var nextPageVisibility = + getIntersectionHeight( + this.pageDimensions_[firstVisiblePage + 1], viewportRect) / this.pageDimensions_[firstVisiblePage + 1].height; if (nextPageVisibility > firstVisiblePageVisibility) return firstVisiblePage + 1; @@ -573,8 +571,8 @@ Viewport.prototype = { return; // When computing fit-to-width, the maximum width of a page in the // document is used, which is equal to the size of the document width. - this.setZoomInternal_(this.computeFittingZoom_(this.documentDimensions_, - true)); + this.setZoomInternal_( + this.computeFittingZoom_(this.documentDimensions_, true)); var page = this.getMostVisiblePage(); this.updateViewport_(); }.bind(this)); @@ -600,10 +598,7 @@ Viewport.prototype = { }; this.setZoomInternal_(this.computeFittingZoom_(dimensions, false)); if (scrollToTopOfPage) { - this.position = { - x: 0, - y: this.pageDimensions_[page].y * this.zoom - }; + this.position = {x: 0, y: this.pageDimensions_[page].y * this.zoom}; } this.updateViewport_(); }.bind(this)); @@ -656,15 +651,15 @@ Viewport.prototype = { pinchZoom: function(e) { this.mightZoom_(function() { this.pinchPhase_ = e.direction == 'out' ? - Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT : - Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN; + Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT : + Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN; var scaleDelta = e.startScaleRatio / this.prevScale_; this.pinchPanVector_ = vectorDelta(e.center, this.firstPinchCenterInFrame_); - var needsScrollbars = this.documentNeedsScrollbars_( - this.zoomManager_.applyBrowserZoom( + var needsScrollbars = + this.documentNeedsScrollbars_(this.zoomManager_.applyBrowserZoom( clampScale(this.internalZoom_ * scaleDelta))); this.pinchCenter_ = e.center; @@ -686,8 +681,7 @@ Viewport.prototype = { this.keepContentCentered_ = false; } - this.setPinchZoomInternal_( - scaleDelta, frameToPluginCoordinate(e.center)); + this.setPinchZoomInternal_(scaleDelta, frameToPluginCoordinate(e.center)); this.updateViewport_(); this.prevScale_ = e.startScaleRatio; }.bind(this)); @@ -712,8 +706,7 @@ Viewport.prototype = { var scaleDelta = e.startScaleRatio / this.prevScale_; this.pinchCenter_ = e.center; - this.setPinchZoomInternal_( - scaleDelta, frameToPluginCoordinate(e.center)); + this.setPinchZoomInternal_(scaleDelta, frameToPluginCoordinate(e.center)); this.updateViewport_(); }.bind(this)); @@ -760,13 +753,10 @@ Viewport.prototype = { this.documentDimensions_ = documentDimensions; this.pageDimensions_ = this.documentDimensions_.pageDimensions; if (initialDimensions) { - this.setZoomInternal_( - Math.min(this.defaultZoom_, - this.computeFittingZoom_(this.documentDimensions_, true))); - this.position = { - x: 0, - y: -this.topToolbarHeight_ - }; + this.setZoomInternal_(Math.min( + this.defaultZoom_, + this.computeFittingZoom_(this.documentDimensions_, true))); + this.position = {x: 0, y: -this.topToolbarHeight_}; } this.contentSizeChanged_(); this.resize_(); @@ -781,12 +771,7 @@ Viewport.prototype = { */ getPageScreenRect: function(page) { if (!this.documentDimensions_) { - return { - x: 0, - y: 0, - width: 0, - height: 0 - }; + return {x: 0, y: 0, width: 0, height: 0}; } if (page >= this.pageDimensions_.length) page = this.pageDimensions_.length - 1; @@ -810,8 +795,8 @@ Viewport.prototype = { Viewport.PAGE_SHADOW.left; // Compute the space on the left of the document if the document fits // completely in the screen. - var spaceOnLeft = (this.size.width - - this.documentDimensions_.width * this.zoom) / 2; + var spaceOnLeft = + (this.size.width - this.documentDimensions_.width * this.zoom) / 2; spaceOnLeft = Math.max(spaceOnLeft, 0); return { diff --git a/chromium/chrome/browser/resources/pdf/viewport_scroller.js b/chromium/chrome/browser/resources/pdf/viewport_scroller.js index eeef83956b9..8246e54e98c 100644 --- a/chromium/chrome/browser/resources/pdf/viewport_scroller.js +++ b/chromium/chrome/browser/resources/pdf/viewport_scroller.js @@ -44,9 +44,9 @@ ViewportScroller.prototype = { */ startDragScrollTimer_: function() { if (this.timerId_ === null) { - this.timerId_ = - this.window_.setInterval(this.dragScrollPage_.bind(this), - ViewportScroller.DRAG_TIMER_INTERVAL_MS_); + this.timerId_ = this.window_.setInterval( + this.dragScrollPage_.bind(this), + ViewportScroller.DRAG_TIMER_INTERVAL_MS_); this.lastFrameTime_ = Date.now(); } }, @@ -71,7 +71,7 @@ ViewportScroller.prototype = { var position = this.viewport_.position; var currentFrameTime = Date.now(); var timeAdjustment = (currentFrameTime - this.lastFrameTime_) / - ViewportScroller.DRAG_TIMER_INTERVAL_MS_; + ViewportScroller.DRAG_TIMER_INTERVAL_MS_; position.y += (this.scrollVelocity_.y * timeAdjustment); position.x += (this.scrollVelocity_.x * timeAdjustment); this.viewport_.position = position; @@ -86,18 +86,19 @@ ViewportScroller.prototype = { * @return {Object} Object with x and y direction scroll velocity. */ calculateVelocity_: function(event) { - var x = Math.min(Math.max(-event.offsetX, - event.offsetX - this.plugin_.offsetWidth, 0), - ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) * - Math.sign(event.offsetX); - var y = Math.min(Math.max(-event.offsetY, - event.offsetY - this.plugin_.offsetHeight, 0), - ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) * - Math.sign(event.offsetY); - return { - x: x, - y: y - }; + var x = + Math.min( + Math.max( + -event.offsetX, event.offsetX - this.plugin_.offsetWidth, 0), + ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) * + Math.sign(event.offsetX); + var y = + Math.min( + Math.max( + -event.offsetY, event.offsetY - this.plugin_.offsetHeight, 0), + ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) * + Math.sign(event.offsetY); + return {x: x, y: y}; }, /** @@ -123,13 +124,13 @@ ViewportScroller.prototype = { if (isSelecting) { if (!this.mousemoveCallback_) this.mousemoveCallback_ = this.onMousemove_.bind(this); - this.plugin_.addEventListener('mousemove', this.mousemoveCallback_, - false); + this.plugin_.addEventListener( + 'mousemove', this.mousemoveCallback_, false); } else { this.stopDragScrollTimer_(); if (this.mousemoveCallback_) { - this.plugin_.removeEventListener('mousemove', this.mousemoveCallback_, - false); + this.plugin_.removeEventListener( + 'mousemove', this.mousemoveCallback_, false); } } } diff --git a/chromium/chrome/browser/resources/pdf/zoom_manager.js b/chromium/chrome/browser/resources/pdf/zoom_manager.js index 5ed2c74ac39..eec9115cd84 100644 --- a/chromium/chrome/browser/resources/pdf/zoom_manager.js +++ b/chromium/chrome/browser/resources/pdf/zoom_manager.js @@ -145,16 +145,16 @@ class ActiveZoomManager extends ZoomManager { if (this.floatingPointEquals(this.browserZoom_, zoom)) return; - this.changingBrowserZoom_ = this.setBrowserZoomFunction_(zoom).then( - function() { - this.browserZoom_ = zoom; - this.changingBrowserZoom_ = null; - - // The extension's zoom level may have changed while the browser zoom - // change was in progress. We call back into onPdfZoomChange to ensure the - // browser zoom is up to date. - this.onPdfZoomChange(); - }.bind(this)); + this.changingBrowserZoom_ = + this.setBrowserZoomFunction_(zoom).then(function() { + this.browserZoom_ = zoom; + this.changingBrowserZoom_ = null; + + // The extension's zoom level may have changed while the browser zoom + // change was in progress. We call back into onPdfZoomChange to ensure + // the browser zoom is up to date. + this.onPdfZoomChange(); + }.bind(this)); } /** |