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

Side by Side Diff: fpdfsdk/src/javascript/JS_Context.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 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 | « fpdfsdk/src/javascript/Icon.cpp ('k') | fpdfsdk/src/javascript/JS_EventHandler.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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 //#include "../../include/javascript/JS_ResMgr.h" 9 //#include "../../include/javascript/JS_ResMgr.h"
10 #include "../../include/javascript/JS_Context.h" 10 #include "../../include/javascript/JS_Context.h"
11 #include "../../include/javascript/JS_EventHandler.h" 11 #include "../../include/javascript/JS_EventHandler.h"
12 #include "../../include/javascript/JS_Runtime.h" 12 #include "../../include/javascript/JS_Runtime.h"
13 #include "../../include/javascript/resource.h" 13 #include "../../include/javascript/resource.h"
14 14
15 /* -------------------------- CJS_Context -------------------------- */ 15 /* -------------------------- CJS_Context -------------------------- */
16 16
17 CJS_Context::CJS_Context(CJS_Runtime* pRuntime) : 17 CJS_Context::CJS_Context(CJS_Runtime* pRuntime) :
18 m_pRuntime(pRuntime), 18 m_pRuntime(pRuntime),
19 » m_bBusy(FALSE), 19 » m_bBusy(false),
20 » m_bMsgBoxEnable(TRUE) 20 » m_bMsgBoxEnable(true)
21 { 21 {
22 m_pEventHandler = new CJS_EventHandler(this); 22 m_pEventHandler = new CJS_EventHandler(this);
23 } 23 }
24 24
25 CJS_Context::~CJS_Context(void) 25 CJS_Context::~CJS_Context(void)
26 { 26 {
27 delete m_pEventHandler; 27 delete m_pEventHandler;
28 } 28 }
29 29
30 CPDFSDK_Document* CJS_Context::GetReaderDocument() 30 CPDFSDK_Document* CJS_Context::GetReaderDocument()
31 { 31 {
32 ASSERT(m_pRuntime != NULL); 32 ASSERT(m_pRuntime != NULL);
33 33
34 return m_pRuntime->GetReaderDocument(); 34 return m_pRuntime->GetReaderDocument();
35 } 35 }
36 36
37 CPDFDoc_Environment* CJS_Context::GetReaderApp() 37 CPDFDoc_Environment* CJS_Context::GetReaderApp()
38 { 38 {
39 ASSERT(m_pRuntime != NULL); 39 ASSERT(m_pRuntime != NULL);
40 40
41 return m_pRuntime->GetReaderApp(); 41 return m_pRuntime->GetReaderApp();
42 } 42 }
43 43
44 FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideStri ng& info) 44 bool CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info)
45 { 45 {
46 if (m_bBusy) 46 if (m_bBusy)
47 { 47 {
48 info = JSGetStringFromID(this, IDS_STRING_JSBUSY); 48 info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
49 » » return FALSE; 49 » » return false;
50 } 50 }
51 51
52 » m_bBusy = TRUE; 52 » m_bBusy = true;
53 53
54 ASSERT(m_pRuntime != NULL); 54 ASSERT(m_pRuntime != NULL);
55 ASSERT(m_pEventHandler != NULL); 55 ASSERT(m_pEventHandler != NULL);
56 ASSERT(m_pEventHandler->IsValid()); 56 ASSERT(m_pEventHandler->IsValid());
57 57
58 if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventH andler->EventType())) 58 if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventH andler->EventType()))
59 { 59 {
60 info = JSGetStringFromID(this, IDS_STRING_JSEVENT); 60 info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
61 » » return FALSE; 61 » » return false;
62 } 62 }
63 63
64 FXJSErr error ={NULL,NULL, 0}; 64 FXJSErr error ={NULL,NULL, 0};
65 int nRet = 0; 65 int nRet = 0;
66 66
67 if (script.GetLength() > 0) 67 if (script.GetLength() > 0)
68 { 68 {
69 if (nMode == 0) 69 if (nMode == 0)
70 { 70 {
71 nRet = JS_Execute(*m_pRuntime, this, script.c_str(), scr ipt.GetLength(), &error); 71 nRet = JS_Execute(*m_pRuntime, this, script.c_str(), scr ipt.GetLength(), &error);
(...skipping 16 matching lines...) Expand all
88 info += sLine; 88 info += sLine;
89 } 89 }
90 else 90 else
91 { 91 {
92 info = JSGetStringFromID(this, IDS_STRING_RUN); 92 info = JSGetStringFromID(this, IDS_STRING_RUN);
93 } 93 }
94 94
95 m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHan dler->EventType()); 95 m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHan dler->EventType());
96 96
97 m_pEventHandler->Destroy(); 97 m_pEventHandler->Destroy();
98 » m_bBusy = FALSE; 98 » m_bBusy = false;
99 99
100 return nRet >= 0; 100 return nRet >= 0;
101 } 101 }
102 102
103 FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& inf o) 103 bool CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
104 { 104 {
105 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); 105 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
106 v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); 106 v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
107 v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); 107 v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
108 v8::Context::Scope context_scope(context); 108 v8::Context::Scope context_scope(context);
109 109
110 return DoJob(0, script, info); 110 return DoJob(0, script, info);
111 } 111 }
112 112
113 FX_BOOL CJS_Context::Compile(const CFX_WideString& script, CFX_WideString& info) 113 bool CJS_Context::Compile(const CFX_WideString& script, CFX_WideString& info)
114 { 114 {
115 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); 115 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
116 v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); 116 v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
117 v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); 117 v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
118 v8::Context::Scope context_scope(context); 118 v8::Context::Scope context_scope(context);
119 119
120 return DoJob(1, script, info); 120 return DoJob(1, script, info);
121 } 121 }
122 122
123 void CJS_Context::OnApp_Init() 123 void CJS_Context::OnApp_Init()
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ASSERT(m_pEventHandler != NULL); 179 ASSERT(m_pEventHandler != NULL);
180 m_pEventHandler->OnPage_InView(pTarget); 180 m_pEventHandler->OnPage_InView(pTarget);
181 } 181 }
182 182
183 void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget) 183 void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget)
184 { 184 {
185 ASSERT(m_pEventHandler != NULL); 185 ASSERT(m_pEventHandler != NULL);
186 m_pEventHandler->OnPage_OutView(pTarget); 186 m_pEventHandler->OnPage_OutView(pTarget);
187 } 187 }
188 188
189 void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_Form Field *pTarget) 189 void CJS_Context::OnField_MouseDown(bool bModifier, bool bShift, CPDF_FormField *pTarget)
190 { 190 {
191 ASSERT(m_pEventHandler != NULL); 191 ASSERT(m_pEventHandler != NULL);
192 m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget); 192 m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget);
193 } 193 }
194 194
195 void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_For mField *pTarget) 195 void CJS_Context::OnField_MouseEnter(bool bModifier, bool bShift, CPDF_FormField *pTarget)
196 { 196 {
197 ASSERT(m_pEventHandler != NULL); 197 ASSERT(m_pEventHandler != NULL);
198 m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget); 198 m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget);
199 } 199 }
200 200
201 void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_Form Field *pTarget) 201 void CJS_Context::OnField_MouseExit(bool bModifier, bool bShift, CPDF_FormField *pTarget)
202 { 202 {
203 ASSERT(m_pEventHandler != NULL); 203 ASSERT(m_pEventHandler != NULL);
204 m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget); 204 m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget);
205 } 205 }
206 206
207 void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormFi eld *pTarget) 207 void CJS_Context::OnField_MouseUp(bool bModifier, bool bShift, CPDF_FormField *p Target)
208 { 208 {
209 ASSERT(m_pEventHandler != NULL); 209 ASSERT(m_pEventHandler != NULL);
210 m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget); 210 m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget);
211 } 211 }
212 212
213 void CJS_Context::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormFiel d* pTarget, const CFX_WideString& Value) 213 void CJS_Context::OnField_Focus(bool bModifier, bool bShift, CPDF_FormField* pTa rget, const CFX_WideString& Value)
214 { 214 {
215 ASSERT(m_pEventHandler != NULL); 215 ASSERT(m_pEventHandler != NULL);
216 m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value); 216 m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value);
217 } 217 }
218 218
219 void CJS_Context::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField * pTarget, const CFX_WideString& Value) 219 void CJS_Context::OnField_Blur(bool bModifier, bool bShift, CPDF_FormField* pTar get, const CFX_WideString& Value)
220 { 220 {
221 ASSERT(m_pEventHandler != NULL); 221 ASSERT(m_pEventHandler != NULL);
222 m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value); 222 m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value);
223 } 223 }
224 224
225 void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTa rget, CFX_WideString& Value, FX_BOOL& bRc) 225 void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTa rget, CFX_WideString& Value, bool& bRc)
226 { 226 {
227 ASSERT(m_pEventHandler != NULL); 227 ASSERT(m_pEventHandler != NULL);
228 m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc); 228 m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc);
229 } 229 }
230 230
231 void CJS_Context::OnField_Format(CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit) 231 void CJS_Context::OnField_Format(CPDF_FormField* pTarget, CFX_WideString& Value, bool bWillCommit)
232 { 232 {
233 m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit); 233 m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit);
234 } 234 }
235 235
236 236
237 void CJS_Context::OnField_Keystroke(CFX_WideString& strChange, const CFX_WideStr ing& strChangeEx, 237 void CJS_Context::OnField_Keystroke(CFX_WideString& strChange, const CFX_WideStr ing& strChangeEx,
238 » » » » » » » » » FX_BOOL bKeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart, 238 » » » » » » » » » bool bKe yDown, bool bModifier, int &nSelEnd,int &nSelStart,
239 » » » » » » » » » FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value, 239 » » » » » » » » » bool bSh ift, CPDF_FormField* pTarget, CFX_WideString& Value,
240 » » » » » » » » » FX_BOOL bWillCommit, FX_BOOL bFieldFull, FX_BOOL& bRc) 240 » » » » » » » » » bool bWi llCommit, bool bFieldFull, bool& bRc)
241 { 241 {
242 m_pEventHandler->OnField_Keystroke( 242 m_pEventHandler->OnField_Keystroke(
243 strChange, strChangeEx, bKeyDown, bModifier, nSelEnd, nSelStart, 243 strChange, strChangeEx, bKeyDown, bModifier, nSelEnd, nSelStart,
244 bShift, pTarget, Value, bWillCommit, bFieldFull, bRc); 244 bShift, pTarget, Value, bWillCommit, bFieldFull, bRc);
245 } 245 }
246 246
247 void CJS_Context::OnField_Validate(CFX_WideString& strChange,const CFX_WideStrin g& strChangeEx, 247 void CJS_Context::OnField_Validate(CFX_WideString& strChange,const CFX_WideStrin g& strChangeEx,
248 » » » » » » » » FX_BOOL bKeyD own, FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, 248 » » » » » » » » bool bKeyDown , bool bModifier, bool bShift, CPDF_FormField* pTarget,
249 » » » » » » » » CFX_WideStrin g& Value, FX_BOOL& bRc) 249 » » » » » » » » CFX_WideStrin g& Value, bool& bRc)
250 { 250 {
251 ASSERT(m_pEventHandler != NULL); 251 ASSERT(m_pEventHandler != NULL);
252 m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bMod ifier, bShift, pTarget, Value, bRc); 252 m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bMod ifier, bShift, pTarget, Value, bRc);
253 } 253 }
254 254
255 void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Anno t* pScreen) 255 void CJS_Context::OnScreen_Focus(bool bModifier, bool bShift, CPDFSDK_Annot* pSc reen)
256 { 256 {
257 ASSERT(m_pEventHandler != NULL); 257 ASSERT(m_pEventHandler != NULL);
258 m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen); 258 m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen);
259 } 259 }
260 260
261 void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot * pScreen) 261 void CJS_Context::OnScreen_Blur(bool bModifier, bool bShift, CPDFSDK_Annot* pScr een)
262 { 262 {
263 ASSERT(m_pEventHandler != NULL); 263 ASSERT(m_pEventHandler != NULL);
264 m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen); 264 m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen);
265 } 265 }
266 266
267 void CJS_Context::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot * pScreen) 267 void CJS_Context::OnScreen_Open(bool bModifier, bool bShift, CPDFSDK_Annot* pScr een)
268 { 268 {
269 ASSERT(m_pEventHandler != NULL); 269 ASSERT(m_pEventHandler != NULL);
270 m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen); 270 m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen);
271 } 271 }
272 272
273 void CJS_Context::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Anno t* pScreen) 273 void CJS_Context::OnScreen_Close(bool bModifier, bool bShift, CPDFSDK_Annot* pSc reen)
274 { 274 {
275 ASSERT(m_pEventHandler != NULL); 275 ASSERT(m_pEventHandler != NULL);
276 m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen); 276 m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen);
277 } 277 }
278 278
279 void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_ Annot* pScreen) 279 void CJS_Context::OnScreen_MouseDown(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen)
280 { 280 {
281 ASSERT(m_pEventHandler != NULL); 281 ASSERT(m_pEventHandler != NULL);
282 m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen); 282 m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen);
283 } 283 }
284 284
285 void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_An not* pScreen) 285 void CJS_Context::OnScreen_MouseUp(bool bModifier, bool bShift, CPDFSDK_Annot* p Screen)
286 { 286 {
287 ASSERT(m_pEventHandler != NULL); 287 ASSERT(m_pEventHandler != NULL);
288 m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen); 288 m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen);
289 } 289 }
290 290
291 void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK _Annot* pScreen) 291 void CJS_Context::OnScreen_MouseEnter(bool bModifier, bool bShift, CPDFSDK_Annot * pScreen)
292 { 292 {
293 ASSERT(m_pEventHandler != NULL); 293 ASSERT(m_pEventHandler != NULL);
294 m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen); 294 m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen);
295 } 295 }
296 296
297 void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_ Annot* pScreen) 297 void CJS_Context::OnScreen_MouseExit(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen)
298 { 298 {
299 ASSERT(m_pEventHandler != NULL); 299 ASSERT(m_pEventHandler != NULL);
300 m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen); 300 m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen);
301 } 301 }
302 302
303 void CJS_Context::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Ann ot* pScreen) 303 void CJS_Context::OnScreen_InView(bool bModifier, bool bShift, CPDFSDK_Annot* pS creen)
304 { 304 {
305 ASSERT(m_pEventHandler != NULL); 305 ASSERT(m_pEventHandler != NULL);
306 m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen); 306 m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen);
307 } 307 }
308 308
309 void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_An not* pScreen) 309 void CJS_Context::OnScreen_OutView(bool bModifier, bool bShift, CPDFSDK_Annot* p Screen)
310 { 310 {
311 ASSERT(m_pEventHandler != NULL); 311 ASSERT(m_pEventHandler != NULL);
312 m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen); 312 m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen);
313 } 313 }
314 314
315 void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) 315 void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
316 { 316 {
317 ASSERT(m_pEventHandler != NULL); 317 ASSERT(m_pEventHandler != NULL);
318 m_pEventHandler->OnBookmark_MouseUp(pBookMark); 318 m_pEventHandler->OnBookmark_MouseUp(pBookMark);
319 } 319 }
(...skipping 21 matching lines...) Expand all
341 ASSERT(m_pEventHandler != NULL); 341 ASSERT(m_pEventHandler != NULL);
342 m_pEventHandler->OnBatchExec(pTarget); 342 m_pEventHandler->OnBatchExec(pTarget);
343 } 343 }
344 344
345 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,const CFX_WideString& st rTargetName) 345 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,const CFX_WideString& st rTargetName)
346 { 346 {
347 ASSERT(m_pEventHandler != NULL); 347 ASSERT(m_pEventHandler != NULL);
348 m_pEventHandler->OnMenu_Exec(pTarget, strTargetName); 348 m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
349 } 349 }
350 350
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/Icon.cpp ('k') | fpdfsdk/src/javascript/JS_EventHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698