kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 1 | // Copyright 2017 The PDFium Authors |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "fxjs/xfa/cjx_eventpseudomodel.h" |
| 8 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 9 | #include <algorithm> |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 12 | #include "fxjs/fxv8.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 13 | #include "fxjs/xfa/cfxjse_engine.h" |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 14 | #include "third_party/base/notreached.h" |
| 15 | #include "third_party/base/numerics/safe_conversions.h" |
| 16 | #include "v8/include/v8-primitive.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 17 | #include "xfa/fxfa/cxfa_eventparam.h" |
| 18 | #include "xfa/fxfa/cxfa_ffnotify.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 19 | #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" |
| 20 | |
| 21 | namespace { |
| 22 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 23 | void StringProperty(v8::Isolate* pIsolate, |
| 24 | v8::Local<v8::Value>* pReturn, |
| 25 | WideString* wsValue, |
| 26 | bool bSetting) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 27 | if (bSetting) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 28 | *wsValue = fxv8::ReentrantToWideStringHelper(pIsolate, *pReturn); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 29 | return; |
| 30 | } |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 31 | *pReturn = fxv8::NewStringHelper(pIsolate, wsValue->ToUTF8().AsStringView()); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 32 | } |
| 33 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 34 | void IntegerProperty(v8::Isolate* pIsolate, |
| 35 | v8::Local<v8::Value>* pReturn, |
| 36 | int32_t* iValue, |
| 37 | bool bSetting) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 38 | if (bSetting) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 39 | *iValue = fxv8::ReentrantToInt32Helper(pIsolate, *pReturn); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 40 | return; |
| 41 | } |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 42 | *pReturn = fxv8::NewNumberHelper(pIsolate, *iValue); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 43 | } |
| 44 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 45 | void BooleanProperty(v8::Isolate* pIsolate, |
| 46 | v8::Local<v8::Value>* pReturn, |
| 47 | bool* bValue, |
| 48 | bool bSetting) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 49 | if (bSetting) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 50 | *bValue = fxv8::ReentrantToBooleanHelper(pIsolate, *pReturn); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 51 | return; |
| 52 | } |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 53 | *pReturn = fxv8::NewBooleanHelper(pIsolate, *bValue); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | const CJX_MethodSpec CJX_EventPseudoModel::MethodSpecs[] = { |
| 59 | {"emit", emit_static}, |
| 60 | {"reset", reset_static}}; |
| 61 | |
| 62 | CJX_EventPseudoModel::CJX_EventPseudoModel(CScript_EventPseudoModel* model) |
| 63 | : CJX_Object(model) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 64 | DefineMethods(MethodSpecs); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 65 | } |
| 66 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 67 | CJX_EventPseudoModel::~CJX_EventPseudoModel() = default; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 68 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 69 | bool CJX_EventPseudoModel::DynamicTypeIs(TypeTag eType) const { |
| 70 | return eType == static_type__ || ParentType__::DynamicTypeIs(eType); |
| 71 | } |
| 72 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 73 | void CJX_EventPseudoModel::cancelAction(v8::Isolate* pIsolate, |
| 74 | v8::Local<v8::Value>* pValue, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 75 | bool bSetting, |
| 76 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 77 | Property(pIsolate, pValue, XFA_Event::CancelAction, bSetting); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 78 | } |
| 79 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 80 | void CJX_EventPseudoModel::change(v8::Isolate* pIsolate, |
| 81 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 82 | bool bSetting, |
| 83 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 84 | Property(pIsolate, pValue, XFA_Event::Change, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 85 | } |
| 86 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 87 | void CJX_EventPseudoModel::commitKey(v8::Isolate* pIsolate, |
| 88 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 89 | bool bSetting, |
| 90 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 91 | Property(pIsolate, pValue, XFA_Event::CommitKey, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 92 | } |
| 93 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 94 | void CJX_EventPseudoModel::fullText(v8::Isolate* pIsolate, |
| 95 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 96 | bool bSetting, |
| 97 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 98 | Property(pIsolate, pValue, XFA_Event::FullText, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 99 | } |
| 100 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 101 | void CJX_EventPseudoModel::keyDown(v8::Isolate* pIsolate, |
| 102 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 103 | bool bSetting, |
| 104 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 105 | Property(pIsolate, pValue, XFA_Event::Keydown, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 106 | } |
| 107 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 108 | void CJX_EventPseudoModel::modifier(v8::Isolate* pIsolate, |
| 109 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 110 | bool bSetting, |
| 111 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 112 | Property(pIsolate, pValue, XFA_Event::Modifier, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 113 | } |
| 114 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 115 | void CJX_EventPseudoModel::newContentType(v8::Isolate* pIsolate, |
| 116 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 117 | bool bSetting, |
| 118 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 119 | Property(pIsolate, pValue, XFA_Event::NewContentType, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 120 | } |
| 121 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 122 | void CJX_EventPseudoModel::newText(v8::Isolate* pIsolate, |
| 123 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 124 | bool bSetting, |
| 125 | XFA_Attribute eAttribute) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 126 | if (bSetting) |
| 127 | return; |
| 128 | |
| 129 | CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); |
| 130 | CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
| 131 | if (!pEventParam) |
| 132 | return; |
| 133 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 134 | *pValue = fxv8::NewStringHelper( |
| 135 | pIsolate, pEventParam->GetNewText().ToUTF8().AsStringView()); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 136 | } |
| 137 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 138 | void CJX_EventPseudoModel::prevContentType(v8::Isolate* pIsolate, |
| 139 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 140 | bool bSetting, |
| 141 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 142 | Property(pIsolate, pValue, XFA_Event::PreviousContentType, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 143 | } |
| 144 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 145 | void CJX_EventPseudoModel::prevText(v8::Isolate* pIsolate, |
| 146 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 147 | bool bSetting, |
| 148 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 149 | Property(pIsolate, pValue, XFA_Event::PreviousText, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 150 | } |
| 151 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 152 | void CJX_EventPseudoModel::reenter(v8::Isolate* pIsolate, |
| 153 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 154 | bool bSetting, |
| 155 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 156 | Property(pIsolate, pValue, XFA_Event::Reenter, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 157 | } |
| 158 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 159 | void CJX_EventPseudoModel::selEnd(v8::Isolate* pIsolate, |
| 160 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 161 | bool bSetting, |
| 162 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 163 | Property(pIsolate, pValue, XFA_Event::SelectionEnd, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 164 | } |
| 165 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 166 | void CJX_EventPseudoModel::selStart(v8::Isolate* pIsolate, |
| 167 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 168 | bool bSetting, |
| 169 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 170 | Property(pIsolate, pValue, XFA_Event::SelectionStart, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 171 | } |
| 172 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 173 | void CJX_EventPseudoModel::shift(v8::Isolate* pIsolate, |
| 174 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 175 | bool bSetting, |
| 176 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 177 | Property(pIsolate, pValue, XFA_Event::Shift, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 178 | } |
| 179 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 180 | void CJX_EventPseudoModel::soapFaultCode(v8::Isolate* pIsolate, |
| 181 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 182 | bool bSetting, |
| 183 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 184 | Property(pIsolate, pValue, XFA_Event::SoapFaultCode, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 185 | } |
| 186 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 187 | void CJX_EventPseudoModel::soapFaultString(v8::Isolate* pIsolate, |
| 188 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 189 | bool bSetting, |
| 190 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 191 | Property(pIsolate, pValue, XFA_Event::SoapFaultString, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 192 | } |
| 193 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 194 | void CJX_EventPseudoModel::target(v8::Isolate* pIsolate, |
| 195 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 196 | bool bSetting, |
| 197 | XFA_Attribute eAttribute) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 198 | Property(pIsolate, pValue, XFA_Event::Target, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 201 | CJS_Result CJX_EventPseudoModel::emit( |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 202 | CFXJSE_Engine* runtime, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 203 | const std::vector<v8::Local<v8::Value>>& params) { |
| 204 | CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 205 | CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
| 206 | if (!pEventParam) |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 207 | return CJS_Result::Success(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 208 | |
| 209 | CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); |
| 210 | if (!pNotify) |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 211 | return CJS_Result::Success(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 212 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 213 | pNotify->HandleWidgetEvent(pScriptContext->GetEventTarget(), pEventParam); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 214 | return CJS_Result::Success(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 217 | CJS_Result CJX_EventPseudoModel::reset( |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 218 | CFXJSE_Engine* runtime, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 219 | const std::vector<v8::Local<v8::Value>>& params) { |
| 220 | CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 221 | CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 222 | if (pEventParam) |
| 223 | *pEventParam = CXFA_EventParam(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 224 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 225 | return CJS_Result::Success(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 226 | } |
| 227 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 228 | void CJX_EventPseudoModel::Property(v8::Isolate* pIsolate, |
| 229 | v8::Local<v8::Value>* pValue, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 230 | XFA_Event dwFlag, |
| 231 | bool bSetting) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 232 | // Only the cancelAction, selStart, selEnd and change properties are writable. |
| 233 | if (bSetting && dwFlag != XFA_Event::CancelAction && |
| 234 | dwFlag != XFA_Event::SelectionStart && |
| 235 | dwFlag != XFA_Event::SelectionEnd && dwFlag != XFA_Event::Change) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 236 | return; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 237 | } |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 238 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 239 | CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 240 | CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
| 241 | if (!pEventParam) |
| 242 | return; |
| 243 | |
| 244 | switch (dwFlag) { |
| 245 | case XFA_Event::CancelAction: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 246 | BooleanProperty(pIsolate, pValue, &pEventParam->m_bCancelAction, |
| 247 | bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 248 | break; |
| 249 | case XFA_Event::Change: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 250 | StringProperty(pIsolate, pValue, &pEventParam->m_wsChange, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 251 | break; |
| 252 | case XFA_Event::CommitKey: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 253 | IntegerProperty(pIsolate, pValue, &pEventParam->m_iCommitKey, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 254 | break; |
| 255 | case XFA_Event::FullText: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 256 | StringProperty(pIsolate, pValue, &pEventParam->m_wsFullText, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 257 | break; |
| 258 | case XFA_Event::Keydown: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 259 | BooleanProperty(pIsolate, pValue, &pEventParam->m_bKeyDown, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 260 | break; |
| 261 | case XFA_Event::Modifier: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 262 | BooleanProperty(pIsolate, pValue, &pEventParam->m_bModifier, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 263 | break; |
| 264 | case XFA_Event::NewContentType: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 265 | StringProperty(pIsolate, pValue, &pEventParam->m_wsNewContentType, |
| 266 | bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 267 | break; |
| 268 | case XFA_Event::NewText: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 269 | NOTREACHED(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 270 | break; |
| 271 | case XFA_Event::PreviousContentType: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 272 | StringProperty(pIsolate, pValue, &pEventParam->m_wsPrevContentType, |
| 273 | bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 274 | break; |
| 275 | case XFA_Event::PreviousText: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 276 | StringProperty(pIsolate, pValue, &pEventParam->m_wsPrevText, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 277 | break; |
| 278 | case XFA_Event::Reenter: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 279 | BooleanProperty(pIsolate, pValue, &pEventParam->m_bReenter, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 280 | break; |
| 281 | case XFA_Event::SelectionEnd: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 282 | IntegerProperty(pIsolate, pValue, &pEventParam->m_iSelEnd, bSetting); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 283 | |
| 284 | pEventParam->m_iSelEnd = std::max(0, pEventParam->m_iSelEnd); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 285 | pEventParam->m_iSelEnd = std::min( |
| 286 | pEventParam->m_iSelEnd, pdfium::base::checked_cast<int32_t>( |
| 287 | pEventParam->m_wsPrevText.GetLength())); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 288 | pEventParam->m_iSelStart = |
| 289 | std::min(pEventParam->m_iSelStart, pEventParam->m_iSelEnd); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 290 | break; |
| 291 | case XFA_Event::SelectionStart: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 292 | IntegerProperty(pIsolate, pValue, &pEventParam->m_iSelStart, bSetting); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 293 | pEventParam->m_iSelStart = std::max(0, pEventParam->m_iSelStart); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 294 | pEventParam->m_iSelStart = std::min( |
| 295 | pEventParam->m_iSelStart, pdfium::base::checked_cast<int32_t>( |
| 296 | pEventParam->m_wsPrevText.GetLength())); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 297 | pEventParam->m_iSelEnd = |
| 298 | std::max(pEventParam->m_iSelStart, pEventParam->m_iSelEnd); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 299 | break; |
| 300 | case XFA_Event::Shift: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 301 | BooleanProperty(pIsolate, pValue, &pEventParam->m_bShift, bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 302 | break; |
| 303 | case XFA_Event::SoapFaultCode: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 304 | StringProperty(pIsolate, pValue, &pEventParam->m_wsSoapFaultCode, |
| 305 | bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 306 | break; |
| 307 | case XFA_Event::SoapFaultString: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 308 | StringProperty(pIsolate, pValue, &pEventParam->m_wsSoapFaultString, |
| 309 | bSetting); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 310 | break; |
| 311 | case XFA_Event::Target: |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 312 | default: |
| 313 | break; |
| 314 | } |
| 315 | } |