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

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

Issue 806633003: Implement basic toolbar with Material Design and loading progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Strip out unnecessary components 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 28 matching lines...) Expand all
39 /** 39 /**
40 * Creates a new PDFViewer. There should only be one of these objects per 40 * Creates a new PDFViewer. There should only be one of these objects per
41 * document. 41 * document.
42 * @param {Object} streamDetails The stream object which points to the data 42 * @param {Object} streamDetails The stream object which points to the data
43 * contained in the PDF. 43 * contained in the PDF.
44 */ 44 */
45 function PDFViewer(streamDetails) { 45 function PDFViewer(streamDetails) {
46 this.streamDetails = streamDetails; 46 this.streamDetails = streamDetails;
47 this.loaded = false; 47 this.loaded = false;
48 48
49 var loc = window.location.href;
50 var pageLoaded = loc.substring(loc.lastIndexOf('/') + 1, loc.indexOf('?'));
51 this.isMaterial = pageLoaded === 'index-material.html';
raymes 2015/01/09 04:15:10 I think this can just be: this.isMaterial_ = locat
Alexandre Carlton 2015/01/12 06:33:57 Done.
49 // The sizer element is placed behind the plugin element to cause scrollbars 52 // The sizer element is placed behind the plugin element to cause scrollbars
50 // to be displayed in the window. It is sized according to the document size 53 // to be displayed in the window. It is sized according to the document size
51 // of the pdf and zoom level. 54 // of the pdf and zoom level.
52 this.sizer_ = $('sizer'); 55 this.sizer_ = $('sizer');
53 this.toolbar_ = $('toolbar'); 56 this.toolbar_ = $('toolbar');
54 this.pageIndicator_ = $('page-indicator'); 57 this.pageIndicator_ = $('page-indicator');
55 this.progressBar_ = $('progress-bar'); 58 this.progressBar_ = $('progress-bar');
56 this.passwordScreen_ = $('password-screen'); 59 this.passwordScreen_ = $('password-screen');
57 this.passwordScreen_.addEventListener('password-submitted', 60 this.passwordScreen_.addEventListener('password-submitted',
58 this.onPasswordSubmitted_.bind(this)); 61 this.onPasswordSubmitted_.bind(this));
(...skipping 10 matching lines...) Expand all
69 // element is sized to fill the entire window and is set to be fixed 72 // element is sized to fill the entire window and is set to be fixed
70 // positioning, acting as a viewport. The plugin renders into this viewport 73 // positioning, acting as a viewport. The plugin renders into this viewport
71 // according to the scroll position of the window. 74 // according to the scroll position of the window.
72 this.plugin_ = document.createElement('embed'); 75 this.plugin_ = document.createElement('embed');
73 // NOTE: The plugin's 'id' field must be set to 'plugin' since 76 // NOTE: The plugin's 'id' field must be set to 'plugin' since
74 // chrome/renderer/printing/print_web_view_helper.cc actually references it. 77 // chrome/renderer/printing/print_web_view_helper.cc actually references it.
75 this.plugin_.id = 'plugin'; 78 this.plugin_.id = 'plugin';
76 this.plugin_.type = 'application/x-google-chrome-pdf'; 79 this.plugin_.type = 'application/x-google-chrome-pdf';
77 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), 80 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this),
78 false); 81 false);
79 82 if (this.isMaterial) {
83 this.toolbarHeight_ = $('pdf-toolbar').clientHeight;
84 this.plugin_.style.top = this.toolbarHeight_ + 'px';
85 }
raymes 2015/01/09 04:15:10 We should set the plugin size here too, but it doe
80 // Handle scripting messages from outside the extension that wish to interact 86 // Handle scripting messages from outside the extension that wish to interact
81 // with it. We also send a message indicating that extension has loaded and 87 // with it. We also send a message indicating that extension has loaded and
82 // is ready to receive messages. 88 // is ready to receive messages.
83 window.addEventListener('message', this.handleScriptingMessage_.bind(this), 89 window.addEventListener('message', this.handleScriptingMessage_.bind(this),
84 false); 90 false);
85 this.sendScriptingMessage_({type: 'readyToReceive'}); 91 this.sendScriptingMessage_({type: 'readyToReceive'});
86 92
87 document.title = getFilenameFromURL(this.streamDetails.originalUrl); 93 document.title = getFilenameFromURL(this.streamDetails.originalUrl);
94 if (this.isMaterial)
95 $('title').innerHTML = document.title;
88 this.plugin_.setAttribute('src', this.streamDetails.originalUrl); 96 this.plugin_.setAttribute('src', this.streamDetails.originalUrl);
89 this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl); 97 this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl);
90 var headers = ''; 98 var headers = '';
91 for (var header in this.streamDetails.responseHeaders) { 99 for (var header in this.streamDetails.responseHeaders) {
92 headers += header + ': ' + 100 headers += header + ': ' +
93 this.streamDetails.responseHeaders[header] + '\n'; 101 this.streamDetails.responseHeaders[header] + '\n';
94 } 102 }
95 this.plugin_.setAttribute('headers', headers); 103 this.plugin_.setAttribute('headers', headers);
96 104
97 if (!this.streamDetails.embedded) 105 if (!this.streamDetails.embedded)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 this.viewport_.setZoom(this.urlParams_.zoom); 314 this.viewport_.setZoom(this.urlParams_.zoom);
307 }, 315 },
308 316
309 /** 317 /**
310 * @private 318 * @private
311 * Update the loading progress of the document in response to a progress 319 * Update the loading progress of the document in response to a progress
312 * message being received from the plugin. 320 * message being received from the plugin.
313 * @param {number} progress the progress as a percentage. 321 * @param {number} progress the progress as a percentage.
314 */ 322 */
315 updateProgress_: function(progress) { 323 updateProgress_: function(progress) {
316 this.progressBar_.progress = progress; 324 if (this.isMaterial)
325 this.progressBar_.value = progress;
326 else
327 this.progressBar_.progress = progress;
328
317 if (progress == -1) { 329 if (progress == -1) {
318 // Document load failed. 330 // Document load failed.
319 this.errorScreen_.style.visibility = 'visible'; 331 this.errorScreen_.style.visibility = 'visible';
320 this.sizer_.style.display = 'none'; 332 this.sizer_.style.display = 'none';
321 this.toolbar_.style.visibility = 'hidden'; 333 this.toolbar_.style.visibility = 'hidden';
322 if (this.passwordScreen_.active) { 334 if (this.passwordScreen_.active) {
323 this.passwordScreen_.deny(); 335 this.passwordScreen_.deny();
324 this.passwordScreen_.active = false; 336 this.passwordScreen_.active = false;
325 } 337 }
326 } else if (progress == 100) { 338 } else if (progress == 100) {
327 // Document load complete. 339 // Document load complete.
340 if (this.isMaterial)
341 this.progressBar_.style.visibility = 'hidden';
328 if (this.lastViewportPosition_) 342 if (this.lastViewportPosition_)
329 this.viewport_.position = this.lastViewportPosition_; 343 this.viewport_.position = this.lastViewportPosition_;
330 this.handleURLParams_(); 344 this.handleURLParams_();
331 this.loaded = true; 345 this.loaded = true;
332 var loadEvent = new Event('pdfload'); 346 var loadEvent = new Event('pdfload');
333 window.dispatchEvent(loadEvent); 347 window.dispatchEvent(loadEvent);
334 this.sendScriptingMessage_({ 348 this.sendScriptingMessage_({
335 type: 'documentLoaded' 349 type: 'documentLoaded'
336 }); 350 });
337 } 351 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 case 'setScrollPosition': 418 case 'setScrollPosition':
405 var position = this.viewport_.position; 419 var position = this.viewport_.position;
406 if (message.data.x != undefined) 420 if (message.data.x != undefined)
407 position.x = message.data.x; 421 position.x = message.data.x;
408 if (message.data.y != undefined) 422 if (message.data.y != undefined)
409 position.y = message.data.y; 423 position.y = message.data.y;
410 this.viewport_.position = position; 424 this.viewport_.position = position;
411 break; 425 break;
412 case 'setTranslatedStrings': 426 case 'setTranslatedStrings':
413 this.passwordScreen_.text = message.data.getPasswordString; 427 this.passwordScreen_.text = message.data.getPasswordString;
414 this.progressBar_.text = message.data.loadingString; 428 if (!this.isMaterial)
429 this.progressBar_.text = message.data.loadingString;
415 this.progressBar_.style.visibility = 'visible'; 430 this.progressBar_.style.visibility = 'visible';
416 this.errorScreen_.text = message.data.loadFailedString; 431 this.errorScreen_.text = message.data.loadFailedString;
417 break; 432 break;
418 case 'cancelStreamUrl': 433 case 'cancelStreamUrl':
419 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); 434 chrome.streamsPrivate.abort(this.streamDetails.streamUrl);
420 break; 435 break;
421 } 436 }
422 }, 437 },
423 438
424 /** 439 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 }, 487 },
473 488
474 /** 489 /**
475 * @private 490 * @private
476 * A callback that's called after the viewport changes. 491 * A callback that's called after the viewport changes.
477 */ 492 */
478 viewportChanged_: function() { 493 viewportChanged_: function() {
479 if (!this.documentDimensions_) 494 if (!this.documentDimensions_)
480 return; 495 return;
481 496
497 if (this.isMaterial) {
498 this.plugin_.style.height =
499 (window.innerHeight - this.toolbarHeight_) + 'px';
500 }
raymes 2015/01/09 04:15:10 Same here, we can move this outside the if-block.
raymes 2015/01/13 00:26:18 I think we need to keep something here.
Alexandre Carlton 2015/01/13 03:57:27 Done.
501
482 // Update the buttons selected. 502 // Update the buttons selected.
483 $('fit-to-page-button').classList.remove('polymer-selected'); 503 $('fit-to-page-button').classList.remove('polymer-selected');
484 $('fit-to-width-button').classList.remove('polymer-selected'); 504 $('fit-to-width-button').classList.remove('polymer-selected');
485 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 505 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
486 $('fit-to-page-button').classList.add('polymer-selected'); 506 $('fit-to-page-button').classList.add('polymer-selected');
487 } else if (this.viewport_.fittingType == 507 } else if (this.viewport_.fittingType ==
488 Viewport.FittingType.FIT_TO_WIDTH) { 508 Viewport.FittingType.FIT_TO_WIDTH) {
489 $('fit-to-width-button').classList.add('polymer-selected'); 509 $('fit-to-width-button').classList.add('polymer-selected');
490 } 510 }
491 511
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 this.streamDetails.tabId != -1); 622 this.streamDetails.tabId != -1);
603 }, 623 },
604 624
605 /** 625 /**
606 * @type {Viewport} the viewport of the PDF viewer. 626 * @type {Viewport} the viewport of the PDF viewer.
607 */ 627 */
608 get viewport() { 628 get viewport() {
609 return this.viewport_; 629 return this.viewport_;
610 } 630 }
611 }; 631 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698