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 && old_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 |
Lei Zhang
2017/06/29 02:52:46
If this method does not have |old_selected_form_te
drgage
2017/06/29 17:49:59
Yes, something like that would work. That's actual
| |
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 old_selected_form_text_ = selected_form_text_; |
1653 } | 1653 selected_form_text_ = base::UTF16ToUTF8(selected_form_text16); |
1654 if (old_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); | |
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) | |
Lei Zhang
2017/06/29 02:52:46
This change is a bit out of date and won't apply a
drgage
2017/06/29 17:49:58
I'm not sure what you mean. I removed this check b
Lei Zhang
2017/06/29 22:38:04
Didn't you already change this block of code to al
drgage
2017/06/29 23:00:50
Oh yeah, at the time that I started working on thi
| |
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 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3603 selecting_ = selecting; | 3604 selecting_ = selecting; |
3604 if (selecting_ != was_selecting) | 3605 if (selecting_ != was_selecting) |
3605 client_->IsSelectingChanged(selecting); | 3606 client_->IsSelectingChanged(selecting); |
3606 } | 3607 } |
3607 | 3608 |
3608 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) { | 3609 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) { |
3609 client_->FormTextFieldFocusChange(in_form_text_area); | 3610 client_->FormTextFieldFocusChange(in_form_text_area); |
3610 in_form_text_area_ = in_form_text_area; | 3611 in_form_text_area_ = in_form_text_area; |
3611 } | 3612 } |
3612 | 3613 |
3614 void PDFiumEngine::SetMouseHeldDown(bool mouse_held_down) { | |
3615 mouse_held_down_ = mouse_held_down; | |
3616 } | |
3617 | |
3613 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { | 3618 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
3614 touch_timers_[++next_touch_timer_id_] = evt; | 3619 touch_timers_[++next_touch_timer_id_] = evt; |
3615 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, | 3620 client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |
3616 kTouchLongPressTimeoutMs); | 3621 kTouchLongPressTimeoutMs); |
3617 } | 3622 } |
3618 | 3623 |
3619 void PDFiumEngine::KillTouchTimer(int timer_id) { | 3624 void PDFiumEngine::KillTouchTimer(int timer_id) { |
3620 touch_timers_.erase(timer_id); | 3625 touch_timers_.erase(timer_id); |
3621 } | 3626 } |
3622 | 3627 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4192 FPDF_DOCUMENT doc = | 4197 FPDF_DOCUMENT doc = |
4193 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4198 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4194 if (!doc) | 4199 if (!doc) |
4195 return false; | 4200 return false; |
4196 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4201 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4197 FPDF_CloseDocument(doc); | 4202 FPDF_CloseDocument(doc); |
4198 return success; | 4203 return success; |
4199 } | 4204 } |
4200 | 4205 |
4201 } // namespace chrome_pdf | 4206 } // namespace chrome_pdf |
OLD | NEW |