Chromium Code Reviews| 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 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1631 } | 1631 } |
| 1632 | 1632 |
| 1633 void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle, | 1633 void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle, |
| 1634 FPDF_PAGE page) { | 1634 FPDF_PAGE page) { |
| 1635 unsigned long form_sel_text_len = | 1635 unsigned long form_sel_text_len = |
| 1636 FORM_GetSelectedText(form_handle, page, nullptr, 0); | 1636 FORM_GetSelectedText(form_handle, page, nullptr, 0); |
| 1637 | 1637 |
| 1638 // Check to see if there is selected text in the form. When | 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 | 1639 // |form_sel_text_len| is 2, that represents a wide string with just a |
| 1640 // NUL-terminator. | 1640 // NUL-terminator. |
| 1641 if (form_sel_text_len <= 2) | 1641 if (form_sel_text_len <= 2 && selected_form_text_.empty()) |
| 1642 return; | 1642 return; |
| 1643 | 1643 |
| 1644 base::string16 selected_form_text16; | 1644 base::string16 selected_form_text16; |
| 1645 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( | 1645 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( |
| 1646 &selected_form_text16, form_sel_text_len, false); | 1646 &selected_form_text16, form_sel_text_len, false); |
| 1647 string_adapter.Close(FORM_GetSelectedText( | 1647 string_adapter.Close(FORM_GetSelectedText( |
| 1648 form_handle, page, string_adapter.GetData(), form_sel_text_len)); | 1648 form_handle, page, string_adapter.GetData(), form_sel_text_len)); |
| 1649 | 1649 |
| 1650 std::string selected_form_text = base::UTF16ToUTF8(selected_form_text16); | 1650 // Update previous and current selections, then compare them to check if |
| 1651 if (!selected_form_text.empty()) { | 1651 // selection has changed. If so, set plugin text selection. |
| 1652 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); | 1652 std::string selected_form_text = selected_form_text_; |
| 1653 } | 1653 selected_form_text_ = base::UTF16ToUTF8(selected_form_text16); |
| 1654 if (selected_form_text != selected_form_text_) | |
| 1655 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text_.c_str()); | |
| 1654 } | 1656 } |
| 1655 | 1657 |
| 1656 void PDFiumEngine::PrintEnd() { | 1658 void PDFiumEngine::PrintEnd() { |
| 1657 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1659 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
| 1658 } | 1660 } |
| 1659 | 1661 |
| 1660 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, | 1662 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, |
| 1661 int* page_index, | 1663 int* page_index, |
| 1662 int* char_index, | 1664 int* char_index, |
| 1663 int* form_type, | 1665 int* form_type, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1722 SelectionChangeInvalidator selection_invalidator(this); | 1724 SelectionChangeInvalidator selection_invalidator(this); |
| 1723 selection_.clear(); | 1725 selection_.clear(); |
| 1724 | 1726 |
| 1725 int page_index = -1; | 1727 int page_index = -1; |
| 1726 int char_index = -1; | 1728 int char_index = -1; |
| 1727 int form_type = FPDF_FORMFIELD_UNKNOWN; | 1729 int form_type = FPDF_FORMFIELD_UNKNOWN; |
| 1728 PDFiumPage::LinkTarget target; | 1730 PDFiumPage::LinkTarget target; |
| 1729 PDFiumPage::Area area = | 1731 PDFiumPage::Area area = |
| 1730 GetCharIndex(event, &page_index, &char_index, &form_type, &target); | 1732 GetCharIndex(event, &page_index, &char_index, &form_type, &target); |
| 1731 mouse_down_state_.Set(area, target); | 1733 mouse_down_state_.Set(area, target); |
| 1734 SetMouseHeldDown(true); | |
|
Lei Zhang
2017/06/30 21:39:36
If SetMouseHeldDown() is really SetMouseLeftButton
drgage
2017/06/30 23:37:32
Done.
| |
| 1732 | 1735 |
| 1733 // Decide whether to open link or not based on user action in mouse up and | 1736 // Decide whether to open link or not based on user action in mouse up and |
| 1734 // mouse move events. | 1737 // mouse move events. |
| 1735 if (area == PDFiumPage::WEBLINK_AREA || area == PDFiumPage::DOCLINK_AREA) | 1738 if (area == PDFiumPage::WEBLINK_AREA || area == PDFiumPage::DOCLINK_AREA) |
| 1736 return true; | 1739 return true; |
| 1737 | 1740 |
| 1738 // Prevent middle mouse button from selecting texts. | 1741 // Prevent middle mouse button from selecting texts. |
| 1739 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1742 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
| 1740 return false; | 1743 return false; |
| 1741 | 1744 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1813 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { | 1816 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { |
| 1814 return false; | 1817 return false; |
| 1815 } | 1818 } |
| 1816 | 1819 |
| 1817 int page_index = -1; | 1820 int page_index = -1; |
| 1818 int char_index = -1; | 1821 int char_index = -1; |
| 1819 int form_type = FPDF_FORMFIELD_UNKNOWN; | 1822 int form_type = FPDF_FORMFIELD_UNKNOWN; |
| 1820 PDFiumPage::LinkTarget target; | 1823 PDFiumPage::LinkTarget target; |
| 1821 PDFiumPage::Area area = | 1824 PDFiumPage::Area area = |
| 1822 GetCharIndex(event, &page_index, &char_index, &form_type, &target); | 1825 GetCharIndex(event, &page_index, &char_index, &form_type, &target); |
| 1826 SetMouseHeldDown(false); | |
| 1823 | 1827 |
| 1824 // Open link on mouse up for same link for which mouse down happened earlier. | 1828 // Open link on mouse up for same link for which mouse down happened earlier. |
| 1825 if (mouse_down_state_.Matches(area, target)) { | 1829 if (mouse_down_state_.Matches(area, target)) { |
| 1826 if (area == PDFiumPage::WEBLINK_AREA) { | 1830 if (area == PDFiumPage::WEBLINK_AREA) { |
| 1827 uint32_t modifiers = event.GetModifiers(); | 1831 uint32_t modifiers = event.GetModifiers(); |
| 1828 bool middle_button = | 1832 bool middle_button = |
| 1829 !!(modifiers & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN); | 1833 !!(modifiers & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN); |
| 1830 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1834 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
| 1831 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1835 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
| 1832 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1836 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1850 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1854 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
| 1851 return false; | 1855 return false; |
| 1852 | 1856 |
| 1853 if (page_index != -1) { | 1857 if (page_index != -1) { |
| 1854 double page_x, page_y; | 1858 double page_x, page_y; |
| 1855 pp::Point point = event.GetPosition(); | 1859 pp::Point point = event.GetPosition(); |
| 1856 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1860 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| 1857 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1861 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| 1858 } | 1862 } |
| 1859 | 1863 |
| 1860 if (area == PDFiumPage::FORM_TEXT_AREA && last_page_mouse_down_ != -1) | |
| 1861 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
| 1862 | |
| 1863 if (!selecting_) | 1864 if (!selecting_) |
| 1864 return false; | 1865 return false; |
| 1865 | 1866 |
| 1866 SetSelecting(false); | 1867 SetSelecting(false); |
| 1867 return true; | 1868 return true; |
| 1868 } | 1869 } |
| 1869 | 1870 |
| 1870 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1871 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
| 1871 int page_index = -1; | 1872 int page_index = -1; |
| 1872 int char_index = -1; | 1873 int char_index = -1; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1917 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1918 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| 1918 FORM_OnMouseMove(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1919 FORM_OnMouseMove(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| 1919 } | 1920 } |
| 1920 | 1921 |
| 1921 client_->UpdateCursor(cursor); | 1922 client_->UpdateCursor(cursor); |
| 1922 std::string url = GetLinkAtPosition(event.GetPosition()); | 1923 std::string url = GetLinkAtPosition(event.GetPosition()); |
| 1923 if (url != link_under_cursor_) { | 1924 if (url != link_under_cursor_) { |
| 1924 link_under_cursor_ = url; | 1925 link_under_cursor_ = url; |
| 1925 pp::PDF::SetLinkUnderCursor(GetPluginInstance(), url.c_str()); | 1926 pp::PDF::SetLinkUnderCursor(GetPluginInstance(), url.c_str()); |
| 1926 } | 1927 } |
| 1928 | |
| 1929 // If in form text area while left mouse button is held down, check if form | |
| 1930 // text selection needs to be updated. | |
| 1931 if (mouse_held_down_ && area == PDFiumPage::FORM_TEXT_AREA && | |
| 1932 last_page_mouse_down_ != -1) { | |
| 1933 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
| 1934 } | |
| 1935 | |
| 1927 // No need to swallow the event, since this might interfere with the | 1936 // No need to swallow the event, since this might interfere with the |
| 1928 // scrollbars if the user is dragging them. | 1937 // scrollbars if the user is dragging them. |
| 1929 return false; | 1938 return false; |
| 1930 } | 1939 } |
| 1931 | 1940 |
| 1932 // We're selecting but right now we're not over text, so don't change the | 1941 // We're selecting but right now we're not over text, so don't change the |
| 1933 // current selection. | 1942 // current selection. |
| 1934 if (area != PDFiumPage::TEXT_AREA && area != PDFiumPage::WEBLINK_AREA && | 1943 if (area != PDFiumPage::TEXT_AREA && area != PDFiumPage::WEBLINK_AREA && |
| 1935 area != PDFiumPage::DOCLINK_AREA) { | 1944 area != PDFiumPage::DOCLINK_AREA) { |
| 1936 return false; | 1945 return false; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2011 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev ision=31805 | 2020 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev ision=31805 |
| 2012 // for more information. So just fake one since PDFium uses it. | 2021 // for more information. So just fake one since PDFium uses it. |
| 2013 std::string str; | 2022 std::string str; |
| 2014 str.push_back(event.GetKeyCode()); | 2023 str.push_back(event.GetKeyCode()); |
| 2015 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent( | 2024 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent( |
| 2016 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR, | 2025 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR, |
| 2017 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str)); | 2026 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str)); |
| 2018 OnChar(synthesized); | 2027 OnChar(synthesized); |
| 2019 } | 2028 } |
| 2020 | 2029 |
| 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 | |
| 2029 return rv; | 2030 return rv; |
| 2030 } | 2031 } |
| 2031 | 2032 |
| 2032 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 2033 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
| 2033 if (last_page_mouse_down_ == -1) | 2034 if (last_page_mouse_down_ == -1) |
| 2034 return false; | 2035 return false; |
| 2035 | 2036 |
| 2037 // Check if form text selection needs to be updated. | |
| 2036 if (in_form_text_area_) { | 2038 if (in_form_text_area_) { |
| 2037 if (event.GetKeyCode() == ui::VKEY_SHIFT) | 2039 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
| 2038 SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); | |
| 2039 } | 2040 } |
| 2040 | 2041 |
| 2041 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), | 2042 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
| 2042 event.GetKeyCode(), event.GetModifiers()); | 2043 event.GetKeyCode(), event.GetModifiers()); |
| 2043 } | 2044 } |
| 2044 | 2045 |
| 2045 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2046 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
| 2046 if (last_page_mouse_down_ == -1) | 2047 if (last_page_mouse_down_ == -1) |
| 2047 return false; | 2048 return false; |
| 2048 | 2049 |
| (...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3609 selecting_ = selecting; | 3610 selecting_ = selecting; |
| 3610 if (selecting_ != was_selecting) | 3611 if (selecting_ != was_selecting) |
| 3611 client_->IsSelectingChanged(selecting); | 3612 client_->IsSelectingChanged(selecting); |
| 3612 } | 3613 } |
| 3613 | 3614 |
| 3614 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) { | 3615 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) { |
| 3615 client_->FormTextFieldFocusChange(in_form_text_area); | 3616 client_->FormTextFieldFocusChange(in_form_text_area); |
| 3616 in_form_text_area_ = in_form_text_area; | 3617 in_form_text_area_ = in_form_text_area; |
| 3617 } | 3618 } |
| 3618 | 3619 |
| 3620 void PDFiumEngine::SetMouseHeldDown(bool mouse_held_down) { | |
| 3621 mouse_held_down_ = mouse_held_down; | |
| 3622 } | |
| 3623 | |
| 3619 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3624 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
| 3620 touch_timers_[++next_touch_timer_id_] = evt; | 3625 touch_timers_[++next_touch_timer_id_] = evt; |
| 3621 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3626 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
| 3622 kTouchLongPressTimeoutMs); | 3627 kTouchLongPressTimeoutMs); |
| 3623 } | 3628 } |
| 3624 | 3629 |
| 3625 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3630 void PDFiumEngine::KillTouchTimer(int timer_id) { |
| 3626 touch_timers_.erase(timer_id); | 3631 touch_timers_.erase(timer_id); |
| 3627 } | 3632 } |
| 3628 | 3633 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4198 FPDF_DOCUMENT doc = | 4203 FPDF_DOCUMENT doc = |
| 4199 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4204 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4200 if (!doc) | 4205 if (!doc) |
| 4201 return false; | 4206 return false; |
| 4202 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4207 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4203 FPDF_CloseDocument(doc); | 4208 FPDF_CloseDocument(doc); |
| 4204 return success; | 4209 return success; |
| 4205 } | 4210 } |
| 4206 | 4211 |
| 4207 } // namespace chrome_pdf | 4212 } // namespace chrome_pdf |
| OLD | NEW |