diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-05-29 19:42:39 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-29 19:42:39 +0000 |
commit | 6af5369477ec05554ef9e73ae6762860095f09e9 (patch) | |
tree | 0a9d28f4e3f89ca5b141954913169fdff63bf59c /xfa/fxfa/cxfa_fftextedit.cpp | |
parent | 162a31a6af1538acf7ac9835111626161287d742 (diff) | |
download | pdfium-6af5369477ec05554ef9e73ae6762860095f09e9.tar.xz |
[xfa] Propagate the xfa change data for text to JS and back.
This CL adds the necessary plumbing to propagate the change information
for a text widget from FWL out to JS and handle the returned value as
necessary.
Bug: pdfium:1066
Change-Id: I78fd81761b90294f1836e9f09dba12ed238963cc
Reviewed-on: https://pdfium-review.googlesource.com/33070
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/cxfa_fftextedit.cpp')
-rw-r--r-- | xfa/fxfa/cxfa_fftextedit.cpp | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp index 02787d579b..a8080d13d5 100644 --- a/xfa/fxfa/cxfa_fftextedit.cpp +++ b/xfa/fxfa/cxfa_fftextedit.cpp @@ -11,7 +11,7 @@ #include "xfa/fwl/cfwl_datetimepicker.h" #include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_eventtarget.h" -#include "xfa/fwl/cfwl_eventtextchanged.h" +#include "xfa/fwl/cfwl_eventtextwillchange.h" #include "xfa/fwl/cfwl_messagekillfocus.h" #include "xfa/fwl/cfwl_messagesetfocus.h" #include "xfa/fwl/cfwl_notedriver.h" @@ -287,7 +287,7 @@ bool CXFA_FFTextEdit::UpdateFWLData() { WideString wsText = m_pNode->GetValue(eType); WideString wsOldText = pEdit->GetText(); if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { - pEdit->SetText(wsText); + pEdit->SetText(wsText, CFDE_TextEditEngine::RecordOperation::kSkipNotify); bUpdate = true; } if (bUpdate) @@ -296,28 +296,26 @@ bool CXFA_FFTextEdit::UpdateFWLData() { return true; } -void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, - const WideString& wsChanged, - const WideString& wsPrevText) { +void CXFA_FFTextEdit::OnTextWillChange(CFWL_Widget* pWidget, + CFWL_EventTextWillChange* event) { m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged; + CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; - eParam.m_wsChange = wsChanged; + eParam.m_wsChange = event->change_text; eParam.m_pTarget = m_pNode.Get(); - eParam.m_wsPrevText = wsPrevText; - if (m_pNode->GetFFWidgetType() == XFA_FFWidgetType::kDateTimeEdit) { - auto* pDateTime = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - if (pDateTime->HasSelection()) { - size_t count; - std::tie(eParam.m_iSelStart, count) = pDateTime->GetSelection(); - eParam.m_iSelEnd = eParam.m_iSelStart + count; - } - } else { - CFWL_Edit* pEdit = ToEdit(m_pNormalWidget.get()); - if (pEdit->HasSelection()) - std::tie(eParam.m_iSelStart, eParam.m_iSelEnd) = pEdit->GetSelection(); - } + eParam.m_wsPrevText = event->previous_text; + eParam.m_iSelStart = static_cast<int32_t>(event->selection_start); + eParam.m_iSelEnd = static_cast<int32_t>(event->selection_end); + m_pNode->ProcessEvent(GetDocView(), XFA_AttributeEnum::Change, &eParam); + + // Copy the data back out of the EventParam and into the TextChanged event so + // it can propagate back to the calling widget. + event->cancelled = eParam.m_bCancelAction; + event->change_text = eParam.m_wsChange; + event->selection_start = static_cast<size_t>(eParam.m_iSelStart); + event->selection_end = static_cast<size_t>(eParam.m_iSelEnd); } void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { @@ -334,17 +332,13 @@ void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { CXFA_FFField::OnProcessEvent(pEvent); switch (pEvent->GetType()) { - case CFWL_Event::Type::TextChanged: { - CFWL_EventTextChanged* event = - static_cast<CFWL_EventTextChanged*>(pEvent); - WideString wsChange; - OnTextChanged(m_pNormalWidget.get(), wsChange, event->wsPrevText); + case CFWL_Event::Type::TextWillChange: + OnTextWillChange(m_pNormalWidget.get(), + static_cast<CFWL_EventTextWillChange*>(pEvent)); break; - } - case CFWL_Event::Type::TextFull: { + case CFWL_Event::Type::TextFull: OnTextFull(m_pNormalWidget.get()); break; - } default: break; } |