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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2864603006: Revert of Handle long press in PDF documents. (Closed)
Patch Set: Created 3 years, 7 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/pdfium/pdfium_engine.h ('k') | pdf/preview_mode_client.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/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
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
93 // See Table 3.20 in 91 // See Table 3.20 in
94 // http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf 92 // http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
95 const uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2; 93 const uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2;
96 const uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11; 94 const uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11;
97 const uint32_t kPDFPermissionCopyMask = 1 << 4; 95 const uint32_t kPDFPermissionCopyMask = 1 << 4;
98 const uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9; 96 const uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9;
99 97
100 const int32_t kLoadingTextVerticalOffset = 50; 98 const int32_t kLoadingTextVerticalOffset = 50;
101 99
102 // The maximum amount of time we'll spend doing a paint before we give back 100 // 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
676 defer_page_unload_(false), 674 defer_page_unload_(false),
677 selecting_(false), 675 selecting_(false),
678 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, 676 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA,
679 PDFiumPage::LinkTarget()), 677 PDFiumPage::LinkTarget()),
680 next_page_to_search_(-1), 678 next_page_to_search_(-1),
681 last_page_to_search_(-1), 679 last_page_to_search_(-1),
682 last_character_index_to_search_(-1), 680 last_character_index_to_search_(-1),
683 permissions_(0), 681 permissions_(0),
684 permissions_handler_revision_(-1), 682 permissions_handler_revision_(-1),
685 fpdf_availability_(nullptr), 683 fpdf_availability_(nullptr),
686 next_formfill_timer_id_(0), 684 next_timer_id_(0),
687 next_touch_timer_id_(0),
688 last_page_mouse_down_(-1), 685 last_page_mouse_down_(-1),
689 most_visible_page_(-1), 686 most_visible_page_(-1),
690 called_do_document_action_(false), 687 called_do_document_action_(false),
691 render_grayscale_(false), 688 render_grayscale_(false),
692 render_annots_(true), 689 render_annots_(true),
693 progressive_paint_timeout_(0), 690 progressive_paint_timeout_(0),
694 getting_password_(false) { 691 getting_password_(false) {
695 find_factory_.Initialize(this); 692 find_factory_.Initialize(this);
696 password_factory_.Initialize(this); 693 password_factory_.Initialize(this);
697 694
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 break; 1328 break;
1332 case PP_INPUTEVENT_TYPE_KEYDOWN: 1329 case PP_INPUTEVENT_TYPE_KEYDOWN:
1333 rv = OnKeyDown(pp::KeyboardInputEvent(event)); 1330 rv = OnKeyDown(pp::KeyboardInputEvent(event));
1334 break; 1331 break;
1335 case PP_INPUTEVENT_TYPE_KEYUP: 1332 case PP_INPUTEVENT_TYPE_KEYUP:
1336 rv = OnKeyUp(pp::KeyboardInputEvent(event)); 1333 rv = OnKeyUp(pp::KeyboardInputEvent(event));
1337 break; 1334 break;
1338 case PP_INPUTEVENT_TYPE_CHAR: 1335 case PP_INPUTEVENT_TYPE_CHAR:
1339 rv = OnChar(pp::KeyboardInputEvent(event)); 1336 rv = OnChar(pp::KeyboardInputEvent(event));
1340 break; 1337 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_);
1356 default: 1338 default:
1357 break; 1339 break;
1358 } 1340 }
1359 1341
1360 DCHECK(defer_page_unload_); 1342 DCHECK(defer_page_unload_);
1361 defer_page_unload_ = false; 1343 defer_page_unload_ = false;
1362 for (int page_index : deferred_page_unloads_) 1344 for (int page_index : deferred_page_unloads_)
1363 pages_[page_index]->Unload(); 1345 pages_[page_index]->Unload();
1364 deferred_page_unloads_.clear(); 1346 deferred_page_unloads_.clear();
1365 return rv; 1347 return rv;
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 2457
2476 int PDFiumEngine::GetVerticalScrollbarYPosition() { 2458 int PDFiumEngine::GetVerticalScrollbarYPosition() {
2477 return position_.y(); 2459 return position_.y();
2478 } 2460 }
2479 2461
2480 void PDFiumEngine::SetGrayscale(bool grayscale) { 2462 void PDFiumEngine::SetGrayscale(bool grayscale) {
2481 render_grayscale_ = grayscale; 2463 render_grayscale_ = grayscale;
2482 } 2464 }
2483 2465
2484 void PDFiumEngine::OnCallback(int id) { 2466 void PDFiumEngine::OnCallback(int id) {
2485 if (!formfill_timers_.count(id)) 2467 if (!timers_.count(id))
2486 return; 2468 return;
2487 2469
2488 formfill_timers_[id].second(id); 2470 timers_[id].second(id);
2489 if (formfill_timers_.count(id)) // The callback might delete the timer. 2471 if (timers_.count(id)) // The callback might delete the timer.
2490 client_->ScheduleCallback(id, formfill_timers_[id].first); 2472 client_->ScheduleCallback(id, 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);
2515 } 2473 }
2516 2474
2517 int PDFiumEngine::GetCharCount(int page_index) { 2475 int PDFiumEngine::GetCharCount(int page_index) {
2518 DCHECK(PageIndexInBounds(page_index)); 2476 DCHECK(PageIndexInBounds(page_index));
2519 return pages_[page_index]->GetCharCount(); 2477 return pages_[page_index]->GetCharCount();
2520 } 2478 }
2521 2479
2522 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { 2480 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) {
2523 DCHECK(PageIndexInBounds(page_index)); 2481 DCHECK(PageIndexInBounds(page_index));
2524 return pages_[page_index]->GetCharBounds(char_index); 2482 return pages_[page_index]->GetCharBounds(char_index);
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
3573 client_->ScrollToPage(most_visible_page); 3531 client_->ScrollToPage(most_visible_page);
3574 } 3532 }
3575 3533
3576 void PDFiumEngine::SetSelecting(bool selecting) { 3534 void PDFiumEngine::SetSelecting(bool selecting) {
3577 bool was_selecting = selecting_; 3535 bool was_selecting = selecting_;
3578 selecting_ = selecting; 3536 selecting_ = selecting;
3579 if (selecting_ != was_selecting) 3537 if (selecting_ != was_selecting)
3580 client_->IsSelectingChanged(selecting); 3538 client_->IsSelectingChanged(selecting);
3581 } 3539 }
3582 3540
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
3593 bool PDFiumEngine::PageIndexInBounds(int index) const { 3541 bool PDFiumEngine::PageIndexInBounds(int index) const {
3594 return index >= 0 && index < static_cast<int>(pages_.size()); 3542 return index >= 0 && index < static_cast<int>(pages_.size());
3595 } 3543 }
3596 3544
3597 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, 3545 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param,
3598 FPDF_PAGE page, 3546 FPDF_PAGE page,
3599 double left, 3547 double left,
3600 double top, 3548 double top,
3601 double right, 3549 double right,
3602 double bottom) { 3550 double bottom) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 3582
3635 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { 3583 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) {
3636 // We don't need this since it's not enough to change the cursor in all 3584 // We don't need this since it's not enough to change the cursor in all
3637 // scenarios. Instead, we check which form field we're under in OnMouseMove. 3585 // scenarios. Instead, we check which form field we're under in OnMouseMove.
3638 } 3586 }
3639 3587
3640 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, 3588 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param,
3641 int elapse, 3589 int elapse,
3642 TimerCallback timer_func) { 3590 TimerCallback timer_func) {
3643 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3591 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3644 engine->formfill_timers_[++engine->next_formfill_timer_id_] = 3592 engine->timers_[++engine->next_timer_id_] =
3645 std::pair<int, TimerCallback>(elapse, timer_func); 3593 std::pair<int, TimerCallback>(elapse, timer_func);
3646 engine->client_->ScheduleCallback(engine->next_formfill_timer_id_, elapse); 3594 engine->client_->ScheduleCallback(engine->next_timer_id_, elapse);
3647 return engine->next_formfill_timer_id_; 3595 return engine->next_timer_id_;
3648 } 3596 }
3649 3597
3650 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { 3598 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) {
3651 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3599 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3652 engine->formfill_timers_.erase(timer_id); 3600 engine->timers_.erase(timer_id);
3653 } 3601 }
3654 3602
3655 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) { 3603 FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) {
3656 base::Time time = base::Time::Now(); 3604 base::Time time = base::Time::Now();
3657 base::Time::Exploded exploded; 3605 base::Time::Exploded exploded;
3658 time.LocalExplode(&exploded); 3606 time.LocalExplode(&exploded);
3659 3607
3660 FPDF_SYSTEMTIME rv; 3608 FPDF_SYSTEMTIME rv;
3661 rv.wYear = exploded.year; 3609 rv.wYear = exploded.year;
3662 rv.wMonth = exploded.month; 3610 rv.wMonth = exploded.month;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
4171 FPDF_DOCUMENT doc = 4119 FPDF_DOCUMENT doc =
4172 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 4120 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
4173 if (!doc) 4121 if (!doc)
4174 return false; 4122 return false;
4175 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4123 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4176 FPDF_CloseDocument(doc); 4124 FPDF_CloseDocument(doc);
4177 return success; 4125 return success;
4178 } 4126 }
4179 4127
4180 } // namespace chrome_pdf 4128 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/preview_mode_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698