Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fxfa / src / common / xfa_script.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FXFA_SCRIPT_H\r
8 #define _FXFA_SCRIPT_H\r
9 #define XFA_RESOLVENODE_Children                        0x0001\r
10 #define XFA_RESOLVENODE_Attributes                      0x0004\r
11 #define XFA_RESOLVENODE_Properties                      0x0008\r
12 #define XFA_RESOLVENODE_Siblings                        0x0020\r
13 #define XFA_RESOLVENODE_Parent                          0x0040\r
14 #define XFA_RESOLVENODE_AnyChild                        0x0080\r
15 #define XFA_RESOLVENODE_ALL                                     0x0100\r
16 #define XFA_RESOLVENODE_CreateNode                      0x0400\r
17 #define XFA_RESOLVENODE_Bind                            0x0800\r
18 #define XFA_RESOLVENODE_BindNew                         0x1000\r
19 enum XFA_SCRIPTLANGTYPE {\r
20     XFA_SCRIPTLANGTYPE_Formcalc = XFA_SCRIPTTYPE_Formcalc,\r
21     XFA_SCRIPTLANGTYPE_Javascript = XFA_SCRIPTTYPE_Javascript,\r
22     XFA_SCRIPTLANGTYPE_Unkown = XFA_SCRIPTTYPE_Unkown,\r
23 };\r
24 enum XFA_RESOVENODE_RSTYPE {\r
25     XFA_RESOVENODE_RSTYPE_Nodes,\r
26     XFA_RESOVENODE_RSTYPE_Attribute,\r
27     XFA_RESOLVENODE_RSTYPE_CreateNodeOne,\r
28     XFA_RESOLVENODE_RSTYPE_CreateNodeAll,\r
29     XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll,\r
30     XFA_RESOVENODE_RSTYPE_ExistNodes,\r
31 };\r
32 class CXFA_HVALUEArray : public CFX_ArrayTemplate<FXJSE_HVALUE>\r
33 {\r
34 public:\r
35     CXFA_HVALUEArray(FXJSE_HRUNTIME hRunTime) : m_hRunTime(hRunTime) {};\r
36     ~CXFA_HVALUEArray()\r
37     {\r
38         for (FX_INT32 i = 0; i < GetSize(); i++) {\r
39             FXJSE_Value_Release(GetAt(i));\r
40         }\r
41     }\r
42     void GetAttributeObject(CXFA_ObjArray& objArray)\r
43     {\r
44         for (FX_INT32 i = 0; i < GetSize(); i++) {\r
45             CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(GetAt(i), NULL);\r
46             objArray.Add(pObject);\r
47         }\r
48     }\r
49     FXJSE_HRUNTIME              m_hRunTime;\r
50 };\r
51 typedef struct _XFA_RESOLVENODE_RS : public CFX_Object {\r
52     _XFA_RESOLVENODE_RS() : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(NULL) { }\r
53     ~_XFA_RESOLVENODE_RS()\r
54     {\r
55         nodes.RemoveAll();\r
56     }\r
57     FX_INT32 GetAttributeResult(CXFA_HVALUEArray& hValueArray) const\r
58     {\r
59         if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) {\r
60             FXJSE_HRUNTIME hRunTime = hValueArray.m_hRunTime;\r
61             for (FX_INT32 i = 0; i < nodes.GetSize(); i++) {\r
62                 FXJSE_HVALUE hValue = FXJSE_Value_Create(hRunTime);\r
63                 (nodes[i]->*(pScriptAttribute->lpfnCallback))(hValue, FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute);\r
64                 hValueArray.Add(hValue);\r
65             }\r
66         }\r
67         return hValueArray.GetSize();\r
68     }\r
69     CXFA_ObjArray                               nodes;\r
70     XFA_LPCSCRIPTATTRIBUTEINFO  pScriptAttribute;\r
71     XFA_RESOVENODE_RSTYPE               dwFlags;\r
72 } XFA_RESOLVENODE_RS, * XFA_LPRESOLVENODE_RS;\r
73 typedef struct _XFA_JSBUILTININFO {\r
74     FX_UINT32                                           uUnicodeHash;\r
75     FX_LPCSTR                                           pName;\r
76 } XFA_JSBUILTININFO, * XFA_LPJSBUILTININFO;\r
77 typedef XFA_JSBUILTININFO const * XFA_LPCJSBUILTININFO;\r
78 XFA_LPCJSBUILTININFO XFA_GetJSBuiltinByHash(FX_UINT32 uHashCode);\r
79 class IXFA_ScriptContext\r
80 {\r
81 public:\r
82     virtual void        Release() = 0;\r
83     virtual void        Initialize(FXJSE_HRUNTIME hRuntime) = 0;\r
84 \r
85     virtual void                                SetEventParam(CXFA_EventParam* pEventParam) = 0;\r
86     virtual CXFA_EventParam*    GetEventParam() = 0;\r
87     virtual FX_BOOL             RunScript(XFA_SCRIPTLANGTYPE eScriptType, FX_WSTR wsScript, FXJSE_HVALUE hRetValue, CXFA_Object* pThisObject = NULL) = 0;\r
88     virtual FX_INT32    ResolveObjects(CXFA_Object* refNode, FX_WSTR wsExpression, XFA_RESOLVENODE_RS& resolveNodeRS, FX_DWORD dwStyles = XFA_RESOLVENODE_Children, CXFA_Node* bindNode = NULL) = 0;\r
89     virtual FXJSE_HVALUE                GetJSValueFromMap(CXFA_Object* pObject) = 0;\r
90     virtual void                                CacheList(CXFA_NodeList* pList) = 0;\r
91     virtual CXFA_Object*                GetThisObject() const = 0;\r
92     virtual FXJSE_HRUNTIME              GetRuntime() const = 0;\r
93     virtual FX_INT32                    GetIndexByName(CXFA_Node* refNode) = 0;\r
94     virtual FX_INT32                    GetIndexByClassName(CXFA_Node* refNode) = 0;\r
95     virtual void                                GetSomExpression(CXFA_Node* refNode, CFX_WideString &wsExpression) = 0;\r
96 \r
97     virtual void                                SetNodesOfRunScript(CXFA_NodeArray *pArray) = 0;\r
98     virtual void                                AddNodesOfRunScript(const CXFA_NodeArray& nodes) = 0;\r
99     virtual void                                AddNodesOfRunScript(CXFA_Node* pNode) = 0;\r
100     virtual FXJSE_HCLASS                GetJseNormalClass() = 0;\r
101     virtual XFA_SCRIPTLANGTYPE  GetType() = 0;\r
102     virtual     void                            AddJSBuiltinObject(XFA_LPCJSBUILTININFO pBuitinObject) = 0;\r
103     virtual     void                            SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) = 0;\r
104     virtual FX_BOOL                             IsRunAtClient() = 0;\r
105 };\r
106 IXFA_ScriptContext* XFA_ScriptContext_Create(CXFA_Document* pDocument);\r
107 #endif\r