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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2781613002: PDF Viewer pinch zoom: Update state for zoom in following a zoom out. (Closed)
Patch Set: Remove redundant code and clarify variable. Created 3 years, 8 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 | « pdf/out_of_process_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "pdf/out_of_process_instance.h" 5 #include "pdf/out_of_process_instance.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // for min/max() 10 #include <algorithm> // for min/max()
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 stop_scrolling_ = false; 413 stop_scrolling_ = false;
414 PinchPhase pinch_phase = 414 PinchPhase pinch_phase =
415 static_cast<PinchPhase>(dict.Get(pp::Var(kJSPinchPhase)).AsInt()); 415 static_cast<PinchPhase>(dict.Get(pp::Var(kJSPinchPhase)).AsInt());
416 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); 416 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble();
417 double zoom_ratio = zoom / zoom_; 417 double zoom_ratio = zoom / zoom_;
418 418
419 pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(), 419 pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(),
420 dict.Get(pp::Var(kJSYOffset)).AsDouble()); 420 dict.Get(pp::Var(kJSYOffset)).AsDouble());
421 421
422 if (pinch_phase == PINCH_START) { 422 if (pinch_phase == PINCH_START) {
423 starting_scroll_offset_ = scroll_offset; 423 scroll_offset_at_last_raster_ = scroll_offset;
424 initial_zoom_ratio_ = zoom_ratio;
425 last_bitmap_smaller_ = false; 424 last_bitmap_smaller_ = false;
426 needs_reraster_ = false; 425 needs_reraster_ = false;
427 return; 426 return;
428 } 427 }
429 428
430 // When zooming in, we set a layer transform to avoid unneeded rerasters. 429 // When zooming in, we set a layer transform to avoid unneeded rerasters.
431 // Also, if we're zooming out and the last time we rerastered was when 430 // Also, if we're zooming out and the last time we rerastered was when
432 // we were even further zoomed out (i.e. we pinch zoomed in and are now 431 // we were even further zoomed out (i.e. we pinch zoomed in and are now
433 // pinch zooming back out in the same gesture), we update the layer 432 // pinch zooming back out in the same gesture), we update the layer
434 // transform instead of rerastering. 433 // transform instead of rerastering.
(...skipping 18 matching lines...) Expand all
453 // If the rendered document doesn't fill the display area we will 452 // If the rendered document doesn't fill the display area we will
454 // use |paint_offset| to anchor the paint vertically into the same place. 453 // use |paint_offset| to anchor the paint vertically into the same place.
455 // We use the scroll bars instead of the pinch vector to get the actual 454 // We use the scroll bars instead of the pinch vector to get the actual
456 // position on screen of the paint. 455 // position on screen of the paint.
457 pp::Point paint_offset; 456 pp::Point paint_offset;
458 457
459 if (plugin_size_.width() > GetDocumentPixelWidth() * zoom_ratio) { 458 if (plugin_size_.width() > GetDocumentPixelWidth() * zoom_ratio) {
460 // We want to keep the paint in the middle but it must stay in the same 459 // We want to keep the paint in the middle but it must stay in the same
461 // position relative to the scroll bars. 460 // position relative to the scroll bars.
462 paint_offset = pp::Point(0, (1 - zoom_ratio) * pinch_center.y()); 461 paint_offset = pp::Point(0, (1 - zoom_ratio) * pinch_center.y());
463 scroll_delta = pp::Point(0, 462 scroll_delta =
464 (scroll_offset.y() - 463 pp::Point(0, (scroll_offset.y() -
465 starting_scroll_offset_.y() * zoom_ratio / initial_zoom_ratio_)); 464 scroll_offset_at_last_raster_.y() * zoom_ratio));
466 465
467 pinch_vector = pp::Point(); 466 pinch_vector = pp::Point();
468 last_bitmap_smaller_ = true; 467 last_bitmap_smaller_ = true;
469 } else if (last_bitmap_smaller_) { 468 } else if (last_bitmap_smaller_) {
470 pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2, 469 pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2,
471 (plugin_size_.height() / device_scale_) / 2); 470 (plugin_size_.height() / device_scale_) / 2);
472 const double zoom_when_doc_covers_plugin_width = 471 const double zoom_when_doc_covers_plugin_width =
473 zoom_ * plugin_size_.width() / GetDocumentPixelWidth(); 472 zoom_ * plugin_size_.width() / GetDocumentPixelWidth();
474 paint_offset = pp::Point( 473 paint_offset = pp::Point(
475 (1 - zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(), 474 (1 - zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(),
476 (1 - zoom_ratio) * pinch_center.y()); 475 (1 - zoom_ratio) * pinch_center.y());
477 pinch_vector = pp::Point(); 476 pinch_vector = pp::Point();
478 scroll_delta = pp::Point( 477 scroll_delta =
479 (scroll_offset.x() - 478 pp::Point((scroll_offset.x() -
480 starting_scroll_offset_.x() * zoom_ratio / initial_zoom_ratio_), 479 scroll_offset_at_last_raster_.x() * zoom_ratio),
481 (scroll_offset.y() - 480 (scroll_offset.y() -
482 starting_scroll_offset_.y() * zoom_ratio / initial_zoom_ratio_)); 481 scroll_offset_at_last_raster_.y() * zoom_ratio));
483 } 482 }
484 483
485 paint_manager_.SetTransform(zoom_ratio, pinch_center, 484 paint_manager_.SetTransform(zoom_ratio, pinch_center,
486 pinch_vector + paint_offset + scroll_delta, 485 pinch_vector + paint_offset + scroll_delta,
487 true); 486 true);
488 needs_reraster_ = false; 487 needs_reraster_ = false;
489 return; 488 return;
490 } 489 }
491 490
492 if (pinch_phase == PINCH_UPDATE_ZOOM_OUT || pinch_phase == PINCH_END) { 491 if (pinch_phase == PINCH_UPDATE_ZOOM_OUT || pinch_phase == PINCH_END) {
493 // We reraster on pinch zoom out in order to solve the invalid regions 492 // We reraster on pinch zoom out in order to solve the invalid regions
494 // that appear after zooming out. 493 // that appear after zooming out.
495 // On pinch end the scale is again 1.f and we request a reraster 494 // On pinch end the scale is again 1.f and we request a reraster
496 // in the new position. 495 // in the new position.
497 paint_manager_.ClearTransform(); 496 paint_manager_.ClearTransform();
498 last_bitmap_smaller_ = false; 497 last_bitmap_smaller_ = false;
499 needs_reraster_ = true; 498 needs_reraster_ = true;
499
500 // If we're rerastering due to zooming out, we need to update
501 // |scroll_offset_at_last_raster_|, in case the user continues the
502 // gesture by zooming in.
503 scroll_offset_at_last_raster_ = scroll_offset;
500 } 504 }
501 505
502 // Bound the input parameters. 506 // Bound the input parameters.
503 zoom = std::max(kMinZoom, zoom); 507 zoom = std::max(kMinZoom, zoom);
504 SetZoom(zoom); 508 SetZoom(zoom);
505 scroll_offset = BoundScrollOffsetToDocument(scroll_offset); 509 scroll_offset = BoundScrollOffsetToDocument(scroll_offset);
506 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); 510 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_);
507 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); 511 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_);
508 } else if (type == kJSGetPasswordCompleteType && 512 } else if (type == kJSGetPasswordCompleteType &&
509 dict.Get(pp::Var(kJSPassword)).is_string()) { 513 dict.Get(pp::Var(kJSPassword)).is_string()) {
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 const pp::FloatPoint& scroll_offset) { 1654 const pp::FloatPoint& scroll_offset) {
1651 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1655 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1652 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1656 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1653 float min_y = -top_toolbar_height_; 1657 float min_y = -top_toolbar_height_;
1654 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1658 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1655 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1659 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1656 return pp::FloatPoint(x, y); 1660 return pp::FloatPoint(x, y);
1657 } 1661 }
1658 1662
1659 } // namespace chrome_pdf 1663 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698