0

Add text field structs for PDF accessibility.

This change adds struct PP_PrivateAccessibilityTextFieldInfo to
PP_PrivateAccessibilityPageObjects to transfer accessibility related PDF
text field data from the plugin process to the mimehandler process. Made
the same changes to the C++ versions of these structs and added the
appropriate conversion code.

Bug: 1030242
Change-Id: I50c9e82a9416445394b9cd1747606fc6d3706ef2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032463
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com>
Commit-Queue: Mansi Awasthi <maawas@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#738857}
This commit is contained in:
Mansi Awasthi
2020-02-06 05:53:54 +00:00
committed by Commit Bot
parent 9f2611fb8c
commit 87d0258c57
8 changed files with 129 additions and 0 deletions

@ -229,6 +229,7 @@ bool GetAccessibilityInfo(
&page_objects->images);
GetAccessibilityHighlightInfo(engine, page_index, *text_runs,
&page_objects->highlights);
// TODO(crbug.com/1030242): Populate text fields.
return true;
}

@ -179,6 +179,33 @@ struct PP_PrivateAccessibilityHighlightInfo {
uint32_t color;
};
// This holds text form field information provided by the PDF and will be used
// in accessibility to expose it. Needs to stay in sync with C++ versions
// (PdfAccessibilityTextFieldInfo and PrivateAccessibilityTextFieldInfo).
struct PP_PrivateAccessibilityTextFieldInfo {
// Represents the name property of text field, if present.
const char* name;
uint32_t name_length;
// Represents the value property of text field, if present.
const char* value;
uint32_t value_length;
// Represents if the text field is non-editable.
bool is_read_only;
// Represents if the field should have value at the time it is exported by a
// submit form action.
bool is_required;
// Represents if the text field is a password text field type.
bool is_password;
// Index of the text field in the collection of text fields in the page. Used
// to identify the annotation on which action needs to be performed.
uint32_t index_in_page;
// We anchor the text field to a text run index, this denotes the text run
// before which the text field should be inserted in the accessibility tree.
uint32_t text_run_index;
// Bounding box of the text field.
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
@ -190,6 +217,8 @@ struct PP_PrivateAccessibilityPageObjects {
uint32_t image_count;
struct PP_PrivateAccessibilityHighlightInfo* highlights;
uint32_t highlight_count;
struct PP_PrivateAccessibilityTextFieldInfo* text_fields;
uint32_t text_field_count;
};
struct PPB_PDF {

@ -73,6 +73,21 @@ void ConvertPrivateAccessibilityHighlightInfo(
info->color = highlight.color;
}
void ConvertPrivateAccessibilityTextFieldInfo(
const PDF::PrivateAccessibilityTextFieldInfo& text_field,
PP_PrivateAccessibilityTextFieldInfo* info) {
info->name = text_field.name.c_str();
info->name_length = text_field.name.size();
info->value = text_field.value.c_str();
info->value_length = text_field.value.size();
info->is_read_only = text_field.is_read_only;
info->is_required = text_field.is_required;
info->is_password = text_field.is_password;
info->index_in_page = text_field.index_in_page;
info->text_run_index = text_field.text_run_index;
info->bounds = text_field.bounds;
}
} // namespace
// static
@ -283,6 +298,15 @@ void PDF::SetAccessibilityPageInfo(
&highlight_info[i]);
}
const std::vector<PrivateAccessibilityTextFieldInfo>& text_fields =
page_objects.text_fields;
std::vector<PP_PrivateAccessibilityTextFieldInfo> text_field_info(
text_fields.size());
for (size_t i = 0; i < text_fields.size(); ++i) {
ConvertPrivateAccessibilityTextFieldInfo(text_fields[i],
&text_field_info[i]);
}
PP_PrivateAccessibilityPageObjects pp_page_objects;
pp_page_objects.links = link_info.data();
pp_page_objects.link_count = link_info.size();
@ -290,6 +314,8 @@ void PDF::SetAccessibilityPageInfo(
pp_page_objects.image_count = image_info.size();
pp_page_objects.highlights = highlight_info.data();
pp_page_objects.highlight_count = highlight_info.size();
pp_page_objects.text_fields = text_field_info.data();
pp_page_objects.text_field_count = text_field_info.size();
get_interface<PPB_PDF>()->SetAccessibilityPageInfo(
instance.pp_instance(), page_info, text_run_info.data(), chars.data(),

@ -82,12 +82,29 @@ class PDF {
uint32_t color;
};
// C++ version of PP_PrivateAccessibilityTextFieldInfo.
// Needs to stay in sync with the C version.
struct PrivateAccessibilityTextFieldInfo {
std::string name;
std::string value;
bool is_read_only;
bool is_required;
bool is_password;
// Index of this text field in the collection of text fields in the page.
uint32_t index_in_page;
// We anchor the text field to a text run index, this denotes the text run
// before which the text field should be inserted in the accessibility tree.
uint32_t text_run_index;
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;
std::vector<PrivateAccessibilityTextFieldInfo> text_fields;
};
// Returns true if the required interface is available.

@ -241,11 +241,17 @@ void PDFResource::SetAccessibilityPageInfo(
for (size_t i = 0; i < page_objects->highlight_count; i++) {
highlight_vector.emplace_back(page_objects->highlights[i]);
}
std::vector<ppapi::PdfAccessibilityTextFieldInfo> text_field_vector;
text_field_vector.reserve(page_objects->text_field_count);
for (size_t i = 0; i < page_objects->text_field_count; i++) {
text_field_vector.emplace_back(page_objects->text_fields[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);
ppapi_page_objects.text_fields = std::move(text_field_vector);
Post(RENDERER,
PpapiHostMsg_PDF_SetAccessibilityPageInfo(

@ -337,10 +337,22 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityHighlightInfo)
IPC_STRUCT_TRAITS_MEMBER(color)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityTextFieldInfo)
IPC_STRUCT_TRAITS_MEMBER(name)
IPC_STRUCT_TRAITS_MEMBER(value)
IPC_STRUCT_TRAITS_MEMBER(is_read_only)
IPC_STRUCT_TRAITS_MEMBER(is_required)
IPC_STRUCT_TRAITS_MEMBER(is_password)
IPC_STRUCT_TRAITS_MEMBER(index_in_page)
IPC_STRUCT_TRAITS_MEMBER(text_run_index)
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_MEMBER(text_fields)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PP_URLComponent_Dev)

@ -73,6 +73,21 @@ PdfAccessibilityHighlightInfo::PdfAccessibilityHighlightInfo(
bounds(highlight.bounds),
color(highlight.color) {}
PdfAccessibilityTextFieldInfo::PdfAccessibilityTextFieldInfo() = default;
PdfAccessibilityTextFieldInfo::~PdfAccessibilityTextFieldInfo() = default;
PdfAccessibilityTextFieldInfo::PdfAccessibilityTextFieldInfo(
const PP_PrivateAccessibilityTextFieldInfo& text_field)
: name(std::string(text_field.name, text_field.name_length)),
value(std::string(text_field.value, text_field.value_length)),
is_read_only(text_field.is_read_only),
is_required(text_field.is_required),
is_password(text_field.is_password),
index_in_page(text_field.index_in_page),
text_run_index(text_field.text_run_index),
bounds(text_field.bounds) {}
PdfAccessibilityPageObjects::PdfAccessibilityPageObjects() = default;
PdfAccessibilityPageObjects::PdfAccessibilityPageObjects(
@ -91,6 +106,11 @@ PdfAccessibilityPageObjects::PdfAccessibilityPageObjects(
for (size_t i = 0; i < page_objects.highlight_count; i++) {
highlights.emplace_back(page_objects.highlights[i]);
}
text_fields.reserve(page_objects.text_field_count);
for (size_t i = 0; i < page_objects.text_field_count; i++) {
text_fields.emplace_back(page_objects.text_fields[i]);
}
}
PdfAccessibilityPageObjects::~PdfAccessibilityPageObjects() = default;

@ -90,6 +90,23 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityHighlightInfo {
uint32_t color;
};
// Needs to stay in sync with PP_PrivateAccessibilityTextFieldInfo.
struct PPAPI_SHARED_EXPORT PdfAccessibilityTextFieldInfo {
PdfAccessibilityTextFieldInfo();
explicit PdfAccessibilityTextFieldInfo(
const PP_PrivateAccessibilityTextFieldInfo& text_field);
~PdfAccessibilityTextFieldInfo();
std::string name;
std::string value;
bool is_read_only;
bool is_required;
bool is_password;
uint32_t index_in_page;
uint32_t text_run_index;
PP_FloatRect bounds;
};
// Needs to stay in sync with PP_PrivateAccessibilityPageObjects.
struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects {
PdfAccessibilityPageObjects();
@ -100,6 +117,7 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects {
std::vector<PdfAccessibilityLinkInfo> links;
std::vector<PdfAccessibilityImageInfo> images;
std::vector<PdfAccessibilityHighlightInfo> highlights;
std::vector<PdfAccessibilityTextFieldInfo> text_fields;
};
} // namespace ppapi