0

Add highlight color information to the accessibility tree

The CL retrieves highlight color information from PDFium and passes it
from plugin to mimehandler. The color information is added to the
accessibility tree.

Bug: 1008775
Change-Id: I1faf7e1e7808a19ddbc234705dedcd546670de9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018568
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736750}
This commit is contained in:
Ankit Kumar 🌪️
2020-01-30 07:13:21 +00:00
committed by Commit Bot
parent c15b4bc70f
commit 221befc872
16 changed files with 85 additions and 23 deletions

@ -916,6 +916,8 @@ ui::AXNodeData* PdfAccessibilityTree::CreateHighlightNode(
highlight_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
std::string());
highlight_node->relative_bounds.bounds = ToGfxRectF(highlight.bounds);
highlight_node->AddIntAttribute(ax::mojom::IntAttribute::kBackgroundColor,
highlight.color);
return highlight_node;
}

@ -64,6 +64,13 @@ void CompareRect(const gfx::RectF& expected_rect,
EXPECT_FLOAT_EQ(expected_rect.size().width(), actual_rect.size().width());
}
constexpr uint32_t MakeARGB(unsigned int a,
unsigned int r,
unsigned int g,
unsigned int b) {
return (a << 24) | (r << 16) | (g << 8) | b;
}
// This class overrides content::FakePepperPluginInstance to record received
// action data when tests make an accessibility action call.
class ActionHandlingFakePepperPluginInstance
@ -349,6 +356,8 @@ TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) {
scoped_feature_list.InitAndEnableFeature(
chrome_pdf::features::kAccessiblePDFHighlight);
constexpr uint32_t kHighlightWhiteColor = MakeARGB(255, 255, 255, 255);
text_runs_.emplace_back(kFirstTextRun);
text_runs_.emplace_back(kSecondTextRun);
chars_.insert(chars_.end(), std::begin(kDummyCharsData),
@ -359,6 +368,7 @@ TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) {
highlight.bounds = PP_MakeFloatRectFromXYWH(1.0f, 1.0f, 5.0f, 6.0f);
highlight.text_run_index = 0;
highlight.text_run_count = 2;
highlight.color = kHighlightWhiteColor;
page_objects_.highlights.push_back(std::move(highlight));
}
@ -411,6 +421,11 @@ TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) {
ax::mojom::StringAttribute::kRoleDescription));
EXPECT_EQ(gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f),
highlight_node->data().relative_bounds.bounds);
ASSERT_TRUE(highlight_node->HasIntAttribute(
ax::mojom::IntAttribute::kBackgroundColor));
EXPECT_EQ(kHighlightWhiteColor,
static_cast<uint32_t>(highlight_node->GetIntAttribute(
ax::mojom::IntAttribute::kBackgroundColor)));
ASSERT_EQ(1u, highlight_node->children().size());
ui::AXNode* static_text_node = highlight_node->children()[0];

@ -122,6 +122,7 @@ void GetAccessibilityHighlightInfo(
pp::PDF::PrivateAccessibilityHighlightInfo highlight_info;
highlight_info.index_in_page = i;
highlight_info.bounds = std::move(cur_highlight_info.bounds);
highlight_info.color = cur_highlight_info.color;
if (!GetEnclosingTextRunRangeForCharRange(
text_runs, cur_highlight_info.start_char_index,

@ -301,6 +301,7 @@ class PDFEngine {
int start_char_index = -1;
int char_count;
pp::FloatRect bounds;
uint32_t color;
};
// Factory method to create an instance of the PDF Engine.

@ -480,10 +480,14 @@ TEST_F(AccessibilityTest, GetAccessibilityLinkInfo) {
}
TEST_F(AccessibilityTest, GetAccessibilityHighlightInfo) {
constexpr uint32_t kHighlightDefaultColor = MakeARGB(255, 255, 255, 0);
constexpr uint32_t kHighlightRedColor = MakeARGB(102, 230, 0, 0);
constexpr uint32_t kHighlightNoColor = MakeARGB(0, 0, 0, 0);
static const pp::PDF::PrivateAccessibilityHighlightInfo
kExpectedHighlightInfo[] = {{"", 0, 0, 1, {{5, 196}, {49, 26}}},
{"", 1, 2, 1, {{110, 196}, {77, 26}}},
{"", 2, 3, 1, {{192, 196}, {13, 26}}}};
kExpectedHighlightInfo[] = {
{"", 0, 0, 1, {{5, 196}, {49, 26}}, kHighlightDefaultColor},
{"", 1, 2, 1, {{110, 196}, {77, 26}}, kHighlightRedColor},
{"", 2, 3, 1, {{192, 196}, {13, 26}}, kHighlightNoColor}};
static const pp::Rect kExpectedPageRect = {{5, 3}, {533, 266}};
@ -515,6 +519,7 @@ TEST_F(AccessibilityTest, GetAccessibilityHighlightInfo) {
kExpectedHighlightInfo[i].text_run_index);
EXPECT_EQ(highlight_info.text_run_count,
kExpectedHighlightInfo[i].text_run_count);
EXPECT_EQ(highlight_info.color, kExpectedHighlightInfo[i].color);
}
}

@ -183,13 +183,6 @@ bool FloatEquals(float f1, float f2) {
kEpsilonScale * fmaxf(fmaxf(fabsf(f1), fabsf(f2)), kEpsilonScale);
}
uint32_t MakeARGB(unsigned int a,
unsigned int r,
unsigned int g,
unsigned int b) {
return (a << 24) | (r << 16) | (g << 8) | b;
}
} // namespace
PDFiumPage::LinkTarget::LinkTarget() : page(-1) {}
@ -585,6 +578,7 @@ PDFiumPage::GetHighlightInfo() {
cur_info.bounds = pp::FloatRect(
highlight.bounding_rect.x(), highlight.bounding_rect.y(),
highlight.bounding_rect.width(), highlight.bounding_rect.height());
cur_info.color = highlight.color;
highlight_info.push_back(std::move(cur_info));
}
return highlight_info;
@ -1080,6 +1074,22 @@ void PDFiumPage::PopulateHighlights() {
std::abs(rect.bottom - rect.top)),
&highlight.start_char_index, &highlight.char_count);
// Retrieve the color of the highlight.
unsigned int color_r;
unsigned int color_g;
unsigned int color_b;
unsigned int color_a;
FPDF_PAGEOBJECT page_object = FPDFAnnot_GetObject(annot.get(), 0);
if (FPDFPageObj_GetFillColor(page_object, &color_r, &color_g, &color_b,
&color_a)) {
highlight.color = MakeARGB(color_a, color_r, color_g, color_b);
} else {
// Set the same default color as in pdfium. See calls to
// GetColorStringWithDefault() in CPVT_GenerateAP::Generate*AP() in
// pdfium.
highlight.color = MakeARGB(255, 255, 255, 0);
}
highlights_.push_back(std::move(highlight));
}
}

@ -269,6 +269,10 @@ class PDFiumPage {
// Number of characters encompassed by this highlight.
int32_t char_count = 0;
pp::Rect bounding_rect;
// Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
// follows after it with each using 8 bytes.
uint32_t color;
};
PDFiumEngine* engine_;
@ -297,6 +301,13 @@ class PDFiumPage {
// FPDF_RenderPage().
int ToPDFiumRotation(PageOrientation orientation);
constexpr uint32_t MakeARGB(unsigned int a,
unsigned int r,
unsigned int g,
unsigned int b) {
return (a << 24) | (r << 16) | (g << 8) | b;
}
} // namespace chrome_pdf
#endif // PDF_PDFIUM_PDFIUM_PAGE_H_

@ -353,12 +353,16 @@ TEST_F(PDFiumPageHighlightTest, TestPopulateHighlights) {
int32_t start_char_index;
int32_t char_count;
pp::Rect bounding_rect;
uint32_t color;
};
constexpr uint32_t kHighlightDefaultColor = MakeARGB(255, 255, 255, 0);
constexpr uint32_t kHighlightRedColor = MakeARGB(102, 230, 0, 0);
constexpr uint32_t kHighlightNoColor = MakeARGB(0, 0, 0, 0);
static const ExpectedHighlight kExpectedHighlights[] = {
{0, 5, {5, 196, 49, 26}},
{12, 7, {110, 196, 77, 26}},
{20, 1, {192, 196, 13, 26}}};
{0, 5, {5, 196, 49, 26}, kHighlightDefaultColor},
{12, 7, {110, 196, 77, 26}, kHighlightRedColor},
{20, 1, {192, 196, 13, 26}, kHighlightNoColor}};
TestClient client;
std::unique_ptr<PDFiumEngine> engine =
@ -378,6 +382,7 @@ TEST_F(PDFiumPageHighlightTest, TestPopulateHighlights) {
page->highlights_[i].char_count);
CompareRect(kExpectedHighlights[i].bounding_rect,
page->highlights_[i].bounding_rect);
ASSERT_EQ(kExpectedHighlights[i].color, page->highlights_[i].color);
}
}

@ -45,7 +45,6 @@ endobj
/Subtype /Highlight
/QuadPoints [0 55 36 59 0 36 36 36]
/Rect [0 36 36 55]
/C [0.15 0 0.9 0]
/P 3 0 R
>>
endobj
@ -54,7 +53,8 @@ endobj
/Subtype /Highlight
/QuadPoints [79 55 136 55 79 36 136 36]
/Rect [79 36 136 55]
/C [0.15 0 0.9 0]
/C [0.9 0 0]
/CA 0.4
/P 3 0 R
>>
endobj
@ -63,7 +63,8 @@ endobj
/Subtype /Highlight
/QuadPoints [140 55 149 55 140 36 149 36]
/Rect [140 36 149 55]
/C [0.15 0 0.9 0]
/C [0 0 0]
/CA 0
/P 3 0 R
>>
endobj

@ -46,7 +46,6 @@ endobj
/Subtype /Highlight
/QuadPoints [0 55 36 59 0 36 36 36]
/Rect [0 36 36 55]
/C [0.15 0 0.9 0]
/P 3 0 R
>>
endobj
@ -55,7 +54,8 @@ endobj
/Subtype /Highlight
/QuadPoints [79 55 136 55 79 36 136 36]
/Rect [79 36 136 55]
/C [0.15 0 0.9 0]
/C [0.9 0 0]
/CA 0.4
/P 3 0 R
>>
endobj
@ -64,7 +64,8 @@ endobj
/Subtype /Highlight
/QuadPoints [140 55 149 55 140 36 149 36]
/Rect [140 36 149 55]
/C [0.15 0 0.9 0]
/C [0 0 0]
/CA 0
/P 3 0 R
>>
endobj
@ -77,12 +78,12 @@ xref
0000000313 00000 n
0000000389 00000 n
0000000493 00000 n
0000000641 00000 n
0000000795 00000 n
0000000621 00000 n
0000000780 00000 n
trailer <<
/Root 1 0 R
/Size 9
>>
startxref
952
938
%%EOF

@ -174,6 +174,9 @@ struct PP_PrivateAccessibilityHighlightInfo {
uint32_t text_run_count;
// Bounding box of the highlight.
struct PP_FloatRect bounds;
// Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
// follows after it with each using 8 bytes.
uint32_t color;
};
// Holds links, images and highlights within a PDF page so that IPC messages

@ -70,6 +70,7 @@ void ConvertPrivateAccessibilityHighlightInfo(
info->text_run_index = highlight.text_run_index;
info->text_run_count = highlight.text_run_count;
info->bounds = highlight.bounds;
info->color = highlight.color;
}
} // namespace

@ -77,6 +77,9 @@ class PDF {
uint32_t text_run_index;
uint32_t text_run_count;
FloatRect bounds;
// Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
// follows after it with each using 8 bytes.
uint32_t color;
};
// C++ version of PP_PrivateAccessibilityPageObjects.

@ -334,6 +334,7 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityHighlightInfo)
IPC_STRUCT_TRAITS_MEMBER(text_run_index)
IPC_STRUCT_TRAITS_MEMBER(text_run_count)
IPC_STRUCT_TRAITS_MEMBER(bounds)
IPC_STRUCT_TRAITS_MEMBER(color)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(ppapi::PdfAccessibilityPageObjects)

@ -70,7 +70,8 @@ PdfAccessibilityHighlightInfo::PdfAccessibilityHighlightInfo(
index_in_page(highlight.index_in_page),
text_run_index(highlight.text_run_index),
text_run_count(highlight.text_run_count),
bounds(highlight.bounds) {}
bounds(highlight.bounds),
color(highlight.color) {}
PdfAccessibilityPageObjects::PdfAccessibilityPageObjects() = default;

@ -87,6 +87,7 @@ struct PPAPI_SHARED_EXPORT PdfAccessibilityHighlightInfo {
uint32_t text_run_index;
uint32_t text_run_count;
PP_FloatRect bounds;
uint32_t color;
};
// Needs to stay in sync with PP_PrivateAccessibilityPageObjects.