| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" | 7 #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" |
| 8 | 8 |
| 9 #include "fxjs/cfxjse_arguments.h" | 9 #include "fxjs/cfxjse_arguments.h" |
| 10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 11 #include "xfa/fxfa/cxfa_eventparam.h" | 11 #include "xfa/fxfa/cxfa_eventparam.h" |
| 12 #include "xfa/fxfa/parser/cxfa_document.h" | 12 #include "xfa/fxfa/parser/cxfa_document.h" |
| 13 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" | 13 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
| 14 #include "xfa/fxfa/parser/xfa_localemgr.h" | 14 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 15 #include "xfa/fxfa/parser/xfa_object.h" | 15 #include "xfa/fxfa/parser/xfa_object.h" |
| 16 #include "xfa/fxfa/parser/xfa_utils.h" | 16 #include "xfa/fxfa/parser/xfa_utils.h" |
| 17 #include "xfa/fxfa/xfa_ffwidgethandler.h" | 17 #include "xfa/fxfa/xfa_ffwidgethandler.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 void StringProperty(CFXJSE_Value* pValue, | 21 void StringProperty(CFXJSE_Value* pValue, |
| 22 CFX_WideString& wsValue, | 22 CFX_WideString& wsValue, |
| 23 FX_BOOL bSetting) { | 23 bool bSetting) { |
| 24 if (bSetting) { | 24 if (bSetting) { |
| 25 wsValue = pValue->ToWideString(); | 25 wsValue = pValue->ToWideString(); |
| 26 return; | 26 return; |
| 27 } | 27 } |
| 28 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); | 28 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, FX_BOOL bSetting) { | 31 void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, bool bSetting) { |
| 32 if (bSetting) { | 32 if (bSetting) { |
| 33 iValue = pValue->ToInteger(); | 33 iValue = pValue->ToInteger(); |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 pValue->SetInteger(iValue); | 36 pValue->SetInteger(iValue); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void BooleanProperty(CFXJSE_Value* pValue, FX_BOOL& bValue, FX_BOOL bSetting) { | 39 void BooleanProperty(CFXJSE_Value* pValue, bool& bValue, bool bSetting) { |
| 40 if (bSetting) { | 40 if (bSetting) { |
| 41 bValue = pValue->ToBoolean(); | 41 bValue = pValue->ToBoolean(); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 pValue->SetBoolean(bValue); | 44 pValue->SetBoolean(bValue); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) | 49 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) |
| 50 : CXFA_Object(pDocument, | 50 : CXFA_Object(pDocument, |
| 51 XFA_ObjectType::Object, | 51 XFA_ObjectType::Object, |
| 52 XFA_Element::EventPseudoModel, | 52 XFA_Element::EventPseudoModel, |
| 53 CFX_WideStringC(L"eventPseudoModel")) {} | 53 CFX_WideStringC(L"eventPseudoModel")) {} |
| 54 | 54 |
| 55 CScript_EventPseudoModel::~CScript_EventPseudoModel() {} | 55 CScript_EventPseudoModel::~CScript_EventPseudoModel() {} |
| 56 | 56 |
| 57 void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue, | 57 void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue, |
| 58 XFA_Event dwFlag, | 58 XFA_Event dwFlag, |
| 59 FX_BOOL bSetting) { | 59 bool bSetting) { |
| 60 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 60 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
| 61 if (!pScriptContext) | 61 if (!pScriptContext) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | 64 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
| 65 if (!pEventParam) | 65 if (!pEventParam) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 switch (dwFlag) { | 68 switch (dwFlag) { |
| 69 case XFA_Event::CancelAction: | 69 case XFA_Event::CancelAction: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 case XFA_Event::SoapFaultString: | 114 case XFA_Event::SoapFaultString: |
| 115 StringProperty(pValue, pEventParam->m_wsSoapFaultString, bSetting); | 115 StringProperty(pValue, pEventParam->m_wsSoapFaultString, bSetting); |
| 116 break; | 116 break; |
| 117 case XFA_Event::Target: | 117 case XFA_Event::Target: |
| 118 break; | 118 break; |
| 119 default: | 119 default: |
| 120 break; | 120 break; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 void CScript_EventPseudoModel::Change(CFXJSE_Value* pValue, | 123 void CScript_EventPseudoModel::Change(CFXJSE_Value* pValue, |
| 124 FX_BOOL bSetting, | 124 bool bSetting, |
| 125 XFA_ATTRIBUTE eAttribute) { | 125 XFA_ATTRIBUTE eAttribute) { |
| 126 Property(pValue, XFA_Event::Change, bSetting); | 126 Property(pValue, XFA_Event::Change, bSetting); |
| 127 } | 127 } |
| 128 void CScript_EventPseudoModel::CommitKey(CFXJSE_Value* pValue, | 128 void CScript_EventPseudoModel::CommitKey(CFXJSE_Value* pValue, |
| 129 FX_BOOL bSetting, | 129 bool bSetting, |
| 130 XFA_ATTRIBUTE eAttribute) { | 130 XFA_ATTRIBUTE eAttribute) { |
| 131 Property(pValue, XFA_Event::CommitKey, bSetting); | 131 Property(pValue, XFA_Event::CommitKey, bSetting); |
| 132 } | 132 } |
| 133 void CScript_EventPseudoModel::FullText(CFXJSE_Value* pValue, | 133 void CScript_EventPseudoModel::FullText(CFXJSE_Value* pValue, |
| 134 FX_BOOL bSetting, | 134 bool bSetting, |
| 135 XFA_ATTRIBUTE eAttribute) { | 135 XFA_ATTRIBUTE eAttribute) { |
| 136 Property(pValue, XFA_Event::FullText, bSetting); | 136 Property(pValue, XFA_Event::FullText, bSetting); |
| 137 } | 137 } |
| 138 void CScript_EventPseudoModel::KeyDown(CFXJSE_Value* pValue, | 138 void CScript_EventPseudoModel::KeyDown(CFXJSE_Value* pValue, |
| 139 FX_BOOL bSetting, | 139 bool bSetting, |
| 140 XFA_ATTRIBUTE eAttribute) { | 140 XFA_ATTRIBUTE eAttribute) { |
| 141 Property(pValue, XFA_Event::Keydown, bSetting); | 141 Property(pValue, XFA_Event::Keydown, bSetting); |
| 142 } | 142 } |
| 143 void CScript_EventPseudoModel::Modifier(CFXJSE_Value* pValue, | 143 void CScript_EventPseudoModel::Modifier(CFXJSE_Value* pValue, |
| 144 FX_BOOL bSetting, | 144 bool bSetting, |
| 145 XFA_ATTRIBUTE eAttribute) { | 145 XFA_ATTRIBUTE eAttribute) { |
| 146 Property(pValue, XFA_Event::Modifier, bSetting); | 146 Property(pValue, XFA_Event::Modifier, bSetting); |
| 147 } | 147 } |
| 148 void CScript_EventPseudoModel::NewContentType(CFXJSE_Value* pValue, | 148 void CScript_EventPseudoModel::NewContentType(CFXJSE_Value* pValue, |
| 149 FX_BOOL bSetting, | 149 bool bSetting, |
| 150 XFA_ATTRIBUTE eAttribute) { | 150 XFA_ATTRIBUTE eAttribute) { |
| 151 Property(pValue, XFA_Event::NewContentType, bSetting); | 151 Property(pValue, XFA_Event::NewContentType, bSetting); |
| 152 } | 152 } |
| 153 void CScript_EventPseudoModel::NewText(CFXJSE_Value* pValue, | 153 void CScript_EventPseudoModel::NewText(CFXJSE_Value* pValue, |
| 154 FX_BOOL bSetting, | 154 bool bSetting, |
| 155 XFA_ATTRIBUTE eAttribute) { | 155 XFA_ATTRIBUTE eAttribute) { |
| 156 Property(pValue, XFA_Event::NewText, bSetting); | 156 Property(pValue, XFA_Event::NewText, bSetting); |
| 157 } | 157 } |
| 158 void CScript_EventPseudoModel::PrevContentType(CFXJSE_Value* pValue, | 158 void CScript_EventPseudoModel::PrevContentType(CFXJSE_Value* pValue, |
| 159 FX_BOOL bSetting, | 159 bool bSetting, |
| 160 XFA_ATTRIBUTE eAttribute) { | 160 XFA_ATTRIBUTE eAttribute) { |
| 161 Property(pValue, XFA_Event::PreviousContentType, bSetting); | 161 Property(pValue, XFA_Event::PreviousContentType, bSetting); |
| 162 } | 162 } |
| 163 void CScript_EventPseudoModel::PrevText(CFXJSE_Value* pValue, | 163 void CScript_EventPseudoModel::PrevText(CFXJSE_Value* pValue, |
| 164 FX_BOOL bSetting, | 164 bool bSetting, |
| 165 XFA_ATTRIBUTE eAttribute) { | 165 XFA_ATTRIBUTE eAttribute) { |
| 166 Property(pValue, XFA_Event::PreviousText, bSetting); | 166 Property(pValue, XFA_Event::PreviousText, bSetting); |
| 167 } | 167 } |
| 168 void CScript_EventPseudoModel::Reenter(CFXJSE_Value* pValue, | 168 void CScript_EventPseudoModel::Reenter(CFXJSE_Value* pValue, |
| 169 FX_BOOL bSetting, | 169 bool bSetting, |
| 170 XFA_ATTRIBUTE eAttribute) { | 170 XFA_ATTRIBUTE eAttribute) { |
| 171 Property(pValue, XFA_Event::Reenter, bSetting); | 171 Property(pValue, XFA_Event::Reenter, bSetting); |
| 172 } | 172 } |
| 173 void CScript_EventPseudoModel::SelEnd(CFXJSE_Value* pValue, | 173 void CScript_EventPseudoModel::SelEnd(CFXJSE_Value* pValue, |
| 174 FX_BOOL bSetting, | 174 bool bSetting, |
| 175 XFA_ATTRIBUTE eAttribute) { | 175 XFA_ATTRIBUTE eAttribute) { |
| 176 Property(pValue, XFA_Event::SelectionEnd, bSetting); | 176 Property(pValue, XFA_Event::SelectionEnd, bSetting); |
| 177 } | 177 } |
| 178 void CScript_EventPseudoModel::SelStart(CFXJSE_Value* pValue, | 178 void CScript_EventPseudoModel::SelStart(CFXJSE_Value* pValue, |
| 179 FX_BOOL bSetting, | 179 bool bSetting, |
| 180 XFA_ATTRIBUTE eAttribute) { | 180 XFA_ATTRIBUTE eAttribute) { |
| 181 Property(pValue, XFA_Event::SelectionStart, bSetting); | 181 Property(pValue, XFA_Event::SelectionStart, bSetting); |
| 182 } | 182 } |
| 183 void CScript_EventPseudoModel::Shift(CFXJSE_Value* pValue, | 183 void CScript_EventPseudoModel::Shift(CFXJSE_Value* pValue, |
| 184 FX_BOOL bSetting, | 184 bool bSetting, |
| 185 XFA_ATTRIBUTE eAttribute) { | 185 XFA_ATTRIBUTE eAttribute) { |
| 186 Property(pValue, XFA_Event::Shift, bSetting); | 186 Property(pValue, XFA_Event::Shift, bSetting); |
| 187 } | 187 } |
| 188 void CScript_EventPseudoModel::SoapFaultCode(CFXJSE_Value* pValue, | 188 void CScript_EventPseudoModel::SoapFaultCode(CFXJSE_Value* pValue, |
| 189 FX_BOOL bSetting, | 189 bool bSetting, |
| 190 XFA_ATTRIBUTE eAttribute) { | 190 XFA_ATTRIBUTE eAttribute) { |
| 191 Property(pValue, XFA_Event::SoapFaultCode, bSetting); | 191 Property(pValue, XFA_Event::SoapFaultCode, bSetting); |
| 192 } | 192 } |
| 193 void CScript_EventPseudoModel::SoapFaultString(CFXJSE_Value* pValue, | 193 void CScript_EventPseudoModel::SoapFaultString(CFXJSE_Value* pValue, |
| 194 FX_BOOL bSetting, | 194 bool bSetting, |
| 195 XFA_ATTRIBUTE eAttribute) { | 195 XFA_ATTRIBUTE eAttribute) { |
| 196 Property(pValue, XFA_Event::SoapFaultString, bSetting); | 196 Property(pValue, XFA_Event::SoapFaultString, bSetting); |
| 197 } | 197 } |
| 198 void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue, | 198 void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue, |
| 199 FX_BOOL bSetting, | 199 bool bSetting, |
| 200 XFA_ATTRIBUTE eAttribute) { | 200 XFA_ATTRIBUTE eAttribute) { |
| 201 Property(pValue, XFA_Event::Target, bSetting); | 201 Property(pValue, XFA_Event::Target, bSetting); |
| 202 } | 202 } |
| 203 void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) { | 203 void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) { |
| 204 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 204 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
| 205 if (!pScriptContext) { | 205 if (!pScriptContext) { |
| 206 return; | 206 return; |
| 207 } | 207 } |
| 208 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | 208 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
| 209 if (!pEventParam) { | 209 if (!pEventParam) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 223 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 223 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
| 224 if (!pScriptContext) { | 224 if (!pScriptContext) { |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | 227 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
| 228 if (!pEventParam) { | 228 if (!pEventParam) { |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 pEventParam->Reset(); | 231 pEventParam->Reset(); |
| 232 } | 232 } |
| OLD | NEW |