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