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 | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 393 | CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | CPDFDoc_Environment* pEnv) |
| 395 | : m_pDoc(pDoc), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 396 | m_pFocusAnnot(nullptr), |
| 397 | m_pEnv(pEnv), |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 398 | m_bChangeMask(FALSE), |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 399 | m_bBeingDestroyed(FALSE) {} |
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 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 412 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView( |
| 413 | UnderlyingPageType* pUnderlyingPage, |
| 414 | FX_BOOL ReNew) { |
| 415 | auto it = m_pageMap.find(pUnderlyingPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 416 | if (it != m_pageMap.end()) |
| 417 | return it->second; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 418 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | if (!ReNew) |
| 420 | return nullptr; |
| 421 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 422 | CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); |
| 423 | m_pageMap[pUnderlyingPage] = pPageView; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | // Delay to load all the annotations, to avoid endless loop. |
| 425 | pPageView->LoadFXAnnots(); |
| 426 | return pPageView; |
| 427 | } |
| 428 | |
| 429 | CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 430 | UnderlyingPageType* pPage = |
| 431 | UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | return pPage ? GetPageView(pPage, TRUE) : nullptr; |
| 433 | } |
| 434 | |
| 435 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 436 | UnderlyingPageType* pTempPage = |
| 437 | UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 438 | if (!pTempPage) |
| 439 | return nullptr; |
| 440 | |
| 441 | auto it = m_pageMap.find(pTempPage); |
| 442 | return it->second; |
| 443 | } |
| 444 | |
| 445 | void CPDFSDK_Document::ProcJavascriptFun() { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 446 | CPDF_Document* pPDFDoc = GetPDFDocument(); |
| 447 | CPDF_DocJSActions docJS(pPDFDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | int iCount = docJS.CountJSActions(); |
| 449 | if (iCount < 1) |
| 450 | return; |
| 451 | for (int i = 0; i < iCount; i++) { |
| 452 | CFX_ByteString csJSName; |
| 453 | CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
| 454 | if (m_pEnv->GetActionHander()) |
| 455 | m_pEnv->GetActionHander()->DoAction_JavaScript( |
| 456 | jsAction, CFX_WideString::FromLocal(csJSName), this); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | FX_BOOL CPDFSDK_Document::ProcOpenAction() { |
| 461 | if (!m_pDoc) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 462 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 464 | CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | if (!pRoot) |
| 466 | return FALSE; |
| 467 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame^] | 468 | CPDF_Object* pOpenAction = pRoot->GetDictBy("OpenAction"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | if (!pOpenAction) |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame^] | 470 | pOpenAction = pRoot->GetArrayBy("OpenAction"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | |
| 472 | if (!pOpenAction) |
| 473 | return FALSE; |
| 474 | |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 475 | if (pOpenAction->IsArray()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | return TRUE; |
| 477 | |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 478 | if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | CPDF_Action action(pDict); |
| 480 | if (m_pEnv->GetActionHander()) |
| 481 | m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); |
| 482 | return TRUE; |
| 483 | } |
| 484 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | CPDF_OCContext* CPDFSDK_Document::GetOCContext() { |
| 488 | if (!m_pOccontent) |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 489 | m_pOccontent.reset(new CPDF_OCContext(GetPDFDocument())); |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 490 | return m_pOccontent.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 491 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 492 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 493 | void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { |
| 494 | auto it = m_pageMap.find(pUnderlyingPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | if (it == m_pageMap.end()) |
| 496 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 497 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 498 | CPDFSDK_PageView* pPageView = it->second; |
| 499 | if (pPageView->IsLocked()) |
| 500 | return; |
| 501 | |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 502 | pPageView->KillFocusAnnotIfNeeded(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | delete pPageView; |
| 504 | m_pageMap.erase(it); |
| 505 | } |
| 506 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 507 | UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { |
| 508 | return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | if (m_pFocusAnnot) { |
| 539 | if (!KillFocusAnnot(nFlag)) |
| 540 | return FALSE; |
| 541 | } |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 542 | |
| 543 | if (!pAnnot) |
| 544 | return FALSE; |
| 545 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 546 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 547 | CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 548 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 549 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
| 550 | if (pPageView && pPageView->IsValid()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 551 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 552 | if (!m_pFocusAnnot) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 553 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 554 | if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 555 | return FALSE; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 556 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) |
| 558 | return FALSE; |
| 559 | if (!m_pFocusAnnot) { |
| 560 | m_pFocusAnnot = pAnnot; |
| 561 | return TRUE; |
| 562 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 563 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | } |
| 565 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { |
| 569 | if (m_pFocusAnnot) { |
| 570 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 571 | CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
| 572 | m_pFocusAnnot = nullptr; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 573 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 574 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 575 | if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) |
| 576 | return FALSE; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 577 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 578 | |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 579 | if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 580 | if (pFocusAnnot->GetType() == "Widget") { |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 581 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
| 582 | int nFieldType = pWidget->GetFieldType(); |
| 583 | if (FIELDTYPE_TEXTFIELD == nFieldType || |
| 584 | FIELDTYPE_COMBOBOX == nFieldType) { |
| 585 | m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 586 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 587 | } |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 588 | |
| 589 | if (!m_pFocusAnnot) |
| 590 | return TRUE; |
| 591 | } else { |
| 592 | m_pFocusAnnot = pFocusAnnot; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 593 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | } |
| 595 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 596 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 597 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 598 | void CPDFSDK_Document::OnCloseDocument() { |
| 599 | KillFocusAnnot(); |
| 600 | } |
| 601 | |
| 602 | FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 603 | return GetPDFDocument()->GetUserPermissions() & nFlag; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 606 | IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 607 | return m_pEnv->GetJSRuntime(); |
| 608 | } |
| 609 | |
| 610 | CFX_WideString CPDFSDK_Document::GetPath() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 611 | return m_pEnv->JS_docGetFilePath(); |
| 612 | } |
| 613 | |
| 614 | CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 615 | UnderlyingPageType* page) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 616 | : m_page(page), |
| 617 | m_pSDKDoc(pSDKDoc), |
| 618 | m_CaptureWidget(nullptr), |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 619 | #ifndef PDF_ENABLE_XFA |
| 620 | m_bTakeOverPage(FALSE), |
| 621 | #endif // PDF_ENABLE_XFA |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 622 | m_bEnterWidget(FALSE), |
| 623 | m_bExitWidget(FALSE), |
| 624 | m_bOnWidget(FALSE), |
| 625 | m_bValid(FALSE), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 626 | m_bLocked(FALSE) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 627 | CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
| 628 | if (pInterForm) { |
| 629 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 630 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | if (page->GetPDFPage()) |
| 632 | pPDFInterForm->FixPageFields(page->GetPDFPage()); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 633 | #else // PDF_ENABLE_XFA |
| 634 | pPDFInterForm->FixPageFields(page); |
| 635 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | } |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 637 | #ifndef PDF_ENABLE_XFA |
| 638 | m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 639 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | CPDFSDK_PageView::~CPDFSDK_PageView() { |
| 643 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 644 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 645 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 646 | pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 647 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 648 | m_fxAnnotArray.clear(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 649 | m_pAnnotList.reset(); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 650 | #ifndef PDF_ENABLE_XFA |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 651 | m_page->RemovePrivateData((void*)m_page); |
| 652 | if (m_bTakeOverPage) { |
| 653 | delete m_page; |
| 654 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 655 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 659 | CFX_Matrix* pUser2Device, |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 660 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | CPDF_RenderOptions* pOptions, |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame] | 662 | const FX_RECT& pClip) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 663 | #else |
| 664 | CPDF_RenderOptions* pOptions) { |
| 665 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | m_curMatrix = *pUser2Device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 667 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 668 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 669 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | CPDFXFA_Page* pPage = GetPDFXFAPage(); |
Jun Fang | 2592eaa | 2015-12-02 14:09:28 +0800 | [diff] [blame] | 671 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 672 | return; |
| 673 | |
Tom Sepez | d3116dc | 2015-11-24 15:58:06 -0800 | [diff] [blame] | 674 | if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | CFX_Graphics gs; |
| 676 | gs.Create(pDevice); |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame] | 677 | CFX_RectF rectClip; |
| 678 | rectClip.Set(static_cast<FX_FLOAT>(pClip.left), |
| 679 | static_cast<FX_FLOAT>(pClip.top), |
| 680 | static_cast<FX_FLOAT>(pClip.Width()), |
| 681 | static_cast<FX_FLOAT>(pClip.Height())); |
| 682 | gs.SetClipRect(rectClip); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); |
| 684 | if (!pRenderContext) |
| 685 | return; |
| 686 | CXFA_RenderOptions renderOptions; |
| 687 | renderOptions.m_bHighlight = TRUE; |
Jun Fang | 2592eaa | 2015-12-02 14:09:28 +0800 | [diff] [blame] | 688 | IXFA_PageView* xfaView = pPage->GetXFAPageView(); |
| 689 | pRenderContext->StartRender(xfaView, &gs, *pUser2Device, renderOptions); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | pRenderContext->DoRender(); |
| 691 | pRenderContext->StopRender(); |
| 692 | pRenderContext->Release(); |
Jun Fang | 2592eaa | 2015-12-02 14:09:28 +0800 | [diff] [blame] | 693 | IXFA_DocView* docView = xfaView->GetDocView(); |
| 694 | if (!docView) |
| 695 | return; |
| 696 | CPDFSDK_Annot* annot = GetFocusAnnot(); |
| 697 | if (!annot) |
| 698 | return; |
| 699 | // Render the focus widget |
| 700 | docView->GetWidgetHandler()->RenderWidget(annot->GetXFAWidget(), &gs, |
| 701 | pUser2Device, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | return; |
| 703 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 704 | #endif // PDF_ENABLE_XFA |
| 705 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | // for pdf/static xfa. |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 707 | CPDFSDK_AnnotIterator annotIterator(this, true); |
| 708 | while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 713 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 714 | const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
| 715 | FX_FLOAT pageY) { |
| 716 | for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | CFX_FloatRect annotRect; |
| 718 | pAnnot->GetRect(annotRect); |
| 719 | if (annotRect.Contains(pageX, pageY)) |
| 720 | return pAnnot; |
| 721 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 722 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 725 | const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, |
| 726 | FX_FLOAT pageY) { |
| 727 | for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 728 | if (pAnnot->GetSubType() == "Widget") { |
| 729 | CFX_FloatRect annotRect; |
| 730 | pAnnot->GetRect(annotRect); |
| 731 | if (annotRect.Contains(pageX, pageY)) |
| 732 | return pAnnot; |
| 733 | } |
| 734 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 735 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, |
| 739 | FX_FLOAT pageY) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 740 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 741 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 742 | CPDFSDK_AnnotIterator annotIterator(this, false); |
| 743 | while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 744 | CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 745 | if (rc.Contains(pageX, pageY)) |
| 746 | return pSDKAnnot; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 749 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, |
| 753 | FX_FLOAT pageY) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 754 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 755 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 756 | CPDFSDK_AnnotIterator annotIterator(this, false); |
| 757 | while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 758 | bool bHitTest = pSDKAnnot->GetType() == "Widget"; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 759 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 760 | bHitTest = bHitTest || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 761 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 762 | if (bHitTest) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 763 | pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 764 | CPDF_Point point(pageX, pageY); |
| 765 | if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
| 766 | return pSDKAnnot; |
| 767 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 770 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 773 | void CPDFSDK_PageView::KillFocusAnnotIfNeeded() { |
| 774 | // if there is a focused annot on the page, we should kill the focus first. |
| 775 | if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) { |
Lei Zhang | cd2bb30 | 2015-12-22 13:49:44 -0800 | [diff] [blame] | 776 | if (pdfium::ContainsValue(m_fxAnnotArray, focusedAnnot)) |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 777 | KillFocusAnnot(); |
| 778 | } |
| 779 | } |
| 780 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 781 | FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) { |
| 782 | CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict(); |
| 783 | if (pAnnotDic) |
| 784 | return pAnnotDic->KeyExist("AS"); |
| 785 | return FALSE; |
| 786 | } |
| 787 | |
| 788 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { |
| 789 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 790 | ASSERT(pEnv); |
| 791 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 792 | CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 793 | if (!pSDKAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 794 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 796 | m_fxAnnotArray.push_back(pSDKAnnot); |
| 797 | pAnnotHandler->Annot_OnCreate(pSDKAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | return pSDKAnnot; |
| 799 | } |
| 800 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 801 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { |
| 803 | if (!pPDFAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 804 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 805 | |
| 806 | CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 807 | if (pSDKAnnot) |
| 808 | return pSDKAnnot; |
| 809 | |
| 810 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 811 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 812 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 813 | if (!pSDKAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 814 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 815 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 816 | m_fxAnnotArray.push_back(pSDKAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | return pSDKAnnot; |
| 818 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 819 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 820 | |
| 821 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame^] | 822 | return pDict ? AddAnnot(pDict->GetStringBy("Subtype"), pDict) : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, |
| 826 | CPDF_Dictionary* pDict) { |
| 827 | return NULL; |
| 828 | } |
| 829 | |
| 830 | FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 831 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 832 | if (!pAnnot) |
| 833 | return FALSE; |
| 834 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 835 | if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
Tom Sepez | d3116dc | 2015-11-24 15:58:06 -0800 | [diff] [blame] | 836 | pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 837 | return FALSE; |
| 838 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 839 | auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); |
| 840 | if (it != m_fxAnnotArray.end()) |
| 841 | m_fxAnnotArray.erase(it); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | if (m_CaptureWidget == pAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 843 | m_CaptureWidget = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | |
| 845 | return TRUE; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 846 | #else // PDF_ENABLE_XFA |
| 847 | return FALSE; |
| 848 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
| 852 | if (m_page) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 853 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 854 | return m_page->GetDocument()->GetPDFDoc(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 855 | #else // PDF_ENABLE_XFA |
| 856 | return m_page->m_pDocument; |
| 857 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | } |
| 859 | return NULL; |
| 860 | } |
| 861 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 862 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 863 | CPDF_Page* CPDFSDK_PageView::GetPDFPage() { |
| 864 | if (m_page) { |
| 865 | return m_page->GetPDFPage(); |
| 866 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | return NULL; |
| 868 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 869 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 870 | |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 871 | size_t CPDFSDK_PageView::CountAnnots() const { |
| 872 | return m_fxAnnotArray.size(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 875 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { |
| 876 | return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 880 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 881 | if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 882 | return pAnnot; |
| 883 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 884 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 885 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 886 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 887 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 888 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 889 | if (!hWidget) |
| 890 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 891 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 892 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | if (pAnnot->GetXFAWidget() == hWidget) |
| 894 | return pAnnot; |
| 895 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 896 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 898 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | |
| 900 | FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, |
| 901 | FX_UINT nFlag) { |
| 902 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 903 | ASSERT(pEnv); |
| 904 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 905 | if (!pFXAnnot) { |
| 906 | KillFocusAnnot(nFlag); |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 907 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | } |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 909 | |
| 910 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 911 | FX_BOOL bRet = |
| 912 | pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); |
| 913 | if (bRet) |
| 914 | SetFocusAnnot(pFXAnnot); |
| 915 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 918 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 919 | FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, |
| 920 | FX_UINT nFlag) { |
| 921 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 922 | ASSERT(pEnv); |
| 923 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 924 | ASSERT(pAnnotHandlerMgr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 925 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 926 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 927 | |
| 928 | if (pFXAnnot == NULL) |
| 929 | return FALSE; |
| 930 | |
| 931 | FX_BOOL bRet = |
| 932 | pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); |
| 933 | if (bRet) { |
| 934 | SetFocusAnnot(pFXAnnot); |
| 935 | } |
| 936 | return TRUE; |
| 937 | } |
| 938 | |
| 939 | FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 940 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 941 | ASSERT(pEnv); |
| 942 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 943 | |
| 944 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 945 | |
| 946 | if (pFXAnnot == NULL) |
| 947 | return FALSE; |
| 948 | |
| 949 | FX_BOOL bRet = |
| 950 | pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); |
| 951 | if (bRet) { |
| 952 | SetFocusAnnot(pFXAnnot); |
| 953 | } |
| 954 | return TRUE; |
| 955 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 956 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | |
| 958 | FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 959 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 960 | ASSERT(pEnv); |
| 961 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 962 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 963 | CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); |
| 964 | FX_BOOL bRet = FALSE; |
| 965 | if (pFocusAnnot && pFocusAnnot != pFXAnnot) { |
| 966 | // Last focus Annot gets a chance to handle the event. |
| 967 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); |
| 968 | } |
Lei Zhang | a060146 | 2015-10-30 14:54:37 -0700 | [diff] [blame] | 969 | if (pFXAnnot && !bRet) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 970 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | return bRet; |
| 972 | } |
| 973 | |
| 974 | FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point& point, int nFlag) { |
| 975 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 976 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | if (CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
| 978 | if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { |
| 979 | m_bExitWidget = TRUE; |
| 980 | m_bEnterWidget = FALSE; |
| 981 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 982 | } |
| 983 | m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot; |
| 984 | m_bOnWidget = TRUE; |
| 985 | if (!m_bEnterWidget) { |
| 986 | m_bEnterWidget = TRUE; |
| 987 | m_bExitWidget = FALSE; |
| 988 | pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); |
| 989 | } |
| 990 | pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); |
| 991 | return TRUE; |
| 992 | } |
| 993 | if (m_bOnWidget) { |
| 994 | m_bOnWidget = FALSE; |
| 995 | m_bExitWidget = TRUE; |
| 996 | m_bEnterWidget = FALSE; |
| 997 | if (m_CaptureWidget) { |
| 998 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 999 | m_CaptureWidget = NULL; |
| 1000 | } |
| 1001 | } |
| 1002 | return FALSE; |
| 1003 | } |
| 1004 | |
| 1005 | FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, |
| 1006 | double deltaY, |
| 1007 | const CPDF_Point& point, |
| 1008 | int nFlag) { |
| 1009 | if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1010 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1011 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, |
| 1013 | (int)deltaY, point); |
| 1014 | } |
| 1015 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) { |
| 1019 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1020 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1021 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1022 | return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
| 1023 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1024 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1025 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1028 | FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { |
| 1029 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1030 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1031 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1032 | return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 1033 | } |
| 1034 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1037 | FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1038 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1041 | void CPDFSDK_PageView::LoadFXAnnots() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1042 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1043 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1044 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1045 | #else |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1046 | FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 1047 | // Disable the default AP construction. |
| 1048 | CPDF_InterForm::EnableUpdateAP(FALSE); |
| 1049 | m_pAnnotList.reset(new CPDF_AnnotList(m_page)); |
| 1050 | CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
| 1051 | const size_t nCount = m_pAnnotList->Count(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1052 | #endif // PDF_ENABLE_XFA |
| 1053 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1054 | SetLock(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1055 | |
| 1056 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1057 | m_page->AddRef(); |
Tom Sepez | d3116dc | 2015-11-24 15:58:06 -0800 | [diff] [blame] | 1058 | if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | IXFA_PageView* pageView = NULL; |
| 1060 | pageView = m_page->GetXFAPageView(); |
| 1061 | ASSERT(pageView != NULL); |
| 1062 | |
| 1063 | IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator( |
| 1064 | XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible | |
| 1065 | XFA_WIDGETFILTER_Viewable | |
| 1066 | XFA_WIDGETFILTER_AllType); |
| 1067 | if (!pWidgetHander) { |
| 1068 | m_page->Release(); |
| 1069 | SetLock(FALSE); |
| 1070 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1071 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1073 | while (IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1074 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1075 | if (!pAnnot) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1076 | continue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1077 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1078 | m_fxAnnotArray.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1079 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1080 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1081 | pWidgetHander->Release(); |
| 1082 | } else { |
| 1083 | CPDF_Page* pPage = m_page->GetPDFPage(); |
| 1084 | ASSERT(pPage != NULL); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1085 | FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 1086 | // Disable the default AP construction. |
| 1087 | CPDF_InterForm::EnableUpdateAP(FALSE); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1088 | m_pAnnotList.reset(new CPDF_AnnotList(pPage)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1089 | CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
| 1090 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1091 | const size_t nCount = m_pAnnotList->Count(); |
| 1092 | for (size_t i = 0; i < nCount; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1093 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 1094 | CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1095 | |
| 1096 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 1097 | if (!pAnnot) |
| 1098 | continue; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1099 | m_fxAnnotArray.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1100 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1101 | } |
| 1102 | } |
| 1103 | m_page->Release(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1104 | #else // PDF_ENABLE_XFA |
| 1105 | for (size_t i = 0; i < nCount; ++i) { |
| 1106 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 1107 | CPDF_Document* pDoc = GetPDFDocument(); |
| 1108 | CheckUnSupportAnnot(pDoc, pPDFAnnot); |
| 1109 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1110 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 1111 | if (!pAnnot) |
| 1112 | continue; |
| 1113 | m_fxAnnotArray.push_back(pAnnot); |
| 1114 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1115 | } |
| 1116 | #endif // PDF_ENABLE_XFA |
| 1117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1118 | SetLock(FALSE); |
| 1119 | } |
| 1120 | |
Jun Fang | 7523954 | 2016-01-20 08:04:47 +0800 | [diff] [blame] | 1121 | void CPDFSDK_PageView::ClearFXAnnots() { |
| 1122 | SetLock(TRUE); |
| 1123 | if (m_pSDKDoc && GetFocusAnnot()) |
| 1124 | m_pSDKDoc->SetFocusAnnot(nullptr); |
| 1125 | m_CaptureWidget = nullptr; |
| 1126 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
| 1127 | m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); |
| 1128 | m_fxAnnotArray.clear(); |
| 1129 | m_pAnnotList.reset(); |
| 1130 | SetLock(FALSE); |
| 1131 | } |
| 1132 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1133 | void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { |
| 1134 | for (int i = 0; i < rects.GetSize(); i++) { |
| 1135 | CPDF_Rect rc = rects.GetAt(i); |
| 1136 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1137 | pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
| 1142 | CPDF_Rect rcWindow = pAnnot->GetRect(); |
| 1143 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1144 | pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, |
| 1145 | rcWindow.bottom); |
| 1146 | } |
| 1147 | |
| 1148 | int CPDFSDK_PageView::GetPageIndex() { |
| 1149 | if (m_page) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1150 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1151 | CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1152 | #else // PDF_ENABLE_XFA |
| 1153 | CPDF_Dictionary* pDic = m_page->m_pFormDict; |
| 1154 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1155 | CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1156 | if (pDoc && pDic) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1157 | return pDoc->GetPageIndex(pDic->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | return -1; |
| 1161 | } |
| 1162 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1163 | bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1164 | if (!p) |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1165 | return false; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1166 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 1167 | const auto& annots = m_pAnnotList->All(); |
Lei Zhang | cd2bb30 | 2015-12-22 13:49:44 -0800 | [diff] [blame] | 1168 | return pdfium::ContainsValue(annots, p); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1171 | CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
| 1172 | CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
| 1173 | if (!pFocusAnnot) |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1174 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1175 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1176 | for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1177 | if (pAnnot == pFocusAnnot) |
| 1178 | return pAnnot; |
| 1179 | } |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1180 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1181 | } |