Implement scroll to global point action in PDFiumEngine
This change adds the following - Adds name PP_PDF_SCROLL_TO_GLOBAL_POINT in PP_PdfAccessibilityAction action enum. - Handle PP_PDF_SCROLL_TO_GLOBAL_POINT action in PDFiumEngine. The action is used by certain screen readers to scroll content in viewport during continuous read operation. Bug: 811233 Change-Id: I725a5295f42049af139856ce9815799cf67c0088 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954800 Commit-Queue: Virender Singh <virens@microsoft.com> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com> Cr-Commit-Position: refs/heads/master@{#724911}
This commit is contained in:

committed by
Commit Bot

parent
025f4202ec
commit
9ee0969926
pdf/pdfium
ppapi
@ -337,6 +337,28 @@ TEST_F(AccessibilityTest, TestScrollToNearestEdge) {
|
|||||||
ComparePoint({-199, -199}, client.GetScrollRequestPoints());
|
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
|
// This class is required to just override the NavigateTo
|
||||||
// functionality for testing in a specific way. It will
|
// functionality for testing in a specific way. It will
|
||||||
// keep the TestClient class clean for extension by others.
|
// keep the TestClient class clean for extension by others.
|
||||||
|
@ -2024,6 +2024,10 @@ void PDFiumEngine::HandleAccessibilityAction(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PP_PdfAccessibilityAction::PP_PDF_SCROLL_TO_GLOBAL_POINT: {
|
||||||
|
ScrollToGlobalPoint(action_data.target_rect, action_data.target_point);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
break;
|
break;
|
||||||
@ -2197,6 +2201,12 @@ void PDFiumEngine::ScrollBasedOnScrollAlignment(
|
|||||||
client_->ScrollBy(scroll_offset);
|
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(
|
base::Optional<PDFEngine::NamedDestination> PDFiumEngine::GetNamedDestination(
|
||||||
const std::string& destination) {
|
const std::string& destination) {
|
||||||
// Look for the destination.
|
// Look for the destination.
|
||||||
|
@ -536,6 +536,11 @@ class PDFiumEngine : public PDFEngine,
|
|||||||
const PP_PdfAccessibilityScrollAlignment& horizontal_scroll_alignment,
|
const PP_PdfAccessibilityScrollAlignment& horizontal_scroll_alignment,
|
||||||
const PP_PdfAccessibilityScrollAlignment& vertical_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.
|
// Set if the document has any local edits.
|
||||||
void SetEditMode(bool edit_mode);
|
void SetEditMode(bool edit_mode);
|
||||||
|
|
||||||
|
@ -67,8 +67,10 @@ typedef enum {
|
|||||||
PP_PDF_SCROLL_TO_MAKE_VISIBLE = 1,
|
PP_PDF_SCROLL_TO_MAKE_VISIBLE = 1,
|
||||||
// Invokes default action on a node.
|
// Invokes default action on a node.
|
||||||
PP_PDF_DO_DEFAULT_ACTION = 2,
|
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.
|
// 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_PdfAccessibilityAction;
|
||||||
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PdfAccessibilityAction, 4);
|
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PdfAccessibilityAction, 4);
|
||||||
|
|
||||||
@ -108,6 +110,8 @@ struct PP_PdfAccessibilityActionData {
|
|||||||
PP_PdfAccessibilityAction action;
|
PP_PdfAccessibilityAction action;
|
||||||
// Annotation type on which the action is to be performed.
|
// Annotation type on which the action is to be performed.
|
||||||
PP_PdfAccessibilityAnnotationType annotation_type;
|
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.
|
// Target rect on which the action is to be performed.
|
||||||
struct PP_Rect target_rect;
|
struct PP_Rect target_rect;
|
||||||
// Index of annotation in page.
|
// Index of annotation in page.
|
||||||
@ -119,7 +123,7 @@ struct PP_PdfAccessibilityActionData {
|
|||||||
// Vertical scroll alignment with respect to the viewport
|
// Vertical scroll alignment with respect to the viewport
|
||||||
PP_PdfAccessibilityScrollAlignment vertical_scroll_alignment;
|
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 {
|
struct PPP_Pdf_1_1 {
|
||||||
// Returns an absolute URL if the position is over a link.
|
// Returns an absolute URL if the position is over a link.
|
||||||
|
@ -237,6 +237,7 @@ IPC_STRUCT_TRAITS_END()
|
|||||||
IPC_STRUCT_TRAITS_BEGIN(PP_PdfAccessibilityActionData)
|
IPC_STRUCT_TRAITS_BEGIN(PP_PdfAccessibilityActionData)
|
||||||
IPC_STRUCT_TRAITS_MEMBER(action)
|
IPC_STRUCT_TRAITS_MEMBER(action)
|
||||||
IPC_STRUCT_TRAITS_MEMBER(annotation_type)
|
IPC_STRUCT_TRAITS_MEMBER(annotation_type)
|
||||||
|
IPC_STRUCT_TRAITS_MEMBER(target_point)
|
||||||
IPC_STRUCT_TRAITS_MEMBER(target_rect)
|
IPC_STRUCT_TRAITS_MEMBER(target_rect)
|
||||||
IPC_STRUCT_TRAITS_MEMBER(annotation_index)
|
IPC_STRUCT_TRAITS_MEMBER(annotation_index)
|
||||||
IPC_STRUCT_TRAITS_MEMBER(page_index)
|
IPC_STRUCT_TRAITS_MEMBER(page_index)
|
||||||
|
Reference in New Issue
Block a user