Add annotation structs for PDF accessibility
This change adds new *AccessibilityAnnotInfo structs to transfer accessibility related PDF annotation data from the plugin process up to the mimehandler process via the pepper API. This annotation information is bundled along with links and images into the *AccessibilityPageObjects group of structs introduced as a part of http://crrev.com/c/1831957. It will be populated from within pdfium_page in a subsequent change. Bug: 1008775 Change-Id: I89eabc8f56c135eac95c2c887d33854fbccbbcb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837558 Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com> Reviewed-by: Bill Budge <bbudge@chromium.org> Reviewed-by: Ian Prest <iapres@microsoft.com> Commit-Queue: Kalpak Tapas <katapas@microsoft.com> Cr-Commit-Position: refs/heads/master@{#716555}
This commit is contained in:
pdf
ppapi
c
private
cpp
proxy
shared_impl
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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(),
|
||||
|
@ -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.
|
||||
|
@ -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(
|
||||
|
@ -315,9 +315,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)
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user