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

Side by Side Diff: fpdfsdk/cpdfsdk_environment.cpp

Issue 2354363003: Move CPDFSDK_Environment code to cpp file (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | fpdfsdk/include/cpdfsdk_environment.h » ('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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "fpdfsdk/include/cpdfsdk_environment.h" 7 #include "fpdfsdk/include/cpdfsdk_environment.h"
8 8
9 #include "fpdfsdk/formfiller/cffl_iformfiller.h" 9 #include "fpdfsdk/formfiller/cffl_iformfiller.h"
10 #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" 10 #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!m_pActionHandler) 205 if (!m_pActionHandler)
206 m_pActionHandler.reset(new CPDFSDK_ActionHandler()); 206 m_pActionHandler.reset(new CPDFSDK_ActionHandler());
207 return m_pActionHandler.get(); 207 return m_pActionHandler.get();
208 } 208 }
209 209
210 CFFL_IFormFiller* CPDFSDK_Environment::GetIFormFiller() { 210 CFFL_IFormFiller* CPDFSDK_Environment::GetIFormFiller() {
211 if (!m_pIFormFiller) 211 if (!m_pIFormFiller)
212 m_pIFormFiller.reset(new CFFL_IFormFiller(this)); 212 m_pIFormFiller.reset(new CFFL_IFormFiller(this));
213 return m_pIFormFiller.get(); 213 return m_pIFormFiller.get();
214 } 214 }
215
216 void CPDFSDK_Environment::Invalidate(FPDF_PAGE page,
217 double left,
218 double top,
219 double right,
220 double bottom) {
221 if (m_pInfo && m_pInfo->FFI_Invalidate)
222 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
223 }
224
225 void CPDFSDK_Environment::OutputSelectedRect(FPDF_PAGE page,
226 double left,
227 double top,
228 double right,
229 double bottom) {
230 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
231 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
232 }
233
234 void CPDFSDK_Environment::SetCursor(int nCursorType) {
235 if (m_pInfo && m_pInfo->FFI_SetCursor)
236 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
237 }
238
239 int CPDFSDK_Environment::SetTimer(int uElapse, TimerCallback lpTimerFunc) {
240 if (m_pInfo && m_pInfo->FFI_SetTimer)
241 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
242 return -1;
243 }
244
245 void CPDFSDK_Environment::KillTimer(int nTimerID) {
246 if (m_pInfo && m_pInfo->FFI_KillTimer)
247 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
248 }
249
250 FX_SYSTEMTIME CPDFSDK_Environment::GetLocalTime() const {
251 FX_SYSTEMTIME fxtime;
252 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
253 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
254 fxtime.wDay = systime.wDay;
255 fxtime.wDayOfWeek = systime.wDayOfWeek;
256 fxtime.wHour = systime.wHour;
257 fxtime.wMilliseconds = systime.wMilliseconds;
258 fxtime.wMinute = systime.wMinute;
259 fxtime.wMonth = systime.wMonth;
260 fxtime.wSecond = systime.wSecond;
261 fxtime.wYear = systime.wYear;
262 }
263 return fxtime;
264 }
265
266 void CPDFSDK_Environment::OnChange() {
267 if (m_pInfo && m_pInfo->FFI_OnChange)
268 m_pInfo->FFI_OnChange(m_pInfo);
269 }
270
271 FX_BOOL CPDFSDK_Environment::IsSHIFTKeyDown(uint32_t nFlag) const {
272 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
273 }
274
275 FX_BOOL CPDFSDK_Environment::IsCTRLKeyDown(uint32_t nFlag) const {
276 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
277 }
278
279 FX_BOOL CPDFSDK_Environment::IsALTKeyDown(uint32_t nFlag) const {
280 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
281 }
282
283 FPDF_PAGE CPDFSDK_Environment::GetPage(FPDF_DOCUMENT document, int nPageIndex) {
284 if (m_pInfo && m_pInfo->FFI_GetPage)
285 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
286 return nullptr;
287 }
288
289 FPDF_PAGE CPDFSDK_Environment::GetCurrentPage(FPDF_DOCUMENT document) {
290 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
291 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
292 return nullptr;
293 }
294
295 void CPDFSDK_Environment::ExecuteNamedAction(const FX_CHAR* namedAction) {
296 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
297 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
298 }
299
300 void CPDFSDK_Environment::OnSetFieldInputFocus(void* field,
npm 2016/09/21 21:05:06 Where is field parameter being used? Otherwise, ca
dsinclair 2016/09/22 13:16:45 Done. It looks like the stranger issue is that whi
301 FPDF_WIDESTRING focusText,
302 FPDF_DWORD nTextLen,
303 FX_BOOL bFocus) {
304 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
305 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
306 }
307
308 void CPDFSDK_Environment::DoURIAction(const FX_CHAR* bsURI) {
309 if (m_pInfo && m_pInfo->FFI_DoURIAction)
310 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
311 }
312
313 void CPDFSDK_Environment::DoGoToAction(int nPageIndex,
314 int zoomMode,
315 float* fPosArray,
316 int sizeOfArray) {
317 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
npm 2016/09/21 21:05:07 Nit: brackets
dsinclair 2016/09/22 13:16:45 Done.
318 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
319 sizeOfArray);
320 }
321
322 #ifdef PDF_ENABLE_XFA
323 void CPDFSDK_Environment::DisplayCaret(FPDF_PAGE page,
324 FPDF_BOOL bVisible,
325 double left,
326 double top,
327 double right,
328 double bottom) {
329 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
npm 2016/09/21 21:05:06 Ditto
dsinclair 2016/09/22 13:16:45 Done.
330 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
331 bottom);
332 }
333
334 int CPDFSDK_Environment::GetCurrentPageIndex(FPDF_DOCUMENT document) {
335 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex)
336 return -1;
337 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
338 }
339
340 void CPDFSDK_Environment::SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
341 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
342 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
343 }
344
345 CFX_WideString CPDFSDK_Environment::GetPlatform() {
346 if (!m_pInfo || !m_pInfo->FFI_GetPlatform)
347 return L"";
348
349 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
350 if (nRequiredLen <= 0)
351 return L"";
352
353 char* pbuff = new char[nRequiredLen];
354 memset(pbuff, 0, nRequiredLen);
355 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
356 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
357 delete[] pbuff;
358 return L"";
359 }
360 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
361 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
362 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
363 bsRet.GetLength() / sizeof(unsigned short));
364 delete[] pbuff;
365 return wsRet;
366 }
367
368 void CPDFSDK_Environment::GotoURL(FPDF_DOCUMENT document,
369 const CFX_WideStringC& wsURL,
370 FX_BOOL bAppend) {
npm 2016/09/21 21:05:06 bAppend unused?
dsinclair 2016/09/22 13:16:46 Done.
371 if (m_pInfo && m_pInfo->FFI_GotoURL) {
372 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
373 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
374 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
375 bsTo.ReleaseBuffer();
376 }
377 }
378
379 void CPDFSDK_Environment::GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
380 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
381 double left;
382 double top;
383 double right;
384 double bottom;
385 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
386
387 dstRect.left = static_cast<float>(left);
388 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
389 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
390 dstRect.right = static_cast<float>(right);
391 }
392 }
393
394 FX_BOOL CPDFSDK_Environment::PopupMenu(FPDF_PAGE page,
395 FPDF_WIDGET hWidget,
396 int menuFlag,
397 CFX_PointF ptPopup,
398 const CFX_PointF* pRectExclude) {
npm 2016/09/21 21:05:06 Unused pRectExclude?
dsinclair 2016/09/22 13:16:45 Done.
399 if (m_pInfo && m_pInfo->FFI_PopupMenu)
npm 2016/09/21 21:05:06 {}s
dsinclair 2016/09/22 13:16:46 Done.
400 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
401 ptPopup.y);
402 return FALSE;
403 }
404
405 void CPDFSDK_Environment::Alert(FPDF_WIDESTRING Msg,
406 FPDF_WIDESTRING Title,
407 int Type,
408 int Icon) {
409 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
npm 2016/09/21 21:05:06 {}s
dsinclair 2016/09/22 13:16:45 Done.
410 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type,
411 Icon);
412 }
413
414 void CPDFSDK_Environment::EmailTo(FPDF_FILEHANDLER* fileHandler,
415 FPDF_WIDESTRING pTo,
416 FPDF_WIDESTRING pSubject,
417 FPDF_WIDESTRING pCC,
418 FPDF_WIDESTRING pBcc,
419 FPDF_WIDESTRING pMsg) {
420 if (m_pInfo && m_pInfo->FFI_EmailTo)
421 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg);
422 }
423
424 void CPDFSDK_Environment::UploadTo(FPDF_FILEHANDLER* fileHandler,
425 int fileFlag,
426 FPDF_WIDESTRING uploadTo) {
427 if (m_pInfo && m_pInfo->FFI_UploadTo)
428 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
429 }
430
431 FPDF_FILEHANDLER* CPDFSDK_Environment::OpenFile(int fileType,
432 FPDF_WIDESTRING wsURL,
433 const char* mode) {
434 if (m_pInfo && m_pInfo->FFI_OpenFile)
435 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
436 return nullptr;
437 }
438
439 IFX_FileRead* CPDFSDK_Environment::DownloadFromURL(const FX_WCHAR* url) {
440 if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL)
441 return nullptr;
442
443 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
444 FPDF_WIDESTRING wsURL =
445 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
446
447 FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
448
449 return new CFPDF_FileStream(fileHandler);
450 }
451
452 CFX_WideString CPDFSDK_Environment::PostRequestURL(
453 const FX_WCHAR* wsURL,
454 const FX_WCHAR* wsData,
455 const FX_WCHAR* wsContentType,
456 const FX_WCHAR* wsEncode,
457 const FX_WCHAR* wsHeader) {
458 if (!m_pInfo || !m_pInfo->FFI_PostRequestURL)
459 return L"";
460
461 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
462 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
npm 2016/09/21 21:05:07 Remove C-cast
dsinclair 2016/09/22 13:16:46 FPDF_WIDESTRING is strange and has to be c-style a
463
464 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
465 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
npm 2016/09/21 21:05:06 ditto here and several others in this same method
dsinclair 2016/09/22 13:16:45 as above
466
467 CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode();
468 FPDF_WIDESTRING contentType =
469 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
470
471 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
472 FPDF_WIDESTRING encode =
473 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
474
475 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
476 FPDF_WIDESTRING header =
477 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
478
479 FPDF_BSTR response;
480 FPDF_BStr_Init(&response);
481 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header,
482 &response);
483
484 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
485 (unsigned short*)response.str, response.len / sizeof(unsigned short));
npm 2016/09/21 21:05:06 C-Cast
dsinclair 2016/09/22 13:16:45 This is really a FPDF_WIDESTRING.
486 FPDF_BStr_Clear(&response);
487
488 return wsRet;
489 }
490
491 FPDF_BOOL CPDFSDK_Environment::PutRequestURL(const FX_WCHAR* wsURL,
492 const FX_WCHAR* wsData,
493 const FX_WCHAR* wsEncode) {
494 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL)
495 return FALSE;
496
497 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
498 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
npm 2016/09/21 21:05:06 ditto here and below
dsinclair 2016/09/22 13:16:45 Acknowledged.
499
500 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
501 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
502
503 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
504 FPDF_WIDESTRING encode =
505 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
506
507 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
508 }
509
510 CFX_WideString CPDFSDK_Environment::GetLanguage() {
511 if (!m_pInfo || !m_pInfo->FFI_GetLanguage)
512 return L"";
513
514 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
515 if (nRequiredLen <= 0)
516 return L"";
517
518 char* pbuff = new char[nRequiredLen];
519 memset(pbuff, 0, nRequiredLen);
520 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
521 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
522 delete[] pbuff;
523 return L"";
524 }
525 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
526 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
527 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
npm 2016/09/21 21:05:06 ditto
dsinclair 2016/09/22 13:16:45 Acknowledged.
528 bsRet.GetLength() / sizeof(unsigned short));
529 delete[] pbuff;
530 return wsRet;
531 }
532
533 void CPDFSDK_Environment::PageEvent(int iPageCount,
534 uint32_t dwEventType) const {
535 if (m_pInfo && m_pInfo->FFI_PageEvent)
536 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
537 }
538 #endif // PDF_ENABLE_XFA
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/include/cpdfsdk_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698