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 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1618 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1618 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
1619 TransformPDFPageForPrinting(page, print_settings); | 1619 TransformPDFPageForPrinting(page, print_settings); |
1620 FPDF_ClosePage(page); | 1620 FPDF_ClosePage(page); |
1621 } | 1621 } |
1622 } | 1622 } |
1623 } | 1623 } |
1624 | 1624 |
1625 void PDFiumEngine::SaveSelectedFormForPrint() { | 1625 void PDFiumEngine::SaveSelectedFormForPrint() { |
1626 FORM_ForceToKillFocus(form_); | 1626 FORM_ForceToKillFocus(form_); |
1627 client_->FormTextFieldFocusChange(false); | 1627 client_->FormTextFieldFocusChange(false); |
1628 SetInFormTextField(false); | |
1629 SetInFormComboboxTextField(false); | |
1630 } | |
1631 | |
1632 void PDFiumEngine::SetFormSelectedText(const FPDF_FORMHANDLE& form_handle, | |
Lei Zhang
2017/06/17 02:21:17
We don't do this consistently, so let's try to be
drgage
2017/06/19 21:53:52
Done.
| |
1633 const FPDF_PAGE& page) { | |
1634 size_t form_sel_text_len = | |
1635 FORM_GetSelectedText(form_handle, page, nullptr, 0); | |
1636 | |
1637 // Initial length = 2 (not 0) because text is CFX_WideString and | |
Lei Zhang
2017/06/17 02:21:18
CFX_WideString is suppose to be an implementation
drgage
2017/06/19 21:53:52
Done.
| |
1638 // sentinel char is included in count. | |
Lei Zhang
2017/06/17 02:21:17
By "sentinel char" do you really mean NUL characte
drgage
2017/06/19 21:53:52
Done.
| |
1639 if (form_sel_text_len <= 2) | |
1640 return; | |
1641 | |
1642 base::string16 selected_form_text16; | |
1643 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( | |
1644 &selected_form_text16, form_sel_text_len, false); | |
1645 string_adapter.Close(FORM_GetSelectedText( | |
1646 form_handle, page, string_adapter.GetData(), form_sel_text_len)); | |
1647 | |
1648 std::string selected_form_text = UTF16ToUTF8(selected_form_text16); | |
1649 if (!selected_form_text.empty()) { | |
1650 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); | |
1651 } | |
1628 } | 1652 } |
1629 | 1653 |
1630 void PDFiumEngine::PrintEnd() { | 1654 void PDFiumEngine::PrintEnd() { |
1631 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1655 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
1632 } | 1656 } |
1633 | 1657 |
1634 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, | 1658 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, |
1635 int* page_index, | 1659 int* page_index, |
1636 int* char_index, | 1660 int* char_index, |
1637 int* form_type, | 1661 int* form_type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1714 return false; | 1738 return false; |
1715 | 1739 |
1716 if (page_index != -1) { | 1740 if (page_index != -1) { |
1717 last_page_mouse_down_ = page_index; | 1741 last_page_mouse_down_ = page_index; |
1718 double page_x, page_y; | 1742 double page_x, page_y; |
1719 pp::Point point = event.GetPosition(); | 1743 pp::Point point = event.GetPosition(); |
1720 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1744 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1721 | 1745 |
1722 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1746 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1723 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1747 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
1724 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | 1748 if (form_type == FPDF_FORMFIELD_TEXTFIELD) |
1749 mouse_down_state_.Set(PDFiumPage::FORM_TEXT_AREA, target); | |
1750 else if (form_type == FPDF_FORMFIELD_COMBOBOX) | |
1751 mouse_down_state_.Set(PDFiumPage::FORM_COMBOBOX_TEXT_AREA, target); | |
1752 else | |
1753 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | |
1754 | |
1725 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || | 1755 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
1726 form_type == FPDF_FORMFIELD_COMBOBOX); | 1756 form_type == FPDF_FORMFIELD_COMBOBOX); |
1757 | |
1758 // TODO(bug_62400): figure out selection and copying | |
1759 // for XFA fields | |
1727 #if defined(PDF_ENABLE_XFA) | 1760 #if defined(PDF_ENABLE_XFA) |
1728 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); | 1761 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
1729 #endif | 1762 #endif |
1763 | |
1764 // TODO(drgage): implement copying for comboboxes | |
1730 client_->FormTextFieldFocusChange(is_valid_control); | 1765 client_->FormTextFieldFocusChange(is_valid_control); |
1766 SetInFormTextField(form_type == FPDF_FORMFIELD_TEXTFIELD); | |
1767 SetInFormComboboxTextField(form_type == FPDF_FORMFIELD_COMBOBOX); | |
1731 return true; // Return now before we get into the selection code. | 1768 return true; // Return now before we get into the selection code. |
1732 } | 1769 } |
1733 } | 1770 } |
1734 | 1771 |
1735 client_->FormTextFieldFocusChange(false); | 1772 client_->FormTextFieldFocusChange(false); |
1773 SetInFormTextField(false); | |
1774 SetInFormComboboxTextField(false); | |
1736 | 1775 |
1737 if (area != PDFiumPage::TEXT_AREA) | 1776 if (area != PDFiumPage::TEXT_AREA) |
1738 return true; // Return true so WebKit doesn't do its own highlighting. | 1777 return true; // Return true so WebKit doesn't do its own highlighting. |
1739 | 1778 |
1740 if (event.GetClickCount() == 1) { | 1779 if (event.GetClickCount() == 1) { |
1741 OnSingleClick(page_index, char_index); | 1780 OnSingleClick(page_index, char_index); |
1742 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { | 1781 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { |
1743 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1782 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
1744 } | 1783 } |
1745 | 1784 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1801 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1840 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
1802 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1841 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
1803 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1842 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
1804 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | 1843 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); |
1805 | 1844 |
1806 WindowOpenDisposition disposition = ui::DispositionFromClick( | 1845 WindowOpenDisposition disposition = ui::DispositionFromClick( |
1807 middle_button, alt_key, ctrl_key, meta_key, shift_key); | 1846 middle_button, alt_key, ctrl_key, meta_key, shift_key); |
1808 | 1847 |
1809 client_->NavigateTo(target.url, disposition); | 1848 client_->NavigateTo(target.url, disposition); |
1810 client_->FormTextFieldFocusChange(false); | 1849 client_->FormTextFieldFocusChange(false); |
1850 SetInFormTextField(false); | |
1851 SetInFormComboboxTextField(false); | |
1811 return true; | 1852 return true; |
1812 } | 1853 } |
1813 if (area == PDFiumPage::DOCLINK_AREA) { | 1854 if (area == PDFiumPage::DOCLINK_AREA) { |
1814 client_->ScrollToPage(target.page); | 1855 client_->ScrollToPage(target.page); |
1815 client_->FormTextFieldFocusChange(false); | 1856 client_->FormTextFieldFocusChange(false); |
1857 SetInFormTextField(false); | |
1858 SetInFormComboboxTextField(false); | |
1816 return true; | 1859 return true; |
1817 } | 1860 } |
1818 } | 1861 } |
1819 | 1862 |
1820 // Prevent middle mouse button from selecting texts. | 1863 // Prevent middle mouse button from selecting texts. |
1821 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1864 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
1822 return false; | 1865 return false; |
1823 | 1866 |
1824 if (page_index != -1) { | 1867 if (page_index != -1) { |
1825 double page_x, page_y; | 1868 double page_x, page_y; |
1826 pp::Point point = event.GetPosition(); | 1869 pp::Point point = event.GetPosition(); |
1827 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1870 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1828 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1871 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1829 } | 1872 } |
1830 | 1873 |
1874 if (area == PDFiumPage::FORM_TEXT_AREA || | |
1875 area == PDFiumPage::FORM_COMBOBOX_TEXT_AREA) { | |
1876 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
1877 } | |
1878 | |
1831 if (!selecting_) | 1879 if (!selecting_) |
1832 return false; | 1880 return false; |
1833 | 1881 |
1834 SetSelecting(false); | 1882 SetSelecting(false); |
1835 return true; | 1883 return true; |
1836 } | 1884 } |
1837 | 1885 |
1838 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1886 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
1839 int page_index = -1; | 1887 int page_index = -1; |
1840 int char_index = -1; | 1888 int char_index = -1; |
(...skipping 11 matching lines...) Expand all Loading... | |
1852 PP_CursorType_Dev cursor; | 1900 PP_CursorType_Dev cursor; |
1853 switch (area) { | 1901 switch (area) { |
1854 case PDFiumPage::TEXT_AREA: | 1902 case PDFiumPage::TEXT_AREA: |
1855 cursor = PP_CURSORTYPE_IBEAM; | 1903 cursor = PP_CURSORTYPE_IBEAM; |
1856 break; | 1904 break; |
1857 case PDFiumPage::WEBLINK_AREA: | 1905 case PDFiumPage::WEBLINK_AREA: |
1858 case PDFiumPage::DOCLINK_AREA: | 1906 case PDFiumPage::DOCLINK_AREA: |
1859 cursor = PP_CURSORTYPE_HAND; | 1907 cursor = PP_CURSORTYPE_HAND; |
1860 break; | 1908 break; |
1861 case PDFiumPage::NONSELECTABLE_AREA: | 1909 case PDFiumPage::NONSELECTABLE_AREA: |
1910 case PDFiumPage::FORM_TEXT_AREA: | |
1911 case PDFiumPage::FORM_COMBOBOX_TEXT_AREA: | |
1862 default: | 1912 default: |
1863 switch (form_type) { | 1913 switch (form_type) { |
1864 case FPDF_FORMFIELD_PUSHBUTTON: | 1914 case FPDF_FORMFIELD_PUSHBUTTON: |
1865 case FPDF_FORMFIELD_CHECKBOX: | 1915 case FPDF_FORMFIELD_CHECKBOX: |
1866 case FPDF_FORMFIELD_RADIOBUTTON: | 1916 case FPDF_FORMFIELD_RADIOBUTTON: |
1867 case FPDF_FORMFIELD_COMBOBOX: | 1917 case FPDF_FORMFIELD_COMBOBOX: |
1868 case FPDF_FORMFIELD_LISTBOX: | 1918 case FPDF_FORMFIELD_LISTBOX: |
1869 cursor = PP_CURSORTYPE_HAND; | 1919 cursor = PP_CURSORTYPE_HAND; |
1870 break; | 1920 break; |
1871 case FPDF_FORMFIELD_TEXTFIELD: | 1921 case FPDF_FORMFIELD_TEXTFIELD: |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1985 OnChar(synthesized); | 2035 OnChar(synthesized); |
1986 } | 2036 } |
1987 | 2037 |
1988 return rv; | 2038 return rv; |
1989 } | 2039 } |
1990 | 2040 |
1991 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 2041 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
1992 if (last_page_mouse_down_ == -1) | 2042 if (last_page_mouse_down_ == -1) |
1993 return false; | 2043 return false; |
1994 | 2044 |
2045 if (in_form_text_field_ || in_form_combobox_text_field_) { | |
2046 if (event.GetKeyCode() == ui::VKEY_SHIFT) | |
2047 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
2048 else { | |
2049 // If a key other than shift is released while shift is not also | |
2050 // being held down, selection of form field text should be cleared. | |
2051 if (event.GetModifiers() & ~PP_INPUTEVENT_MODIFIER_SHIFTKEY) | |
2052 pp::PDF::SetSelectedText(GetPluginInstance(), ""); | |
Lei Zhang
2017/06/17 02:21:17
Are you sure the key up event is the best time to
drgage
2017/06/19 21:53:52
Done.
| |
2053 } | |
2054 } | |
2055 | |
1995 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), | 2056 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
1996 event.GetKeyCode(), event.GetModifiers()); | 2057 event.GetKeyCode(), event.GetModifiers()); |
1997 } | 2058 } |
1998 | 2059 |
1999 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2060 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
2000 if (last_page_mouse_down_ == -1) | 2061 if (last_page_mouse_down_ == -1) |
2001 return false; | 2062 return false; |
2002 | 2063 |
2003 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 2064 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
2004 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], | 2065 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... | |
3546 client_->ScrollToPage(most_visible_page); | 3607 client_->ScrollToPage(most_visible_page); |
3547 } | 3608 } |
3548 | 3609 |
3549 void PDFiumEngine::SetSelecting(bool selecting) { | 3610 void PDFiumEngine::SetSelecting(bool selecting) { |
3550 bool was_selecting = selecting_; | 3611 bool was_selecting = selecting_; |
3551 selecting_ = selecting; | 3612 selecting_ = selecting; |
3552 if (selecting_ != was_selecting) | 3613 if (selecting_ != was_selecting) |
3553 client_->IsSelectingChanged(selecting); | 3614 client_->IsSelectingChanged(selecting); |
3554 } | 3615 } |
3555 | 3616 |
3617 void PDFiumEngine::SetInFormTextField(bool in_form_text_field) { | |
3618 in_form_text_field_ = in_form_text_field; | |
3619 } | |
3620 | |
3621 void PDFiumEngine::SetInFormComboboxTextField( | |
3622 bool in_form_combobox_text_field) { | |
3623 in_form_combobox_text_field_ = in_form_combobox_text_field; | |
3624 } | |
3625 | |
3556 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3626 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
3557 touch_timers_[++next_touch_timer_id_] = evt; | 3627 touch_timers_[++next_touch_timer_id_] = evt; |
3558 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3628 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
3559 kTouchLongPressTimeoutMs); | 3629 kTouchLongPressTimeoutMs); |
3560 } | 3630 } |
3561 | 3631 |
3562 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3632 void PDFiumEngine::KillTouchTimer(int timer_id) { |
3563 touch_timers_.erase(timer_id); | 3633 touch_timers_.erase(timer_id); |
3564 } | 3634 } |
3565 | 3635 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4135 FPDF_DOCUMENT doc = | 4205 FPDF_DOCUMENT doc = |
4136 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4206 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4137 if (!doc) | 4207 if (!doc) |
4138 return false; | 4208 return false; |
4139 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4209 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4140 FPDF_CloseDocument(doc); | 4210 FPDF_CloseDocument(doc); |
4141 return success; | 4211 return success; |
4142 } | 4212 } |
4143 | 4213 |
4144 } // namespace chrome_pdf | 4214 } // namespace chrome_pdf |
OLD | NEW |