diff --git a/pdf/accessibility.cc b/pdf/accessibility.cc index 96d2800a44a11..ea33c0cbf75f4 100644 --- a/pdf/accessibility.cc +++ b/pdf/accessibility.cc @@ -191,6 +191,7 @@ bool GetAccessibilityInfo( &page_objects->links); GetAccessibilityImageInfo(engine, page_index, page_info->text_run_count, &page_objects->images); + // TODO(crbug.com/1008775): Populate highlights return true; } diff --git a/ppapi/c/private/ppb_pdf.h b/ppapi/c/private/ppb_pdf.h index b94c412bdf743..99608a2c26c2b 100644 --- a/ppapi/c/private/ppb_pdf.h +++ b/ppapi/c/private/ppb_pdf.h @@ -149,7 +149,29 @@ struct PP_PrivateAccessibilityImageInfo { struct PP_FloatRect bounds; }; -// Holds links and images within a PDF page so that IPC messages +// This holds text highlight information provided by the PDF and will be +// used in accessibility to expose it. Text highlights can have an associated +// popup note, the data of which is also captured here. +// Needs to stay in sync with C++ versions (PdfAccessibilityHighlightInfo and +// PrivateAccessibilityHighlightInfo). +struct PP_PrivateAccessibilityHighlightInfo { + // Represents the text of the associated popup note, if present. + const char* note_text; + uint32_t note_text_length; + // Index of the highlight in the page annotation list. Used to identify the + // annotation on which action needs to be performed. + uint32_t index_in_page; + // Highlights are annotations over existing page text. |text_run_index| + // denotes the index of the text run where the highlight starts and + // |text_run_count| denotes the number of text runs which the highlight spans + // across. + uint32_t text_run_index; + uint32_t text_run_count; + // Bounding box of the highlight. + struct PP_FloatRect bounds; +}; + +// Holds links, images and highlights within a PDF page so that IPC messages // passing accessibility objects do not have too many parameters. // Needs to stay in sync with C++ versions (PdfAccessibilityPageObjects and // PrivateAccessibilityPageObjects). @@ -158,6 +180,8 @@ struct PP_PrivateAccessibilityPageObjects { uint32_t link_count; struct PP_PrivateAccessibilityImageInfo* images; uint32_t image_count; + struct PP_PrivateAccessibilityHighlightInfo* highlights; + uint32_t highlight_count; }; struct PPB_PDF { diff --git a/ppapi/cpp/private/pdf.cc b/ppapi/cpp/private/pdf.cc index 0242e261bd79a..b79603ebf9db2 100644 --- a/ppapi/cpp/private/pdf.cc +++ b/ppapi/cpp/private/pdf.cc @@ -61,6 +61,17 @@ void ConvertPrivateAccessibilityImageInfo( info->bounds = image.bounds; } +void ConvertPrivateAccessibilityHighlightInfo( + const PDF::PrivateAccessibilityHighlightInfo& highlight, + PP_PrivateAccessibilityHighlightInfo* info) { + info->note_text = highlight.note_text.c_str(); + info->note_text_length = highlight.note_text.size(); + info->index_in_page = highlight.index_in_page; + info->text_run_index = highlight.text_run_index; + info->text_run_count = highlight.text_run_count; + info->bounds = highlight.bounds; +} + } // namespace // static @@ -262,11 +273,22 @@ void PDF::SetAccessibilityPageInfo( for (size_t i = 0; i < images.size(); ++i) ConvertPrivateAccessibilityImageInfo(images[i], &image_info[i]); + const std::vector<PrivateAccessibilityHighlightInfo>& highlights = + page_objects.highlights; + std::vector<PP_PrivateAccessibilityHighlightInfo> highlight_info( + highlights.size()); + for (size_t i = 0; i < highlights.size(); ++i) { + ConvertPrivateAccessibilityHighlightInfo(highlights[i], + &highlight_info[i]); + } + PP_PrivateAccessibilityPageObjects pp_page_objects; pp_page_objects.links = link_info.data(); pp_page_objects.link_count = link_info.size(); pp_page_objects.images = image_info.data(); pp_page_objects.image_count = image_info.size(); + pp_page_objects.highlights = highlight_info.data(); + pp_page_objects.highlight_count = highlight_info.size(); get_interface<PPB_PDF>()->SetAccessibilityPageInfo( instance.pp_instance(), page_info, text_run_info.data(), chars.data(), diff --git a/ppapi/cpp/private/pdf.h b/ppapi/cpp/private/pdf.h index ebdde29b12b45..384115d1552e7 100644 --- a/ppapi/cpp/private/pdf.h +++ b/ppapi/cpp/private/pdf.h @@ -49,7 +49,10 @@ class PDF { // Needs to stay in sync with the C version. struct PrivateAccessibilityLinkInfo { std::string url; + // Index of this link in the collection of links in the page. uint32_t index_in_page; + // Index of the starting text run of this link in the collection of all + // text runs in the page. uint32_t text_run_index; uint32_t text_run_count; FloatRect bounds; @@ -63,11 +66,25 @@ class PDF { FloatRect bounds; }; + // C++ version of PP_PrivateAccessibilityHighlightInfo. + // Needs to stay in sync with the C version. + struct PrivateAccessibilityHighlightInfo { + std::string note_text; + // Index of this highlight in the collection of highlights in the page. + uint32_t index_in_page; + // Index of the starting text run of this highlight in the collection of all + // text runs in the page. + uint32_t text_run_index; + uint32_t text_run_count; + FloatRect bounds; + }; + // C++ version of PP_PrivateAccessibilityPageObjects. // Needs to stay in sync with the C version. struct PrivateAccessibilityPageObjects { std::vector<PrivateAccessibilityLinkInfo> links; std::vector<PrivateAccessibilityImageInfo> images; + std::vector<PrivateAccessibilityHighlightInfo> highlights; }; // Returns true if the required interface is available. diff --git a/ppapi/proxy/pdf_resource.cc b/ppapi/proxy/pdf_resource.cc index 6b50d7dc189f2..bb320f89c8f01 100644 --- a/ppapi/proxy/pdf_resource.cc +++ b/ppapi/proxy/pdf_resource.cc @@ -236,10 +236,16 @@ void PDFResource::SetAccessibilityPageInfo( for (size_t i = 0; i < page_objects->image_count; i++) { image_vector.emplace_back(page_objects->images[i]); } + std::vector<ppapi::PdfAccessibilityHighlightInfo> highlight_vector; + highlight_vector.reserve(page_objects->highlight_count); + for (size_t i = 0; i < page_objects->highlight_count; i++) { + highlight_vector.emplace_back(page_objects->highlights[i]); + } ppapi::PdfAccessibilityPageObjects ppapi_page_objects; ppapi_page_objects.links = std::move(link_vector); ppapi_page_objects.images = std::move(image_vector); + ppapi_page_objects.highlights = std::move(highlight_vector); Post(RENDERER, PpapiHostMsg_PDF_SetAccessibilityPageInfo( diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index b798623abf6ba..f11166db32ae0 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -314,9 +314,18 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityImageInfo) IPC_STRUCT_TRAITS_MEMBER(bounds) IPC_STRUCT_TRAITS_END() +IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityHighlightInfo) + IPC_STRUCT_TRAITS_MEMBER(note_text) + IPC_STRUCT_TRAITS_MEMBER(index_in_page) + IPC_STRUCT_TRAITS_MEMBER(text_run_index) + IPC_STRUCT_TRAITS_MEMBER(text_run_count) + IPC_STRUCT_TRAITS_MEMBER(bounds) +IPC_STRUCT_TRAITS_END() + IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityPageObjects) IPC_STRUCT_TRAITS_MEMBER(links) IPC_STRUCT_TRAITS_MEMBER(images) + IPC_STRUCT_TRAITS_MEMBER(highlights) IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(PP_URLComponent_Dev) diff --git a/ppapi/shared_impl/pdf_accessibility_shared.cc b/ppapi/shared_impl/pdf_accessibility_shared.cc index b91297e711dac..6237517ad0290 100644 --- a/ppapi/shared_impl/pdf_accessibility_shared.cc +++ b/ppapi/shared_impl/pdf_accessibility_shared.cc @@ -60,6 +60,18 @@ PdfAccessibilityImageInfo::PdfAccessibilityImageInfo( PdfAccessibilityImageInfo::~PdfAccessibilityImageInfo() = default; +PdfAccessibilityHighlightInfo::PdfAccessibilityHighlightInfo() = default; + +PdfAccessibilityHighlightInfo::~PdfAccessibilityHighlightInfo() = default; + +PdfAccessibilityHighlightInfo::PdfAccessibilityHighlightInfo( + const PP_PrivateAccessibilityHighlightInfo& highlight) + : note_text(std::string(highlight.note_text, highlight.note_text_length)), + index_in_page(highlight.index_in_page), + text_run_index(highlight.text_run_index), + text_run_count(highlight.text_run_count), + bounds(highlight.bounds) {} + PdfAccessibilityPageObjects::PdfAccessibilityPageObjects() = default; PdfAccessibilityPageObjects::PdfAccessibilityPageObjects( @@ -73,6 +85,11 @@ PdfAccessibilityPageObjects::PdfAccessibilityPageObjects( for (size_t i = 0; i < page_objects.image_count; i++) { images.emplace_back(page_objects.images[i]); } + + highlights.reserve(page_objects.highlight_count); + for (size_t i = 0; i < page_objects.highlight_count; i++) { + highlights.emplace_back(page_objects.highlights[i]); + } } PdfAccessibilityPageObjects::~PdfAccessibilityPageObjects() = default; diff --git a/ppapi/shared_impl/pdf_accessibility_shared.h b/ppapi/shared_impl/pdf_accessibility_shared.h index e1952aa2aff34..d3012d1d5cdf3 100644 --- a/ppapi/shared_impl/pdf_accessibility_shared.h +++ b/ppapi/shared_impl/pdf_accessibility_shared.h @@ -75,6 +75,20 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityImageInfo { PP_FloatRect bounds; }; +// Needs to stay in sync with PP_PrivateAccessibilityHighlightInfo. +struct PPAPI_SHARED_EXPORT PdfAccessibilityHighlightInfo { + PdfAccessibilityHighlightInfo(); + explicit PdfAccessibilityHighlightInfo( + const PP_PrivateAccessibilityHighlightInfo& highlight); + ~PdfAccessibilityHighlightInfo(); + + std::string note_text; + uint32_t index_in_page; + uint32_t text_run_index; + uint32_t text_run_count; + PP_FloatRect bounds; +}; + // Needs to stay in sync with PP_PrivateAccessibilityPageObjects. struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects { PdfAccessibilityPageObjects(); @@ -84,6 +98,7 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects { std::vector<PdfAccessibilityLinkInfo> links; std::vector<PdfAccessibilityImageInfo> images; + std::vector<PdfAccessibilityHighlightInfo> highlights; }; } // namespace ppapi