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/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const int32_t kHighlightColorG = 193; | 81 const int32_t kHighlightColorG = 193; |
82 const int32_t kHighlightColorB = 218; | 82 const int32_t kHighlightColorB = 218; |
83 | 83 |
84 const uint32_t kPendingPageColor = 0xFFEEEEEE; | 84 const uint32_t kPendingPageColor = 0xFFEEEEEE; |
85 | 85 |
86 const uint32_t kFormHighlightColor = 0xFFE4DD; | 86 const uint32_t kFormHighlightColor = 0xFFE4DD; |
87 const int32_t kFormHighlightAlpha = 100; | 87 const int32_t kFormHighlightAlpha = 100; |
88 | 88 |
89 const int32_t kMaxPasswordTries = 3; | 89 const int32_t kMaxPasswordTries = 3; |
90 | 90 |
| 91 const int32_t kTouchLongPressTimeoutMs = 300; |
| 92 |
91 // See Table 3.20 in | 93 // See Table 3.20 in |
92 // http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf | 94 // http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf |
93 const uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2; | 95 const uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2; |
94 const uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11; | 96 const uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11; |
95 const uint32_t kPDFPermissionCopyMask = 1 << 4; | 97 const uint32_t kPDFPermissionCopyMask = 1 << 4; |
96 const uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9; | 98 const uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9; |
97 | 99 |
98 const int32_t kLoadingTextVerticalOffset = 50; | 100 const int32_t kLoadingTextVerticalOffset = 50; |
99 | 101 |
100 // The maximum amount of time we'll spend doing a paint before we give back | 102 // The maximum amount of time we'll spend doing a paint before we give back |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 defer_page_unload_(false), | 676 defer_page_unload_(false), |
675 selecting_(false), | 677 selecting_(false), |
676 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 678 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
677 PDFiumPage::LinkTarget()), | 679 PDFiumPage::LinkTarget()), |
678 next_page_to_search_(-1), | 680 next_page_to_search_(-1), |
679 last_page_to_search_(-1), | 681 last_page_to_search_(-1), |
680 last_character_index_to_search_(-1), | 682 last_character_index_to_search_(-1), |
681 permissions_(0), | 683 permissions_(0), |
682 permissions_handler_revision_(-1), | 684 permissions_handler_revision_(-1), |
683 fpdf_availability_(nullptr), | 685 fpdf_availability_(nullptr), |
684 next_timer_id_(0), | 686 next_formfill_timer_id_(0), |
| 687 next_touch_timer_id_(0), |
685 last_page_mouse_down_(-1), | 688 last_page_mouse_down_(-1), |
686 most_visible_page_(-1), | 689 most_visible_page_(-1), |
687 called_do_document_action_(false), | 690 called_do_document_action_(false), |
688 render_grayscale_(false), | 691 render_grayscale_(false), |
689 render_annots_(true), | 692 render_annots_(true), |
690 progressive_paint_timeout_(0), | 693 progressive_paint_timeout_(0), |
691 getting_password_(false) { | 694 getting_password_(false) { |
692 find_factory_.Initialize(this); | 695 find_factory_.Initialize(this); |
693 password_factory_.Initialize(this); | 696 password_factory_.Initialize(this); |
694 | 697 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 break; | 1331 break; |
1329 case PP_INPUTEVENT_TYPE_KEYDOWN: | 1332 case PP_INPUTEVENT_TYPE_KEYDOWN: |
1330 rv = OnKeyDown(pp::KeyboardInputEvent(event)); | 1333 rv = OnKeyDown(pp::KeyboardInputEvent(event)); |
1331 break; | 1334 break; |
1332 case PP_INPUTEVENT_TYPE_KEYUP: | 1335 case PP_INPUTEVENT_TYPE_KEYUP: |
1333 rv = OnKeyUp(pp::KeyboardInputEvent(event)); | 1336 rv = OnKeyUp(pp::KeyboardInputEvent(event)); |
1334 break; | 1337 break; |
1335 case PP_INPUTEVENT_TYPE_CHAR: | 1338 case PP_INPUTEVENT_TYPE_CHAR: |
1336 rv = OnChar(pp::KeyboardInputEvent(event)); | 1339 rv = OnChar(pp::KeyboardInputEvent(event)); |
1337 break; | 1340 break; |
| 1341 case PP_INPUTEVENT_TYPE_TOUCHSTART: { |
| 1342 KillTouchTimer(next_touch_timer_id_); |
| 1343 |
| 1344 pp::TouchInputEvent touch_event(event); |
| 1345 if (touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) |
| 1346 ScheduleTouchTimer(touch_event); |
| 1347 break; |
| 1348 } |
| 1349 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 1350 KillTouchTimer(next_touch_timer_id_); |
| 1351 break; |
| 1352 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 1353 // TODO(dsinclair): This should allow a little bit of movement (up to the |
| 1354 // touch radii) to account for finger jiggle. |
| 1355 KillTouchTimer(next_touch_timer_id_); |
1338 default: | 1356 default: |
1339 break; | 1357 break; |
1340 } | 1358 } |
1341 | 1359 |
1342 DCHECK(defer_page_unload_); | 1360 DCHECK(defer_page_unload_); |
1343 defer_page_unload_ = false; | 1361 defer_page_unload_ = false; |
1344 for (int page_index : deferred_page_unloads_) | 1362 for (int page_index : deferred_page_unloads_) |
1345 pages_[page_index]->Unload(); | 1363 pages_[page_index]->Unload(); |
1346 deferred_page_unloads_.clear(); | 1364 deferred_page_unloads_.clear(); |
1347 return rv; | 1365 return rv; |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 | 2475 |
2458 int PDFiumEngine::GetVerticalScrollbarYPosition() { | 2476 int PDFiumEngine::GetVerticalScrollbarYPosition() { |
2459 return position_.y(); | 2477 return position_.y(); |
2460 } | 2478 } |
2461 | 2479 |
2462 void PDFiumEngine::SetGrayscale(bool grayscale) { | 2480 void PDFiumEngine::SetGrayscale(bool grayscale) { |
2463 render_grayscale_ = grayscale; | 2481 render_grayscale_ = grayscale; |
2464 } | 2482 } |
2465 | 2483 |
2466 void PDFiumEngine::OnCallback(int id) { | 2484 void PDFiumEngine::OnCallback(int id) { |
2467 if (!timers_.count(id)) | 2485 if (!formfill_timers_.count(id)) |
2468 return; | 2486 return; |
2469 | 2487 |
2470 timers_[id].second(id); | 2488 formfill_timers_[id].second(id); |
2471 if (timers_.count(id)) // The callback might delete the timer. | 2489 if (formfill_timers_.count(id)) // The callback might delete the timer. |
2472 client_->ScheduleCallback(id, timers_[id].first); | 2490 client_->ScheduleCallback(id, formfill_timers_[id].first); |
| 2491 } |
| 2492 |
| 2493 void PDFiumEngine::OnTouchTimerCallback(int id) { |
| 2494 if (!touch_timers_.count(id)) |
| 2495 return; |
| 2496 |
| 2497 HandleLongPress(touch_timers_[id]); |
| 2498 KillTouchTimer(id); |
| 2499 } |
| 2500 |
| 2501 void PDFiumEngine::HandleLongPress(const pp::TouchInputEvent& event) { |
| 2502 pp::FloatPoint fp = |
| 2503 event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position(); |
| 2504 pp::Point point; |
| 2505 point.set_x(fp.x()); |
| 2506 point.set_y(fp.y()); |
| 2507 |
| 2508 // Send a fake mouse down to trigger the multi-click selection code. |
| 2509 pp::MouseInputEvent mouse_event( |
| 2510 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_MOUSEDOWN, |
| 2511 event.GetTimeStamp(), event.GetModifiers(), |
| 2512 PP_INPUTEVENT_MOUSEBUTTON_LEFT, point, 2, point); |
| 2513 |
| 2514 OnMouseDown(mouse_event); |
2473 } | 2515 } |
2474 | 2516 |
2475 int PDFiumEngine::GetCharCount(int page_index) { | 2517 int PDFiumEngine::GetCharCount(int page_index) { |
2476 DCHECK(PageIndexInBounds(page_index)); | 2518 DCHECK(PageIndexInBounds(page_index)); |
2477 return pages_[page_index]->GetCharCount(); | 2519 return pages_[page_index]->GetCharCount(); |
2478 } | 2520 } |
2479 | 2521 |
2480 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { | 2522 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { |
2481 DCHECK(PageIndexInBounds(page_index)); | 2523 DCHECK(PageIndexInBounds(page_index)); |
2482 return pages_[page_index]->GetCharBounds(char_index); | 2524 return pages_[page_index]->GetCharBounds(char_index); |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3531 client_->ScrollToPage(most_visible_page); | 3573 client_->ScrollToPage(most_visible_page); |
3532 } | 3574 } |
3533 | 3575 |
3534 void PDFiumEngine::SetSelecting(bool selecting) { | 3576 void PDFiumEngine::SetSelecting(bool selecting) { |
3535 bool was_selecting = selecting_; | 3577 bool was_selecting = selecting_; |
3536 selecting_ = selecting; | 3578 selecting_ = selecting; |
3537 if (selecting_ != was_selecting) | 3579 if (selecting_ != was_selecting) |
3538 client_->IsSelectingChanged(selecting); | 3580 client_->IsSelectingChanged(selecting); |
3539 } | 3581 } |
3540 | 3582 |
| 3583 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
| 3584 touch_timers_[++next_touch_timer_id_] = evt; |
| 3585 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
| 3586 kTouchLongPressTimeoutMs); |
| 3587 } |
| 3588 |
| 3589 void PDFiumEngine::KillTouchTimer(int timer_id) { |
| 3590 touch_timers_.erase(timer_id); |
| 3591 } |
| 3592 |
3541 bool PDFiumEngine::PageIndexInBounds(int index) const { | 3593 bool PDFiumEngine::PageIndexInBounds(int index) const { |
3542 return index >= 0 && index < static_cast<int>(pages_.size()); | 3594 return index >= 0 && index < static_cast<int>(pages_.size()); |
3543 } | 3595 } |
3544 | 3596 |
3545 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, | 3597 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, |
3546 FPDF_PAGE page, | 3598 FPDF_PAGE page, |
3547 double left, | 3599 double left, |
3548 double top, | 3600 double top, |
3549 double right, | 3601 double right, |
3550 double bottom) { | 3602 double bottom) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 | 3634 |
3583 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { | 3635 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { |
3584 // We don't need this since it's not enough to change the cursor in all | 3636 // We don't need this since it's not enough to change the cursor in all |
3585 // scenarios. Instead, we check which form field we're under in OnMouseMove. | 3637 // scenarios. Instead, we check which form field we're under in OnMouseMove. |
3586 } | 3638 } |
3587 | 3639 |
3588 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, | 3640 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, |
3589 int elapse, | 3641 int elapse, |
3590 TimerCallback timer_func) { | 3642 TimerCallback timer_func) { |
3591 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3643 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3592 engine->timers_[++engine->next_timer_id_] = | 3644 engine->formfill_timers_[++engine->next_formfill_timer_id_] = |
3593 std::pair<int, TimerCallback>(elapse, timer_func); | 3645 std::pair<int, TimerCallback>(elapse, timer_func); |
3594 engine->client_->ScheduleCallback(engine->next_timer_id_, elapse); | 3646 engine->client_->ScheduleCallback(engine->next_formfill_timer_id_, elapse); |
3595 return engine->next_timer_id_; | 3647 return engine->next_formfill_timer_id_; |
3596 } | 3648 } |
3597 | 3649 |
3598 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { | 3650 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { |
3599 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3651 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3600 engine->timers_.erase(timer_id); | 3652 engine->formfill_timers_.erase(timer_id); |
3601 } | 3653 } |
3602 | 3654 |
3603 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { | 3655 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { |
3604 base::Time time = base::Time::Now(); | 3656 base::Time time = base::Time::Now(); |
3605 base::Time::Exploded exploded; | 3657 base::Time::Exploded exploded; |
3606 time.LocalExplode(&exploded); | 3658 time.LocalExplode(&exploded); |
3607 | 3659 |
3608 FPDF_SYSTEMTIME rv; | 3660 FPDF_SYSTEMTIME rv; |
3609 rv.wYear = exploded.year; | 3661 rv.wYear = exploded.year; |
3610 rv.wMonth = exploded.month; | 3662 rv.wMonth = exploded.month; |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4119 FPDF_DOCUMENT doc = | 4171 FPDF_DOCUMENT doc = |
4120 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4172 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4121 if (!doc) | 4173 if (!doc) |
4122 return false; | 4174 return false; |
4123 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4175 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4124 FPDF_CloseDocument(doc); | 4176 FPDF_CloseDocument(doc); |
4125 return success; | 4177 return success; |
4126 } | 4178 } |
4127 | 4179 |
4128 } // namespace chrome_pdf | 4180 } // namespace chrome_pdf |
OLD | NEW |