diff options
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cfxjse_formcalc_context_embeddertest.cpp | 37 | ||||
-rw-r--r-- | fxjs/xfa/cjx_eventpseudomodel.cpp | 15 |
2 files changed, 50 insertions, 2 deletions
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); |