1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MEDIAPROVIDER_PDF_JNI_PDFCLIENT_EXTERNAL_FORMFILLINFO_H_
18 #define MEDIAPROVIDER_PDF_JNI_PDFCLIENT_EXTERNAL_FORMFILLINFO_H_
19 
20 #include "fpdf_formfill.h"
21 
22 namespace pdfClient {
23 
FormInvalidate(FPDF_FORMFILLINFO * pThis,FPDF_PAGE page,double l,double t,double r,double b)24 static void FormInvalidate(FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, double l, double t, double r,
25                            double b) {
26     // Nothing required.
27 }
28 
FormSetCursor(FPDF_FORMFILLINFO * pThis,int nCursorType)29 static void FormSetCursor(FPDF_FORMFILLINFO* pThis, int nCursorType) {
30     // Nothing required.
31 }
32 
FormSetTimer(FPDF_FORMFILLINFO * pThis,int uElapse,TimerCallback lpTimerFunc)33 static int FormSetTimer(FPDF_FORMFILLINFO* pThis, int uElapse, TimerCallback lpTimerFunc) {
34     return 0;
35 }
36 
FormKillTimer(FPDF_FORMFILLINFO * pThis,int nTimerID)37 static void FormKillTimer(FPDF_FORMFILLINFO* pThis, int nTimerID) {
38     // Nothing required.
39 }
40 
FormGetLocalTime(FPDF_FORMFILLINFO * pThis)41 static FPDF_SYSTEMTIME FormGetLocalTime(FPDF_FORMFILLINFO* pThis) {
42     return FPDF_SYSTEMTIME();
43 }
44 
FormGetPage(FPDF_FORMFILLINFO * pThis,FPDF_DOCUMENT doc,int pageIndex)45 static FPDF_PAGE FormGetPage(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT doc, int pageIndex) {
46     return nullptr;
47 }
48 
FormGetCurrentPage(FPDF_FORMFILLINFO * pThis,FPDF_DOCUMENT doc)49 static FPDF_PAGE FormGetCurrentPage(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT doc) {
50     return nullptr;
51 }
52 
FormGetRotation(FPDF_FORMFILLINFO * pThis,FPDF_PAGE page)53 static int FormGetRotation(FPDF_FORMFILLINFO* pThis, FPDF_PAGE page) {
54     return 0;  // Unrotated.
55 }
56 
FormExecuteNamedAction(FPDF_FORMFILLINFO * pThis,FPDF_BYTESTRING namedAction)57 static void FormExecuteNamedAction(FPDF_FORMFILLINFO* pThis, FPDF_BYTESTRING namedAction) {
58     // Nothing required.
59 }
60 
FormSetTextFieldFocus(FPDF_FORMFILLINFO * pThis,FPDF_WIDESTRING value,FPDF_DWORD valueLen,FPDF_BOOL isFocus)61 static void FormSetTextFieldFocus(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING value,
62                                   FPDF_DWORD valueLen, FPDF_BOOL isFocus) {
63     // Nothing required.
64 }
65 
66 // Stubs out all the function pointers in the FormFillInfo that are required
67 // with empty implementations. Those functions that are actually needed can
68 // be set to something useful after making this call.
StubFormFillInfo(FPDF_FORMFILLINFO * ffi)69 inline void StubFormFillInfo(FPDF_FORMFILLINFO* ffi) {
70     ffi->version = 1;
71     ffi->FFI_Invalidate = &FormInvalidate;
72     ffi->FFI_SetCursor = &FormSetCursor;
73     ffi->FFI_SetTimer = &FormSetTimer;
74     ffi->FFI_KillTimer = &FormKillTimer;
75     ffi->FFI_GetLocalTime = &FormGetLocalTime;
76     ffi->FFI_GetPage = &FormGetPage;
77     ffi->FFI_GetCurrentPage = &FormGetCurrentPage;
78     ffi->FFI_GetRotation = &FormGetRotation;
79     ffi->FFI_ExecuteNamedAction = &FormExecuteNamedAction;
80     ffi->FFI_SetTextFieldFocus = &FormSetTextFieldFocus;
81     // Implementation not required for the following:
82     ffi->m_pJsPlatform = nullptr;
83     ffi->Release = nullptr;
84     ffi->FFI_OnChange = nullptr;
85     ffi->FFI_OutputSelectedRect = nullptr;
86     ffi->FFI_DoURIAction = nullptr;
87     ffi->FFI_DoGoToAction = nullptr;
88 }
89 
90 }  // namespace pdfClient
91 
92 #endif  // MEDIAPROVIDER_PDF_JNI_PDFCLIENT_EXTERNAL_FORMFILLINFO_H_