OLD | NEW |
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 Loading... |
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_state_(ACCESSIBILITY_STATE_OFF) { |
307 loader_factory_.Initialize(this); | 307 loader_factory_.Initialize(this); |
308 timer_factory_.Initialize(this); | 308 timer_factory_.Initialize(this); |
309 form_factory_.Initialize(this); | 309 form_factory_.Initialize(this); |
310 print_callback_factory_.Initialize(this); | 310 print_callback_factory_.Initialize(this); |
311 engine_.reset(PDFEngine::Create(this)); | 311 engine_.reset(PDFEngine::Create(this)); |
312 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); | 312 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); |
313 AddPerInstanceObject(kPPPPdfInterface, this); | 313 AddPerInstanceObject(kPPPPdfInterface, this); |
314 | 314 |
315 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 315 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
316 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 316 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 options->duplex = | 623 options->duplex = |
624 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); | 624 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); |
625 options->copies = engine_->GetCopiesToPrint(); | 625 options->copies = engine_->GetCopiesToPrint(); |
626 pp::Size uniform_page_size; | 626 pp::Size uniform_page_size; |
627 options->is_page_size_uniform = | 627 options->is_page_size_uniform = |
628 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); | 628 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); |
629 options->uniform_page_size = uniform_page_size; | 629 options->uniform_page_size = uniform_page_size; |
630 } | 630 } |
631 | 631 |
632 void OutOfProcessInstance::EnableAccessibility() { | 632 void OutOfProcessInstance::EnableAccessibility() { |
633 if (accessibility_enabled_) | 633 if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) |
634 return; | 634 return; |
635 | 635 |
636 accessibility_enabled_ = true; | 636 if (accessibility_state_ == ACCESSIBILITY_STATE_OFF) |
| 637 accessibility_state_ = ACCESSIBILITY_STATE_PENDING; |
637 | 638 |
| 639 if (document_load_state_ == LOAD_STATE_COMPLETE) |
| 640 LoadAccessibility(); |
| 641 } |
| 642 |
| 643 void OutOfProcessInstance::LoadAccessibility() { |
| 644 accessibility_state_ = ACCESSIBILITY_STATE_LOADED; |
638 PP_PrivateAccessibilityDocInfo doc_info; | 645 PP_PrivateAccessibilityDocInfo doc_info; |
639 doc_info.page_count = engine_->GetNumberOfPages(); | 646 doc_info.page_count = engine_->GetNumberOfPages(); |
640 doc_info.text_accessible = PP_FromBool( | 647 doc_info.text_accessible = PP_FromBool( |
641 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); | 648 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); |
642 doc_info.text_copyable = PP_FromBool( | 649 doc_info.text_copyable = PP_FromBool( |
643 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); | 650 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); |
| 651 |
644 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); | 652 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); |
645 | 653 |
646 // If the document contents isn't accessible, don't send anything more. | 654 // If the document contents isn't accessible, don't send anything more. |
647 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || | 655 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || |
648 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { | 656 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { |
649 return; | 657 return; |
650 } | 658 } |
651 | 659 |
652 PP_PrivateAccessibilityViewportInfo viewport_info; | 660 PP_PrivateAccessibilityViewportInfo viewport_info; |
653 viewport_info.scroll.x = 0; | 661 viewport_info.scroll.x = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
670 | 678 |
671 int char_count = engine_->GetCharCount(page_index); | 679 int char_count = engine_->GetCharCount(page_index); |
672 PP_PrivateAccessibilityPageInfo page_info; | 680 PP_PrivateAccessibilityPageInfo page_info; |
673 page_info.page_index = page_index; | 681 page_info.page_index = page_index; |
674 page_info.bounds = engine_->GetPageBoundsRect(page_index); | 682 page_info.bounds = engine_->GetPageBoundsRect(page_index); |
675 page_info.char_count = char_count; | 683 page_info.char_count = char_count; |
676 | 684 |
677 std::vector<PP_PrivateAccessibilityCharInfo> chars(page_info.char_count); | 685 std::vector<PP_PrivateAccessibilityCharInfo> chars(page_info.char_count); |
678 for (uint32_t i = 0; i < page_info.char_count; ++i) { | 686 for (uint32_t i = 0; i < page_info.char_count; ++i) { |
679 chars[i].unicode_character = engine_->GetCharUnicode(page_index, i); | 687 chars[i].unicode_character = engine_->GetCharUnicode(page_index, i); |
680 chars[i].char_width = engine_->GetCharWidth(page_index, i); | |
681 } | 688 } |
682 | 689 |
683 std::vector<PP_PrivateAccessibilityTextRunInfo> text_runs; | 690 std::vector<PP_PrivateAccessibilityTextRunInfo> text_runs; |
684 int char_index = 0; | 691 int char_index = 0; |
685 while (char_index < char_count) { | 692 while (char_index < char_count) { |
686 PP_PrivateAccessibilityTextRunInfo text_run_info; | 693 PP_PrivateAccessibilityTextRunInfo text_run_info; |
687 pp::FloatRect bounds; | 694 pp::FloatRect bounds; |
688 engine_->GetTextRunInfo(page_index, char_index, &text_run_info.len, | 695 engine_->GetTextRunInfo(page_index, char_index, &text_run_info.len, |
689 &text_run_info.font_size, &bounds); | 696 &text_run_info.font_size, &bounds); |
| 697 DCHECK_LE(char_index + text_run_info.len, |
| 698 static_cast<uint32_t>(char_count)); |
690 text_run_info.direction = PP_PRIVATEDIRECTION_LTR; | 699 text_run_info.direction = PP_PRIVATEDIRECTION_LTR; |
691 text_run_info.bounds = bounds; | 700 text_run_info.bounds = bounds; |
692 text_runs.push_back(text_run_info); | 701 text_runs.push_back(text_run_info); |
| 702 |
| 703 // We need to provide enough information to draw a bounding box |
| 704 // around any arbitrary text range, but the bounding boxes of characters |
| 705 // we get from PDFium don't necessarily "line up". Walk through the |
| 706 // characters in each text run and let the width of each character be |
| 707 // the difference between the x coordinate of one character and the |
| 708 // x coordinate of the next. The rest of the bounds of each character |
| 709 // can be computed from the bounds of the text run. |
| 710 pp::FloatRect char_bounds = engine_->GetCharBounds(page_index, char_index); |
| 711 for (uint32_t i = 0; i < text_run_info.len - 1; i++) { |
| 712 DCHECK_LT(char_index + i + 1, |
| 713 static_cast<uint32_t>(char_count)); |
| 714 pp::FloatRect next_char_bounds = engine_->GetCharBounds( |
| 715 page_index, char_index + i + 1); |
| 716 chars[char_index + i].char_width = next_char_bounds.x() - char_bounds.x(); |
| 717 char_bounds = next_char_bounds; |
| 718 } |
| 719 chars[char_index + text_run_info.len - 1].char_width = char_bounds.width(); |
| 720 |
693 char_index += text_run_info.len; | 721 char_index += text_run_info.len; |
694 } | 722 } |
695 | 723 |
696 page_info.text_run_count = text_runs.size(); | 724 page_info.text_run_count = text_runs.size(); |
697 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info, | 725 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info, |
698 text_runs.data(), chars.data()); | 726 text_runs.data(), chars.data()); |
699 | 727 |
700 // Schedule loading the next page. | 728 // Schedule loading the next page. |
701 pp::CompletionCallback callback = timer_factory_.NewCallback( | 729 pp::CompletionCallback callback = timer_factory_.NewCallback( |
702 &OutOfProcessInstance::SendNextAccessibilityPage); | 730 &OutOfProcessInstance::SendNextAccessibilityPage); |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 content_restrictions |= CONTENT_RESTRICTION_COPY; | 1275 content_restrictions |= CONTENT_RESTRICTION_COPY; |
1248 | 1276 |
1249 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && | 1277 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && |
1250 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { | 1278 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { |
1251 content_restrictions |= CONTENT_RESTRICTION_PRINT; | 1279 content_restrictions |= CONTENT_RESTRICTION_PRINT; |
1252 } | 1280 } |
1253 | 1281 |
1254 pp::PDF::SetContentRestriction(this, content_restrictions); | 1282 pp::PDF::SetContentRestriction(this, content_restrictions); |
1255 | 1283 |
1256 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50); | 1284 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50); |
| 1285 |
| 1286 if (accessibility_state_ == ACCESSIBILITY_STATE_PENDING) |
| 1287 LoadAccessibility(); |
1257 } | 1288 } |
1258 | 1289 |
1259 void OutOfProcessInstance::RotateClockwise() { | 1290 void OutOfProcessInstance::RotateClockwise() { |
1260 engine_->RotateClockwise(); | 1291 engine_->RotateClockwise(); |
1261 } | 1292 } |
1262 | 1293 |
1263 void OutOfProcessInstance::RotateCounterclockwise() { | 1294 void OutOfProcessInstance::RotateCounterclockwise() { |
1264 engine_->RotateCounterclockwise(); | 1295 engine_->RotateCounterclockwise(); |
1265 } | 1296 } |
1266 | 1297 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 const pp::FloatPoint& scroll_offset) { | 1557 const pp::FloatPoint& scroll_offset) { |
1527 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1558 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); | 1559 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1529 float min_y = -top_toolbar_height_; | 1560 float min_y = -top_toolbar_height_; |
1530 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1561 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); | 1562 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1532 return pp::FloatPoint(x, y); | 1563 return pp::FloatPoint(x, y); |
1533 } | 1564 } |
1534 | 1565 |
1535 } // namespace chrome_pdf | 1566 } // namespace chrome_pdf |
OLD | NEW |