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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 // Selecting text in document (Plugin -> Page) | 146 // Selecting text in document (Plugin -> Page) |
147 const char kJSSetIsSelectingType[] = "setIsSelecting"; | 147 const char kJSSetIsSelectingType[] = "setIsSelecting"; |
148 const char kJSIsSelecting[] = "isSelecting"; | 148 const char kJSIsSelecting[] = "isSelecting"; |
149 | 149 |
150 // Notify when a form field is focused (Plugin -> Page) | 150 // Notify when a form field is focused (Plugin -> Page) |
151 const char kJSFieldFocusType[] = "formFocusChange"; | 151 const char kJSFieldFocusType[] = "formFocusChange"; |
152 const char kJSFieldFocus[] = "focused"; | 152 const char kJSFieldFocus[] = "focused"; |
153 | 153 |
154 const int kFindResultCooldownMs = 100; | 154 const int kFindResultCooldownMs = 100; |
155 | 155 |
156 // A delay to wait between each accessibility page to keep the system | |
157 // responsive. | |
158 const int kAccessibilityPageDelayMs = 100; | |
159 | |
156 const double kMinZoom = 0.01; | 160 const double kMinZoom = 0.01; |
157 | 161 |
158 namespace { | 162 namespace { |
159 | 163 |
160 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 164 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; |
161 | 165 |
162 // Used for UMA. Do not delete entries, and keep in sync with histograms.xml. | 166 // Used for UMA. Do not delete entries, and keep in sync with histograms.xml. |
163 enum PDFFeatures { | 167 enum PDFFeatures { |
164 LOADED_DOCUMENT = 0, | 168 LOADED_DOCUMENT = 0, |
165 HAS_TITLE = 1, | 169 HAS_TITLE = 1, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 PP_PdfPrintPresetOptions_Dev* options) { | 203 PP_PdfPrintPresetOptions_Dev* options) { |
200 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); | 204 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
201 if (object) { | 205 if (object) { |
202 OutOfProcessInstance* obj_instance = | 206 OutOfProcessInstance* obj_instance = |
203 static_cast<OutOfProcessInstance*>(object); | 207 static_cast<OutOfProcessInstance*>(object); |
204 obj_instance->GetPrintPresetOptionsFromDocument(options); | 208 obj_instance->GetPrintPresetOptionsFromDocument(options); |
205 } | 209 } |
206 return PP_TRUE; | 210 return PP_TRUE; |
207 } | 211 } |
208 | 212 |
213 void EnableAccessibility(PP_Instance instance) { | |
214 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); | |
215 if (object) { | |
216 OutOfProcessInstance* obj_instance = | |
217 static_cast<OutOfProcessInstance*>(object); | |
218 return obj_instance->EnableAccessibility(); | |
219 } | |
220 } | |
221 | |
209 const PPP_Pdf ppp_private = { | 222 const PPP_Pdf ppp_private = { |
210 &GetLinkAtPosition, | 223 &GetLinkAtPosition, |
211 &Transform, | 224 &Transform, |
212 &GetPrintPresetOptionsFromDocument | 225 &GetPrintPresetOptionsFromDocument, |
226 &EnableAccessibility, | |
213 }; | 227 }; |
214 | 228 |
215 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 229 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
216 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 230 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
217 std::vector<std::string> url_substr = base::SplitString( | 231 std::vector<std::string> url_substr = base::SplitString( |
218 src_url.substr(strlen(kChromePrint)), "/", | 232 src_url.substr(strlen(kChromePrint)), "/", |
219 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 233 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
220 if (url_substr.size() != 3) | 234 if (url_substr.size() != 3) |
221 return -1; | 235 return -1; |
222 | 236 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 preview_document_load_state_(LOAD_STATE_COMPLETE), | 295 preview_document_load_state_(LOAD_STATE_COMPLETE), |
282 uma_(this), | 296 uma_(this), |
283 told_browser_about_unsupported_feature_(false), | 297 told_browser_about_unsupported_feature_(false), |
284 print_preview_page_count_(0), | 298 print_preview_page_count_(0), |
285 last_progress_sent_(0), | 299 last_progress_sent_(0), |
286 recently_sent_find_update_(false), | 300 recently_sent_find_update_(false), |
287 received_viewport_message_(false), | 301 received_viewport_message_(false), |
288 did_call_start_loading_(false), | 302 did_call_start_loading_(false), |
289 stop_scrolling_(false), | 303 stop_scrolling_(false), |
290 background_color_(0), | 304 background_color_(0), |
291 top_toolbar_height_(0) { | 305 top_toolbar_height_(0), |
Lei Zhang
2016/06/01 21:26:33
indentation
dmazzoni
2016/06/01 22:56:43
Done.
| |
306 accessibility_enabled_(false) { | |
292 loader_factory_.Initialize(this); | 307 loader_factory_.Initialize(this); |
293 timer_factory_.Initialize(this); | 308 timer_factory_.Initialize(this); |
294 form_factory_.Initialize(this); | 309 form_factory_.Initialize(this); |
295 print_callback_factory_.Initialize(this); | 310 print_callback_factory_.Initialize(this); |
296 engine_.reset(PDFEngine::Create(this)); | 311 engine_.reset(PDFEngine::Create(this)); |
297 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); | 312 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); |
298 AddPerInstanceObject(kPPPPdfInterface, this); | 313 AddPerInstanceObject(kPPPPdfInterface, this); |
299 | 314 |
300 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 315 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
301 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 316 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | 622 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
608 options->duplex = | 623 options->duplex = |
609 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); | 624 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); |
610 options->copies = engine_->GetCopiesToPrint(); | 625 options->copies = engine_->GetCopiesToPrint(); |
611 pp::Size uniform_page_size; | 626 pp::Size uniform_page_size; |
612 options->is_page_size_uniform = | 627 options->is_page_size_uniform = |
613 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); | 628 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); |
614 options->uniform_page_size = uniform_page_size; | 629 options->uniform_page_size = uniform_page_size; |
615 } | 630 } |
616 | 631 |
632 void OutOfProcessInstance::EnableAccessibility() { | |
633 if (accessibility_enabled_) | |
634 return; | |
635 | |
636 accessibility_enabled_ = true; | |
637 | |
638 PP_PrivateAccessibilityDocInfo doc_info; | |
639 doc_info.page_count = engine_->GetNumberOfPages(); | |
640 doc_info.text_accessible = PP_FromBool( | |
641 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); | |
642 doc_info.text_copyable = PP_FromBool( | |
643 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); | |
644 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); | |
645 | |
646 // If the document contents isn't accessible, don't send anything more. | |
647 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || | |
648 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { | |
649 return; | |
650 } | |
651 | |
652 PP_PrivateAccessibilityViewportInfo viewport_info; | |
653 viewport_info.scroll.x = 0; | |
654 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_; | |
655 viewport_info.offset = available_area_.point(); | |
656 viewport_info.zoom = zoom_; | |
657 pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info); | |
658 | |
659 // Schedule loading the first page. | |
660 pp::CompletionCallback callback = | |
661 timer_factory_.NewCallback( | |
662 &OutOfProcessInstance::SendNextAccessibilityPage); | |
663 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, | |
664 callback, 0); | |
665 } | |
666 | |
667 void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { | |
668 int page_count = engine_->GetNumberOfPages(); | |
669 if (page_index < 0 || page_index >= page_count) | |
670 return; | |
671 | |
672 int char_count = engine_->GetCharCount(page_index); | |
673 PP_PrivateAccessibilityPageInfo page_info; | |
674 page_info.page_index = page_index; | |
675 page_info.bounds = engine_->GetPageBoundsRect(page_index); | |
676 page_info.char_count = char_count; | |
677 | |
678 std::vector<PP_PrivateAccessibilityCharInfo> chars(page_info.char_count); | |
679 for (uint32_t i = 0; i < page_info.char_count; ++i) { | |
680 chars[i].unicode_character = engine_->GetCharUnicode(page_index, i); | |
681 chars[i].char_width = engine_->GetCharWidth(page_index, i); | |
682 } | |
683 | |
684 std::vector<PP_PrivateAccessibilityTextRunInfo> text_runs; | |
685 int char_index = 0; | |
686 int text_run_index = 0; | |
687 while (char_index < char_count) { | |
688 PP_PrivateAccessibilityTextRunInfo text_run_info; | |
689 pp::FloatRect bounds; | |
690 engine_->GetTextRunInfo( | |
691 page_index, char_index, &text_run_info.len, | |
692 &text_run_info.font_size, &bounds); | |
693 text_run_info.direction = PP_PRIVATEDIRECTION_LTR; | |
694 text_run_info.bounds = bounds; | |
695 text_runs.push_back(text_run_info); | |
696 text_run_index++; | |
Lei Zhang
2016/06/01 21:26:33
We increment |text_run_index| but it's never read.
dmazzoni
2016/06/01 22:56:43
Done.
| |
697 char_index += text_run_info.len; | |
698 } | |
699 | |
700 page_info.text_run_count = text_runs.size(); | |
701 pp::PDF::SetAccessibilityPageInfo( | |
702 GetPluginInstance(), &page_info, text_runs.data(), chars.data()); | |
703 | |
704 // Schedule loading the next page. | |
705 pp::CompletionCallback callback = | |
706 timer_factory_.NewCallback( | |
707 &OutOfProcessInstance::SendNextAccessibilityPage); | |
708 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, | |
709 callback, page_index + 1); | |
710 } | |
711 | |
617 pp::Var OutOfProcessInstance::GetLinkAtPosition( | 712 pp::Var OutOfProcessInstance::GetLinkAtPosition( |
618 const pp::Point& point) { | 713 const pp::Point& point) { |
619 pp::Point offset_point(point); | 714 pp::Point offset_point(point); |
620 ScalePoint(device_scale_, &offset_point); | 715 ScalePoint(device_scale_, &offset_point); |
621 offset_point.set_x(offset_point.x() - available_area_.x()); | 716 offset_point.set_x(offset_point.x() - available_area_.x()); |
622 return engine_->GetLinkAtPosition(offset_point); | 717 return engine_->GetLinkAtPosition(offset_point); |
623 } | 718 } |
624 | 719 |
625 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() { | 720 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() { |
626 return engine_->QuerySupportedPrintOutputFormats(); | 721 return engine_->QuerySupportedPrintOutputFormats(); |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1436 const pp::FloatPoint& scroll_offset) { | 1531 const pp::FloatPoint& scroll_offset) { |
1437 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1532 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1438 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1533 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1439 float min_y = -top_toolbar_height_; | 1534 float min_y = -top_toolbar_height_; |
1440 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1535 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1441 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1536 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1442 return pp::FloatPoint(x, y); | 1537 return pp::FloatPoint(x, y); |
1443 } | 1538 } |
1444 | 1539 |
1445 } // namespace chrome_pdf | 1540 } // namespace chrome_pdf |
OLD | NEW |