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

Side by Side Diff: fpdfsdk/include/cpdfdoc_environment.h

Issue 2333413003: Rename CPDFDoc_Environment to CPDFSDK_Environment (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
OLDNEW
(Empty)
1 // Copyright 2016 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 #ifndef FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_
8 #define FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_
9
10 #include <memory>
11
12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
14 #include "core/fpdfdoc/include/cpdf_occontext.h"
15 #include "core/fxcrt/include/cfx_observable.h"
16 #include "fpdfsdk/cfx_systemhandler.h"
17 #include "fpdfsdk/include/fsdk_define.h"
18 #include "public/fpdf_formfill.h"
19 #include "public/fpdf_fwlevent.h"
20
21 class CFFL_IFormFiller;
22 class CFX_SystemHandler;
23 class CPDFSDK_ActionHandler;
24 class CPDFSDK_AnnotHandlerMgr;
25 class CPDFSDK_Document;
26 class IJS_Runtime;
27
28 class CPDFDoc_Environment final {
29 public:
30 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
31 ~CPDFDoc_Environment();
32
33 void FFI_Invalidate(FPDF_PAGE page,
34 double left,
35 double top,
36 double right,
37 double bottom) {
38 if (m_pInfo && m_pInfo->FFI_Invalidate)
39 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
40 }
41
42 void FFI_OutputSelectedRect(FPDF_PAGE page,
43 double left,
44 double top,
45 double right,
46 double bottom) {
47 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
48 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
49 }
50
51 void FFI_SetCursor(int nCursorType) {
52 if (m_pInfo && m_pInfo->FFI_SetCursor)
53 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
54 }
55
56 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
57 if (m_pInfo && m_pInfo->FFI_SetTimer)
58 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
59 return -1;
60 }
61
62 void FFI_KillTimer(int nTimerID) {
63 if (m_pInfo && m_pInfo->FFI_KillTimer)
64 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
65 }
66
67 FX_SYSTEMTIME FFI_GetLocalTime() const {
68 FX_SYSTEMTIME fxtime;
69 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
70 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
71 fxtime.wDay = systime.wDay;
72 fxtime.wDayOfWeek = systime.wDayOfWeek;
73 fxtime.wHour = systime.wHour;
74 fxtime.wMilliseconds = systime.wMilliseconds;
75 fxtime.wMinute = systime.wMinute;
76 fxtime.wMonth = systime.wMonth;
77 fxtime.wSecond = systime.wSecond;
78 fxtime.wYear = systime.wYear;
79 }
80 return fxtime;
81 }
82
83 void FFI_OnChange() {
84 if (m_pInfo && m_pInfo->FFI_OnChange)
85 m_pInfo->FFI_OnChange(m_pInfo);
86 }
87
88 FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const {
89 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
90 }
91
92 FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const {
93 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
94 }
95
96 FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const {
97 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
98 }
99
100 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
101 if (m_pInfo && m_pInfo->FFI_GetPage)
102 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
103 return nullptr;
104 }
105
106 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
107 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
108 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
109 return nullptr;
110 }
111
112 int FFI_GetRotation(FPDF_PAGE page) {
113 if (m_pInfo && m_pInfo->FFI_GetRotation)
114 return m_pInfo->FFI_GetRotation(m_pInfo, page);
115 return 0;
116 }
117
118 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
119 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
120 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
121 }
122
123 void FFI_OnSetFieldInputFocus(void* field,
124 FPDF_WIDESTRING focusText,
125 FPDF_DWORD nTextLen,
126 FX_BOOL bFocus) {
127 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
128 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
129 }
130
131 void FFI_DoURIAction(const FX_CHAR* bsURI) {
132 if (m_pInfo && m_pInfo->FFI_DoURIAction)
133 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
134 }
135
136 void FFI_DoGoToAction(int nPageIndex,
137 int zoomMode,
138 float* fPosArray,
139 int sizeOfArray) {
140 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
141 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
142 sizeOfArray);
143 }
144
145 #ifdef PDF_ENABLE_XFA
146 void FFI_DisplayCaret(FPDF_PAGE page,
147 FPDF_BOOL bVisible,
148 double left,
149 double top,
150 double right,
151 double bottom) {
152 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
153 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
154 bottom);
155 }
156
157 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
158 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
159 return -1;
160 }
161 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
162 }
163
164 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
165 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
166 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
167 }
168
169 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
170
171 CFX_WideString FFI_GetPlatform() {
172 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
173 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
174 if (nRequiredLen <= 0)
175 return L"";
176
177 char* pbuff = new char[nRequiredLen];
178 memset(pbuff, 0, nRequiredLen);
179 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
180 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
181 delete[] pbuff;
182 return L"";
183 }
184 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
185 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
186 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
187 bsRet.GetLength() / sizeof(unsigned short));
188 delete[] pbuff;
189 return wsRet;
190 }
191 return L"";
192 }
193
194 void FFI_GotoURL(FPDF_DOCUMENT document,
195 const CFX_WideStringC& wsURL,
196 FX_BOOL bAppend) {
197 if (m_pInfo && m_pInfo->FFI_GotoURL) {
198 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
199 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
200 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
201 bsTo.ReleaseBuffer();
202 }
203 }
204
205 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
206 wsURL = CFX_WideString();
207 }
208
209 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
210 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
211 double left;
212 double top;
213 double right;
214 double bottom;
215 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
216
217 dstRect.left = static_cast<float>(left);
218 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
219 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
220 dstRect.right = static_cast<float>(right);
221 }
222 }
223
224 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
225 FPDF_WIDGET hWidget,
226 int menuFlag,
227 CFX_PointF ptPopup,
228 const CFX_PointF* pRectExclude) {
229 if (m_pInfo && m_pInfo->FFI_PopupMenu)
230 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
231 ptPopup.y);
232 return FALSE;
233 }
234
235 void FFI_Alert(FPDF_WIDESTRING Msg,
236 FPDF_WIDESTRING Title,
237 int Type,
238 int Icon) {
239 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
240 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
241 Type, Icon);
242 }
243
244 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
245 FPDF_WIDESTRING pTo,
246 FPDF_WIDESTRING pSubject,
247 FPDF_WIDESTRING pCC,
248 FPDF_WIDESTRING pBcc,
249 FPDF_WIDESTRING pMsg) {
250 if (m_pInfo && m_pInfo->FFI_EmailTo)
251 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
252 pMsg);
253 }
254
255 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
256 int fileFlag,
257 FPDF_WIDESTRING uploadTo) {
258 if (m_pInfo && m_pInfo->FFI_UploadTo)
259 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
260 }
261
262 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
263 FPDF_WIDESTRING wsURL,
264 const char* mode) {
265 if (m_pInfo && m_pInfo->FFI_OpenFile)
266 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
267 return nullptr;
268 }
269
270 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
271 return L"";
272 }
273
274 int FFI_GetDocumentCount() const { return 0; }
275 int FFI_GetCurDocument() const { return 0; }
276
277 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
278 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
279 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
280 FPDF_WIDESTRING wsURL =
281 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
282
283 FPDF_LPFILEHANDLER fileHandler =
284 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
285
286 return new CFPDF_FileStream(fileHandler);
287 }
288 return nullptr;
289 }
290
291 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
292 const FX_WCHAR* wsData,
293 const FX_WCHAR* wsContentType,
294 const FX_WCHAR* wsEncode,
295 const FX_WCHAR* wsHeader) {
296 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
297 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
298 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
299
300 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
301 FPDF_WIDESTRING data =
302 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
303
304 CFX_ByteString bsContentType =
305 CFX_WideString(wsContentType).UTF16LE_Encode();
306 FPDF_WIDESTRING contentType =
307 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
308
309 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
310 FPDF_WIDESTRING encode =
311 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
312
313 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
314 FPDF_WIDESTRING header =
315 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
316
317 FPDF_BSTR response;
318 FPDF_BStr_Init(&response);
319 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
320 header, &response);
321
322 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
323 (unsigned short*)response.str, response.len / sizeof(unsigned short));
324 FPDF_BStr_Clear(&response);
325
326 return wsRet;
327 }
328 return L"";
329 }
330
331 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
332 const FX_WCHAR* wsData,
333 const FX_WCHAR* wsEncode) {
334 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
335 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
336 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
337
338 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
339 FPDF_WIDESTRING data =
340 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
341
342 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
343 FPDF_WIDESTRING encode =
344 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
345
346 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
347 }
348 return FALSE;
349 }
350
351 CFX_WideString FFI_GetLanguage() {
352 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
353 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
354 if (nRequiredLen <= 0)
355 return L"";
356
357 char* pbuff = new char[nRequiredLen];
358 memset(pbuff, 0, nRequiredLen);
359 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
360 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
361 delete[] pbuff;
362 return L"";
363 }
364 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
365 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
366 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
367 bsRet.GetLength() / sizeof(unsigned short));
368 delete[] pbuff;
369 return wsRet;
370 }
371 return L"";
372 }
373
374 void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const {
375 if (m_pInfo && m_pInfo->FFI_PageEvent)
376 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
377 }
378 #endif // PDF_ENABLE_XFA
379
380 int JS_appAlert(const FX_WCHAR* Msg,
381 const FX_WCHAR* Title,
382 FX_UINT Type,
383 FX_UINT Icon);
384 int JS_appResponse(const FX_WCHAR* Question,
385 const FX_WCHAR* Title,
386 const FX_WCHAR* Default,
387 const FX_WCHAR* cLabel,
388 FPDF_BOOL bPassword,
389 void* response,
390 int length);
391 void JS_appBeep(int nType);
392 CFX_WideString JS_fieldBrowse();
393 CFX_WideString JS_docGetFilePath();
394 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
395 void JS_docmailForm(void* mailData,
396 int length,
397 FPDF_BOOL bUI,
398 const FX_WCHAR* To,
399 const FX_WCHAR* Subject,
400 const FX_WCHAR* CC,
401 const FX_WCHAR* BCC,
402 const FX_WCHAR* Msg);
403 void JS_docprint(FPDF_BOOL bUI,
404 int nStart,
405 int nEnd,
406 FPDF_BOOL bSilent,
407 FPDF_BOOL bShrinkToFit,
408 FPDF_BOOL bPrintAsImage,
409 FPDF_BOOL bReverse,
410 FPDF_BOOL bAnnotations);
411 void JS_docgotoPage(int nPageNum);
412
413 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
414 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
415 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
416 UnderlyingDocumentType* GetUnderlyingDocument() const {
417 return m_pUnderlyingDoc;
418 }
419 CFX_ByteString GetAppName() const { return ""; }
420 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
421 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
422
423 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
424 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
425 IJS_Runtime* GetJSRuntime(); // Creates if not present.
426 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
427
428 private:
429 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
430 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
431 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
432 FPDF_FORMFILLINFO* const m_pInfo;
433 CPDFSDK_Document* m_pSDKDoc;
434 UnderlyingDocumentType* const m_pUnderlyingDoc;
435 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
436 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
437 };
438
439 #endif // FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698