OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 <memory> | |
8 | |
9 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. | |
10 #include "fpdfsdk/include/javascript/IJavaScript.h" | |
11 | |
12 class CJS_ContextStub final : public IJS_Context { | |
13 public: | |
14 CJS_ContextStub() {} | |
15 ~CJS_ContextStub() override {} | |
16 | |
17 // IJS_Context: | |
18 FX_BOOL RunScript(const CFX_WideString& script, | |
19 CFX_WideString* info) override { | |
20 return FALSE; | |
21 } | |
22 | |
23 void OnApp_Init() override {} | |
24 void OnDoc_Open(CPDFSDK_Document* pDoc, | |
25 const CFX_WideString& strTargetName) override {} | |
26 void OnDoc_WillPrint(CPDFSDK_Document* pDoc) override {} | |
27 void OnDoc_DidPrint(CPDFSDK_Document* pDoc) override {} | |
28 void OnDoc_WillSave(CPDFSDK_Document* pDoc) override {} | |
29 void OnDoc_DidSave(CPDFSDK_Document* pDoc) override {} | |
30 void OnDoc_WillClose(CPDFSDK_Document* pDoc) override {} | |
31 void OnPage_Open(CPDFSDK_Document* pTarget) override {} | |
32 void OnPage_Close(CPDFSDK_Document* pTarget) override {} | |
33 void OnPage_InView(CPDFSDK_Document* pTarget) override {} | |
34 void OnPage_OutView(CPDFSDK_Document* pTarget) override {} | |
35 void OnField_MouseDown(FX_BOOL bModifier, | |
36 FX_BOOL bShift, | |
37 CPDF_FormField* pTarget) override {} | |
38 void OnField_MouseEnter(FX_BOOL bModifier, | |
39 FX_BOOL bShift, | |
40 CPDF_FormField* pTarget) override {} | |
41 void OnField_MouseExit(FX_BOOL bModifier, | |
42 FX_BOOL bShift, | |
43 CPDF_FormField* pTarget) override {} | |
44 void OnField_MouseUp(FX_BOOL bModifier, | |
45 FX_BOOL bShift, | |
46 CPDF_FormField* pTarget) override {} | |
47 void OnField_Focus(FX_BOOL bModifier, | |
48 FX_BOOL bShift, | |
49 CPDF_FormField* pTarget, | |
50 const CFX_WideString& Value) override {} | |
51 void OnField_Blur(FX_BOOL bModifier, | |
52 FX_BOOL bShift, | |
53 CPDF_FormField* pTarget, | |
54 const CFX_WideString& Value) override {} | |
55 void OnField_Calculate(CPDF_FormField* pSource, | |
56 CPDF_FormField* pTarget, | |
57 CFX_WideString& Value, | |
58 FX_BOOL& bRc) override {} | |
59 void OnField_Format(CPDF_FormField* pTarget, | |
60 CFX_WideString& Value, | |
61 FX_BOOL bWillCommit) override {} | |
62 void OnField_Keystroke(CFX_WideString& strChange, | |
63 const CFX_WideString& strChangeEx, | |
64 FX_BOOL KeyDown, | |
65 FX_BOOL bModifier, | |
66 int& nSelEnd, | |
67 int& nSelStart, | |
68 FX_BOOL bShift, | |
69 CPDF_FormField* pTarget, | |
70 CFX_WideString& Value, | |
71 FX_BOOL bWillCommit, | |
72 FX_BOOL bFieldFull, | |
73 FX_BOOL& bRc) override {} | |
74 void OnField_Validate(CFX_WideString& strChange, | |
75 const CFX_WideString& strChangeEx, | |
76 FX_BOOL bKeyDown, | |
77 FX_BOOL bModifier, | |
78 FX_BOOL bShift, | |
79 CPDF_FormField* pTarget, | |
80 CFX_WideString& Value, | |
81 FX_BOOL& bRc) override {} | |
82 void OnScreen_Focus(FX_BOOL bModifier, | |
83 FX_BOOL bShift, | |
84 CPDFSDK_Annot* pScreen) override {} | |
85 void OnScreen_Blur(FX_BOOL bModifier, | |
86 FX_BOOL bShift, | |
87 CPDFSDK_Annot* pScreen) override {} | |
88 void OnScreen_Open(FX_BOOL bModifier, | |
89 FX_BOOL bShift, | |
90 CPDFSDK_Annot* pScreen) override {} | |
91 void OnScreen_Close(FX_BOOL bModifier, | |
92 FX_BOOL bShift, | |
93 CPDFSDK_Annot* pScreen) override {} | |
94 void OnScreen_MouseDown(FX_BOOL bModifier, | |
95 FX_BOOL bShift, | |
96 CPDFSDK_Annot* pScreen) override {} | |
97 void OnScreen_MouseUp(FX_BOOL bModifier, | |
98 FX_BOOL bShift, | |
99 CPDFSDK_Annot* pScreen) override {} | |
100 void OnScreen_MouseEnter(FX_BOOL bModifier, | |
101 FX_BOOL bShift, | |
102 CPDFSDK_Annot* pScreen) override {} | |
103 void OnScreen_MouseExit(FX_BOOL bModifier, | |
104 FX_BOOL bShift, | |
105 CPDFSDK_Annot* pScreen) override {} | |
106 void OnScreen_InView(FX_BOOL bModifier, | |
107 FX_BOOL bShift, | |
108 CPDFSDK_Annot* pScreen) override {} | |
109 void OnScreen_OutView(FX_BOOL bModifier, | |
110 FX_BOOL bShift, | |
111 CPDFSDK_Annot* pScreen) override {} | |
112 void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) override {} | |
113 void OnLink_MouseUp(CPDFSDK_Document* pTarget) override {} | |
114 void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString&) override {} | |
115 void OnBatchExec(CPDFSDK_Document* pTarget) override {} | |
116 void OnConsole_Exec() override {} | |
117 void OnExternal_Exec() override {} | |
118 void EnableMessageBox(FX_BOOL bEnable) override {} | |
119 }; | |
120 | |
121 class CJS_RuntimeStub final : public IJS_Runtime { | |
122 public: | |
123 CJS_RuntimeStub() : m_pDoc(nullptr) {} | |
124 ~CJS_RuntimeStub() override {} | |
125 | |
126 IJS_Context* NewContext() override { | |
127 if (!m_pContext) | |
128 m_pContext.reset(new CJS_ContextStub()); | |
129 return GetCurrentContext(); | |
130 } | |
131 | |
132 IJS_Context* GetCurrentContext() override { return m_pContext.get(); } | |
133 void ReleaseContext(IJS_Context* pContext) override {} | |
134 | |
135 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override { | |
136 m_pDoc = pReaderDoc; | |
137 } | |
138 CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; } | |
139 | |
140 #ifdef PDF_ENABLE_XFA | |
141 FX_BOOL GetHValueByName(const CFX_ByteStringC&, FXJSE_HVALUE) override { | |
142 return FALSE; | |
143 } | |
144 | |
145 FX_BOOL SetHValueByName(const CFX_ByteStringC&, FXJSE_HVALUE) override { | |
146 return FALSE; | |
147 } | |
148 #endif // PDF_ENABLE_XFA | |
149 | |
150 int Execute(IJS_Context* cc, | |
151 const wchar_t* script, | |
152 CFX_WideString* info) override { | |
153 return 0; | |
154 } | |
155 | |
156 protected: | |
157 CPDFSDK_Document* m_pDoc; | |
158 std::unique_ptr<CJS_ContextStub> m_pContext; | |
159 }; | |
160 | |
161 // static | |
162 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { | |
163 } | |
164 | |
165 // static | |
166 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { | |
167 return new CJS_RuntimeStub; | |
168 } | |
OLD | NEW |