Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index afc8b71633bcd2bbab24880da6b033316bfe63a9..2c38a30cf4a03ee069087a72255cad44cabf00aa 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -1625,6 +1625,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() { |
| @@ -1721,18 +1743,29 @@ 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); |
| + mouse_down_state_.Set(form_type == FPDF_FORMFIELD_TEXTFIELD |
| + ? PDFiumPage::FORM_TEXT_AREA |
| + : PDFiumPage::NONSELECTABLE_AREA, |
| + target); |
| + |
| bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
| form_type == FPDF_FORMFIELD_COMBOBOX); |
| + |
| +// TODO(bug_62400): figure out selection and copying |
| +// for XFA fields |
| #if defined(PDF_ENABLE_XFA) |
| is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
| #endif |
| + |
| + // TODO(drgage): 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. |
| @@ -1808,11 +1841,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; |
| } |
| } |
| @@ -1828,6 +1863,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; |
| @@ -1859,6 +1898,7 @@ bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
| cursor = PP_CURSORTYPE_HAND; |
| break; |
| case PDFiumPage::NONSELECTABLE_AREA: |
| + case PDFiumPage::FORM_TEXT_AREA: |
| default: |
| switch (form_type) { |
| case FPDF_FORMFIELD_PUSHBUTTON: |
| @@ -1992,6 +2032,19 @@ bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
| if (last_page_mouse_down_ == -1) |
| return false; |
| + if (in_form_text_field_) { |
| + if (event.GetKeyCode() == ui::VKEY_SHIFT) |
| + SetFormSelectedText(form_, pages_[last_page_mouse_down_]->GetPage()); |
| + else { |
| + uint32_t modifiers = event.GetModifiers(); |
|
Lei Zhang
2017/06/16 21:34:53
Try to declare variables as close to where they ar
drgage
2017/06/16 23:15:04
Done.
|
| + |
| + // If a key other than shift is released while shift is not also |
| + // being held down, selection of form field text should be invalidated. |
| + if (modifiers & ~PP_INPUTEVENT_MODIFIER_SHIFTKEY) |
| + SelectionChangeInvalidator selection_invalidator(this); |
|
Lei Zhang
2017/06/16 21:34:53
SelectionChangeInvalidator seems to do a lot of wo
drgage
2017/06/16 23:15:04
Done.
|
| + } |
| + } |
| + |
| return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
| event.GetKeyCode(), event.GetModifiers()); |
| } |
| @@ -3553,6 +3606,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_, |