Index: pdf/pdfium/pdfium_engine.cc |
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
index c4f8d644a2b2e7a3ad23f0922ed76ad8bced8231..48f6fd592475d0b6d9bc62d1a616391403747d86 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. |
Lei Zhang
2017/07/05 19:31:12
Update the comment, now that the if-statement has
drgage
2017/07/06 19:13:55
Done.
|
- 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() { |
@@ -1719,6 +1721,8 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
return false; |
} |
+ SetMouseLeftButtonDown(event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT); |
+ |
SelectionChangeInvalidator selection_invalidator(this); |
selection_.clear(); |
@@ -1814,6 +1818,9 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { |
return false; |
} |
+ if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) |
+ SetMouseLeftButtonDown(false); |
+ |
int page_index = -1; |
int char_index = -1; |
int form_type = FPDF_FORMFIELD_UNKNOWN; |
@@ -1857,9 +1864,6 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { |
FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
} |
- 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 +1928,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 +2030,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 +2037,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 +3620,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_, |