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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2050973003: PDF accessibility tweaks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pdf_1_hastreedata
Patch Set: Created 4 years, 6 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/out_of_process_instance.h" 5 #include "pdf/out_of_process_instance.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // for min/max() 10 #include <algorithm> // for min/max()
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 uma_(this), 296 uma_(this),
297 told_browser_about_unsupported_feature_(false), 297 told_browser_about_unsupported_feature_(false),
298 print_preview_page_count_(0), 298 print_preview_page_count_(0),
299 last_progress_sent_(0), 299 last_progress_sent_(0),
300 recently_sent_find_update_(false), 300 recently_sent_find_update_(false),
301 received_viewport_message_(false), 301 received_viewport_message_(false),
302 did_call_start_loading_(false), 302 did_call_start_loading_(false),
303 stop_scrolling_(false), 303 stop_scrolling_(false),
304 background_color_(0), 304 background_color_(0),
305 top_toolbar_height_(0), 305 top_toolbar_height_(0),
306 accessibility_enabled_(false) { 306 accessibility_enabled_(false),
307 accessibility_loaded_(false) {
307 loader_factory_.Initialize(this); 308 loader_factory_.Initialize(this);
308 timer_factory_.Initialize(this); 309 timer_factory_.Initialize(this);
309 form_factory_.Initialize(this); 310 form_factory_.Initialize(this);
310 print_callback_factory_.Initialize(this); 311 print_callback_factory_.Initialize(this);
311 engine_.reset(PDFEngine::Create(this)); 312 engine_.reset(PDFEngine::Create(this));
312 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); 313 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
313 AddPerInstanceObject(kPPPPdfInterface, this); 314 AddPerInstanceObject(kPPPPdfInterface, this);
314 315
315 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 316 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
316 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 317 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 options->duplex = 624 options->duplex =
624 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); 625 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType());
625 options->copies = engine_->GetCopiesToPrint(); 626 options->copies = engine_->GetCopiesToPrint();
626 pp::Size uniform_page_size; 627 pp::Size uniform_page_size;
627 options->is_page_size_uniform = 628 options->is_page_size_uniform =
628 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); 629 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size));
629 options->uniform_page_size = uniform_page_size; 630 options->uniform_page_size = uniform_page_size;
630 } 631 }
631 632
632 void OutOfProcessInstance::EnableAccessibility() { 633 void OutOfProcessInstance::EnableAccessibility() {
633 if (accessibility_enabled_) 634 accessibility_enabled_ = true;
635 if (document_load_state_ == LOAD_STATE_LOADING)
634 return; 636 return;
635 637
636 accessibility_enabled_ = true; 638 if (accessibility_loaded_ || document_load_state_ != LOAD_STATE_COMPLETE)
639 return;
637 640
641 accessibility_loaded_ = true;
638 PP_PrivateAccessibilityDocInfo doc_info; 642 PP_PrivateAccessibilityDocInfo doc_info;
639 doc_info.page_count = engine_->GetNumberOfPages(); 643 doc_info.page_count = engine_->GetNumberOfPages();
640 doc_info.text_accessible = PP_FromBool( 644 doc_info.text_accessible = PP_FromBool(
641 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); 645 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE));
642 doc_info.text_copyable = PP_FromBool( 646 doc_info.text_copyable = PP_FromBool(
643 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); 647 engine_->HasPermission(PDFEngine::PERMISSION_COPY));
648
644 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); 649 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info);
645 650
646 // If the document contents isn't accessible, don't send anything more. 651 // If the document contents isn't accessible, don't send anything more.
647 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || 652 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
648 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { 653 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) {
649 return; 654 return;
650 } 655 }
651 656
652 PP_PrivateAccessibilityViewportInfo viewport_info; 657 PP_PrivateAccessibilityViewportInfo viewport_info;
653 viewport_info.scroll.x = 0; 658 viewport_info.scroll.x = 0;
(...skipping 16 matching lines...) Expand all
670 675
671 int char_count = engine_->GetCharCount(page_index); 676 int char_count = engine_->GetCharCount(page_index);
672 PP_PrivateAccessibilityPageInfo page_info; 677 PP_PrivateAccessibilityPageInfo page_info;
673 page_info.page_index = page_index; 678 page_info.page_index = page_index;
674 page_info.bounds = engine_->GetPageBoundsRect(page_index); 679 page_info.bounds = engine_->GetPageBoundsRect(page_index);
675 page_info.char_count = char_count; 680 page_info.char_count = char_count;
676 681
677 std::vector<PP_PrivateAccessibilityCharInfo> chars(page_info.char_count); 682 std::vector<PP_PrivateAccessibilityCharInfo> chars(page_info.char_count);
678 for (uint32_t i = 0; i < page_info.char_count; ++i) { 683 for (uint32_t i = 0; i < page_info.char_count; ++i) {
679 chars[i].unicode_character = engine_->GetCharUnicode(page_index, i); 684 chars[i].unicode_character = engine_->GetCharUnicode(page_index, i);
680 chars[i].char_width = engine_->GetCharWidth(page_index, i);
681 } 685 }
682 686
683 std::vector<PP_PrivateAccessibilityTextRunInfo> text_runs; 687 std::vector<PP_PrivateAccessibilityTextRunInfo> text_runs;
684 int char_index = 0; 688 int char_index = 0;
685 while (char_index < char_count) { 689 while (char_index < char_count) {
686 PP_PrivateAccessibilityTextRunInfo text_run_info; 690 PP_PrivateAccessibilityTextRunInfo text_run_info;
687 pp::FloatRect bounds; 691 pp::FloatRect bounds;
688 engine_->GetTextRunInfo(page_index, char_index, &text_run_info.len, 692 engine_->GetTextRunInfo(page_index, char_index, &text_run_info.len,
689 &text_run_info.font_size, &bounds); 693 &text_run_info.font_size, &bounds);
690 text_run_info.direction = PP_PRIVATEDIRECTION_LTR; 694 text_run_info.direction = PP_PRIVATEDIRECTION_LTR;
691 text_run_info.bounds = bounds; 695 text_run_info.bounds = bounds;
692 text_runs.push_back(text_run_info); 696 text_runs.push_back(text_run_info);
697
698 pp::FloatRect char_bounds = engine_->GetCharBounds(page_index, char_index);
Lei Zhang 2016/06/09 22:19:05 Can you add a brief description of what this new b
dmazzoni 2016/06/10 17:44:52 Done.
699 for (uint32_t i = 0; i < text_run_info.len - 1; i++) {
700 pp::FloatRect next_char_bounds = engine_->GetCharBounds(
701 page_index, char_index + i + 1);
Lei Zhang 2016/06/09 22:19:05 Can you double check and make sure char_index + i
dmazzoni 2016/06/10 17:44:52 Added a DCHECK.
702 chars[char_index + i].char_width = next_char_bounds.x() - char_bounds.x();
703 char_bounds = next_char_bounds;
704 }
705 chars[char_index + text_run_info.len - 1].char_width = char_bounds.width();
706
693 char_index += text_run_info.len; 707 char_index += text_run_info.len;
694 } 708 }
695 709
696 page_info.text_run_count = text_runs.size(); 710 page_info.text_run_count = text_runs.size();
697 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info, 711 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info,
698 text_runs.data(), chars.data()); 712 text_runs.data(), chars.data());
699 713
700 // Schedule loading the next page. 714 // Schedule loading the next page.
701 pp::CompletionCallback callback = timer_factory_.NewCallback( 715 pp::CompletionCallback callback = timer_factory_.NewCallback(
702 &OutOfProcessInstance::SendNextAccessibilityPage); 716 &OutOfProcessInstance::SendNextAccessibilityPage);
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 content_restrictions |= CONTENT_RESTRICTION_COPY; 1261 content_restrictions |= CONTENT_RESTRICTION_COPY;
1248 1262
1249 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && 1263 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
1250 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { 1264 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
1251 content_restrictions |= CONTENT_RESTRICTION_PRINT; 1265 content_restrictions |= CONTENT_RESTRICTION_PRINT;
1252 } 1266 }
1253 1267
1254 pp::PDF::SetContentRestriction(this, content_restrictions); 1268 pp::PDF::SetContentRestriction(this, content_restrictions);
1255 1269
1256 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50); 1270 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50);
1271
1272 if (accessibility_enabled_)
Lei Zhang 2016/06/09 22:19:05 This is a bit confusing, since EnableAccessibility
dmazzoni 2016/06/10 17:44:52 Split into EnableAccessibility() and LoadAccessibi
1273 EnableAccessibility();
1257 } 1274 }
1258 1275
1259 void OutOfProcessInstance::RotateClockwise() { 1276 void OutOfProcessInstance::RotateClockwise() {
1260 engine_->RotateClockwise(); 1277 engine_->RotateClockwise();
1261 } 1278 }
1262 1279
1263 void OutOfProcessInstance::RotateCounterclockwise() { 1280 void OutOfProcessInstance::RotateCounterclockwise() {
1264 engine_->RotateCounterclockwise(); 1281 engine_->RotateCounterclockwise();
1265 } 1282 }
1266 1283
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 const pp::FloatPoint& scroll_offset) { 1543 const pp::FloatPoint& scroll_offset) {
1527 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1544 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1528 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1545 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1529 float min_y = -top_toolbar_height_; 1546 float min_y = -top_toolbar_height_;
1530 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1547 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1531 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1548 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1532 return pp::FloatPoint(x, y); 1549 return pp::FloatPoint(x, y);
1533 } 1550 }
1534 1551
1535 } // namespace chrome_pdf 1552 } // namespace chrome_pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698