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

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

Issue 1521913002: PDF: Delete non-material viewer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 this.browserApi_ = browserApi; 124 this.browserApi_ = browserApi;
125 this.loadState_ = LoadState.LOADING; 125 this.loadState_ = LoadState.LOADING;
126 this.parentWindow_ = null; 126 this.parentWindow_ = null;
127 this.parentOrigin_ = null; 127 this.parentOrigin_ = null;
128 this.isFormFieldFocused_ = false; 128 this.isFormFieldFocused_ = false;
129 129
130 this.delayedScriptingMessages_ = []; 130 this.delayedScriptingMessages_ = [];
131 131
132 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( 132 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf(
133 'chrome://print') == 0; 133 'chrome://print') == 0;
134 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html';
135 134
136 // The sizer element is placed behind the plugin element to cause scrollbars 135 // The sizer element is placed behind the plugin element to cause scrollbars
137 // to be displayed in the window. It is sized according to the document size 136 // to be displayed in the window. It is sized according to the document size
138 // of the pdf and zoom level. 137 // of the pdf and zoom level.
139 this.sizer_ = $('sizer'); 138 this.sizer_ = $('sizer');
140 this.toolbar_ = $('toolbar'); 139 if (this.isPrintPreview_)
141 if (!this.isMaterial_ || this.isPrintPreview_)
142 this.pageIndicator_ = $('page-indicator'); 140 this.pageIndicator_ = $('page-indicator');
143 this.progressBar_ = $('progress-bar');
144 this.passwordScreen_ = $('password-screen'); 141 this.passwordScreen_ = $('password-screen');
145 this.passwordScreen_.addEventListener('password-submitted', 142 this.passwordScreen_.addEventListener('password-submitted',
146 this.onPasswordSubmitted_.bind(this)); 143 this.onPasswordSubmitted_.bind(this));
147 this.errorScreen_ = $('error-screen'); 144 this.errorScreen_ = $('error-screen');
148 // Can only reload if we are in a normal tab. 145 // Can only reload if we are in a normal tab.
149 if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) { 146 if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) {
150 this.errorScreen_.reloadFn = function() { 147 this.errorScreen_.reloadFn = function() {
151 chrome.tabs.reload(this.browserApi_.getStreamInfo().tabId); 148 chrome.tabs.reload(this.browserApi_.getStreamInfo().tabId);
152 }.bind(this); 149 }.bind(this);
153 } 150 }
154 151
155 // Create the viewport. 152 // Create the viewport.
156 var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT; 153 var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT;
157 var topToolbarHeight = 154 var topToolbarHeight = (!this.isPrintPreview_ && !shortWindow) ?
158 (this.isMaterial_ && !this.isPrintPreview_ && !shortWindow) ? 155 PDFViewer.MATERIAL_TOOLBAR_HEIGHT :
159 PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0; 156 0;
160 this.viewport_ = new Viewport(window, 157 this.viewport_ = new Viewport(window,
161 this.sizer_, 158 this.sizer_,
162 this.viewportChanged_.bind(this), 159 this.viewportChanged_.bind(this),
163 this.beforeZoom_.bind(this), 160 this.beforeZoom_.bind(this),
164 this.afterZoom_.bind(this), 161 this.afterZoom_.bind(this),
165 getScrollbarWidth(), 162 getScrollbarWidth(),
166 this.browserApi_.getDefaultZoom(), 163 this.browserApi_.getDefaultZoom(),
167 topToolbarHeight); 164 topToolbarHeight);
168 165
169 // Create the plugin object dynamically so we can set its src. The plugin 166 // Create the plugin object dynamically so we can set its src. The plugin
(...skipping 19 matching lines...) Expand all
189 this.plugin_.setAttribute('stream-url', 186 this.plugin_.setAttribute('stream-url',
190 this.browserApi_.getStreamInfo().streamUrl); 187 this.browserApi_.getStreamInfo().streamUrl);
191 var headers = ''; 188 var headers = '';
192 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { 189 for (var header in this.browserApi_.getStreamInfo().responseHeaders) {
193 headers += header + ': ' + 190 headers += header + ': ' +
194 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; 191 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n';
195 } 192 }
196 this.plugin_.setAttribute('headers', headers); 193 this.plugin_.setAttribute('headers', headers);
197 194
198 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR; 195 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR;
199 if (!this.isMaterial_)
200 backgroundColor = PDFViewer.LIGHT_BACKGROUND_COLOR;
201 this.plugin_.setAttribute('background-color', backgroundColor); 196 this.plugin_.setAttribute('background-color', backgroundColor);
202 this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight); 197 this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight);
203 198
204 if (!this.browserApi_.getStreamInfo().embedded) 199 if (!this.browserApi_.getStreamInfo().embedded)
205 this.plugin_.setAttribute('full-frame', ''); 200 this.plugin_.setAttribute('full-frame', '');
206 document.body.appendChild(this.plugin_); 201 document.body.appendChild(this.plugin_);
207 202
208 // Setup the button event listeners. 203 // Setup the button event listeners.
209 if (!this.isMaterial_) { 204 this.zoomToolbar_ = $('zoom-toolbar');
210 $('fit-to-width-button').addEventListener('click', 205 this.zoomToolbar_.addEventListener('fit-to-width',
211 this.viewport_.fitToWidth.bind(this.viewport_)); 206 this.viewport_.fitToWidth.bind(this.viewport_));
212 $('fit-to-page-button').addEventListener('click', 207 this.zoomToolbar_.addEventListener('fit-to-page',
213 this.viewport_.fitToPage.bind(this.viewport_)); 208 this.fitToPage_.bind(this));
214 $('zoom-in-button').addEventListener('click', 209 this.zoomToolbar_.addEventListener('zoom-in',
215 this.viewport_.zoomIn.bind(this.viewport_)); 210 this.viewport_.zoomIn.bind(this.viewport_));
216 $('zoom-out-button').addEventListener('click', 211 this.zoomToolbar_.addEventListener('zoom-out',
217 this.viewport_.zoomOut.bind(this.viewport_)); 212 this.viewport_.zoomOut.bind(this.viewport_));
218 $('save-button').addEventListener('click', this.save_.bind(this)); 213
219 $('print-button').addEventListener('click', this.print_.bind(this)); 214 if (!this.isPrintPreview_) {
215 this.materialToolbar_ = $('material-toolbar');
216 this.materialToolbar_.hidden = false;
217 this.materialToolbar_.addEventListener('save', this.save_.bind(this));
218 this.materialToolbar_.addEventListener('print', this.print_.bind(this));
219 this.materialToolbar_.addEventListener('rotate-right',
220 this.rotateClockwise_.bind(this));
221 // Must attach to mouseup on the plugin element, since it eats mousedown
222 // and click events.
223 this.plugin_.addEventListener('mouseup',
224 this.materialToolbar_.hideDropdowns.bind(this.materialToolbar_));
225
226 this.materialToolbar_.docTitle =
227 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl);
220 } 228 }
221 229
222 if (this.isMaterial_) { 230 document.body.addEventListener('change-page', function(e) {
223 this.zoomToolbar_ = $('zoom-toolbar'); 231 this.viewport_.goToPage(e.detail.page);
224 this.zoomToolbar_.addEventListener('fit-to-width', 232 }.bind(this));
225 this.viewport_.fitToWidth.bind(this.viewport_));
226 this.zoomToolbar_.addEventListener('fit-to-page',
227 this.fitToPage_.bind(this));
228 this.zoomToolbar_.addEventListener('zoom-in',
229 this.viewport_.zoomIn.bind(this.viewport_));
230 this.zoomToolbar_.addEventListener('zoom-out',
231 this.viewport_.zoomOut.bind(this.viewport_));
232 233
233 if (!this.isPrintPreview_) { 234 this.toolbarManager_ =
234 this.materialToolbar_ = $('material-toolbar'); 235 new ToolbarManager(window, this.materialToolbar_, this.zoomToolbar_);
235 this.materialToolbar_.hidden = false;
236 this.materialToolbar_.addEventListener('save', this.save_.bind(this));
237 this.materialToolbar_.addEventListener('print', this.print_.bind(this));
238 this.materialToolbar_.addEventListener('rotate-right',
239 this.rotateClockwise_.bind(this));
240 // Must attach to mouseup on the plugin element, since it eats mousedown
241 // and click events.
242 this.plugin_.addEventListener('mouseup',
243 this.materialToolbar_.hideDropdowns.bind(this.materialToolbar_));
244
245 this.materialToolbar_.docTitle =
246 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl);
247 }
248
249 document.body.addEventListener('change-page', function(e) {
250 this.viewport_.goToPage(e.detail.page);
251 }.bind(this));
252
253 this.toolbarManager_ =
254 new ToolbarManager(window, this.materialToolbar_, this.zoomToolbar_);
255 }
256 236
257 // Set up the ZoomManager. 237 // Set up the ZoomManager.
258 this.zoomManager_ = new ZoomManager( 238 this.zoomManager_ = new ZoomManager(
259 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_), 239 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_),
260 this.browserApi_.getInitialZoom()); 240 this.browserApi_.getInitialZoom());
261 this.browserApi_.addZoomEventListener( 241 this.browserApi_.addZoomEventListener(
262 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); 242 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_));
263 243
264 // Setup the keyboard event listener. 244 // Setup the keyboard event listener.
265 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); 245 document.addEventListener('keydown', this.handleKeyEvent_.bind(this));
(...skipping 28 matching lines...) Expand all
294 * @param {KeyboardEvent} e the event to handle. 274 * @param {KeyboardEvent} e the event to handle.
295 */ 275 */
296 handleKeyEvent_: function(e) { 276 handleKeyEvent_: function(e) {
297 var position = this.viewport_.position; 277 var position = this.viewport_.position;
298 // Certain scroll events may be sent from outside of the extension. 278 // Certain scroll events may be sent from outside of the extension.
299 var fromScriptingAPI = e.fromScriptingAPI; 279 var fromScriptingAPI = e.fromScriptingAPI;
300 280
301 if (shouldIgnoreKeyEvents(document.activeElement) || e.defaultPrevented) 281 if (shouldIgnoreKeyEvents(document.activeElement) || e.defaultPrevented)
302 return; 282 return;
303 283
304 if (this.isMaterial_) 284 this.toolbarManager_.hideToolbarsAfterTimeout(e);
305 this.toolbarManager_.hideToolbarsAfterTimeout(e);
306 285
307 var pageUpHandler = function() { 286 var pageUpHandler = function() {
308 // Go to the previous page if we are fit-to-page. 287 // Go to the previous page if we are fit-to-page.
309 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 288 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
310 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); 289 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
311 // Since we do the movement of the page. 290 // Since we do the movement of the page.
312 e.preventDefault(); 291 e.preventDefault();
313 } else if (fromScriptingAPI) { 292 } else if (fromScriptingAPI) {
314 position.y -= this.viewport.size.height; 293 position.y -= this.viewport.size.height;
315 this.viewport.position = position; 294 this.viewport.position = position;
316 } 295 }
317 }.bind(this); 296 }.bind(this);
318 var pageDownHandler = function() { 297 var pageDownHandler = function() {
319 // Go to the next page if we are fit-to-page. 298 // Go to the next page if we are fit-to-page.
320 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 299 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
321 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1); 300 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
322 // Since we do the movement of the page. 301 // Since we do the movement of the page.
323 e.preventDefault(); 302 e.preventDefault();
324 } else if (fromScriptingAPI) { 303 } else if (fromScriptingAPI) {
325 position.y += this.viewport.size.height; 304 position.y += this.viewport.size.height;
326 this.viewport.position = position; 305 this.viewport.position = position;
327 } 306 }
328 }.bind(this); 307 }.bind(this);
329 308
330 switch (e.keyCode) { 309 switch (e.keyCode) {
331 case 9: // Tab key. 310 case 9: // Tab key.
332 this.toolbarManager_.showToolbarsForKeyboardNavigation(); 311 this.toolbarManager_.showToolbarsForKeyboardNavigation();
333 return; 312 return;
334 case 27: // Escape key. 313 case 27: // Escape key.
335 if (this.isMaterial_ && !this.isPrintPreview_) { 314 if (!this.isPrintPreview_) {
336 this.toolbarManager_.hideSingleToolbarLayer(); 315 this.toolbarManager_.hideSingleToolbarLayer();
337 return; 316 return;
338 } 317 }
339 break; // Ensure escape falls through to the print-preview handler. 318 break; // Ensure escape falls through to the print-preview handler.
340 case 32: // Space key. 319 case 32: // Space key.
341 if (e.shiftKey) 320 if (e.shiftKey)
342 pageUpHandler(); 321 pageUpHandler();
343 else 322 else
344 pageDownHandler(); 323 pageDownHandler();
345 return; 324 return;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 case 65: // a key. 373 case 65: // a key.
395 if (e.ctrlKey || e.metaKey) { 374 if (e.ctrlKey || e.metaKey) {
396 this.plugin_.postMessage({ 375 this.plugin_.postMessage({
397 type: 'selectAll' 376 type: 'selectAll'
398 }); 377 });
399 // Since we do selection ourselves. 378 // Since we do selection ourselves.
400 e.preventDefault(); 379 e.preventDefault();
401 } 380 }
402 return; 381 return;
403 case 71: // g key. 382 case 71: // g key.
404 if (this.isMaterial_ && this.materialToolbar_ && 383 if (this.materialToolbar_ && (e.ctrlKey || e.metaKey)) {
405 (e.ctrlKey || e.metaKey)) {
406 this.toolbarManager_.showToolbars(); 384 this.toolbarManager_.showToolbars();
407 this.materialToolbar_.selectPageNumber(); 385 this.materialToolbar_.selectPageNumber();
408 // To prevent the default "find text" behaviour in Chrome. 386 // To prevent the default "find text" behaviour in Chrome.
409 e.preventDefault(); 387 e.preventDefault();
410 } 388 }
411 return; 389 return;
412 case 219: // left bracket. 390 case 219: // left bracket.
413 if (e.ctrlKey) 391 if (e.ctrlKey)
414 this.rotateCounterClockwise_(); 392 this.rotateCounterClockwise_();
415 return; 393 return;
416 case 221: // right bracket. 394 case 221: // right bracket.
417 if (e.ctrlKey) 395 if (e.ctrlKey)
418 this.rotateClockwise_(); 396 this.rotateClockwise_();
419 return; 397 return;
420 } 398 }
421 399
422 // Give print preview a chance to handle the key event. 400 // Give print preview a chance to handle the key event.
423 if (!fromScriptingAPI && this.isPrintPreview_) { 401 if (!fromScriptingAPI && this.isPrintPreview_) {
424 this.sendScriptingMessage_({ 402 this.sendScriptingMessage_({
425 type: 'sendKeyEvent', 403 type: 'sendKeyEvent',
426 keyEvent: SerializeKeyEvent(e) 404 keyEvent: SerializeKeyEvent(e)
427 }); 405 });
428 } else if (this.isMaterial_) { 406 } else {
429 // Show toolbars as a fallback. 407 // Show toolbars as a fallback.
430 if (!(e.shiftKey || e.ctrlKey || e.altKey)) 408 if (!(e.shiftKey || e.ctrlKey || e.altKey))
431 this.toolbarManager_.showToolbars(); 409 this.toolbarManager_.showToolbars();
432 } 410 }
433 }, 411 },
434 412
435 handleMouseEvent_: function(e) { 413 handleMouseEvent_: function(e) {
436 if (this.isMaterial_) { 414 if (e.type == 'mousemove')
437 if (e.type == 'mousemove') 415 this.toolbarManager_.handleMouseMove(e);
438 this.toolbarManager_.handleMouseMove(e); 416 else if (e.type == 'mouseout')
439 else if (e.type == 'mouseout') 417 this.toolbarManager_.hideToolbarsForMouseOut();
440 this.toolbarManager_.hideToolbarsForMouseOut();
441 }
442 }, 418 },
443 419
444 /** 420 /**
445 * @private 421 * @private
446 * Rotate the plugin clockwise. 422 * Rotate the plugin clockwise.
447 */ 423 */
448 rotateClockwise_: function() { 424 rotateClockwise_: function() {
449 this.plugin_.postMessage({ 425 this.plugin_.postMessage({
450 type: 'rotateClockwise' 426 type: 'rotateClockwise'
451 }); 427 });
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 this.viewport_.setZoom(viewportPosition.zoom); 510 this.viewport_.setZoom(viewportPosition.zoom);
535 }, 511 },
536 512
537 /** 513 /**
538 * @private 514 * @private
539 * Update the loading progress of the document in response to a progress 515 * Update the loading progress of the document in response to a progress
540 * message being received from the plugin. 516 * message being received from the plugin.
541 * @param {number} progress the progress as a percentage. 517 * @param {number} progress the progress as a percentage.
542 */ 518 */
543 updateProgress_: function(progress) { 519 updateProgress_: function(progress) {
544 if (this.isMaterial_) { 520 if (this.materialToolbar_)
545 if (this.materialToolbar_) 521 this.materialToolbar_.loadProgress = progress;
546 this.materialToolbar_.loadProgress = progress;
547 } else {
548 this.progressBar_.progress = progress;
549 }
550 522
551 if (progress == -1) { 523 if (progress == -1) {
552 // Document load failed. 524 // Document load failed.
553 this.errorScreen_.show(); 525 this.errorScreen_.show();
554 this.sizer_.style.display = 'none'; 526 this.sizer_.style.display = 'none';
555 if (!this.isMaterial_)
556 this.toolbar_.style.visibility = 'hidden';
557 if (this.passwordScreen_.active) { 527 if (this.passwordScreen_.active) {
558 this.passwordScreen_.deny(); 528 this.passwordScreen_.deny();
559 this.passwordScreen_.active = false; 529 this.passwordScreen_.active = false;
560 } 530 }
561 this.loadState_ = LoadState.FAILED; 531 this.loadState_ = LoadState.FAILED;
562 this.sendDocumentLoadedMessage_(); 532 this.sendDocumentLoadedMessage_();
563 } else if (progress == 100) { 533 } else if (progress == 100) {
564 // Document load complete. 534 // Document load complete.
565 if (this.lastViewportPosition_) 535 if (this.lastViewportPosition_)
566 this.viewport_.position = this.lastViewportPosition_; 536 this.viewport_.position = this.lastViewportPosition_;
567 this.paramsParser_.getViewportFromUrlParams( 537 this.paramsParser_.getViewportFromUrlParams(
568 this.browserApi_.getStreamInfo().originalUrl, 538 this.browserApi_.getStreamInfo().originalUrl,
569 this.handleURLParams_.bind(this)); 539 this.handleURLParams_.bind(this));
570 this.loadState_ = LoadState.SUCCESS; 540 this.loadState_ = LoadState.SUCCESS;
571 this.sendDocumentLoadedMessage_(); 541 this.sendDocumentLoadedMessage_();
572 while (this.delayedScriptingMessages_.length > 0) 542 while (this.delayedScriptingMessages_.length > 0)
573 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); 543 this.handleScriptingMessage(this.delayedScriptingMessages_.shift());
574 544
575 if (this.isMaterial_) 545 this.toolbarManager_.hideToolbarsAfterTimeout();
576 this.toolbarManager_.hideToolbarsAfterTimeout();
577 } 546 }
578 }, 547 },
579 548
580 /** 549 /**
581 * @private 550 * @private
582 * Load a dictionary of translated strings into the UI. Used as a callback for 551 * Load a dictionary of translated strings into the UI. Used as a callback for
583 * chrome.resourcesPrivate. 552 * chrome.resourcesPrivate.
584 * @param {Object} strings Dictionary of translated strings 553 * @param {Object} strings Dictionary of translated strings
585 */ 554 */
586 handleStrings_: function(strings) { 555 handleStrings_: function(strings) {
587 if (this.isMaterial_) { 556 window.loadTimeData.data = strings;
588 window.loadTimeData.data = strings; 557 i18nTemplate.process(document, loadTimeData);
589 i18nTemplate.process(document, loadTimeData); 558 this.zoomToolbar_.updateTooltips();
590 this.zoomToolbar_.updateTooltips();
591 } else {
592 this.passwordScreen_.text = strings.passwordPrompt;
593 this.progressBar_.text = strings.pageLoading;
594 if (!this.isPrintPreview_)
595 this.progressBar_.style.visibility = 'visible';
596 this.errorScreen_.text = strings.pageLoadFailed;
597 }
598 }, 559 },
599 560
600 /** 561 /**
601 * @private 562 * @private
602 * An event handler for handling password-submitted events. These are fired 563 * An event handler for handling password-submitted events. These are fired
603 * when an event is entered into the password screen. 564 * when an event is entered into the password screen.
604 * @param {Object} event a password-submitted event. 565 * @param {Object} event a password-submitted event.
605 */ 566 */
606 onPasswordSubmitted_: function(event) { 567 onPasswordSubmitted_: function(event) {
607 this.plugin_.postMessage({ 568 this.plugin_.postMessage({
(...skipping 13 matching lines...) Expand all
621 this.documentDimensions_ = message.data; 582 this.documentDimensions_ = message.data;
622 this.viewport_.setDocumentDimensions(this.documentDimensions_); 583 this.viewport_.setDocumentDimensions(this.documentDimensions_);
623 // If we received the document dimensions, the password was good so we 584 // If we received the document dimensions, the password was good so we
624 // can dismiss the password screen. 585 // can dismiss the password screen.
625 if (this.passwordScreen_.active) 586 if (this.passwordScreen_.active)
626 this.passwordScreen_.accept(); 587 this.passwordScreen_.accept();
627 588
628 if (this.pageIndicator_) 589 if (this.pageIndicator_)
629 this.pageIndicator_.initialFadeIn(); 590 this.pageIndicator_.initialFadeIn();
630 591
631 if (this.isMaterial_) { 592 if (this.materialToolbar_) {
632 if (this.materialToolbar_) { 593 this.materialToolbar_.docLength =
633 this.materialToolbar_.docLength = 594 this.documentDimensions_.pageDimensions.length;
634 this.documentDimensions_.pageDimensions.length;
635 }
636 } else {
637 this.toolbar_.initialFadeIn();
638 } 595 }
639 break; 596 break;
640 case 'email': 597 case 'email':
641 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + 598 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
642 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + 599 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject +
643 '&body=' + message.data.body; 600 '&body=' + message.data.body;
644 window.location.href = href; 601 window.location.href = href;
645 break; 602 break;
646 case 'getAccessibilityJSONReply': 603 case 'getAccessibilityJSONReply':
647 this.sendScriptingMessage_(message.data); 604 this.sendScriptingMessage_(message.data);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 chrome.mimeHandlerPrivate.abortStream(); 639 chrome.mimeHandlerPrivate.abortStream();
683 break; 640 break;
684 case 'metadata': 641 case 'metadata':
685 if (message.data.title) { 642 if (message.data.title) {
686 document.title = message.data.title; 643 document.title = message.data.title;
687 } else { 644 } else {
688 document.title = 645 document.title =
689 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl); 646 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl);
690 } 647 }
691 this.bookmarks_ = message.data.bookmarks; 648 this.bookmarks_ = message.data.bookmarks;
692 if (this.isMaterial_ && this.materialToolbar_) { 649 if (this.materialToolbar_) {
693 this.materialToolbar_.docTitle = document.title; 650 this.materialToolbar_.docTitle = document.title;
694 this.materialToolbar_.bookmarks = this.bookmarks; 651 this.materialToolbar_.bookmarks = this.bookmarks;
695 } 652 }
696 break; 653 break;
697 case 'setIsSelecting': 654 case 'setIsSelecting':
698 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); 655 this.viewportScroller_.setEnableScrolling(message.data.isSelecting);
699 break; 656 break;
700 case 'getNamedDestinationReply': 657 case 'getNamedDestinationReply':
701 this.paramsParser_.onNamedDestinationReceived( 658 this.paramsParser_.onNamedDestinationReceived(
702 message.data.pageNumber); 659 message.data.pageNumber);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 }, 693 },
737 694
738 /** 695 /**
739 * @private 696 * @private
740 * A callback that's called after the viewport changes. 697 * A callback that's called after the viewport changes.
741 */ 698 */
742 viewportChanged_: function() { 699 viewportChanged_: function() {
743 if (!this.documentDimensions_) 700 if (!this.documentDimensions_)
744 return; 701 return;
745 702
746 // Update the buttons selected.
747 if (!this.isMaterial_) {
748 $('fit-to-page-button').classList.remove('polymer-selected');
749 $('fit-to-width-button').classList.remove('polymer-selected');
750 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
751 $('fit-to-page-button').classList.add('polymer-selected');
752 } else if (this.viewport_.fittingType ==
753 Viewport.FittingType.FIT_TO_WIDTH) {
754 $('fit-to-width-button').classList.add('polymer-selected');
755 }
756 }
757
758 // Offset the toolbar position so that it doesn't move if scrollbars appear. 703 // Offset the toolbar position so that it doesn't move if scrollbars appear.
759 var hasScrollbars = this.viewport_.documentHasScrollbars(); 704 var hasScrollbars = this.viewport_.documentHasScrollbars();
760 var scrollbarWidth = this.viewport_.scrollbarWidth; 705 var scrollbarWidth = this.viewport_.scrollbarWidth;
761 var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0; 706 var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
762 var horizontalScrollbarWidth = 707 var horizontalScrollbarWidth =
763 hasScrollbars.horizontal ? scrollbarWidth : 0; 708 hasScrollbars.horizontal ? scrollbarWidth : 0;
764 if (this.isMaterial_) { 709
765 // Shift the zoom toolbar to the left by half a scrollbar width. This 710 // Shift the zoom toolbar to the left by half a scrollbar width. This
766 // gives a compromise: if there is no scrollbar visible then the toolbar 711 // gives a compromise: if there is no scrollbar visible then the toolbar
767 // will be half a scrollbar width further left than the spec but if there 712 // will be half a scrollbar width further left than the spec but if there
768 // is a scrollbar visible it will be half a scrollbar width further right 713 // is a scrollbar visible it will be half a scrollbar width further right
769 // than the spec. In RTL layout, the zoom toolbar is on the left side, but 714 // than the spec. In RTL layout, the zoom toolbar is on the left side, but
770 // the scrollbar is still on the right, so this is not necessary. 715 // the scrollbar is still on the right, so this is not necessary.
771 if (!isRTL()) { 716 if (!isRTL()) {
772 this.zoomToolbar_.style.right = -verticalScrollbarWidth + 717 this.zoomToolbar_.style.right = -verticalScrollbarWidth +
773 (scrollbarWidth / 2) + 'px'; 718 (scrollbarWidth / 2) + 'px';
774 }
775 // Having a horizontal scrollbar is much rarer so we don't offset the
776 // toolbar from the bottom any more than what the spec says. This means
777 // that when there is a scrollbar visible, it will be a full scrollbar
778 // width closer to the bottom of the screen than usual, but this is ok.
779 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px';
780 } else {
781 var toolbarRight = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
782 var toolbarBottom =
783 Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
784 toolbarRight -= verticalScrollbarWidth;
785 toolbarBottom -= horizontalScrollbarWidth;
786 this.toolbar_.style.right = toolbarRight + 'px';
787 this.toolbar_.style.bottom = toolbarBottom + 'px';
788 // Hide the toolbar if it doesn't fit in the viewport.
789 if (this.toolbar_.offsetLeft < 0 || this.toolbar_.offsetTop < 0)
790 this.toolbar_.style.visibility = 'hidden';
791 else
792 this.toolbar_.style.visibility = 'visible';
793 } 719 }
720 // Having a horizontal scrollbar is much rarer so we don't offset the
721 // toolbar from the bottom any more than what the spec says. This means
722 // that when there is a scrollbar visible, it will be a full scrollbar
723 // width closer to the bottom of the screen than usual, but this is ok.
724 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px';
794 725
795 // Update the page indicator. 726 // Update the page indicator.
796 var visiblePage = this.viewport_.getMostVisiblePage(); 727 var visiblePage = this.viewport_.getMostVisiblePage();
797 728
798 if (this.materialToolbar_) 729 if (this.materialToolbar_)
799 this.materialToolbar_.pageNo = visiblePage + 1; 730 this.materialToolbar_.pageNo = visiblePage + 1;
800 731
801 // TODO(raymes): Give pageIndicator_ the same API as materialToolbar_. 732 // TODO(raymes): Give pageIndicator_ the same API as materialToolbar_.
802 if (this.pageIndicator_) { 733 if (this.pageIndicator_) {
803 this.pageIndicator_.index = visiblePage; 734 this.pageIndicator_.index = visiblePage;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 * Each bookmark is an Object containing a: 874 * Each bookmark is an Object containing a:
944 * - title 875 * - title
945 * - page (optional) 876 * - page (optional)
946 * - array of children (themselves bookmarks) 877 * - array of children (themselves bookmarks)
947 * @type {Array} the top-level bookmarks of the PDF. 878 * @type {Array} the top-level bookmarks of the PDF.
948 */ 879 */
949 get bookmarks() { 880 get bookmarks() {
950 return this.bookmarks_; 881 return this.bookmarks_;
951 } 882 }
952 }; 883 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/manifest.json ('k') | chrome/browser/resources/pdf/pdf_scripting_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698