| 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 defer_page_unload_(false), | 690 defer_page_unload_(false), |
| 689 selecting_(false), | 691 selecting_(false), |
| 690 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 692 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
| 691 PDFiumPage::LinkTarget()), | 693 PDFiumPage::LinkTarget()), |
| 692 next_page_to_search_(-1), | 694 next_page_to_search_(-1), |
| 693 last_page_to_search_(-1), | 695 last_page_to_search_(-1), |
| 694 last_character_index_to_search_(-1), | 696 last_character_index_to_search_(-1), |
| 695 permissions_(0), | 697 permissions_(0), |
| 696 permissions_handler_revision_(-1), | 698 permissions_handler_revision_(-1), |
| 697 fpdf_availability_(nullptr), | 699 fpdf_availability_(nullptr), |
| 698 next_timer_id_(0), | 700 next_formfill_timer_id_(0), |
| 699 last_page_mouse_down_(-1), | 701 last_page_mouse_down_(-1), |
| 700 most_visible_page_(-1), | 702 most_visible_page_(-1), |
| 701 called_do_document_action_(false), | 703 called_do_document_action_(false), |
| 702 render_grayscale_(false), | 704 render_grayscale_(false), |
| 703 render_annots_(true), | 705 render_annots_(true), |
| 704 progressive_paint_timeout_(0), | 706 progressive_paint_timeout_(0), |
| 705 getting_password_(false) { | 707 getting_password_(false) { |
| 706 find_factory_.Initialize(this); | 708 find_factory_.Initialize(this); |
| 707 password_factory_.Initialize(this); | 709 password_factory_.Initialize(this); |
| 708 | 710 |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 break; | 1348 break; |
| 1347 case PP_INPUTEVENT_TYPE_KEYDOWN: | 1349 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 1348 rv = OnKeyDown(pp::KeyboardInputEvent(event)); | 1350 rv = OnKeyDown(pp::KeyboardInputEvent(event)); |
| 1349 break; | 1351 break; |
| 1350 case PP_INPUTEVENT_TYPE_KEYUP: | 1352 case PP_INPUTEVENT_TYPE_KEYUP: |
| 1351 rv = OnKeyUp(pp::KeyboardInputEvent(event)); | 1353 rv = OnKeyUp(pp::KeyboardInputEvent(event)); |
| 1352 break; | 1354 break; |
| 1353 case PP_INPUTEVENT_TYPE_CHAR: | 1355 case PP_INPUTEVENT_TYPE_CHAR: |
| 1354 rv = OnChar(pp::KeyboardInputEvent(event)); | 1356 rv = OnChar(pp::KeyboardInputEvent(event)); |
| 1355 break; | 1357 break; |
| 1358 case PP_INPUTEVENT_TYPE_TOUCHSTART: { |
| 1359 KillTouchTimer(next_touch_timer_id_); |
| 1360 |
| 1361 pp::TouchInputEvent touch_event(event); |
| 1362 if (touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) |
| 1363 ScheduleTouchTimer(touch_event); |
| 1364 break; |
| 1365 } |
| 1366 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 1367 KillTouchTimer(next_touch_timer_id_); |
| 1368 break; |
| 1369 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 1370 // TODO(dsinclair): This should allow a little bit of movement (up to the |
| 1371 // touch radii) to account for finger jiggle. |
| 1372 KillTouchTimer(next_touch_timer_id_); |
| 1356 default: | 1373 default: |
| 1357 break; | 1374 break; |
| 1358 } | 1375 } |
| 1359 | 1376 |
| 1360 DCHECK(defer_page_unload_); | 1377 DCHECK(defer_page_unload_); |
| 1361 defer_page_unload_ = false; | 1378 defer_page_unload_ = false; |
| 1362 for (int page_index : deferred_page_unloads_) | 1379 for (int page_index : deferred_page_unloads_) |
| 1363 pages_[page_index]->Unload(); | 1380 pages_[page_index]->Unload(); |
| 1364 deferred_page_unloads_.clear(); | 1381 deferred_page_unloads_.clear(); |
| 1365 return rv; | 1382 return rv; |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 | 2529 |
| 2513 int PDFiumEngine::GetVerticalScrollbarYPosition() { | 2530 int PDFiumEngine::GetVerticalScrollbarYPosition() { |
| 2514 return position_.y(); | 2531 return position_.y(); |
| 2515 } | 2532 } |
| 2516 | 2533 |
| 2517 void PDFiumEngine::SetGrayscale(bool grayscale) { | 2534 void PDFiumEngine::SetGrayscale(bool grayscale) { |
| 2518 render_grayscale_ = grayscale; | 2535 render_grayscale_ = grayscale; |
| 2519 } | 2536 } |
| 2520 | 2537 |
| 2521 void PDFiumEngine::OnCallback(int id) { | 2538 void PDFiumEngine::OnCallback(int id) { |
| 2522 if (!timers_.count(id)) | 2539 if (!formfill_timers_.count(id)) |
| 2523 return; | 2540 return; |
| 2524 | 2541 |
| 2525 timers_[id].second(id); | 2542 formfill_timers_[id].second(id); |
| 2526 if (timers_.count(id)) // The callback might delete the timer. | 2543 if (formfill_timers_.count(id)) // The callback might delete the timer. |
| 2527 client_->ScheduleCallback(id, timers_[id].first); | 2544 client_->ScheduleCallback(id, formfill_timers_[id].first); |
| 2545 } |
| 2546 |
| 2547 void PDFiumEngine::OnTouchTimerCallback(int id) { |
| 2548 if (!touch_timers_.count(id)) |
| 2549 return; |
| 2550 |
| 2551 HandleLongPress(touch_timers_[id]); |
| 2552 KillTouchTimer(id); |
| 2553 } |
| 2554 |
| 2555 void PDFiumEngine::HandleLongPress(const pp::TouchInputEvent& event) { |
| 2556 pp::FloatPoint fp = |
| 2557 event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position(); |
| 2558 pp::Point point; |
| 2559 point.set_x(fp.x()); |
| 2560 point.set_y(fp.y()); |
| 2561 |
| 2562 // Send a fake mouse down to trigger the multi-click selection code. |
| 2563 pp::MouseInputEvent mouse_event( |
| 2564 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_MOUSEDOWN, |
| 2565 event.GetTimeStamp(), event.GetModifiers(), |
| 2566 PP_INPUTEVENT_MOUSEBUTTON_LEFT, point, 2, point); |
| 2567 |
| 2568 OnMouseDown(mouse_event); |
| 2528 } | 2569 } |
| 2529 | 2570 |
| 2530 int PDFiumEngine::GetCharCount(int page_index) { | 2571 int PDFiumEngine::GetCharCount(int page_index) { |
| 2531 DCHECK(PageIndexInBounds(page_index)); | 2572 DCHECK(PageIndexInBounds(page_index)); |
| 2532 return pages_[page_index]->GetCharCount(); | 2573 return pages_[page_index]->GetCharCount(); |
| 2533 } | 2574 } |
| 2534 | 2575 |
| 2535 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { | 2576 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { |
| 2536 DCHECK(PageIndexInBounds(page_index)); | 2577 DCHECK(PageIndexInBounds(page_index)); |
| 2537 return pages_[page_index]->GetCharBounds(char_index); | 2578 return pages_[page_index]->GetCharBounds(char_index); |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3605 client_->ScrollToPage(most_visible_page); | 3646 client_->ScrollToPage(most_visible_page); |
| 3606 } | 3647 } |
| 3607 | 3648 |
| 3608 void PDFiumEngine::SetSelecting(bool selecting) { | 3649 void PDFiumEngine::SetSelecting(bool selecting) { |
| 3609 bool was_selecting = selecting_; | 3650 bool was_selecting = selecting_; |
| 3610 selecting_ = selecting; | 3651 selecting_ = selecting; |
| 3611 if (selecting_ != was_selecting) | 3652 if (selecting_ != was_selecting) |
| 3612 client_->IsSelectingChanged(selecting); | 3653 client_->IsSelectingChanged(selecting); |
| 3613 } | 3654 } |
| 3614 | 3655 |
| 3656 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
| 3657 touch_timers_[++next_touch_timer_id_] = evt; |
| 3658 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
| 3659 kTouchLongPressTimeoutMs); |
| 3660 } |
| 3661 |
| 3662 void PDFiumEngine::KillTouchTimer(int timer_id) { |
| 3663 touch_timers_.erase(timer_id); |
| 3664 } |
| 3665 |
| 3615 bool PDFiumEngine::PageIndexInBounds(int index) const { | 3666 bool PDFiumEngine::PageIndexInBounds(int index) const { |
| 3616 return index >= 0 && index < static_cast<int>(pages_.size()); | 3667 return index >= 0 && index < static_cast<int>(pages_.size()); |
| 3617 } | 3668 } |
| 3618 | 3669 |
| 3619 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, | 3670 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, |
| 3620 FPDF_PAGE page, | 3671 FPDF_PAGE page, |
| 3621 double left, | 3672 double left, |
| 3622 double top, | 3673 double top, |
| 3623 double right, | 3674 double right, |
| 3624 double bottom) { | 3675 double bottom) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3656 | 3707 |
| 3657 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { | 3708 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { |
| 3658 // We don't need this since it's not enough to change the cursor in all | 3709 // We don't need this since it's not enough to change the cursor in all |
| 3659 // scenarios. Instead, we check which form field we're under in OnMouseMove. | 3710 // scenarios. Instead, we check which form field we're under in OnMouseMove. |
| 3660 } | 3711 } |
| 3661 | 3712 |
| 3662 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, | 3713 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, |
| 3663 int elapse, | 3714 int elapse, |
| 3664 TimerCallback timer_func) { | 3715 TimerCallback timer_func) { |
| 3665 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3716 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3666 engine->timers_[++engine->next_timer_id_] = | 3717 engine->formfill_timers_[++engine->next_formfill_timer_id_] = |
| 3667 std::pair<int, TimerCallback>(elapse, timer_func); | 3718 std::pair<int, TimerCallback>(elapse, timer_func); |
| 3668 engine->client_->ScheduleCallback(engine->next_timer_id_, elapse); | 3719 engine->client_->ScheduleCallback(engine->next_formfill_timer_id_, elapse); |
| 3669 return engine->next_timer_id_; | 3720 return engine->next_formfill_timer_id_; |
| 3670 } | 3721 } |
| 3671 | 3722 |
| 3672 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { | 3723 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { |
| 3673 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3724 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3674 engine->timers_.erase(timer_id); | 3725 engine->formfill_timers_.erase(timer_id); |
| 3675 } | 3726 } |
| 3676 | 3727 |
| 3677 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { | 3728 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { |
| 3678 base::Time time = base::Time::Now(); | 3729 base::Time time = base::Time::Now(); |
| 3679 base::Time::Exploded exploded; | 3730 base::Time::Exploded exploded; |
| 3680 time.LocalExplode(&exploded); | 3731 time.LocalExplode(&exploded); |
| 3681 | 3732 |
| 3682 FPDF_SYSTEMTIME rv; | 3733 FPDF_SYSTEMTIME rv; |
| 3683 rv.wYear = exploded.year; | 3734 rv.wYear = exploded.year; |
| 3684 rv.wMonth = exploded.month; | 3735 rv.wMonth = exploded.month; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4199 FPDF_DOCUMENT doc = | 4250 FPDF_DOCUMENT doc = |
| 4200 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4251 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4201 if (!doc) | 4252 if (!doc) |
| 4202 return false; | 4253 return false; |
| 4203 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4254 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4204 FPDF_CloseDocument(doc); | 4255 FPDF_CloseDocument(doc); |
| 4205 return success; | 4256 return success; |
| 4206 } | 4257 } |
| 4207 | 4258 |
| 4208 } // namespace chrome_pdf | 4259 } // namespace chrome_pdf |
| OLD | NEW |