Commit 78dd839a authored by dpapad's avatar dpapad Committed by Commit Bot

PDF Viewer update: Send scroll updates from JS to C++.

Bug: 1101598
Change-Id: Ic83fc7e442158942a62feb8584471007447468c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309031
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791664}
parent 022cf77f
......@@ -166,6 +166,14 @@ export class PluginController extends ContentController {
return this.eventTarget_;
}
/**
* @param {number} x
* @param {number} y
*/
updateScroll(x, y) {
this.postMessage_({type: 'updateScroll', x, y});
}
/**
* Notify the plugin to stop reacting to scroll events while zoom is taking
* place to avoid flickering.
......
......@@ -117,7 +117,7 @@
<template is="dom-if" if="[[pdfViewerUpdateEnabled_]]">
<div id="container">
<div id="sidenav">sidenav</div>
<div id="main">
<div id="main" on-scroll="onScroll_">
<div id="sizer"></div>
<div id="content"></div>
</div>
......
......@@ -508,6 +508,14 @@ export class PDFViewerElement extends PDFViewerBaseElement {
}
// </if>
/**
* @param {!Event} e
* @private
*/
onScroll_(e) {
this.pluginController.updateScroll(e.target.scrollLeft, e.target.scrollTop);
}
/** @override */
onFitToChanged(e) {
super.onFitToChanged(e);
......
......@@ -89,6 +89,10 @@ constexpr char kJSPinchY[] = "pinchY";
// kJSPinchVector represents the amount of panning caused by the pinch gesture.
constexpr char kJSPinchVectorX[] = "pinchVectorX";
constexpr char kJSPinchVectorY[] = "pinchVectorY";
// UpdateScroll message arguments. (Page -> Plugin).
constexpr char kJSUpdateScrollType[] = "updateScroll";
constexpr char kJSUpdateScrollX[] = "x";
constexpr char kJSUpdateScrollY[] = "y";
// Stop scrolling message (Page -> Plugin)
constexpr char kJSStopScrollingType[] = "stopScrolling";
// Document dimension arguments (Plugin -> Page).
......@@ -567,6 +571,8 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
if (type == kJSViewportType) {
HandleViewportMessage(dict);
} else if (type == kJSUpdateScrollType) {
HandleUpdateScrollMessage(dict);
} else if (type == kJSGetPasswordCompleteType) {
HandleGetPasswordCompleteMessage(dict);
} else if (type == kJSPrintType) {
......@@ -692,21 +698,34 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) {
OnGeometryChanged(zoom_, old_device_scale);
}
if (!is_print_preview_ &&
base::FeatureList::IsEnabled(features::kPDFViewerUpdate)) {
// Scrolling in the new PDF Viewer UI is already handled by
// HandleUpdateScrollMessage().
return;
}
if (!stop_scrolling_) {
scroll_offset_ = view.GetScrollOffset();
// Because view messages come from the DOM, the coordinates of the viewport
// are 0-based (i.e. they do not correspond to the viewport's coordinates in
// JS), so we need to subtract the toolbar height to convert them into
// viewport coordinates.
pp::FloatPoint scroll_offset_float(
scroll_offset_.x(),
scroll_offset_.y() - top_toolbar_height_in_viewport_coords_);
scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float);
engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_);
engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_);
UpdateScroll();
}
}
void OutOfProcessInstance::UpdateScroll() {
DCHECK(!stop_scrolling_);
// Because view messages come from the DOM, the coordinates of the viewport
// are 0-based (i.e. they do not correspond to the viewport's coordinates in
// JS), so we need to subtract the toolbar height to convert them into
// viewport coordinates.
pp::FloatPoint scroll_offset_float(
scroll_offset_.x(),
scroll_offset_.y() - top_toolbar_height_in_viewport_coords_);
scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float);
engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_);
engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_);
}
void OutOfProcessInstance::DidChangeFocus(bool has_focus) {
engine_->UpdateFocus(has_focus);
}
......@@ -1699,6 +1718,25 @@ void OutOfProcessInstance::HandleSetTwoUpViewMessage(
engine_->SetTwoUpView(dict.Get(pp::Var(kJSEnableTwoUpView)).AsBool());
}
void OutOfProcessInstance::HandleUpdateScrollMessage(
const pp::VarDictionary& dict) {
if (!base::FeatureList::IsEnabled(features::kPDFViewerUpdate) ||
!dict.Get(pp::Var(kJSUpdateScrollX)).is_int() ||
!dict.Get(pp::Var(kJSUpdateScrollY)).is_int()) {
NOTREACHED();
return;
}
if (stop_scrolling_) {
return;
}
int x = dict.Get(pp::Var(kJSUpdateScrollX)).AsInt();
int y = dict.Get(pp::Var(kJSUpdateScrollY)).AsInt();
scroll_offset_ = pp::Point(x, y);
UpdateScroll();
}
void OutOfProcessInstance::HandleViewportMessage(
const pp::VarDictionary& dict) {
pp::Var layout_options_var = dict.Get(kJSLayoutOptions);
......
......@@ -184,8 +184,12 @@ class OutOfProcessInstance : public pp::Instance,
void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict);
void HandleSaveMessage(const pp::VarDictionary& dict);
void HandleSetTwoUpViewMessage(const pp::VarDictionary& dict);
void HandleUpdateScrollMessage(const pp::VarDictionary& dict);
void HandleViewportMessage(const pp::VarDictionary& dict);
// Repaints plugin contents based on the current scroll position.
void UpdateScroll();
void ResetRecentlySentFindUpdate(int32_t);
// Called whenever the plugin geometry changes to update the location of the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment