| 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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 defer_page_unload_(false), | 681 defer_page_unload_(false), |
| 680 selecting_(false), | 682 selecting_(false), |
| 681 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 683 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
| 682 PDFiumPage::LinkTarget()), | 684 PDFiumPage::LinkTarget()), |
| 683 next_page_to_search_(-1), | 685 next_page_to_search_(-1), |
| 684 last_page_to_search_(-1), | 686 last_page_to_search_(-1), |
| 685 last_character_index_to_search_(-1), | 687 last_character_index_to_search_(-1), |
| 686 permissions_(0), | 688 permissions_(0), |
| 687 permissions_handler_revision_(-1), | 689 permissions_handler_revision_(-1), |
| 688 fpdf_availability_(nullptr), | 690 fpdf_availability_(nullptr), |
| 689 next_timer_id_(0), | 691 next_formfill_timer_id_(0), |
| 692 next_touch_timer_id_(0), |
| 690 last_page_mouse_down_(-1), | 693 last_page_mouse_down_(-1), |
| 691 most_visible_page_(-1), | 694 most_visible_page_(-1), |
| 692 called_do_document_action_(false), | 695 called_do_document_action_(false), |
| 693 render_grayscale_(false), | 696 render_grayscale_(false), |
| 694 render_annots_(true), | 697 render_annots_(true), |
| 695 progressive_paint_timeout_(0), | 698 progressive_paint_timeout_(0), |
| 696 getting_password_(false) { | 699 getting_password_(false) { |
| 697 find_factory_.Initialize(this); | 700 find_factory_.Initialize(this); |
| 698 password_factory_.Initialize(this); | 701 password_factory_.Initialize(this); |
| 699 | 702 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 break; | 1321 break; |
| 1319 case PP_INPUTEVENT_TYPE_KEYDOWN: | 1322 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 1320 rv = OnKeyDown(pp::KeyboardInputEvent(event)); | 1323 rv = OnKeyDown(pp::KeyboardInputEvent(event)); |
| 1321 break; | 1324 break; |
| 1322 case PP_INPUTEVENT_TYPE_KEYUP: | 1325 case PP_INPUTEVENT_TYPE_KEYUP: |
| 1323 rv = OnKeyUp(pp::KeyboardInputEvent(event)); | 1326 rv = OnKeyUp(pp::KeyboardInputEvent(event)); |
| 1324 break; | 1327 break; |
| 1325 case PP_INPUTEVENT_TYPE_CHAR: | 1328 case PP_INPUTEVENT_TYPE_CHAR: |
| 1326 rv = OnChar(pp::KeyboardInputEvent(event)); | 1329 rv = OnChar(pp::KeyboardInputEvent(event)); |
| 1327 break; | 1330 break; |
| 1331 case PP_INPUTEVENT_TYPE_TOUCHSTART: { |
| 1332 KillTouchTimer(next_touch_timer_id_); |
| 1333 |
| 1334 pp::TouchInputEvent touch_event(event); |
| 1335 if (touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) |
| 1336 ScheduleTouchTimer(touch_event); |
| 1337 break; |
| 1338 } |
| 1339 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 1340 KillTouchTimer(next_touch_timer_id_); |
| 1341 break; |
| 1342 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 1343 // TODO(dsinclair): This should allow a little bit of movement (up to the |
| 1344 // touch radii) to account for finger jiggle. |
| 1345 KillTouchTimer(next_touch_timer_id_); |
| 1328 default: | 1346 default: |
| 1329 break; | 1347 break; |
| 1330 } | 1348 } |
| 1331 | 1349 |
| 1332 DCHECK(defer_page_unload_); | 1350 DCHECK(defer_page_unload_); |
| 1333 defer_page_unload_ = false; | 1351 defer_page_unload_ = false; |
| 1334 for (int page_index : deferred_page_unloads_) | 1352 for (int page_index : deferred_page_unloads_) |
| 1335 pages_[page_index]->Unload(); | 1353 pages_[page_index]->Unload(); |
| 1336 deferred_page_unloads_.clear(); | 1354 deferred_page_unloads_.clear(); |
| 1337 return rv; | 1355 return rv; |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 | 2455 |
| 2438 int PDFiumEngine::GetVerticalScrollbarYPosition() { | 2456 int PDFiumEngine::GetVerticalScrollbarYPosition() { |
| 2439 return position_.y(); | 2457 return position_.y(); |
| 2440 } | 2458 } |
| 2441 | 2459 |
| 2442 void PDFiumEngine::SetGrayscale(bool grayscale) { | 2460 void PDFiumEngine::SetGrayscale(bool grayscale) { |
| 2443 render_grayscale_ = grayscale; | 2461 render_grayscale_ = grayscale; |
| 2444 } | 2462 } |
| 2445 | 2463 |
| 2446 void PDFiumEngine::OnCallback(int id) { | 2464 void PDFiumEngine::OnCallback(int id) { |
| 2447 if (!timers_.count(id)) | 2465 if (!formfill_timers_.count(id)) |
| 2448 return; | 2466 return; |
| 2449 | 2467 |
| 2450 timers_[id].second(id); | 2468 formfill_timers_[id].second(id); |
| 2451 if (timers_.count(id)) // The callback might delete the timer. | 2469 if (formfill_timers_.count(id)) // The callback might delete the timer. |
| 2452 client_->ScheduleCallback(id, timers_[id].first); | 2470 client_->ScheduleCallback(id, formfill_timers_[id].first); |
| 2471 } |
| 2472 |
| 2473 void PDFiumEngine::OnTouchTimerCallback(int id) { |
| 2474 if (!touch_timers_.count(id)) |
| 2475 return; |
| 2476 |
| 2477 HandleLongPress(touch_timers_[id]); |
| 2478 KillTouchTimer(id); |
| 2479 } |
| 2480 |
| 2481 void PDFiumEngine::HandleLongPress(const pp::TouchInputEvent& event) { |
| 2482 pp::FloatPoint fp = |
| 2483 event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position(); |
| 2484 pp::Point point; |
| 2485 point.set_x(fp.x()); |
| 2486 point.set_y(fp.y()); |
| 2487 |
| 2488 // Send a fake mouse down to trigger the multi-click selection code. |
| 2489 pp::MouseInputEvent mouse_event( |
| 2490 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_MOUSEDOWN, |
| 2491 event.GetTimeStamp(), event.GetModifiers(), |
| 2492 PP_INPUTEVENT_MOUSEBUTTON_LEFT, point, 2, point); |
| 2493 |
| 2494 OnMouseDown(mouse_event); |
| 2453 } | 2495 } |
| 2454 | 2496 |
| 2455 int PDFiumEngine::GetCharCount(int page_index) { | 2497 int PDFiumEngine::GetCharCount(int page_index) { |
| 2456 DCHECK(PageIndexInBounds(page_index)); | 2498 DCHECK(PageIndexInBounds(page_index)); |
| 2457 return pages_[page_index]->GetCharCount(); | 2499 return pages_[page_index]->GetCharCount(); |
| 2458 } | 2500 } |
| 2459 | 2501 |
| 2460 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { | 2502 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { |
| 2461 DCHECK(PageIndexInBounds(page_index)); | 2503 DCHECK(PageIndexInBounds(page_index)); |
| 2462 return pages_[page_index]->GetCharBounds(char_index); | 2504 return pages_[page_index]->GetCharBounds(char_index); |
| (...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3511 client_->ScrollToPage(most_visible_page); | 3553 client_->ScrollToPage(most_visible_page); |
| 3512 } | 3554 } |
| 3513 | 3555 |
| 3514 void PDFiumEngine::SetSelecting(bool selecting) { | 3556 void PDFiumEngine::SetSelecting(bool selecting) { |
| 3515 bool was_selecting = selecting_; | 3557 bool was_selecting = selecting_; |
| 3516 selecting_ = selecting; | 3558 selecting_ = selecting; |
| 3517 if (selecting_ != was_selecting) | 3559 if (selecting_ != was_selecting) |
| 3518 client_->IsSelectingChanged(selecting); | 3560 client_->IsSelectingChanged(selecting); |
| 3519 } | 3561 } |
| 3520 | 3562 |
| 3563 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
| 3564 touch_timers_[++next_touch_timer_id_] = evt; |
| 3565 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
| 3566 kTouchLongPressTimeoutMs); |
| 3567 } |
| 3568 |
| 3569 void PDFiumEngine::KillTouchTimer(int timer_id) { |
| 3570 touch_timers_.erase(timer_id); |
| 3571 } |
| 3572 |
| 3521 bool PDFiumEngine::PageIndexInBounds(int index) const { | 3573 bool PDFiumEngine::PageIndexInBounds(int index) const { |
| 3522 return index >= 0 && index < static_cast<int>(pages_.size()); | 3574 return index >= 0 && index < static_cast<int>(pages_.size()); |
| 3523 } | 3575 } |
| 3524 | 3576 |
| 3525 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, | 3577 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, |
| 3526 FPDF_PAGE page, | 3578 FPDF_PAGE page, |
| 3527 double left, | 3579 double left, |
| 3528 double top, | 3580 double top, |
| 3529 double right, | 3581 double right, |
| 3530 double bottom) { | 3582 double bottom) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3562 | 3614 |
| 3563 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { | 3615 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { |
| 3564 // We don't need this since it's not enough to change the cursor in all | 3616 // We don't need this since it's not enough to change the cursor in all |
| 3565 // scenarios. Instead, we check which form field we're under in OnMouseMove. | 3617 // scenarios. Instead, we check which form field we're under in OnMouseMove. |
| 3566 } | 3618 } |
| 3567 | 3619 |
| 3568 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, | 3620 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, |
| 3569 int elapse, | 3621 int elapse, |
| 3570 TimerCallback timer_func) { | 3622 TimerCallback timer_func) { |
| 3571 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3623 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3572 engine->timers_[++engine->next_timer_id_] = | 3624 engine->formfill_timers_[++engine->next_formfill_timer_id_] = |
| 3573 std::pair<int, TimerCallback>(elapse, timer_func); | 3625 std::pair<int, TimerCallback>(elapse, timer_func); |
| 3574 engine->client_->ScheduleCallback(engine->next_timer_id_, elapse); | 3626 engine->client_->ScheduleCallback(engine->next_formfill_timer_id_, elapse); |
| 3575 return engine->next_timer_id_; | 3627 return engine->next_formfill_timer_id_; |
| 3576 } | 3628 } |
| 3577 | 3629 |
| 3578 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { | 3630 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { |
| 3579 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3631 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3580 engine->timers_.erase(timer_id); | 3632 engine->formfill_timers_.erase(timer_id); |
| 3581 } | 3633 } |
| 3582 | 3634 |
| 3583 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { | 3635 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { |
| 3584 base::Time time = base::Time::Now(); | 3636 base::Time time = base::Time::Now(); |
| 3585 base::Time::Exploded exploded; | 3637 base::Time::Exploded exploded; |
| 3586 time.LocalExplode(&exploded); | 3638 time.LocalExplode(&exploded); |
| 3587 | 3639 |
| 3588 FPDF_SYSTEMTIME rv; | 3640 FPDF_SYSTEMTIME rv; |
| 3589 rv.wYear = exploded.year; | 3641 rv.wYear = exploded.year; |
| 3590 rv.wMonth = exploded.month; | 3642 rv.wMonth = exploded.month; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4090 FPDF_DOCUMENT doc = | 4142 FPDF_DOCUMENT doc = |
| 4091 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4143 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4092 if (!doc) | 4144 if (!doc) |
| 4093 return false; | 4145 return false; |
| 4094 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4146 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4095 FPDF_CloseDocument(doc); | 4147 FPDF_CloseDocument(doc); |
| 4096 return success; | 4148 return success; |
| 4097 } | 4149 } |
| 4098 | 4150 |
| 4099 } // namespace chrome_pdf | 4151 } // namespace chrome_pdf |
| OLD | NEW |