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

Side by Side Diff: pdf/out_of_process_instance.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 and run git cl format 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
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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),
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
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 = timer_factory_.NewCallback(
661 &OutOfProcessInstance::SendNextAccessibilityPage);
662 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
663 callback, 0);
664 }
665
666 void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
667 int page_count = engine_->GetNumberOfPages();
668 if (page_index < 0 || page_index >= page_count)
669 return;
670
671 int char_count = engine_->GetCharCount(page_index);
672 PP_PrivateAccessibilityPageInfo page_info;
673 page_info.page_index = page_index;
674 page_info.bounds = engine_->GetPageBoundsRect(page_index);
675 page_info.char_count = char_count;
676
677 std::vector<PP_PrivateAccessibilityCharInfo> chars(page_info.char_count);
678 for (uint32_t i = 0; i < page_info.char_count; ++i) {
679 chars[i].unicode_character = engine_->GetCharUnicode(page_index, i);
680 chars[i].char_width = engine_->GetCharWidth(page_index, i);
681 }
682
683 std::vector<PP_PrivateAccessibilityTextRunInfo> text_runs;
684 int char_index = 0;
685 while (char_index < char_count) {
686 PP_PrivateAccessibilityTextRunInfo text_run_info;
687 pp::FloatRect bounds;
688 engine_->GetTextRunInfo(page_index, char_index, &text_run_info.len,
689 &text_run_info.font_size, &bounds);
690 text_run_info.direction = PP_PRIVATEDIRECTION_LTR;
691 text_run_info.bounds = bounds;
692 text_runs.push_back(text_run_info);
693 char_index += text_run_info.len;
694 }
695
696 page_info.text_run_count = text_runs.size();
697 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info,
698 text_runs.data(), chars.data());
699
700 // Schedule loading the next page.
701 pp::CompletionCallback callback = timer_factory_.NewCallback(
702 &OutOfProcessInstance::SendNextAccessibilityPage);
703 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
704 callback, page_index + 1);
705 }
706
617 pp::Var OutOfProcessInstance::GetLinkAtPosition( 707 pp::Var OutOfProcessInstance::GetLinkAtPosition(
618 const pp::Point& point) { 708 const pp::Point& point) {
619 pp::Point offset_point(point); 709 pp::Point offset_point(point);
620 ScalePoint(device_scale_, &offset_point); 710 ScalePoint(device_scale_, &offset_point);
621 offset_point.set_x(offset_point.x() - available_area_.x()); 711 offset_point.set_x(offset_point.x() - available_area_.x());
622 return engine_->GetLinkAtPosition(offset_point); 712 return engine_->GetLinkAtPosition(offset_point);
623 } 713 }
624 714
625 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() { 715 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() {
626 return engine_->QuerySupportedPrintOutputFormats(); 716 return engine_->QuerySupportedPrintOutputFormats();
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 const pp::FloatPoint& scroll_offset) { 1526 const pp::FloatPoint& scroll_offset) {
1437 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1527 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); 1528 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1439 float min_y = -top_toolbar_height_; 1529 float min_y = -top_toolbar_height_;
1440 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1530 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); 1531 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1442 return pp::FloatPoint(x, y); 1532 return pp::FloatPoint(x, y);
1443 } 1533 }
1444 1534
1445 } // namespace chrome_pdf 1535 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698