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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) | 602 if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) |
603 return; | 603 return; |
604 | 604 |
605 if (accessibility_state_ == ACCESSIBILITY_STATE_OFF) | 605 if (accessibility_state_ == ACCESSIBILITY_STATE_OFF) |
606 accessibility_state_ = ACCESSIBILITY_STATE_PENDING; | 606 accessibility_state_ = ACCESSIBILITY_STATE_PENDING; |
607 | 607 |
608 if (document_load_state_ == LOAD_STATE_COMPLETE) | 608 if (document_load_state_ == LOAD_STATE_COMPLETE) |
609 LoadAccessibility(); | 609 LoadAccessibility(); |
610 } | 610 } |
611 | 611 |
612 void OutOfProcessInstance::LoadAccessibility() { | 612 void OutOfProcessInstance::LoadAccessibility() { |
raymes
2016/09/27 05:05:31
We should make sure these functions are in the sam
dmazzoni
2016/09/27 16:19:32
I rearranged these three to match. The rest of the
| |
613 accessibility_state_ = ACCESSIBILITY_STATE_LOADED; | 613 accessibility_state_ = ACCESSIBILITY_STATE_LOADED; |
614 PP_PrivateAccessibilityDocInfo doc_info; | 614 PP_PrivateAccessibilityDocInfo doc_info; |
615 doc_info.page_count = engine_->GetNumberOfPages(); | 615 doc_info.page_count = engine_->GetNumberOfPages(); |
616 doc_info.text_accessible = PP_FromBool( | 616 doc_info.text_accessible = PP_FromBool( |
617 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); | 617 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); |
618 doc_info.text_copyable = PP_FromBool( | 618 doc_info.text_copyable = PP_FromBool( |
619 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); | 619 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); |
620 | 620 |
621 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); | 621 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); |
622 | 622 |
623 // If the document contents isn't accessible, don't send anything more. | 623 // If the document contents isn't accessible, don't send anything more. |
624 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || | 624 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || |
625 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { | 625 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { |
626 return; | 626 return; |
627 } | 627 } |
628 | 628 |
629 PP_PrivateAccessibilityViewportInfo viewport_info; | 629 SendAccessibilityViewportInfo(); |
630 viewport_info.scroll.x = 0; | |
631 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_; | |
632 viewport_info.offset = available_area_.point(); | |
633 viewport_info.zoom = zoom_ * device_scale_; | |
634 pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info); | |
635 | 630 |
636 // Schedule loading the first page. | 631 // Schedule loading the first page. |
637 pp::CompletionCallback callback = timer_factory_.NewCallback( | 632 pp::CompletionCallback callback = timer_factory_.NewCallback( |
638 &OutOfProcessInstance::SendNextAccessibilityPage); | 633 &OutOfProcessInstance::SendNextAccessibilityPage); |
639 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, | 634 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, |
640 callback, 0); | 635 callback, 0); |
641 } | 636 } |
642 | 637 |
638 void OutOfProcessInstance::SendAccessibilityViewportInfo() { | |
639 PP_PrivateAccessibilityViewportInfo viewport_info; | |
640 viewport_info.scroll.x = 0; | |
641 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_; | |
642 viewport_info.offset = available_area_.point(); | |
643 viewport_info.zoom = zoom_ * device_scale_; | |
644 pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info); | |
645 } | |
646 | |
643 void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { | 647 void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { |
644 int page_count = engine_->GetNumberOfPages(); | 648 int page_count = engine_->GetNumberOfPages(); |
645 if (page_index < 0 || page_index >= page_count) | 649 if (page_index < 0 || page_index >= page_count) |
646 return; | 650 return; |
647 | 651 |
648 int char_count = engine_->GetCharCount(page_index); | 652 int char_count = engine_->GetCharCount(page_index); |
649 PP_PrivateAccessibilityPageInfo page_info; | 653 PP_PrivateAccessibilityPageInfo page_info; |
650 page_info.page_index = page_index; | 654 page_info.page_index = page_index; |
651 page_info.bounds = engine_->GetPageBoundsRect(page_index); | 655 page_info.bounds = engine_->GetPageBoundsRect(page_index); |
652 page_info.char_count = char_count; | 656 page_info.char_count = char_count; |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 if (bottom_of_document < available_area_.height()) | 1415 if (bottom_of_document < available_area_.height()) |
1412 available_area_.set_height(bottom_of_document); | 1416 available_area_.set_height(bottom_of_document); |
1413 | 1417 |
1414 CalculateBackgroundParts(); | 1418 CalculateBackgroundParts(); |
1415 engine_->PageOffsetUpdated(available_area_.point()); | 1419 engine_->PageOffsetUpdated(available_area_.point()); |
1416 engine_->PluginSizeUpdated(available_area_.size()); | 1420 engine_->PluginSizeUpdated(available_area_.size()); |
1417 | 1421 |
1418 if (document_size_.IsEmpty()) | 1422 if (document_size_.IsEmpty()) |
1419 return; | 1423 return; |
1420 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); | 1424 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); |
1425 | |
1426 if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) | |
1427 SendAccessibilityViewportInfo(); | |
1421 } | 1428 } |
1422 | 1429 |
1423 void OutOfProcessInstance::LoadUrl(const std::string& url) { | 1430 void OutOfProcessInstance::LoadUrl(const std::string& url) { |
1424 LoadUrlInternal(url, &embed_loader_, &OutOfProcessInstance::DidOpen); | 1431 LoadUrlInternal(url, &embed_loader_, &OutOfProcessInstance::DidOpen); |
1425 } | 1432 } |
1426 | 1433 |
1427 void OutOfProcessInstance::LoadPreviewUrl(const std::string& url) { | 1434 void OutOfProcessInstance::LoadPreviewUrl(const std::string& url) { |
1428 LoadUrlInternal(url, &embed_preview_loader_, | 1435 LoadUrlInternal(url, &embed_preview_loader_, |
1429 &OutOfProcessInstance::DidOpenPreview); | 1436 &OutOfProcessInstance::DidOpenPreview); |
1430 } | 1437 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1527 const pp::FloatPoint& scroll_offset) { | 1534 const pp::FloatPoint& scroll_offset) { |
1528 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1535 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1529 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1536 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1530 float min_y = -top_toolbar_height_; | 1537 float min_y = -top_toolbar_height_; |
1531 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1538 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1532 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1539 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1533 return pp::FloatPoint(x, y); | 1540 return pp::FloatPoint(x, y); |
1534 } | 1541 } |
1535 | 1542 |
1536 } // namespace chrome_pdf | 1543 } // namespace chrome_pdf |
OLD | NEW |