OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
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 "xfa/fxfa/parser/xfa_script_eventpseudomodel.h" | |
8 | |
9 #include "fxjs/include/cfxjse_arguments.h" | |
10 #include "xfa/fxfa/app/xfa_ffnotify.h" | |
11 #include "xfa/fxfa/include/cxfa_eventparam.h" | |
12 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" | |
13 #include "xfa/fxfa/parser/xfa_doclayout.h" | |
14 #include "xfa/fxfa/parser/xfa_document.h" | |
15 #include "xfa/fxfa/parser/xfa_localemgr.h" | |
16 #include "xfa/fxfa/parser/xfa_object.h" | |
17 #include "xfa/fxfa/parser/xfa_script.h" | |
18 #include "xfa/fxfa/parser/xfa_script_imp.h" | |
19 #include "xfa/fxfa/parser/xfa_utils.h" | |
20 | |
21 namespace { | |
22 | |
23 void StringProperty(CFXJSE_Value* pValue, | |
24 CFX_WideString& wsValue, | |
25 FX_BOOL bSetting) { | |
26 if (bSetting) { | |
27 wsValue = pValue->ToWideString(); | |
28 return; | |
29 } | |
30 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); | |
31 } | |
32 | |
33 void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, FX_BOOL bSetting) { | |
34 if (bSetting) { | |
35 iValue = pValue->ToInteger(); | |
36 return; | |
37 } | |
38 pValue->SetInteger(iValue); | |
39 } | |
40 | |
41 void BooleanProperty(CFXJSE_Value* pValue, FX_BOOL& bValue, FX_BOOL bSetting) { | |
42 if (bSetting) { | |
43 bValue = pValue->ToBoolean(); | |
44 return; | |
45 } | |
46 pValue->SetBoolean(bValue); | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) | |
52 : CXFA_Object(pDocument, | |
53 XFA_ObjectType::Object, | |
54 XFA_Element::EventPseudoModel, | |
55 CFX_WideStringC(L"eventPseudoModel")) {} | |
56 | |
57 CScript_EventPseudoModel::~CScript_EventPseudoModel() {} | |
58 | |
59 void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue, | |
60 XFA_Event dwFlag, | |
61 FX_BOOL bSetting) { | |
62 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
63 if (!pScriptContext) | |
64 return; | |
65 | |
66 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | |
67 if (!pEventParam) | |
68 return; | |
69 | |
70 switch (dwFlag) { | |
71 case XFA_Event::CancelAction: | |
72 BooleanProperty(pValue, pEventParam->m_bCancelAction, bSetting); | |
73 break; | |
74 case XFA_Event::Change: | |
75 StringProperty(pValue, pEventParam->m_wsChange, bSetting); | |
76 break; | |
77 case XFA_Event::CommitKey: | |
78 InterProperty(pValue, pEventParam->m_iCommitKey, bSetting); | |
79 break; | |
80 case XFA_Event::FullText: | |
81 StringProperty(pValue, pEventParam->m_wsFullText, bSetting); | |
82 break; | |
83 case XFA_Event::Keydown: | |
84 BooleanProperty(pValue, pEventParam->m_bKeyDown, bSetting); | |
85 break; | |
86 case XFA_Event::Modifier: | |
87 BooleanProperty(pValue, pEventParam->m_bModifier, bSetting); | |
88 break; | |
89 case XFA_Event::NewContentType: | |
90 StringProperty(pValue, pEventParam->m_wsNewContentType, bSetting); | |
91 break; | |
92 case XFA_Event::NewText: | |
93 StringProperty(pValue, pEventParam->m_wsNewText, bSetting); | |
94 break; | |
95 case XFA_Event::PreviousContentType: | |
96 StringProperty(pValue, pEventParam->m_wsPrevContentType, bSetting); | |
97 break; | |
98 case XFA_Event::PreviousText: | |
99 StringProperty(pValue, pEventParam->m_wsPrevText, bSetting); | |
100 break; | |
101 case XFA_Event::Reenter: | |
102 BooleanProperty(pValue, pEventParam->m_bReenter, bSetting); | |
103 break; | |
104 case XFA_Event::SelectionEnd: | |
105 InterProperty(pValue, pEventParam->m_iSelEnd, bSetting); | |
106 break; | |
107 case XFA_Event::SelectionStart: | |
108 InterProperty(pValue, pEventParam->m_iSelStart, bSetting); | |
109 break; | |
110 case XFA_Event::Shift: | |
111 BooleanProperty(pValue, pEventParam->m_bShift, bSetting); | |
112 break; | |
113 case XFA_Event::SoapFaultCode: | |
114 StringProperty(pValue, pEventParam->m_wsSoapFaultCode, bSetting); | |
115 break; | |
116 case XFA_Event::SoapFaultString: | |
117 StringProperty(pValue, pEventParam->m_wsSoapFaultString, bSetting); | |
118 break; | |
119 case XFA_Event::Target: | |
120 break; | |
121 default: | |
122 break; | |
123 } | |
124 } | |
125 void CScript_EventPseudoModel::Change(CFXJSE_Value* pValue, | |
126 FX_BOOL bSetting, | |
127 XFA_ATTRIBUTE eAttribute) { | |
128 Property(pValue, XFA_Event::Change, bSetting); | |
129 } | |
130 void CScript_EventPseudoModel::CommitKey(CFXJSE_Value* pValue, | |
131 FX_BOOL bSetting, | |
132 XFA_ATTRIBUTE eAttribute) { | |
133 Property(pValue, XFA_Event::CommitKey, bSetting); | |
134 } | |
135 void CScript_EventPseudoModel::FullText(CFXJSE_Value* pValue, | |
136 FX_BOOL bSetting, | |
137 XFA_ATTRIBUTE eAttribute) { | |
138 Property(pValue, XFA_Event::FullText, bSetting); | |
139 } | |
140 void CScript_EventPseudoModel::KeyDown(CFXJSE_Value* pValue, | |
141 FX_BOOL bSetting, | |
142 XFA_ATTRIBUTE eAttribute) { | |
143 Property(pValue, XFA_Event::Keydown, bSetting); | |
144 } | |
145 void CScript_EventPseudoModel::Modifier(CFXJSE_Value* pValue, | |
146 FX_BOOL bSetting, | |
147 XFA_ATTRIBUTE eAttribute) { | |
148 Property(pValue, XFA_Event::Modifier, bSetting); | |
149 } | |
150 void CScript_EventPseudoModel::NewContentType(CFXJSE_Value* pValue, | |
151 FX_BOOL bSetting, | |
152 XFA_ATTRIBUTE eAttribute) { | |
153 Property(pValue, XFA_Event::NewContentType, bSetting); | |
154 } | |
155 void CScript_EventPseudoModel::NewText(CFXJSE_Value* pValue, | |
156 FX_BOOL bSetting, | |
157 XFA_ATTRIBUTE eAttribute) { | |
158 Property(pValue, XFA_Event::NewText, bSetting); | |
159 } | |
160 void CScript_EventPseudoModel::PrevContentType(CFXJSE_Value* pValue, | |
161 FX_BOOL bSetting, | |
162 XFA_ATTRIBUTE eAttribute) { | |
163 Property(pValue, XFA_Event::PreviousContentType, bSetting); | |
164 } | |
165 void CScript_EventPseudoModel::PrevText(CFXJSE_Value* pValue, | |
166 FX_BOOL bSetting, | |
167 XFA_ATTRIBUTE eAttribute) { | |
168 Property(pValue, XFA_Event::PreviousText, bSetting); | |
169 } | |
170 void CScript_EventPseudoModel::Reenter(CFXJSE_Value* pValue, | |
171 FX_BOOL bSetting, | |
172 XFA_ATTRIBUTE eAttribute) { | |
173 Property(pValue, XFA_Event::Reenter, bSetting); | |
174 } | |
175 void CScript_EventPseudoModel::SelEnd(CFXJSE_Value* pValue, | |
176 FX_BOOL bSetting, | |
177 XFA_ATTRIBUTE eAttribute) { | |
178 Property(pValue, XFA_Event::SelectionEnd, bSetting); | |
179 } | |
180 void CScript_EventPseudoModel::SelStart(CFXJSE_Value* pValue, | |
181 FX_BOOL bSetting, | |
182 XFA_ATTRIBUTE eAttribute) { | |
183 Property(pValue, XFA_Event::SelectionStart, bSetting); | |
184 } | |
185 void CScript_EventPseudoModel::Shift(CFXJSE_Value* pValue, | |
186 FX_BOOL bSetting, | |
187 XFA_ATTRIBUTE eAttribute) { | |
188 Property(pValue, XFA_Event::Shift, bSetting); | |
189 } | |
190 void CScript_EventPseudoModel::SoapFaultCode(CFXJSE_Value* pValue, | |
191 FX_BOOL bSetting, | |
192 XFA_ATTRIBUTE eAttribute) { | |
193 Property(pValue, XFA_Event::SoapFaultCode, bSetting); | |
194 } | |
195 void CScript_EventPseudoModel::SoapFaultString(CFXJSE_Value* pValue, | |
196 FX_BOOL bSetting, | |
197 XFA_ATTRIBUTE eAttribute) { | |
198 Property(pValue, XFA_Event::SoapFaultString, bSetting); | |
199 } | |
200 void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue, | |
201 FX_BOOL bSetting, | |
202 XFA_ATTRIBUTE eAttribute) { | |
203 Property(pValue, XFA_Event::Target, bSetting); | |
204 } | |
205 void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) { | |
206 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
207 if (!pScriptContext) { | |
208 return; | |
209 } | |
210 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | |
211 if (!pEventParam) { | |
212 return; | |
213 } | |
214 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
215 if (!pNotify) { | |
216 return; | |
217 } | |
218 CXFA_FFWidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler(); | |
219 if (!pWidgetHandler) { | |
220 return; | |
221 } | |
222 pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); | |
223 } | |
224 void CScript_EventPseudoModel::Reset(CFXJSE_Arguments* pArguments) { | |
225 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
226 if (!pScriptContext) { | |
227 return; | |
228 } | |
229 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | |
230 if (!pEventParam) { | |
231 return; | |
232 } | |
233 pEventParam->Reset(); | |
234 } | |
OLD | NEW |