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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2963403002: Fix another discrepancy in text selection between PDF and HTML forms. (Closed)
Patch Set: Change how text selection and form text selection is cleared Created 3 years, 5 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 | « no previous file | no next file » | 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 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 base::string16 selected_form_text16; 1646 base::string16 selected_form_text16;
1647 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( 1647 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter(
1648 &selected_form_text16, form_sel_text_len, false); 1648 &selected_form_text16, form_sel_text_len, false);
1649 string_adapter.Close(FORM_GetSelectedText( 1649 string_adapter.Close(FORM_GetSelectedText(
1650 form_handle, page, string_adapter.GetData(), form_sel_text_len)); 1650 form_handle, page, string_adapter.GetData(), form_sel_text_len));
1651 1651
1652 // Update previous and current selections, then compare them to check if 1652 // Update previous and current selections, then compare them to check if
1653 // selection has changed. If so, set plugin text selection. 1653 // selection has changed. If so, set plugin text selection.
1654 std::string selected_form_text = selected_form_text_; 1654 std::string selected_form_text = selected_form_text_;
1655 selected_form_text_ = base::UTF16ToUTF8(selected_form_text16); 1655 selected_form_text_ = base::UTF16ToUTF8(selected_form_text16);
1656 if (selected_form_text != selected_form_text_) 1656 if (selected_form_text != selected_form_text_) {
1657 DCHECK(in_form_text_area_);
1657 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text_.c_str()); 1658 pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text_.c_str());
1659 }
1658 } 1660 }
1659 1661
1660 void PDFiumEngine::PrintEnd() { 1662 void PDFiumEngine::PrintEnd() {
1661 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); 1663 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP);
1662 } 1664 }
1663 1665
1664 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event, 1666 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::MouseInputEvent& event,
1665 int* page_index, 1667 int* page_index,
1666 int* char_index, 1668 int* char_index,
1667 int* form_type, 1669 int* form_type,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 return true; 1720 return true;
1719 } 1721 }
1720 1722
1721 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT && 1723 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1722 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { 1724 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1723 return false; 1725 return false;
1724 } 1726 }
1725 1727
1726 SetMouseLeftButtonDown(event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT); 1728 SetMouseLeftButtonDown(event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT);
1727 1729
1728 SelectionChangeInvalidator selection_invalidator(this); 1730 std::unique_ptr<chrome_pdf::PDFiumEngine::SelectionChangeInvalidator>
Lei Zhang 2017/07/10 23:08:20 Since the return value from base::MakeUnique() (wh
drgage 2017/07/11 17:25:36 Done.
1731 selection_invalidator =
1732 base::MakeUnique<SelectionChangeInvalidator>(this);
1729 selection_.clear(); 1733 selection_.clear();
1730 1734
1731 int page_index = -1; 1735 int page_index = -1;
1732 int char_index = -1; 1736 int char_index = -1;
1733 int form_type = FPDF_FORMFIELD_UNKNOWN; 1737 int form_type = FPDF_FORMFIELD_UNKNOWN;
1734 PDFiumPage::LinkTarget target; 1738 PDFiumPage::LinkTarget target;
1735 PDFiumPage::Area area = 1739 PDFiumPage::Area area =
1736 GetCharIndex(event, &page_index, &char_index, &form_type, &target); 1740 GetCharIndex(event, &page_index, &char_index, &form_type, &target);
1737 mouse_down_state_.Set(area, target); 1741 mouse_down_state_.Set(area, target);
1738 1742
1739 // Decide whether to open link or not based on user action in mouse up and 1743 // Decide whether to open link or not based on user action in mouse up and
1740 // mouse move events. 1744 // mouse move events.
1741 if (area == PDFiumPage::WEBLINK_AREA || area == PDFiumPage::DOCLINK_AREA) 1745 if (area == PDFiumPage::WEBLINK_AREA || area == PDFiumPage::DOCLINK_AREA)
1742 return true; 1746 return true;
1743 1747
1744 // Prevent middle mouse button from selecting texts. 1748 // Prevent middle mouse button from selecting texts.
1745 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) 1749 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
1746 return false; 1750 return false;
1747 1751
1748 if (page_index != -1) { 1752 if (page_index != -1) {
1749 last_page_mouse_down_ = page_index; 1753 last_page_mouse_down_ = page_index;
1750 double page_x, page_y; 1754 double page_x, page_y;
1751 pp::Point point = event.GetPosition(); 1755 pp::Point point = event.GetPosition();
1752 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1756 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1753 1757
1754 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1758 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1755 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... 1759 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes...
1756 mouse_down_state_.Set(PDFiumPage::FormTypeToArea(form_type), target); 1760 mouse_down_state_.Set(PDFiumPage::FormTypeToArea(form_type), target);
1761 selection_invalidator.reset();
Lei Zhang 2017/07/10 23:08:21 Can you add a comment to explain why this has to b
drgage 2017/07/11 17:25:36 Done.
1757 1762
1758 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || 1763 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD ||
1759 form_type == FPDF_FORMFIELD_COMBOBOX); 1764 form_type == FPDF_FORMFIELD_COMBOBOX);
1760 1765
1761 // TODO(bug_62400): figure out selection and copying 1766 // TODO(bug_62400): figure out selection and copying
1762 // for XFA fields 1767 // for XFA fields
1763 #if defined(PDF_ENABLE_XFA) 1768 #if defined(PDF_ENABLE_XFA)
1764 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); 1769 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA);
1765 #endif 1770 #endif
1766 SetInFormTextArea(is_valid_control); 1771 SetInFormTextArea(is_valid_control);
(...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after
3576 *region = nullptr; 3581 *region = nullptr;
3577 return; 3582 return;
3578 } 3583 }
3579 3584
3580 buffer += location.y() * (*stride); 3585 buffer += location.y() * (*stride);
3581 buffer += (location.x() + page_offset_.x()) * 4; 3586 buffer += (location.x() + page_offset_.x()) * 4;
3582 *region = buffer; 3587 *region = buffer;
3583 } 3588 }
3584 3589
3585 void PDFiumEngine::OnSelectionChanged() { 3590 void PDFiumEngine::OnSelectionChanged() {
3591 DCHECK(!in_form_text_area_);
3586 pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str()); 3592 pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str());
3587 } 3593 }
3588 3594
3589 void PDFiumEngine::RotateInternal() { 3595 void PDFiumEngine::RotateInternal() {
3590 // Store the current find index so that we can resume finding at that 3596 // Store the current find index so that we can resume finding at that
3591 // particular index after we have recomputed the find results. 3597 // particular index after we have recomputed the find results.
3592 std::string current_find_text = current_find_text_; 3598 std::string current_find_text = current_find_text_;
3593 if (current_find_index_.valid()) 3599 if (current_find_index_.valid())
3594 resume_find_index_.SetIndex(current_find_index_.GetIndex()); 3600 resume_find_index_.SetIndex(current_find_index_.GetIndex());
3595 else 3601 else
(...skipping 18 matching lines...) Expand all
3614 } 3620 }
3615 3621
3616 void PDFiumEngine::SetSelecting(bool selecting) { 3622 void PDFiumEngine::SetSelecting(bool selecting) {
3617 bool was_selecting = selecting_; 3623 bool was_selecting = selecting_;
3618 selecting_ = selecting; 3624 selecting_ = selecting;
3619 if (selecting_ != was_selecting) 3625 if (selecting_ != was_selecting)
3620 client_->IsSelectingChanged(selecting); 3626 client_->IsSelectingChanged(selecting);
3621 } 3627 }
3622 3628
3623 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) { 3629 void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
3630 // If focus previously in form text area, clear form text selection.
Lei Zhang 2017/07/10 23:08:20 // If focus was previously in the form text area,
drgage 2017/07/11 17:25:37 Otherwise, nothing is cleared; the focus is change
Lei Zhang 2017/07/11 20:37:38 Otherwise, nothing is cleared and if |in_form_text
3631 if (in_form_text_area_)
3632 pp::PDF::SetSelectedText(GetPluginInstance(), "");
3633
3624 client_->FormTextFieldFocusChange(in_form_text_area); 3634 client_->FormTextFieldFocusChange(in_form_text_area);
3625 in_form_text_area_ = in_form_text_area; 3635 in_form_text_area_ = in_form_text_area;
3626 } 3636 }
3627 3637
3628 void PDFiumEngine::SetMouseLeftButtonDown(bool is_mouse_left_button_down) { 3638 void PDFiumEngine::SetMouseLeftButtonDown(bool is_mouse_left_button_down) {
3629 mouse_left_button_down_ = is_mouse_left_button_down; 3639 mouse_left_button_down_ = is_mouse_left_button_down;
3630 } 3640 }
3631 3641
3632 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { 3642 void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
3633 touch_timers_[++next_touch_timer_id_] = evt; 3643 touch_timers_[++next_touch_timer_id_] = evt;
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
4211 FPDF_DOCUMENT doc = 4221 FPDF_DOCUMENT doc =
4212 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 4222 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
4213 if (!doc) 4223 if (!doc)
4214 return false; 4224 return false;
4215 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4225 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4216 FPDF_CloseDocument(doc); 4226 FPDF_CloseDocument(doc);
4217 return success; 4227 return success;
4218 } 4228 }
4219 4229
4220 } // namespace chrome_pdf 4230 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698