Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index c4f8d644a2b2e7a3ad23f0922ed76ad8bced8231..bd4f723381da87276f0dae9b23ec1a8ccdb7bde5 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -1638,7 +1638,7 @@ void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle, |
| // Check to see if there is selected text in the form. When |
| // |form_sel_text_len| is 2, that represents a wide string with just a |
| // NUL-terminator. |
| - if (form_sel_text_len <= 2) |
| + if (form_sel_text_len <= 2 && selected_form_text_.empty()) |
| return; |
| base::string16 selected_form_text16; |
| @@ -1647,10 +1647,12 @@ void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle, |
| string_adapter.Close(FORM_GetSelectedText( |
| form_handle, page, string_adapter.GetData(), form_sel_text_len)); |
| - std::string selected_form_text = base::UTF16ToUTF8(selected_form_text16); |
| - if (!selected_form_text.empty()) { |
| - pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); |
| - } |
| + // Update previous and current selections, then compare them to check if |
| + // selection has changed. If so, set plugin text selection. |
| + std::string selected_form_text = selected_form_text_; |
| + selected_form_text_ = base::UTF16ToUTF8(selected_form_text16); |
| + if (selected_form_text != selected_form_text_) |
| + pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text_.c_str()); |
| } |
| void PDFiumEngine::PrintEnd() { |
| @@ -1746,6 +1748,7 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
| DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| + SetMouseLeftButtonDown(true); |
|
Lei Zhang
2017/07/01 00:30:46
So if we move the call here, then if the user left
drgage
2017/07/05 18:29:31
Done.
|
| if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
| mouse_down_state_.Set(PDFiumPage::FormTypeToArea(form_type), target); |
| @@ -1855,11 +1858,9 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { |
| pp::Point point = event.GetPosition(); |
| DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| + SetMouseLeftButtonDown(false); |
| } |
| - if (area == PDFiumPage::FORM_TEXT_AREA && last_page_mouse_down_ != -1) |
| - SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
| - |
| if (!selecting_) |
| return false; |
| @@ -1924,6 +1925,14 @@ bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
| link_under_cursor_ = url; |
| pp::PDF::SetLinkUnderCursor(GetPluginInstance(), url.c_str()); |
| } |
| + |
| + // If in form text area while left mouse button is held down, check if form |
| + // text selection needs to be updated. |
| + if (mouse_left_button_down_ && area == PDFiumPage::FORM_TEXT_AREA && |
| + last_page_mouse_down_ != -1) { |
| + SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
| + } |
| + |
| // No need to swallow the event, since this might interfere with the |
| // scrollbars if the user is dragging them. |
| return false; |
| @@ -2018,14 +2027,6 @@ bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { |
| OnChar(synthesized); |
| } |
| - // If form selected text is empty and key pressed within form text area, |
| - // plugin text selection should be cleared. |
| - if (in_form_text_area_ && |
| - FORM_GetSelectedText(form_, pages_[last_page_mouse_down_]->GetPage(), |
| - nullptr, 0) <= 2) { |
| - pp::PDF::SetSelectedText(GetPluginInstance(), ""); |
| - } |
| - |
| return rv; |
| } |
| @@ -2033,9 +2034,9 @@ bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
| if (last_page_mouse_down_ == -1) |
| return false; |
| + // Check if form text selection needs to be updated. |
| if (in_form_text_area_) { |
| - if (event.GetKeyCode() == ui::VKEY_SHIFT) |
| - SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
| + SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
| } |
| return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
| @@ -3616,6 +3617,10 @@ void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) { |
| in_form_text_area_ = in_form_text_area; |
| } |
| +void PDFiumEngine::SetMouseLeftButtonDown(bool is_mouse_left_button_down) { |
| + mouse_left_button_down_ = is_mouse_left_button_down; |
| +} |
| + |
| void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
| touch_timers_[++next_touch_timer_id_] = evt; |
| client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |