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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 2963753003: Fix discrepancies in form text selection between PDF and HTML forms. (Closed)
Patch Set: Remove extra parentheses Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« pdf/pdfium/pdfium_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index eb7f4cb08fb315aac8cb6540a857b39c3212fd21..50926470710ee2f4977aa134f1ffaa593ad5250e 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 && old_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
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
+ // selection has changed. If so, set plugin text selection.
+ old_selected_form_text_ = selected_form_text_;
+ selected_form_text_ = base::UTF16ToUTF8(selected_form_text16);
+ if (old_selected_form_text_ != selected_form_text_)
+ pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text_.c_str());
}
void PDFiumEngine::PrintEnd() {
@@ -1729,6 +1731,7 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) {
PDFiumPage::Area area =
GetCharIndex(event, &page_index, &char_index, &form_type, &target);
mouse_down_state_.Set(area, target);
+ SetMouseHeldDown(true);
// Decide whether to open link or not based on user action in mouse up and
// mouse move events.
@@ -1820,6 +1823,7 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
PDFiumPage::LinkTarget target;
PDFiumPage::Area area =
GetCharIndex(event, &page_index, &char_index, &form_type, &target);
+ SetMouseHeldDown(false);
// Open link on mouse up for same link for which mouse down happened earlier.
if (mouse_down_state_.Matches(area, target)) {
@@ -1857,9 +1861,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)
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
- 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_held_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(),
@@ -3610,6 +3611,10 @@ void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
in_form_text_area_ = in_form_text_area;
}
+void PDFiumEngine::SetMouseHeldDown(bool mouse_held_down) {
+ mouse_held_down_ = mouse_held_down;
+}
+
void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
touch_timers_[++next_touch_timer_id_] = evt;
client_->ScheduleTouchTimerCallback(next_touch_timer_id_,
« pdf/pdfium/pdfium_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698