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

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: Implement Raymes' suggestions 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 29 matching lines...) Expand all
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 this.parentWindow_ = null; 48 this.parentWindow_ = null;
49 49
50 this.isMaterial_ = location.pathname.substring(1) == 'index-material.html';
50 // The sizer element is placed behind the plugin element to cause scrollbars 51 // The sizer element is placed behind the plugin element to cause scrollbars
51 // to be displayed in the window. It is sized according to the document size 52 // to be displayed in the window. It is sized according to the document size
52 // of the pdf and zoom level. 53 // of the pdf and zoom level.
53 this.sizer_ = $('sizer'); 54 this.sizer_ = $('sizer');
54 this.toolbar_ = $('toolbar'); 55 this.toolbar_ = $('toolbar');
55 this.pageIndicator_ = $('page-indicator'); 56 this.pageIndicator_ = $('page-indicator');
56 this.progressBar_ = $('progress-bar'); 57 this.progressBar_ = $('progress-bar');
57 this.passwordScreen_ = $('password-screen'); 58 this.passwordScreen_ = $('password-screen');
58 this.passwordScreen_.addEventListener('password-submitted', 59 this.passwordScreen_.addEventListener('password-submitted',
59 this.onPasswordSubmitted_.bind(this)); 60 this.onPasswordSubmitted_.bind(this));
60 this.errorScreen_ = $('error-screen'); 61 this.errorScreen_ = $('error-screen');
62 this.toolbarHeight_ = (this.isMaterial_) ? $('pdf-toolbar').clientHeight : 0;
61 63
62 // Create the viewport. 64 // Create the viewport.
63 this.viewport_ = new Viewport(window, 65 this.viewport_ = new Viewport(window,
64 this.sizer_, 66 this.sizer_,
65 this.viewportChanged_.bind(this), 67 this.viewportChanged_.bind(this),
66 this.beforeZoom_.bind(this), 68 this.beforeZoom_.bind(this),
67 this.afterZoom_.bind(this), 69 this.afterZoom_.bind(this),
68 getScrollbarWidth()); 70 getScrollbarWidth(),
71 this.toolbarHeight_);
69 // Create the plugin object dynamically so we can set its src. The plugin 72 // Create the plugin object dynamically so we can set its src. The plugin
70 // element is sized to fill the entire window and is set to be fixed 73 // element is sized to fill the entire window and is set to be fixed
71 // positioning, acting as a viewport. The plugin renders into this viewport 74 // positioning, acting as a viewport. The plugin renders into this viewport
72 // according to the scroll position of the window. 75 // according to the scroll position of the window.
73 this.plugin_ = document.createElement('embed'); 76 this.plugin_ = document.createElement('embed');
74 // NOTE: The plugin's 'id' field must be set to 'plugin' since 77 // NOTE: The plugin's 'id' field must be set to 'plugin' since
75 // chrome/renderer/printing/print_web_view_helper.cc actually references it. 78 // chrome/renderer/printing/print_web_view_helper.cc actually references it.
76 this.plugin_.id = 'plugin'; 79 this.plugin_.id = 'plugin';
77 this.plugin_.type = 'application/x-google-chrome-pdf'; 80 this.plugin_.type = 'application/x-google-chrome-pdf';
78 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), 81 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this),
79 false); 82 false);
83 this.plugin_.style.top = this.toolbarHeight_ + 'px';
84 this.plugin_.style.height = (window.innerHeight - this.toolbarHeight_) + 'px';
raymes 2015/01/13 05:27:27 We'll have to add if (this.isMaterial_) here too.
Alexandre Carlton 2015/01/13 06:22:41 Done.
85 this.plugin_.style.width = window.innerWidth + 'px';
86
80 87
81 // Handle scripting messages from outside the extension that wish to interact 88 // Handle scripting messages from outside the extension that wish to interact
82 // with it. We also send a message indicating that extension has loaded and 89 // with it. We also send a message indicating that extension has loaded and
83 // is ready to receive messages. 90 // is ready to receive messages.
84 window.addEventListener('message', this.handleScriptingMessage.bind(this), 91 window.addEventListener('message', this.handleScriptingMessage.bind(this),
85 false); 92 false);
86 93
87 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); 94 document.title = getFilenameFromURL(this.streamDetails_.originalUrl);
95 if (this.isMaterial_)
96 $('title').innerHTML = document.title;
88 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); 97 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl);
89 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); 98 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl);
90 var headers = ''; 99 var headers = '';
91 for (var header in this.streamDetails_.responseHeaders) { 100 for (var header in this.streamDetails_.responseHeaders) {
92 headers += header + ': ' + 101 headers += header + ': ' +
93 this.streamDetails_.responseHeaders[header] + '\n'; 102 this.streamDetails_.responseHeaders[header] + '\n';
94 } 103 }
95 this.plugin_.setAttribute('headers', headers); 104 this.plugin_.setAttribute('headers', headers);
96 105
97 if (!this.streamDetails_.embedded) 106 if (!this.streamDetails_.embedded)
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 this.viewport_.setZoom(this.urlParams_.zoom); 306 this.viewport_.setZoom(this.urlParams_.zoom);
298 }, 307 },
299 308
300 /** 309 /**
301 * @private 310 * @private
302 * Update the loading progress of the document in response to a progress 311 * Update the loading progress of the document in response to a progress
303 * message being received from the plugin. 312 * message being received from the plugin.
304 * @param {number} progress the progress as a percentage. 313 * @param {number} progress the progress as a percentage.
305 */ 314 */
306 updateProgress_: function(progress) { 315 updateProgress_: function(progress) {
307 this.progressBar_.progress = progress; 316 if (this.isMaterial_)
317 this.progressBar_.value = progress;
318 else
319 this.progressBar_.progress = progress;
320
308 if (progress == -1) { 321 if (progress == -1) {
309 // Document load failed. 322 // Document load failed.
310 this.errorScreen_.style.visibility = 'visible'; 323 this.errorScreen_.style.visibility = 'visible';
311 this.sizer_.style.display = 'none'; 324 this.sizer_.style.display = 'none';
312 this.toolbar_.style.visibility = 'hidden'; 325 this.toolbar_.style.visibility = 'hidden';
313 if (this.passwordScreen_.active) { 326 if (this.passwordScreen_.active) {
314 this.passwordScreen_.deny(); 327 this.passwordScreen_.deny();
315 this.passwordScreen_.active = false; 328 this.passwordScreen_.active = false;
316 } 329 }
317 } else if (progress == 100) { 330 } else if (progress == 100) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 case 'setScrollPosition': 404 case 'setScrollPosition':
392 var position = this.viewport_.position; 405 var position = this.viewport_.position;
393 if (message.data.x != undefined) 406 if (message.data.x != undefined)
394 position.x = message.data.x; 407 position.x = message.data.x;
395 if (message.data.y != undefined) 408 if (message.data.y != undefined)
396 position.y = message.data.y; 409 position.y = message.data.y;
397 this.viewport_.position = position; 410 this.viewport_.position = position;
398 break; 411 break;
399 case 'setTranslatedStrings': 412 case 'setTranslatedStrings':
400 this.passwordScreen_.text = message.data.getPasswordString; 413 this.passwordScreen_.text = message.data.getPasswordString;
401 this.progressBar_.text = message.data.loadingString; 414 if (!this.isMaterial_)
415 this.progressBar_.text = message.data.loadingString;
402 this.progressBar_.style.visibility = 'visible'; 416 this.progressBar_.style.visibility = 'visible';
403 this.errorScreen_.text = message.data.loadFailedString; 417 this.errorScreen_.text = message.data.loadFailedString;
404 break; 418 break;
405 case 'cancelStreamUrl': 419 case 'cancelStreamUrl':
406 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl); 420 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl);
407 break; 421 break;
408 } 422 }
409 }, 423 },
410 424
411 /** 425 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 }, 473 },
460 474
461 /** 475 /**
462 * @private 476 * @private
463 * A callback that's called after the viewport changes. 477 * A callback that's called after the viewport changes.
464 */ 478 */
465 viewportChanged_: function() { 479 viewportChanged_: function() {
466 if (!this.documentDimensions_) 480 if (!this.documentDimensions_)
467 return; 481 return;
468 482
483 if (this.isMaterial_) {
484 this.plugin_.style.height =
485 (window.innerHeight - this.toolbarHeight_) + 'px';
486 this.plugin_.style.height = window.innerWidth;
487 }
488
469 // Update the buttons selected. 489 // Update the buttons selected.
470 $('fit-to-page-button').classList.remove('polymer-selected'); 490 $('fit-to-page-button').classList.remove('polymer-selected');
471 $('fit-to-width-button').classList.remove('polymer-selected'); 491 $('fit-to-width-button').classList.remove('polymer-selected');
472 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 492 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
473 $('fit-to-page-button').classList.add('polymer-selected'); 493 $('fit-to-page-button').classList.add('polymer-selected');
474 } else if (this.viewport_.fittingType == 494 } else if (this.viewport_.fittingType ==
475 Viewport.FittingType.FIT_TO_WIDTH) { 495 Viewport.FittingType.FIT_TO_WIDTH) {
476 $('fit-to-width-button').classList.add('polymer-selected'); 496 $('fit-to-width-button').classList.add('polymer-selected');
477 } 497 }
478 498
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 this.streamDetails_.tabId != -1); 621 this.streamDetails_.tabId != -1);
602 }, 622 },
603 623
604 /** 624 /**
605 * @type {Viewport} the viewport of the PDF viewer. 625 * @type {Viewport} the viewport of the PDF viewer.
606 */ 626 */
607 get viewport() { 627 get viewport() {
608 return this.viewport_; 628 return this.viewport_;
609 } 629 }
610 }; 630 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698