Commit 87d0258c authored by Mansi Awasthi's avatar Mansi Awasthi Committed by Commit Bot

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/+/2032463Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Commit-Queue: Mansi Awasthi <maawas@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#738857}
parent 9f2611fb
...@@ -229,6 +229,7 @@ bool GetAccessibilityInfo( ...@@ -229,6 +229,7 @@ bool GetAccessibilityInfo(
&page_objects->images); &page_objects->images);
GetAccessibilityHighlightInfo(engine, page_index, *text_runs, GetAccessibilityHighlightInfo(engine, page_index, *text_runs,
&page_objects->highlights); &page_objects->highlights);
// TODO(crbug.com/1030242): Populate text fields.
return true; return true;
} }
......
...@@ -179,6 +179,33 @@ struct PP_PrivateAccessibilityHighlightInfo { ...@@ -179,6 +179,33 @@ struct PP_PrivateAccessibilityHighlightInfo {
uint32_t color; 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 // Holds links, images and highlights within a PDF page so that IPC messages
// passing accessibility objects do not have too many parameters. // passing accessibility objects do not have too many parameters.
// Needs to stay in sync with C++ versions (PdfAccessibilityPageObjects and // Needs to stay in sync with C++ versions (PdfAccessibilityPageObjects and
...@@ -190,6 +217,8 @@ struct PP_PrivateAccessibilityPageObjects { ...@@ -190,6 +217,8 @@ struct PP_PrivateAccessibilityPageObjects {
uint32_t image_count; uint32_t image_count;
struct PP_PrivateAccessibilityHighlightInfo* highlights; struct PP_PrivateAccessibilityHighlightInfo* highlights;
uint32_t highlight_count; uint32_t highlight_count;
struct PP_PrivateAccessibilityTextFieldInfo* text_fields;
uint32_t text_field_count;
}; };
struct PPB_PDF { struct PPB_PDF {
......
...@@ -73,6 +73,21 @@ void ConvertPrivateAccessibilityHighlightInfo( ...@@ -73,6 +73,21 @@ void ConvertPrivateAccessibilityHighlightInfo(
info->color = highlight.color; 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 } // namespace
// static // static
...@@ -283,6 +298,15 @@ void PDF::SetAccessibilityPageInfo( ...@@ -283,6 +298,15 @@ void PDF::SetAccessibilityPageInfo(
&highlight_info[i]); &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_PrivateAccessibilityPageObjects pp_page_objects;
pp_page_objects.links = link_info.data(); pp_page_objects.links = link_info.data();
pp_page_objects.link_count = link_info.size(); pp_page_objects.link_count = link_info.size();
...@@ -290,6 +314,8 @@ void PDF::SetAccessibilityPageInfo( ...@@ -290,6 +314,8 @@ void PDF::SetAccessibilityPageInfo(
pp_page_objects.image_count = image_info.size(); pp_page_objects.image_count = image_info.size();
pp_page_objects.highlights = highlight_info.data(); pp_page_objects.highlights = highlight_info.data();
pp_page_objects.highlight_count = highlight_info.size(); 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( get_interface<PPB_PDF>()->SetAccessibilityPageInfo(
instance.pp_instance(), page_info, text_run_info.data(), chars.data(), instance.pp_instance(), page_info, text_run_info.data(), chars.data(),
......
...@@ -82,12 +82,29 @@ class PDF { ...@@ -82,12 +82,29 @@ class PDF {
uint32_t color; 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. // C++ version of PP_PrivateAccessibilityPageObjects.
// Needs to stay in sync with the C version. // Needs to stay in sync with the C version.
struct PrivateAccessibilityPageObjects { struct PrivateAccessibilityPageObjects {
std::vector<PrivateAccessibilityLinkInfo> links; std::vector<PrivateAccessibilityLinkInfo> links;
std::vector<PrivateAccessibilityImageInfo> images; std::vector<PrivateAccessibilityImageInfo> images;
std::vector<PrivateAccessibilityHighlightInfo> highlights; std::vector<PrivateAccessibilityHighlightInfo> highlights;
std::vector<PrivateAccessibilityTextFieldInfo> text_fields;
}; };
// Returns true if the required interface is available. // Returns true if the required interface is available.
......
...@@ -241,11 +241,17 @@ void PDFResource::SetAccessibilityPageInfo( ...@@ -241,11 +241,17 @@ void PDFResource::SetAccessibilityPageInfo(
for (size_t i = 0; i < page_objects->highlight_count; i++) { for (size_t i = 0; i < page_objects->highlight_count; i++) {
highlight_vector.emplace_back(page_objects->highlights[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::PdfAccessibilityPageObjects ppapi_page_objects;
ppapi_page_objects.links = std::move(link_vector); ppapi_page_objects.links = std::move(link_vector);
ppapi_page_objects.images = std::move(image_vector); ppapi_page_objects.images = std::move(image_vector);
ppapi_page_objects.highlights = std::move(highlight_vector); ppapi_page_objects.highlights = std::move(highlight_vector);
ppapi_page_objects.text_fields = std::move(text_field_vector);
Post(RENDERER, Post(RENDERER,
PpapiHostMsg_PDF_SetAccessibilityPageInfo( PpapiHostMsg_PDF_SetAccessibilityPageInfo(
......
...@@ -337,10 +337,22 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityHighlightInfo) ...@@ -337,10 +337,22 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityHighlightInfo)
IPC_STRUCT_TRAITS_MEMBER(color) IPC_STRUCT_TRAITS_MEMBER(color)
IPC_STRUCT_TRAITS_END() 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_BEGIN(ppapi::PdfAccessibilityPageObjects)
IPC_STRUCT_TRAITS_MEMBER(links) IPC_STRUCT_TRAITS_MEMBER(links)
IPC_STRUCT_TRAITS_MEMBER(images) IPC_STRUCT_TRAITS_MEMBER(images)
IPC_STRUCT_TRAITS_MEMBER(highlights) IPC_STRUCT_TRAITS_MEMBER(highlights)
IPC_STRUCT_TRAITS_MEMBER(text_fields)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PP_URLComponent_Dev) IPC_STRUCT_TRAITS_BEGIN(PP_URLComponent_Dev)
......
...@@ -73,6 +73,21 @@ PdfAccessibilityHighlightInfo::PdfAccessibilityHighlightInfo( ...@@ -73,6 +73,21 @@ PdfAccessibilityHighlightInfo::PdfAccessibilityHighlightInfo(
bounds(highlight.bounds), bounds(highlight.bounds),
color(highlight.color) {} 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() = default;
PdfAccessibilityPageObjects::PdfAccessibilityPageObjects( PdfAccessibilityPageObjects::PdfAccessibilityPageObjects(
...@@ -91,6 +106,11 @@ PdfAccessibilityPageObjects::PdfAccessibilityPageObjects( ...@@ -91,6 +106,11 @@ PdfAccessibilityPageObjects::PdfAccessibilityPageObjects(
for (size_t i = 0; i < page_objects.highlight_count; i++) { for (size_t i = 0; i < page_objects.highlight_count; i++) {
highlights.emplace_back(page_objects.highlights[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; PdfAccessibilityPageObjects::~PdfAccessibilityPageObjects() = default;
......
...@@ -90,6 +90,23 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityHighlightInfo { ...@@ -90,6 +90,23 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityHighlightInfo {
uint32_t color; 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. // Needs to stay in sync with PP_PrivateAccessibilityPageObjects.
struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects { struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects {
PdfAccessibilityPageObjects(); PdfAccessibilityPageObjects();
...@@ -100,6 +117,7 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects { ...@@ -100,6 +117,7 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityPageObjects {
std::vector<PdfAccessibilityLinkInfo> links; std::vector<PdfAccessibilityLinkInfo> links;
std::vector<PdfAccessibilityImageInfo> images; std::vector<PdfAccessibilityImageInfo> images;
std::vector<PdfAccessibilityHighlightInfo> highlights; std::vector<PdfAccessibilityHighlightInfo> highlights;
std::vector<PdfAccessibilityTextFieldInfo> text_fields;
}; };
} // namespace ppapi } // namespace ppapi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment