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

@ -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