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 | |
1634 if (form_sel_text_len) { | |
Lei Zhang
2017/06/10 01:55:49
Invert + early return.
drgage
2017/06/12 18:57:47
Done.
| |
1635 base::string16 selected_form_text; | |
Lei Zhang
2017/06/10 01:55:49
How about calling the std::string version selected
drgage
2017/06/12 18:57:47
Done.
| |
1636 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( | |
1637 &selected_form_text, form_sel_text_len, false); | |
1638 string_adapter.Close(FORM_GetSelectedText( | |
1639 hHandle, page, string_adapter.GetData(), form_sel_text_len)); | |
1640 | |
1641 std::string str_selected_form_text = UTF16ToUTF8(selected_form_text); | |
1642 if (str_selected_form_text.c_str() && str_selected_form_text != "") { | |
Lei Zhang
2017/06/10 01:55:49
I think you just want to check: !str_selected_form
drgage
2017/06/12 18:57:47
Done.
| |
1643 pp::PDF::SetSelectedText(GetPluginInstance(), | |
1644 str_selected_form_text.c_str()); | |
1645 } | |
1646 } | |
1627 } | 1647 } |
1628 | 1648 |
1629 void PDFiumEngine::PrintEnd() { | 1649 void PDFiumEngine::PrintEnd() { |
1630 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1650 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
1631 } | 1651 } |
1632 | 1652 |
1633 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, | 1653 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, |
1634 int* page_index, | 1654 int* page_index, |
1635 int* char_index, | 1655 int* char_index, |
1636 int* form_type, | 1656 int* form_type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1713 return false; | 1733 return false; |
1714 | 1734 |
1715 if (page_index != -1) { | 1735 if (page_index != -1) { |
1716 last_page_mouse_down_ = page_index; | 1736 last_page_mouse_down_ = page_index; |
1717 double page_x, page_y; | 1737 double page_x, page_y; |
1718 pp::Point point = event.GetPosition(); | 1738 pp::Point point = event.GetPosition(); |
1719 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1739 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1720 | 1740 |
1721 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1741 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1722 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1742 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
1723 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | 1743 mouse_down_state_.Set(PDFiumPage::FORM_TEXT_AREA, target); |
1724 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || | 1744 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
1725 form_type == FPDF_FORMFIELD_COMBOBOX); | 1745 form_type == FPDF_FORMFIELD_COMBOBOX); |
1726 #if defined(PDF_ENABLE_XFA) | 1746 #if defined(PDF_ENABLE_XFA) |
1727 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); | 1747 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
1728 #endif | 1748 #endif |
1729 client_->FormTextFieldFocusChange(is_valid_control); | 1749 client_->FormTextFieldFocusChange(is_valid_control); |
1750 SetInFormTextField(is_valid_control); | |
Lei Zhang
2017/06/10 01:55:49
Isn't this also going to be true for a combo box?
drgage
2017/06/12 18:57:47
Yeah, you're right. Do you think I should change h
| |
1730 return true; // Return now before we get into the selection code. | 1751 return true; // Return now before we get into the selection code. |
1731 } | 1752 } |
1732 } | 1753 } |
1733 | 1754 |
1734 client_->FormTextFieldFocusChange(false); | 1755 client_->FormTextFieldFocusChange(false); |
1756 SetInFormTextField(false); | |
1735 | 1757 |
1736 if (area != PDFiumPage::TEXT_AREA) | 1758 if (area != PDFiumPage::TEXT_AREA) |
1737 return true; // Return true so WebKit doesn't do its own highlighting. | 1759 return true; // Return true so WebKit doesn't do its own highlighting. |
1738 | 1760 |
1739 if (event.GetClickCount() == 1) { | 1761 if (event.GetClickCount() == 1) { |
1740 OnSingleClick(page_index, char_index); | 1762 OnSingleClick(page_index, char_index); |
1741 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { | 1763 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { |
1742 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1764 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
1743 } | 1765 } |
1744 | 1766 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1822 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
1801 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1823 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
1802 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1824 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
1803 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | 1825 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); |
1804 | 1826 |
1805 WindowOpenDisposition disposition = ui::DispositionFromClick( | 1827 WindowOpenDisposition disposition = ui::DispositionFromClick( |
1806 middle_button, alt_key, ctrl_key, meta_key, shift_key); | 1828 middle_button, alt_key, ctrl_key, meta_key, shift_key); |
1807 | 1829 |
1808 client_->NavigateTo(target.url, disposition); | 1830 client_->NavigateTo(target.url, disposition); |
1809 client_->FormTextFieldFocusChange(false); | 1831 client_->FormTextFieldFocusChange(false); |
1832 SetInFormTextField(false); | |
1810 return true; | 1833 return true; |
1811 } | 1834 } |
1812 if (area == PDFiumPage::DOCLINK_AREA) { | 1835 if (area == PDFiumPage::DOCLINK_AREA) { |
1813 client_->ScrollToPage(target.page); | 1836 client_->ScrollToPage(target.page); |
1814 client_->FormTextFieldFocusChange(false); | 1837 client_->FormTextFieldFocusChange(false); |
1838 SetInFormTextField(false); | |
1815 return true; | 1839 return true; |
1816 } | 1840 } |
1817 } | 1841 } |
1818 | 1842 |
1819 // Prevent middle mouse button from selecting texts. | 1843 // Prevent middle mouse button from selecting texts. |
1820 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1844 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
1821 return false; | 1845 return false; |
1822 | 1846 |
1823 if (page_index != -1) { | 1847 if (page_index != -1) { |
1824 double page_x, page_y; | 1848 double page_x, page_y; |
1825 pp::Point point = event.GetPosition(); | 1849 pp::Point point = event.GetPosition(); |
1826 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1850 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1827 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1851 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1828 } | 1852 } |
1829 | 1853 |
1854 if (area == PDFiumPage::FORM_TEXT_AREA) { | |
1855 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
1856 } | |
1857 | |
1830 if (!selecting_) | 1858 if (!selecting_) |
1831 return false; | 1859 return false; |
1832 | 1860 |
1833 SetSelecting(false); | 1861 SetSelecting(false); |
1834 return true; | 1862 return true; |
1835 } | 1863 } |
1836 | 1864 |
1837 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1865 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
1838 int page_index = -1; | 1866 int page_index = -1; |
1839 int char_index = -1; | 1867 int char_index = -1; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1984 OnChar(synthesized); | 2012 OnChar(synthesized); |
1985 } | 2013 } |
1986 | 2014 |
1987 return rv; | 2015 return rv; |
1988 } | 2016 } |
1989 | 2017 |
1990 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 2018 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
1991 if (last_page_mouse_down_ == -1) | 2019 if (last_page_mouse_down_ == -1) |
1992 return false; | 2020 return false; |
1993 | 2021 |
2022 uint32_t modifiers = event.GetModifiers(); | |
2023 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | |
2024 | |
2025 if (in_form_text_field_ && shift_key) { | |
Lei Zhang
2017/06/10 01:55:49
If |in_form_text_field_| is false, then it is not
drgage
2017/06/12 18:57:47
Done.
| |
2026 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
2027 } | |
2028 | |
1994 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), | 2029 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
1995 event.GetKeyCode(), event.GetModifiers()); | 2030 event.GetKeyCode(), event.GetModifiers()); |
1996 } | 2031 } |
1997 | 2032 |
1998 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2033 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
1999 if (last_page_mouse_down_ == -1) | 2034 if (last_page_mouse_down_ == -1) |
2000 return false; | 2035 return false; |
2001 | 2036 |
2002 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 2037 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
2003 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], | 2038 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); | 3580 client_->ScrollToPage(most_visible_page); |
3546 } | 3581 } |
3547 | 3582 |
3548 void PDFiumEngine::SetSelecting(bool selecting) { | 3583 void PDFiumEngine::SetSelecting(bool selecting) { |
3549 bool was_selecting = selecting_; | 3584 bool was_selecting = selecting_; |
3550 selecting_ = selecting; | 3585 selecting_ = selecting; |
3551 if (selecting_ != was_selecting) | 3586 if (selecting_ != was_selecting) |
3552 client_->IsSelectingChanged(selecting); | 3587 client_->IsSelectingChanged(selecting); |
3553 } | 3588 } |
3554 | 3589 |
3590 void PDFiumEngine::SetInFormTextField(bool in_form_text_field) { | |
3591 in_form_text_field_ = in_form_text_field; | |
3592 } | |
3593 | |
3555 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3594 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
3556 touch_timers_[++next_touch_timer_id_] = evt; | 3595 touch_timers_[++next_touch_timer_id_] = evt; |
3557 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3596 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
3558 kTouchLongPressTimeoutMs); | 3597 kTouchLongPressTimeoutMs); |
3559 } | 3598 } |
3560 | 3599 |
3561 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3600 void PDFiumEngine::KillTouchTimer(int timer_id) { |
3562 touch_timers_.erase(timer_id); | 3601 touch_timers_.erase(timer_id); |
3563 } | 3602 } |
3564 | 3603 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4134 FPDF_DOCUMENT doc = | 4173 FPDF_DOCUMENT doc = |
4135 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4174 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4136 if (!doc) | 4175 if (!doc) |
4137 return false; | 4176 return false; |
4138 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4177 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4139 FPDF_CloseDocument(doc); | 4178 FPDF_CloseDocument(doc); |
4140 return success; | 4179 return success; |
4141 } | 4180 } |
4142 | 4181 |
4143 } // namespace chrome_pdf | 4182 } // namespace chrome_pdf |
OLD | NEW |