| 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 "event.h" | 7 #include "event.h" |
| 8 | 8 |
| 9 #include "Field.h" | 9 #include "Field.h" |
| 10 #include "JS_Context.h" | 10 #include "JS_Context.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} | 50 event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} |
| 51 | 51 |
| 52 event::~event() { | 52 event::~event() { |
| 53 } | 53 } |
| 54 | 54 |
| 55 FX_BOOL event::change(IJS_Context* cc, | 55 FX_BOOL event::change(IJS_Context* cc, |
| 56 CJS_PropValue& vp, | 56 CJS_PropValue& vp, |
| 57 CFX_WideString& sError) { | 57 CFX_WideString& sError) { |
| 58 CJS_Context* pContext = (CJS_Context*)cc; | 58 CJS_Context* pContext = (CJS_Context*)cc; |
| 59 ASSERT(pContext != NULL); | |
| 60 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 59 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 61 ASSERT(pEvent != NULL); | |
| 62 | |
| 63 CFX_WideString& wChange = pEvent->Change(); | 60 CFX_WideString& wChange = pEvent->Change(); |
| 64 if (vp.IsSetting()) { | 61 if (vp.IsSetting()) { |
| 65 if (vp.GetType() == CJS_Value::VT_string) | 62 if (vp.GetType() == CJS_Value::VT_string) |
| 66 vp >> wChange; | 63 vp >> wChange; |
| 67 } else { | 64 } else { |
| 68 vp << wChange; | 65 vp << wChange; |
| 69 } | 66 } |
| 70 return TRUE; | 67 return TRUE; |
| 71 } | 68 } |
| 72 | 69 |
| 73 FX_BOOL event::changeEx(IJS_Context* cc, | 70 FX_BOOL event::changeEx(IJS_Context* cc, |
| 74 CJS_PropValue& vp, | 71 CJS_PropValue& vp, |
| 75 CFX_WideString& sError) { | 72 CFX_WideString& sError) { |
| 76 if (!vp.IsGetting()) | 73 if (!vp.IsGetting()) |
| 77 return FALSE; | 74 return FALSE; |
| 78 | 75 |
| 79 CJS_Context* pContext = (CJS_Context*)cc; | 76 CJS_Context* pContext = (CJS_Context*)cc; |
| 80 ASSERT(pContext != NULL); | |
| 81 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 77 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 82 ASSERT(pEvent != NULL); | |
| 83 | 78 |
| 84 vp << pEvent->ChangeEx(); | 79 vp << pEvent->ChangeEx(); |
| 85 return TRUE; | 80 return TRUE; |
| 86 } | 81 } |
| 87 | 82 |
| 88 FX_BOOL event::commitKey(IJS_Context* cc, | 83 FX_BOOL event::commitKey(IJS_Context* cc, |
| 89 CJS_PropValue& vp, | 84 CJS_PropValue& vp, |
| 90 CFX_WideString& sError) { | 85 CFX_WideString& sError) { |
| 91 if (!vp.IsGetting()) | 86 if (!vp.IsGetting()) |
| 92 return FALSE; | 87 return FALSE; |
| 93 | 88 |
| 94 CJS_Context* pContext = (CJS_Context*)cc; | 89 CJS_Context* pContext = (CJS_Context*)cc; |
| 95 ASSERT(pContext != NULL); | |
| 96 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 90 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 97 ASSERT(pEvent != NULL); | |
| 98 | 91 |
| 99 vp << pEvent->CommitKey(); | 92 vp << pEvent->CommitKey(); |
| 100 return TRUE; | 93 return TRUE; |
| 101 } | 94 } |
| 102 | 95 |
| 103 FX_BOOL event::fieldFull(IJS_Context* cc, | 96 FX_BOOL event::fieldFull(IJS_Context* cc, |
| 104 CJS_PropValue& vp, | 97 CJS_PropValue& vp, |
| 105 CFX_WideString& sError) { | 98 CFX_WideString& sError) { |
| 106 CJS_Context* pContext = (CJS_Context*)cc; | 99 CJS_Context* pContext = (CJS_Context*)cc; |
| 107 ASSERT(pContext != NULL); | |
| 108 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 100 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 109 ASSERT(pEvent != NULL); | |
| 110 | 101 |
| 111 if (!vp.IsGetting() && | 102 if (!vp.IsGetting() && |
| 112 wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) | 103 wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
| 113 return FALSE; | 104 return FALSE; |
| 114 | 105 |
| 115 if (pEvent->FieldFull()) | 106 if (pEvent->FieldFull()) |
| 116 vp << TRUE; | 107 vp << TRUE; |
| 117 else | 108 else |
| 118 vp << FALSE; | 109 vp << FALSE; |
| 119 return TRUE; | 110 return TRUE; |
| 120 } | 111 } |
| 121 | 112 |
| 122 FX_BOOL event::keyDown(IJS_Context* cc, | 113 FX_BOOL event::keyDown(IJS_Context* cc, |
| 123 CJS_PropValue& vp, | 114 CJS_PropValue& vp, |
| 124 CFX_WideString& sError) { | 115 CFX_WideString& sError) { |
| 125 if (!vp.IsGetting()) | 116 if (!vp.IsGetting()) |
| 126 return FALSE; | 117 return FALSE; |
| 127 | 118 |
| 128 CJS_Context* pContext = (CJS_Context*)cc; | 119 CJS_Context* pContext = (CJS_Context*)cc; |
| 129 ASSERT(pContext != NULL); | |
| 130 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 120 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 131 ASSERT(pEvent != NULL); | |
| 132 | 121 |
| 133 if (pEvent->KeyDown()) | 122 if (pEvent->KeyDown()) |
| 134 vp << TRUE; | 123 vp << TRUE; |
| 135 else | 124 else |
| 136 vp << FALSE; | 125 vp << FALSE; |
| 137 return TRUE; | 126 return TRUE; |
| 138 } | 127 } |
| 139 | 128 |
| 140 FX_BOOL event::modifier(IJS_Context* cc, | 129 FX_BOOL event::modifier(IJS_Context* cc, |
| 141 CJS_PropValue& vp, | 130 CJS_PropValue& vp, |
| 142 CFX_WideString& sError) { | 131 CFX_WideString& sError) { |
| 143 if (!vp.IsGetting()) | 132 if (!vp.IsGetting()) |
| 144 return FALSE; | 133 return FALSE; |
| 145 | 134 |
| 146 CJS_Context* pContext = (CJS_Context*)cc; | 135 CJS_Context* pContext = (CJS_Context*)cc; |
| 147 ASSERT(pContext != NULL); | |
| 148 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 136 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 149 ASSERT(pEvent != NULL); | |
| 150 | 137 |
| 151 if (pEvent->Modifier()) | 138 if (pEvent->Modifier()) |
| 152 vp << TRUE; | 139 vp << TRUE; |
| 153 else | 140 else |
| 154 vp << FALSE; | 141 vp << FALSE; |
| 155 return TRUE; | 142 return TRUE; |
| 156 } | 143 } |
| 157 | 144 |
| 158 FX_BOOL event::name(IJS_Context* cc, | 145 FX_BOOL event::name(IJS_Context* cc, |
| 159 CJS_PropValue& vp, | 146 CJS_PropValue& vp, |
| 160 CFX_WideString& sError) { | 147 CFX_WideString& sError) { |
| 161 if (!vp.IsGetting()) | 148 if (!vp.IsGetting()) |
| 162 return FALSE; | 149 return FALSE; |
| 163 | 150 |
| 164 CJS_Context* pContext = (CJS_Context*)cc; | 151 CJS_Context* pContext = (CJS_Context*)cc; |
| 165 ASSERT(pContext != NULL); | |
| 166 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 152 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 167 ASSERT(pEvent != NULL); | |
| 168 | 153 |
| 169 vp << pEvent->Name(); | 154 vp << pEvent->Name(); |
| 170 return TRUE; | 155 return TRUE; |
| 171 } | 156 } |
| 172 | 157 |
| 173 FX_BOOL event::rc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 158 FX_BOOL event::rc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 174 CJS_Context* pContext = (CJS_Context*)cc; | 159 CJS_Context* pContext = (CJS_Context*)cc; |
| 175 ASSERT(pContext != NULL); | |
| 176 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 160 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 177 ASSERT(pEvent != NULL); | |
| 178 | 161 |
| 179 FX_BOOL& bRc = pEvent->Rc(); | 162 FX_BOOL& bRc = pEvent->Rc(); |
| 180 if (vp.IsSetting()) { | 163 if (vp.IsSetting()) { |
| 181 vp >> bRc; | 164 vp >> bRc; |
| 182 } else { | 165 } else { |
| 183 vp << bRc; | 166 vp << bRc; |
| 184 } | 167 } |
| 185 return TRUE; | 168 return TRUE; |
| 186 } | 169 } |
| 187 | 170 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 215 } else { | 198 } else { |
| 216 ; | 199 ; |
| 217 } | 200 } |
| 218 return TRUE; | 201 return TRUE; |
| 219 } | 202 } |
| 220 | 203 |
| 221 FX_BOOL event::selEnd(IJS_Context* cc, | 204 FX_BOOL event::selEnd(IJS_Context* cc, |
| 222 CJS_PropValue& vp, | 205 CJS_PropValue& vp, |
| 223 CFX_WideString& sError) { | 206 CFX_WideString& sError) { |
| 224 CJS_Context* pContext = (CJS_Context*)cc; | 207 CJS_Context* pContext = (CJS_Context*)cc; |
| 225 ASSERT(pContext != NULL); | |
| 226 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 208 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 227 ASSERT(pEvent != NULL); | |
| 228 | 209 |
| 229 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) { | 210 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) { |
| 230 return TRUE; | 211 return TRUE; |
| 231 } | 212 } |
| 232 | 213 |
| 233 int& iSelEnd = pEvent->SelEnd(); | 214 int& iSelEnd = pEvent->SelEnd(); |
| 234 if (vp.IsSetting()) { | 215 if (vp.IsSetting()) { |
| 235 vp >> iSelEnd; | 216 vp >> iSelEnd; |
| 236 } else { | 217 } else { |
| 237 vp << iSelEnd; | 218 vp << iSelEnd; |
| 238 } | 219 } |
| 239 return TRUE; | 220 return TRUE; |
| 240 } | 221 } |
| 241 | 222 |
| 242 FX_BOOL event::selStart(IJS_Context* cc, | 223 FX_BOOL event::selStart(IJS_Context* cc, |
| 243 CJS_PropValue& vp, | 224 CJS_PropValue& vp, |
| 244 CFX_WideString& sError) { | 225 CFX_WideString& sError) { |
| 245 CJS_Context* pContext = (CJS_Context*)cc; | 226 CJS_Context* pContext = (CJS_Context*)cc; |
| 246 ASSERT(pContext != NULL); | |
| 247 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 227 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 248 ASSERT(pEvent != NULL); | |
| 249 | 228 |
| 250 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) { | 229 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) { |
| 251 return TRUE; | 230 return TRUE; |
| 252 } | 231 } |
| 253 int& iSelStart = pEvent->SelStart(); | 232 int& iSelStart = pEvent->SelStart(); |
| 254 if (vp.IsSetting()) { | 233 if (vp.IsSetting()) { |
| 255 vp >> iSelStart; | 234 vp >> iSelStart; |
| 256 } else { | 235 } else { |
| 257 vp << iSelStart; | 236 vp << iSelStart; |
| 258 } | 237 } |
| 259 return TRUE; | 238 return TRUE; |
| 260 } | 239 } |
| 261 | 240 |
| 262 FX_BOOL event::shift(IJS_Context* cc, | 241 FX_BOOL event::shift(IJS_Context* cc, |
| 263 CJS_PropValue& vp, | 242 CJS_PropValue& vp, |
| 264 CFX_WideString& sError) { | 243 CFX_WideString& sError) { |
| 265 if (!vp.IsGetting()) | 244 if (!vp.IsGetting()) |
| 266 return FALSE; | 245 return FALSE; |
| 267 | 246 |
| 268 CJS_Context* pContext = (CJS_Context*)cc; | 247 CJS_Context* pContext = (CJS_Context*)cc; |
| 269 ASSERT(pContext != NULL); | |
| 270 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 248 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 271 ASSERT(pEvent != NULL); | |
| 272 | 249 |
| 273 if (pEvent->Shift()) | 250 if (pEvent->Shift()) |
| 274 vp << TRUE; | 251 vp << TRUE; |
| 275 else | 252 else |
| 276 vp << FALSE; | 253 vp << FALSE; |
| 277 return TRUE; | 254 return TRUE; |
| 278 } | 255 } |
| 279 | 256 |
| 280 FX_BOOL event::source(IJS_Context* cc, | 257 FX_BOOL event::source(IJS_Context* cc, |
| 281 CJS_PropValue& vp, | 258 CJS_PropValue& vp, |
| 282 CFX_WideString& sError) { | 259 CFX_WideString& sError) { |
| 283 if (!vp.IsGetting()) | 260 if (!vp.IsGetting()) |
| 284 return FALSE; | 261 return FALSE; |
| 285 | 262 |
| 286 CJS_Context* pContext = (CJS_Context*)cc; | 263 CJS_Context* pContext = (CJS_Context*)cc; |
| 287 ASSERT(pContext != NULL); | |
| 288 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 264 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 289 ASSERT(pEvent != NULL); | |
| 290 | 265 |
| 291 vp << pEvent->Source()->GetJSObject(); | 266 vp << pEvent->Source()->GetJSObject(); |
| 292 return TRUE; | 267 return TRUE; |
| 293 } | 268 } |
| 294 | 269 |
| 295 FX_BOOL event::target(IJS_Context* cc, | 270 FX_BOOL event::target(IJS_Context* cc, |
| 296 CJS_PropValue& vp, | 271 CJS_PropValue& vp, |
| 297 CFX_WideString& sError) { | 272 CFX_WideString& sError) { |
| 298 if (!vp.IsGetting()) | 273 if (!vp.IsGetting()) |
| 299 return FALSE; | 274 return FALSE; |
| 300 | 275 |
| 301 CJS_Context* pContext = (CJS_Context*)cc; | 276 CJS_Context* pContext = (CJS_Context*)cc; |
| 302 ASSERT(pContext != NULL); | |
| 303 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 277 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 304 ASSERT(pEvent != NULL); | |
| 305 | 278 |
| 306 vp << pEvent->Target_Field()->GetJSObject(); | 279 vp << pEvent->Target_Field()->GetJSObject(); |
| 307 return TRUE; | 280 return TRUE; |
| 308 } | 281 } |
| 309 | 282 |
| 310 FX_BOOL event::targetName(IJS_Context* cc, | 283 FX_BOOL event::targetName(IJS_Context* cc, |
| 311 CJS_PropValue& vp, | 284 CJS_PropValue& vp, |
| 312 CFX_WideString& sError) { | 285 CFX_WideString& sError) { |
| 313 if (!vp.IsGetting()) | 286 if (!vp.IsGetting()) |
| 314 return FALSE; | 287 return FALSE; |
| 315 | 288 |
| 316 CJS_Context* pContext = (CJS_Context*)cc; | 289 CJS_Context* pContext = (CJS_Context*)cc; |
| 317 ASSERT(pContext != NULL); | |
| 318 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 290 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 319 ASSERT(pEvent != NULL); | |
| 320 | 291 |
| 321 vp << pEvent->TargetName(); | 292 vp << pEvent->TargetName(); |
| 322 return TRUE; | 293 return TRUE; |
| 323 } | 294 } |
| 324 | 295 |
| 325 FX_BOOL event::type(IJS_Context* cc, | 296 FX_BOOL event::type(IJS_Context* cc, |
| 326 CJS_PropValue& vp, | 297 CJS_PropValue& vp, |
| 327 CFX_WideString& sError) { | 298 CFX_WideString& sError) { |
| 328 if (!vp.IsGetting()) | 299 if (!vp.IsGetting()) |
| 329 return FALSE; | 300 return FALSE; |
| 330 | 301 |
| 331 CJS_Context* pContext = (CJS_Context*)cc; | 302 CJS_Context* pContext = (CJS_Context*)cc; |
| 332 ASSERT(pContext != NULL); | |
| 333 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 303 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 334 ASSERT(pEvent != NULL); | |
| 335 | 304 |
| 336 vp << pEvent->Type(); | 305 vp << pEvent->Type(); |
| 337 return TRUE; | 306 return TRUE; |
| 338 } | 307 } |
| 339 | 308 |
| 340 FX_BOOL event::value(IJS_Context* cc, | 309 FX_BOOL event::value(IJS_Context* cc, |
| 341 CJS_PropValue& vp, | 310 CJS_PropValue& vp, |
| 342 CFX_WideString& sError) { | 311 CFX_WideString& sError) { |
| 343 CJS_Context* pContext = (CJS_Context*)cc; | 312 CJS_Context* pContext = (CJS_Context*)cc; |
| 344 ASSERT(pContext != NULL); | |
| 345 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 313 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 346 ASSERT(pEvent != NULL); | |
| 347 | 314 |
| 348 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) | 315 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) |
| 349 return FALSE; | 316 return FALSE; |
| 350 if (!pEvent->m_pValue) | 317 if (!pEvent->m_pValue) |
| 351 return FALSE; | 318 return FALSE; |
| 352 CFX_WideString& val = pEvent->Value(); | 319 CFX_WideString& val = pEvent->Value(); |
| 353 if (vp.IsSetting()) { | 320 if (vp.IsSetting()) { |
| 354 vp >> val; | 321 vp >> val; |
| 355 } else { | 322 } else { |
| 356 vp << val; | 323 vp << val; |
| 357 } | 324 } |
| 358 return TRUE; | 325 return TRUE; |
| 359 } | 326 } |
| 360 | 327 |
| 361 FX_BOOL event::willCommit(IJS_Context* cc, | 328 FX_BOOL event::willCommit(IJS_Context* cc, |
| 362 CJS_PropValue& vp, | 329 CJS_PropValue& vp, |
| 363 CFX_WideString& sError) { | 330 CFX_WideString& sError) { |
| 364 if (!vp.IsGetting()) | 331 if (!vp.IsGetting()) |
| 365 return FALSE; | 332 return FALSE; |
| 366 | 333 |
| 367 CJS_Context* pContext = (CJS_Context*)cc; | 334 CJS_Context* pContext = (CJS_Context*)cc; |
| 368 ASSERT(pContext != NULL); | |
| 369 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 335 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 370 ASSERT(pEvent != NULL); | |
| 371 | 336 |
| 372 if (pEvent->WillCommit()) | 337 if (pEvent->WillCommit()) |
| 373 vp << TRUE; | 338 vp << TRUE; |
| 374 else | 339 else |
| 375 vp << FALSE; | 340 vp << FALSE; |
| 376 return TRUE; | 341 return TRUE; |
| 377 } | 342 } |
| OLD | NEW |