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

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

Issue 2503633002: Propagate browser zoom changes to embedded PDFs. (Closed)
Patch Set: Use American spelling of behaviour. Created 4 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
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | chrome/browser/resources/pdf/zoom_manager.js » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 5 /**
6 * Returns the height of the intersection of two rectangles. 6 * Returns the height of the intersection of two rectangles.
7 * @param {Object} rect1 the first rect 7 * @param {Object} rect1 the first rect
8 * @param {Object} rect2 the second rect 8 * @param {Object} rect2 the second rect
9 * @return {number} the height of the intersection of the rects 9 * @return {number} the height of the intersection of the rects
10 */ 10 */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 afterZoomCallback, 65 afterZoomCallback,
66 scrollbarWidth, 66 scrollbarWidth,
67 defaultZoom, 67 defaultZoom,
68 topToolbarHeight) { 68 topToolbarHeight) {
69 this.window_ = window; 69 this.window_ = window;
70 this.sizer_ = sizer; 70 this.sizer_ = sizer;
71 this.viewportChangedCallback_ = viewportChangedCallback; 71 this.viewportChangedCallback_ = viewportChangedCallback;
72 this.beforeZoomCallback_ = beforeZoomCallback; 72 this.beforeZoomCallback_ = beforeZoomCallback;
73 this.afterZoomCallback_ = afterZoomCallback; 73 this.afterZoomCallback_ = afterZoomCallback;
74 this.allowedToChangeZoom_ = false; 74 this.allowedToChangeZoom_ = false;
75 this.zoom_ = 1; 75 this.internalZoom_ = 1;
76 this.zoomManager_ = new InactiveZoomManager(this, 1);
76 this.documentDimensions_ = null; 77 this.documentDimensions_ = null;
77 this.pageDimensions_ = []; 78 this.pageDimensions_ = [];
78 this.scrollbarWidth_ = scrollbarWidth; 79 this.scrollbarWidth_ = scrollbarWidth;
79 this.fittingType_ = Viewport.FittingType.NONE; 80 this.fittingType_ = Viewport.FittingType.NONE;
80 this.defaultZoom_ = defaultZoom; 81 this.defaultZoom_ = defaultZoom;
81 this.topToolbarHeight_ = topToolbarHeight; 82 this.topToolbarHeight_ = topToolbarHeight;
82 this.prevScale_ = 1; 83 this.prevScale_ = 1;
83 this.pinchPhase_ = Viewport.PinchPhase.PINCH_NONE; 84 this.pinchPhase_ = Viewport.PinchPhase.PINCH_NONE;
84 this.pinchPanVector_ = null; 85 this.pinchPanVector_ = null;
85 this.pinchCenter_ = null; 86 this.pinchCenter_ = null;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 }; 193 };
193 }, 194 },
194 195
195 /** 196 /**
196 * Returns true if the document needs scrollbars at the current zoom level. 197 * Returns true if the document needs scrollbars at the current zoom level.
197 * @return {Object} with 'x' and 'y' keys which map to bool values 198 * @return {Object} with 'x' and 'y' keys which map to bool values
198 * indicating if the horizontal and vertical scrollbars are needed 199 * indicating if the horizontal and vertical scrollbars are needed
199 * respectively. 200 * respectively.
200 */ 201 */
201 documentHasScrollbars: function() { 202 documentHasScrollbars: function() {
202 return this.documentNeedsScrollbars_(this.zoom_); 203 return this.documentNeedsScrollbars_(this.zoom);
203 }, 204 },
204 205
205 /** 206 /**
206 * @private 207 * @private
207 * Helper function called when the zoomed document size changes. 208 * Helper function called when the zoomed document size changes.
208 */ 209 */
209 contentSizeChanged_: function() { 210 contentSizeChanged_: function() {
210 var zoomedDimensions = this.getZoomedDocumentDimensions_(this.zoom_); 211 var zoomedDimensions = this.getZoomedDocumentDimensions_(this.zoom);
211 if (zoomedDimensions) { 212 if (zoomedDimensions) {
212 this.sizer_.style.width = zoomedDimensions.width + 'px'; 213 this.sizer_.style.width = zoomedDimensions.width + 'px';
213 this.sizer_.style.height = zoomedDimensions.height + 214 this.sizer_.style.height = zoomedDimensions.height +
214 this.topToolbarHeight_ + 'px'; 215 this.topToolbarHeight_ + 'px';
215 } 216 }
216 }, 217 },
217 218
218 /** 219 /**
219 * @private 220 * @private
220 * Called when the viewport should be updated. 221 * Called when the viewport should be updated.
(...skipping 30 matching lines...) Expand all
251 * @type {Object} position the position to scroll to. 252 * @type {Object} position the position to scroll to.
252 */ 253 */
253 set position(position) { 254 set position(position) {
254 this.window_.scrollTo(position.x, position.y + this.topToolbarHeight_); 255 this.window_.scrollTo(position.x, position.y + this.topToolbarHeight_);
255 }, 256 },
256 257
257 /** 258 /**
258 * @type {Object} the size of the viewport excluding scrollbars. 259 * @type {Object} the size of the viewport excluding scrollbars.
259 */ 260 */
260 get size() { 261 get size() {
261 var needsScrollbars = this.documentNeedsScrollbars_(this.zoom_); 262 var needsScrollbars = this.documentNeedsScrollbars_(this.zoom);
262 var scrollbarWidth = needsScrollbars.vertical ? this.scrollbarWidth_ : 0; 263 var scrollbarWidth = needsScrollbars.vertical ? this.scrollbarWidth_ : 0;
263 var scrollbarHeight = needsScrollbars.horizontal ? this.scrollbarWidth_ : 0; 264 var scrollbarHeight = needsScrollbars.horizontal ? this.scrollbarWidth_ : 0;
264 return { 265 return {
265 width: this.window_.innerWidth - scrollbarWidth, 266 width: this.window_.innerWidth - scrollbarWidth,
266 height: this.window_.innerHeight - scrollbarHeight 267 height: this.window_.innerHeight - scrollbarHeight
267 }; 268 };
268 }, 269 },
269 270
270 /** 271 /**
271 * @type {number} the zoom level of the viewport. 272 * @type {number} the zoom level of the viewport.
272 */ 273 */
273 get zoom() { 274 get zoom() {
274 return this.zoom_; 275 return this.zoomManager_.applyBrowserZoom(this.internalZoom_);
275 }, 276 },
276 277
277 /** 278 /**
279 * Set the zoom manager.
280 * @type {ZoomManager} manager the zoom manager to set.
281 */
282 set zoomManager(manager) {
283 this.zoomManager_ = manager;
284 },
285
286 /**
278 * @type {Viewport.PinchPhase} The phase of the current pinch gesture for 287 * @type {Viewport.PinchPhase} The phase of the current pinch gesture for
279 * the viewport. 288 * the viewport.
280 */ 289 */
281 get pinchPhase() { 290 get pinchPhase() {
282 return this.pinchPhase_; 291 return this.pinchPhase_;
283 }, 292 },
284 293
285 /** 294 /**
286 * @type {Object} The panning caused by the current pinch gesture (as 295 * @type {Object} The panning caused by the current pinch gesture (as
287 * the deltas of the x and y coordinates). 296 * the deltas of the x and y coordinates).
(...skipping 29 matching lines...) Expand all
317 * Sets the zoom of the viewport. 326 * Sets the zoom of the viewport.
318 * @param {number} newZoom the zoom level to zoom to. 327 * @param {number} newZoom the zoom level to zoom to.
319 */ 328 */
320 setZoomInternal_: function(newZoom) { 329 setZoomInternal_: function(newZoom) {
321 if (!this.allowedToChangeZoom_) { 330 if (!this.allowedToChangeZoom_) {
322 throw 'Called Viewport.setZoomInternal_ without calling ' + 331 throw 'Called Viewport.setZoomInternal_ without calling ' +
323 'Viewport.mightZoom_.'; 332 'Viewport.mightZoom_.';
324 } 333 }
325 // Record the scroll position (relative to the top-left of the window). 334 // Record the scroll position (relative to the top-left of the window).
326 var currentScrollPos = { 335 var currentScrollPos = {
327 x: this.position.x / this.zoom_, 336 x: this.position.x / this.zoom,
328 y: this.position.y / this.zoom_ 337 y: this.position.y / this.zoom
329 }; 338 };
330 this.zoom_ = newZoom; 339 this.internalZoom_ = newZoom;
331 this.contentSizeChanged_(); 340 this.contentSizeChanged_();
332 // Scroll to the scaled scroll position. 341 // Scroll to the scaled scroll position.
333 this.position = { 342 this.position = {
334 x: currentScrollPos.x * newZoom, 343 x: currentScrollPos.x * this.zoom,
335 y: currentScrollPos.y * newZoom 344 y: currentScrollPos.y * this.zoom
336 }; 345 };
337 }, 346 },
338 347
339 /** 348 /**
340 * @private 349 * @private
341 * Sets the zoom of the viewport. 350 * Sets the zoom of the viewport.
342 * Same as setZoomInternal_ but for pinch zoom we have some more operations. 351 * Same as setZoomInternal_ but for pinch zoom we have some more operations.
343 * @param {number} scaleDelta The zoom delta. 352 * @param {number} scaleDelta The zoom delta.
344 * @param {!Object} center The pinch center in content coordinates. 353 * @param {!Object} center The pinch center in content coordinates.
345 */ 354 */
346 setPinchZoomInternal_: function(scaleDelta, center) { 355 setPinchZoomInternal_: function(scaleDelta, center) {
347 assert(this.allowedToChangeZoom_, 356 assert(this.allowedToChangeZoom_,
348 'Called Viewport.setPinchZoomInternal_ without calling ' + 357 'Called Viewport.setPinchZoomInternal_ without calling ' +
349 'Viewport.mightZoom_.'); 358 'Viewport.mightZoom_.');
350 this.zoom_ = clampScale(this.zoom_ * scaleDelta); 359 this.internalZoom_ = clampScale(this.internalZoom_ * scaleDelta);
351 360
352 var newCenterInContent = this.frameToContent(center); 361 var newCenterInContent = this.frameToContent(center);
353 var delta = { 362 var delta = {
354 x: (newCenterInContent.x - this.oldCenterInContent.x), 363 x: (newCenterInContent.x - this.oldCenterInContent.x),
355 y: (newCenterInContent.y - this.oldCenterInContent.y) 364 y: (newCenterInContent.y - this.oldCenterInContent.y)
356 }; 365 };
357 366
358 // Record the scroll position (relative to the pinch center). 367 // Record the scroll position (relative to the pinch center).
359 var currentScrollPos = { 368 var currentScrollPos = {
360 x: this.position.x - delta.x * this.zoom_, 369 x: this.position.x - delta.x * this.zoom,
361 y: this.position.y - delta.y * this.zoom_ 370 y: this.position.y - delta.y * this.zoom
362 }; 371 };
363 372
364 this.contentSizeChanged_(); 373 this.contentSizeChanged_();
365 // Scroll to the scaled scroll position. 374 // Scroll to the scaled scroll position.
366 this.position = { 375 this.position = {
367 x: currentScrollPos.x, 376 x: currentScrollPos.x,
368 y: currentScrollPos.y 377 y: currentScrollPos.y
369 }; 378 };
370 }, 379 },
371 380
372 /** 381 /**
373 * @private 382 * @private
374 * Converts a point from frame to content coordinates. 383 * Converts a point from frame to content coordinates.
375 * @param {!Object} framePoint The frame coordinates. 384 * @param {!Object} framePoint The frame coordinates.
376 * @return {!Object} The content coordinates. 385 * @return {!Object} The content coordinates.
377 */ 386 */
378 frameToContent: function(framePoint) { 387 frameToContent: function(framePoint) {
379 // TODO(mcnee) Add a helper Point class to avoid duplicating operations 388 // TODO(mcnee) Add a helper Point class to avoid duplicating operations
380 // on plain {x,y} objects. 389 // on plain {x,y} objects.
381 return { 390 return {
382 x: (framePoint.x + this.position.x) / this.zoom_, 391 x: (framePoint.x + this.position.x) / this.zoom,
383 y: (framePoint.y + this.position.y) / this.zoom_ 392 y: (framePoint.y + this.position.y) / this.zoom
384 }; 393 };
385 }, 394 },
386 395
387 /** 396 /**
388 * Sets the zoom to the given zoom level. 397 * Sets the zoom to the given zoom level.
389 * @param {number} newZoom the zoom level to zoom to. 398 * @param {number} newZoom the zoom level to zoom to.
390 */ 399 */
391 setZoom: function(newZoom) { 400 setZoom: function(newZoom) {
392 this.fittingType_ = Viewport.FittingType.NONE; 401 this.fittingType_ = Viewport.FittingType.NONE;
393 newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min, 402 newZoom = Math.max(Viewport.ZOOM_FACTOR_RANGE.min,
394 Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max)); 403 Math.min(newZoom, Viewport.ZOOM_FACTOR_RANGE.max));
395 this.mightZoom_(function() { 404 this.mightZoom_(function() {
396 this.setZoomInternal_(newZoom); 405 this.setZoomInternal_(newZoom);
397 this.updateViewport_(); 406 this.updateViewport_();
398 }.bind(this)); 407 }.bind(this));
399 }, 408 },
400 409
401 /** 410 /**
411 * Gets notified of the browser zoom changing seperately from the
412 * internal zoom.
413 * @param {number} oldBrowserZoom the previous value of the browser zoom.
414 */
415 updateZoomFromBrowserChange: function(oldBrowserZoom) {
416 this.mightZoom_(function() {
417 // Record the scroll position (relative to the top-left of the window).
418 var oldZoom = oldBrowserZoom * this.internalZoom_;
419 var currentScrollPos = {
420 x: this.position.x / oldZoom,
421 y: this.position.y / oldZoom
422 };
423 this.contentSizeChanged_();
424 // Scroll to the scaled scroll position.
425 this.position = {
426 x: currentScrollPos.x * this.zoom,
427 y: currentScrollPos.y * this.zoom
428 };
429 this.updateViewport_();
430 }.bind(this));
431 },
432
433 /**
402 * @type {number} the width of scrollbars in the viewport in pixels. 434 * @type {number} the width of scrollbars in the viewport in pixels.
403 */ 435 */
404 get scrollbarWidth() { 436 get scrollbarWidth() {
405 return this.scrollbarWidth_; 437 return this.scrollbarWidth_;
406 }, 438 },
407 439
408 /** 440 /**
409 * @type {Viewport.FittingType} the fitting type the viewport is currently in. 441 * @type {Viewport.FittingType} the fitting type the viewport is currently in.
410 */ 442 */
411 get fittingType() { 443 get fittingType() {
(...skipping 29 matching lines...) Expand all
441 } 473 }
442 return 0; 474 return 0;
443 }, 475 },
444 476
445 /** 477 /**
446 * Returns the page with the greatest proportion of its height in the current 478 * Returns the page with the greatest proportion of its height in the current
447 * viewport. 479 * viewport.
448 * @return {int} the index of the most visible page. 480 * @return {int} the index of the most visible page.
449 */ 481 */
450 getMostVisiblePage: function() { 482 getMostVisiblePage: function() {
451 var firstVisiblePage = this.getPageAtY_(this.position.y / this.zoom_); 483 var firstVisiblePage = this.getPageAtY_(this.position.y / this.zoom);
452 if (firstVisiblePage == this.pageDimensions_.length - 1) 484 if (firstVisiblePage == this.pageDimensions_.length - 1)
453 return firstVisiblePage; 485 return firstVisiblePage;
454 486
455 var viewportRect = { 487 var viewportRect = {
456 x: this.position.x / this.zoom_, 488 x: this.position.x / this.zoom,
457 y: this.position.y / this.zoom_, 489 y: this.position.y / this.zoom,
458 width: this.size.width / this.zoom_, 490 width: this.size.width / this.zoom,
459 height: this.size.height / this.zoom_ 491 height: this.size.height / this.zoom
460 }; 492 };
461 var firstVisiblePageVisibility = getIntersectionHeight( 493 var firstVisiblePageVisibility = getIntersectionHeight(
462 this.pageDimensions_[firstVisiblePage], viewportRect) / 494 this.pageDimensions_[firstVisiblePage], viewportRect) /
463 this.pageDimensions_[firstVisiblePage].height; 495 this.pageDimensions_[firstVisiblePage].height;
464 var nextPageVisibility = getIntersectionHeight( 496 var nextPageVisibility = getIntersectionHeight(
465 this.pageDimensions_[firstVisiblePage + 1], viewportRect) / 497 this.pageDimensions_[firstVisiblePage + 1], viewportRect) /
466 this.pageDimensions_[firstVisiblePage + 1].height; 498 this.pageDimensions_[firstVisiblePage + 1].height;
467 if (nextPageVisibility > firstVisiblePageVisibility) 499 if (nextPageVisibility > firstVisiblePageVisibility)
468 return firstVisiblePage + 1; 500 return firstVisiblePage + 1;
469 return firstVisiblePage; 501 return firstVisiblePage;
470 }, 502 },
471 503
472 /** 504 /**
473 * @private 505 * @private
474 * Compute the zoom level for fit-to-page or fit-to-width. |pageDimensions| is 506 * Compute the zoom level for fit-to-page or fit-to-width. |pageDimensions| is
475 * the dimensions for a given page and if |widthOnly| is true, it indicates 507 * the dimensions for a given page and if |widthOnly| is true, it indicates
476 * that fit-to-page zoom should be computed rather than fit-to-page. 508 * that fit-to-page zoom should be computed rather than fit-to-page.
477 * @param {Object} pageDimensions the dimensions of a given page 509 * @param {Object} pageDimensions the dimensions of a given page
478 * @param {boolean} widthOnly a bool indicating whether fit-to-page or 510 * @param {boolean} widthOnly a bool indicating whether fit-to-page or
479 * fit-to-width should be computed. 511 * fit-to-width should be computed.
480 * @return {number} the zoom to use 512 * @return {number} the internal zoom to set
481 */ 513 */
482 computeFittingZoom_: function(pageDimensions, widthOnly) { 514 computeFittingZoom_: function(pageDimensions, widthOnly) {
483 // First compute the zoom without scrollbars. 515 // First compute the zoom without scrollbars.
484 var zoomWidth = this.window_.innerWidth / pageDimensions.width; 516 var zoomWidth = this.window_.innerWidth / pageDimensions.width;
485 var zoom; 517 var zoom;
486 var zoomHeight; 518 var zoomHeight;
487 if (widthOnly) { 519 if (widthOnly) {
488 zoom = zoomWidth; 520 zoom = zoomWidth;
489 } else { 521 } else {
490 zoomHeight = this.window_.innerHeight / pageDimensions.height; 522 zoomHeight = this.window_.innerHeight / pageDimensions.height;
(...skipping 30 matching lines...) Expand all
521 windowWithScrollbars.width -= scrollbarWidth; 553 windowWithScrollbars.width -= scrollbarWidth;
522 554
523 // Recompute the zoom. 555 // Recompute the zoom.
524 zoomWidth = windowWithScrollbars.width / pageDimensions.width; 556 zoomWidth = windowWithScrollbars.width / pageDimensions.width;
525 if (widthOnly) { 557 if (widthOnly) {
526 zoom = zoomWidth; 558 zoom = zoomWidth;
527 } else { 559 } else {
528 zoomHeight = windowWithScrollbars.height / pageDimensions.height; 560 zoomHeight = windowWithScrollbars.height / pageDimensions.height;
529 zoom = Math.min(zoomWidth, zoomHeight); 561 zoom = Math.min(zoomWidth, zoomHeight);
530 } 562 }
531 return zoom; 563 return this.zoomManager_.internalZoomComponent(zoom);
532 }, 564 },
533 565
534 /** 566 /**
535 * Zoom the viewport so that the page-width consumes the entire viewport. 567 * Zoom the viewport so that the page-width consumes the entire viewport.
536 */ 568 */
537 fitToWidth: function() { 569 fitToWidth: function() {
538 this.mightZoom_(function() { 570 this.mightZoom_(function() {
539 this.fittingType_ = Viewport.FittingType.FIT_TO_WIDTH; 571 this.fittingType_ = Viewport.FittingType.FIT_TO_WIDTH;
540 if (!this.documentDimensions_) 572 if (!this.documentDimensions_)
541 return; 573 return;
(...skipping 21 matching lines...) Expand all
563 var page = this.getMostVisiblePage(); 595 var page = this.getMostVisiblePage();
564 // Fit to the current page's height and the widest page's width. 596 // Fit to the current page's height and the widest page's width.
565 var dimensions = { 597 var dimensions = {
566 width: this.documentDimensions_.width, 598 width: this.documentDimensions_.width,
567 height: this.pageDimensions_[page].height, 599 height: this.pageDimensions_[page].height,
568 }; 600 };
569 this.setZoomInternal_(this.computeFittingZoom_(dimensions, false)); 601 this.setZoomInternal_(this.computeFittingZoom_(dimensions, false));
570 if (scrollToTopOfPage) { 602 if (scrollToTopOfPage) {
571 this.position = { 603 this.position = {
572 x: 0, 604 x: 0,
573 y: this.pageDimensions_[page].y * this.zoom_ 605 y: this.pageDimensions_[page].y * this.zoom
574 }; 606 };
575 } 607 }
576 this.updateViewport_(); 608 this.updateViewport_();
577 }.bind(this)); 609 }.bind(this));
578 }, 610 },
579 611
580 /** 612 /**
581 * Zoom the viewport so that a page consumes the entire viewport. Also scrolls 613 * Zoom the viewport so that a page consumes the entire viewport. Also scrolls
582 * the viewport to the top of the current page. 614 * the viewport to the top of the current page.
583 */ 615 */
584 fitToPage: function() { 616 fitToPage: function() {
585 this.fitToPageInternal_(true); 617 this.fitToPageInternal_(true);
586 }, 618 },
587 619
588 /** 620 /**
589 * Zoom out to the next predefined zoom level. 621 * Zoom out to the next predefined zoom level.
590 */ 622 */
591 zoomOut: function() { 623 zoomOut: function() {
592 this.mightZoom_(function() { 624 this.mightZoom_(function() {
593 this.fittingType_ = Viewport.FittingType.NONE; 625 this.fittingType_ = Viewport.FittingType.NONE;
594 var nextZoom = Viewport.ZOOM_FACTORS[0]; 626 var nextZoom = Viewport.ZOOM_FACTORS[0];
595 for (var i = 0; i < Viewport.ZOOM_FACTORS.length; i++) { 627 for (var i = 0; i < Viewport.ZOOM_FACTORS.length; i++) {
596 if (Viewport.ZOOM_FACTORS[i] < this.zoom_) 628 if (Viewport.ZOOM_FACTORS[i] < this.internalZoom_)
597 nextZoom = Viewport.ZOOM_FACTORS[i]; 629 nextZoom = Viewport.ZOOM_FACTORS[i];
598 } 630 }
599 this.setZoomInternal_(nextZoom); 631 this.setZoomInternal_(nextZoom);
600 this.updateViewport_(); 632 this.updateViewport_();
601 }.bind(this)); 633 }.bind(this));
602 }, 634 },
603 635
604 /** 636 /**
605 * Zoom in to the next predefined zoom level. 637 * Zoom in to the next predefined zoom level.
606 */ 638 */
607 zoomIn: function() { 639 zoomIn: function() {
608 this.mightZoom_(function() { 640 this.mightZoom_(function() {
609 this.fittingType_ = Viewport.FittingType.NONE; 641 this.fittingType_ = Viewport.FittingType.NONE;
610 var nextZoom = Viewport.ZOOM_FACTORS[Viewport.ZOOM_FACTORS.length - 1]; 642 var nextZoom = Viewport.ZOOM_FACTORS[Viewport.ZOOM_FACTORS.length - 1];
611 for (var i = Viewport.ZOOM_FACTORS.length - 1; i >= 0; i--) { 643 for (var i = Viewport.ZOOM_FACTORS.length - 1; i >= 0; i--) {
612 if (Viewport.ZOOM_FACTORS[i] > this.zoom_) 644 if (Viewport.ZOOM_FACTORS[i] > this.internalZoom_)
613 nextZoom = Viewport.ZOOM_FACTORS[i]; 645 nextZoom = Viewport.ZOOM_FACTORS[i];
614 } 646 }
615 this.setZoomInternal_(nextZoom); 647 this.setZoomInternal_(nextZoom);
616 this.updateViewport_(); 648 this.updateViewport_();
617 }.bind(this)); 649 }.bind(this));
618 }, 650 },
619 651
620 /** 652 /**
621 * Pinch zoom event handler. 653 * Pinch zoom event handler.
622 * @param {!Object} e The pinch event. 654 * @param {!Object} e The pinch event.
623 */ 655 */
624 pinchZoom: function(e) { 656 pinchZoom: function(e) {
625 this.mightZoom_(function() { 657 this.mightZoom_(function() {
626 this.pinchPhase_ = e.direction == 'out' ? 658 this.pinchPhase_ = e.direction == 'out' ?
627 Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT : 659 Viewport.PinchPhase.PINCH_UPDATE_ZOOM_OUT :
628 Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN; 660 Viewport.PinchPhase.PINCH_UPDATE_ZOOM_IN;
629 661
630 var scaleDelta = e.startScaleRatio / this.prevScale_; 662 var scaleDelta = e.startScaleRatio / this.prevScale_;
631 this.pinchPanVector_ = 663 this.pinchPanVector_ =
632 vectorDelta(e.center, this.firstPinchCenterInFrame_); 664 vectorDelta(e.center, this.firstPinchCenterInFrame_);
633 665
634 var needsScrollbars = this.documentNeedsScrollbars_( 666 var needsScrollbars = this.documentNeedsScrollbars_(
635 clampScale(this.zoom_ * scaleDelta)); 667 this.zoomManager_.applyBrowserZoom(
668 clampScale(this.internalZoom_ * scaleDelta)));
636 669
637 this.pinchCenter_ = e.center; 670 this.pinchCenter_ = e.center;
638 671
639 // If there's no horizontal scrolling, keep the content centered so the 672 // If there's no horizontal scrolling, keep the content centered so the
640 // user can't zoom in on the non-content area. 673 // user can't zoom in on the non-content area.
641 // TODO(mcnee) Investigate other ways of scaling when we don't have 674 // TODO(mcnee) Investigate other ways of scaling when we don't have
642 // horizontal scrolling. We want to keep the document centered, 675 // horizontal scrolling. We want to keep the document centered,
643 // but this causes a potentially awkward transition when we start 676 // but this causes a potentially awkward transition when we start
644 // using the gesture center. 677 // using the gesture center.
645 if (!needsScrollbars.horizontal) { 678 if (!needsScrollbars.horizontal) {
(...skipping 13 matching lines...) Expand all
659 this.prevScale_ = e.startScaleRatio; 692 this.prevScale_ = e.startScaleRatio;
660 }.bind(this)); 693 }.bind(this));
661 }, 694 },
662 695
663 pinchZoomStart: function(e) { 696 pinchZoomStart: function(e) {
664 this.pinchPhase_ = Viewport.PinchPhase.PINCH_START; 697 this.pinchPhase_ = Viewport.PinchPhase.PINCH_START;
665 this.prevScale_ = 1; 698 this.prevScale_ = 1;
666 this.oldCenterInContent = 699 this.oldCenterInContent =
667 this.frameToContent(frameToPluginCoordinate(e.center)); 700 this.frameToContent(frameToPluginCoordinate(e.center));
668 701
669 var needsScrollbars = this.documentNeedsScrollbars_(this.zoom_); 702 var needsScrollbars = this.documentNeedsScrollbars_(this.zoom);
670 this.keepContentCentered_ = !needsScrollbars.horizontal; 703 this.keepContentCentered_ = !needsScrollbars.horizontal;
671 // We keep track of begining of the pinch. 704 // We keep track of begining of the pinch.
672 // By doing so we will be able to compute the pan distance. 705 // By doing so we will be able to compute the pan distance.
673 this.firstPinchCenterInFrame_ = e.center; 706 this.firstPinchCenterInFrame_ = e.center;
674 }, 707 },
675 708
676 pinchZoomEnd: function(e) { 709 pinchZoomEnd: function(e) {
677 this.mightZoom_(function() { 710 this.mightZoom_(function() {
678 this.pinchPhase_ = Viewport.PinchPhase.PINCH_END; 711 this.pinchPhase_ = Viewport.PinchPhase.PINCH_END;
679 var scaleDelta = e.startScaleRatio / this.prevScale_; 712 var scaleDelta = e.startScaleRatio / this.prevScale_;
(...skipping 23 matching lines...) Expand all
703 if (page >= this.pageDimensions_.length) 736 if (page >= this.pageDimensions_.length)
704 page = this.pageDimensions_.length - 1; 737 page = this.pageDimensions_.length - 1;
705 var dimensions = this.pageDimensions_[page]; 738 var dimensions = this.pageDimensions_[page];
706 var toolbarOffset = 0; 739 var toolbarOffset = 0;
707 // Unless we're in fit to page mode, scroll above the page by 740 // Unless we're in fit to page mode, scroll above the page by
708 // |this.topToolbarHeight_| so that the toolbar isn't covering it 741 // |this.topToolbarHeight_| so that the toolbar isn't covering it
709 // initially. 742 // initially.
710 if (this.fittingType_ != Viewport.FittingType.FIT_TO_PAGE) 743 if (this.fittingType_ != Viewport.FittingType.FIT_TO_PAGE)
711 toolbarOffset = this.topToolbarHeight_; 744 toolbarOffset = this.topToolbarHeight_;
712 this.position = { 745 this.position = {
713 x: dimensions.x * this.zoom_, 746 x: dimensions.x * this.zoom,
714 y: dimensions.y * this.zoom_ - toolbarOffset 747 y: dimensions.y * this.zoom - toolbarOffset
715 }; 748 };
716 this.updateViewport_(); 749 this.updateViewport_();
717 }.bind(this)); 750 }.bind(this));
718 }, 751 },
719 752
720 /** 753 /**
721 * Set the dimensions of the document. 754 * Set the dimensions of the document.
722 * @param {Object} documentDimensions the dimensions of the document 755 * @param {Object} documentDimensions the dimensions of the document
723 */ 756 */
724 setDocumentDimensions: function(documentDimensions) { 757 setDocumentDimensions: function(documentDimensions) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 }; 804 };
772 805
773 // Compute the x-coordinate of the page within the document. 806 // Compute the x-coordinate of the page within the document.
774 // TODO(raymes): This should really be set when the PDF plugin passes the 807 // TODO(raymes): This should really be set when the PDF plugin passes the
775 // page coordinates, but it isn't yet. 808 // page coordinates, but it isn't yet.
776 var x = (this.documentDimensions_.width - pageDimensions.width) / 2 + 809 var x = (this.documentDimensions_.width - pageDimensions.width) / 2 +
777 Viewport.PAGE_SHADOW.left; 810 Viewport.PAGE_SHADOW.left;
778 // Compute the space on the left of the document if the document fits 811 // Compute the space on the left of the document if the document fits
779 // completely in the screen. 812 // completely in the screen.
780 var spaceOnLeft = (this.size.width - 813 var spaceOnLeft = (this.size.width -
781 this.documentDimensions_.width * this.zoom_) / 2; 814 this.documentDimensions_.width * this.zoom) / 2;
782 spaceOnLeft = Math.max(spaceOnLeft, 0); 815 spaceOnLeft = Math.max(spaceOnLeft, 0);
783 816
784 return { 817 return {
785 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, 818 x: x * this.zoom + spaceOnLeft - this.window_.pageXOffset,
786 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, 819 y: insetDimensions.y * this.zoom - this.window_.pageYOffset,
787 width: insetDimensions.width * this.zoom_, 820 width: insetDimensions.width * this.zoom,
788 height: insetDimensions.height * this.zoom_ 821 height: insetDimensions.height * this.zoom
789 }; 822 };
790 } 823 }
791 }; 824 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | chrome/browser/resources/pdf/zoom_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698