From cbf1550e48e300142a53f635daba3c1d8910add9 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Fri, 25 May 2018 16:18:40 +0000 Subject: [xfa] Generate CXFA_EventParam.newText dynamically When an xfa.event is sent it is possible to change the selStart, selEnd and change values of the event. This should cause the value of newText to be changed as needed. This CL removes m_wsNewText from CXFA_EventParam and instead generates the new text based on the previous text, the selection and the change. Bug: 1066 Change-Id: I35d126fad9771c8980654a8af64d2b98989bff3f Reviewed-on: https://pdfium-review.googlesource.com/32970 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- fxjs/cfxjse_formcalc_context_embeddertest.cpp | 37 +++++++++++++++++++++++++++ fxjs/xfa/cjx_eventpseudomodel.cpp | 15 +++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) (limited to 'fxjs') diff --git a/fxjs/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/cfxjse_formcalc_context_embeddertest.cpp index 4b9d93a660..ed0c5bccc7 100644 --- a/fxjs/cfxjse_formcalc_context_embeddertest.cpp +++ b/fxjs/cfxjse_formcalc_context_embeddertest.cpp @@ -1573,3 +1573,40 @@ TEST_F(CFXJSE_FormCalcContextEmbedderTest, XFAEventCancelAction) { EXPECT_TRUE(Execute("xfa.event.cancelAction = \"true\"")); EXPECT_TRUE(context->GetEventParam()->m_bCancelAction); } + +TEST_F(CFXJSE_FormCalcContextEmbedderTest, ComplexTextChangeEvent) { + ASSERT_TRUE(OpenDocument("simple_xfa.pdf")); + + CXFA_EventParam params; + params.m_wsChange = L"g"; + params.m_wsPrevText = L"abcd"; + params.m_iSelStart = 1; + params.m_iSelEnd = 3; + + CFXJSE_Engine* context = GetScriptContext(); + context->SetEventParam(params); + + EXPECT_EQ(L"abcd", context->GetEventParam()->m_wsPrevText); + EXPECT_EQ(L"agd", context->GetEventParam()->GetNewText()); + EXPECT_EQ(L"g", context->GetEventParam()->m_wsChange); + EXPECT_EQ(1, context->GetEventParam()->m_iSelStart); + EXPECT_EQ(3, context->GetEventParam()->m_iSelEnd); + + const char change_event[] = {"xfa.event.change = \"xyz\""}; + EXPECT_TRUE(Execute(change_event)); + + EXPECT_EQ(L"abcd", context->GetEventParam()->m_wsPrevText); + EXPECT_EQ(L"xyz", context->GetEventParam()->m_wsChange); + EXPECT_EQ(L"axyzd", context->GetEventParam()->GetNewText()); + EXPECT_EQ(1, context->GetEventParam()->m_iSelStart); + EXPECT_EQ(3, context->GetEventParam()->m_iSelEnd); + + const char sel_event[] = {"xfa.event.selEnd = \"1\""}; + EXPECT_TRUE(Execute(sel_event)); + + EXPECT_EQ(L"abcd", context->GetEventParam()->m_wsPrevText); + EXPECT_EQ(L"xyz", context->GetEventParam()->m_wsChange); + EXPECT_EQ(L"axyzbcd", context->GetEventParam()->GetNewText()); + EXPECT_EQ(1, context->GetEventParam()->m_iSelStart); + EXPECT_EQ(1, context->GetEventParam()->m_iSelEnd); +} diff --git a/fxjs/xfa/cjx_eventpseudomodel.cpp b/fxjs/xfa/cjx_eventpseudomodel.cpp index 82b76fce12..d2364c8f32 100644 --- a/fxjs/xfa/cjx_eventpseudomodel.cpp +++ b/fxjs/xfa/cjx_eventpseudomodel.cpp @@ -101,7 +101,18 @@ void CJX_EventPseudoModel::newContentType(CFXJSE_Value* pValue, void CJX_EventPseudoModel::newText(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - Property(pValue, XFA_Event::NewText, bSetting); + if (bSetting) + return; + + CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); + if (!pScriptContext) + return; + + CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); + if (!pEventParam) + return; + + pValue->SetString(pEventParam->GetNewText().UTF8Encode().AsStringView()); } void CJX_EventPseudoModel::prevContentType(CFXJSE_Value* pValue, @@ -237,7 +248,7 @@ void CJX_EventPseudoModel::Property(CFXJSE_Value* pValue, StringProperty(pValue, &pEventParam->m_wsNewContentType, bSetting); break; case XFA_Event::NewText: - StringProperty(pValue, &pEventParam->m_wsNewText, bSetting); + NOTREACHED(); break; case XFA_Event::PreviousContentType: StringProperty(pValue, &pEventParam->m_wsPrevContentType, bSetting); -- cgit v1.2.3