summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-29 19:42:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-29 19:42:39 +0000
commit6af5369477ec05554ef9e73ae6762860095f09e9 (patch)
tree0a9d28f4e3f89ca5b141954913169fdff63bf59c /xfa/fxfa
parent162a31a6af1538acf7ac9835111626161287d742 (diff)
downloadpdfium-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')
-rw-r--r--xfa/fxfa/cxfa_eventparam.cpp2
-rw-r--r--xfa/fxfa/cxfa_fftextedit.cpp48
-rw-r--r--xfa/fxfa/cxfa_fftextedit.h5
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp3
4 files changed, 26 insertions, 32 deletions
diff --git a/xfa/fxfa/cxfa_eventparam.cpp b/xfa/fxfa/cxfa_eventparam.cpp
index 4e3cae9d1d..4746a6ad86 100644
--- a/xfa/fxfa/cxfa_eventparam.cpp
+++ b/xfa/fxfa/cxfa_eventparam.cpp
@@ -21,7 +21,7 @@ CXFA_EventParam::CXFA_EventParam()
m_bShift(false),
m_bIsFormReady(false) {}
-CXFA_EventParam::~CXFA_EventParam() {}
+CXFA_EventParam::~CXFA_EventParam() = default;
CXFA_EventParam::CXFA_EventParam(const CXFA_EventParam& other) = default;
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;
}
diff --git a/xfa/fxfa/cxfa_fftextedit.h b/xfa/fxfa/cxfa_fftextedit.h
index 7c19444ae6..9b61373df9 100644
--- a/xfa/fxfa/cxfa_fftextedit.h
+++ b/xfa/fxfa/cxfa_fftextedit.h
@@ -12,6 +12,7 @@
#include "xfa/fxfa/cxfa_fffield.h"
class CFWL_Event;
+class CFWL_EventTextWillChange;
class CFWL_Widget;
class CFX_Matrix;
class CXFA_FFWidget;
@@ -38,9 +39,7 @@ class CXFA_FFTextEdit : public CXFA_FFField {
void OnDrawWidget(CXFA_Graphics* pGraphics,
const CFX_Matrix& matrix) override;
- void OnTextChanged(CFWL_Widget* pWidget,
- const WideString& wsChanged,
- const WideString& wsPrevText);
+ void OnTextWillChange(CFWL_Widget* pWidget, CFWL_EventTextWillChange* change);
void OnTextFull(CFWL_Widget* pWidget);
// CXFA_FFWidget
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 66c4fb99f4..6672e7fb29 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -2290,7 +2290,7 @@ std::pair<int32_t, bool> CXFA_Node::ExecuteBoolScript(
CXFA_FFDoc* pDoc = docView->GetDoc();
CFXJSE_Engine* pContext = pDoc->GetXFADoc()->GetScriptContext();
- pContext->SetEventParam(*pEventParam);
+ pContext->SetEventParam(pEventParam);
pContext->SetRunAtType(script->GetRunAt());
std::vector<CXFA_Node*> refNodes;
@@ -2344,6 +2344,7 @@ std::pair<int32_t, bool> CXFA_Node::ExecuteBoolScript(
}
}
pContext->SetNodesOfRunScript(nullptr);
+ pContext->SetEventParam(nullptr);
return {iRet, pTmpRetValue->IsBoolean() ? pTmpRetValue->ToBoolean() : false};
}