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

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

Issue 923063002: Sample Patch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 zoomChangeInfo.newZoomFactor); 183 zoomChangeInfo.newZoomFactor);
184 // We should not change zoom level when we are responsible for initiating 184 // We should not change zoom level when we are responsible for initiating
185 // the zoom. onZoomChange() is called before setZoomComplete() callback 185 // the zoom. onZoomChange() is called before setZoomComplete() callback
186 // when we initiate the zoom. 186 // when we initiate the zoom.
187 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) 187 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
188 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 188 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
189 }.bind(this)); 189 }.bind(this));
190 } 190 }
191 191
192 // Parse open pdf parameters. 192 // Parse open pdf parameters.
193 this.paramsParser_ = new OpenPDFParamsParser(); 193 this.paramsParser_ =
194 new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
194 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, 195 this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
195 this.viewport_, this.paramsParser_, onNavigateInCurrentTab, 196 this.viewport_, this.paramsParser_, onNavigateInCurrentTab,
196 onNavigateInNewTab); 197 onNavigateInNewTab);
197 this.viewportScroller_ = 198 this.viewportScroller_ =
198 new ViewportScroller(this.viewport_, this.plugin_, window); 199 new ViewportScroller(this.viewport_, this.plugin_, window);
199 } 200 }
200 201
201 PDFViewer.prototype = { 202 PDFViewer.prototype = {
202 /** 203 /**
203 * @private 204 * @private
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 rotateCounterClockwise_: function() { 344 rotateCounterClockwise_: function() {
344 this.plugin_.postMessage({ 345 this.plugin_.postMessage({
345 type: 'rotateCounterclockwise' 346 type: 'rotateCounterclockwise'
346 }); 347 });
347 }, 348 },
348 349
349 /** 350 /**
350 * @private 351 * @private
351 * Notify the plugin to print. 352 * Notify the plugin to print.
352 */ 353 */
353 print_: function() { this.plugin_.postMessage({type: 'print'}); }, 354 print_: function() {
355 this.plugin_.postMessage({
356 type: 'print'});
357 },
354 358
355 /** 359 /**
356 * @private 360 * @private
357 * Notify the plugin to save. 361 * Notify the plugin to save.
358 */ 362 */
359 save_: function() { this.plugin_.postMessage({type: 'save'}); }, 363 save_: function() {
364 this.plugin_.postMessage({
365 type: 'save'});
366 },
367
368 /**
369 * Callback to fetch namedDestination from plugin.
370 */
371 getNamedDestination_: function(name) {
372 this.plugin_.postMessage({
373 type: 'getNamedDestination',
374 namedDestination: name
375 });
376 },
360 377
361 /** 378 /**
362 * @private 379 * @private
363 * Handle open pdf parameters. This function updates the viewport as per 380 * Handle open pdf parameters. This function updates the viewport as per
364 * the parameters mentioned in the url while opening pdf. The order is 381 * the parameters mentioned in the url while opening pdf. The order is
365 * important as later actions can override the effects of previous actions. 382 * important as later actions can override the effects of previous actions.
366 */ 383 */
367 handleURLParams_: function() { 384 handleURLParams_: function() {
368 var urlParams = 385 this.parmsParser_.getViewportFromUrlParams(
369 this.paramsParser_.getViewportFromUrlParams( 386 this.streamDetails_.originalUrl, function(initialViewport) {
370 this.streamDetails_.originalUrl); 387 if (initialViewport.page != undefined)
371 if (urlParams.page) 388 this.viewport_.goToPage(initialViewport.page);
372 this.viewport_.goToPage(urlParams.page); 389 if (initialViewport.position) {
373 if (urlParams.position) { 390 // Make sure we don't cancel effect of page parameter.
374 // Make sure we don't cancel effect of page parameter. 391 this.viewport_.position = {
375 this.viewport_.position = { 392 x: this.viewport_.position.x + initialViewport.position.x,
376 x: this.viewport_.position.x + urlParams.position.x, 393 y: this.viewport_.position.y + initialViewport.position.y
377 y: this.viewport_.position.y + urlParams.position.y 394 };
378 }; 395 }
379 } 396 if (initialViewport.zoom)
380 if (urlParams.zoom) 397 this.viewport_.setZoom(initialViewport.zoom);
381 this.viewport_.setZoom(urlParams.zoom); 398 }.bind(this));
382 }, 399 },
383 400
384 /** 401 /**
385 * @private 402 * @private
386 * Update the loading progress of the document in response to a progress 403 * Update the loading progress of the document in response to a progress
387 * message being received from the plugin. 404 * message being received from the plugin.
388 * @param {number} progress the progress as a percentage. 405 * @param {number} progress the progress as a percentage.
389 */ 406 */
390 updateProgress_: function(progress) { 407 updateProgress_: function(progress) {
391 if (this.isMaterial_) 408 if (this.isMaterial_)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 case 'loadProgress': 496 case 'loadProgress':
480 this.updateProgress_(message.data.progress); 497 this.updateProgress_(message.data.progress);
481 break; 498 break;
482 case 'navigate': 499 case 'navigate':
483 // If in print preview, always open a new tab. 500 // If in print preview, always open a new tab.
484 if (this.isPrintPreview_) 501 if (this.isPrintPreview_)
485 this.navigator_.navigate(message.data.url, true); 502 this.navigator_.navigate(message.data.url, true);
486 else 503 else
487 this.navigator_.navigate(message.data.url, message.data.newTab); 504 this.navigator_.navigate(message.data.url, message.data.newTab);
488 break; 505 break;
489 case 'setNamedDestinations':
490 this.paramsParser_.namedDestinations = message.data.namedDestinations;
491 break;
492 case 'setScrollPosition': 506 case 'setScrollPosition':
493 var position = this.viewport_.position; 507 var position = this.viewport_.position;
494 if (message.data.x !== undefined) 508 if (message.data.x !== undefined)
495 position.x = message.data.x; 509 position.x = message.data.x;
496 if (message.data.y !== undefined) 510 if (message.data.y !== undefined)
497 position.y = message.data.y; 511 position.y = message.data.y;
498 this.viewport_.position = position; 512 this.viewport_.position = position;
499 break; 513 break;
500 case 'setTranslatedStrings': 514 case 'setTranslatedStrings':
501 this.passwordScreen_.text = message.data.getPasswordString; 515 this.passwordScreen_.text = message.data.getPasswordString;
(...skipping 10 matching lines...) Expand all
512 case 'bookmarks': 526 case 'bookmarks':
513 this.bookmarks_ = message.data.bookmarks; 527 this.bookmarks_ = message.data.bookmarks;
514 if (this.isMaterial_ && this.bookmarks_.length !== 0) { 528 if (this.isMaterial_ && this.bookmarks_.length !== 0) {
515 $('bookmarks-container').bookmarks = this.bookmarks; 529 $('bookmarks-container').bookmarks = this.bookmarks;
516 this.materialToolbar_.hasBookmarks = true; 530 this.materialToolbar_.hasBookmarks = true;
517 } 531 }
518 break; 532 break;
519 case 'setIsSelecting': 533 case 'setIsSelecting':
520 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); 534 this.viewportScroller_.setEnableScrolling(message.data.isSelecting);
521 break; 535 break;
536 case 'getNamedDestinationReply':
537 this.paramsParser_.onNamedDestinationReceived(
538 message.data.namedDestinationPageNumber);
539 break;
522 } 540 }
523 }, 541 },
524 542
525 /** 543 /**
526 * @private 544 * @private
527 * A callback that's called before the zoom changes. Notify the plugin to stop 545 * A callback that's called before the zoom changes. Notify the plugin to stop
528 * reacting to scroll events while zoom is taking place to avoid flickering. 546 * reacting to scroll events while zoom is taking place to avoid flickering.
529 */ 547 */
530 beforeZoom_: function() { 548 beforeZoom_: function() {
531 this.plugin_.postMessage({ 549 this.plugin_.postMessage({
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 * Each bookmark is an Object containing a: 776 * Each bookmark is an Object containing a:
759 * - title 777 * - title
760 * - page (optional) 778 * - page (optional)
761 * - array of children (themselves bookmarks) 779 * - array of children (themselves bookmarks)
762 * @type {Array} the top-level bookmarks of the PDF. 780 * @type {Array} the top-level bookmarks of the PDF.
763 */ 781 */
764 get bookmarks() { 782 get bookmarks() {
765 return this.bookmarks_; 783 return this.bookmarks_;
766 } 784 }
767 }; 785 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698