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 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1617 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1617 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
1618 TransformPDFPageForPrinting(page, print_settings); | 1618 TransformPDFPageForPrinting(page, print_settings); |
1619 FPDF_ClosePage(page); | 1619 FPDF_ClosePage(page); |
1620 } | 1620 } |
1621 } | 1621 } |
1622 } | 1622 } |
1623 | 1623 |
1624 void PDFiumEngine::SaveSelectedFormForPrint() { | 1624 void PDFiumEngine::SaveSelectedFormForPrint() { |
1625 FORM_ForceToKillFocus(form_); | 1625 FORM_ForceToKillFocus(form_); |
1626 client_->FormTextFieldFocusChange(false); | 1626 client_->FormTextFieldFocusChange(false); |
1627 SetInFormTextField(false); | |
1628 } | |
1629 | |
1630 void PDFiumEngine::SetFormSelectedText(const FPDF_FORMHANDLE& hHandle, | |
1631 const FPDF_PAGE& page) { | |
1632 size_t form_sel_text_len = FORM_GetSelectedText(hHandle, page, nullptr, 0); | |
1633 | |
1634 // Initial length = 2 (not 0) because text is CFX_WideString and | |
1635 // sentinel char is included in count. | |
1636 if (form_sel_text_len <= 2) | |
1637 return; | |
1638 | |
1639 base::string16 selected_form_text16; | |
1640 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( | |
1641 &selected_form_text16, form_sel_text_len, false); | |
1642 string_adapter.Close(FORM_GetSelectedText( | |
1643 hHandle, page, string_adapter.GetData(), form_sel_text_len)); | |
1644 | |
1645 std::string selected_form_text = UTF16ToUTF8(selected_form_text16); | |
1646 if (!selected_form_text.empty()) { | |
1647 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); | |
1648 } | |
1627 } | 1649 } |
1628 | 1650 |
1629 void PDFiumEngine::PrintEnd() { | 1651 void PDFiumEngine::PrintEnd() { |
1630 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1652 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
1631 } | 1653 } |
1632 | 1654 |
1633 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, | 1655 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, |
1634 int* page_index, | 1656 int* page_index, |
1635 int* char_index, | 1657 int* char_index, |
1636 int* form_type, | 1658 int* form_type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1713 return false; | 1735 return false; |
1714 | 1736 |
1715 if (page_index != -1) { | 1737 if (page_index != -1) { |
1716 last_page_mouse_down_ = page_index; | 1738 last_page_mouse_down_ = page_index; |
1717 double page_x, page_y; | 1739 double page_x, page_y; |
1718 pp::Point point = event.GetPosition(); | 1740 pp::Point point = event.GetPosition(); |
1719 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1741 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1720 | 1742 |
1721 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1743 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1722 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1744 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
1723 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | 1745 (form_type == FPDF_FORMFIELD_TEXTFIELD) |
Lei Zhang
2017/06/15 18:11:28
style: With a ternary operator, write this as:
mo
drgage
2017/06/16 01:49:21
Done.
| |
1746 ? mouse_down_state_.Set(PDFiumPage::FORM_TEXT_AREA, target) | |
1747 : mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | |
1748 | |
1724 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || | 1749 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
1725 form_type == FPDF_FORMFIELD_COMBOBOX); | 1750 form_type == FPDF_FORMFIELD_COMBOBOX); |
1751 | |
1752 // TODO (bug_62400): come back to this to figure out selection and copying | |
1753 // for XFA fields | |
1726 #if defined(PDF_ENABLE_XFA) | 1754 #if defined(PDF_ENABLE_XFA) |
1727 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); | 1755 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
1728 #endif | 1756 #endif |
1757 | |
1758 // TODO (drgage): come back and implement copying for comboboxes | |
1729 client_->FormTextFieldFocusChange(is_valid_control); | 1759 client_->FormTextFieldFocusChange(is_valid_control); |
1760 SetInFormTextField(is_valid_control); | |
1730 return true; // Return now before we get into the selection code. | 1761 return true; // Return now before we get into the selection code. |
1731 } | 1762 } |
1732 } | 1763 } |
1733 | 1764 |
1734 client_->FormTextFieldFocusChange(false); | 1765 client_->FormTextFieldFocusChange(false); |
1766 SetInFormTextField(false); | |
1735 | 1767 |
1736 if (area != PDFiumPage::TEXT_AREA) | 1768 if (area != PDFiumPage::TEXT_AREA) |
1737 return true; // Return true so WebKit doesn't do its own highlighting. | 1769 return true; // Return true so WebKit doesn't do its own highlighting. |
1738 | 1770 |
1739 if (event.GetClickCount() == 1) { | 1771 if (event.GetClickCount() == 1) { |
1740 OnSingleClick(page_index, char_index); | 1772 OnSingleClick(page_index, char_index); |
1741 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { | 1773 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { |
1742 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1774 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
1743 } | 1775 } |
1744 | 1776 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1832 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
1801 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1833 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
1802 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1834 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
1803 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | 1835 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); |
1804 | 1836 |
1805 WindowOpenDisposition disposition = ui::DispositionFromClick( | 1837 WindowOpenDisposition disposition = ui::DispositionFromClick( |
1806 middle_button, alt_key, ctrl_key, meta_key, shift_key); | 1838 middle_button, alt_key, ctrl_key, meta_key, shift_key); |
1807 | 1839 |
1808 client_->NavigateTo(target.url, disposition); | 1840 client_->NavigateTo(target.url, disposition); |
1809 client_->FormTextFieldFocusChange(false); | 1841 client_->FormTextFieldFocusChange(false); |
1842 SetInFormTextField(false); | |
1810 return true; | 1843 return true; |
1811 } | 1844 } |
1812 if (area == PDFiumPage::DOCLINK_AREA) { | 1845 if (area == PDFiumPage::DOCLINK_AREA) { |
1813 client_->ScrollToPage(target.page); | 1846 client_->ScrollToPage(target.page); |
1814 client_->FormTextFieldFocusChange(false); | 1847 client_->FormTextFieldFocusChange(false); |
1848 SetInFormTextField(false); | |
1815 return true; | 1849 return true; |
1816 } | 1850 } |
1817 } | 1851 } |
1818 | 1852 |
1819 // Prevent middle mouse button from selecting texts. | 1853 // Prevent middle mouse button from selecting texts. |
1820 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1854 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
1821 return false; | 1855 return false; |
1822 | 1856 |
1823 if (page_index != -1) { | 1857 if (page_index != -1) { |
1824 double page_x, page_y; | 1858 double page_x, page_y; |
1825 pp::Point point = event.GetPosition(); | 1859 pp::Point point = event.GetPosition(); |
1826 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1860 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1827 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1861 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1828 } | 1862 } |
1829 | 1863 |
1864 if (area == PDFiumPage::FORM_TEXT_AREA) { | |
1865 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
1866 } | |
1867 | |
1830 if (!selecting_) | 1868 if (!selecting_) |
1831 return false; | 1869 return false; |
1832 | 1870 |
1833 SetSelecting(false); | 1871 SetSelecting(false); |
1834 return true; | 1872 return true; |
1835 } | 1873 } |
1836 | 1874 |
1837 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1875 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
1838 int page_index = -1; | 1876 int page_index = -1; |
1839 int char_index = -1; | 1877 int char_index = -1; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1984 OnChar(synthesized); | 2022 OnChar(synthesized); |
1985 } | 2023 } |
1986 | 2024 |
1987 return rv; | 2025 return rv; |
1988 } | 2026 } |
1989 | 2027 |
1990 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 2028 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
1991 if (last_page_mouse_down_ == -1) | 2029 if (last_page_mouse_down_ == -1) |
1992 return false; | 2030 return false; |
1993 | 2031 |
2032 if (in_form_text_field_) { | |
2033 uint32_t modifiers = event.GetModifiers(); | |
2034 if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) | |
2035 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
2036 } | |
2037 | |
1994 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), | 2038 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
1995 event.GetKeyCode(), event.GetModifiers()); | 2039 event.GetKeyCode(), event.GetModifiers()); |
1996 } | 2040 } |
1997 | 2041 |
1998 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2042 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
1999 if (last_page_mouse_down_ == -1) | 2043 if (last_page_mouse_down_ == -1) |
2000 return false; | 2044 return false; |
2001 | 2045 |
2002 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 2046 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
2003 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], | 2047 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], |
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3545 client_->ScrollToPage(most_visible_page); | 3589 client_->ScrollToPage(most_visible_page); |
3546 } | 3590 } |
3547 | 3591 |
3548 void PDFiumEngine::SetSelecting(bool selecting) { | 3592 void PDFiumEngine::SetSelecting(bool selecting) { |
3549 bool was_selecting = selecting_; | 3593 bool was_selecting = selecting_; |
3550 selecting_ = selecting; | 3594 selecting_ = selecting; |
3551 if (selecting_ != was_selecting) | 3595 if (selecting_ != was_selecting) |
3552 client_->IsSelectingChanged(selecting); | 3596 client_->IsSelectingChanged(selecting); |
3553 } | 3597 } |
3554 | 3598 |
3599 void PDFiumEngine::SetInFormTextField(bool in_form_text_field) { | |
3600 in_form_text_field_ = in_form_text_field; | |
3601 } | |
3602 | |
3555 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3603 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
3556 touch_timers_[++next_touch_timer_id_] = evt; | 3604 touch_timers_[++next_touch_timer_id_] = evt; |
3557 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3605 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
3558 kTouchLongPressTimeoutMs); | 3606 kTouchLongPressTimeoutMs); |
3559 } | 3607 } |
3560 | 3608 |
3561 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3609 void PDFiumEngine::KillTouchTimer(int timer_id) { |
3562 touch_timers_.erase(timer_id); | 3610 touch_timers_.erase(timer_id); |
3563 } | 3611 } |
3564 | 3612 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4134 FPDF_DOCUMENT doc = | 4182 FPDF_DOCUMENT doc = |
4135 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4183 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4136 if (!doc) | 4184 if (!doc) |
4137 return false; | 4185 return false; |
4138 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4186 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4139 FPDF_CloseDocument(doc); | 4187 FPDF_CloseDocument(doc); |
4140 return success; | 4188 return success; |
4141 } | 4189 } |
4142 | 4190 |
4143 } // namespace chrome_pdf | 4191 } // namespace chrome_pdf |
OLD | NEW |