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

Side by Side Diff: fpdfsdk/cpdfsdk_environment.cpp

Issue 2354363003: Move CPDFSDK_Environment code to cpp file (Closed)
Patch Set: Review feedback 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 | « fpdfsdk/cpdfsdk_document.cpp ('k') | fpdfsdk/formfiller/cffl_combobox.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 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_interactiveformfiller.h" 9 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
10 #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" 10 #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); 200 m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this));
201 return m_pAnnotHandlerMgr.get(); 201 return m_pAnnotHandlerMgr.get();
202 } 202 }
203 203
204 CPDFSDK_ActionHandler* CPDFSDK_Environment::GetActionHander() { 204 CPDFSDK_ActionHandler* CPDFSDK_Environment::GetActionHander() {
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_InteractiveFormFiller* CPDFSDK_Environment::GetInteractiveFormFiller() { 210 CFFL_InteractiveFormFiller* CPDFSDK_Environment::GetInteractiveFormFiller() {
npm 2016/09/22 17:18:22 This is from rebase?
dsinclair 2016/09/22 17:20:16 Acknowledged.
211 if (!m_pFormFiller) 211 if (!m_pFormFiller)
212 m_pFormFiller.reset(new CFFL_InteractiveFormFiller(this)); 212 m_pFormFiller.reset(new CFFL_InteractiveFormFiller(this));
213 return m_pFormFiller.get(); 213 return m_pFormFiller.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 return fxtime;
254
255 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
256 fxtime.wDay = systime.wDay;
257 fxtime.wDayOfWeek = systime.wDayOfWeek;
258 fxtime.wHour = systime.wHour;
259 fxtime.wMilliseconds = systime.wMilliseconds;
260 fxtime.wMinute = systime.wMinute;
261 fxtime.wMonth = systime.wMonth;
262 fxtime.wSecond = systime.wSecond;
263 fxtime.wYear = systime.wYear;
264 return fxtime;
265 }
266
267 void CPDFSDK_Environment::OnChange() {
268 if (m_pInfo && m_pInfo->FFI_OnChange)
269 m_pInfo->FFI_OnChange(m_pInfo);
270 }
271
272 FX_BOOL CPDFSDK_Environment::IsSHIFTKeyDown(uint32_t nFlag) const {
273 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
274 }
275
276 FX_BOOL CPDFSDK_Environment::IsCTRLKeyDown(uint32_t nFlag) const {
277 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
278 }
279
280 FX_BOOL CPDFSDK_Environment::IsALTKeyDown(uint32_t nFlag) const {
281 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
282 }
283
284 FPDF_PAGE CPDFSDK_Environment::GetPage(FPDF_DOCUMENT document, int nPageIndex) {
285 if (m_pInfo && m_pInfo->FFI_GetPage)
286 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
287 return nullptr;
288 }
289
290 FPDF_PAGE CPDFSDK_Environment::GetCurrentPage(FPDF_DOCUMENT document) {
291 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
292 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
293 return nullptr;
294 }
295
296 void CPDFSDK_Environment::ExecuteNamedAction(const FX_CHAR* namedAction) {
297 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
298 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
299 }
300
301 void CPDFSDK_Environment::OnSetFieldInputFocus(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) {
318 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
319 sizeOfArray);
320 }
321 }
322
323 #ifdef PDF_ENABLE_XFA
324 void CPDFSDK_Environment::DisplayCaret(FPDF_PAGE page,
325 FPDF_BOOL bVisible,
326 double left,
327 double top,
328 double right,
329 double bottom) {
330 if (m_pInfo && m_pInfo->FFI_DisplayCaret) {
331 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
332 bottom);
333 }
334 }
335
336 int CPDFSDK_Environment::GetCurrentPageIndex(FPDF_DOCUMENT document) {
337 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex)
338 return -1;
339 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
340 }
341
342 void CPDFSDK_Environment::SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
343 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
344 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
345 }
346
347 CFX_WideString CPDFSDK_Environment::GetPlatform() {
348 if (!m_pInfo || !m_pInfo->FFI_GetPlatform)
349 return L"";
350
351 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
352 if (nRequiredLen <= 0)
353 return L"";
354
355 char* pbuff = new char[nRequiredLen];
356 memset(pbuff, 0, nRequiredLen);
357 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
358 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
359 delete[] pbuff;
360 return L"";
361 }
362 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
363 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
364 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
365 bsRet.GetLength() / sizeof(unsigned short));
366 delete[] pbuff;
367 return wsRet;
368 }
369
370 void CPDFSDK_Environment::GotoURL(FPDF_DOCUMENT document,
371 const CFX_WideStringC& wsURL) {
372 if (!m_pInfo || !m_pInfo->FFI_GotoURL)
373 return;
374
375 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
376 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
377 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
378 bsTo.ReleaseBuffer();
379 }
380
381 void CPDFSDK_Environment::GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
382 if (!m_pInfo || !m_pInfo->FFI_GetPageViewRect)
383 return;
384
385 double left;
386 double top;
387 double right;
388 double bottom;
389 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
390
391 dstRect.left = static_cast<float>(left);
392 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
393 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
394 dstRect.right = static_cast<float>(right);
395 }
396
397 FX_BOOL CPDFSDK_Environment::PopupMenu(FPDF_PAGE page,
398 FPDF_WIDGET hWidget,
399 int menuFlag,
400 CFX_PointF pt) {
401 if (!m_pInfo || !m_pInfo->FFI_PopupMenu)
402 return FALSE;
403 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y);
404 }
405
406 void CPDFSDK_Environment::Alert(FPDF_WIDESTRING Msg,
407 FPDF_WIDESTRING Title,
408 int Type,
409 int Icon) {
410 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) {
411 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type,
412 Icon);
413 }
414 }
415
416 void CPDFSDK_Environment::EmailTo(FPDF_FILEHANDLER* fileHandler,
417 FPDF_WIDESTRING pTo,
418 FPDF_WIDESTRING pSubject,
419 FPDF_WIDESTRING pCC,
420 FPDF_WIDESTRING pBcc,
421 FPDF_WIDESTRING pMsg) {
422 if (m_pInfo && m_pInfo->FFI_EmailTo)
423 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg);
424 }
425
426 void CPDFSDK_Environment::UploadTo(FPDF_FILEHANDLER* fileHandler,
427 int fileFlag,
428 FPDF_WIDESTRING uploadTo) {
429 if (m_pInfo && m_pInfo->FFI_UploadTo)
430 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
431 }
432
433 FPDF_FILEHANDLER* CPDFSDK_Environment::OpenFile(int fileType,
434 FPDF_WIDESTRING wsURL,
435 const char* mode) {
436 if (m_pInfo && m_pInfo->FFI_OpenFile)
437 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
438 return nullptr;
439 }
440
441 IFX_FileRead* CPDFSDK_Environment::DownloadFromURL(const FX_WCHAR* url) {
442 if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL)
443 return nullptr;
444
445 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
446 FPDF_WIDESTRING wsURL =
447 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
448
449 FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
450
451 return new CFPDF_FileStream(fileHandler);
452 }
453
454 CFX_WideString CPDFSDK_Environment::PostRequestURL(
455 const FX_WCHAR* wsURL,
456 const FX_WCHAR* wsData,
457 const FX_WCHAR* wsContentType,
458 const FX_WCHAR* wsEncode,
459 const FX_WCHAR* wsHeader) {
460 if (!m_pInfo || !m_pInfo->FFI_PostRequestURL)
461 return L"";
462
463 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
464 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
465
466 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
467 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
468
469 CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode();
470 FPDF_WIDESTRING contentType =
471 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
472
473 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
474 FPDF_WIDESTRING encode =
475 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
476
477 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
478 FPDF_WIDESTRING header =
479 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
480
481 FPDF_BSTR response;
482 FPDF_BStr_Init(&response);
483 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header,
484 &response);
485
486 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
487 (FPDF_WIDESTRING)response.str, response.len / sizeof(FPDF_WIDESTRING));
488 FPDF_BStr_Clear(&response);
489
490 return wsRet;
491 }
492
493 FPDF_BOOL CPDFSDK_Environment::PutRequestURL(const FX_WCHAR* wsURL,
494 const FX_WCHAR* wsData,
495 const FX_WCHAR* wsEncode) {
496 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL)
497 return FALSE;
498
499 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
500 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
501
502 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
503 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
504
505 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
506 FPDF_WIDESTRING encode =
507 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
508
509 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
510 }
511
512 CFX_WideString CPDFSDK_Environment::GetLanguage() {
513 if (!m_pInfo || !m_pInfo->FFI_GetLanguage)
514 return L"";
515
516 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
517 if (nRequiredLen <= 0)
518 return L"";
519
520 char* pbuff = new char[nRequiredLen];
521 memset(pbuff, 0, nRequiredLen);
522 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
523 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
524 delete[] pbuff;
525 return L"";
526 }
527 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
528 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
529 (FPDF_WIDESTRING)bsRet.GetBuffer(bsRet.GetLength()),
530 bsRet.GetLength() / sizeof(FPDF_WIDESTRING));
531 delete[] pbuff;
532 return wsRet;
533 }
534
535 void CPDFSDK_Environment::PageEvent(int iPageCount,
536 uint32_t dwEventType) const {
537 if (m_pInfo && m_pInfo->FFI_PageEvent)
538 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
539 }
540 #endif // PDF_ENABLE_XFA
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_document.cpp ('k') | fpdfsdk/formfiller/cffl_combobox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698