John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 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. |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 9 | #include "../../public/fpdf_ext.h" |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 10 | #include "../../third_party/base/nonstd_unique_ptr.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 11 | #include "../include/formfiller/FFL_FormFiller.h" |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 12 | #include "../include/fsdk_define.h" |
| 13 | #include "../include/fsdk_mgr.h" |
| 14 | #include "../include/javascript/IJavaScript.h" |
| 15 | |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 16 | #include "../include/fpdfxfa/fpdfxfa_app.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 17 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 18 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 19 | #include "../include/fpdfxfa/fpdfxfa_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
| 21 | #if _FX_OS_ == _FX_ANDROID_ |
| 22 | #include "time.h" |
| 23 | #else |
| 24 | #include <ctime> |
| 25 | #endif |
| 26 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | class CFX_SystemHandler : public IFX_SystemHandler { |
| 28 | public: |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 29 | explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) |
| 30 | : m_pEnv(pEnv), m_nCharSet(-1) {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 31 | ~CFX_SystemHandler() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | public: |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 34 | // IFX_SystemHandler |
| 35 | void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override; |
| 36 | void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) override; |
| 37 | FX_BOOL IsSelectionImplemented() override; |
| 38 | CFX_WideString GetClipboardText(FX_HWND hWnd) override { return L""; } |
| 39 | FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | return FALSE; |
| 41 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 42 | void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) override {} |
| 43 | void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) override {} |
| 44 | void SetCursor(int32_t nCursorType) override; |
| 45 | FX_HMENU CreatePopupMenu() override { return NULL; } |
| 46 | FX_BOOL AppendMenuItem(FX_HMENU hMenu, |
| 47 | int32_t nIDNewItem, |
| 48 | CFX_WideString string) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | return FALSE; |
| 50 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 51 | FX_BOOL EnableMenuItem(FX_HMENU hMenu, |
| 52 | int32_t nIDItem, |
| 53 | FX_BOOL bEnabled) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | return FALSE; |
| 55 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 56 | int32_t TrackPopupMenu(FX_HMENU hMenu, |
| 57 | int32_t x, |
| 58 | int32_t y, |
| 59 | FX_HWND hParent) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | return -1; |
| 61 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 62 | void DestroyMenu(FX_HMENU hMenu) override {} |
| 63 | CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset) override; |
| 64 | FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, |
| 65 | CFX_ByteString sFontFaceName) override; |
| 66 | CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, |
| 67 | CFX_ByteString sFontFaceName, |
| 68 | uint8_t nCharset) override; |
| 69 | int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override; |
| 70 | void KillTimer(int32_t nID) override; |
| 71 | FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | return m_pEnv->FFI_IsSHIFTKeyDown(nFlag); |
| 73 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 74 | FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | return m_pEnv->FFI_IsCTRLKeyDown(nFlag); |
| 76 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 77 | FX_BOOL IsALTKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | return m_pEnv->FFI_IsALTKeyDown(nFlag); |
| 79 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 80 | FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | return m_pEnv->FFI_IsINSERTKeyDown(nFlag); |
| 82 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 83 | FX_SYSTEMTIME GetLocalTime() override; |
| 84 | int32_t GetCharSet() override { return m_nCharSet; } |
| 85 | void SetCharSet(int32_t nCharSet) override { m_nCharSet = nCharSet; } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | CPDFDoc_Environment* m_pEnv; |
| 89 | int m_nCharSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | void CFX_SystemHandler::SetCursor(int32_t nCursorType) { |
| 93 | m_pEnv->FFI_SetCursor(nCursorType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { |
| 97 | // g_pFormFillApp->FFI_Invalidate(); |
| 98 | CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; |
| 99 | CPDFXFA_Page* pPage = NULL; |
| 100 | CPDFSDK_PageView* pPageView = NULL; |
| 101 | pPageView = pSDKAnnot->GetPageView(); |
| 102 | pPage = pSDKAnnot->GetPDFXFAPage(); |
| 103 | if (!pPage || !pPageView) |
| 104 | return; |
| 105 | CPDF_Matrix page2device; |
| 106 | pPageView->GetCurrentMatrix(page2device); |
| 107 | CPDF_Matrix device2page; |
| 108 | device2page.SetReverse(page2device); |
| 109 | FX_FLOAT left, top, right, bottom; |
| 110 | device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); |
| 111 | device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, |
| 112 | bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | CPDF_Rect rcPDF(left, bottom, right, top); |
| 114 | rcPDF.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, |
| 117 | rcPDF.bottom); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 119 | void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) { |
| 120 | CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; |
| 121 | if (pFFL) { |
| 122 | CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom); |
| 123 | CPDF_Point righttop = CPDF_Point(rect.right, rect.top); |
| 124 | CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); |
| 125 | CPDF_Point ptB = pFFL->PWLtoFFL(righttop); |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); |
| 128 | ASSERT(pAnnot); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 129 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | ASSERT(pPage); |
| 131 | m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); |
| 132 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | FX_BOOL CFX_SystemHandler::IsSelectionImplemented() { |
| 136 | if (m_pEnv) { |
| 137 | FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); |
| 138 | if (pInfo && pInfo->FFI_OutputSelectedRect) |
| 139 | return TRUE; |
| 140 | } |
| 141 | return FALSE; |
| 142 | } |
| 143 | |
| 144 | CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset) { |
| 145 | return ""; |
| 146 | } |
| 147 | |
| 148 | FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont( |
| 149 | int32_t nCharset, |
| 150 | CFX_ByteString sFontFaceName) { |
| 151 | CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
Lei Zhang | 122ee21 | 2015-10-21 17:07:24 -0700 | [diff] [blame] | 152 | if (!pFontMgr) |
| 153 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 154 | |
Lei Zhang | 122ee21 | 2015-10-21 17:07:24 -0700 | [diff] [blame] | 155 | CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
| 156 | if (!pFontMapper) |
| 157 | return FALSE; |
| 158 | |
| 159 | int nSize = pFontMapper->m_InstalledTTFonts.GetSize(); |
| 160 | if (nSize == 0) { |
| 161 | pFontMapper->LoadInstalledFonts(); |
| 162 | nSize = pFontMapper->m_InstalledTTFonts.GetSize(); |
| 163 | } |
| 164 | |
| 165 | for (int i = 0; i < nSize; ++i) { |
| 166 | if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName)) |
| 167 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return FALSE; |
| 171 | } |
| 172 | |
| 173 | static int CharSet2CP(int charset) { |
| 174 | if (charset == 128) |
| 175 | return 932; |
| 176 | if (charset == 134) |
| 177 | return 936; |
| 178 | if (charset == 129) |
| 179 | return 949; |
| 180 | if (charset == 136) |
| 181 | return 950; |
| 182 | return 0; |
| 183 | } |
| 184 | CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( |
| 185 | CPDF_Document* pDoc, |
| 186 | CFX_ByteString sFontFaceName, |
| 187 | uint8_t nCharset) { |
| 188 | if (pDoc) { |
| 189 | CFX_Font* pFXFont = new CFX_Font(); |
| 190 | pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), |
| 191 | FALSE); |
| 192 | CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); |
| 193 | delete pFXFont; |
| 194 | return pFont; |
| 195 | } |
| 196 | |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, |
| 201 | TimerCallback lpTimerFunc) { |
| 202 | return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); |
| 203 | } |
| 204 | void CFX_SystemHandler::KillTimer(int32_t nID) { |
| 205 | m_pEnv->FFI_KillTimer(nID); |
| 206 | } |
| 207 | |
| 208 | FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { |
| 209 | return m_pEnv->FFI_GetLocalTime(); |
| 210 | } |
| 211 | |
| 212 | CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc, |
| 213 | FPDF_FORMFILLINFO* pFFinfo) |
Oliver Chang | de6088d | 2015-10-30 16:30:28 -0700 | [diff] [blame] | 214 | : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pXFADoc(pDoc) { |
| 215 | m_pSysHandler.reset(new CFX_SystemHandler(this)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | CPDFDoc_Environment::~CPDFDoc_Environment() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
Tom Sepez | ed7b2b5 | 2015-09-22 08:36:17 -0700 | [diff] [blame] | 220 | if (pProvider->m_pEnvList.GetSize() == 0) |
| 221 | pProvider->SetJavaScriptInitialized(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, |
| 225 | const FX_WCHAR* Title, |
| 226 | FX_UINT Type, |
| 227 | FX_UINT Icon) { |
| 228 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { |
| 229 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 230 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 231 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 232 | FPDF_WIDESTRING pTitle = |
| 233 | (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); |
| 234 | int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, |
| 235 | pTitle, Type, Icon); |
| 236 | bsMsg.ReleaseBuffer(); |
| 237 | bsTitle.ReleaseBuffer(); |
| 238 | return ret; |
| 239 | } |
| 240 | return -1; |
| 241 | } |
| 242 | |
| 243 | int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, |
| 244 | const FX_WCHAR* Title, |
| 245 | const FX_WCHAR* Default, |
| 246 | const FX_WCHAR* cLabel, |
| 247 | FPDF_BOOL bPassword, |
| 248 | void* response, |
| 249 | int length) { |
| 250 | if (m_pInfo && m_pInfo->m_pJsPlatform && |
| 251 | m_pInfo->m_pJsPlatform->app_response) { |
| 252 | CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); |
| 253 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 254 | CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); |
| 255 | CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); |
| 256 | FPDF_WIDESTRING pQuestion = |
| 257 | (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength()); |
| 258 | FPDF_WIDESTRING pTitle = |
| 259 | (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); |
| 260 | FPDF_WIDESTRING pDefault = |
| 261 | (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength()); |
| 262 | FPDF_WIDESTRING pLabel = |
| 263 | (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength()); |
| 264 | int ret = m_pInfo->m_pJsPlatform->app_response( |
| 265 | m_pInfo->m_pJsPlatform, pQuestion, pTitle, pDefault, pLabel, bPassword, |
| 266 | response, length); |
| 267 | bsQuestion.ReleaseBuffer(); |
| 268 | bsTitle.ReleaseBuffer(); |
| 269 | bsDefault.ReleaseBuffer(); |
| 270 | bsLabel.ReleaseBuffer(); |
| 271 | return ret; |
| 272 | } |
| 273 | return -1; |
| 274 | } |
| 275 | |
| 276 | CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { |
| 277 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 278 | !m_pInfo->m_pJsPlatform->Field_browse) { |
| 279 | return L""; |
| 280 | } |
| 281 | |
| 282 | const int nRequiredLen = |
| 283 | m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); |
| 284 | if (nRequiredLen <= 0) |
| 285 | return L""; |
| 286 | |
| 287 | nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 288 | memset(pBuff.get(), 0, nRequiredLen); |
| 289 | const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( |
| 290 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 291 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 292 | return L""; |
| 293 | |
| 294 | CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 295 | CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 296 | return wsRet; |
| 297 | } |
| 298 | |
| 299 | CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { |
| 300 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 301 | !m_pInfo->m_pJsPlatform->Doc_getFilePath) { |
| 302 | return L""; |
| 303 | } |
| 304 | |
| 305 | const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 306 | m_pInfo->m_pJsPlatform, nullptr, 0); |
| 307 | if (nRequiredLen <= 0) |
| 308 | return L""; |
| 309 | |
| 310 | nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 311 | memset(pBuff.get(), 0, nRequiredLen); |
| 312 | const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 313 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 314 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 315 | return L""; |
| 316 | |
| 317 | CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 318 | CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 319 | return wsRet; |
| 320 | } |
| 321 | |
| 322 | void CPDFDoc_Environment::JS_docSubmitForm(void* formData, |
| 323 | int length, |
| 324 | const FX_WCHAR* URL) { |
| 325 | if (m_pInfo && m_pInfo->m_pJsPlatform && |
| 326 | m_pInfo->m_pJsPlatform->Doc_submitForm) { |
| 327 | CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); |
| 328 | FPDF_WIDESTRING pDestination = |
| 329 | (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength()); |
| 330 | m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, |
| 331 | length, pDestination); |
| 332 | bsDestination.ReleaseBuffer(); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void CPDFDoc_Environment::JS_docmailForm(void* mailData, |
| 337 | int length, |
| 338 | FPDF_BOOL bUI, |
| 339 | const FX_WCHAR* To, |
| 340 | const FX_WCHAR* Subject, |
| 341 | const FX_WCHAR* CC, |
| 342 | const FX_WCHAR* BCC, |
| 343 | const FX_WCHAR* Msg) { |
| 344 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) { |
| 345 | CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); |
| 346 | CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode(); |
| 347 | CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); |
| 348 | CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); |
| 349 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 350 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); |
| 351 | FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); |
| 352 | FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); |
| 353 | FPDF_WIDESTRING pSubject = |
| 354 | (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); |
| 355 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 356 | m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, |
| 357 | bUI, pTo, pSubject, pCC, pBcc, pMsg); |
| 358 | bsTo.ReleaseBuffer(); |
| 359 | bsCC.ReleaseBuffer(); |
| 360 | bsBcc.ReleaseBuffer(); |
| 361 | bsSubject.ReleaseBuffer(); |
| 362 | bsMsg.ReleaseBuffer(); |
| 363 | } |
| 364 | } |
| 365 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 366 | IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | if (!IsJSInitiated()) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 368 | return NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | if (!m_pJSRuntime) |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 370 | m_pJSRuntime.reset(IJS_Runtime::Create(this)); |
Tom Sepez | 854a7f6 | 2015-09-21 17:07:49 -0700 | [diff] [blame] | 371 | return m_pJSRuntime.get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { |
| 375 | if (!m_pAnnotHandlerMgr) |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 376 | m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); |
| 377 | return m_pAnnotHandlerMgr.get(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { |
| 381 | if (!m_pActionHandler) |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 382 | m_pActionHandler.reset(new CPDFSDK_ActionHandler()); |
| 383 | return m_pActionHandler.get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 386 | CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { |
| 387 | if (!m_pIFormFiller) |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 388 | m_pIFormFiller.reset(new CFFL_IFormFiller(this)); |
| 389 | return m_pIFormFiller.get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc, |
| 393 | CPDFDoc_Environment* pEnv) |
| 394 | : m_pDoc(pDoc), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | m_pFocusAnnot(nullptr), |
| 396 | m_pEnv(pEnv), |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 397 | m_bChangeMask(FALSE), |
| 398 | m_bBeingDestroyed(FALSE) { |
| 399 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 400 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 401 | CPDFSDK_Document::~CPDFSDK_Document() { |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 402 | m_bBeingDestroyed = TRUE; |
| 403 | |
| 404 | for (auto& it : m_pageMap) |
| 405 | it.second->KillFocusAnnotIfNeeded(); |
| 406 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | for (auto& it : m_pageMap) |
| 408 | delete it.second; |
| 409 | m_pageMap.clear(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 410 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 411 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 412 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, |
| 413 | FX_BOOL ReNew) { |
| 414 | auto it = m_pageMap.find(pPDFXFAPage); |
| 415 | if (it != m_pageMap.end()) |
| 416 | return it->second; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 417 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 418 | if (!ReNew) |
| 419 | return nullptr; |
| 420 | |
| 421 | CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFXFAPage); |
| 422 | m_pageMap[pPDFXFAPage] = pPageView; |
| 423 | // Delay to load all the annotations, to avoid endless loop. |
| 424 | pPageView->LoadFXAnnots(); |
| 425 | return pPageView; |
| 426 | } |
| 427 | |
| 428 | CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { |
| 429 | CPDFXFA_Page* pPage = (CPDFXFA_Page*)m_pEnv->FFI_GetCurrentPage(m_pDoc); |
| 430 | return pPage ? GetPageView(pPage, TRUE) : nullptr; |
| 431 | } |
| 432 | |
| 433 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { |
| 434 | CPDFXFA_Page* pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); |
| 435 | if (!pTempPage) |
| 436 | return nullptr; |
| 437 | |
| 438 | auto it = m_pageMap.find(pTempPage); |
| 439 | return it->second; |
| 440 | } |
| 441 | |
| 442 | void CPDFSDK_Document::ProcJavascriptFun() { |
| 443 | CPDFXFA_Document* pPDFDoc = GetDocument(); |
| 444 | CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc()); |
| 445 | int iCount = docJS.CountJSActions(); |
| 446 | if (iCount < 1) |
| 447 | return; |
| 448 | for (int i = 0; i < iCount; i++) { |
| 449 | CFX_ByteString csJSName; |
| 450 | CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
| 451 | if (m_pEnv->GetActionHander()) |
| 452 | m_pEnv->GetActionHander()->DoAction_JavaScript( |
| 453 | jsAction, CFX_WideString::FromLocal(csJSName), this); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | FX_BOOL CPDFSDK_Document::ProcOpenAction() { |
| 458 | if (!m_pDoc) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 459 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | |
| 461 | CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot(); |
| 462 | if (!pRoot) |
| 463 | return FALSE; |
| 464 | |
| 465 | CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); |
| 466 | if (!pOpenAction) |
| 467 | pOpenAction = pRoot->GetArray("OpenAction"); |
| 468 | |
| 469 | if (!pOpenAction) |
| 470 | return FALSE; |
| 471 | |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 472 | if (pOpenAction->IsArray()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | return TRUE; |
| 474 | |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 475 | if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | CPDF_Action action(pDict); |
| 477 | if (m_pEnv->GetActionHander()) |
| 478 | m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); |
| 479 | return TRUE; |
| 480 | } |
| 481 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | CPDF_OCContext* CPDFSDK_Document::GetOCContext() { |
| 485 | if (!m_pOccontent) |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 486 | m_pOccontent.reset(new CPDF_OCContext(m_pDoc->GetPDFDoc())); |
| 487 | return m_pOccontent.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 488 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 489 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) { |
| 491 | auto it = m_pageMap.find(pPDFXFAPage); |
| 492 | if (it == m_pageMap.end()) |
| 493 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 494 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | CPDFSDK_PageView* pPageView = it->second; |
| 496 | if (pPageView->IsLocked()) |
| 497 | return; |
| 498 | |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 499 | pPageView->KillFocusAnnotIfNeeded(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | delete pPageView; |
| 501 | m_pageMap.erase(it); |
| 502 | } |
| 503 | |
| 504 | CPDFXFA_Page* CPDFSDK_Document::GetPage(int nIndex) { |
| 505 | CPDFXFA_Page* pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); |
| 506 | if (!pTempPage) |
| 507 | return NULL; |
| 508 | return pTempPage; |
| 509 | } |
| 510 | |
| 511 | CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { |
| 512 | if (!m_pInterForm) |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 513 | m_pInterForm.reset(new CPDFSDK_InterForm(this)); |
| 514 | return m_pInterForm.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, |
| 518 | CPDFSDK_Annot* pAnnot) { |
| 519 | for (const auto& it : m_pageMap) { |
| 520 | CPDFSDK_PageView* pPageView = it.second; |
| 521 | if (pPageView != pSender) { |
| 522 | pPageView->UpdateView(pAnnot); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { |
| 528 | return m_pFocusAnnot; |
| 529 | } |
| 530 | |
| 531 | FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 532 | if (m_bBeingDestroyed) |
| 533 | return FALSE; |
| 534 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | if (m_pFocusAnnot == pAnnot) |
| 536 | return TRUE; |
| 537 | |
| 538 | CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
| 539 | |
| 540 | if (m_pFocusAnnot) { |
| 541 | if (!KillFocusAnnot(nFlag)) |
| 542 | return FALSE; |
| 543 | } |
| 544 | CPDFSDK_PageView* pPageView = NULL; |
| 545 | if (pAnnot) |
| 546 | pPageView = pAnnot->GetPageView(); |
| 547 | if (pAnnot && pPageView->IsValid()) { |
| 548 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 549 | if (!m_pFocusAnnot) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 551 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 552 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 553 | if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) |
| 554 | return FALSE; |
| 555 | if (!m_pFocusAnnot) { |
| 556 | m_pFocusAnnot = pAnnot; |
| 557 | return TRUE; |
| 558 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 559 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 560 | } |
| 561 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { |
| 565 | if (m_pFocusAnnot) { |
| 566 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 567 | CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
| 568 | m_pFocusAnnot = nullptr; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 569 | |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 570 | if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) |
| 571 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 572 | |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 573 | if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
| 574 | if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) { |
| 575 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
| 576 | int nFieldType = pWidget->GetFieldType(); |
| 577 | if (FIELDTYPE_TEXTFIELD == nFieldType || |
| 578 | FIELDTYPE_COMBOBOX == nFieldType) { |
| 579 | m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | } |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 582 | |
| 583 | if (!m_pFocusAnnot) |
| 584 | return TRUE; |
| 585 | } else { |
| 586 | m_pFocusAnnot = pFocusAnnot; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 587 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 588 | } |
| 589 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 590 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 591 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount) { |
| 593 | if (nStart < 0 || nStart >= GetPageCount() || nCount <= 0) { |
| 594 | return FALSE; |
| 595 | } |
| 596 | |
| 597 | CPDFXFA_Page* pTempPage = NULL; |
| 598 | for (int i = nCount - 1; i >= 0; i--) { |
| 599 | pTempPage = GetPage(nStart + i); |
| 600 | if (pTempPage != NULL) { |
| 601 | ReMovePageView(pTempPage); |
| 602 | } |
| 603 | } |
| 604 | return TRUE; |
| 605 | } |
| 606 | |
| 607 | void CPDFSDK_Document::OnCloseDocument() { |
| 608 | KillFocusAnnot(); |
| 609 | } |
| 610 | |
| 611 | FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { |
| 612 | FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions(); |
| 613 | return dwPermissions & nFlag; |
| 614 | } |
| 615 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 616 | IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | ASSERT(m_pEnv != NULL); |
| 618 | return m_pEnv->GetJSRuntime(); |
| 619 | } |
| 620 | |
| 621 | CFX_WideString CPDFSDK_Document::GetPath() { |
| 622 | ASSERT(m_pEnv != NULL); |
| 623 | return m_pEnv->JS_docGetFilePath(); |
| 624 | } |
| 625 | |
| 626 | CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
| 627 | CPDFXFA_Page* page) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 628 | : m_page(page), |
| 629 | m_pSDKDoc(pSDKDoc), |
| 630 | m_CaptureWidget(nullptr), |
| 631 | m_bEnterWidget(FALSE), |
| 632 | m_bExitWidget(FALSE), |
| 633 | m_bOnWidget(FALSE), |
| 634 | m_bValid(FALSE), |
| 635 | m_bLocked(FALSE) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
| 637 | if (pInterForm) { |
| 638 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 639 | if (page->GetPDFPage()) |
| 640 | pPDFInterForm->FixPageFields(page->GetPDFPage()); |
| 641 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | CPDFSDK_PageView::~CPDFSDK_PageView() { |
| 645 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 646 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 647 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 649 | m_fxAnnotArray.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 651 | m_pAnnotList.reset(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 655 | CPDF_Matrix* pUser2Device, |
| 656 | CPDF_RenderOptions* pOptions, |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame^] | 657 | const FX_RECT& pClip) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 658 | m_curMatrix = *pUser2Device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 659 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 660 | CPDFXFA_Page* pPage = GetPDFXFAPage(); |
| 661 | |
| 662 | if (pPage == NULL) |
| 663 | return; |
| 664 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 665 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { |
| 667 | CFX_Graphics gs; |
| 668 | gs.Create(pDevice); |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame^] | 669 | CFX_RectF rectClip; |
| 670 | rectClip.Set(static_cast<FX_FLOAT>(pClip.left), |
| 671 | static_cast<FX_FLOAT>(pClip.top), |
| 672 | static_cast<FX_FLOAT>(pClip.Width()), |
| 673 | static_cast<FX_FLOAT>(pClip.Height())); |
| 674 | gs.SetClipRect(rectClip); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); |
| 676 | if (!pRenderContext) |
| 677 | return; |
| 678 | CXFA_RenderOptions renderOptions; |
| 679 | renderOptions.m_bHighlight = TRUE; |
| 680 | pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, |
| 681 | renderOptions); |
| 682 | pRenderContext->DoRender(); |
| 683 | pRenderContext->StopRender(); |
| 684 | pRenderContext->Release(); |
| 685 | return; |
| 686 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 687 | #endif // PDF_ENABLE_XFA |
| 688 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 689 | // for pdf/static xfa. |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 690 | CPDFSDK_AnnotIterator annotIterator(this, true); |
| 691 | while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 693 | pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 696 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 697 | const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
| 698 | FX_FLOAT pageY) { |
| 699 | for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 700 | CFX_FloatRect annotRect; |
| 701 | pAnnot->GetRect(annotRect); |
| 702 | if (annotRect.Contains(pageX, pageY)) |
| 703 | return pAnnot; |
| 704 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 705 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 708 | const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, |
| 709 | FX_FLOAT pageY) { |
| 710 | for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | if (pAnnot->GetSubType() == "Widget") { |
| 712 | CFX_FloatRect annotRect; |
| 713 | pAnnot->GetRect(annotRect); |
| 714 | if (annotRect.Contains(pageX, pageY)) |
| 715 | return pAnnot; |
| 716 | } |
| 717 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 718 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, |
| 722 | FX_FLOAT pageY) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 724 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 725 | CPDFSDK_AnnotIterator annotIterator(this, false); |
| 726 | while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 728 | if (rc.Contains(pageX, pageY)) |
| 729 | return pSDKAnnot; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 732 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, |
| 736 | FX_FLOAT pageY) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 738 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 739 | CPDFSDK_AnnotIterator annotIterator(this, false); |
| 740 | while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 741 | if (pSDKAnnot->GetType() == "Widget" || |
| 742 | pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME) { |
| 743 | pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 744 | CPDF_Point point(pageX, pageY); |
| 745 | if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
| 746 | return pSDKAnnot; |
| 747 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 750 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 753 | void CPDFSDK_PageView::KillFocusAnnotIfNeeded() { |
| 754 | // if there is a focused annot on the page, we should kill the focus first. |
| 755 | if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) { |
| 756 | auto it = |
| 757 | std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), focusedAnnot); |
| 758 | if (it != m_fxAnnotArray.end()) |
| 759 | KillFocusAnnot(); |
| 760 | } |
| 761 | } |
| 762 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 763 | FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) { |
| 764 | CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict(); |
| 765 | if (pAnnotDic) |
| 766 | return pAnnotDic->KeyExist("AS"); |
| 767 | return FALSE; |
| 768 | } |
| 769 | |
| 770 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { |
| 771 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 772 | ASSERT(pEnv); |
| 773 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 774 | CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 775 | if (!pSDKAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 776 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 777 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 778 | m_fxAnnotArray.push_back(pSDKAnnot); |
| 779 | pAnnotHandler->Annot_OnCreate(pSDKAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 780 | return pSDKAnnot; |
| 781 | } |
| 782 | |
| 783 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { |
| 784 | if (!pPDFAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 785 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 786 | |
| 787 | CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 788 | if (pSDKAnnot) |
| 789 | return pSDKAnnot; |
| 790 | |
| 791 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 792 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 793 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 794 | if (!pSDKAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 795 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 796 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 797 | m_fxAnnotArray.push_back(pSDKAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | return pSDKAnnot; |
| 799 | } |
| 800 | |
| 801 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { |
| 802 | return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; |
| 803 | } |
| 804 | |
| 805 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, |
| 806 | CPDF_Dictionary* pDict) { |
| 807 | return NULL; |
| 808 | } |
| 809 | |
| 810 | FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
| 811 | if (!pAnnot) |
| 812 | return FALSE; |
| 813 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 814 | if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
| 815 | pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA)) |
| 816 | return FALSE; |
| 817 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 818 | auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); |
| 819 | if (it != m_fxAnnotArray.end()) |
| 820 | m_fxAnnotArray.erase(it); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 821 | if (m_CaptureWidget == pAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 822 | m_CaptureWidget = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | |
| 824 | return TRUE; |
| 825 | } |
| 826 | |
| 827 | CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
| 828 | if (m_page) { |
| 829 | return m_page->GetDocument()->GetPDFDoc(); |
| 830 | } |
| 831 | return NULL; |
| 832 | } |
| 833 | |
| 834 | CPDF_Page* CPDFSDK_PageView::GetPDFPage() { |
| 835 | if (m_page) { |
| 836 | return m_page->GetPDFPage(); |
| 837 | } |
| 838 | |
| 839 | return NULL; |
| 840 | } |
| 841 | |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 842 | size_t CPDFSDK_PageView::CountAnnots() const { |
| 843 | return m_fxAnnotArray.size(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 846 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { |
| 847 | return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 851 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 852 | if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 853 | return pAnnot; |
| 854 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 855 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 856 | } |
| 857 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 858 | if (!hWidget) |
| 859 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 860 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 861 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 862 | if (pAnnot->GetXFAWidget() == hWidget) |
| 863 | return pAnnot; |
| 864 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 865 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, |
| 869 | FX_UINT nFlag) { |
| 870 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 871 | ASSERT(pEnv); |
| 872 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 873 | if (!pFXAnnot) { |
| 874 | KillFocusAnnot(nFlag); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 875 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 876 | } |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 877 | |
| 878 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 879 | FX_BOOL bRet = |
| 880 | pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); |
| 881 | if (bRet) |
| 882 | SetFocusAnnot(pFXAnnot); |
| 883 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, |
| 887 | FX_UINT nFlag) { |
| 888 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 889 | ASSERT(pEnv); |
| 890 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 891 | ASSERT(pAnnotHandlerMgr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 892 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 894 | |
| 895 | if (pFXAnnot == NULL) |
| 896 | return FALSE; |
| 897 | |
| 898 | FX_BOOL bRet = |
| 899 | pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); |
| 900 | if (bRet) { |
| 901 | SetFocusAnnot(pFXAnnot); |
| 902 | } |
| 903 | return TRUE; |
| 904 | } |
| 905 | |
| 906 | FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 907 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 908 | ASSERT(pEnv); |
| 909 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 910 | |
| 911 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 912 | |
| 913 | if (pFXAnnot == NULL) |
| 914 | return FALSE; |
| 915 | |
| 916 | FX_BOOL bRet = |
| 917 | pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); |
| 918 | if (bRet) { |
| 919 | SetFocusAnnot(pFXAnnot); |
| 920 | } |
| 921 | return TRUE; |
| 922 | } |
| 923 | |
| 924 | FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 925 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 926 | ASSERT(pEnv); |
| 927 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 928 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 929 | CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); |
| 930 | FX_BOOL bRet = FALSE; |
| 931 | if (pFocusAnnot && pFocusAnnot != pFXAnnot) { |
| 932 | // Last focus Annot gets a chance to handle the event. |
| 933 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); |
| 934 | } |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 935 | if (pFXAnnot && !bRet) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 936 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 937 | return bRet; |
| 938 | } |
| 939 | |
| 940 | FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point& point, int nFlag) { |
| 941 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 942 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 943 | if (CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
| 944 | if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { |
| 945 | m_bExitWidget = TRUE; |
| 946 | m_bEnterWidget = FALSE; |
| 947 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 948 | } |
| 949 | m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot; |
| 950 | m_bOnWidget = TRUE; |
| 951 | if (!m_bEnterWidget) { |
| 952 | m_bEnterWidget = TRUE; |
| 953 | m_bExitWidget = FALSE; |
| 954 | pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); |
| 955 | } |
| 956 | pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); |
| 957 | return TRUE; |
| 958 | } |
| 959 | if (m_bOnWidget) { |
| 960 | m_bOnWidget = FALSE; |
| 961 | m_bExitWidget = TRUE; |
| 962 | m_bEnterWidget = FALSE; |
| 963 | if (m_CaptureWidget) { |
| 964 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 965 | m_CaptureWidget = NULL; |
| 966 | } |
| 967 | } |
| 968 | return FALSE; |
| 969 | } |
| 970 | |
| 971 | FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, |
| 972 | double deltaY, |
| 973 | const CPDF_Point& point, |
| 974 | int nFlag) { |
| 975 | if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 976 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 977 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 978 | return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, |
| 979 | (int)deltaY, point); |
| 980 | } |
| 981 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 984 | FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) { |
| 985 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 986 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 987 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 988 | return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
| 989 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 990 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 991 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 994 | FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { |
| 995 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 996 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 997 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 998 | return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 999 | } |
| 1000 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1003 | FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1004 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1007 | void CPDFSDK_PageView::LoadFXAnnots() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1008 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1009 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1010 | |
| 1011 | SetLock(TRUE); |
| 1012 | m_page->AddRef(); |
| 1013 | if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { |
| 1014 | IXFA_PageView* pageView = NULL; |
| 1015 | pageView = m_page->GetXFAPageView(); |
| 1016 | ASSERT(pageView != NULL); |
| 1017 | |
| 1018 | IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator( |
| 1019 | XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible | |
| 1020 | XFA_WIDGETFILTER_Viewable | |
| 1021 | XFA_WIDGETFILTER_AllType); |
| 1022 | if (!pWidgetHander) { |
| 1023 | m_page->Release(); |
| 1024 | SetLock(FALSE); |
| 1025 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1026 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1027 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1028 | while (IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1029 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1030 | if (!pAnnot) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1031 | continue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1032 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1033 | m_fxAnnotArray.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | pWidgetHander->Release(); |
| 1038 | } else { |
| 1039 | CPDF_Page* pPage = m_page->GetPDFPage(); |
| 1040 | ASSERT(pPage != NULL); |
| 1041 | |
| 1042 | FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 1043 | // Disable the default AP construction. |
| 1044 | CPDF_InterForm::EnableUpdateAP(FALSE); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1045 | m_pAnnotList.reset(new CPDF_AnnotList(pPage)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1046 | CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
| 1047 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1048 | const size_t nCount = m_pAnnotList->Count(); |
| 1049 | for (size_t i = 0; i < nCount; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1050 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 1051 | CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1052 | |
| 1053 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 1054 | if (!pAnnot) |
| 1055 | continue; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1056 | m_fxAnnotArray.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1057 | |
| 1058 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1059 | } |
| 1060 | } |
| 1061 | m_page->Release(); |
| 1062 | SetLock(FALSE); |
| 1063 | } |
| 1064 | |
| 1065 | void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { |
| 1066 | for (int i = 0; i < rects.GetSize(); i++) { |
| 1067 | CPDF_Rect rc = rects.GetAt(i); |
| 1068 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1069 | pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
| 1074 | CPDF_Rect rcWindow = pAnnot->GetRect(); |
| 1075 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1076 | pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, |
| 1077 | rcWindow.bottom); |
| 1078 | } |
| 1079 | |
| 1080 | int CPDFSDK_PageView::GetPageIndex() { |
| 1081 | if (m_page) { |
| 1082 | CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
| 1083 | CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); |
| 1084 | if (pDoc && pDic) { |
| 1085 | return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); |
| 1086 | } |
| 1087 | } |
| 1088 | return -1; |
| 1089 | } |
| 1090 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1091 | bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1092 | if (!p) |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1093 | return false; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1094 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1095 | const auto& annots = m_pAnnotList->All(); |
| 1096 | return std::find(annots.begin(), annots.end(), p) != annots.end(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1099 | CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
| 1100 | CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
| 1101 | if (!pFocusAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1102 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1103 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1104 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1105 | if (pAnnot == pFocusAnnot) |
| 1106 | return pAnnot; |
| 1107 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1108 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1109 | } |