Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1953053002: Add private PPAPI interfaces for PDFium accessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback from Lei Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1) 2296 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1)
2297 return "{}"; 2297 return "{}";
2298 2298
2299 std::unique_ptr<base::Value> node( 2299 std::unique_ptr<base::Value> node(
2300 pages_[index]->GetAccessibleContentAsValue(current_rotation_)); 2300 pages_[index]->GetAccessibleContentAsValue(current_rotation_));
2301 std::string page_json; 2301 std::string page_json;
2302 base::JSONWriter::Write(*node, &page_json); 2302 base::JSONWriter::Write(*node, &page_json);
2303 return page_json; 2303 return page_json;
2304 } 2304 }
2305 2305
2306 void PDFiumEngine::EnableAccessibility() {
2307 PP_PrivateAccessibilityDocInfo doc_info;
2308 doc_info.page_count = pages_.size();
2309 doc_info.text_accessible = PP_FromBool(
2310 HasPermission(PERMISSION_COPY_ACCESSIBLE));
2311 doc_info.text_copyable = PP_FromBool(HasPermission(PERMISSION_COPY));
2312 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info);
2313
2314 // If the document contents isn't accessible, don't send anything more.
2315 if (!(HasPermission(PERMISSION_COPY) ||
2316 HasPermission(PERMISSION_COPY_ACCESSIBLE))) {
2317 return;
2318 }
2319
2320 PP_PrivateAccessibilityViewportInfo viewport_info;
2321 viewport_info.scroll.x = 0;
2322 viewport_info.scroll.y = -client_->GetToolbarHeight();
2323 viewport_info.offset = page_offset_;
2324 viewport_info.zoom = current_zoom_;
2325 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
2326
2327 for (size_t page_index = 0; page_index < pages_.size(); ++page_index) {
2328 FPDF_TEXTPAGE text_page = pages_[page_index]->GetTextPage();
2329 int char_count = FPDFText_CountChars(text_page);
2330 PP_PrivateAccessibilityPageInfo page_info;
2331 page_info.bounds = pages_[page_index]->rect();
2332 page_info.char_count = char_count;
2333 pp::PDF::SetAccessibilityPageInfo(
2334 GetPluginInstance(), page_index, &page_info);
2335
2336 int char_index = 0;
2337 int text_run_index = 0;
2338 while (char_index < char_count) {
2339 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
2340 pp::FloatRect bounds;
2341 pages_[page_index]->GetTextRunInfo(
2342 char_index, &text_run_info.len, &text_run_info.font_size, &bounds);
2343 text_run_info.direction = PP_PRIVATEDIRECTION_LTR;
2344 text_run_info.bounds = bounds;
2345 std::vector<PP_PrivateAccessibilityCharInfo> chars(text_run_info.len);
2346 for (uint32_t i = 0; i < text_run_info.len; ++i) {
2347 chars[i].unicode_character = FPDFText_GetUnicode(text_page, i);
2348 chars[i].char_width = pages_[page_index]->GetCharWidth(i);
2349 }
2350
2351 pp::PDF::SetAccessibilityTextRunInfo(GetPluginInstance(),
2352 page_index,
2353 text_run_index,
2354 &text_run_info,
2355 chars.data());
2356 text_run_index++;
2357 char_index += text_run_info.len;
2358 }
2359 }
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
2360 }
2361
2306 bool PDFiumEngine::GetPrintScaling() { 2362 bool PDFiumEngine::GetPrintScaling() {
2307 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); 2363 return !!FPDF_VIEWERREF_GetPrintScaling(doc_);
2308 } 2364 }
2309 2365
2310 int PDFiumEngine::GetCopiesToPrint() { 2366 int PDFiumEngine::GetCopiesToPrint() {
2311 return FPDF_VIEWERREF_GetNumCopies(doc_); 2367 return FPDF_VIEWERREF_GetNumCopies(doc_);
2312 } 2368 }
2313 2369
2314 int PDFiumEngine::GetDuplexType() { 2370 int PDFiumEngine::GetDuplexType() {
2315 return static_cast<int>(FPDF_VIEWERREF_GetDuplex(doc_)); 2371 return static_cast<int>(FPDF_VIEWERREF_GetDuplex(doc_));
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
3873 FPDF_DOCUMENT doc = 3929 FPDF_DOCUMENT doc =
3874 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3930 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3875 if (!doc) 3931 if (!doc)
3876 return false; 3932 return false;
3877 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3933 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3878 FPDF_CloseDocument(doc); 3934 FPDF_CloseDocument(doc);
3879 return success; 3935 return success;
3880 } 3936 }
3881 3937
3882 } // namespace chrome_pdf 3938 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | pdf/pdfium/pdfium_page.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698