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