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

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: Update FormTypeToArea() to be static, 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
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 FPDF_PAGE page = FPDF_LoadPage(doc, i); 1621 FPDF_PAGE page = FPDF_LoadPage(doc, i);
1622 TransformPDFPageForPrinting(page, print_settings); 1622 TransformPDFPageForPrinting(page, print_settings);
1623 FPDF_ClosePage(page); 1623 FPDF_ClosePage(page);
1624 } 1624 }
1625 } 1625 }
1626 } 1626 }
1627 1627
1628 void PDFiumEngine::SaveSelectedFormForPrint() { 1628 void PDFiumEngine::SaveSelectedFormForPrint() {
1629 FORM_ForceToKillFocus(form_); 1629 FORM_ForceToKillFocus(form_);
1630 client_->FormTextFieldFocusChange(false); 1630 client_->FormTextFieldFocusChange(false);
1631 SetInFormTextArea(false);
1632 }
1633
1634 void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle,
1635 FPDF_PAGE page) {
1636 unsigned long form_sel_text_len =
1637 FORM_GetSelectedText(form_handle, page, nullptr, 0);
1638
1639 // Check to see if there is selected text in the form. When
1640 // |form_sel_text_len| is 2, that represents a wide string with just a
1641 // NUL-terminator.
1642 if (form_sel_text_len <= 2)
1643 return;
1644
1645 base::string16 selected_form_text16;
1646 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter(
1647 &selected_form_text16, form_sel_text_len, false);
1648 string_adapter.Close(FORM_GetSelectedText(
1649 form_handle, page, string_adapter.GetData(), form_sel_text_len));
1650
1651 std::string selected_form_text = UTF16ToUTF8(selected_form_text16);
1652 if (!selected_form_text.empty()) {
1653 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str());
1654 }
1631 } 1655 }
1632 1656
1633 void PDFiumEngine::PrintEnd() { 1657 void PDFiumEngine::PrintEnd() {
1634 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); 1658 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP);
1635 } 1659 }
1636 1660
1637 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, 1661 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event,
1638 int* page_index, 1662 int* page_index,
1639 int* char_index, 1663 int* char_index,
1640 int* form_type, 1664 int* form_type,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 return false; 1741 return false;
1718 1742
1719 if (page_index != -1) { 1743 if (page_index != -1) {
1720 last_page_mouse_down_ = page_index; 1744 last_page_mouse_down_ = page_index;
1721 double page_x, page_y; 1745 double page_x, page_y;
1722 pp::Point point = event.GetPosition(); 1746 pp::Point point = event.GetPosition();
1723 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1747 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1724 1748
1725 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1749 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1726 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... 1750 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes...
1727 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); 1751 mouse_down_state_.Set(PDFiumPage::FormTypeToArea(form_type), target);
1752
1728 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || 1753 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD ||
1729 form_type == FPDF_FORMFIELD_COMBOBOX); 1754 form_type == FPDF_FORMFIELD_COMBOBOX);
1755
1756 // TODO(bug_62400): figure out selection and copying
1757 // for XFA fields
1730 #if defined(PDF_ENABLE_XFA) 1758 #if defined(PDF_ENABLE_XFA)
1731 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); 1759 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA);
1732 #endif 1760 #endif
1733 client_->FormTextFieldFocusChange(is_valid_control); 1761 client_->FormTextFieldFocusChange(is_valid_control);
1762 SetInFormTextArea(is_valid_control);
1734 return true; // Return now before we get into the selection code. 1763 return true; // Return now before we get into the selection code.
1735 } 1764 }
1736 } 1765 }
1737
1738 client_->FormTextFieldFocusChange(false); 1766 client_->FormTextFieldFocusChange(false);
1767 SetInFormTextArea(false);
1739 1768
1740 if (area != PDFiumPage::TEXT_AREA) 1769 if (area != PDFiumPage::TEXT_AREA)
1741 return true; // Return true so WebKit doesn't do its own highlighting. 1770 return true; // Return true so WebKit doesn't do its own highlighting.
1742 1771
1743 if (event.GetClickCount() == 1) { 1772 if (event.GetClickCount() == 1) {
1744 OnSingleClick(page_index, char_index); 1773 OnSingleClick(page_index, char_index);
1745 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { 1774 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) {
1746 OnMultipleClick(event.GetClickCount(), page_index, char_index); 1775 OnMultipleClick(event.GetClickCount(), page_index, char_index);
1747 } 1776 }
1748 1777
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); 1833 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY);
1805 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); 1834 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY);
1806 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); 1835 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY);
1807 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); 1836 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY);
1808 1837
1809 WindowOpenDisposition disposition = ui::DispositionFromClick( 1838 WindowOpenDisposition disposition = ui::DispositionFromClick(
1810 middle_button, alt_key, ctrl_key, meta_key, shift_key); 1839 middle_button, alt_key, ctrl_key, meta_key, shift_key);
1811 1840
1812 client_->NavigateTo(target.url, disposition); 1841 client_->NavigateTo(target.url, disposition);
1813 client_->FormTextFieldFocusChange(false); 1842 client_->FormTextFieldFocusChange(false);
1843 SetInFormTextArea(false);
1814 return true; 1844 return true;
1815 } 1845 }
1816 if (area == PDFiumPage::DOCLINK_AREA) { 1846 if (area == PDFiumPage::DOCLINK_AREA) {
1817 client_->ScrollToPage(target.page); 1847 client_->ScrollToPage(target.page);
1818 client_->FormTextFieldFocusChange(false); 1848 client_->FormTextFieldFocusChange(false);
1849 SetInFormTextArea(false);
1819 return true; 1850 return true;
1820 } 1851 }
1821 } 1852 }
1822 1853
1823 // Prevent middle mouse button from selecting texts. 1854 // Prevent middle mouse button from selecting texts.
1824 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) 1855 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
1825 return false; 1856 return false;
1826 1857
1827 if (page_index != -1) { 1858 if (page_index != -1) {
1828 double page_x, page_y; 1859 double page_x, page_y;
1829 pp::Point point = event.GetPosition(); 1860 pp::Point point = event.GetPosition();
1830 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1861 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1831 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1862 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1832 } 1863 }
1833 1864
1865 if (area == PDFiumPage::FORM_TEXT_AREA)
1866 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage());
1867
1834 if (!selecting_) 1868 if (!selecting_)
1835 return false; 1869 return false;
1836 1870
1837 SetSelecting(false); 1871 SetSelecting(false);
1838 return true; 1872 return true;
1839 } 1873 }
1840 1874
1841 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { 1875 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) {
1842 int page_index = -1; 1876 int page_index = -1;
1843 int char_index = -1; 1877 int char_index = -1;
(...skipping 11 matching lines...) Expand all
1855 PP_CursorType_Dev cursor; 1889 PP_CursorType_Dev cursor;
1856 switch (area) { 1890 switch (area) {
1857 case PDFiumPage::TEXT_AREA: 1891 case PDFiumPage::TEXT_AREA:
1858 cursor = PP_CURSORTYPE_IBEAM; 1892 cursor = PP_CURSORTYPE_IBEAM;
1859 break; 1893 break;
1860 case PDFiumPage::WEBLINK_AREA: 1894 case PDFiumPage::WEBLINK_AREA:
1861 case PDFiumPage::DOCLINK_AREA: 1895 case PDFiumPage::DOCLINK_AREA:
1862 cursor = PP_CURSORTYPE_HAND; 1896 cursor = PP_CURSORTYPE_HAND;
1863 break; 1897 break;
1864 case PDFiumPage::NONSELECTABLE_AREA: 1898 case PDFiumPage::NONSELECTABLE_AREA:
1899 case PDFiumPage::FORM_TEXT_AREA:
1865 default: 1900 default:
1866 switch (form_type) { 1901 switch (form_type) {
1867 case FPDF_FORMFIELD_PUSHBUTTON: 1902 case FPDF_FORMFIELD_PUSHBUTTON:
1868 case FPDF_FORMFIELD_CHECKBOX: 1903 case FPDF_FORMFIELD_CHECKBOX:
1869 case FPDF_FORMFIELD_RADIOBUTTON: 1904 case FPDF_FORMFIELD_RADIOBUTTON:
1870 case FPDF_FORMFIELD_COMBOBOX: 1905 case FPDF_FORMFIELD_COMBOBOX:
1871 case FPDF_FORMFIELD_LISTBOX: 1906 case FPDF_FORMFIELD_LISTBOX:
1872 cursor = PP_CURSORTYPE_HAND; 1907 cursor = PP_CURSORTYPE_HAND;
1873 break; 1908 break;
1874 case FPDF_FORMFIELD_TEXTFIELD: 1909 case FPDF_FORMFIELD_TEXTFIELD:
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev ision=31805 2016 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev ision=31805
1982 // for more information. So just fake one since PDFium uses it. 2017 // for more information. So just fake one since PDFium uses it.
1983 std::string str; 2018 std::string str;
1984 str.push_back(event.GetKeyCode()); 2019 str.push_back(event.GetKeyCode());
1985 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent( 2020 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent(
1986 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR, 2021 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR,
1987 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str)); 2022 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str));
1988 OnChar(synthesized); 2023 OnChar(synthesized);
1989 } 2024 }
1990 2025
2026 // If form selected text is empty and key pressed within form text area,
2027 // plugin text selection should be cleared.
2028 if (in_form_text_area_ &&
2029 FORM_GetSelectedText(form_, pages_[last_page_mouse_down_]->GetPage(),
2030 nullptr, 0) <= 2)
Lei Zhang 2017/06/23 19:41:23 style: Should add braces.
drgage 2017/06/23 22:16:13 Done.
2031 pp::PDF::SetSelectedText(GetPluginInstance(), "");
2032
1991 return rv; 2033 return rv;
1992 } 2034 }
1993 2035
1994 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { 2036 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) {
1995 if (last_page_mouse_down_ == -1) 2037 if (last_page_mouse_down_ == -1)
1996 return false; 2038 return false;
1997 2039
2040 if (in_form_text_area_) {
2041 if (event.GetKeyCode() == ui::VKEY_SHIFT)
2042 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage());
2043 }
2044
1998 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), 2045 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(),
1999 event.GetKeyCode(), event.GetModifiers()); 2046 event.GetKeyCode(), event.GetModifiers());
2000 } 2047 }
2001 2048
2002 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { 2049 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) {
2003 if (last_page_mouse_down_ == -1) 2050 if (last_page_mouse_down_ == -1)
2004 return false; 2051 return false;
2005 2052
2006 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); 2053 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString());
2007 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], 2054 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0],
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
3549 client_->ScrollToPage(most_visible_page); 3596 client_->ScrollToPage(most_visible_page);
3550 } 3597 }
3551 3598
3552 void PDFiumEngine::SetSelecting(bool selecting) { 3599 void PDFiumEngine::SetSelecting(bool selecting) {
3553 bool was_selecting = selecting_; 3600 bool was_selecting = selecting_;
3554 selecting_ = selecting; 3601 selecting_ = selecting;
3555 if (selecting_ != was_selecting) 3602 if (selecting_ != was_selecting)
3556 client_->IsSelectingChanged(selecting); 3603 client_->IsSelectingChanged(selecting);
3557 } 3604 }
3558 3605
3606 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
3607 in_form_text_area_ = in_form_text_area;
3608 }
3609
3559 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { 3610 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
3560 touch_timers_[++next_touch_timer_id_] = evt; 3611 touch_timers_[++next_touch_timer_id_] = evt;
3561 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, 3612 client_->ScheduleTouchTimerCallback(next_touch_timer_id_,
3562 kTouchLongPressTimeoutMs); 3613 kTouchLongPressTimeoutMs);
3563 } 3614 }
3564 3615
3565 void PDFiumEngine::KillTouchTimer(int timer_id) { 3616 void PDFiumEngine::KillTouchTimer(int timer_id) {
3566 touch_timers_.erase(timer_id); 3617 touch_timers_.erase(timer_id);
3567 } 3618 }
3568 3619
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
4138 FPDF_DOCUMENT doc = 4189 FPDF_DOCUMENT doc =
4139 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 4190 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
4140 if (!doc) 4191 if (!doc)
4141 return false; 4192 return false;
4142 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4193 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4143 FPDF_CloseDocument(doc); 4194 FPDF_CloseDocument(doc);
4144 return success; 4195 return success;
4145 } 4196 }
4146 4197
4147 } // namespace chrome_pdf 4198 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698