Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(856)

Side by Side Diff: xfa/fxfa/parser/cxfa_scriptcontext.cpp

Issue 2165993002: Move xfa_basic_imp to cxfa_widetextread. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review feedback Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/parser/cxfa_para.cpp ('k') | xfa/fxfa/parser/cxfa_simple_parser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/cxfa_scriptcontext.h" 7 #include "xfa/fxfa/parser/cxfa_scriptcontext.h"
8 8
9 #include "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 #include "fxjs/include/cfxjse_arguments.h" 10 #include "fxjs/include/cfxjse_arguments.h"
11 #include "fxjs/include/cfxjse_class.h" 11 #include "fxjs/include/cfxjse_class.h"
12 #include "fxjs/include/cfxjse_value.h" 12 #include "fxjs/include/cfxjse_value.h"
13 #include "xfa/fxfa/app/xfa_ffnotify.h" 13 #include "xfa/fxfa/app/xfa_ffnotify.h"
14 #include "xfa/fxfa/include/cxfa_eventparam.h" 14 #include "xfa/fxfa/include/cxfa_eventparam.h"
15 #include "xfa/fxfa/parser/cxfa_nodehelper.h" 15 #include "xfa/fxfa/parser/cxfa_nodehelper.h"
16 #include "xfa/fxfa/parser/cxfa_resolveprocessor.h" 16 #include "xfa/fxfa/parser/cxfa_resolveprocessor.h"
17 #include "xfa/fxfa/parser/xfa_basic_data.h"
17 #include "xfa/fxfa/parser/xfa_doclayout.h" 18 #include "xfa/fxfa/parser/xfa_doclayout.h"
18 #include "xfa/fxfa/parser/xfa_document.h" 19 #include "xfa/fxfa/parser/xfa_document.h"
19 #include "xfa/fxfa/parser/xfa_localemgr.h" 20 #include "xfa/fxfa/parser/xfa_localemgr.h"
20 #include "xfa/fxfa/parser/xfa_object.h" 21 #include "xfa/fxfa/parser/xfa_object.h"
21 #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" 22 #include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
22 #include "xfa/fxfa/parser/xfa_utils.h" 23 #include "xfa/fxfa/parser/xfa_utils.h"
23 24
24 namespace { 25 namespace {
25 26
26 const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { 27 const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 nullptr, // property deleter 65 nullptr, // property deleter
65 CXFA_ScriptContext::NormalMethodCall, 66 CXFA_ScriptContext::NormalMethodCall,
66 }; 67 };
67 68
68 const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime"; 69 const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime";
69 70
70 CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { 71 CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) {
71 return static_cast<CXFA_ThisProxy*>(pValue->ToHostObject(pClass)); 72 return static_cast<CXFA_ThisProxy*>(pValue->ToHostObject(pClass));
72 } 73 }
73 74
75 const XFA_METHODINFO* GetMethodByName(XFA_Element eElement,
76 const CFX_WideStringC& wsMethodName) {
77 if (wsMethodName.IsEmpty())
78 return nullptr;
79
80 int32_t iElementIndex = static_cast<int32_t>(eElement);
81 while (iElementIndex >= 0 && iElementIndex < g_iScriptIndexCount) {
82 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex;
83 int32_t icount = scriptIndex->wMethodCount;
84 if (icount == 0) {
85 iElementIndex = scriptIndex->wParentIndex;
86 continue;
87 }
88 uint32_t uHash = FX_HashCode_GetW(wsMethodName, false);
89 int32_t iStart = scriptIndex->wMethodStart;
90 // TODO(dsinclair): Switch to std::lower_bound.
91 int32_t iEnd = iStart + icount - 1;
92 do {
93 int32_t iMid = (iStart + iEnd) / 2;
94 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid;
95 if (uHash == pInfo->uHash)
96 return pInfo;
97 if (uHash < pInfo->uHash)
98 iEnd = iMid - 1;
99 else
100 iStart = iMid + 1;
101 } while (iStart <= iEnd);
102 iElementIndex = scriptIndex->wParentIndex;
103 }
104 return nullptr;
105 }
106
74 } // namespace 107 } // namespace
75 108
76 // static. 109 // static.
77 CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, 110 CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue,
78 CFXJSE_Class* pClass) { 111 CFXJSE_Class* pClass) {
79 return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass)); 112 return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass));
80 } 113 }
81 114
82 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) 115 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument)
83 : m_pDocument(pDocument), 116 : m_pDocument(pDocument),
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 FX_BOOL bQueryIn) { 383 FX_BOOL bQueryIn) {
351 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); 384 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr);
352 if (!pObject) 385 if (!pObject)
353 return FXJSE_ClassPropType_None; 386 return FXJSE_ClassPropType_None;
354 387
355 CXFA_ScriptContext* lpScriptContext = 388 CXFA_ScriptContext* lpScriptContext =
356 pObject->GetDocument()->GetScriptContext(); 389 pObject->GetDocument()->GetScriptContext();
357 pObject = lpScriptContext->GetVariablesThis(pObject); 390 pObject = lpScriptContext->GetVariablesThis(pObject);
358 XFA_Element eType = pObject->GetElementType(); 391 XFA_Element eType = pObject->GetElementType();
359 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); 392 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName);
360 if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { 393 if (GetMethodByName(eType, wsPropName.AsStringC())) {
361 return FXJSE_ClassPropType_Method; 394 return FXJSE_ClassPropType_Method;
362 } 395 }
363 if (bQueryIn && 396 if (bQueryIn &&
364 !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringC())) { 397 !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringC())) {
365 return FXJSE_ClassPropType_None; 398 return FXJSE_ClassPropType_None;
366 } 399 }
367 return FXJSE_ClassPropType_Property; 400 return FXJSE_ClassPropType_Property;
368 } 401 }
369 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( 402 int32_t CXFA_ScriptContext::GlobalPropTypeGetter(
370 CFXJSE_Value* pOriginalValue, 403 CFXJSE_Value* pOriginalValue,
371 const CFX_ByteStringC& szPropName, 404 const CFX_ByteStringC& szPropName,
372 FX_BOOL bQueryIn) { 405 FX_BOOL bQueryIn) {
373 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); 406 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr);
374 if (!pObject) 407 if (!pObject)
375 return FXJSE_ClassPropType_None; 408 return FXJSE_ClassPropType_None;
376 409
377 CXFA_ScriptContext* lpScriptContext = 410 CXFA_ScriptContext* lpScriptContext =
378 pObject->GetDocument()->GetScriptContext(); 411 pObject->GetDocument()->GetScriptContext();
379 pObject = lpScriptContext->GetVariablesThis(pObject); 412 pObject = lpScriptContext->GetVariablesThis(pObject);
380 XFA_Element eType = pObject->GetElementType(); 413 XFA_Element eType = pObject->GetElementType();
381 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); 414 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName);
382 if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { 415 if (GetMethodByName(eType, wsPropName.AsStringC())) {
383 return FXJSE_ClassPropType_Method; 416 return FXJSE_ClassPropType_Method;
384 } 417 }
385 return FXJSE_ClassPropType_Property; 418 return FXJSE_ClassPropType_Property;
386 } 419 }
387 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, 420 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis,
388 const CFX_ByteStringC& szFuncName, 421 const CFX_ByteStringC& szFuncName,
389 CFXJSE_Arguments& args) { 422 CFXJSE_Arguments& args) {
390 CXFA_Object* pObject = ToObject(pThis, nullptr); 423 CXFA_Object* pObject = ToObject(pThis, nullptr);
391 if (!pObject) 424 if (!pObject)
392 return; 425 return;
393 426
394 CXFA_ScriptContext* lpScriptContext = 427 CXFA_ScriptContext* lpScriptContext =
395 pObject->GetDocument()->GetScriptContext(); 428 pObject->GetDocument()->GetScriptContext();
396 pObject = lpScriptContext->GetVariablesThis(pObject); 429 pObject = lpScriptContext->GetVariablesThis(pObject);
397 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); 430 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName);
398 const XFA_METHODINFO* lpMethodInfo = 431 const XFA_METHODINFO* lpMethodInfo =
399 XFA_GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); 432 GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC());
400 if (!lpMethodInfo) 433 if (!lpMethodInfo)
401 return; 434 return;
402 435
403 (pObject->*(lpMethodInfo->lpfnCallback))(&args); 436 (pObject->*(lpMethodInfo->lpfnCallback))(&args);
404 } 437 }
405 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { 438 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() {
406 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); 439 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping);
407 } 440 }
408 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { 441 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() {
409 return m_eScriptType; 442 return m_eScriptType;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 return; 763 return;
731 if (nodes.GetSize() > 0) 764 if (nodes.GetSize() > 0)
732 m_pScriptNodeArray->Copy(nodes); 765 m_pScriptNodeArray->Copy(nodes);
733 } 766 }
734 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { 767 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) {
735 if (!m_pScriptNodeArray) 768 if (!m_pScriptNodeArray)
736 return; 769 return;
737 if (m_pScriptNodeArray->Find(pNode) == -1) 770 if (m_pScriptNodeArray->Find(pNode) == -1)
738 m_pScriptNodeArray->Add(pNode); 771 m_pScriptNodeArray->Add(pNode);
739 } 772 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/cxfa_para.cpp ('k') | xfa/fxfa/parser/cxfa_simple_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698