Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index 09d8a2f5ec1e64c196e87981fce53607ab6817ea..32d8a1deb3ffb2f82c38941e6d1dd5ca75da9646 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -2303,6 +2303,62 @@ std::string PDFiumEngine::GetPageAsJSON(int index) { |
| return page_json; |
| } |
| +void PDFiumEngine::EnableAccessibility() { |
| + PP_PrivateAccessibilityDocInfo doc_info; |
| + doc_info.page_count = pages_.size(); |
| + doc_info.text_accessible = PP_FromBool( |
| + HasPermission(PERMISSION_COPY_ACCESSIBLE)); |
| + doc_info.text_copyable = PP_FromBool(HasPermission(PERMISSION_COPY)); |
| + pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); |
| + |
| + // If the document contents isn't accessible, don't send anything more. |
| + if (!(HasPermission(PERMISSION_COPY) || |
| + HasPermission(PERMISSION_COPY_ACCESSIBLE))) { |
| + return; |
| + } |
| + |
| + PP_PrivateAccessibilityViewportInfo viewport_info; |
| + viewport_info.scroll.x = 0; |
| + viewport_info.scroll.y = -client_->GetToolbarHeight(); |
| + viewport_info.offset = page_offset_; |
| + viewport_info.zoom = current_zoom_; |
| + pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info); |
|
raymes
2016/05/17 20:38:40
Does the viewport info need to be updated as the v
raymes
2016/05/17 20:40:12
Also, is the viewport information important for ac
dmazzoni
2016/05/17 20:56:58
Yes, I just haven't implemented that yet.
dmazzoni
2016/05/17 20:56:58
Yes, it's important to expose the on-screen locati
|
| + |
| + for (size_t page_index = 0; page_index < pages_.size(); ++page_index) { |
| + FPDF_TEXTPAGE text_page = pages_[page_index]->GetTextPage(); |
| + int char_count = FPDFText_CountChars(text_page); |
| + PP_PrivateAccessibilityPageInfo page_info; |
| + page_info.bounds = pages_[page_index]->rect(); |
| + page_info.char_count = char_count; |
| + pp::PDF::SetAccessibilityPageInfo( |
| + GetPluginInstance(), page_index, &page_info); |
| + |
| + int char_index = 0; |
| + int text_run_index = 0; |
| + while (char_index < char_count) { |
| + PP_PrivateAccessibilityTextRunInfo text_run_info; |
|
raymes
2016/05/17 20:38:40
Could getting all this data be slow for large docs
dmazzoni
2016/05/17 20:56:58
I think I'd prefer to do this, maybe one page at a
|
| + pp::FloatRect bounds; |
| + pages_[page_index]->GetTextRunInfo( |
| + char_index, &text_run_info.len, &text_run_info.font_size, &bounds); |
| + text_run_info.direction = PP_PRIVATEDIRECTION_LTR; |
| + text_run_info.bounds = bounds; |
| + std::vector<PP_PrivateAccessibilityCharInfo> chars(text_run_info.len); |
| + for (uint32_t i = 0; i < text_run_info.len; ++i) { |
| + chars[i].unicode_character = FPDFText_GetUnicode(text_page, i); |
| + chars[i].char_width = pages_[page_index]->GetCharWidth(i); |
| + } |
| + |
| + pp::PDF::SetAccessibilityTextRunInfo(GetPluginInstance(), |
| + page_index, |
| + text_run_index, |
| + &text_run_info, |
| + chars.data()); |
| + text_run_index++; |
| + char_index += text_run_info.len; |
| + } |
| + } |
|
raymes
2016/05/17 20:38:40
Could this code live in out_of_process_instance.cc
dmazzoni
2016/05/17 20:56:58
Sure. That's one of the reasons I wanted to stop a
|
| +} |
| + |
| bool PDFiumEngine::GetPrintScaling() { |
| return !!FPDF_VIEWERREF_GetPrintScaling(doc_); |
| } |