Index: pdf/pdfium/pdfium_engine.cc |
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
index 37c01618778ebd942421fbab1c4c6f6b8a3affcf..2a65c283114a0aabc6c9609f881a8c157438de6d 100644 |
--- a/pdf/pdfium/pdfium_engine.cc |
+++ b/pdf/pdfium/pdfium_engine.cc |
@@ -1624,6 +1624,28 @@ void PDFiumEngine::FitContentsToPrintableAreaIfRequired( |
void PDFiumEngine::SaveSelectedFormForPrint() { |
FORM_ForceToKillFocus(form_); |
client_->FormTextFieldFocusChange(false); |
+ SetInFormTextField(false); |
+} |
+ |
+void PDFiumEngine::SetFormSelectedText(const FPDF_FORMHANDLE& hHandle, |
+ const FPDF_PAGE& page) { |
+ size_t form_sel_text_len = FORM_GetSelectedText(hHandle, page, nullptr, 0); |
+ |
+ // Initial length = 2 (not 0) because text is CFX_WideString and |
+ // sentinel char is included in count. |
+ if (form_sel_text_len <= 2) |
+ return; |
+ |
+ base::string16 selected_form_text16; |
+ PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( |
+ &selected_form_text16, form_sel_text_len, false); |
+ string_adapter.Close(FORM_GetSelectedText( |
+ hHandle, page, string_adapter.GetData(), form_sel_text_len)); |
+ |
+ std::string selected_form_text = UTF16ToUTF8(selected_form_text16); |
+ if (!selected_form_text.empty()) { |
+ pp::PDF::SetSelectedText(GetPluginInstance(), selected_form_text.c_str()); |
+ } |
} |
void PDFiumEngine::PrintEnd() { |
@@ -1720,18 +1742,28 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
- mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); |
+ (form_type == FPDF_FORMFIELD_TEXTFIELD) |
Lei Zhang
2017/06/15 18:11:28
style: With a ternary operator, write this as:
mo
drgage
2017/06/16 01:49:21
Done.
|
+ ? mouse_down_state_.Set(PDFiumPage::FORM_TEXT_AREA, target) |
+ : mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); |
+ |
bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
form_type == FPDF_FORMFIELD_COMBOBOX); |
+ |
+// TODO (bug_62400): come back to this to figure out selection and copying |
+// for XFA fields |
#if defined(PDF_ENABLE_XFA) |
is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
#endif |
+ |
+ // TODO (drgage): come back and implement copying for comboboxes |
client_->FormTextFieldFocusChange(is_valid_control); |
+ SetInFormTextField(is_valid_control); |
return true; // Return now before we get into the selection code. |
} |
} |
client_->FormTextFieldFocusChange(false); |
+ SetInFormTextField(false); |
if (area != PDFiumPage::TEXT_AREA) |
return true; // Return true so WebKit doesn't do its own highlighting. |
@@ -1807,11 +1839,13 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { |
client_->NavigateTo(target.url, disposition); |
client_->FormTextFieldFocusChange(false); |
+ SetInFormTextField(false); |
return true; |
} |
if (area == PDFiumPage::DOCLINK_AREA) { |
client_->ScrollToPage(target.page); |
client_->FormTextFieldFocusChange(false); |
+ SetInFormTextField(false); |
return true; |
} |
} |
@@ -1827,6 +1861,10 @@ 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) { |
+ SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
+ } |
+ |
if (!selecting_) |
return false; |
@@ -1991,6 +2029,12 @@ bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
if (last_page_mouse_down_ == -1) |
return false; |
+ if (in_form_text_field_) { |
+ uint32_t modifiers = event.GetModifiers(); |
+ if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) |
+ SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
+ } |
+ |
return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
event.GetKeyCode(), event.GetModifiers()); |
} |
@@ -3552,6 +3596,10 @@ void PDFiumEngine::SetSelecting(bool selecting) { |
client_->IsSelectingChanged(selecting); |
} |
+void PDFiumEngine::SetInFormTextField(bool in_form_text_field) { |
+ in_form_text_field_ = in_form_text_field; |
+} |
+ |
void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) { |
touch_timers_[++next_touch_timer_id_] = evt; |
client_->ScheduleTouchTimerCallback(next_touch_timer_id_, |