diff --git a/pdf/pdfium/accessibility_unittest.cc b/pdf/pdfium/accessibility_unittest.cc index a32003a4cabba..af575fa217da2 100644 --- a/pdf/pdfium/accessibility_unittest.cc +++ b/pdf/pdfium/accessibility_unittest.cc @@ -337,6 +337,28 @@ TEST_F(AccessibilityTest, TestScrollToNearestEdge) { ComparePoint({-199, -199}, client.GetScrollRequestPoints()); } +TEST_F(AccessibilityTest, TestScrollToGlobalPoint) { + ScrollEnabledTestClient client; + std::unique_ptr<PDFiumEngine> engine = InitializeEngine( + &client, FILE_PATH_LITERAL("rectangles_multi_pages.pdf")); + ASSERT_TRUE(engine); + engine->PluginSizeUpdated({400, 400}); + PP_PdfAccessibilityActionData action_data; + action_data.action = PP_PdfAccessibilityAction::PP_PDF_SCROLL_TO_GLOBAL_POINT; + + // Scroll up if global point is below the target rect + action_data.target_rect = {{201, 201}, {10, 10}}; + action_data.target_point = {230, 230}; + engine->HandleAccessibilityAction(action_data); + ComparePoint({-29, -29}, client.GetScrollRequestPoints()); + + // Scroll down if global point is above the target rect + action_data.target_rect = {{230, 230}, {10, 10}}; + action_data.target_point = {201, 201}; + engine->HandleAccessibilityAction(action_data); + ComparePoint({29, 29}, client.GetScrollRequestPoints()); +} + // This class is required to just override the NavigateTo // functionality for testing in a specific way. It will // keep the TestClient class clean for extension by others. diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index 9d916fc5686a3..11e59e347d768 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -2024,6 +2024,10 @@ void PDFiumEngine::HandleAccessibilityAction( } break; } + case PP_PdfAccessibilityAction::PP_PDF_SCROLL_TO_GLOBAL_POINT: { + ScrollToGlobalPoint(action_data.target_rect, action_data.target_point); + break; + } default: NOTREACHED(); break; @@ -2197,6 +2201,12 @@ void PDFiumEngine::ScrollBasedOnScrollAlignment( client_->ScrollBy(scroll_offset); } +void PDFiumEngine::ScrollToGlobalPoint(const pp::Rect& target_rect, + const pp::Point& global_point) { + pp::Point scroll_offset = GetScreenRect(target_rect).point(); + client_->ScrollBy(scroll_offset - global_point); +} + base::Optional<PDFEngine::NamedDestination> PDFiumEngine::GetNamedDestination( const std::string& destination) { // Look for the destination. diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index de878abb73897..b66953773406f 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -536,6 +536,11 @@ class PDFiumEngine : public PDFEngine, const PP_PdfAccessibilityScrollAlignment& horizontal_scroll_alignment, const PP_PdfAccessibilityScrollAlignment& vertical_scroll_alignment); + // Scrolls top left of a rect in page |target_rect| to |global_point|. + // Global point is point relative to viewport in screen. + void ScrollToGlobalPoint(const pp::Rect& target_rect, + const pp::Point& global_point); + // Set if the document has any local edits. void SetEditMode(bool edit_mode); diff --git a/ppapi/c/private/ppp_pdf.h b/ppapi/c/private/ppp_pdf.h index d72c6bd92337e..da1c5a3aeec08 100644 --- a/ppapi/c/private/ppp_pdf.h +++ b/ppapi/c/private/ppp_pdf.h @@ -67,8 +67,10 @@ typedef enum { PP_PDF_SCROLL_TO_MAKE_VISIBLE = 1, // Invokes default action on a node. PP_PDF_DO_DEFAULT_ACTION = 2, + // Action specifying a command to scroll to the global point. + PP_PDF_SCROLL_TO_GLOBAL_POINT = 3, // Last enum value marker. - PP_PDF_ACCESSIBILITYACTION_LAST = PP_PDF_DO_DEFAULT_ACTION + PP_PDF_ACCESSIBILITYACTION_LAST = PP_PDF_SCROLL_TO_GLOBAL_POINT } PP_PdfAccessibilityAction; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PdfAccessibilityAction, 4); @@ -108,6 +110,8 @@ struct PP_PdfAccessibilityActionData { PP_PdfAccessibilityAction action; // Annotation type on which the action is to be performed. PP_PdfAccessibilityAnnotationType annotation_type; + // Target point on which the action is to be performed. + struct PP_Point target_point; // Target rect on which the action is to be performed. struct PP_Rect target_rect; // Index of annotation in page. @@ -119,7 +123,7 @@ struct PP_PdfAccessibilityActionData { // Vertical scroll alignment with respect to the viewport PP_PdfAccessibilityScrollAlignment vertical_scroll_alignment; }; -PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_PdfAccessibilityActionData, 40); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_PdfAccessibilityActionData, 48); struct PPP_Pdf_1_1 { // Returns an absolute URL if the position is over a link. diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 3b9e6d4bee041..2eaa68bee0d2f 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -237,6 +237,7 @@ IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(PP_PdfAccessibilityActionData) IPC_STRUCT_TRAITS_MEMBER(action) IPC_STRUCT_TRAITS_MEMBER(annotation_type) + IPC_STRUCT_TRAITS_MEMBER(target_point) IPC_STRUCT_TRAITS_MEMBER(target_rect) IPC_STRUCT_TRAITS_MEMBER(annotation_index) IPC_STRUCT_TRAITS_MEMBER(page_index)