Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2924343005: Add functionality for copying text within form text fields and form combobox text fields (Closed)
Patch Set: Add FormTypeToArea helper, style changes Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 SetInFormTextArea(false);
1629 }
1630
1631 void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle,
1632 FPDF_PAGE page) {
1633 unsigned long form_sel_text_len =
1634 FORM_GetSelectedText(form_handle, page, nullptr, 0);
1635
1636 // Initial length = 2 (not 0) because an empty NUL-terminated wide string is
Lei Zhang 2017/06/21 00:19:45 Not sure why I didn't mention this earlier, but th
drgage 2017/06/21 01:30:23 Done.
1637 // two bytes long
1638 if (form_sel_text_len <= 2)
1639 return;
1640
1641 base::string16 selected_form_text16;
1642 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter(
1643 &selected_form_text16, form_sel_text_len, false);
1644 string_adapter.Close(FORM_GetSelectedText(
1645 form_handle, page, string_adapter.GetData(), form_sel_text_len));
1646
1647 std::string selected_form_text = UTF16ToUTF8(selected_form_text16);
1648 if (!selected_form_text.empty()) {
1649 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str());
1650 }
1628 } 1651 }
1629 1652
1630 void PDFiumEngine::PrintEnd() { 1653 void PDFiumEngine::PrintEnd() {
1631 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); 1654 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP);
1632 } 1655 }
1633 1656
1634 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, 1657 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event,
1635 int* page_index, 1658 int* page_index,
1636 int* char_index, 1659 int* char_index,
1637 int* form_type, 1660 int* form_type,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 return false; 1737 return false;
1715 1738
1716 if (page_index != -1) { 1739 if (page_index != -1) {
1717 last_page_mouse_down_ = page_index; 1740 last_page_mouse_down_ = page_index;
1718 double page_x, page_y; 1741 double page_x, page_y;
1719 pp::Point point = event.GetPosition(); 1742 pp::Point point = event.GetPosition();
1720 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1743 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1721 1744
1722 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1745 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1723 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... 1746 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes...
1724 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); 1747 mouse_down_state_.Set(pages_[page_index]->FormTypeToArea(form_type),
Lei Zhang 2017/06/21 00:19:45 If PDFiumPage::FormTypeToArea() became a static me
drgage 2017/06/21 01:30:23 Done.
1748 target);
1749
1725 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || 1750 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD ||
1726 form_type == FPDF_FORMFIELD_COMBOBOX); 1751 form_type == FPDF_FORMFIELD_COMBOBOX);
1752
1753 // TODO(bug_62400): figure out selection and copying
1754 // for XFA fields
1727 #if defined(PDF_ENABLE_XFA) 1755 #if defined(PDF_ENABLE_XFA)
1728 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); 1756 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA);
1729 #endif 1757 #endif
1730 client_->FormTextFieldFocusChange(is_valid_control); 1758 client_->FormTextFieldFocusChange(is_valid_control);
1759 SetInFormTextArea(is_valid_control);
1731 return true; // Return now before we get into the selection code. 1760 return true; // Return now before we get into the selection code.
1732 } 1761 }
1733 } 1762 }
1734
1735 client_->FormTextFieldFocusChange(false); 1763 client_->FormTextFieldFocusChange(false);
1764 SetInFormTextArea(false);
1736 1765
1737 if (area != PDFiumPage::TEXT_AREA) 1766 if (area != PDFiumPage::TEXT_AREA)
1738 return true; // Return true so WebKit doesn't do its own highlighting. 1767 return true; // Return true so WebKit doesn't do its own highlighting.
1739 1768
1740 if (event.GetClickCount() == 1) { 1769 if (event.GetClickCount() == 1) {
1741 OnSingleClick(page_index, char_index); 1770 OnSingleClick(page_index, char_index);
1742 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { 1771 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) {
1743 OnMultipleClick(event.GetClickCount(), page_index, char_index); 1772 OnMultipleClick(event.GetClickCount(), page_index, char_index);
1744 } 1773 }
1745 1774
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); 1830 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY);
1802 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); 1831 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY);
1803 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); 1832 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY);
1804 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); 1833 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY);
1805 1834
1806 WindowOpenDisposition disposition = ui::DispositionFromClick( 1835 WindowOpenDisposition disposition = ui::DispositionFromClick(
1807 middle_button, alt_key, ctrl_key, meta_key, shift_key); 1836 middle_button, alt_key, ctrl_key, meta_key, shift_key);
1808 1837
1809 client_->NavigateTo(target.url, disposition); 1838 client_->NavigateTo(target.url, disposition);
1810 client_->FormTextFieldFocusChange(false); 1839 client_->FormTextFieldFocusChange(false);
1840 SetInFormTextArea(false);
1811 return true; 1841 return true;
1812 } 1842 }
1813 if (area == PDFiumPage::DOCLINK_AREA) { 1843 if (area == PDFiumPage::DOCLINK_AREA) {
1814 client_->ScrollToPage(target.page); 1844 client_->ScrollToPage(target.page);
1815 client_->FormTextFieldFocusChange(false); 1845 client_->FormTextFieldFocusChange(false);
1846 SetInFormTextArea(false);
1816 return true; 1847 return true;
1817 } 1848 }
1818 } 1849 }
1819 1850
1820 // Prevent middle mouse button from selecting texts. 1851 // Prevent middle mouse button from selecting texts.
1821 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) 1852 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
1822 return false; 1853 return false;
1823 1854
1824 if (page_index != -1) { 1855 if (page_index != -1) {
1825 double page_x, page_y; 1856 double page_x, page_y;
1826 pp::Point point = event.GetPosition(); 1857 pp::Point point = event.GetPosition();
1827 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1858 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1828 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1859 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1829 } 1860 }
1830 1861
1862 if (area == PDFiumPage::FORM_TEXT_AREA)
1863 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage());
1864
1831 if (!selecting_) 1865 if (!selecting_)
1832 return false; 1866 return false;
1833 1867
1834 SetSelecting(false); 1868 SetSelecting(false);
1835 return true; 1869 return true;
1836 } 1870 }
1837 1871
1838 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { 1872 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) {
1839 int page_index = -1; 1873 int page_index = -1;
1840 int char_index = -1; 1874 int char_index = -1;
(...skipping 11 matching lines...) Expand all
1852 PP_CursorType_Dev cursor; 1886 PP_CursorType_Dev cursor;
1853 switch (area) { 1887 switch (area) {
1854 case PDFiumPage::TEXT_AREA: 1888 case PDFiumPage::TEXT_AREA:
1855 cursor = PP_CURSORTYPE_IBEAM; 1889 cursor = PP_CURSORTYPE_IBEAM;
1856 break; 1890 break;
1857 case PDFiumPage::WEBLINK_AREA: 1891 case PDFiumPage::WEBLINK_AREA:
1858 case PDFiumPage::DOCLINK_AREA: 1892 case PDFiumPage::DOCLINK_AREA:
1859 cursor = PP_CURSORTYPE_HAND; 1893 cursor = PP_CURSORTYPE_HAND;
1860 break; 1894 break;
1861 case PDFiumPage::NONSELECTABLE_AREA: 1895 case PDFiumPage::NONSELECTABLE_AREA:
1896 case PDFiumPage::FORM_TEXT_AREA:
1862 default: 1897 default:
1863 switch (form_type) { 1898 switch (form_type) {
1864 case FPDF_FORMFIELD_PUSHBUTTON: 1899 case FPDF_FORMFIELD_PUSHBUTTON:
1865 case FPDF_FORMFIELD_CHECKBOX: 1900 case FPDF_FORMFIELD_CHECKBOX:
1866 case FPDF_FORMFIELD_RADIOBUTTON: 1901 case FPDF_FORMFIELD_RADIOBUTTON:
1867 case FPDF_FORMFIELD_COMBOBOX: 1902 case FPDF_FORMFIELD_COMBOBOX:
1868 case FPDF_FORMFIELD_LISTBOX: 1903 case FPDF_FORMFIELD_LISTBOX:
1869 cursor = PP_CURSORTYPE_HAND; 1904 cursor = PP_CURSORTYPE_HAND;
1870 break; 1905 break;
1871 case FPDF_FORMFIELD_TEXTFIELD: 1906 case FPDF_FORMFIELD_TEXTFIELD:
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev ision=31805 2013 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev ision=31805
1979 // for more information. So just fake one since PDFium uses it. 2014 // for more information. So just fake one since PDFium uses it.
1980 std::string str; 2015 std::string str;
1981 str.push_back(event.GetKeyCode()); 2016 str.push_back(event.GetKeyCode());
1982 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent( 2017 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent(
1983 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR, 2018 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR,
1984 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str)); 2019 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str));
1985 OnChar(synthesized); 2020 OnChar(synthesized);
1986 } 2021 }
1987 2022
2023 // If form selected text is empty and key pressed within form text area,
2024 // plugin text selection should be cleared.
2025 if (in_form_text_area_ &&
2026 FORM_GetSelectedText(form_, pages_[last_page_mouse_down_]->GetPage(),
2027 nullptr, 0) <= 2)
2028 pp::PDF::SetSelectedText(GetPluginInstance(), "");
2029
1988 return rv; 2030 return rv;
1989 } 2031 }
1990 2032
1991 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { 2033 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) {
1992 if (last_page_mouse_down_ == -1) 2034 if (last_page_mouse_down_ == -1)
1993 return false; 2035 return false;
1994 2036
2037 if (in_form_text_area_) {
2038 if (event.GetKeyCode() == ui::VKEY_SHIFT)
2039 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage());
2040 }
2041
1995 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), 2042 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(),
1996 event.GetKeyCode(), event.GetModifiers()); 2043 event.GetKeyCode(), event.GetModifiers());
1997 } 2044 }
1998 2045
1999 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { 2046 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) {
2000 if (last_page_mouse_down_ == -1) 2047 if (last_page_mouse_down_ == -1)
2001 return false; 2048 return false;
2002 2049
2003 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); 2050 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString());
2004 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], 2051 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0],
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 client_->ScrollToPage(most_visible_page); 3593 client_->ScrollToPage(most_visible_page);
3547 } 3594 }
3548 3595
3549 void PDFiumEngine::SetSelecting(bool selecting) { 3596 void PDFiumEngine::SetSelecting(bool selecting) {
3550 bool was_selecting = selecting_; 3597 bool was_selecting = selecting_;
3551 selecting_ = selecting; 3598 selecting_ = selecting;
3552 if (selecting_ != was_selecting) 3599 if (selecting_ != was_selecting)
3553 client_->IsSelectingChanged(selecting); 3600 client_->IsSelectingChanged(selecting);
3554 } 3601 }
3555 3602
3603 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
3604 in_form_text_area_ = in_form_text_area;
3605 }
3606
3556 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { 3607 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
3557 touch_timers_[++next_touch_timer_id_] = evt; 3608 touch_timers_[++next_touch_timer_id_] = evt;
3558 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, 3609 client_->ScheduleTouchTimerCallback(next_touch_timer_id_,
3559 kTouchLongPressTimeoutMs); 3610 kTouchLongPressTimeoutMs);
3560 } 3611 }
3561 3612
3562 void PDFiumEngine::KillTouchTimer(int timer_id) { 3613 void PDFiumEngine::KillTouchTimer(int timer_id) {
3563 touch_timers_.erase(timer_id); 3614 touch_timers_.erase(timer_id);
3564 } 3615 }
3565 3616
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 FPDF_DOCUMENT doc = 4186 FPDF_DOCUMENT doc =
4136 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 4187 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
4137 if (!doc) 4188 if (!doc)
4138 return false; 4189 return false;
4139 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4190 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4140 FPDF_CloseDocument(doc); 4191 FPDF_CloseDocument(doc);
4141 return success; 4192 return success;
4142 } 4193 }
4143 4194
4144 } // namespace chrome_pdf 4195 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | pdf/pdfium/pdfium_page.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698