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 } | |
1630 | |
1631 void PDFiumEngine::SetFormSelectedText(const FPDF_FORMHANDLE& hHandle, | |
1632 const FPDF_PAGE& page) { | |
1633 size_t form_sel_text_len = FORM_GetSelectedText(hHandle, page, nullptr, 0); | |
1634 | |
1635 // Initial length = 2 (not 0) because text is CFX_WideString and | |
1636 // sentinel char is included in count. | |
1637 if (form_sel_text_len <= 2) | |
1638 return; | |
1639 | |
1640 base::string16 selected_form_text16; | |
1641 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( | |
1642 &selected_form_text16, form_sel_text_len, false); | |
1643 string_adapter.Close(FORM_GetSelectedText( | |
1644 hHandle, page, string_adapter.GetData(), form_sel_text_len)); | |
1645 | |
1646 std::string selected_form_text = UTF16ToUTF8(selected_form_text16); | |
1647 if (!selected_form_text.empty()) { | |
1648 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); | |
1649 } | |
1628 } | 1650 } |
1629 | 1651 |
1630 void PDFiumEngine::PrintEnd() { | 1652 void PDFiumEngine::PrintEnd() { |
1631 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1653 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
1632 } | 1654 } |
1633 | 1655 |
1634 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, | 1656 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, |
1635 int* page_index, | 1657 int* page_index, |
1636 int* char_index, | 1658 int* char_index, |
1637 int* form_type, | 1659 int* form_type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1714 return false; | 1736 return false; |
1715 | 1737 |
1716 if (page_index != -1) { | 1738 if (page_index != -1) { |
1717 last_page_mouse_down_ = page_index; | 1739 last_page_mouse_down_ = page_index; |
1718 double page_x, page_y; | 1740 double page_x, page_y; |
1719 pp::Point point = event.GetPosition(); | 1741 pp::Point point = event.GetPosition(); |
1720 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1742 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1721 | 1743 |
1722 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1744 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1723 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1745 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
1724 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | 1746 mouse_down_state_.Set(form_type == FPDF_FORMFIELD_TEXTFIELD |
1747 ? PDFiumPage::FORM_TEXT_AREA | |
1748 : PDFiumPage::NONSELECTABLE_AREA, | |
1749 target); | |
1750 | |
1725 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || | 1751 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
1726 form_type == FPDF_FORMFIELD_COMBOBOX); | 1752 form_type == FPDF_FORMFIELD_COMBOBOX); |
1753 | |
1754 // TODO(bug_62400): figure out selection and copying | |
1755 // for XFA fields | |
1727 #if defined(PDF_ENABLE_XFA) | 1756 #if defined(PDF_ENABLE_XFA) |
1728 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); | 1757 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
1729 #endif | 1758 #endif |
1759 | |
1760 // TODO(drgage): implement copying for comboboxes | |
1730 client_->FormTextFieldFocusChange(is_valid_control); | 1761 client_->FormTextFieldFocusChange(is_valid_control); |
1762 SetInFormTextField(is_valid_control); | |
1731 return true; // Return now before we get into the selection code. | 1763 return true; // Return now before we get into the selection code. |
1732 } | 1764 } |
1733 } | 1765 } |
1734 | 1766 |
1735 client_->FormTextFieldFocusChange(false); | 1767 client_->FormTextFieldFocusChange(false); |
1768 SetInFormTextField(false); | |
1736 | 1769 |
1737 if (area != PDFiumPage::TEXT_AREA) | 1770 if (area != PDFiumPage::TEXT_AREA) |
1738 return true; // Return true so WebKit doesn't do its own highlighting. | 1771 return true; // Return true so WebKit doesn't do its own highlighting. |
1739 | 1772 |
1740 if (event.GetClickCount() == 1) { | 1773 if (event.GetClickCount() == 1) { |
1741 OnSingleClick(page_index, char_index); | 1774 OnSingleClick(page_index, char_index); |
1742 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { | 1775 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { |
1743 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1776 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
1744 } | 1777 } |
1745 | 1778 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1801 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1834 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
1802 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1835 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
1803 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1836 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
1804 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | 1837 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); |
1805 | 1838 |
1806 WindowOpenDisposition disposition = ui::DispositionFromClick( | 1839 WindowOpenDisposition disposition = ui::DispositionFromClick( |
1807 middle_button, alt_key, ctrl_key, meta_key, shift_key); | 1840 middle_button, alt_key, ctrl_key, meta_key, shift_key); |
1808 | 1841 |
1809 client_->NavigateTo(target.url, disposition); | 1842 client_->NavigateTo(target.url, disposition); |
1810 client_->FormTextFieldFocusChange(false); | 1843 client_->FormTextFieldFocusChange(false); |
1844 SetInFormTextField(false); | |
1811 return true; | 1845 return true; |
1812 } | 1846 } |
1813 if (area == PDFiumPage::DOCLINK_AREA) { | 1847 if (area == PDFiumPage::DOCLINK_AREA) { |
1814 client_->ScrollToPage(target.page); | 1848 client_->ScrollToPage(target.page); |
1815 client_->FormTextFieldFocusChange(false); | 1849 client_->FormTextFieldFocusChange(false); |
1850 SetInFormTextField(false); | |
1816 return true; | 1851 return true; |
1817 } | 1852 } |
1818 } | 1853 } |
1819 | 1854 |
1820 // Prevent middle mouse button from selecting texts. | 1855 // Prevent middle mouse button from selecting texts. |
1821 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1856 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
1822 return false; | 1857 return false; |
1823 | 1858 |
1824 if (page_index != -1) { | 1859 if (page_index != -1) { |
1825 double page_x, page_y; | 1860 double page_x, page_y; |
1826 pp::Point point = event.GetPosition(); | 1861 pp::Point point = event.GetPosition(); |
1827 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1862 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1828 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1863 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1829 } | 1864 } |
1830 | 1865 |
1866 if (area == PDFiumPage::FORM_TEXT_AREA) { | |
1867 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
1868 } | |
1869 | |
1831 if (!selecting_) | 1870 if (!selecting_) |
1832 return false; | 1871 return false; |
1833 | 1872 |
1834 SetSelecting(false); | 1873 SetSelecting(false); |
1835 return true; | 1874 return true; |
1836 } | 1875 } |
1837 | 1876 |
1838 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1877 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
1839 int page_index = -1; | 1878 int page_index = -1; |
1840 int char_index = -1; | 1879 int char_index = -1; |
(...skipping 11 matching lines...) Expand all Loading... | |
1852 PP_CursorType_Dev cursor; | 1891 PP_CursorType_Dev cursor; |
1853 switch (area) { | 1892 switch (area) { |
1854 case PDFiumPage::TEXT_AREA: | 1893 case PDFiumPage::TEXT_AREA: |
1855 cursor = PP_CURSORTYPE_IBEAM; | 1894 cursor = PP_CURSORTYPE_IBEAM; |
1856 break; | 1895 break; |
1857 case PDFiumPage::WEBLINK_AREA: | 1896 case PDFiumPage::WEBLINK_AREA: |
1858 case PDFiumPage::DOCLINK_AREA: | 1897 case PDFiumPage::DOCLINK_AREA: |
1859 cursor = PP_CURSORTYPE_HAND; | 1898 cursor = PP_CURSORTYPE_HAND; |
1860 break; | 1899 break; |
1861 case PDFiumPage::NONSELECTABLE_AREA: | 1900 case PDFiumPage::NONSELECTABLE_AREA: |
1901 case PDFiumPage::FORM_TEXT_AREA: | |
1862 default: | 1902 default: |
1863 switch (form_type) { | 1903 switch (form_type) { |
1864 case FPDF_FORMFIELD_PUSHBUTTON: | 1904 case FPDF_FORMFIELD_PUSHBUTTON: |
1865 case FPDF_FORMFIELD_CHECKBOX: | 1905 case FPDF_FORMFIELD_CHECKBOX: |
1866 case FPDF_FORMFIELD_RADIOBUTTON: | 1906 case FPDF_FORMFIELD_RADIOBUTTON: |
1867 case FPDF_FORMFIELD_COMBOBOX: | 1907 case FPDF_FORMFIELD_COMBOBOX: |
1868 case FPDF_FORMFIELD_LISTBOX: | 1908 case FPDF_FORMFIELD_LISTBOX: |
1869 cursor = PP_CURSORTYPE_HAND; | 1909 cursor = PP_CURSORTYPE_HAND; |
1870 break; | 1910 break; |
1871 case FPDF_FORMFIELD_TEXTFIELD: | 1911 case FPDF_FORMFIELD_TEXTFIELD: |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1985 OnChar(synthesized); | 2025 OnChar(synthesized); |
1986 } | 2026 } |
1987 | 2027 |
1988 return rv; | 2028 return rv; |
1989 } | 2029 } |
1990 | 2030 |
1991 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 2031 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
1992 if (last_page_mouse_down_ == -1) | 2032 if (last_page_mouse_down_ == -1) |
1993 return false; | 2033 return false; |
1994 | 2034 |
2035 if (in_form_text_field_) { | |
2036 if (event.GetKeyCode() == ui::VKEY_SHIFT) | |
2037 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
2038 else { | |
2039 uint32_t modifiers = event.GetModifiers(); | |
Lei Zhang
2017/06/16 21:34:53
Try to declare variables as close to where they ar
drgage
2017/06/16 23:15:04
Done.
| |
2040 | |
2041 // If a key other than shift is released while shift is not also | |
2042 // being held down, selection of form field text should be invalidated. | |
2043 if (modifiers & ~PP_INPUTEVENT_MODIFIER_SHIFTKEY) | |
2044 SelectionChangeInvalidator selection_invalidator(this); | |
Lei Zhang
2017/06/16 21:34:53
SelectionChangeInvalidator seems to do a lot of wo
drgage
2017/06/16 23:15:04
Done.
| |
2045 } | |
2046 } | |
2047 | |
1995 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), | 2048 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
1996 event.GetKeyCode(), event.GetModifiers()); | 2049 event.GetKeyCode(), event.GetModifiers()); |
1997 } | 2050 } |
1998 | 2051 |
1999 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2052 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
2000 if (last_page_mouse_down_ == -1) | 2053 if (last_page_mouse_down_ == -1) |
2001 return false; | 2054 return false; |
2002 | 2055 |
2003 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 2056 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
2004 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], | 2057 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); | 3599 client_->ScrollToPage(most_visible_page); |
3547 } | 3600 } |
3548 | 3601 |
3549 void PDFiumEngine::SetSelecting(bool selecting) { | 3602 void PDFiumEngine::SetSelecting(bool selecting) { |
3550 bool was_selecting = selecting_; | 3603 bool was_selecting = selecting_; |
3551 selecting_ = selecting; | 3604 selecting_ = selecting; |
3552 if (selecting_ != was_selecting) | 3605 if (selecting_ != was_selecting) |
3553 client_->IsSelectingChanged(selecting); | 3606 client_->IsSelectingChanged(selecting); |
3554 } | 3607 } |
3555 | 3608 |
3609 void PDFiumEngine::SetInFormTextField(bool in_form_text_field) { | |
3610 in_form_text_field_ = in_form_text_field; | |
3611 } | |
3612 | |
3556 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3613 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
3557 touch_timers_[++next_touch_timer_id_] = evt; | 3614 touch_timers_[++next_touch_timer_id_] = evt; |
3558 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3615 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
3559 kTouchLongPressTimeoutMs); | 3616 kTouchLongPressTimeoutMs); |
3560 } | 3617 } |
3561 | 3618 |
3562 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3619 void PDFiumEngine::KillTouchTimer(int timer_id) { |
3563 touch_timers_.erase(timer_id); | 3620 touch_timers_.erase(timer_id); |
3564 } | 3621 } |
3565 | 3622 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4135 FPDF_DOCUMENT doc = | 4192 FPDF_DOCUMENT doc = |
4136 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4193 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4137 if (!doc) | 4194 if (!doc) |
4138 return false; | 4195 return false; |
4139 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4196 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4140 FPDF_CloseDocument(doc); | 4197 FPDF_CloseDocument(doc); |
4141 return success; | 4198 return success; |
4142 } | 4199 } |
4143 | 4200 |
4144 } // namespace chrome_pdf | 4201 } // namespace chrome_pdf |
OLD | NEW |