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 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 last_character_index_to_search_(-1), | 593 last_character_index_to_search_(-1), |
594 permissions_(0), | 594 permissions_(0), |
595 fpdf_availability_(NULL), | 595 fpdf_availability_(NULL), |
596 next_timer_id_(0), | 596 next_timer_id_(0), |
597 last_page_mouse_down_(-1), | 597 last_page_mouse_down_(-1), |
598 first_visible_page_(-1), | 598 first_visible_page_(-1), |
599 most_visible_page_(-1), | 599 most_visible_page_(-1), |
600 called_do_document_action_(false), | 600 called_do_document_action_(false), |
601 render_grayscale_(false), | 601 render_grayscale_(false), |
602 progressive_paint_timeout_(0), | 602 progressive_paint_timeout_(0), |
603 getting_password_(false) { | 603 getting_password_(false), |
| 604 last_char_index_(-1) { |
604 find_factory_.Initialize(this); | 605 find_factory_.Initialize(this); |
605 password_factory_.Initialize(this); | 606 password_factory_.Initialize(this); |
606 | 607 |
607 file_access_.m_FileLen = 0; | 608 file_access_.m_FileLen = 0; |
608 file_access_.m_GetBlock = &GetBlock; | 609 file_access_.m_GetBlock = &GetBlock; |
609 file_access_.m_Param = &doc_loader_; | 610 file_access_.m_Param = &doc_loader_; |
610 | 611 |
611 file_availability_.version = 1; | 612 file_availability_.version = 1; |
612 file_availability_.IsDataAvail = &IsDataAvail; | 613 file_availability_.IsDataAvail = &IsDataAvail; |
613 file_availability_.loader = &doc_loader_; | 614 file_availability_.loader = &doc_loader_; |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 // mouse move events. | 1687 // mouse move events. |
1687 if (area == PDFiumPage::WEBLINK_AREA) | 1688 if (area == PDFiumPage::WEBLINK_AREA) |
1688 return true; | 1689 return true; |
1689 | 1690 |
1690 if (area == PDFiumPage::DOCLINK_AREA) { | 1691 if (area == PDFiumPage::DOCLINK_AREA) { |
1691 client_->ScrollToPage(target.page); | 1692 client_->ScrollToPage(target.page); |
1692 client_->FormTextFieldFocusChange(false); | 1693 client_->FormTextFieldFocusChange(false); |
1693 return true; | 1694 return true; |
1694 } | 1695 } |
1695 | 1696 |
| 1697 int last_page_index = last_page_mouse_down_; |
1696 if (page_index != -1) { | 1698 if (page_index != -1) { |
1697 last_page_mouse_down_ = page_index; | 1699 last_page_mouse_down_ = page_index; |
1698 double page_x, page_y; | 1700 double page_x, page_y; |
1699 pp::Point point = event.GetPosition(); | 1701 pp::Point point = event.GetPosition(); |
1700 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1702 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1701 | 1703 |
1702 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1704 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1703 int control = FPDPage_HasFormFieldAtPoint( | 1705 int control = FPDPage_HasFormFieldAtPoint( |
1704 form_, pages_[page_index]->GetPage(), page_x, page_y); | 1706 form_, pages_[page_index]->GetPage(), page_x, page_y); |
1705 if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1707 if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
1706 #ifdef PDF_USE_XFA | 1708 #ifdef PDF_USE_XFA |
1707 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || | 1709 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
1708 control == FPDF_FORMFIELD_COMBOBOX || control == FPDF_FORMFIELD_XFA); | 1710 control == FPDF_FORMFIELD_COMBOBOX || control == FPDF_FORMFIELD_XFA); |
1709 #else | 1711 #else |
1710 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || | 1712 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
1711 control == FPDF_FORMFIELD_COMBOBOX); | 1713 control == FPDF_FORMFIELD_COMBOBOX); |
1712 #endif | 1714 #endif |
1713 return true; // Return now before we get into the selection code. | 1715 return true; // Return now before we get into the selection code. |
1714 } | 1716 } |
1715 } | 1717 } |
1716 | 1718 |
1717 client_->FormTextFieldFocusChange(false); | 1719 client_->FormTextFieldFocusChange(false); |
| 1720 if (event.GetModifiers() == (PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN | |
| 1721 PP_INPUTEVENT_MODIFIER_SHIFTKEY) && |
| 1722 event.GetClickCount() == 1) { |
| 1723 HandleShiftClick(last_page_index, page_index, char_index); |
| 1724 last_char_index_ = char_index; |
| 1725 return true; |
| 1726 } |
| 1727 |
| 1728 last_char_index_ = char_index; |
1718 | 1729 |
1719 if (area != PDFiumPage::TEXT_AREA) | 1730 if (area != PDFiumPage::TEXT_AREA) |
1720 return true; // Return true so WebKit doesn't do its own highlighting. | 1731 return true; // Return true so WebKit doesn't do its own highlighting. |
1721 | 1732 |
1722 if (event.GetClickCount() == 1) { | 1733 if (event.GetClickCount() == 1) { |
1723 OnSingleClick(page_index, char_index); | 1734 OnSingleClick(page_index, char_index); |
1724 } else if (event.GetClickCount() == 2 || | 1735 } else if (event.GetClickCount() == 2 || |
1725 event.GetClickCount() == 3) { | 1736 event.GetClickCount() == 3) { |
1726 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1737 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
1727 } | 1738 } |
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3462 | 3473 |
3463 InvalidateAllPages(); | 3474 InvalidateAllPages(); |
3464 | 3475 |
3465 if (!current_find_text.empty()) { | 3476 if (!current_find_text.empty()) { |
3466 // Clear the UI. | 3477 // Clear the UI. |
3467 client_->NotifyNumberOfFindResultsChanged(0, false); | 3478 client_->NotifyNumberOfFindResultsChanged(0, false); |
3468 StartFind(current_find_text.c_str(), false); | 3479 StartFind(current_find_text.c_str(), false); |
3469 } | 3480 } |
3470 } | 3481 } |
3471 | 3482 |
| 3483 void PDFiumEngine::HandleShiftClick(const int last_page_index, |
| 3484 const int page_index, |
| 3485 const int char_index) { |
| 3486 selecting_ = true; |
| 3487 if (last_page_index == -1 || last_page_index == page_index) { |
| 3488 if (last_char_index_ != -1) { |
| 3489 if (char_index == -1) { |
| 3490 selection_.push_back( |
| 3491 PDFiumRange(pages_[page_index], 0, last_char_index_ + 1)); |
| 3492 } else { |
| 3493 if (char_index > last_char_index_) { |
| 3494 selection_.push_back(PDFiumRange(pages_[page_index], last_char_index_, |
| 3495 char_index - last_char_index_ + 1)); |
| 3496 } else if (char_index < last_char_index_) { |
| 3497 selection_.push_back(PDFiumRange(pages_[page_index], char_index, |
| 3498 last_char_index_ - char_index + 1)); |
| 3499 } |
| 3500 } |
| 3501 } else { |
| 3502 if (char_index != -1) |
| 3503 selection_.push_back( |
| 3504 PDFiumRange(pages_[page_index], 0, char_index + 1)); |
| 3505 } |
| 3506 } else { |
| 3507 if (last_char_index_ != -1 && char_index != -1) { |
| 3508 if (last_page_index < page_index) { |
| 3509 selection_.push_back( |
| 3510 PDFiumRange(pages_[last_page_index], last_char_index_, |
| 3511 pages_[last_page_index]->GetCharCount())); |
| 3512 for (int i = last_page_index + 1; i < page_index; i++) { |
| 3513 selection_.push_back( |
| 3514 PDFiumRange(pages_[i], 0, pages_[i]->GetCharCount())); |
| 3515 } |
| 3516 selection_.push_back( |
| 3517 PDFiumRange(pages_[page_index], 0, char_index + 1)); |
| 3518 } else { |
| 3519 selection_.push_back(PDFiumRange(pages_[page_index], char_index, |
| 3520 pages_[page_index]->GetCharCount())); |
| 3521 for (int i = page_index + 1; i < last_page_index; i++) { |
| 3522 selection_.push_back( |
| 3523 PDFiumRange(pages_[i], 0, pages_[i]->GetCharCount())); |
| 3524 } |
| 3525 selection_.push_back( |
| 3526 PDFiumRange(pages_[last_page_index], 0, last_char_index_ + 1)); |
| 3527 } |
| 3528 } |
| 3529 } |
| 3530 } |
| 3531 |
3472 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, | 3532 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, |
3473 FPDF_PAGE page, | 3533 FPDF_PAGE page, |
3474 double left, | 3534 double left, |
3475 double top, | 3535 double top, |
3476 double right, | 3536 double right, |
3477 double bottom) { | 3537 double bottom) { |
3478 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3538 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3479 int page_index = engine->GetVisiblePageIndex(page); | 3539 int page_index = engine->GetVisiblePageIndex(page); |
3480 if (page_index == -1) { | 3540 if (page_index == -1) { |
3481 // This can sometime happen when the page is closed because it went off | 3541 // This can sometime happen when the page is closed because it went off |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4018 double* height) { | 4078 double* height) { |
4019 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4079 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4020 if (!doc) | 4080 if (!doc) |
4021 return false; | 4081 return false; |
4022 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4082 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4023 FPDF_CloseDocument(doc); | 4083 FPDF_CloseDocument(doc); |
4024 return success; | 4084 return success; |
4025 } | 4085 } |
4026 | 4086 |
4027 } // namespace chrome_pdf | 4087 } // namespace chrome_pdf |
OLD | NEW |