Skip to content

Commit

Permalink
Plumb separate DidScroll message from PDF plugin to embedder.
Browse files Browse the repository at this point in the history
The change in r509091 added code to notify the embedder whenever the
PDF was scrolled so that touch-selection handles, which are drawn by the
browser and not the PDF viewer, could have their positions adjusted to
match the scroll.

This was done by having PDFiumEngine call OnSelectionChanged() for
each scroll, which triggers re-sending the selection coordinates to the
embedder. However, it seems this also triggers a DCHECK as
OnSelectionChanged() should not be called when the selection is in
a form area.

This CL plumbs an independent pathway from the PDF plugin to the
embedder so that this DCHECK can be avoided.

Bug: 784932
Change-Id: I8db353f0afa0e8c8bd625735d27e00d58c9b0dac
Reviewed-on: https://chromium-review.googlesource.com/782404
Reviewed-by: Ken Buchanan <[email protected]>
Reviewed-by: dsinclair <[email protected]>
Reviewed-by: Jochen Eisinger <[email protected]>
Commit-Queue: James MacLean <[email protected]>
Cr-Commit-Position: refs/heads/master@{#518936}
  • Loading branch information
W. James MacLean authored and Commit Bot committed Nov 23, 2017
1 parent 5464476 commit 289948d
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions components/pdf/common/pdf.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ interface PdfService {
// current selection.
SelectionChanged(gfx.mojom.PointF left, int32 left_height,
gfx.mojom.PointF right, int32 right_height);

// Notifies the embedder that the PDF scrolled, and thus global coordinates
// of current selection may require adjustment.
DidScroll();
};
12 changes: 12 additions & 0 deletions components/pdf/renderer/pepper_pdf_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ int32_t PepperPDFHost::OnResourceMessageReceived(
OnHostMsgSetAccessibilityPageInfo)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SelectionChanged,
OnHostMsgSelectionChanged)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_DidScroll,
OnHostMsgDidScroll)
PPAPI_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
Expand Down Expand Up @@ -249,6 +251,16 @@ int32_t PepperPDFHost::OnHostMsgSelectionChanged(
return PP_OK;
}

int32_t PepperPDFHost::OnHostMsgDidScroll(
ppapi::host::HostMessageContext* context) {
mojom::PdfService* service = GetRemotePdfService();
if (!service)
return PP_ERROR_FAILED;

service->DidScroll();
return PP_OK;
}

void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() {
if (!pdf_accessibility_tree_) {
pdf_accessibility_tree_ =
Expand Down
1 change: 1 addition & 0 deletions components/pdf/renderer/pepper_pdf_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class PepperPDFHost : public ppapi::host::ResourceHost,
int32_t left_height,
const PP_FloatPoint& right,
int32_t right_height);
int32_t OnHostMsgDidScroll(ppapi::host::HostMessageContext* context);

void CreatePdfAccessibilityTreeIfNeeded();

Expand Down
4 changes: 3 additions & 1 deletion pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,10 @@ void OutOfProcessInstance::Invalidate(const pp::Rect& rect) {
}

void OutOfProcessInstance::Scroll(const pp::Point& point) {
if (!image_data_.is_null())
if (!image_data_.is_null()) {
paint_manager_.ScrollRect(available_area_, point);
pp::PDF::DidScroll(GetPluginInstance());
}
}

void OutOfProcessInstance::ScrollToX(int x_in_screen_coords) {
Expand Down
2 changes: 0 additions & 2 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,6 @@ void PDFiumEngine::ScrolledToXPosition(int position) {
position_.set_x(position);
CalculateVisiblePages();
client_->Scroll(pp::Point(old_x - position, 0));
OnSelectionChanged();
}

void PDFiumEngine::ScrolledToYPosition(int position) {
Expand All @@ -1052,7 +1051,6 @@ void PDFiumEngine::ScrolledToYPosition(int position) {
position_.set_y(position);
CalculateVisiblePages();
client_->Scroll(pp::Point(0, old_y - position));
OnSelectionChanged();
}

void PDFiumEngine::PrePaint() {
Expand Down
3 changes: 3 additions & 0 deletions ppapi/c/private/ppb_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ struct PPB_PDF {
int32_t left_height,
const struct PP_FloatPoint* right,
int32_t right_height);

// Notifies embedder that the PDF has scrolled.
void (*DidScroll)(PP_Instance instance);
};

#endif // PPAPI_C_PRIVATE_PPB_PDF_H_
7 changes: 7 additions & 0 deletions ppapi/cpp/private/pdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,11 @@ void PDF::SelectionChanged(const InstanceHandle& instance,
}
}

// static
void PDF::DidScroll(const InstanceHandle& instance) {
if (has_interface<PPB_PDF>()) {
get_interface<PPB_PDF>()->DidScroll(instance.pp_instance());
}
}

} // namespace pp
1 change: 1 addition & 0 deletions ppapi/cpp/private/pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class PDF {
int32_t left_height,
const PP_FloatPoint& right,
int32_t right_height);
static void DidScroll(const InstanceHandle& instance);
};

} // namespace pp
Expand Down
4 changes: 4 additions & 0 deletions ppapi/proxy/pdf_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,9 @@ void PDFResource::SelectionChanged(const PP_FloatPoint& left,
right_height));
}

void PDFResource::DidScroll() {
Post(RENDERER, PpapiHostMsg_PDF_DidScroll());
}

} // namespace proxy
} // namespace ppapi
1 change: 1 addition & 0 deletions ppapi/proxy/pdf_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class PPAPI_PROXY_EXPORT PDFResource
int32_t left_height,
const PP_FloatPoint& right,
int32_t right_height) override;
void DidScroll() override;

private:
std::string locale_;
Expand Down
3 changes: 3 additions & 0 deletions ppapi/proxy/ppapi_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,9 @@ IPC_MESSAGE_CONTROL4(PpapiHostMsg_PDF_SelectionChanged,
PP_FloatPoint /* right */,
int32_t /* right_height */)

// Notify that the plugin has scrolled.
IPC_MESSAGE_CONTROL0(PpapiHostMsg_PDF_DidScroll)

// VideoCapture ----------------------------------------------------------------

// VideoCapture_Dev, plugin -> host
Expand Down
1 change: 1 addition & 0 deletions ppapi/thunk/ppb_pdf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PPB_PDF_API {
int32_t left_height,
const PP_FloatPoint& right,
int32_t right_height) = 0;
virtual void DidScroll() = 0;

static const SingletonResourceID kSingletonResourceID = PDF_SINGLETON_ID;
};
Expand Down
8 changes: 8 additions & 0 deletions ppapi/thunk/ppb_pdf_thunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ void SelectionChanged(PP_Instance instance,
enter.functions()->SelectionChanged(*left, left_height, *right, right_height);
}

void DidScroll(PP_Instance instance) {
EnterInstanceAPI<PPB_PDF_API> enter(instance);
if (enter.failed())
return;
enter.functions()->DidScroll();
}

const PPB_PDF g_ppb_pdf_thunk = {
&GetFontFileWithFallback,
&GetFontTableForPrivateFontFile,
Expand All @@ -200,6 +207,7 @@ const PPB_PDF g_ppb_pdf_thunk = {
&SetAccessibilityPageInfo,
&SetCrashData,
&SelectionChanged,
&DidScroll,
};

} // namespace
Expand Down

0 comments on commit 289948d

Please sign in to comment.