0

[unseasoned-pdf] Replace usage of PdfAccessibilityPageObjects

PdfAccessibilityPageObjects is a Pepper struct. The replacement ensures
that PdfAccessibilityPageObjects is scoped to parts specific to the
Pepper implementation.

Meanwhile, update comment styles to use backticks instead of pipes.

Bug: 1144444
Change-Id: I49ec0f19bbf937a5d856fef1fd444646bc549c19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3057841
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906591}
This commit is contained in:
Daniel Hosseinian
2021-07-29 06:03:20 +00:00
committed by Chromium LUCI CQ
parent 377edb30b8
commit 364172cd21
7 changed files with 405 additions and 320 deletions

@ -48,10 +48,6 @@ const float kHeadingFontSizeRatio = 1.2f;
// page for that line spacing to be considered a paragraph break.
const float kParagraphLineSpacingRatio = 1.2f;
gfx::RectF PpFloatRectToGfxRectF(const PP_FloatRect& r) {
return gfx::RectF(r.point.x, r.point.y, r.size.width, r.size.height);
}
// This class is used as part of our heuristic to determine which text runs live
// on the same "line". As we process runs, we keep a weighted average of the
// top and bottom coordinates of the line, and if a new run falls within that
@ -221,7 +217,7 @@ bool BreakParagraph(
}
ui::AXNode* GetStaticTextNodeFromNode(ui::AXNode* node) {
// Returns the appropriate static text node given |node|'s type.
// Returns the appropriate static text node given `node`'s type.
// Returns nullptr if there is no appropriate static text node.
if (!node)
return nullptr;
@ -272,6 +268,11 @@ bool CompareTextRuns(const T& a, const T& b) {
return a.text_run_index < b.text_run_index;
}
template <typename T>
bool CompareTextRunsWithRange(const T& a, const T& b) {
return a.text_range.index < b.text_range.index;
}
template <typename T>
bool IsObjectInTextRun(const std::vector<T>& objects,
uint32_t object_index,
@ -280,6 +281,14 @@ bool IsObjectInTextRun(const std::vector<T>& objects,
objects[object_index].text_run_index <= text_run_index);
}
template <typename T>
bool IsObjectWithRangeInTextRun(const std::vector<T>& objects,
uint32_t object_index,
size_t text_run_index) {
return (object_index < objects.size() &&
objects[object_index].text_range.index <= text_run_index);
}
size_t NormalizeTextRunIndex(uint32_t object_end_text_run_index,
size_t current_text_run_index) {
return std::max<size_t>(
@ -335,17 +344,14 @@ ui::AXNodeData* CreateNode(
return node_ptr;
}
ax::mojom::Role GetRoleForButtonType(PP_PrivateButtonType button_type) {
ax::mojom::Role GetRoleForButtonType(chrome_pdf::ButtonType button_type) {
switch (button_type) {
case PP_PrivateButtonType::PP_PRIVATEBUTTON_RADIOBUTTON:
case chrome_pdf::ButtonType::kRadioButton:
return ax::mojom::Role::kRadioButton;
case PP_PrivateButtonType::PP_PRIVATEBUTTON_CHECKBOX:
case chrome_pdf::ButtonType::kCheckBox:
return ax::mojom::Role::kCheckBox;
case PP_PrivateButtonType::PP_PRIVATEBUTTON_PUSHBUTTON:
case chrome_pdf::ButtonType::kPushButton:
return ax::mojom::Role::kButton;
default:
NOTREACHED();
return ax::mojom::Role::kNone;
}
}
@ -354,7 +360,7 @@ class PdfAccessibilityTreeBuilder {
explicit PdfAccessibilityTreeBuilder(
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects,
const chrome_pdf::AccessibilityPageObjects& page_objects,
const gfx::RectF& page_bounds,
uint32_t page_index,
ui::AXNodeData* page_node,
@ -410,16 +416,17 @@ class PdfAccessibilityTreeBuilder {
page_node_->child_ids.push_back(para_node->id);
}
// If the |text_run_index| is less than or equal to the link's
// text_run_index, then push the link node in the paragraph.
if (IsObjectInTextRun(links_, current_link_index_, text_run_index)) {
// If the `text_run_index` is less than or equal to the link's
// `text_run_index`, then push the link node in the paragraph.
if (IsObjectWithRangeInTextRun(links_, current_link_index_,
text_run_index)) {
FinishStaticNode(&static_text_node, &static_text);
const ppapi::PdfAccessibilityLinkInfo& link =
const chrome_pdf::AccessibilityLinkInfo& link =
links_[current_link_index_++];
AddLinkToParaNode(link, para_node, &previous_on_line_node,
&text_run_index);
if (link.text_run_count == 0)
if (link.text_range.count == 0)
continue;
} else if (IsObjectInTextRun(images_, current_image_index_,
@ -428,8 +435,8 @@ class PdfAccessibilityTreeBuilder {
AddImageToParaNode(images_[current_image_index_++], para_node,
&text_run_index);
continue;
} else if (IsObjectInTextRun(highlights_, current_highlight_index_,
text_run_index)) {
} else if (IsObjectWithRangeInTextRun(
highlights_, current_highlight_index_, text_run_index)) {
FinishStaticNode(&static_text_node, &static_text);
AddHighlightToParaNode(highlights_[current_highlight_index_++],
para_node, &previous_on_line_node,
@ -546,7 +553,7 @@ class PdfAccessibilityTreeBuilder {
para_node->AddBoolAttribute(ax::mojom::BoolAttribute::kIsLineBreakingObject,
true);
// If font size exceeds the |heading_font_size_threshold_|, then classify
// If font size exceeds the `heading_font_size_threshold_`, then classify
// it as a Heading.
if (heading_font_size_threshold_ > 0 &&
font_size > heading_font_size_threshold_) {
@ -614,7 +621,8 @@ class PdfAccessibilityTreeBuilder {
return inline_text_box_node;
}
ui::AXNodeData* CreateLinkNode(const ppapi::PdfAccessibilityLinkInfo& link) {
ui::AXNodeData* CreateLinkNode(
const chrome_pdf::AccessibilityLinkInfo& link) {
ui::AXNodeData* link_node =
CreateNode(ax::mojom::Role::kLink, ax::mojom::Restriction::kReadOnly,
render_accessibility_, nodes_);
@ -622,7 +630,7 @@ class PdfAccessibilityTreeBuilder {
link_node->AddStringAttribute(ax::mojom::StringAttribute::kUrl, link.url);
link_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
std::string());
link_node->relative_bounds.bounds = PpFloatRectToGfxRectF(link.bounds);
link_node->relative_bounds.bounds = link.bounds;
node_id_to_annotation_info_->emplace(
link_node->id,
PdfAccessibilityTree::AnnotationInfo(page_index_, link.index_in_page));
@ -631,7 +639,7 @@ class PdfAccessibilityTreeBuilder {
}
ui::AXNodeData* CreateImageNode(
const ppapi::PdfAccessibilityImageInfo& image) {
const chrome_pdf::AccessibilityImageInfo& image) {
ui::AXNodeData* image_node =
CreateNode(ax::mojom::Role::kImage, ax::mojom::Restriction::kReadOnly,
render_accessibility_, nodes_);
@ -644,12 +652,12 @@ class PdfAccessibilityTreeBuilder {
image_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
image.alt_text);
}
image_node->relative_bounds.bounds = PpFloatRectToGfxRectF(image.bounds);
image_node->relative_bounds.bounds = image.bounds;
return image_node;
}
ui::AXNodeData* CreateHighlightNode(
const ppapi::PdfAccessibilityHighlightInfo& highlight) {
const chrome_pdf::AccessibilityHighlightInfo& highlight) {
ui::AXNodeData* highlight_node = CreateNode(
ax::mojom::Role::kPdfActionableHighlight,
ax::mojom::Restriction::kReadOnly, render_accessibility_, nodes_);
@ -659,8 +667,7 @@ class PdfAccessibilityTreeBuilder {
l10n_util::GetStringUTF8(IDS_AX_ROLE_DESCRIPTION_PDF_HIGHLIGHT));
highlight_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
std::string());
highlight_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(highlight.bounds);
highlight_node->relative_bounds.bounds = highlight.bounds;
highlight_node->AddIntAttribute(ax::mojom::IntAttribute::kBackgroundColor,
highlight.color);
@ -668,7 +675,7 @@ class PdfAccessibilityTreeBuilder {
}
ui::AXNodeData* CreatePopupNoteNode(
const ppapi::PdfAccessibilityHighlightInfo& highlight) {
const chrome_pdf::AccessibilityHighlightInfo& highlight) {
ui::AXNodeData* popup_note_node =
CreateNode(ax::mojom::Role::kNote, ax::mojom::Restriction::kReadOnly,
render_accessibility_, nodes_);
@ -676,8 +683,7 @@ class PdfAccessibilityTreeBuilder {
popup_note_node->AddStringAttribute(
ax::mojom::StringAttribute::kRoleDescription,
l10n_util::GetStringUTF8(IDS_AX_ROLE_DESCRIPTION_PDF_POPUP_NOTE));
popup_note_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(highlight.bounds);
popup_note_node->relative_bounds.bounds = highlight.bounds;
ui::AXNodeData* static_popup_note_text_node = CreateNode(
ax::mojom::Role::kStaticText, ax::mojom::Restriction::kReadOnly,
@ -686,8 +692,7 @@ class PdfAccessibilityTreeBuilder {
static_popup_note_text_node->SetNameFrom(ax::mojom::NameFrom::kContents);
static_popup_note_text_node->AddStringAttribute(
ax::mojom::StringAttribute::kName, highlight.note_text);
static_popup_note_text_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(highlight.bounds);
static_popup_note_text_node->relative_bounds.bounds = highlight.bounds;
popup_note_node->child_ids.push_back(static_popup_note_text_node->id);
@ -695,7 +700,7 @@ class PdfAccessibilityTreeBuilder {
}
ui::AXNodeData* CreateTextFieldNode(
const ppapi::PdfAccessibilityTextFieldInfo& text_field) {
const chrome_pdf::AccessibilityTextFieldInfo& text_field) {
ax::mojom::Restriction restriction = text_field.is_read_only
? ax::mojom::Restriction::kReadOnly
: ax::mojom::Restriction::kNone;
@ -712,13 +717,12 @@ class PdfAccessibilityTreeBuilder {
text_field_node->AddState(ax::mojom::State::kRequired);
if (text_field.is_password)
text_field_node->AddState(ax::mojom::State::kProtected);
text_field_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(text_field.bounds);
text_field_node->relative_bounds.bounds = text_field.bounds;
return text_field_node;
}
ui::AXNodeData* CreateButtonNode(
const ppapi::PdfAccessibilityButtonInfo& button) {
const chrome_pdf::AccessibilityButtonInfo& button) {
ax::mojom::Restriction restriction = button.is_read_only
? ax::mojom::Restriction::kReadOnly
: ax::mojom::Restriction::kNone;
@ -729,8 +733,8 @@ class PdfAccessibilityTreeBuilder {
button.name);
button_node->AddState(ax::mojom::State::kFocusable);
if (button.type == PP_PRIVATEBUTTON_RADIOBUTTON ||
button.type == PP_PRIVATEBUTTON_CHECKBOX) {
if (button.type == chrome_pdf::ButtonType::kRadioButton ||
button.type == chrome_pdf::ButtonType::kCheckBox) {
ax::mojom::CheckedState checkedState =
button.is_checked ? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kNone;
@ -743,12 +747,12 @@ class PdfAccessibilityTreeBuilder {
button.control_index + 1);
}
button_node->relative_bounds.bounds = PpFloatRectToGfxRectF(button.bounds);
button_node->relative_bounds.bounds = button.bounds;
return button_node;
}
ui::AXNodeData* CreateListboxOptionNode(
const ppapi::PdfAccessibilityChoiceFieldOptionInfo& choice_field_option,
const chrome_pdf::AccessibilityChoiceFieldOptionInfo& choice_field_option,
ax::mojom::Restriction restriction) {
ui::AXNodeData* listbox_option_node =
CreateNode(ax::mojom::Role::kListBoxOption, restriction,
@ -763,7 +767,7 @@ class PdfAccessibilityTreeBuilder {
}
ui::AXNodeData* CreateListboxNode(
const ppapi::PdfAccessibilityChoiceFieldInfo& choice_field,
const chrome_pdf::AccessibilityChoiceFieldInfo& choice_field,
ui::AXNodeData* control_node) {
ax::mojom::Restriction restriction = choice_field.is_read_only
? ax::mojom::Restriction::kReadOnly
@ -771,13 +775,13 @@ class PdfAccessibilityTreeBuilder {
ui::AXNodeData* listbox_node = CreateNode(
ax::mojom::Role::kListBox, restriction, render_accessibility_, nodes_);
if (choice_field.type != PP_PRIVATECHOICEFIELD_COMBOBOX) {
if (choice_field.type != chrome_pdf::ChoiceFieldType::kComboBox) {
listbox_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
choice_field.name);
}
ui::AXNodeData* first_selected_option = nullptr;
for (const ppapi::PdfAccessibilityChoiceFieldOptionInfo& option :
for (const chrome_pdf::AccessibilityChoiceFieldOptionInfo& option :
choice_field.options) {
ui::AXNodeData* listbox_option_node =
CreateListboxOptionNode(option, restriction);
@ -785,9 +789,9 @@ class PdfAccessibilityTreeBuilder {
ax::mojom::BoolAttribute::kSelected)) {
first_selected_option = listbox_option_node;
}
// TODO(bug 1030242): add |listbox_option_node| specific bounds here.
listbox_option_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(choice_field.bounds);
// TODO(crbug.com/1030242): Add `listbox_option_node` specific bounds
// here.
listbox_option_node->relative_bounds.bounds = choice_field.bounds;
listbox_node->child_ids.push_back(listbox_option_node->id);
}
@ -800,13 +804,12 @@ class PdfAccessibilityTreeBuilder {
if (choice_field.is_multi_select)
listbox_node->AddState(ax::mojom::State::kMultiselectable);
listbox_node->AddState(ax::mojom::State::kFocusable);
listbox_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(choice_field.bounds);
listbox_node->relative_bounds.bounds = choice_field.bounds;
return listbox_node;
}
ui::AXNodeData* CreateComboboxInputNode(
const ppapi::PdfAccessibilityChoiceFieldInfo& choice_field,
const chrome_pdf::AccessibilityChoiceFieldInfo& choice_field,
ax::mojom::Restriction restriction) {
ax::mojom::Role input_role = choice_field.has_editable_text_box
? ax::mojom::Role::kTextFieldWithComboBox
@ -815,7 +818,7 @@ class PdfAccessibilityTreeBuilder {
CreateNode(input_role, restriction, render_accessibility_, nodes_);
combobox_input_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
choice_field.name);
for (const ppapi::PdfAccessibilityChoiceFieldOptionInfo& option :
for (const chrome_pdf::AccessibilityChoiceFieldOptionInfo& option :
choice_field.options) {
if (option.is_selected) {
combobox_input_node->AddStringAttribute(
@ -825,13 +828,12 @@ class PdfAccessibilityTreeBuilder {
}
combobox_input_node->AddState(ax::mojom::State::kFocusable);
combobox_input_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(choice_field.bounds);
combobox_input_node->relative_bounds.bounds = choice_field.bounds;
return combobox_input_node;
}
ui::AXNodeData* CreateComboboxNode(
const ppapi::PdfAccessibilityChoiceFieldInfo& choice_field) {
const chrome_pdf::AccessibilityChoiceFieldInfo& choice_field) {
ax::mojom::Restriction restriction = choice_field.is_read_only
? ax::mojom::Restriction::kReadOnly
: ax::mojom::Restriction::kNone;
@ -848,17 +850,18 @@ class PdfAccessibilityTreeBuilder {
combobox_node->child_ids.push_back(input_element->id);
combobox_node->child_ids.push_back(list_element->id);
combobox_node->AddState(ax::mojom::State::kFocusable);
combobox_node->relative_bounds.bounds =
PpFloatRectToGfxRectF(choice_field.bounds);
combobox_node->relative_bounds.bounds = choice_field.bounds;
return combobox_node;
}
ui::AXNodeData* CreateChoiceFieldNode(
const ppapi::PdfAccessibilityChoiceFieldInfo& choice_field) {
if (choice_field.type == PP_PRIVATECHOICEFIELD_LISTBOX)
return CreateListboxNode(choice_field, nullptr);
return CreateComboboxNode(choice_field);
const chrome_pdf::AccessibilityChoiceFieldInfo& choice_field) {
switch (choice_field.type) {
case chrome_pdf::ChoiceFieldType::kListBox:
return CreateListboxNode(choice_field, /*control_node=*/nullptr);
case chrome_pdf::ChoiceFieldType::kComboBox:
return CreateComboboxNode(choice_field);
}
}
void AddTextToAXNode(size_t start_text_run_index,
@ -942,7 +945,7 @@ class PdfAccessibilityTreeBuilder {
// present. In the tree for both overlapping scenarios, link `A` would
// appear first in the tree and link `B` after it.
// If |object_text_run_count| > 0, then the object is part of the page text.
// If `object_text_run_count` > 0, then the object is part of the page text.
// Make the text runs contained by the object children of the object node.
size_t end_text_run_index = object_text_run_index + object_text_run_count;
uint32_t object_end_text_run_index =
@ -957,30 +960,30 @@ class PdfAccessibilityTreeBuilder {
NormalizeTextRunIndex(object_end_text_run_index, *text_run_index);
}
void AddLinkToParaNode(const ppapi::PdfAccessibilityLinkInfo& link,
void AddLinkToParaNode(const chrome_pdf::AccessibilityLinkInfo& link,
ui::AXNodeData* para_node,
ui::AXNodeData** previous_on_line_node,
size_t* text_run_index) {
ui::AXNodeData* link_node = CreateLinkNode(link);
para_node->child_ids.push_back(link_node->id);
// If |link.text_run_count| == 0, then the link is not part of the page
// If `link.text_range.count` == 0, then the link is not part of the page
// text. Push it ahead of the current text run.
if (link.text_run_count == 0) {
if (link.text_range.count == 0) {
--(*text_run_index);
return;
}
// Make the text runs contained by the link children of
// the link node.
AddTextToObjectNode(link.text_run_index, link.text_run_count, link_node,
AddTextToObjectNode(link.text_range.index, link.text_range.count, link_node,
para_node, previous_on_line_node, text_run_index);
}
void AddImageToParaNode(const ppapi::PdfAccessibilityImageInfo& image,
void AddImageToParaNode(const chrome_pdf::AccessibilityImageInfo& image,
ui::AXNodeData* para_node,
size_t* text_run_index) {
// If the |text_run_index| is less than or equal to the image's text run
// If the `text_run_index` is less than or equal to the image's text run
// index, then push the image ahead of the current text run.
ui::AXNodeData* image_node = CreateImageNode(image);
para_node->child_ids.push_back(image_node->id);
@ -988,7 +991,7 @@ class PdfAccessibilityTreeBuilder {
}
void AddHighlightToParaNode(
const ppapi::PdfAccessibilityHighlightInfo& highlight,
const chrome_pdf::AccessibilityHighlightInfo& highlight,
ui::AXNodeData* para_node,
ui::AXNodeData** previous_on_line_node,
size_t* text_run_index) {
@ -997,7 +1000,7 @@ class PdfAccessibilityTreeBuilder {
// Make the text runs contained by the highlight children of
// the highlight node.
AddTextToObjectNode(highlight.text_run_index, highlight.text_run_count,
AddTextToObjectNode(highlight.text_range.index, highlight.text_range.count,
highlight_node, para_node, previous_on_line_node,
text_run_index);
@ -1008,20 +1011,20 @@ class PdfAccessibilityTreeBuilder {
}
void AddTextFieldToParaNode(
const ppapi::PdfAccessibilityTextFieldInfo& text_field,
const chrome_pdf::AccessibilityTextFieldInfo& text_field,
ui::AXNodeData* para_node,
size_t* text_run_index) {
// If the |text_run_index| is less than or equal to the text_field's text
// If the `text_run_index` is less than or equal to the text_field's text
// run index, then push the text_field ahead of the current text run.
ui::AXNodeData* text_field_node = CreateTextFieldNode(text_field);
para_node->child_ids.push_back(text_field_node->id);
--(*text_run_index);
}
void AddButtonToParaNode(const ppapi::PdfAccessibilityButtonInfo& button,
void AddButtonToParaNode(const chrome_pdf::AccessibilityButtonInfo& button,
ui::AXNodeData* para_node,
size_t* text_run_index) {
// If the |text_run_index| is less than or equal to the button's text
// If the `text_run_index` is less than or equal to the button's text
// run index, then push the button ahead of the current text run.
ui::AXNodeData* button_node = CreateButtonNode(button);
para_node->child_ids.push_back(button_node->id);
@ -1029,10 +1032,10 @@ class PdfAccessibilityTreeBuilder {
}
void AddChoiceFieldToParaNode(
const ppapi::PdfAccessibilityChoiceFieldInfo& choice_field,
const chrome_pdf::AccessibilityChoiceFieldInfo& choice_field,
ui::AXNodeData* para_node,
size_t* text_run_index) {
// If the |text_run_index| is less than or equal to the choice_field's text
// If the `text_run_index` is less than or equal to the choice_field's text
// run index, then push the choice_field ahead of the current text run.
ui::AXNodeData* choice_field_node = CreateChoiceFieldNode(choice_field);
para_node->child_ids.push_back(choice_field_node->id);
@ -1098,17 +1101,17 @@ class PdfAccessibilityTreeBuilder {
std::vector<uint32_t> text_run_start_indices_;
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs_;
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars_;
const std::vector<ppapi::PdfAccessibilityLinkInfo>& links_;
const std::vector<chrome_pdf::AccessibilityLinkInfo>& links_;
uint32_t current_link_index_ = 0;
const std::vector<ppapi::PdfAccessibilityImageInfo>& images_;
const std::vector<chrome_pdf::AccessibilityImageInfo>& images_;
uint32_t current_image_index_ = 0;
const std::vector<ppapi::PdfAccessibilityHighlightInfo>& highlights_;
const std::vector<chrome_pdf::AccessibilityHighlightInfo>& highlights_;
uint32_t current_highlight_index_ = 0;
const std::vector<ppapi::PdfAccessibilityTextFieldInfo>& text_fields_;
const std::vector<chrome_pdf::AccessibilityTextFieldInfo>& text_fields_;
uint32_t current_text_field_index_ = 0;
const std::vector<ppapi::PdfAccessibilityButtonInfo>& buttons_;
const std::vector<chrome_pdf::AccessibilityButtonInfo>& buttons_;
uint32_t current_button_index_ = 0;
const std::vector<ppapi::PdfAccessibilityChoiceFieldInfo>& choice_fields_;
const std::vector<chrome_pdf::AccessibilityChoiceFieldInfo>& choice_fields_;
uint32_t current_choice_field_index_ = 0;
const gfx::RectF& page_bounds_;
uint32_t page_index_;
@ -1144,7 +1147,7 @@ PdfAccessibilityTree::~PdfAccessibilityTree() {
bool PdfAccessibilityTree::IsDataFromPluginValid(
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects) {
const chrome_pdf::AccessibilityPageObjects& page_objects) {
base::CheckedNumeric<uint32_t> char_length = 0;
for (const chrome_pdf::AccessibilityTextRunInfo& text_run : text_runs)
char_length += text_run.len;
@ -1152,82 +1155,85 @@ bool PdfAccessibilityTree::IsDataFromPluginValid(
if (!char_length.IsValid() || char_length.ValueOrDie() != chars.size())
return false;
const std::vector<ppapi::PdfAccessibilityLinkInfo>& links =
const std::vector<chrome_pdf::AccessibilityLinkInfo>& links =
page_objects.links;
if (!std::is_sorted(links.begin(), links.end(),
CompareTextRuns<ppapi::PdfAccessibilityLinkInfo>)) {
if (!std::is_sorted(
links.begin(), links.end(),
CompareTextRunsWithRange<chrome_pdf::AccessibilityLinkInfo>)) {
return false;
}
// Text run index of a |link| is out of bounds if it exceeds the size of
// |text_runs|. The index denotes the position of the link relative to the
// text runs. The index value equal to the size of |text_runs| indicates that
// Text run index of a `link` is out of bounds if it exceeds the size of
// `text_runs`. The index denotes the position of the link relative to the
// text runs. The index value equal to the size of `text_runs` indicates that
// the link should be after the last text run.
// |index_in_page| of every |link| should be with in the range of total number
// of links, which is size of |links|.
for (const ppapi::PdfAccessibilityLinkInfo& link : links) {
base::CheckedNumeric<size_t> index = link.text_run_index;
index += link.text_run_count;
// `index_in_page` of every `link` should be with in the range of total number
// of links, which is size of `links`.
for (const chrome_pdf::AccessibilityLinkInfo& link : links) {
base::CheckedNumeric<size_t> index = link.text_range.index;
index += link.text_range.count;
if (!index.IsValid() || index.ValueOrDie() > text_runs.size() ||
link.index_in_page >= links.size()) {
return false;
}
}
const std::vector<ppapi::PdfAccessibilityImageInfo>& images =
const std::vector<chrome_pdf::AccessibilityImageInfo>& images =
page_objects.images;
if (!std::is_sorted(images.begin(), images.end(),
CompareTextRuns<ppapi::PdfAccessibilityImageInfo>)) {
CompareTextRuns<chrome_pdf::AccessibilityImageInfo>)) {
return false;
}
// Text run index of an |image| works on the same logic as the text run index
// of a |link| as mentioned above.
for (const ppapi::PdfAccessibilityImageInfo& image : images) {
// Text run index of an `image` works on the same logic as the text run index
// of a `link` as described above.
for (const chrome_pdf::AccessibilityImageInfo& image : images) {
if (image.text_run_index > text_runs.size())
return false;
}
const std::vector<ppapi::PdfAccessibilityHighlightInfo>& highlights =
const std::vector<chrome_pdf::AccessibilityHighlightInfo>& highlights =
page_objects.highlights;
if (!std::is_sorted(highlights.begin(), highlights.end(),
CompareTextRuns<ppapi::PdfAccessibilityHighlightInfo>)) {
if (!std::is_sorted(
highlights.begin(), highlights.end(),
CompareTextRunsWithRange<chrome_pdf::AccessibilityHighlightInfo>)) {
return false;
}
// Since highlights also span across text runs similar to links, the
// validation method is the same.
// |index_in_page| of a |highlight| follows the same index validation rules
// `index_in_page` of a `highlight` follows the same index validation rules
// as of links.
for (const auto& highlight : highlights) {
base::CheckedNumeric<size_t> index = highlight.text_run_index;
index += highlight.text_run_count;
base::CheckedNumeric<size_t> index = highlight.text_range.index;
index += highlight.text_range.count;
if (!index.IsValid() || index.ValueOrDie() > text_runs.size() ||
highlight.index_in_page >= highlights.size()) {
return false;
}
}
const std::vector<ppapi::PdfAccessibilityTextFieldInfo>& text_fields =
const std::vector<chrome_pdf::AccessibilityTextFieldInfo>& text_fields =
page_objects.form_fields.text_fields;
if (!std::is_sorted(text_fields.begin(), text_fields.end(),
CompareTextRuns<ppapi::PdfAccessibilityTextFieldInfo>)) {
if (!std::is_sorted(
text_fields.begin(), text_fields.end(),
CompareTextRuns<chrome_pdf::AccessibilityTextFieldInfo>)) {
return false;
}
// Text run index of an |text_field| works on the same logic as the text run
// index of a |link| as mentioned above.
// |index_in_page| of a |text_field| follows the same index validation rules
// Text run index of an `text_field` works on the same logic as the text run
// index of a `link` as mentioned above.
// `index_in_page` of a `text_field` follows the same index validation rules
// as of links.
for (const ppapi::PdfAccessibilityTextFieldInfo& text_field : text_fields) {
for (const chrome_pdf::AccessibilityTextFieldInfo& text_field : text_fields) {
if (text_field.text_run_index > text_runs.size() ||
text_field.index_in_page >= text_fields.size()) {
return false;
}
}
const std::vector<ppapi::PdfAccessibilityChoiceFieldInfo>& choice_fields =
const std::vector<chrome_pdf::AccessibilityChoiceFieldInfo>& choice_fields =
page_objects.form_fields.choice_fields;
if (!std::is_sorted(
choice_fields.begin(), choice_fields.end(),
CompareTextRuns<ppapi::PdfAccessibilityChoiceFieldInfo>)) {
CompareTextRuns<chrome_pdf::AccessibilityChoiceFieldInfo>)) {
return false;
}
for (const auto& choice_field : choice_fields) {
@ -1241,24 +1247,22 @@ bool PdfAccessibilityTree::IsDataFromPluginValid(
}
// The type should be valid.
if (choice_field.type < PP_PRIVATECHOICEFIELD_LISTBOX ||
choice_field.type > PP_PRIVATECHOICEFIELD_LAST) {
if (choice_field.type < chrome_pdf::ChoiceFieldType::kMinValue ||
choice_field.type > chrome_pdf::ChoiceFieldType::kMaxValue) {
return false;
}
}
const std::vector<ppapi::PdfAccessibilityButtonInfo>& buttons =
const std::vector<chrome_pdf::AccessibilityButtonInfo>& buttons =
page_objects.form_fields.buttons;
if (!std::is_sorted(
buttons.begin(), buttons.end(),
CompareTextRuns<ppapi::PdfAccessibilityButtonInfo>)) {
if (!std::is_sorted(buttons.begin(), buttons.end(),
CompareTextRuns<chrome_pdf::AccessibilityButtonInfo>)) {
return false;
}
for (const ppapi::PdfAccessibilityButtonInfo& button :
buttons) {
// Text run index of an |button| works on the same logic as the text run
// index of a |link| as mentioned above.
// |index_in_page| of a |button| follows the same index validation rules as
for (const chrome_pdf::AccessibilityButtonInfo& button : buttons) {
// Text run index of an `button` works on the same logic as the text run
// index of a `link` as mentioned above.
// `index_in_page` of a `button` follows the same index validation rules as
// of links.
if (button.text_run_index > text_runs.size() ||
button.index_in_page >= buttons.size()) {
@ -1266,15 +1270,15 @@ bool PdfAccessibilityTree::IsDataFromPluginValid(
}
// The type should be valid.
if (button.type < PP_PRIVATEBUTTON_FIRST ||
button.type > PP_PRIVATEBUTTON_LAST) {
if (button.type < chrome_pdf::ButtonType::kMinValue ||
button.type > chrome_pdf::ButtonType::kMaxValue) {
return false;
}
// For radio button or checkbox, value of |button.control_index| should
// always be less than |button.control_count|.
if ((button.type == PP_PrivateButtonType::PP_PRIVATEBUTTON_CHECKBOX ||
button.type == PP_PrivateButtonType::PP_PRIVATEBUTTON_RADIOBUTTON) &&
// For radio button or checkbox, value of `button.control_index` should
// always be less than `button.control_count`.
if ((button.type == chrome_pdf::ButtonType::kCheckBox ||
button.type == chrome_pdf::ButtonType::kRadioButton) &&
(button.control_index >= button.control_count)) {
return false;
}
@ -1336,7 +1340,7 @@ void PdfAccessibilityTree::SetAccessibilityPageInfo(
const chrome_pdf::AccessibilityPageInfo& page_info,
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects) {
const chrome_pdf::AccessibilityPageObjects& page_objects) {
// Outdated calls are ignored.
uint32_t page_index = page_info.page_index;
if (page_index != next_page_index_)
@ -1347,8 +1351,8 @@ void PdfAccessibilityTree::SetAccessibilityPageInfo(
if (!render_accessibility)
return;
// If unsanitized data is found, don't trust the PPAPI process sending it and
// stop creation of the accessibility tree.
// If unsanitized data is found, don't trust it and stop creation of the
// accessibility tree.
if (!invalid_plugin_message_received_) {
invalid_plugin_message_received_ =
!IsDataFromPluginValid(text_runs, chars, page_objects);
@ -1386,7 +1390,7 @@ void PdfAccessibilityTree::AddPageContent(
uint32_t page_index,
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects) {
const chrome_pdf::AccessibilityPageObjects& page_objects) {
DCHECK(page_node);
content::RenderAccessibility* render_accessibility =
GetRenderAccessibilityIfEnabled();
@ -1513,7 +1517,7 @@ PdfAccessibilityTree::MakeTransformFromViewInfo() const {
double applicable_scale_factor =
content::RenderThread::Get()->IsUseZoomForDSF() ? scale_ : 1;
auto transform = std::make_unique<gfx::Transform>();
// |scroll_| represents the offset from which PDF content starts. It is the
// `scroll_` represents the offset from which PDF content starts. It is the
// height of the PDF toolbar and the width of sidenav in pixels if it is open.
// Sizes of PDF toolbar and sidenav do not change with zoom.
transform->Scale(applicable_scale_factor, applicable_scale_factor);

@ -25,6 +25,7 @@ namespace chrome_pdf {
struct AccessibilityCharInfo;
struct AccessibilityDocInfo;
struct AccessibilityPageInfo;
struct AccessibilityPageObjects;
struct AccessibilityTextRunInfo;
struct AccessibilityViewportInfo;
} // namespace chrome_pdf
@ -52,7 +53,7 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource,
static bool IsDataFromPluginValid(
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects);
const chrome_pdf::AccessibilityPageObjects& page_objects);
// Stores the page index and annotation index in the page.
struct AnnotationInfo {
@ -72,14 +73,14 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource,
const chrome_pdf::AccessibilityPageInfo& page_info,
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects);
const chrome_pdf::AccessibilityPageObjects& page_objects);
void HandleAction(const PP_PdfAccessibilityActionData& action_data);
absl::optional<AnnotationInfo> GetPdfAnnotationInfoFromAXNode(
int32_t ax_node_id) const;
// Given the AXNode and the character offset within the AXNode, finds the
// respective page index and character index within the page. Returns
// false if the |node| is not a valid static text or inline text box
// false if the `node` is not a valid static text or inline text box
// AXNode. Used to find the character offsets of selection.
bool FindCharacterOffset(const ui::AXNode& node,
uint32_t char_offset_in_node,
@ -131,7 +132,7 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource,
uint32_t page_index,
const std::vector<chrome_pdf::AccessibilityTextRunInfo>& text_runs,
const std::vector<chrome_pdf::AccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects);
const chrome_pdf::AccessibilityPageObjects& page_objects);
// Clears the local cache of node data used to create the tree so that
// replacement node data can be introduced.
@ -144,18 +145,18 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource,
ui::AXTreeData tree_data_;
ui::AXTree tree_;
// Unowned. Must outlive |this|.
// Unowned. Must outlive `this`.
PdfAccessibilityActionHandler* const action_handler_;
// |zoom_| signifies the zoom level set in for the browser content.
// |scale_| signifies the scale level set by user. Scale is applied
// `zoom_` signifies the zoom level set in for the browser content.
// `scale_` signifies the scale level set by user. Scale is applied
// by the OS while zoom is applied by the application. Higher scale
// values are usually set to increase the size of everything on screen.
// Preferred by people with blurry/low vision. |zoom_| and |scale_|
// Preferred by people with blurry/low vision. `zoom_` and `scale_`
// both help us increase/descrease the size of content on screen.
// From PDF plugin we receive all the data in logical pixels. Which is
// without the zoom and scale factor applied. We apply the |zoom_| and
// |scale_| to generate the final bounding boxes of elements in accessibility
// without the zoom and scale factor applied. We apply the `zoom_` and
// `scale_` to generate the final bounding boxes of elements in accessibility
// tree.
double zoom_ = 1.0;
double scale_ = 1.0;

@ -146,7 +146,7 @@ class PdfAccessibilityTreeTest : public content::RenderViewTest {
chrome_pdf::AccessibilityPageInfo page_info_;
std::vector<chrome_pdf::AccessibilityTextRunInfo> text_runs_;
std::vector<chrome_pdf::AccessibilityCharInfo> chars_;
ppapi::PdfAccessibilityPageObjects page_objects_;
chrome_pdf::AccessibilityPageObjects page_objects_;
};
TEST_F(PdfAccessibilityTreeTest, TestEmptyPDFPage) {
@ -230,26 +230,26 @@ TEST_F(PdfAccessibilityTreeTest, TestPdfAccessibilityTreeCreation) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
link.url = kChromiumTestUrl;
link.text_run_index = 0;
link.text_run_count = 1;
link.text_range.index = 0;
link.text_range.count = 1;
link.index_in_page = 0;
page_objects_.links.push_back(std::move(link));
}
{
ppapi::PdfAccessibilityImageInfo image;
image.bounds = PP_MakeFloatRectFromXYWH(8.0f, 9.0f, 2.0f, 1.0f);
chrome_pdf::AccessibilityImageInfo image;
image.bounds = gfx::RectF(8.0f, 9.0f, 2.0f, 1.0f);
image.alt_text = kTestAltText;
image.text_run_index = 2;
page_objects_.images.push_back(std::move(image));
}
{
ppapi::PdfAccessibilityImageInfo image;
image.bounds = PP_MakeFloatRectFromXYWH(11.0f, 14.0f, 5.0f, 8.0f);
chrome_pdf::AccessibilityImageInfo image;
image.bounds = gfx::RectF(11.0f, 14.0f, 5.0f, 8.0f);
image.text_run_index = 2;
page_objects_.images.push_back(std::move(image));
}
@ -345,21 +345,21 @@ TEST_F(PdfAccessibilityTreeTest, TestOverlappingAnnots) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
link.url = kChromiumTestUrl;
link.text_run_index = 0;
link.text_run_count = 3;
link.text_range.index = 0;
link.text_range.count = 3;
link.index_in_page = 0;
page_objects_.links.push_back(std::move(link));
}
{
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(1.0f, 2.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(1.0f, 2.0f, 5.0f, 6.0f);
link.url = kChromiumTestUrl;
link.text_run_index = 1;
link.text_run_count = 2;
link.text_range.index = 1;
link.text_range.count = 2;
link.index_in_page = 1;
page_objects_.links.push_back(std::move(link));
}
@ -440,10 +440,10 @@ TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
highlight.text_run_index = 0;
highlight.text_run_count = 2;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
highlight.text_range.index = 0;
highlight.text_range.count = 2;
highlight.index_in_page = 0;
highlight.color = kHighlightWhiteColor;
highlight.note_text = kPopupNoteText;
@ -545,8 +545,8 @@ TEST_F(PdfAccessibilityTreeTest, TestTextFieldNodeCreation) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityTextFieldInfo text_field;
text_field.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityTextFieldInfo text_field;
text_field.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
text_field.index_in_page = 0;
text_field.text_run_index = 2;
text_field.name = "Text Box";
@ -558,8 +558,8 @@ TEST_F(PdfAccessibilityTreeTest, TestTextFieldNodeCreation) {
}
{
ppapi::PdfAccessibilityTextFieldInfo text_field;
text_field.bounds = PP_MakeFloatRectFromXYWH(1.0f, 10.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityTextFieldInfo text_field;
text_field.bounds = gfx::RectF(1.0f, 10.0f, 5.0f, 6.0f);
text_field.index_in_page = 1;
text_field.text_run_index = 2;
text_field.name = "Text Box 2";
@ -671,8 +671,8 @@ TEST_F(PdfAccessibilityTreeTest, TestButtonNodeCreation) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityButtonInfo check_box;
check_box.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityButtonInfo check_box;
check_box.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
check_box.index_in_page = 0;
check_box.text_run_index = 2;
check_box.name = "Read Only Checkbox";
@ -681,13 +681,13 @@ TEST_F(PdfAccessibilityTreeTest, TestButtonNodeCreation) {
check_box.is_checked = true;
check_box.control_count = 1;
check_box.control_index = 0;
check_box.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_CHECKBOX;
check_box.type = chrome_pdf::ButtonType::kCheckBox;
page_objects_.form_fields.buttons.push_back(std::move(check_box));
}
{
ppapi::PdfAccessibilityButtonInfo radio_button;
radio_button.bounds = PP_MakeFloatRectFromXYWH(1.0f, 2.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityButtonInfo radio_button;
radio_button.bounds = gfx::RectF(1.0f, 2.0f, 5.0f, 6.0f);
radio_button.index_in_page = 1;
radio_button.text_run_index = 2;
radio_button.name = "Radio Button";
@ -696,13 +696,13 @@ TEST_F(PdfAccessibilityTreeTest, TestButtonNodeCreation) {
radio_button.is_checked = false;
radio_button.control_count = 2;
radio_button.control_index = 0;
radio_button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_RADIOBUTTON;
radio_button.type = chrome_pdf::ButtonType::kRadioButton;
page_objects_.form_fields.buttons.push_back(std::move(radio_button));
}
{
ppapi::PdfAccessibilityButtonInfo radio_button;
radio_button.bounds = PP_MakeFloatRectFromXYWH(1.0f, 3.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityButtonInfo radio_button;
radio_button.bounds = gfx::RectF(1.0f, 3.0f, 5.0f, 6.0f);
radio_button.index_in_page = 2;
radio_button.text_run_index = 2;
radio_button.name = "Radio Button";
@ -711,18 +711,18 @@ TEST_F(PdfAccessibilityTreeTest, TestButtonNodeCreation) {
radio_button.is_checked = true;
radio_button.control_count = 2;
radio_button.control_index = 1;
radio_button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_RADIOBUTTON;
radio_button.type = chrome_pdf::ButtonType::kRadioButton;
page_objects_.form_fields.buttons.push_back(std::move(radio_button));
}
{
ppapi::PdfAccessibilityButtonInfo push_button;
push_button.bounds = PP_MakeFloatRectFromXYWH(1.0f, 4.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityButtonInfo push_button;
push_button.bounds = gfx::RectF(1.0f, 4.0f, 5.0f, 6.0f);
push_button.index_in_page = 3;
push_button.text_run_index = 2;
push_button.name = "Push Button";
push_button.is_read_only = false;
push_button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_PUSHBUTTON;
push_button.type = chrome_pdf::ButtonType::kPushButton;
page_objects_.form_fields.buttons.push_back(std::move(push_button));
}
@ -877,17 +877,17 @@ TEST_F(PdfAccessibilityTreeTest, TestListboxNodeCreation) {
{1.0f, 10.0f, 5.0f, 6.0f}};
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
choice_field.index_in_page = 0;
choice_field.text_run_index = 2;
choice_field.type = PP_PRIVATECHOICEFIELD_LISTBOX;
choice_field.type = chrome_pdf::ChoiceFieldType::kListBox;
choice_field.name = "List Box";
choice_field.is_read_only = false;
choice_field.is_multi_select = true;
choice_field.has_editable_text_box = false;
for (const ListboxOptionInfo& expected_option : kExpectedOptions[0]) {
ppapi::PdfAccessibilityChoiceFieldOptionInfo choice_field_option;
chrome_pdf::AccessibilityChoiceFieldOptionInfo choice_field_option;
choice_field_option.name = expected_option.name;
choice_field_option.is_selected = expected_option.is_selected;
choice_field.options.push_back(std::move(choice_field_option));
@ -896,17 +896,17 @@ TEST_F(PdfAccessibilityTreeTest, TestListboxNodeCreation) {
}
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = PP_MakeFloatRectFromXYWH(1.0f, 10.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = gfx::RectF(1.0f, 10.0f, 5.0f, 6.0f);
choice_field.index_in_page = 1;
choice_field.text_run_index = 2;
choice_field.type = PP_PRIVATECHOICEFIELD_LISTBOX;
choice_field.type = chrome_pdf::ChoiceFieldType::kListBox;
choice_field.name = "Read Only List Box";
choice_field.is_read_only = true;
choice_field.is_multi_select = false;
choice_field.has_editable_text_box = false;
for (const ListboxOptionInfo& expected_option : kExpectedOptions[1]) {
ppapi::PdfAccessibilityChoiceFieldOptionInfo choice_field_option;
chrome_pdf::AccessibilityChoiceFieldOptionInfo choice_field_option;
choice_field_option.name = expected_option.name;
choice_field_option.is_selected = expected_option.is_selected;
choice_field.options.push_back(std::move(choice_field_option));
@ -1069,17 +1069,17 @@ TEST_F(PdfAccessibilityTreeTest, TestComboboxNodeCreation) {
{1.0f, 10.0f, 5.0f, 6.0f}};
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f);
choice_field.index_in_page = 0;
choice_field.text_run_index = 2;
choice_field.type = PP_PRIVATECHOICEFIELD_COMBOBOX;
choice_field.type = chrome_pdf::ChoiceFieldType::kComboBox;
choice_field.name = "Editable Combo Box";
choice_field.is_read_only = false;
choice_field.is_multi_select = true;
choice_field.has_editable_text_box = true;
for (const ComboboxOptionInfo& expected_option : kExpectedOptions[0]) {
ppapi::PdfAccessibilityChoiceFieldOptionInfo choice_field_option;
chrome_pdf::AccessibilityChoiceFieldOptionInfo choice_field_option;
choice_field_option.name = expected_option.name;
choice_field_option.is_selected = expected_option.is_selected;
choice_field.options.push_back(std::move(choice_field_option));
@ -1088,17 +1088,17 @@ TEST_F(PdfAccessibilityTreeTest, TestComboboxNodeCreation) {
}
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = PP_MakeFloatRectFromXYWH(1.0f, 10.0f, 5.0f, 6.0f);
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.bounds = gfx::RectF(1.0f, 10.0f, 5.0f, 6.0f);
choice_field.index_in_page = 1;
choice_field.text_run_index = 2;
choice_field.type = PP_PRIVATECHOICEFIELD_COMBOBOX;
choice_field.type = chrome_pdf::ChoiceFieldType::kComboBox;
choice_field.name = "Read Only Combo Box";
choice_field.is_read_only = true;
choice_field.is_multi_select = false;
choice_field.has_editable_text_box = false;
for (const ComboboxOptionInfo& expected_option : kExpectedOptions[1]) {
ppapi::PdfAccessibilityChoiceFieldOptionInfo choice_field_option;
chrome_pdf::AccessibilityChoiceFieldOptionInfo choice_field_option;
choice_field_option.name = expected_option.name;
choice_field_option.is_selected = expected_option.is_selected;
choice_field.options.push_back(std::move(choice_field_option));
@ -1308,11 +1308,11 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
link.url = kChromiumTestUrl;
link.text_run_index = 2;
link.text_run_count = 2;
link.text_range.index = 2;
link.text_range.count = 2;
link.index_in_page = 0;
page_objects_.links.push_back(std::move(link));
}
@ -1436,8 +1436,8 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) {
}
TEST_F(PdfAccessibilityTreeTest, TextRunsAndCharsMismatch) {
// |chars_| and |text_runs_| span over the same page text. They should denote
// the same page text size, but |text_runs_| is incorrect and only denotes 1
// `chars_` and `text_runs_` span over the same page text. They should denote
// the same page text size, but `text_runs_` is incorrect and only denotes 1
// of 2 text runs.
text_runs_.emplace_back(kFirstTextRun);
chars_.insert(chars_.end(), std::begin(kDummyCharsData),
@ -1471,19 +1471,19 @@ TEST_F(PdfAccessibilityTreeTest, UnsortedLinkVector) {
{
// Add first link in the vector.
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
link.text_run_index = 2;
link.text_run_count = 0;
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
link.text_range.index = 2;
link.text_range.count = 0;
page_objects_.links.push_back(std::move(link));
}
{
// Add second link in the vector.
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
link.text_run_index = 0;
link.text_run_count = 1;
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
link.text_range.index = 0;
link.text_range.count = 1;
page_objects_.links.push_back(std::move(link));
}
@ -1514,11 +1514,11 @@ TEST_F(PdfAccessibilityTreeTest, OutOfBoundLink) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityLinkInfo link;
link.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
link.text_run_index = 3;
chrome_pdf::AccessibilityLinkInfo link;
link.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
link.text_range.index = 3;
link.index_in_page = 0;
link.text_run_count = 0;
link.text_range.count = 0;
page_objects_.links.push_back(std::move(link));
}
@ -1550,16 +1550,16 @@ TEST_F(PdfAccessibilityTreeTest, UnsortedImageVector) {
{
// Add first image to the vector.
ppapi::PdfAccessibilityImageInfo image;
image.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
chrome_pdf::AccessibilityImageInfo image;
image.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
image.text_run_index = 1;
page_objects_.images.push_back(std::move(image));
}
{
// Add second image to the vector.
ppapi::PdfAccessibilityImageInfo image;
image.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
chrome_pdf::AccessibilityImageInfo image;
image.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
image.text_run_index = 0;
page_objects_.images.push_back(std::move(image));
}
@ -1591,8 +1591,8 @@ TEST_F(PdfAccessibilityTreeTest, OutOfBoundImage) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityImageInfo image;
image.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f);
chrome_pdf::AccessibilityImageInfo image;
image.bounds = gfx::RectF(0.0f, 0.0f, 0.0f, 0.0f);
image.text_run_index = 3;
page_objects_.images.push_back(std::move(image));
}
@ -1625,20 +1625,20 @@ TEST_F(PdfAccessibilityTreeTest, UnsortedHighlightVector) {
{
// Add first highlight in the vector.
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 1.0f, 1.0f);
highlight.text_run_index = 2;
highlight.text_run_count = 0;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.bounds = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f);
highlight.text_range.index = 2;
highlight.text_range.count = 0;
highlight.index_in_page = 0;
page_objects_.highlights.push_back(std::move(highlight));
}
{
// Add second highlight in the vector.
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.bounds = PP_MakeFloatRectFromXYWH(2.0f, 2.0f, 1.0f, 1.0f);
highlight.text_run_index = 0;
highlight.text_run_count = 1;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.bounds = gfx::RectF(2.0f, 2.0f, 1.0f, 1.0f);
highlight.text_range.index = 0;
highlight.text_range.count = 1;
highlight.index_in_page = 1;
page_objects_.highlights.push_back(std::move(highlight));
}
@ -1671,10 +1671,10 @@ TEST_F(PdfAccessibilityTreeTest, OutOfBoundHighlight) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.bounds = PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 1.0f, 1.0f);
highlight.text_run_index = 3;
highlight.text_run_count = 0;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.bounds = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f);
highlight.text_range.index = 3;
highlight.text_range.count = 0;
highlight.index_in_page = 0;
page_objects_.highlights.push_back(std::move(highlight));
}
@ -1806,20 +1806,20 @@ TEST_F(PdfAccessibilityTreeTest, TestClickActionDataConversion) {
std::end(kDummyCharsData));
{
ppapi::PdfAccessibilityLinkInfo link;
chrome_pdf::AccessibilityLinkInfo link;
link.url = kChromiumTestUrl;
link.text_run_index = 0;
link.text_run_count = 1;
link.text_range.index = 0;
link.text_range.count = 1;
link.bounds = {{0, 0}, {10, 10}};
link.index_in_page = 0;
page_objects_.links.push_back(std::move(link));
}
{
ppapi::PdfAccessibilityLinkInfo link;
chrome_pdf::AccessibilityLinkInfo link;
link.url = kChromiumTestUrl;
link.text_run_index = 1;
link.text_run_count = 1;
link.text_range.index = 1;
link.text_range.count = 1;
link.bounds = {{10, 10}, {10, 10}};
link.index_in_page = 1;
page_objects_.links.push_back(std::move(link));

@ -29,8 +29,8 @@ const chrome_pdf::AccessibilityCharInfo kDummyCharsData[] = {
};
TEST(PdfAccessibilityTreeUnitTest, TextRunsAndCharsMismatch) {
// |chars| and |text_runs| span over the same page text. They should denote
// the same page text size, but |text_runs_| is incorrect and only denotes 1
// `chars` and `text_runs` span over the same page text. They should denote
// the same page text size, but `text_runs_` is incorrect and only denotes 1
// of 2 text runs.
std::vector<chrome_pdf::AccessibilityTextRunInfo> text_runs;
text_runs.emplace_back(kFirstTextRun);
@ -38,14 +38,14 @@ TEST(PdfAccessibilityTreeUnitTest, TextRunsAndCharsMismatch) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
EXPECT_FALSE(PdfAccessibilityTree::IsDataFromPluginValid(text_runs, chars,
page_objects));
}
TEST(PdfAccessibilityTreeUnitTest, TextRunsAndCharsMatch) {
// |chars| and |text_runs| span over the same page text. They should denote
// `chars` and `text_runs` span over the same page text. They should denote
// the same page text size.
std::vector<chrome_pdf::AccessibilityTextRunInfo> text_runs;
text_runs.emplace_back(kFirstTextRun);
@ -54,7 +54,7 @@ TEST(PdfAccessibilityTreeUnitTest, TextRunsAndCharsMatch) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
EXPECT_TRUE(PdfAccessibilityTree::IsDataFromPluginValid(text_runs, chars,
page_objects));
@ -68,22 +68,22 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedLinkVector) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first link in the vector.
ppapi::PdfAccessibilityLinkInfo link;
link.text_run_index = 2;
link.text_run_count = 0;
chrome_pdf::AccessibilityLinkInfo link;
link.text_range.index = 2;
link.text_range.count = 0;
link.index_in_page = 0;
page_objects.links.push_back(std::move(link));
}
{
// Add second link in the vector.
ppapi::PdfAccessibilityLinkInfo link;
link.text_run_index = 0;
link.text_run_count = 1;
chrome_pdf::AccessibilityLinkInfo link;
link.text_range.index = 0;
link.text_range.count = 1;
link.index_in_page = 1;
page_objects.links.push_back(std::move(link));
}
@ -100,12 +100,12 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundLink) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityLinkInfo link;
link.text_run_index = 3;
link.text_run_count = 0;
chrome_pdf::AccessibilityLinkInfo link;
link.text_range.index = 3;
link.text_range.count = 0;
link.index_in_page = 0;
page_objects.links.push_back(std::move(link));
}
@ -122,18 +122,18 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedImageVector) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first image to the vector.
ppapi::PdfAccessibilityImageInfo image;
chrome_pdf::AccessibilityImageInfo image;
image.text_run_index = 1;
page_objects.images.push_back(std::move(image));
}
{
// Add second image to the vector.
ppapi::PdfAccessibilityImageInfo image;
chrome_pdf::AccessibilityImageInfo image;
image.text_run_index = 0;
page_objects.images.push_back(std::move(image));
}
@ -150,10 +150,10 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundImage) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityImageInfo image;
chrome_pdf::AccessibilityImageInfo image;
image.text_run_index = 3;
page_objects.images.push_back(std::move(image));
}
@ -170,22 +170,22 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedHighlightVector) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first highlight in the vector.
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.text_run_index = 2;
highlight.text_run_count = 0;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.text_range.index = 2;
highlight.text_range.count = 0;
highlight.index_in_page = 0;
page_objects.highlights.push_back(std::move(highlight));
}
{
// Add second highlight in the vector.
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.text_run_index = 0;
highlight.text_run_count = 1;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.text_range.index = 0;
highlight.text_range.count = 1;
highlight.index_in_page = 1;
page_objects.highlights.push_back(std::move(highlight));
}
@ -202,12 +202,12 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundHighlight) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.text_run_index = 3;
highlight.text_run_count = 0;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.text_range.index = 3;
highlight.text_range.count = 0;
highlight.index_in_page = 0;
page_objects.highlights.push_back(std::move(highlight));
}
@ -224,11 +224,11 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedTextFieldVector) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first text field in the vector.
ppapi::PdfAccessibilityTextFieldInfo text_field;
chrome_pdf::AccessibilityTextFieldInfo text_field;
text_field.text_run_index = 2;
text_field.index_in_page = 0;
page_objects.form_fields.text_fields.push_back(std::move(text_field));
@ -236,7 +236,7 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedTextFieldVector) {
{
// Add second text field in the vector.
ppapi::PdfAccessibilityTextFieldInfo text_field;
chrome_pdf::AccessibilityTextFieldInfo text_field;
text_field.text_run_index = 0;
text_field.index_in_page = 1;
page_objects.form_fields.text_fields.push_back(std::move(text_field));
@ -254,10 +254,10 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundTextField) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityTextFieldInfo text_field;
chrome_pdf::AccessibilityTextFieldInfo text_field;
text_field.text_run_index = 3;
text_field.index_in_page = 0;
page_objects.form_fields.text_fields.push_back(std::move(text_field));
@ -275,11 +275,11 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedChoiceFieldVector) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first choice field in the vector.
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.text_run_index = 2;
choice_field.index_in_page = 0;
page_objects.form_fields.choice_fields.push_back(std::move(choice_field));
@ -287,7 +287,7 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedChoiceFieldVector) {
{
// Add second choice field in the vector.
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.text_run_index = 0;
choice_field.index_in_page = 1;
page_objects.form_fields.choice_fields.push_back(std::move(choice_field));
@ -305,10 +305,10 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundChoiceField) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.text_run_index = 3;
choice_field.index_in_page = 0;
page_objects.form_fields.choice_fields.push_back(std::move(choice_field));
@ -326,11 +326,11 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedButtonVector) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first button in the vector.
ppapi::PdfAccessibilityButtonInfo button;
chrome_pdf::AccessibilityButtonInfo button;
button.text_run_index = 2;
button.index_in_page = 0;
page_objects.form_fields.buttons.push_back(std::move(button));
@ -338,7 +338,7 @@ TEST(PdfAccessibilityTreeUnitTest, UnsortedButtonVector) {
{
// Add second button in the vector.
ppapi::PdfAccessibilityButtonInfo button;
chrome_pdf::AccessibilityButtonInfo button;
button.text_run_index = 0;
button.index_in_page = 1;
page_objects.form_fields.buttons.push_back(std::move(button));
@ -356,10 +356,10 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundButton) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityButtonInfo button;
chrome_pdf::AccessibilityButtonInfo button;
button.text_run_index = 3;
button.index_in_page = 0;
page_objects.form_fields.buttons.push_back(std::move(button));
@ -377,11 +377,11 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundRadioButton) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityButtonInfo button;
button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_RADIOBUTTON;
chrome_pdf::AccessibilityButtonInfo button;
button.type = chrome_pdf::ButtonType::kRadioButton;
button.text_run_index = 0;
button.control_index = 1;
button.control_count = 2;
@ -393,8 +393,8 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundRadioButton) {
page_objects));
{
ppapi::PdfAccessibilityButtonInfo button;
button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_RADIOBUTTON;
chrome_pdf::AccessibilityButtonInfo button;
button.type = chrome_pdf::ButtonType::kRadioButton;
button.text_run_index = 0;
button.control_index = 3;
button.control_count = 2;
@ -414,11 +414,11 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundCheckBox) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityButtonInfo button;
button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_CHECKBOX;
chrome_pdf::AccessibilityButtonInfo button;
button.type = chrome_pdf::ButtonType::kCheckBox;
button.text_run_index = 0;
button.control_index = 1;
button.control_count = 2;
@ -430,8 +430,8 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundCheckBox) {
page_objects));
{
ppapi::PdfAccessibilityButtonInfo button;
button.type = PP_PrivateButtonType::PP_PRIVATEBUTTON_CHECKBOX;
chrome_pdf::AccessibilityButtonInfo button;
button.type = chrome_pdf::ButtonType::kCheckBox;
button.text_run_index = 0;
button.control_index = 3;
button.control_count = 2;
@ -451,11 +451,11 @@ TEST(PdfAccessibilityTreeUnitTest, InvalidButtonType) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityButtonInfo button;
button.type = static_cast<PP_PrivateButtonType>(666);
chrome_pdf::AccessibilityButtonInfo button;
button.type = static_cast<chrome_pdf::ButtonType>(666);
button.text_run_index = 0;
button.control_index = 1;
button.control_count = 2;
@ -475,13 +475,13 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundIndexInPageLink) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
// Add first link in the vector.
ppapi::PdfAccessibilityLinkInfo link;
link.text_run_index = 1;
link.text_run_count = 0;
chrome_pdf::AccessibilityLinkInfo link;
link.text_range.index = 1;
link.text_range.count = 0;
link.index_in_page = 1;
page_objects.links.push_back(std::move(link));
}
@ -498,12 +498,12 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundIndexInPageHighlight) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityHighlightInfo highlight;
highlight.text_run_index = 1;
highlight.text_run_count = 0;
chrome_pdf::AccessibilityHighlightInfo highlight;
highlight.text_range.index = 1;
highlight.text_range.count = 0;
highlight.index_in_page = 1;
page_objects.highlights.push_back(std::move(highlight));
}
@ -520,10 +520,10 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundIndexInPageTextFeild) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityTextFieldInfo text_feild;
chrome_pdf::AccessibilityTextFieldInfo text_feild;
text_feild.text_run_index = 1;
text_feild.index_in_page = 1;
page_objects.form_fields.text_fields.push_back(std::move(text_feild));
@ -541,12 +541,11 @@ TEST(PdfAccessibilityTreeUnitTest, OutOfBoundIndexInChoiceFeild) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
choice_field.type =
PP_PrivateChoiceFieldType::PP_PRIVATECHOICEFIELD_LISTBOX;
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.type = chrome_pdf::ChoiceFieldType::kListBox;
choice_field.text_run_index = 2;
choice_field.index_in_page = 1;
page_objects.form_fields.choice_fields.push_back(std::move(choice_field));
@ -563,11 +562,11 @@ TEST(PdfAccessibilityTreeUnitTest, InvalidChoiceFieldType) {
std::vector<chrome_pdf::AccessibilityCharInfo> chars(
std::begin(kDummyCharsData), std::end(kDummyCharsData));
ppapi::PdfAccessibilityPageObjects page_objects;
chrome_pdf::AccessibilityPageObjects page_objects;
{
ppapi::PdfAccessibilityChoiceFieldInfo choice_field;
choice_field.type = static_cast<PP_PrivateChoiceFieldType>(666);
chrome_pdf::AccessibilityChoiceFieldInfo choice_field;
choice_field.type = static_cast<chrome_pdf::ChoiceFieldType>(666);
choice_field.text_run_index = 0;
choice_field.index_in_page = 0;
page_objects.form_fields.choice_fields.push_back(std::move(choice_field));

@ -302,6 +302,83 @@ chrome_pdf::AccessibilityTextStyleInfo ToAccessibilityTextStyleInfo(
return style;
}
chrome_pdf::AccessibilityPageObjects ToAccessibilityPageObjects(
const ppapi::PdfAccessibilityPageObjects& pp_page_objects) {
chrome_pdf::AccessibilityPageObjects page_objects;
page_objects.links.reserve(pp_page_objects.links.size());
for (const ppapi::PdfAccessibilityLinkInfo& pp_link : pp_page_objects.links) {
chrome_pdf::AccessibilityTextRunRangeInfo range_info = {
pp_link.text_run_index, pp_link.text_run_count};
page_objects.links.emplace_back(pp_link.url, pp_link.index_in_page,
content::PP_ToGfxRectF(pp_link.bounds),
std::move(range_info));
}
page_objects.images.reserve(pp_page_objects.images.size());
for (const ppapi::PdfAccessibilityImageInfo& pp_image :
pp_page_objects.images) {
page_objects.images.emplace_back(pp_image.alt_text, pp_image.text_run_index,
content::PP_ToGfxRectF(pp_image.bounds));
}
page_objects.highlights.reserve(pp_page_objects.highlights.size());
for (const ppapi::PdfAccessibilityHighlightInfo& pp_highlight :
pp_page_objects.highlights) {
chrome_pdf::AccessibilityTextRunRangeInfo range_info = {
pp_highlight.text_run_index, pp_highlight.text_run_count};
page_objects.highlights.emplace_back(
pp_highlight.note_text, pp_highlight.index_in_page, pp_highlight.color,
content::PP_ToGfxRectF(pp_highlight.bounds), std::move(range_info));
}
page_objects.form_fields.text_fields.reserve(
pp_page_objects.form_fields.text_fields.size());
for (const ppapi::PdfAccessibilityTextFieldInfo& pp_text_field :
pp_page_objects.form_fields.text_fields) {
page_objects.form_fields.text_fields.emplace_back(
pp_text_field.name, pp_text_field.value, pp_text_field.is_read_only,
pp_text_field.is_required, pp_text_field.is_password,
pp_text_field.index_in_page, pp_text_field.text_run_index,
content::PP_ToGfxRectF(pp_text_field.bounds));
}
page_objects.form_fields.choice_fields.reserve(
pp_page_objects.form_fields.choice_fields.size());
for (const ppapi::PdfAccessibilityChoiceFieldInfo& pp_choice_field :
pp_page_objects.form_fields.choice_fields) {
std::vector<chrome_pdf::AccessibilityChoiceFieldOptionInfo> options;
options.reserve(pp_choice_field.options.size());
for (const ppapi::PdfAccessibilityChoiceFieldOptionInfo& pp_option :
pp_choice_field.options) {
options.push_back({pp_option.name, pp_option.is_selected,
content::PP_ToGfxRectF(pp_option.bounds)});
}
page_objects.form_fields.choice_fields.emplace_back(
pp_choice_field.name, std::move(options),
static_cast<chrome_pdf::ChoiceFieldType>(pp_choice_field.type),
pp_choice_field.is_read_only, pp_choice_field.is_multi_select,
pp_choice_field.has_editable_text_box, pp_choice_field.index_in_page,
pp_choice_field.text_run_index,
content::PP_ToGfxRectF(pp_choice_field.bounds));
}
page_objects.form_fields.buttons.reserve(
pp_page_objects.form_fields.buttons.size());
for (const ppapi::PdfAccessibilityButtonInfo& pp_button :
pp_page_objects.form_fields.buttons) {
page_objects.form_fields.buttons.emplace_back(
pp_button.name, pp_button.value,
static_cast<chrome_pdf::ButtonType>(pp_button.type),
pp_button.is_read_only, pp_button.is_checked, pp_button.control_count,
pp_button.control_index, pp_button.index_in_page,
pp_button.text_run_index, content::PP_ToGfxRectF(pp_button.bounds));
}
return page_objects;
}
} // namespace
int32_t PepperPDFHost::OnHostMsgSetAccessibilityPageInfo(
@ -309,7 +386,7 @@ int32_t PepperPDFHost::OnHostMsgSetAccessibilityPageInfo(
const PP_PrivateAccessibilityPageInfo& pp_page_info,
const std::vector<ppapi::PdfAccessibilityTextRunInfo>& pp_text_run_infos,
const std::vector<PP_PrivateAccessibilityCharInfo>& pp_chars,
const ppapi::PdfAccessibilityPageObjects& page_objects) {
const ppapi::PdfAccessibilityPageObjects& pp_page_objects) {
if (!host_->GetPluginInstance(pp_instance()))
return PP_ERROR_FAILED;
CreatePdfAccessibilityTreeIfNeeded();
@ -329,6 +406,8 @@ int32_t PepperPDFHost::OnHostMsgSetAccessibilityPageInfo(
chars.reserve(pp_chars.size());
for (const auto& pp_char : pp_chars)
chars.push_back({pp_char.unicode_character, pp_char.char_width});
chrome_pdf::AccessibilityPageObjects page_objects =
ToAccessibilityPageObjects(pp_page_objects);
pdf_accessibility_tree_->SetAccessibilityPageInfo(page_info, text_run_infos,
chars, page_objects);
return PP_OK;

@ -130,7 +130,7 @@ class PepperPDFHost : public ppapi::host::ResourceHost,
const PP_PrivateAccessibilityPageInfo& pp_page_info,
const std::vector<ppapi::PdfAccessibilityTextRunInfo>& pp_text_run_infos,
const std::vector<PP_PrivateAccessibilityCharInfo>& pp_chars,
const ppapi::PdfAccessibilityPageObjects& page_objects);
const ppapi::PdfAccessibilityPageObjects& pp_page_objects);
int32_t OnHostMsgSelectionChanged(ppapi::host::HostMessageContext* context,
const PP_FloatPoint& left,
int32_t left_height,

@ -221,6 +221,7 @@ struct AccessibilityChoiceFieldOptionInfo {
enum class ChoiceFieldType {
kListBox = 0,
kComboBox = 1,
kMinValue = kListBox,
kMaxValue = kComboBox,
};
@ -269,6 +270,7 @@ enum class ButtonType {
kPushButton = 1,
kCheckBox = 2,
kRadioButton = 3,
kMinValue = kPushButton,
kMaxValue = kRadioButton,
};