From bbf4d4d9095e571813aa7b9b67ccd4d6b4bb2c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ankit=20Kumar=20=F0=9F=8C=AA=EF=B8=8F?= Date: Fri, 19 Feb 2021 20:00:03 +0000 Subject: [PATCH] [unseasoned-pdf] Add AccessibilityActionData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add AccessibilityActionData in pdf/ so that we can replace the usage of PP_PdfAccessibilityActionData. The CL only introduces the struct and doesn't use it within pdf/. The struct will be used in future to replace usage of PP_PdfAccessibilityActionData within pdf/. Bug: 1144444 Change-Id: I5ff37feb996a1d7a9a3c9e5e9b5e62250d7852a6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2706381 Commit-Queue: Ankit Kumar 🌪️ Reviewed-by: Daniel Hosseinian Cr-Commit-Position: refs/heads/master@{#855849} --- pdf/accessibility_structs.cc | 29 ++++++ pdf/accessibility_structs.h | 100 +++++++++++++++++++++ pdf/pdfium/pdfium_assert_matching_enums.cc | 35 ++++++++ 3 files changed, 164 insertions(+) diff --git a/pdf/accessibility_structs.cc b/pdf/accessibility_structs.cc index d0741049765181..bfeb2f57598257 100644 --- a/pdf/accessibility_structs.cc +++ b/pdf/accessibility_structs.cc @@ -204,4 +204,33 @@ AccessibilityPageObjects::AccessibilityPageObjects( AccessibilityPageObjects::~AccessibilityPageObjects() = default; +AccessibilityActionData::AccessibilityActionData() = default; + +AccessibilityActionData::AccessibilityActionData( + AccessibilityAction action, + AccessibilityAnnotationType annotation_type, + const gfx::Point& target_point, + const gfx::Rect& target_rect, + uint32_t annotation_index, + uint32_t page_index, + AccessibilityScrollAlignment horizontal_scroll_alignment, + AccessibilityScrollAlignment vertical_scroll_alignment, + const PageCharacterIndex& selection_start_index, + const PageCharacterIndex& selection_end_index) + : action(action), + annotation_type(annotation_type), + target_point(target_point), + target_rect(target_rect), + annotation_index(annotation_index), + page_index(page_index), + horizontal_scroll_alignment(horizontal_scroll_alignment), + vertical_scroll_alignment(vertical_scroll_alignment), + selection_start_index(selection_start_index), + selection_end_index(selection_end_index) {} + +AccessibilityActionData::AccessibilityActionData( + const AccessibilityActionData& other) = default; + +AccessibilityActionData::~AccessibilityActionData() = default; + } // namespace chrome_pdf diff --git a/pdf/accessibility_structs.h b/pdf/accessibility_structs.h index d19a7aba8a9e94..cfce34ac515a88 100644 --- a/pdf/accessibility_structs.h +++ b/pdf/accessibility_structs.h @@ -10,6 +10,7 @@ #include #include +#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect_f.h" @@ -374,6 +375,105 @@ struct AccessibilityViewportInfo { AccessibilityFocusInfo focus_info; }; +// TODO(crbug.com/702993): Remove next line comment after PDF migrates away +// from Pepper. +// Explicitly set all enum values to match enum values in +// PP_PdfAccessibilityAction. +enum class AccessibilityAction { + // No action specified. + kNone = 0, + // Invoke the rect to scroll into the viewport. + kScrollToMakeVisible = 1, + // Invoke the default action on a node. + kDoDefaultAction = 2, + // Invoke the global point to scroll into the viewport. + kScrollToGlobalPoint = 3, + // Set the text selection. + kSetSelection = 4, + // Last enum value marker. + kMaxValue = kSetSelection, +}; + +// TODO(crbug.com/702993): Remove next line comment after PDF migrates away +// from Pepper. +// Explicitly set all enum values to match enum values in +// PP_PdfAccessibilityAnnotationType. +enum class AccessibilityAnnotationType { + // No annotation type defined. + kNone = 0, + // Link annotation. + kLink = 1, + // Last enum value marker. + kMaxValue = kLink, +}; + +enum class AccessibilityScrollAlignment { + // No scroll alignment specified. + kNone = 0, + // Scroll the point to the center of the viewport. + kCenter, + // Scroll the point to the top of the viewport. + kTop, + // Scroll the point to the bottom of the viewport. + kBottom, + // Scroll the point to the left of the viewport. + kLeft, + // Scroll the point to the right of the viewport. + kRight, + // Scroll the point to the closest edge of the viewport. + kClosestToEdge, + // Last enum value marker. + kMaxValue = kClosestToEdge, +}; + +struct PageCharacterIndex { + // Index of PDF page. + uint32_t page_index = 0; + // Index of character within the PDF page. + uint32_t char_index = 0; +}; + +struct AccessibilityActionData { + AccessibilityActionData(); + AccessibilityActionData( + AccessibilityAction action, + AccessibilityAnnotationType annotation_type, + const gfx::Point& target_point, + const gfx::Rect& target_rect, + uint32_t annotation_index, + uint32_t page_index, + AccessibilityScrollAlignment horizontal_scroll_alignment, + AccessibilityScrollAlignment vertical_scroll_alignment, + const PageCharacterIndex& selection_start_index, + const PageCharacterIndex& selection_end_index); + AccessibilityActionData(const AccessibilityActionData& other); + ~AccessibilityActionData(); + + // Accessibility action type. + AccessibilityAction action = AccessibilityAction::kNone; + // Annotation type on which the action is to be performed. + AccessibilityAnnotationType annotation_type = + AccessibilityAnnotationType::kNone; + // Target point on which the action is to be performed. + gfx::Point target_point; + // Target rect on which the action is to be performed. + gfx::Rect target_rect; + // Index of annotation in page. + uint32_t annotation_index = 0; + // Page index on which the link is present. + uint32_t page_index = 0; + // Horizontal scroll alignment with respect to the viewport + AccessibilityScrollAlignment horizontal_scroll_alignment = + AccessibilityScrollAlignment::kNone; + // Vertical scroll alignment with respect to the viewport + AccessibilityScrollAlignment vertical_scroll_alignment = + AccessibilityScrollAlignment::kNone; + // Page and character index of start of selection. + PageCharacterIndex selection_start_index; + // Page and character index of exclusive end of selection. + PageCharacterIndex selection_end_index; +}; + } // namespace chrome_pdf #endif // PDF_ACCESSIBILITY_STRUCTS_H_ diff --git a/pdf/pdfium/pdfium_assert_matching_enums.cc b/pdf/pdfium/pdfium_assert_matching_enums.cc index 4db77cbe8e3533..0943ce91409a82 100644 --- a/pdf/pdfium/pdfium_assert_matching_enums.cc +++ b/pdf/pdfium/pdfium_assert_matching_enums.cc @@ -359,3 +359,38 @@ STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kTextField, PP_PRIVATEFOCUSOBJECT_TEXT_FIELD); STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kMaxValue, PP_PRIVATEFOCUSOBJECT_LAST); + +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kNone, PP_PDF_ACTION_NONE); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kScrollToMakeVisible, + PP_PDF_SCROLL_TO_MAKE_VISIBLE); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kDoDefaultAction, + PP_PDF_DO_DEFAULT_ACTION); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kScrollToGlobalPoint, + PP_PDF_SCROLL_TO_GLOBAL_POINT); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kSetSelection, + PP_PDF_SET_SELECTION); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kMaxValue, + PP_PDF_ACCESSIBILITYACTION_LAST); + +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAnnotationType::kNone, + PP_PDF_TYPE_NONE); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAnnotationType::kLink, PP_PDF_LINK); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAnnotationType::kMaxValue, + PP_PDF_ACCESSIBILITY_ANNOTATIONTYPE_LAST); + +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kNone, + PP_PDF_SCROLL_NONE); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kCenter, + PP_PDF_SCROLL_ALIGNMENT_CENTER); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kTop, + PP_PDF_SCROLL_ALIGNMENT_TOP); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kBottom, + PP_PDF_SCROLL_ALIGNMENT_BOTTOM); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kLeft, + PP_PDF_SCROLL_ALIGNMENT_LEFT); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kRight, + PP_PDF_SCROLL_ALIGNMENT_RIGHT); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kClosestToEdge, + PP_PDF_SCROLL_ALIGNMENT_CLOSEST_EDGE); +STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kMaxValue, + PP_PDF_ACCESSIBILITYSCROLLALIGNMENT_LAST);