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 "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. | |
8 #include "../../include/javascript/IJavaScript.h" | |
9 | |
10 #include <algorithm> | |
11 #include <vector> | |
12 | |
13 class CJS_ContextStub final : public IJS_Context { | |
14 public: | |
15 CJS_ContextStub(IJS_Runtime* pRuntime) : m_pRuntime(pRuntime) {} | |
16 ~CJS_ContextStub() override {} | |
17 | |
18 // IJS_Context: | |
19 FX_BOOL RunScript(const CFX_WideString& script, | |
20 CFX_WideString& info) override { | |
21 return FALSE; | |
22 } | |
23 | |
24 void OnApp_Init() override {} | |
25 void OnDoc_Open(CPDFSDK_Document* pDoc, | |
26 const CFX_WideString& strTargetName) override {} | |
27 void OnDoc_WillPrint(CPDFSDK_Document* pDoc) override {} | |
28 void OnDoc_DidPrint(CPDFSDK_Document* pDoc) override {} | |
29 void OnDoc_WillSave(CPDFSDK_Document* pDoc) override {} | |
30 void OnDoc_DidSave(CPDFSDK_Document* pDoc) override {} | |
31 void OnDoc_WillClose(CPDFSDK_Document* pDoc) override {} | |
32 void OnPage_Open(CPDFSDK_Document* pTarget) override {} | |
33 void OnPage_Close(CPDFSDK_Document* pTarget) override {} | |
34 void OnPage_InView(CPDFSDK_Document* pTarget) override {} | |
35 void OnPage_OutView(CPDFSDK_Document* pTarget) override {} | |
36 void OnField_MouseDown(FX_BOOL bModifier, | |
37 FX_BOOL bShift, | |
38 CPDF_FormField* pTarget) override {} | |
39 void OnField_MouseEnter(FX_BOOL bModifier, | |
40 FX_BOOL bShift, | |
41 CPDF_FormField* pTarget) override {} | |
42 void OnField_MouseExit(FX_BOOL bModifier, | |
43 FX_BOOL bShift, | |
44 CPDF_FormField* pTarget) override {} | |
45 void OnField_MouseUp(FX_BOOL bModifier, | |
46 FX_BOOL bShift, | |
47 CPDF_FormField* pTarget) override {} | |
48 void OnField_Focus(FX_BOOL bModifier, | |
49 FX_BOOL bShift, | |
50 CPDF_FormField* pTarget, | |
51 const CFX_WideString& Value) override {} | |
52 void OnField_Blur(FX_BOOL bModifier, | |
53 FX_BOOL bShift, | |
54 CPDF_FormField* pTarget, | |
55 const CFX_WideString& Value) override {} | |
56 void OnField_Calculate(CPDF_FormField* pSource, | |
57 CPDF_FormField* pTarget, | |
58 CFX_WideString& Value, | |
59 FX_BOOL& bRc) override {} | |
60 void OnField_Format(CPDF_FormField* pTarget, | |
61 CFX_WideString& Value, | |
62 FX_BOOL bWillCommit) override {} | |
63 void OnField_Keystroke(CFX_WideString& strChange, | |
64 const CFX_WideString& strChangeEx, | |
65 FX_BOOL KeyDown, | |
66 FX_BOOL bModifier, | |
67 int& nSelEnd, | |
68 int& nSelStart, | |
69 FX_BOOL bShift, | |
70 CPDF_FormField* pTarget, | |
71 CFX_WideString& Value, | |
72 FX_BOOL bWillCommit, | |
73 FX_BOOL bFieldFull, | |
74 FX_BOOL& bRc) override {} | |
75 void OnField_Validate(CFX_WideString& strChange, | |
76 const CFX_WideString& strChangeEx, | |
77 FX_BOOL bKeyDown, | |
78 FX_BOOL bModifier, | |
79 FX_BOOL bShift, | |
80 CPDF_FormField* pTarget, | |
81 CFX_WideString& Value, | |
82 FX_BOOL& bRc) override {} | |
83 void OnScreen_Focus(FX_BOOL bModifier, | |
84 FX_BOOL bShift, | |
85 CPDFSDK_Annot* pScreen) override {} | |
86 void OnScreen_Blur(FX_BOOL bModifier, | |
87 FX_BOOL bShift, | |
88 CPDFSDK_Annot* pScreen) override {} | |
89 void OnScreen_Open(FX_BOOL bModifier, | |
90 FX_BOOL bShift, | |
91 CPDFSDK_Annot* pScreen) override {} | |
92 void OnScreen_Close(FX_BOOL bModifier, | |
93 FX_BOOL bShift, | |
94 CPDFSDK_Annot* pScreen) override {} | |
95 void OnScreen_MouseDown(FX_BOOL bModifier, | |
96 FX_BOOL bShift, | |
97 CPDFSDK_Annot* pScreen) override {} | |
98 void OnScreen_MouseUp(FX_BOOL bModifier, | |
99 FX_BOOL bShift, | |
100 CPDFSDK_Annot* pScreen) override {} | |
101 void OnScreen_MouseEnter(FX_BOOL bModifier, | |
102 FX_BOOL bShift, | |
103 CPDFSDK_Annot* pScreen) override {} | |
104 void OnScreen_MouseExit(FX_BOOL bModifier, | |
105 FX_BOOL bShift, | |
106 CPDFSDK_Annot* pScreen) override {} | |
107 void OnScreen_InView(FX_BOOL bModifier, | |
108 FX_BOOL bShift, | |
109 CPDFSDK_Annot* pScreen) override {} | |
110 void OnScreen_OutView(FX_BOOL bModifier, | |
111 FX_BOOL bShift, | |
112 CPDFSDK_Annot* pScreen) override {} | |
113 void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) override {} | |
114 void OnLink_MouseUp(CPDFSDK_Document* pTarget) override {} | |
115 void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString&) override {} | |
116 void OnBatchExec(CPDFSDK_Document* pTarget) override {} | |
117 void OnConsole_Exec() override {} | |
118 void OnExternal_Exec() override {} | |
119 void EnableMessageBox(FX_BOOL bEnable) override {} | |
120 | |
121 protected: | |
122 IJS_Runtime* m_pRuntime; | |
David Lattimore
2015/10/08 21:11:54
This doesn't seem to be used.
Tom Sepez
2015/10/08 21:25:33
removed.
| |
123 }; | |
124 | |
125 class CJS_RuntimeStub final : public IJS_Runtime { | |
126 public: | |
127 CJS_RuntimeStub() : m_pDoc(nullptr) {} | |
128 ~CJS_RuntimeStub() override {} | |
129 | |
130 IJS_Context* NewContext() override { | |
131 m_ContextStack.push_back(new CJS_ContextStub(this)); | |
132 return GetCurrentContext(); | |
133 } | |
134 | |
135 IJS_Context* GetCurrentContext() override { | |
136 return m_ContextStack.size() ? m_ContextStack.back() : nullptr; | |
137 } | |
138 | |
139 void ReleaseContext(IJS_Context* pContext) override { | |
140 CJS_ContextStub* pContextStub = static_cast<CJS_ContextStub*>(pContext); | |
141 for (auto it = m_ContextStack.begin(); it != m_ContextStack.end(); ++it) { | |
142 if (*it == pContextStub) { | |
143 m_ContextStack.erase(it); | |
144 delete pContextStub; | |
145 break; | |
146 } | |
147 } | |
148 } | |
149 | |
150 void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override { | |
151 m_pDoc = pReaderDoc; | |
152 } | |
153 CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; } | |
154 | |
155 protected: | |
156 CPDFSDK_Document* m_pDoc; | |
157 std::vector<CJS_ContextStub*> m_ContextStack; | |
David Lattimore
2015/10/08 21:11:54
It looks like you could have a single CJS_ContextS
Tom Sepez
2015/10/08 21:25:33
Yes, but the question remains when to delete it.
David Lattimore
2015/10/08 21:29:42
It couldn't just be owned by CJS_RuntimeStub?
| |
158 }; | |
159 | |
160 // static | |
161 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { | |
162 } | |
163 | |
164 // static | |
165 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { | |
166 return new CJS_RuntimeStub; | |
167 } | |
OLD | NEW |