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

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

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 * an editable element has focus, to allow for proper editing controls. 44 * an editable element has focus, to allow for proper editing controls.
45 * @param {HTMLElement} activeElement The currently selected DOM node. 45 * @param {HTMLElement} activeElement The currently selected DOM node.
46 * @return {boolean} True if keydown events should be ignored. 46 * @return {boolean} True if keydown events should be ignored.
47 */ 47 */
48 function shouldIgnoreKeyEvents(activeElement) { 48 function shouldIgnoreKeyEvents(activeElement) {
49 while (activeElement.shadowRoot != null && 49 while (activeElement.shadowRoot != null &&
50 activeElement.shadowRoot.activeElement != null) { 50 activeElement.shadowRoot.activeElement != null) {
51 activeElement = activeElement.shadowRoot.activeElement; 51 activeElement = activeElement.shadowRoot.activeElement;
52 } 52 }
53 53
54 return (activeElement.isContentEditable || 54 return (
55 activeElement.tagName == 'INPUT' || 55 activeElement.isContentEditable || activeElement.tagName == 'INPUT' ||
56 activeElement.tagName == 'TEXTAREA'); 56 activeElement.tagName == 'TEXTAREA');
57 } 57 }
58 58
59 /** 59 /**
60 * The minimum number of pixels to offset the toolbar by from the bottom and 60 * The minimum number of pixels to offset the toolbar by from the bottom and
61 * right side of the screen. 61 * right side of the screen.
62 */ 62 */
63 PDFViewer.MIN_TOOLBAR_OFFSET = 15; 63 PDFViewer.MIN_TOOLBAR_OFFSET = 15;
64 64
65 /** 65 /**
66 * The height of the toolbar along the top of the page. The document will be 66 * The height of the toolbar along the top of the page. The document will be
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar && 110 this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar &&
111 !this.isPrintPreview_; 111 !this.isPrintPreview_;
112 112
113 // The sizer element is placed behind the plugin element to cause scrollbars 113 // The sizer element is placed behind the plugin element to cause scrollbars
114 // to be displayed in the window. It is sized according to the document size 114 // to be displayed in the window. It is sized according to the document size
115 // of the pdf and zoom level. 115 // of the pdf and zoom level.
116 this.sizer_ = $('sizer'); 116 this.sizer_ = $('sizer');
117 if (this.isPrintPreview_) 117 if (this.isPrintPreview_)
118 this.pageIndicator_ = $('page-indicator'); 118 this.pageIndicator_ = $('page-indicator');
119 this.passwordScreen_ = $('password-screen'); 119 this.passwordScreen_ = $('password-screen');
120 this.passwordScreen_.addEventListener('password-submitted', 120 this.passwordScreen_.addEventListener(
121 this.onPasswordSubmitted_.bind(this)); 121 'password-submitted', this.onPasswordSubmitted_.bind(this));
122 this.errorScreen_ = $('error-screen'); 122 this.errorScreen_ = $('error-screen');
123 // Can only reload if we are in a normal tab. 123 // Can only reload if we are in a normal tab.
124 if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) { 124 if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) {
125 this.errorScreen_.reloadFn = function() { 125 this.errorScreen_.reloadFn = function() {
126 chrome.tabs.reload(this.browserApi_.getStreamInfo().tabId); 126 chrome.tabs.reload(this.browserApi_.getStreamInfo().tabId);
127 }.bind(this); 127 }.bind(this);
128 } 128 }
129 129
130 // Create the viewport. 130 // Create the viewport.
131 var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT; 131 var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT;
132 var topToolbarHeight = 132 var topToolbarHeight =
133 (toolbarEnabled) ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0; 133 (toolbarEnabled) ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0;
134 var defaultZoom = 134 var defaultZoom =
135 this.browserApi_.getZoomBehavior() == BrowserApi.ZoomBehavior.MANAGE ? 135 this.browserApi_.getZoomBehavior() == BrowserApi.ZoomBehavior.MANAGE ?
136 this.browserApi_.getDefaultZoom() : 1.0; 136 this.browserApi_.getDefaultZoom() :
137 this.viewport_ = new Viewport(window, 137 1.0;
138 this.sizer_, 138 this.viewport_ = new Viewport(
139 this.viewportChanged_.bind(this), 139 window, this.sizer_, this.viewportChanged_.bind(this),
140 this.beforeZoom_.bind(this), 140 this.beforeZoom_.bind(this), this.afterZoom_.bind(this),
141 this.afterZoom_.bind(this), 141 getScrollbarWidth(), defaultZoom, topToolbarHeight);
142 getScrollbarWidth(),
143 defaultZoom,
144 topToolbarHeight);
145 142
146 // Create the plugin object dynamically so we can set its src. The plugin 143 // Create the plugin object dynamically so we can set its src. The plugin
147 // element is sized to fill the entire window and is set to be fixed 144 // element is sized to fill the entire window and is set to be fixed
148 // positioning, acting as a viewport. The plugin renders into this viewport 145 // positioning, acting as a viewport. The plugin renders into this viewport
149 // according to the scroll position of the window. 146 // according to the scroll position of the window.
150 this.plugin_ = document.createElement('embed'); 147 this.plugin_ = document.createElement('embed');
151 // NOTE: The plugin's 'id' field must be set to 'plugin' since 148 // NOTE: The plugin's 'id' field must be set to 'plugin' since
152 // chrome/renderer/printing/print_web_view_helper.cc actually references it. 149 // chrome/renderer/printing/print_web_view_helper.cc actually references it.
153 this.plugin_.id = 'plugin'; 150 this.plugin_.id = 'plugin';
154 this.plugin_.type = 'application/x-google-chrome-pdf'; 151 this.plugin_.type = 'application/x-google-chrome-pdf';
155 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), 152 this.plugin_.addEventListener(
156 false); 153 'message', this.handlePluginMessage_.bind(this), false);
157 154
158 // Handle scripting messages from outside the extension that wish to interact 155 // Handle scripting messages from outside the extension that wish to interact
159 // with it. We also send a message indicating that extension has loaded and 156 // with it. We also send a message indicating that extension has loaded and
160 // is ready to receive messages. 157 // is ready to receive messages.
161 window.addEventListener('message', this.handleScriptingMessage.bind(this), 158 window.addEventListener(
162 false); 159 'message', this.handleScriptingMessage.bind(this), false);
163 160
164 this.plugin_.setAttribute('src', this.originalUrl_); 161 this.plugin_.setAttribute('src', this.originalUrl_);
165 this.plugin_.setAttribute('stream-url', 162 this.plugin_.setAttribute(
166 this.browserApi_.getStreamInfo().streamUrl); 163 'stream-url', this.browserApi_.getStreamInfo().streamUrl);
167 var headers = ''; 164 var headers = '';
168 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { 165 for (var header in this.browserApi_.getStreamInfo().responseHeaders) {
169 headers += header + ': ' + 166 headers += header + ': ' +
170 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; 167 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n';
171 } 168 }
172 this.plugin_.setAttribute('headers', headers); 169 this.plugin_.setAttribute('headers', headers);
173 170
174 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR; 171 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR;
175 this.plugin_.setAttribute('background-color', backgroundColor); 172 this.plugin_.setAttribute('background-color', backgroundColor);
176 this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight); 173 this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight);
177 174
178 if (this.browserApi_.getStreamInfo().embedded) { 175 if (this.browserApi_.getStreamInfo().embedded) {
179 this.plugin_.setAttribute('top-level-url', 176 this.plugin_.setAttribute(
180 this.browserApi_.getStreamInfo().tabUrl); 177 'top-level-url', this.browserApi_.getStreamInfo().tabUrl);
181 } else { 178 } else {
182 this.plugin_.setAttribute('full-frame', ''); 179 this.plugin_.setAttribute('full-frame', '');
183 } 180 }
184 document.body.appendChild(this.plugin_); 181 document.body.appendChild(this.plugin_);
185 182
186 // Setup the button event listeners. 183 // Setup the button event listeners.
187 this.zoomToolbar_ = $('zoom-toolbar'); 184 this.zoomToolbar_ = $('zoom-toolbar');
188 this.zoomToolbar_.addEventListener('fit-to-width', 185 this.zoomToolbar_.addEventListener(
189 this.viewport_.fitToWidth.bind(this.viewport_)); 186 'fit-to-width', this.viewport_.fitToWidth.bind(this.viewport_));
190 this.zoomToolbar_.addEventListener('fit-to-page', 187 this.zoomToolbar_.addEventListener('fit-to-page', this.fitToPage_.bind(this));
191 this.fitToPage_.bind(this)); 188 this.zoomToolbar_.addEventListener(
192 this.zoomToolbar_.addEventListener('zoom-in', 189 'zoom-in', this.viewport_.zoomIn.bind(this.viewport_));
193 this.viewport_.zoomIn.bind(this.viewport_)); 190 this.zoomToolbar_.addEventListener(
194 this.zoomToolbar_.addEventListener('zoom-out', 191 'zoom-out', this.viewport_.zoomOut.bind(this.viewport_));
195 this.viewport_.zoomOut.bind(this.viewport_));
196 192
197 this.gestureDetector_ = new GestureDetector(this.plugin_); 193 this.gestureDetector_ = new GestureDetector(this.plugin_);
198 this.gestureDetector_.addEventListener( 194 this.gestureDetector_.addEventListener(
199 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_)); 195 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_));
200 this.sentPinchEvent_ = false; 196 this.sentPinchEvent_ = false;
201 this.gestureDetector_.addEventListener( 197 this.gestureDetector_.addEventListener(
202 'pinchupdate', this.onPinchUpdate_.bind(this)); 198 'pinchupdate', this.onPinchUpdate_.bind(this));
203 this.gestureDetector_.addEventListener( 199 this.gestureDetector_.addEventListener(
204 'pinchend', this.onPinchEnd_.bind(this)); 200 'pinchend', this.onPinchEnd_.bind(this));
205 201
206 if (toolbarEnabled) { 202 if (toolbarEnabled) {
207 this.toolbar_ = $('toolbar'); 203 this.toolbar_ = $('toolbar');
208 this.toolbar_.hidden = false; 204 this.toolbar_.hidden = false;
209 this.toolbar_.addEventListener('save', this.save_.bind(this)); 205 this.toolbar_.addEventListener('save', this.save_.bind(this));
210 this.toolbar_.addEventListener('print', this.print_.bind(this)); 206 this.toolbar_.addEventListener('print', this.print_.bind(this));
211 this.toolbar_.addEventListener('rotate-right', 207 this.toolbar_.addEventListener(
212 this.rotateClockwise_.bind(this)); 208 'rotate-right', this.rotateClockwise_.bind(this));
213 // Must attach to mouseup on the plugin element, since it eats mousedown 209 // Must attach to mouseup on the plugin element, since it eats mousedown
214 // and click events. 210 // and click events.
215 this.plugin_.addEventListener('mouseup', 211 this.plugin_.addEventListener(
216 this.toolbar_.hideDropdowns.bind(this.toolbar_)); 212 'mouseup', this.toolbar_.hideDropdowns.bind(this.toolbar_));
217 213
218 this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_); 214 this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_);
219 } 215 }
220 216
221 document.body.addEventListener('change-page', function(e) { 217 document.body.addEventListener('change-page', function(e) {
222 this.viewport_.goToPage(e.detail.page); 218 this.viewport_.goToPage(e.detail.page);
223 }.bind(this)); 219 }.bind(this));
224 220
225 document.body.addEventListener('navigate', function(e) { 221 document.body.addEventListener('navigate', function(e) {
226 var disposition = 222 var disposition = e.detail.newtab ?
227 e.detail.newtab ? Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB : 223 Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB :
228 Navigator.WindowOpenDisposition.CURRENT_TAB; 224 Navigator.WindowOpenDisposition.CURRENT_TAB;
229 this.navigator_.navigate(e.detail.uri, disposition); 225 this.navigator_.navigate(e.detail.uri, disposition);
230 }.bind(this)); 226 }.bind(this));
231 227
232 this.toolbarManager_ = 228 this.toolbarManager_ =
233 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_); 229 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_);
234 230
235 // Set up the ZoomManager. 231 // Set up the ZoomManager.
236 this.zoomManager_ = ZoomManager.create( 232 this.zoomManager_ = ZoomManager.create(
237 this.browserApi_.getZoomBehavior(), this.viewport_, 233 this.browserApi_.getZoomBehavior(), this.viewport_,
238 this.browserApi_.setZoom.bind(this.browserApi_), 234 this.browserApi_.setZoom.bind(this.browserApi_),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 352 }
357 return; 353 return;
358 case 40: // Down arrow key. 354 case 40: // Down arrow key.
359 if (fromScriptingAPI) { 355 if (fromScriptingAPI) {
360 position.y += Viewport.SCROLL_INCREMENT; 356 position.y += Viewport.SCROLL_INCREMENT;
361 this.viewport.position = position; 357 this.viewport.position = position;
362 } 358 }
363 return; 359 return;
364 case 65: // 'a' key. 360 case 65: // 'a' key.
365 if (e.ctrlKey || e.metaKey) { 361 if (e.ctrlKey || e.metaKey) {
366 this.plugin_.postMessage({ 362 this.plugin_.postMessage({type: 'selectAll'});
367 type: 'selectAll'
368 });
369 // Since we do selection ourselves. 363 // Since we do selection ourselves.
370 e.preventDefault(); 364 e.preventDefault();
371 } 365 }
372 return; 366 return;
373 case 71: // 'g' key. 367 case 71: // 'g' key.
374 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { 368 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) {
375 this.toolbarManager_.showToolbars(); 369 this.toolbarManager_.showToolbars();
376 this.toolbar_.selectPageNumber(); 370 this.toolbar_.selectPageNumber();
377 } 371 }
378 return; 372 return;
379 case 219: // Left bracket key. 373 case 219: // Left bracket key.
380 if (e.ctrlKey) 374 if (e.ctrlKey)
381 this.rotateCounterClockwise_(); 375 this.rotateCounterClockwise_();
382 return; 376 return;
383 case 220: // Backslash key. 377 case 220: // Backslash key.
384 if (e.ctrlKey) 378 if (e.ctrlKey)
385 this.zoomToolbar_.fitToggleFromHotKey(); 379 this.zoomToolbar_.fitToggleFromHotKey();
386 return; 380 return;
387 case 221: // Right bracket key. 381 case 221: // Right bracket key.
388 if (e.ctrlKey) 382 if (e.ctrlKey)
389 this.rotateClockwise_(); 383 this.rotateClockwise_();
390 return; 384 return;
391 } 385 }
392 386
393 // Give print preview a chance to handle the key event. 387 // Give print preview a chance to handle the key event.
394 if (!fromScriptingAPI && this.isPrintPreview_) { 388 if (!fromScriptingAPI && this.isPrintPreview_) {
395 this.sendScriptingMessage_({ 389 this.sendScriptingMessage_(
396 type: 'sendKeyEvent', 390 {type: 'sendKeyEvent', keyEvent: SerializeKeyEvent(e)});
397 keyEvent: SerializeKeyEvent(e)
398 });
399 } else { 391 } else {
400 // Show toolbars as a fallback. 392 // Show toolbars as a fallback.
401 if (!(e.shiftKey || e.ctrlKey || e.altKey)) 393 if (!(e.shiftKey || e.ctrlKey || e.altKey))
402 this.toolbarManager_.showToolbars(); 394 this.toolbarManager_.showToolbars();
403 } 395 }
404 }, 396 },
405 397
406 handleMouseEvent_: function(e) { 398 handleMouseEvent_: function(e) {
407 if (e.type == 'mousemove') 399 if (e.type == 'mousemove')
408 this.toolbarManager_.handleMouseMove(e); 400 this.toolbarManager_.handleMouseMove(e);
409 else if (e.type == 'mouseout') 401 else if (e.type == 'mouseout')
410 this.toolbarManager_.hideToolbarsForMouseOut(); 402 this.toolbarManager_.hideToolbarsForMouseOut();
411 }, 403 },
412 404
413 /** 405 /**
414 * @private 406 * @private
415 * Rotate the plugin clockwise. 407 * Rotate the plugin clockwise.
416 */ 408 */
417 rotateClockwise_: function() { 409 rotateClockwise_: function() {
418 this.plugin_.postMessage({ 410 this.plugin_.postMessage({type: 'rotateClockwise'});
419 type: 'rotateClockwise'
420 });
421 }, 411 },
422 412
423 /** 413 /**
424 * @private 414 * @private
425 * Rotate the plugin counter-clockwise. 415 * Rotate the plugin counter-clockwise.
426 */ 416 */
427 rotateCounterClockwise_: function() { 417 rotateCounterClockwise_: function() {
428 this.plugin_.postMessage({ 418 this.plugin_.postMessage({type: 'rotateCounterclockwise'});
429 type: 'rotateCounterclockwise'
430 });
431 }, 419 },
432 420
433 /** 421 /**
434 * @private 422 * @private
435 * Set zoom to "fit to page". 423 * Set zoom to "fit to page".
436 */ 424 */
437 fitToPage_: function() { 425 fitToPage_: function() {
438 this.viewport_.fitToPage(); 426 this.viewport_.fitToPage();
439 this.toolbarManager_.forceHideTopToolbar(); 427 this.toolbarManager_.forceHideTopToolbar();
440 }, 428 },
441 429
442 /** 430 /**
443 * @private 431 * @private
444 * Notify the plugin to print. 432 * Notify the plugin to print.
445 */ 433 */
446 print_: function() { 434 print_: function() {
447 this.plugin_.postMessage({ 435 this.plugin_.postMessage({type: 'print'});
448 type: 'print'
449 });
450 }, 436 },
451 437
452 /** 438 /**
453 * @private 439 * @private
454 * Notify the plugin to save. 440 * Notify the plugin to save.
455 */ 441 */
456 save_: function() { 442 save_: function() {
457 this.plugin_.postMessage({ 443 this.plugin_.postMessage({type: 'save'});
458 type: 'save'
459 });
460 }, 444 },
461 445
462 /** 446 /**
463 * Fetches the page number corresponding to the given named destination from 447 * Fetches the page number corresponding to the given named destination from
464 * the plugin. 448 * the plugin.
465 * @param {string} name The namedDestination to fetch page number from plugin. 449 * @param {string} name The namedDestination to fetch page number from plugin.
466 */ 450 */
467 getNamedDestination_: function(name) { 451 getNamedDestination_: function(name) {
468 this.plugin_.postMessage({ 452 this.plugin_.postMessage(
469 type: 'getNamedDestination', 453 {type: 'getNamedDestination', namedDestination: name});
470 namedDestination: name
471 });
472 }, 454 },
473 455
474 /** 456 /**
475 * @private 457 * @private
476 * Sends a 'documentLoaded' message to the PDFScriptingAPI if the document has 458 * Sends a 'documentLoaded' message to the PDFScriptingAPI if the document has
477 * finished loading. 459 * finished loading.
478 */ 460 */
479 sendDocumentLoadedMessage_: function() { 461 sendDocumentLoadedMessage_: function() {
480 if (this.loadState_ == LoadState.LOADING) 462 if (this.loadState_ == LoadState.LOADING)
481 return; 463 return;
482 this.sendScriptingMessage_({ 464 this.sendScriptingMessage_(
483 type: 'documentLoaded', 465 {type: 'documentLoaded', load_state: this.loadState_});
484 load_state: this.loadState_
485 });
486 }, 466 },
487 467
488 /** 468 /**
489 * @private 469 * @private
490 * Handle open pdf parameters. This function updates the viewport as per 470 * Handle open pdf parameters. This function updates the viewport as per
491 * the parameters mentioned in the url while opening pdf. The order is 471 * the parameters mentioned in the url while opening pdf. The order is
492 * important as later actions can override the effects of previous actions. 472 * important as later actions can override the effects of previous actions.
493 * @param {Object} viewportPosition The initial position of the viewport to be 473 * @param {Object} viewportPosition The initial position of the viewport to be
494 * displayed. 474 * displayed.
495 */ 475 */
(...skipping 29 matching lines...) Expand all
525 this.passwordScreen_.deny(); 505 this.passwordScreen_.deny();
526 this.passwordScreen_.active = false; 506 this.passwordScreen_.active = false;
527 } 507 }
528 this.loadState_ = LoadState.FAILED; 508 this.loadState_ = LoadState.FAILED;
529 this.sendDocumentLoadedMessage_(); 509 this.sendDocumentLoadedMessage_();
530 } else if (progress == 100) { 510 } else if (progress == 100) {
531 // Document load complete. 511 // Document load complete.
532 if (this.lastViewportPosition_) 512 if (this.lastViewportPosition_)
533 this.viewport_.position = this.lastViewportPosition_; 513 this.viewport_.position = this.lastViewportPosition_;
534 this.paramsParser_.getViewportFromUrlParams( 514 this.paramsParser_.getViewportFromUrlParams(
535 this.originalUrl_, 515 this.originalUrl_, this.handleURLParams_.bind(this));
536 this.handleURLParams_.bind(this));
537 this.loadState_ = LoadState.SUCCESS; 516 this.loadState_ = LoadState.SUCCESS;
538 this.sendDocumentLoadedMessage_(); 517 this.sendDocumentLoadedMessage_();
539 while (this.delayedScriptingMessages_.length > 0) 518 while (this.delayedScriptingMessages_.length > 0)
540 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); 519 this.handleScriptingMessage(this.delayedScriptingMessages_.shift());
541 520
542 this.toolbarManager_.hideToolbarsAfterTimeout(); 521 this.toolbarManager_.hideToolbarsAfterTimeout();
543 } 522 }
544 }, 523 },
545 524
546 /** 525 /**
(...skipping 12 matching lines...) Expand all
559 $('error-screen').strings = strings; 538 $('error-screen').strings = strings;
560 }, 539 },
561 540
562 /** 541 /**
563 * @private 542 * @private
564 * An event handler for handling password-submitted events. These are fired 543 * An event handler for handling password-submitted events. These are fired
565 * when an event is entered into the password screen. 544 * when an event is entered into the password screen.
566 * @param {Object} event a password-submitted event. 545 * @param {Object} event a password-submitted event.
567 */ 546 */
568 onPasswordSubmitted_: function(event) { 547 onPasswordSubmitted_: function(event) {
569 this.plugin_.postMessage({ 548 this.plugin_.postMessage(
570 type: 'getPasswordComplete', 549 {type: 'getPasswordComplete', password: event.detail.password});
571 password: event.detail.password
572 });
573 }, 550 },
574 551
575 /** 552 /**
576 * @private 553 * @private
577 * An event handler for handling message events received from the plugin. 554 * An event handler for handling message events received from the plugin.
578 * @param {MessageObject} message a message event. 555 * @param {MessageObject} message a message event.
579 */ 556 */
580 handlePluginMessage_: function(message) { 557 handlePluginMessage_: function(message) {
581 switch (message.data.type.toString()) { 558 switch (message.data.type.toString()) {
582 case 'documentDimensions': 559 case 'documentDimensions':
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 break; 639 break;
663 } 640 }
664 }, 641 },
665 642
666 /** 643 /**
667 * @private 644 * @private
668 * A callback that's called before the zoom changes. Notify the plugin to stop 645 * A callback that's called before the zoom changes. Notify the plugin to stop
669 * reacting to scroll events while zoom is taking place to avoid flickering. 646 * reacting to scroll events while zoom is taking place to avoid flickering.
670 */ 647 */
671 beforeZoom_: function() { 648 beforeZoom_: function() {
672 this.plugin_.postMessage({ 649 this.plugin_.postMessage({type: 'stopScrolling'});
673 type: 'stopScrolling'
674 });
675 650
676 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { 651 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) {
677 var position = this.viewport_.position; 652 var position = this.viewport_.position;
678 var zoom = this.viewport_.zoom; 653 var zoom = this.viewport_.zoom;
679 var pinchPhase = this.viewport_.pinchPhase; 654 var pinchPhase = this.viewport_.pinchPhase;
680 this.plugin_.postMessage({ 655 this.plugin_.postMessage({
681 type: 'viewport', 656 type: 'viewport',
682 zoom: zoom, 657 zoom: zoom,
683 xOffset: position.x, 658 xOffset: position.x,
684 yOffset: position.y, 659 yOffset: position.y,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 var horizontalScrollbarWidth = 732 var horizontalScrollbarWidth =
758 hasScrollbars.horizontal ? scrollbarWidth : 0; 733 hasScrollbars.horizontal ? scrollbarWidth : 0;
759 734
760 // Shift the zoom toolbar to the left by half a scrollbar width. This 735 // Shift the zoom toolbar to the left by half a scrollbar width. This
761 // gives a compromise: if there is no scrollbar visible then the toolbar 736 // gives a compromise: if there is no scrollbar visible then the toolbar
762 // will be half a scrollbar width further left than the spec but if there 737 // will be half a scrollbar width further left than the spec but if there
763 // is a scrollbar visible it will be half a scrollbar width further right 738 // is a scrollbar visible it will be half a scrollbar width further right
764 // than the spec. In RTL layout, the zoom toolbar is on the left side, but 739 // than the spec. In RTL layout, the zoom toolbar is on the left side, but
765 // the scrollbar is still on the right, so this is not necessary. 740 // the scrollbar is still on the right, so this is not necessary.
766 if (!isRTL()) { 741 if (!isRTL()) {
767 this.zoomToolbar_.style.right = -verticalScrollbarWidth + 742 this.zoomToolbar_.style.right =
768 (scrollbarWidth / 2) + 'px'; 743 -verticalScrollbarWidth + (scrollbarWidth / 2) + 'px';
769 } 744 }
770 // Having a horizontal scrollbar is much rarer so we don't offset the 745 // Having a horizontal scrollbar is much rarer so we don't offset the
771 // toolbar from the bottom any more than what the spec says. This means 746 // toolbar from the bottom any more than what the spec says. This means
772 // that when there is a scrollbar visible, it will be a full scrollbar 747 // that when there is a scrollbar visible, it will be a full scrollbar
773 // width closer to the bottom of the screen than usual, but this is ok. 748 // width closer to the bottom of the screen than usual, but this is ok.
774 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px'; 749 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px';
775 750
776 // Update the page indicator. 751 // Update the page indicator.
777 var visiblePage = this.viewport_.getMostVisiblePage(); 752 var visiblePage = this.viewport_.getMostVisiblePage();
778 753
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 saveButton.parentNode.removeChild(saveButton); 845 saveButton.parentNode.removeChild(saveButton);
871 846
872 this.pageIndicator_.pageLabels = message.data.pageNumbers; 847 this.pageIndicator_.pageLabels = message.data.pageNumbers;
873 848
874 this.plugin_.postMessage({ 849 this.plugin_.postMessage({
875 type: 'resetPrintPreviewMode', 850 type: 'resetPrintPreviewMode',
876 url: message.data.url, 851 url: message.data.url,
877 grayscale: message.data.grayscale, 852 grayscale: message.data.grayscale,
878 // If the PDF isn't modifiable we send 0 as the page count so that no 853 // If the PDF isn't modifiable we send 0 as the page count so that no
879 // blank placeholder pages get appended to the PDF. 854 // blank placeholder pages get appended to the PDF.
880 pageCount: (message.data.modifiable ? 855 pageCount:
881 message.data.pageNumbers.length : 0) 856 (message.data.modifiable ? message.data.pageNumbers.length : 0)
882 }); 857 });
883 return true; 858 return true;
884 case 'sendKeyEvent': 859 case 'sendKeyEvent':
885 this.handleKeyEvent_(DeserializeKeyEvent(message.data.keyEvent)); 860 this.handleKeyEvent_(DeserializeKeyEvent(message.data.keyEvent));
886 return true; 861 return true;
887 } 862 }
888 863
889 return false; 864 return false;
890 }, 865 },
891 866
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 * Each bookmark is an Object containing a: 898 * Each bookmark is an Object containing a:
924 * - title 899 * - title
925 * - page (optional) 900 * - page (optional)
926 * - array of children (themselves bookmarks) 901 * - array of children (themselves bookmarks)
927 * @type {Array} the top-level bookmarks of the PDF. 902 * @type {Array} the top-level bookmarks of the PDF.
928 */ 903 */
929 get bookmarks() { 904 get bookmarks() {
930 return this.bookmarks_; 905 return this.bookmarks_;
931 } 906 }
932 }; 907 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | chrome/browser/resources/pdf/pdf_scripting_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698