Index: pdf/out_of_process_instance.cc |
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc |
index 9e77ec616ac6e3689de8a7f901d4ad6408343546..05bf4ee1b1c81d40cfc236938639b2939c0c6c66 100644 |
--- a/pdf/out_of_process_instance.cc |
+++ b/pdf/out_of_process_instance.cc |
@@ -34,6 +34,7 @@ |
#include "ppapi/cpp/module.h" |
#include "ppapi/cpp/point.h" |
#include "ppapi/cpp/private/pdf.h" |
+#include "ppapi/cpp/private/var_private.h" |
#include "ppapi/cpp/rect.h" |
#include "ppapi/cpp/resource.h" |
#include "ppapi/cpp/url_request_info.h" |
@@ -70,6 +71,8 @@ const char* kJSViewportType = "viewport"; |
const char* kJSXOffset = "xOffset"; |
const char* kJSYOffset = "yOffset"; |
const char* kJSZoom = "zoom"; |
+// Stop scrolling message (Page -> Plugin) |
+const char* kJSStopScrollingType = "stopScrolling"; |
// Document dimension arguments (Plugin -> Page). |
const char* kJSDocumentDimensionsType = "documentDimensions"; |
const char* kJSDocumentWidth = "width"; |
@@ -244,7 +247,8 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) |
last_progress_sent_(0), |
recently_sent_find_update_(false), |
received_viewport_message_(false), |
- did_call_start_loading_(false) { |
+ did_call_start_loading_(false), |
+ stop_scrolling_(false) { |
loader_factory_.Initialize(this); |
timer_factory_.Initialize(this); |
form_factory_.Initialize(this); |
@@ -355,6 +359,7 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) { |
dict.Get(pp::Var(kJSYOffset)).is_int() && |
dict.Get(pp::Var(kJSZoom)).is_number()) { |
received_viewport_message_ = true; |
+ stop_scrolling_ = false; |
double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); |
int x = dict.Get(pp::Var(kJSXOffset)).AsInt(); |
int y = dict.Get(pp::Var(kJSYOffset)).AsInt(); |
@@ -425,6 +430,8 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) { |
reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json)); |
} |
PostMessage(reply); |
+ } else if (type == kJSStopScrollingType) { |
+ stop_scrolling_ = true; |
} else { |
NOTREACHED(); |
} |
@@ -507,6 +514,16 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) { |
pp::Size view_device_size(view_rect.width() * device_scale, |
view_rect.height() * device_scale); |
+ if (!stop_scrolling_) { |
+ pp::Point scroll_offset(view.GetScrollOffset()); |
+ int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
Lei Zhang
2014/06/23 09:19:41
Can we share some of the code with line 369?
raymes
2014/06/24 00:41:53
Done.
|
+ int x = std::max(std::min(scroll_offset.x(), max_x), 0); |
+ int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
+ int y = std::max(std::min(scroll_offset.y(), max_y), 0); |
+ engine_->ScrolledToXPosition(x * device_scale_); |
+ engine_->ScrolledToYPosition(y * device_scale_); |
+ } |
+ |
if (view_device_size == plugin_size_ && device_scale == device_scale_) |
return; // We don't care about the position, only the size. |