summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/pdf
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-20 15:06:40 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-22 11:48:58 +0000
commitdaa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch)
tree96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/chrome/browser/resources/pdf
parentbe59a35641616a4cf23c4a13fa0632624b021c1b (diff)
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/chrome/browser/resources/pdf')
-rw-r--r--chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js41
-rw-r--r--chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html31
-rw-r--r--chromium/chrome/browser/resources/pdf/pdf.js27
-rw-r--r--chromium/chrome/browser/resources/pdf/viewport.js30
4 files changed, 106 insertions, 23 deletions
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 1e7164a333f..de21ff24b32 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
@@ -2,6 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+/**
+ * The |title| is the text label displayed for the bookmark.
+ *
+ * The bookmark may point at a location in the PDF or a URI.
+ * If it points at a location, |page| indicates which 0-based page it leads to.
+ * Optionally, |y| is the y position in that page, in pixel coordinates.
+ * If it points at an URI, |uri| is the target for that bookmark.
+ *
+ * |children| is an array of the |Bookmark|s that are below this in a table of
+ * contents tree
+ * structure.
+ * @typedef {{
+ * title: string,
+ * page: number,
+ * y: number,
+ * uri: string,
+ * children: !Array<!Bookmark>
+ * }}
+ */
+var Bookmark;
+
(function() {
/** Amount that each level of bookmarks is indented by (px). */
var BOOKMARK_INDENT = 20;
@@ -10,12 +31,7 @@ Polymer({
is: 'viewer-bookmark',
properties: {
- /**
- * A bookmark object, each containing a:
- * - title
- * - page (optional)
- * - children (an array of bookmarks)
- */
+ /** @type {Bookmark} */
bookmark: {type: Object, observer: 'bookmarkChanged_'},
depth: {type: Number, observer: 'depthChanged'},
@@ -48,10 +64,17 @@ Polymer({
},
onClick: function() {
- if (this.bookmark.hasOwnProperty('page'))
- this.fire('change-page', {page: this.bookmark.page});
- else if (this.bookmark.hasOwnProperty('uri'))
+ if (this.bookmark.hasOwnProperty('page')) {
+ if (this.bookmark.hasOwnProperty('y')) {
+ this.fire(
+ 'change-page-and-y',
+ {page: this.bookmark.page, y: this.bookmark.y});
+ } else {
+ this.fire('change-page', {page: this.bookmark.page});
+ }
+ } else if (this.bookmark.hasOwnProperty('uri')) {
this.fire('navigate', {uri: this.bookmark.uri, newtab: true});
+ }
},
onEnter_: function(e) {
diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html
index bc6553aab56..9ca3d05e7c8 100644
--- a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html
+++ b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html
@@ -5,7 +5,6 @@
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/neon-animation-runner-behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-progress/paper-progress.html">
-<link rel="import" href="chrome://resources/polymer/v1_0/paper-toolbar/paper-toolbar.html">
<link rel="import" href="chrome://resources/cr_elements/icons.html">
<link rel="import" href="../icons.html">
<link rel="import" href="../viewer-bookmarks-content/viewer-bookmarks-content.html">
@@ -22,8 +21,8 @@
/* We introduce a wrapper aligner element to help with laying out the main
* toolbar content without changing the bottom-aligned progress bar. */
#aligner {
- @apply(--layout-horizontal);
- @apply(--layout-center);
+ align-items: center;
+ display: flex;
padding: 0 8px;
width: 100%;
}
@@ -68,11 +67,23 @@
width: 100%;
}
- paper-toolbar {
- --paper-toolbar-background: rgb(50, 54, 57);
- --paper-toolbar-height: 48px;
+ #toolbar {
@apply(--shadow-elevation-2dp);
+ background-color: rgb(50, 54, 57);
color: rgb(241, 241, 241);
+ display: flex;
+ height: 48px;
+ padding: 0 16px;
+ }
+
+ #progress-container {
+ bottom: 0;
+ left: 0;
+ margin: 0;
+ position: absolute;
+ right: 0;
+ top: auto;
+ width: auto;
}
.invisible {
@@ -103,8 +114,8 @@
}
}
</style>
- <paper-toolbar>
- <div id="aligner" class="middle">
+ <div id="toolbar">
+ <div id="aligner">
<span id="title" title="{{docTitle}}">
<span>{{docTitle}}</span>
</span>
@@ -145,10 +156,10 @@
</viewer-toolbar-dropdown>
</div>
</div>
- <div class="bottom fit">
+ <div id="progress-container">
<paper-progress id="progress" value="{{loadProgress}}"></paper-progress>
</div>
- </paper-toolbar>
+ </div>
</template>
<script src="viewer-pdf-toolbar.js"></script>
</dom-module>
diff --git a/chromium/chrome/browser/resources/pdf/pdf.js b/chromium/chrome/browser/resources/pdf/pdf.js
index ffc2a4907c9..acb36ab187d 100644
--- a/chromium/chrome/browser/resources/pdf/pdf.js
+++ b/chromium/chrome/browser/resources/pdf/pdf.js
@@ -103,6 +103,7 @@ function PDFViewer(browserApi) {
this.isPrintPreview_ = location.origin === 'chrome://print';
this.isPrintPreviewLoaded_ = false;
+ this.isUserInitiatedEvent_ = true;
// Parse open pdf parameters.
this.paramsParser_ =
@@ -139,7 +140,8 @@ function PDFViewer(browserApi) {
this.viewport_ = new Viewport(
window, this.sizer_, this.viewportChanged_.bind(this),
this.beforeZoom_.bind(this), this.afterZoom_.bind(this),
- getScrollbarWidth(), defaultZoom, topToolbarHeight);
+ this.setUserInitiated_.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
@@ -220,6 +222,10 @@ function PDFViewer(browserApi) {
this.viewport_.goToPage(e.detail.page);
});
+ document.body.addEventListener('change-page-and-y', e => {
+ this.viewport_.goToPageAndY(e.detail.page, e.detail.y);
+ });
+
document.body.addEventListener('navigate', e => {
var disposition = e.detail.newtab ?
Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB :
@@ -575,7 +581,9 @@ PDFViewer.prototype = {
switch (message.data.type.toString()) {
case 'documentDimensions':
this.documentDimensions_ = message.data;
+ this.isUserInitiatedEvent_ = false;
this.viewport_.setDocumentDimensions(this.documentDimensions_);
+ this.isUserInitiatedEvent_ = true;
// If we received the document dimensions, the password was good so we
// can dismiss the password screen.
if (this.passwordScreen_.active)
@@ -675,6 +683,7 @@ PDFViewer.prototype = {
var pinchPhase = this.viewport_.pinchPhase;
this.plugin_.postMessage({
type: 'viewport',
+ userInitiated: true,
zoom: zoom,
xOffset: position.x,
yOffset: position.y,
@@ -697,6 +706,7 @@ PDFViewer.prototype = {
this.plugin_.postMessage({
type: 'viewport',
+ userInitiated: this.isUserInitiatedEvent_,
zoom: zoom,
xOffset: position.x,
yOffset: position.y,
@@ -710,6 +720,19 @@ PDFViewer.prototype = {
},
/**
+ * @param {boolean} userInitiated The value to set |isUserInitiatedEvent_|
+ * to.
+ * @private
+ * A callback that sets |isUserInitiatedEvent_| to |userInitiated|.
+ */
+ setUserInitiated_: function(userInitiated) {
+ if (this.isUserInitiatedEvent_ == userInitiated) {
+ throw 'Trying to set user initiated to current value.';
+ }
+ this.isUserInitiatedEvent_ = userInitiated;
+ },
+
+ /**
* @private
* A callback that's called when an update to a pinch zoom is detected.
* @param {!Object} e the pinch event.
@@ -850,7 +873,9 @@ PDFViewer.prototype = {
this.loadState_ = LoadState.LOADING;
if (!this.inPrintPreviewMode_) {
this.inPrintPreviewMode_ = true;
+ this.isUserInitiatedEvent_ = false;
this.zoomToolbar_.forceFitToPage();
+ this.isUserInitiatedEvent_ = true;
}
// Stash the scroll location so that it can be restored when the new
diff --git a/chromium/chrome/browser/resources/pdf/viewport.js b/chromium/chrome/browser/resources/pdf/viewport.js
index 358922c606b..e82551d1080 100644
--- a/chromium/chrome/browser/resources/pdf/viewport.js
+++ b/chromium/chrome/browser/resources/pdf/viewport.js
@@ -51,6 +51,8 @@ function frameToPluginCoordinate(coordinateInFrame) {
* @param {Function} viewportChangedCallback is run when the viewport changes
* @param {Function} beforeZoomCallback is run before a change in zoom
* @param {Function} afterZoomCallback is run after a change in zoom
+ * @param {Function} setUserInitiatedCallback is run to indicate whether a zoom
+ * event is user initiated.
* @param {number} scrollbarWidth the width of scrollbars on the page
* @param {number} defaultZoom The default zoom level.
* @param {number} topToolbarHeight The number of pixels that should initially
@@ -58,12 +60,14 @@ function frameToPluginCoordinate(coordinateInFrame) {
*/
function Viewport(
window, sizer, viewportChangedCallback, beforeZoomCallback,
- afterZoomCallback, scrollbarWidth, defaultZoom, topToolbarHeight) {
+ afterZoomCallback, setUserInitiatedCallback, scrollbarWidth, defaultZoom,
+ topToolbarHeight) {
this.window_ = window;
this.sizer_ = sizer;
this.viewportChangedCallback_ = viewportChangedCallback;
this.beforeZoomCallback_ = beforeZoomCallback;
this.afterZoomCallback_ = afterZoomCallback;
+ this.setUserInitiatedCallback_ = setUserInitiatedCallback;
this.allowedToChangeZoom_ = false;
this.internalZoom_ = 1;
this.zoomManager_ = new InactiveZoomManager(this, 1);
@@ -80,7 +84,7 @@ function Viewport(
this.firstPinchCenterInFrame_ = null;
window.addEventListener('scroll', this.updateViewport_.bind(this));
- window.addEventListener('resize', this.resize_.bind(this));
+ window.addEventListener('resize', this.resizeWrapper_.bind(this));
}
/**
@@ -223,6 +227,16 @@ Viewport.prototype = {
/**
* @private
+ * Called when the browser window size changes.
+ */
+ resizeWrapper_: function() {
+ this.setUserInitiatedCallback_(false);
+ this.resize_();
+ this.setUserInitiatedCallback_(true);
+ },
+
+ /**
+ * @private
* Called when the viewport size changes.
*/
resize_: function() {
@@ -305,6 +319,7 @@ Viewport.prototype = {
/**
* @private
+ * @param {function} f Function to wrap
* Used to wrap a function that might perform zooming on the viewport. This is
* required so that we can notify the plugin that zooming is in progress
* so that while zooming is taking place it can stop reacting to scroll events
@@ -721,6 +736,15 @@ Viewport.prototype = {
* @param {number} page the index of the page to go to. zero-based.
*/
goToPage: function(page) {
+ this.goToPageAndY(page, 0);
+ },
+
+ /**
+ * Go to the given y position in the given page index.
+ * @param {number} page the index of the page to go to. zero-based.
+ * @param {number} y the y position in the page to go to.
+ */
+ goToPageAndY: function(page, y) {
this.mightZoom_(() => {
if (this.pageDimensions_.length === 0)
return;
@@ -737,7 +761,7 @@ Viewport.prototype = {
toolbarOffset = this.topToolbarHeight_;
this.position = {
x: dimensions.x * this.zoom,
- y: dimensions.y * this.zoom - toolbarOffset
+ y: (dimensions.y + y) * this.zoom - toolbarOffset
};
this.updateViewport_();
});