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 if (!form_sel_text_len) | |
1634 return; | |
1635 | |
1636 base::string16 selected_form_text16; | |
1637 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( | |
1638 &selected_form_text16, form_sel_text_len, false); | |
1639 string_adapter.Close(FORM_GetSelectedText( | |
1640 hHandle, page, string_adapter.GetData(), form_sel_text_len)); | |
1641 | |
1642 std::string selected_form_text = UTF16ToUTF8(selected_form_text16); | |
1643 if (!selected_form_text.empty()) { | |
1644 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); | |
1645 } | |
1627 } | 1646 } |
1628 | 1647 |
1629 void PDFiumEngine::PrintEnd() { | 1648 void PDFiumEngine::PrintEnd() { |
1630 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1649 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
1631 } | 1650 } |
1632 | 1651 |
1633 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, | 1652 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, |
1634 int* page_index, | 1653 int* page_index, |
1635 int* char_index, | 1654 int* char_index, |
1636 int* form_type, | 1655 int* form_type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1713 return false; | 1732 return false; |
1714 | 1733 |
1715 if (page_index != -1) { | 1734 if (page_index != -1) { |
1716 last_page_mouse_down_ = page_index; | 1735 last_page_mouse_down_ = page_index; |
1717 double page_x, page_y; | 1736 double page_x, page_y; |
1718 pp::Point point = event.GetPosition(); | 1737 pp::Point point = event.GetPosition(); |
1719 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1738 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1720 | 1739 |
1721 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1740 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1722 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1741 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
1723 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | 1742 mouse_down_state_.Set(PDFiumPage::FORM_TEXT_AREA, target); |
Lei Zhang
2017/06/14 07:07:02
If we click on a form widget that is not a form te
drgage
2017/06/14 22:53:39
Probably not - I'll change this so that it only is
drgage
2017/06/14 22:53:39
Done.
| |
1724 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || | 1743 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
1725 form_type == FPDF_FORMFIELD_COMBOBOX); | 1744 form_type == FPDF_FORMFIELD_COMBOBOX); |
1726 #if defined(PDF_ENABLE_XFA) | 1745 #if defined(PDF_ENABLE_XFA) |
1727 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); | 1746 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
1728 #endif | 1747 #endif |
1729 client_->FormTextFieldFocusChange(is_valid_control); | 1748 client_->FormTextFieldFocusChange(is_valid_control); |
1749 | |
1750 // TODO (drgage): come back here and figure out what to do with | |
Lei Zhang
2017/06/14 07:07:02
I think this is actually correct as is in the non-
drgage
2017/06/14 22:53:39
Done.
| |
1751 // is_valid_control | |
1752 SetInFormTextField(is_valid_control); | |
1730 return true; // Return now before we get into the selection code. | 1753 return true; // Return now before we get into the selection code. |
1731 } | 1754 } |
1732 } | 1755 } |
1733 | 1756 |
1734 client_->FormTextFieldFocusChange(false); | 1757 client_->FormTextFieldFocusChange(false); |
1758 SetInFormTextField(false); | |
1735 | 1759 |
1736 if (area != PDFiumPage::TEXT_AREA) | 1760 if (area != PDFiumPage::TEXT_AREA) |
1737 return true; // Return true so WebKit doesn't do its own highlighting. | 1761 return true; // Return true so WebKit doesn't do its own highlighting. |
1738 | 1762 |
1739 if (event.GetClickCount() == 1) { | 1763 if (event.GetClickCount() == 1) { |
1740 OnSingleClick(page_index, char_index); | 1764 OnSingleClick(page_index, char_index); |
1741 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { | 1765 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { |
1742 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1766 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
1743 } | 1767 } |
1744 | 1768 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1824 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
1801 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1825 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
1802 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1826 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
1803 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | 1827 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); |
1804 | 1828 |
1805 WindowOpenDisposition disposition = ui::DispositionFromClick( | 1829 WindowOpenDisposition disposition = ui::DispositionFromClick( |
1806 middle_button, alt_key, ctrl_key, meta_key, shift_key); | 1830 middle_button, alt_key, ctrl_key, meta_key, shift_key); |
1807 | 1831 |
1808 client_->NavigateTo(target.url, disposition); | 1832 client_->NavigateTo(target.url, disposition); |
1809 client_->FormTextFieldFocusChange(false); | 1833 client_->FormTextFieldFocusChange(false); |
1834 SetInFormTextField(false); | |
1810 return true; | 1835 return true; |
1811 } | 1836 } |
1812 if (area == PDFiumPage::DOCLINK_AREA) { | 1837 if (area == PDFiumPage::DOCLINK_AREA) { |
1813 client_->ScrollToPage(target.page); | 1838 client_->ScrollToPage(target.page); |
1814 client_->FormTextFieldFocusChange(false); | 1839 client_->FormTextFieldFocusChange(false); |
1840 SetInFormTextField(false); | |
1815 return true; | 1841 return true; |
1816 } | 1842 } |
1817 } | 1843 } |
1818 | 1844 |
1819 // Prevent middle mouse button from selecting texts. | 1845 // Prevent middle mouse button from selecting texts. |
1820 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1846 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
1821 return false; | 1847 return false; |
1822 | 1848 |
1823 if (page_index != -1) { | 1849 if (page_index != -1) { |
1824 double page_x, page_y; | 1850 double page_x, page_y; |
1825 pp::Point point = event.GetPosition(); | 1851 pp::Point point = event.GetPosition(); |
1826 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1852 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1827 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1853 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1828 } | 1854 } |
1829 | 1855 |
1856 if (area == PDFiumPage::FORM_TEXT_AREA) { | |
1857 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
1858 } | |
1859 | |
1830 if (!selecting_) | 1860 if (!selecting_) |
Lei Zhang
2017/06/14 07:07:02
The existing code like this member variable and Se
drgage
2017/06/14 22:53:40
Done. Do you think it's sufficient to add an expla
| |
1831 return false; | 1861 return false; |
1832 | 1862 |
1833 SetSelecting(false); | 1863 SetSelecting(false); |
1834 return true; | 1864 return true; |
1835 } | 1865 } |
1836 | 1866 |
1837 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1867 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
1838 int page_index = -1; | 1868 int page_index = -1; |
1839 int char_index = -1; | 1869 int char_index = -1; |
1840 int form_type = FPDF_FORMFIELD_UNKNOWN; | 1870 int form_type = FPDF_FORMFIELD_UNKNOWN; |
(...skipping 10 matching lines...) Expand all Loading... | |
1851 PP_CursorType_Dev cursor; | 1881 PP_CursorType_Dev cursor; |
1852 switch (area) { | 1882 switch (area) { |
1853 case PDFiumPage::TEXT_AREA: | 1883 case PDFiumPage::TEXT_AREA: |
1854 cursor = PP_CURSORTYPE_IBEAM; | 1884 cursor = PP_CURSORTYPE_IBEAM; |
1855 break; | 1885 break; |
1856 case PDFiumPage::WEBLINK_AREA: | 1886 case PDFiumPage::WEBLINK_AREA: |
1857 case PDFiumPage::DOCLINK_AREA: | 1887 case PDFiumPage::DOCLINK_AREA: |
1858 cursor = PP_CURSORTYPE_HAND; | 1888 cursor = PP_CURSORTYPE_HAND; |
1859 break; | 1889 break; |
1860 case PDFiumPage::NONSELECTABLE_AREA: | 1890 case PDFiumPage::NONSELECTABLE_AREA: |
1861 default: | 1891 default: |
Lei Zhang
2017/06/14 07:07:02
Let's handle FORM_TEXT_AREA explicitly here too.
drgage
2017/06/14 22:53:39
Do you think I should just add another case withou
Lei Zhang
2017/06/15 18:11:28
Add another case without a break.
drgage
2017/06/16 02:12:36
Done.
| |
1862 switch (form_type) { | 1892 switch (form_type) { |
1863 case FPDF_FORMFIELD_PUSHBUTTON: | 1893 case FPDF_FORMFIELD_PUSHBUTTON: |
1864 case FPDF_FORMFIELD_CHECKBOX: | 1894 case FPDF_FORMFIELD_CHECKBOX: |
1865 case FPDF_FORMFIELD_RADIOBUTTON: | 1895 case FPDF_FORMFIELD_RADIOBUTTON: |
1866 case FPDF_FORMFIELD_COMBOBOX: | 1896 case FPDF_FORMFIELD_COMBOBOX: |
1867 case FPDF_FORMFIELD_LISTBOX: | 1897 case FPDF_FORMFIELD_LISTBOX: |
1868 cursor = PP_CURSORTYPE_HAND; | 1898 cursor = PP_CURSORTYPE_HAND; |
1869 break; | 1899 break; |
1870 case FPDF_FORMFIELD_TEXTFIELD: | 1900 case FPDF_FORMFIELD_TEXTFIELD: |
1871 cursor = PP_CURSORTYPE_IBEAM; | 1901 cursor = PP_CURSORTYPE_IBEAM; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1984 OnChar(synthesized); | 2014 OnChar(synthesized); |
1985 } | 2015 } |
1986 | 2016 |
1987 return rv; | 2017 return rv; |
1988 } | 2018 } |
1989 | 2019 |
1990 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 2020 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
1991 if (last_page_mouse_down_ == -1) | 2021 if (last_page_mouse_down_ == -1) |
1992 return false; | 2022 return false; |
1993 | 2023 |
2024 if (in_form_text_field_) { | |
2025 uint32_t modifiers = event.GetModifiers(); | |
2026 if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) | |
Lei Zhang
2017/06/14 07:07:02
I tried this code out and noticed if I:
1) used th
drgage
2017/06/14 22:53:39
I see what you mean. I hadn't tried this combinati
Lei Zhang
2017/06/15 18:11:28
I don't think you need to actually know how the vi
drgage
2017/06/16 02:12:36
Done.
| |
2027 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
2028 } | |
2029 | |
1994 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), | 2030 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
1995 event.GetKeyCode(), event.GetModifiers()); | 2031 event.GetKeyCode(), event.GetModifiers()); |
1996 } | 2032 } |
1997 | 2033 |
1998 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2034 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
1999 if (last_page_mouse_down_ == -1) | 2035 if (last_page_mouse_down_ == -1) |
2000 return false; | 2036 return false; |
2001 | 2037 |
2002 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 2038 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
2003 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], | 2039 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); | 3581 client_->ScrollToPage(most_visible_page); |
3546 } | 3582 } |
3547 | 3583 |
3548 void PDFiumEngine::SetSelecting(bool selecting) { | 3584 void PDFiumEngine::SetSelecting(bool selecting) { |
3549 bool was_selecting = selecting_; | 3585 bool was_selecting = selecting_; |
3550 selecting_ = selecting; | 3586 selecting_ = selecting; |
3551 if (selecting_ != was_selecting) | 3587 if (selecting_ != was_selecting) |
3552 client_->IsSelectingChanged(selecting); | 3588 client_->IsSelectingChanged(selecting); |
3553 } | 3589 } |
3554 | 3590 |
3591 void PDFiumEngine::SetInFormTextField(bool in_form_text_field) { | |
3592 in_form_text_field_ = in_form_text_field; | |
3593 } | |
3594 | |
3555 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3595 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
3556 touch_timers_[++next_touch_timer_id_] = evt; | 3596 touch_timers_[++next_touch_timer_id_] = evt; |
3557 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3597 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
3558 kTouchLongPressTimeoutMs); | 3598 kTouchLongPressTimeoutMs); |
3559 } | 3599 } |
3560 | 3600 |
3561 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3601 void PDFiumEngine::KillTouchTimer(int timer_id) { |
3562 touch_timers_.erase(timer_id); | 3602 touch_timers_.erase(timer_id); |
3563 } | 3603 } |
3564 | 3604 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4134 FPDF_DOCUMENT doc = | 4174 FPDF_DOCUMENT doc = |
4135 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4175 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4136 if (!doc) | 4176 if (!doc) |
4137 return false; | 4177 return false; |
4138 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4178 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4139 FPDF_CloseDocument(doc); | 4179 FPDF_CloseDocument(doc); |
4140 return success; | 4180 return success; |
4141 } | 4181 } |
4142 | 4182 |
4143 } // namespace chrome_pdf | 4183 } // namespace chrome_pdf |
OLD | NEW |