Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/resources/pdf/pdf.js

Issue 861673002: Implement Page Selection in PDF Toolbar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pdf-toolbar
Patch Set: Shift CSS into polymer element Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 for (var header in this.streamDetails_.responseHeaders) { 104 for (var header in this.streamDetails_.responseHeaders) {
105 headers += header + ': ' + 105 headers += header + ': ' +
106 this.streamDetails_.responseHeaders[header] + '\n'; 106 this.streamDetails_.responseHeaders[header] + '\n';
107 } 107 }
108 this.plugin_.setAttribute('headers', headers); 108 this.plugin_.setAttribute('headers', headers);
109 109
110 if (!this.streamDetails_.embedded) 110 if (!this.streamDetails_.embedded)
111 this.plugin_.setAttribute('full-frame', ''); 111 this.plugin_.setAttribute('full-frame', '');
112 document.body.appendChild(this.plugin_); 112 document.body.appendChild(this.plugin_);
113 113
114 this.pageIndicator_.addEventListener('changePage', function(e) {
115 this.viewport_.goToPage(e.detail.page);
116 }.bind(this));
117
114 // Setup the button event listeners. 118 // Setup the button event listeners.
115 $('fit-to-width-button').addEventListener('click', 119 $('fit-to-width-button').addEventListener('click',
116 this.viewport_.fitToWidth.bind(this.viewport_)); 120 this.viewport_.fitToWidth.bind(this.viewport_));
117 $('fit-to-page-button').addEventListener('click', 121 $('fit-to-page-button').addEventListener('click',
118 this.viewport_.fitToPage.bind(this.viewport_)); 122 this.viewport_.fitToPage.bind(this.viewport_));
119 $('zoom-in-button').addEventListener('click', 123 $('zoom-in-button').addEventListener('click',
120 this.viewport_.zoomIn.bind(this.viewport_)); 124 this.viewport_.zoomIn.bind(this.viewport_));
121 $('zoom-out-button').addEventListener('click', 125 $('zoom-out-button').addEventListener('click',
122 this.viewport_.zoomOut.bind(this.viewport_)); 126 this.viewport_.zoomOut.bind(this.viewport_));
123 $('save-button').addEventListener('click', this.save_.bind(this)); 127 $('save-button').addEventListener('click', this.save_.bind(this));
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 * Notify the plugin to save. 288 * Notify the plugin to save.
285 */ 289 */
286 save_: function() { 290 save_: function() {
287 this.plugin_.postMessage({ 291 this.plugin_.postMessage({
288 type: 'save' 292 type: 'save'
289 }); 293 });
290 }, 294 },
291 295
292 /** 296 /**
293 * @private 297 * @private
298 * Advance the page.
299 */
300 goToNextPage_: function() {
Sam McNally 2015/01/21 04:03:38 Are these used?
Alexandre Carlton 2015/01/21 05:20:35 Removed.
301 var currentPage = this.viewport_.getMostVisiblePage();
302 this.viewport_.goToPage(currentPage + 1);
303 },
304
305 /**
306 * @private
307 * Go back a page.
308 */
309 goToPreviousPage_: function() {
310 var currentPage = this.viewport_.getMostVisiblePage();
311 this.viewport_.goToPage(currentPage - 1);
312 },
313
314 /**
315 * @private
294 * Handle open pdf parameters. This function updates the viewport as per 316 * Handle open pdf parameters. This function updates the viewport as per
295 * the parameters mentioned in the url while opening pdf. The order is 317 * the parameters mentioned in the url while opening pdf. The order is
296 * important as later actions can override the effects of previous actions. 318 * important as later actions can override the effects of previous actions.
297 */ 319 */
298 handleURLParams_: function() { 320 handleURLParams_: function() {
299 var urlParams = 321 var urlParams =
300 this.paramsParser_.getViewportFromUrlParams( 322 this.paramsParser_.getViewportFromUrlParams(
301 this.streamDetails_.originalUrl); 323 this.streamDetails_.originalUrl);
302 if (urlParams.page) 324 if (urlParams.page)
303 this.viewport_.goToPage(urlParams.page); 325 this.viewport_.goToPage(urlParams.page);
(...skipping 26 matching lines...) Expand all
330 this.sizer_.style.display = 'none'; 352 this.sizer_.style.display = 'none';
331 this.toolbar_.style.visibility = 'hidden'; 353 this.toolbar_.style.visibility = 'hidden';
332 if (this.passwordScreen_.active) { 354 if (this.passwordScreen_.active) {
333 this.passwordScreen_.deny(); 355 this.passwordScreen_.deny();
334 this.passwordScreen_.active = false; 356 this.passwordScreen_.active = false;
335 } 357 }
336 } else if (progress == 100) { 358 } else if (progress == 100) {
337 // Document load complete. 359 // Document load complete.
338 if (this.lastViewportPosition_) 360 if (this.lastViewportPosition_)
339 this.viewport_.position = this.lastViewportPosition_; 361 this.viewport_.position = this.lastViewportPosition_;
362 if (this.isMaterial_)
363 this.pageIndicator_.style.visibility = 'visible';
340 this.handleURLParams_(); 364 this.handleURLParams_();
341 this.loaded_ = true; 365 this.loaded_ = true;
342 this.sendScriptingMessage_({ 366 this.sendScriptingMessage_({
343 type: 'documentLoaded' 367 type: 'documentLoaded'
344 }); 368 });
345 } 369 }
346 }, 370 },
347 371
348 /** 372 /**
349 * @private 373 * @private
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 handlePluginMessage_: function(message) { 452 handlePluginMessage_: function(message) {
429 switch (message.data.type.toString()) { 453 switch (message.data.type.toString()) {
430 case 'documentDimensions': 454 case 'documentDimensions':
431 this.documentDimensions_ = message.data; 455 this.documentDimensions_ = message.data;
432 this.viewport_.setDocumentDimensions(this.documentDimensions_); 456 this.viewport_.setDocumentDimensions(this.documentDimensions_);
433 // If we received the document dimensions, the password was good so we 457 // If we received the document dimensions, the password was good so we
434 // can dismiss the password screen. 458 // can dismiss the password screen.
435 if (this.passwordScreen_.active) 459 if (this.passwordScreen_.active)
436 this.passwordScreen_.accept(); 460 this.passwordScreen_.accept();
437 461
438 this.pageIndicator_.initialFadeIn(); 462 if (this.isMaterial_) {
463 this.pageIndicator_.docLength =
Sam McNally 2015/01/21 04:03:38 Indentation.
Alexandre Carlton 2015/01/21 05:20:35 Done.
464 this.documentDimensions_.pageDimensions.length;
465 } else {
466 this.pageIndicator_.initialFadeIn();
467 }
468
439 this.toolbar_.initialFadeIn(); 469 this.toolbar_.initialFadeIn();
440 break; 470 break;
441 case 'email': 471 case 'email':
442 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + 472 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
443 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + 473 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject +
444 '&body=' + message.data.body; 474 '&body=' + message.data.body;
445 window.location.href = href; 475 window.location.href = href;
446 break; 476 break;
447 case 'getAccessibilityJSONReply': 477 case 'getAccessibilityJSONReply':
448 this.sendScriptingMessage_(message.data); 478 this.sendScriptingMessage_(message.data);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 this.toolbar_.style.bottom = toolbarBottom + 'px'; 614 this.toolbar_.style.bottom = toolbarBottom + 'px';
585 // Hide the toolbar if it doesn't fit in the viewport. 615 // Hide the toolbar if it doesn't fit in the viewport.
586 if (this.toolbar_.offsetLeft < 0 || this.toolbar_.offsetTop < 0) 616 if (this.toolbar_.offsetLeft < 0 || this.toolbar_.offsetTop < 0)
587 this.toolbar_.style.visibility = 'hidden'; 617 this.toolbar_.style.visibility = 'hidden';
588 else 618 else
589 this.toolbar_.style.visibility = 'visible'; 619 this.toolbar_.style.visibility = 'visible';
590 620
591 // Update the page indicator. 621 // Update the page indicator.
592 var visiblePage = this.viewport_.getMostVisiblePage(); 622 var visiblePage = this.viewport_.getMostVisiblePage();
593 this.pageIndicator_.index = visiblePage; 623 this.pageIndicator_.index = visiblePage;
594 if (this.documentDimensions_.pageDimensions.length > 1 && 624 if (!this.isMaterial_) {
595 hasScrollbars.vertical) { 625 if (this.documentDimensions_.pageDimensions.length > 1 &&
596 this.pageIndicator_.style.visibility = 'visible'; 626 hasScrollbars.vertical) {
597 } else { 627 this.pageIndicator_.style.visibility = 'visible';
598 this.pageIndicator_.style.visibility = 'hidden'; 628 } else {
629 this.pageIndicator_.style.visibility = 'hidden';
630 }
599 } 631 }
600 632
601 var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage); 633 var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage);
602 var size = this.viewport_.size; 634 var size = this.viewport_.size;
603 this.sendScriptingMessage_({ 635 this.sendScriptingMessage_({
604 type: 'viewport', 636 type: 'viewport',
605 pageX: visiblePageDimensions.x, 637 pageX: visiblePageDimensions.x,
606 pageY: visiblePageDimensions.y, 638 pageY: visiblePageDimensions.y,
607 pageWidth: visiblePageDimensions.width, 639 pageWidth: visiblePageDimensions.width,
608 viewportWidth: size.width, 640 viewportWidth: size.width,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 this.streamDetails_.tabId != -1); 734 this.streamDetails_.tabId != -1);
703 }, 735 },
704 736
705 /** 737 /**
706 * @type {Viewport} the viewport of the PDF viewer. 738 * @type {Viewport} the viewport of the PDF viewer.
707 */ 739 */
708 get viewport() { 740 get viewport() {
709 return this.viewport_; 741 return this.viewport_;
710 } 742 }
711 }; 743 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698