Chromium Code Reviews| Index: pdf/out_of_process_instance.cc |
| diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc |
| index 92511185c9715dd610adc6353cae440616666284..9cb91b6fb8c1ac48689d4179a73b973e95f1dc1b 100644 |
| --- a/pdf/out_of_process_instance.cc |
| +++ b/pdf/out_of_process_instance.cc |
| @@ -56,6 +56,13 @@ const char kJSViewportType[] = "viewport"; |
| const char kJSXOffset[] = "xOffset"; |
| const char kJSYOffset[] = "yOffset"; |
| const char kJSZoom[] = "zoom"; |
| +const char kJSPinchPhase[] = "pinchPhase"; |
| +// kJSPinchX and kJSPinchY represent the center of the pinch gesture. |
| +const char kJSPinchX[] = "pinchX"; |
| +const char kJSPinchY[] = "pinchY"; |
| +// kJSPinchVector represents the amount of panning caused by the pinch gesture. |
| +const char kJSPinchVectorX[] = "pinchVectorX"; |
| +const char kJSPinchVectorY[] = "pinchVectorY"; |
| // Stop scrolling message (Page -> Plugin) |
| const char kJSStopScrollingType[] = "stopScrolling"; |
| // Document dimension arguments (Plugin -> Page). |
| @@ -274,6 +281,9 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) |
| pp::Printing_Dev(this), |
| cursor_(PP_CURSORTYPE_POINTER), |
| zoom_(1.0), |
| + needs_reraster_(true), |
| + last_current_scroll_(0, 0), |
| + was_smaller_(false), |
| device_scale_(1.0), |
| full_(false), |
| paint_manager_(this, this, true), |
| @@ -395,13 +405,86 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) { |
| if (type == kJSViewportType && |
| dict.Get(pp::Var(kJSXOffset)).is_number() && |
| dict.Get(pp::Var(kJSYOffset)).is_number() && |
| - dict.Get(pp::Var(kJSZoom)).is_number()) { |
| + dict.Get(pp::Var(kJSZoom)).is_number() && |
| + dict.Get(pp::Var(kJSPinchPhase)).is_number()) { |
| received_viewport_message_ = true; |
| stop_scrolling_ = false; |
| + PinchPhase pinch_phase = |
| + static_cast<PinchPhase>(dict.Get(pp::Var(kJSPinchPhase)).AsInt()); |
| double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); |
| + double zoom_delta = zoom / zoom_; |
| + |
| pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(), |
| dict.Get(pp::Var(kJSYOffset)).AsDouble()); |
| + if (pinch_phase == PINCH_START) { |
| + last_current_scroll_ = scroll_offset; |
| + old_zoom_ = zoom; |
| + initial_zoom_delta_ = zoom_delta; |
| + was_smaller_ = false; |
| + needs_reraster_ = false; |
| + return; |
| + } else if (pinch_phase == PINCH_OUT_UPDATE) { |
| + if (!(dict.Get(pp::Var(kJSPinchX)).is_number() && |
| + dict.Get(pp::Var(kJSPinchY)).is_number() && |
| + dict.Get(pp::Var(kJSPinchVectorX)).is_number() && |
| + dict.Get(pp::Var(kJSPinchVectorY)).is_number())) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + pp::Point pinch_center(dict.Get(pp::Var(kJSPinchX)).AsDouble(), |
| + dict.Get(pp::Var(kJSPinchY)).AsDouble()); |
| + // Pinch vector is the panning caused due to change in pinch |
| + // center between start and end of the gesture. |
| + pp::Point pinch_vector = |
| + pp::Point(dict.Get(kJSPinchVectorX).AsDouble() * zoom_delta, |
| + dict.Get(kJSPinchVectorY).AsDouble() * zoom_delta); |
| + pp::Point scroll_delta(0, 0); |
| + // If the rendered document doesn't fill the display area we will |
| + // use paint_offset to anchor the paint vertically into the same place. We |
| + // use the scroll bars instead of the pinch vector to get the actual |
| + // position on screen of the paint. |
| + pp::Point paint_offset(0, 0); |
| + |
| + if (plugin_size_.width() > GetDocumentPixelWidth() * zoom_delta) { |
| + // We want to keep the paint in the middle but it must stay in the same |
| + // position relative to the scroll bars. |
| + paint_offset = pp::Point(0, (1 - zoom_delta) * pinch_center.y()); |
| + scroll_delta = pp::Point(0, |
| + (scroll_offset.y() - |
| + last_current_scroll_.y() * zoom_delta / initial_zoom_delta_)); |
| + |
| + pinch_vector = pp::Point(); |
| + old_zoom_ = zoom; |
| + was_smaller_ = true; |
| + } else if (was_smaller_) { |
| + pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2, |
| + (plugin_size_.height() / device_scale_) / 2); |
| + paint_offset = pp::Point((1 - zoom / old_zoom_) * pinch_center.x(), |
| + (1 - zoom_delta) * pinch_center.y()); |
| + pinch_vector = pp::Point(0, 0); |
| + scroll_delta = pp::Point( |
| + (scroll_offset.x() - |
| + last_current_scroll_.x() * zoom_delta / initial_zoom_delta_), |
| + (scroll_offset.y() - |
| + last_current_scroll_.y() * zoom_delta / initial_zoom_delta_)); |
| + } |
| + |
| + paint_manager_.SetTransform(zoom_delta, pinch_center, |
| + pinch_vector + paint_offset + scroll_delta); |
| + needs_reraster_ = pinch_phase != PINCH_OUT_UPDATE; |
|
bokan
2016/10/17 22:20:16
Isn't this guaranteed to be false?
Kevin McNee - google account
2016/10/24 21:11:47
...oops
Done.
|
| + return; |
| + } else if (pinch_phase == PINCH_IN_UPDATE || pinch_phase == PINCH_END) { |
| + // We reraster on pinchin in order to solve the invalid regions |
| + // that appear after zooming out. |
| + // On pinch end the scale is again 1.f and we request a reraster |
| + // in the new position. |
| + paint_manager_.SetTransform(1.f); |
| + was_smaller_ = false; |
| + needs_reraster_ = true; |
| + } |
| + |
| // Bound the input parameters. |
| zoom = std::max(kMinZoom, zoom); |
| SetZoom(zoom); |
| @@ -788,7 +871,7 @@ void OutOfProcessInstance::OnPaint( |
| ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); |
| } |
| - if (!received_viewport_message_) |
| + if (!received_viewport_message_ || !needs_reraster_) |
| return; |
| engine_->PrePaint(); |