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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 2963403002: Fix another discrepancy in text selection between PDF and HTML forms. (Closed)
Patch Set: Make comments more informative 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | 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 f71ef7ce71f8b2ccb87dc7e2326c1967ee9fe648..37fef3068bc7739a8b2f9acd46cc8ebc2167adbb 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -1653,8 +1653,10 @@ void PDFiumEngine::SetFormSelectedText(FPDF_FORMHANDLE form_handle,
// 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_)
+ if (selected_form_text != selected_form_text_) {
+ DCHECK(in_form_text_area_);
pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text_.c_str());
+ }
}
void PDFiumEngine::PrintEnd() {
@@ -1725,7 +1727,8 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) {
SetMouseLeftButtonDown(event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT);
- SelectionChangeInvalidator selection_invalidator(this);
+ auto selection_invalidator =
+ base::MakeUnique<SelectionChangeInvalidator>(this);
selection_.clear();
int page_index = -1;
@@ -1755,6 +1758,14 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) {
if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes...
mouse_down_state_.Set(PDFiumPage::FormTypeToArea(form_type), target);
+ // Destroy SelectionChangeInvalidator object before SetInFormTextArea()
+ // changes plugin's focus to be in form text area. This way, regular text
+ // selection can be cleared when a user clicks into a form text area
+ // because the pp::PDF::SetSelectedText() call in
+ // ~SelectionChangeInvalidator() still goes to the Mimehandler
+ // (not the Renderer).
+ selection_invalidator.reset();
+
bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD ||
form_type == FPDF_FORMFIELD_COMBOBOX);
@@ -3583,6 +3594,7 @@ void PDFiumEngine::GetRegion(const pp::Point& location,
}
void PDFiumEngine::OnSelectionChanged() {
+ DCHECK(!in_form_text_area_);
pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str());
}
@@ -3621,6 +3633,13 @@ void PDFiumEngine::SetSelecting(bool selecting) {
}
void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
+ // If focus was previously in form text area, clear form text selection.
+ // Clearing needs to be done before changing focus to ensure the correct
+ // observer is notified of the change in selection. When |in_form_text_area_|
+ // is true, this is the Renderer. After it flips, the MimeHandler is notified.
+ if (in_form_text_area_)
+ pp::PDF::SetSelectedText(GetPluginInstance(), "");
+
client_->FormTextFieldFocusChange(in_form_text_area);
in_form_text_area_ = in_form_text_area;
}
« 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