0

Rename link to annotation in PDF a11y action handling pipeline

Earlier we only had link in PDF a11y on which action could be performed.
Now more annotations are to be added in PDF a11y which are actionable.
e.g. highlights.
This CL renames the variables and functions from link to annotation in
action handling pipeline as the same variables and functions will be
used for all actionable annotations.
Additionally an enum PP_PdfAccessibilityAnnotationType is introduced to
disambiguate between the different annotations on which action is to be
performed.

Bug: 1008775
Change-Id: I1b6d75976c49dba5778cb3e7871df318f023779b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1958495
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724262}
This commit is contained in:
Ankit Kumar 🌪️
2019-12-12 18:09:04 +00:00
committed by Commit Bot
parent 1fc08d3311
commit 9b5487d5c9
8 changed files with 63 additions and 38 deletions

@ -855,8 +855,8 @@ ui::AXNodeData* PdfAccessibilityTree::CreateLinkNode(
link_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
std::string());
link_node->relative_bounds.bounds = ToGfxRectF(link.bounds);
node_id_to_link_info_.emplace(link_node->id,
LinkInfo(page_index, link.index_in_page));
node_id_to_annotation_info_.emplace(
link_node->id, AnnotationInfo(page_index, link.index_in_page));
return link_node;
}
@ -1007,13 +1007,14 @@ void PdfAccessibilityTree::AddWordStartsAndEnds(
word_ends);
}
PdfAccessibilityTree::LinkInfo::LinkInfo(uint32_t page_index,
uint32_t link_index)
: page_index(page_index), link_index(link_index) {}
PdfAccessibilityTree::AnnotationInfo::AnnotationInfo(uint32_t page_index,
uint32_t annotation_index)
: page_index(page_index), annotation_index(annotation_index) {}
PdfAccessibilityTree::LinkInfo::LinkInfo(const LinkInfo& other) = default;
PdfAccessibilityTree::AnnotationInfo::AnnotationInfo(
const AnnotationInfo& other) = default;
PdfAccessibilityTree::LinkInfo::~LinkInfo() = default;
PdfAccessibilityTree::AnnotationInfo::~AnnotationInfo() = default;
//
// AXTreeSource implementation.
@ -1087,16 +1088,16 @@ void PdfAccessibilityTree::HandleAction(
}
}
bool PdfAccessibilityTree::GetPdfLinkInfoFromAXNode(
bool PdfAccessibilityTree::GetPdfAnnotationInfoFromAXNode(
int32_t ax_node_id,
uint32_t* page_index,
uint32_t* link_index_in_page) const {
auto iter = node_id_to_link_info_.find(ax_node_id);
if (iter == node_id_to_link_info_.end())
uint32_t* annotation_index_in_page) const {
auto iter = node_id_to_annotation_info_.find(ax_node_id);
if (iter == node_id_to_annotation_info_.end())
return false;
*page_index = iter->second.page_index;
*link_index_in_page = iter->second.link_index;
*annotation_index_in_page = iter->second.annotation_index;
return true;
}

@ -51,9 +51,9 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource {
const std::vector<PP_PrivateAccessibilityCharInfo>& chars,
const ppapi::PdfAccessibilityPageObjects& page_objects);
void HandleAction(const PP_PdfAccessibilityActionData& action_data);
bool GetPdfLinkInfoFromAXNode(int32_t ax_node_id,
uint32_t* page_index,
uint32_t* link_index_in_page) const;
bool GetPdfAnnotationInfoFromAXNode(int32_t ax_node_id,
uint32_t* page_index,
uint32_t* annotation_index_in_page) const;
// PluginAXTreeSource implementation.
bool GetTreeData(ui::AXTreeData* tree_data) const override;
@ -148,14 +148,14 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource {
gfx::Transform* MakeTransformFromViewInfo();
void AddWordStartsAndEnds(ui::AXNodeData* inline_text_box);
// Stores the page index and link index in the page.
struct LinkInfo {
LinkInfo(uint32_t page_index, uint32_t link_index);
LinkInfo(const LinkInfo& other);
~LinkInfo();
// Stores the page index and annotation index in the page.
struct AnnotationInfo {
AnnotationInfo(uint32_t page_index, uint32_t annotation_index);
AnnotationInfo(const AnnotationInfo& other);
~AnnotationInfo();
uint32_t page_index;
uint32_t link_index;
uint32_t annotation_index;
};
ui::AXTreeData tree_data_;
@ -187,9 +187,9 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource {
// character within its page. Used to find the node associated with
// the start or end of a selection.
std::map<int32_t, uint32_t> node_id_to_char_index_in_page_;
// Map between AXNode id to link object. Used to find the link
// Map between AXNode id to annotation object. Used to find the annotation
// object to which an action can be passed.
std::map<int32_t, LinkInfo> node_id_to_link_info_;
std::map<int32_t, AnnotationInfo> node_id_to_annotation_info_;
bool invalid_plugin_message_received_ = false;
};

@ -942,7 +942,9 @@ TEST_F(PdfAccessibilityTreeTest, TestClickActionDataConversion) {
EXPECT_EQ(PP_PdfAccessibilityScrollAlignment::PP_PDF_SCROLL_NONE,
pdf_action_data.vertical_scroll_alignment);
EXPECT_EQ(0u, pdf_action_data.page_index);
EXPECT_EQ(1u, pdf_action_data.link_index);
EXPECT_EQ(PP_PdfAccessibilityAnnotationType::PP_PDF_LINK,
pdf_action_data.annotation_type);
EXPECT_EQ(1u, pdf_action_data.annotation_index);
CompareRect({{0, 0}, {0, 0}}, pdf_action_data.target_rect);
}

@ -56,12 +56,14 @@ bool PdfAXActionTarget::Click() const {
PP_PdfAccessibilityActionData pdf_action_data = {};
if ((target_plugin_node_.data().role != ax::mojom::Role::kLink) ||
!pdf_accessibility_tree_source_->GetPdfLinkInfoFromAXNode(
!pdf_accessibility_tree_source_->GetPdfAnnotationInfoFromAXNode(
target_plugin_node_.data().id, &pdf_action_data.page_index,
&pdf_action_data.link_index)) {
&pdf_action_data.annotation_index)) {
return false;
}
pdf_action_data.annotation_type =
PP_PdfAccessibilityAnnotationType::PP_PDF_LINK;
pdf_action_data.action = PP_PdfAccessibilityAction::PP_PDF_DO_DEFAULT_ACTION;
pdf_accessibility_tree_source_->HandleAction(pdf_action_data);
return true;

@ -389,7 +389,8 @@ TEST_F(AccessibilityTest, TestWebLinkClickActionHandling) {
PP_PdfAccessibilityActionData action_data;
action_data.action = PP_PdfAccessibilityAction::PP_PDF_DO_DEFAULT_ACTION;
action_data.page_index = 0;
action_data.link_index = 0;
action_data.annotation_type = PP_PdfAccessibilityAnnotationType::PP_PDF_LINK;
action_data.annotation_index = 0;
engine->HandleAccessibilityAction(action_data);
EXPECT_EQ("http://yahoo.com", client.url());
EXPECT_EQ(WindowOpenDisposition::CURRENT_TAB, client.disposition());
@ -404,7 +405,8 @@ TEST_F(AccessibilityTest, TestInternalLinkClickActionHandling) {
PP_PdfAccessibilityActionData action_data;
action_data.action = PP_PdfAccessibilityAction::PP_PDF_DO_DEFAULT_ACTION;
action_data.page_index = 0;
action_data.link_index = 1;
action_data.annotation_type = PP_PdfAccessibilityAnnotationType::PP_PDF_LINK;
action_data.annotation_index = 1;
engine->HandleAccessibilityAction(action_data);
EXPECT_EQ(1, client.page());
EXPECT_EQ(266, client.x_in_pixels());

@ -2012,12 +2012,15 @@ void PDFiumEngine::HandleAccessibilityAction(
}
case PP_PdfAccessibilityAction::PP_PDF_DO_DEFAULT_ACTION: {
if (PageIndexInBounds(action_data.page_index)) {
PDFiumPage::LinkTarget target;
PDFiumPage::Area area =
pages_[action_data.page_index]->GetLinkTargetAtIndex(
action_data.link_index, &target);
NavigateToLinkDestination(area, target,
WindowOpenDisposition::CURRENT_TAB);
if (action_data.annotation_type ==
PP_PdfAccessibilityAnnotationType::PP_PDF_LINK) {
PDFiumPage::LinkTarget target;
PDFiumPage::Area area =
pages_[action_data.page_index]->GetLinkTargetAtIndex(
action_data.annotation_index, &target);
NavigateToLinkDestination(area, target,
WindowOpenDisposition::CURRENT_TAB);
}
}
break;
}

@ -93,13 +93,25 @@ typedef enum {
} PP_PdfAccessibilityScrollAlignment;
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PdfAccessibilityScrollAlignment, 4);
typedef enum {
// No annotation type defined.
PP_PDF_TYPE_NONE = 0,
// Link annotation.
PP_PDF_LINK = 1,
// Last enum value marker.
PP_PDF_ACCESSIBILITY_ANNOTATIONTYPE_LAST = PP_PDF_LINK
} PP_PdfAccessibilityAnnotationType;
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PdfAccessibilityAnnotationType, 4);
struct PP_PdfAccessibilityActionData {
// Accessibility action type.
PP_PdfAccessibilityAction action;
// Annotation type on which the action is to be performed.
PP_PdfAccessibilityAnnotationType annotation_type;
// Target rect on which the action is to be performed.
struct PP_Rect target_rect;
// Index of link in page.
uint32_t link_index;
// Index of annotation in page.
uint32_t annotation_index;
// Page index on which the link is present.
uint32_t page_index;
// Horizontal scroll alignment with respect to the viewport
@ -107,7 +119,7 @@ struct PP_PdfAccessibilityActionData {
// Vertical scroll alignment with respect to the viewport
PP_PdfAccessibilityScrollAlignment vertical_scroll_alignment;
};
PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_PdfAccessibilityActionData, 36);
PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_PdfAccessibilityActionData, 40);
struct PPP_Pdf_1_1 {
// Returns an absolute URL if the position is over a link.

@ -157,6 +157,8 @@ IPC_ENUM_TRAITS_MAX_VALUE(PP_PdfAccessibilityAction,
PP_PDF_ACCESSIBILITYACTION_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(PP_PdfAccessibilityScrollAlignment,
PP_PDF_ACCESSIBILITYSCROLLALIGNMENT_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(PP_PdfAccessibilityAnnotationType,
PP_PDF_ACCESSIBILITY_ANNOTATIONTYPE_LAST)
IPC_STRUCT_TRAITS_BEGIN(PP_Point)
IPC_STRUCT_TRAITS_MEMBER(x)
@ -234,8 +236,9 @@ IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PP_PdfAccessibilityActionData)
IPC_STRUCT_TRAITS_MEMBER(action)
IPC_STRUCT_TRAITS_MEMBER(annotation_type)
IPC_STRUCT_TRAITS_MEMBER(target_rect)
IPC_STRUCT_TRAITS_MEMBER(link_index)
IPC_STRUCT_TRAITS_MEMBER(annotation_index)
IPC_STRUCT_TRAITS_MEMBER(page_index)
IPC_STRUCT_TRAITS_MEMBER(horizontal_scroll_alignment)
IPC_STRUCT_TRAITS_MEMBER(vertical_scroll_alignment)