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

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

Powered by Google App Engine
This is Rietveld 408576698