| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/include/fsdk_mgr.h" | 7 #include "fpdfsdk/include/cpdfsdk_pageview.h" |
| 8 | 8 |
| 9 #include <algorithm> | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | |
| 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 15 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" | 10 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
| 16 #include "core/fpdfdoc/include/cpdf_docjsactions.h" | 11 #include "core/fpdfdoc/include/cpdf_annotlist.h" |
| 17 #include "core/fpdfdoc/include/cpdf_interform.h" | 12 #include "core/fpdfdoc/include/cpdf_interform.h" |
| 18 #include "core/fxcrt/include/cfx_retain_ptr.h" | 13 #include "fpdfsdk/include/cpdfdoc_environment.h" |
| 19 #include "core/fxge/include/cfx_renderdevice.h" | 14 #include "fpdfsdk/include/cpdfsdk_annot.h" |
| 20 #include "fpdfsdk/formfiller/cffl_formfiller.h" | |
| 21 #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" | 15 #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" |
| 22 #include "fpdfsdk/include/cpdfsdk_annotiterator.h" | 16 #include "fpdfsdk/include/cpdfsdk_annotiterator.h" |
| 23 #include "fpdfsdk/include/cpdfsdk_interform.h" | 17 #include "fpdfsdk/include/cpdfsdk_interform.h" |
| 24 #include "fpdfsdk/include/cpdfsdk_widget.h" | |
| 25 #include "fpdfsdk/include/fsdk_define.h" | |
| 26 #include "fpdfsdk/include/ipdfsdk_annothandler.h" | |
| 27 #include "fpdfsdk/javascript/ijs_runtime.h" | |
| 28 #include "public/fpdf_ext.h" | |
| 29 #include "third_party/base/stl_util.h" | |
| 30 | 18 |
| 31 #ifdef PDF_ENABLE_XFA | 19 #ifdef PDF_ENABLE_XFA |
| 32 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" | |
| 33 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | |
| 34 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" | 20 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" |
| 35 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" | |
| 36 #include "xfa/fxfa/include/xfa_ffdocview.h" | 21 #include "xfa/fxfa/include/xfa_ffdocview.h" |
| 37 #include "xfa/fxfa/include/xfa_ffpageview.h" | 22 #include "xfa/fxfa/include/xfa_ffpageview.h" |
| 38 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" | 23 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" |
| 39 #include "xfa/fxfa/include/xfa_rendercontext.h" | 24 #include "xfa/fxfa/include/xfa_rendercontext.h" |
| 40 #include "xfa/fxgraphics/include/cfx_graphics.h" | 25 #include "xfa/fxgraphics/include/cfx_graphics.h" |
| 41 #endif // PDF_ENABLE_XFA | 26 #endif // PDF_ENABLE_XFA |
| 42 | 27 |
| 43 #if _FX_OS_ == _FX_ANDROID_ | |
| 44 #include "time.h" | |
| 45 #else | |
| 46 #include <ctime> | |
| 47 #endif | |
| 48 | |
| 49 namespace { | |
| 50 | |
| 51 // NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken | |
| 52 // since modifying the result would impact |bsUTF16LE|. | |
| 53 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { | |
| 54 return reinterpret_cast<FPDF_WIDESTRING>( | |
| 55 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); | |
| 56 } | |
| 57 | |
| 58 } // namespace | |
| 59 | |
| 60 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, | |
| 61 FPDF_FORMFILLINFO* pFFinfo) | |
| 62 : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { | |
| 63 m_pSysHandler.reset(new CFX_SystemHandler(this)); | |
| 64 } | |
| 65 | |
| 66 CPDFDoc_Environment::~CPDFDoc_Environment() { | |
| 67 #ifdef PDF_ENABLE_XFA | |
| 68 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | |
| 69 if (pProvider->m_pEnvList.GetSize() == 0) | |
| 70 pProvider->SetJavaScriptInitialized(FALSE); | |
| 71 #endif // PDF_ENABLE_XFA | |
| 72 if (m_pInfo && m_pInfo->Release) | |
| 73 m_pInfo->Release(m_pInfo); | |
| 74 } | |
| 75 | |
| 76 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, | |
| 77 const FX_WCHAR* Title, | |
| 78 FX_UINT Type, | |
| 79 FX_UINT Icon) { | |
| 80 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 81 !m_pInfo->m_pJsPlatform->app_alert) { | |
| 82 return -1; | |
| 83 } | |
| 84 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); | |
| 85 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); | |
| 86 return m_pInfo->m_pJsPlatform->app_alert( | |
| 87 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg), | |
| 88 AsFPDFWideString(&bsTitle), Type, Icon); | |
| 89 } | |
| 90 | |
| 91 int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, | |
| 92 const FX_WCHAR* Title, | |
| 93 const FX_WCHAR* Default, | |
| 94 const FX_WCHAR* cLabel, | |
| 95 FPDF_BOOL bPassword, | |
| 96 void* response, | |
| 97 int length) { | |
| 98 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 99 !m_pInfo->m_pJsPlatform->app_response) { | |
| 100 return -1; | |
| 101 } | |
| 102 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); | |
| 103 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); | |
| 104 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); | |
| 105 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); | |
| 106 return m_pInfo->m_pJsPlatform->app_response( | |
| 107 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion), | |
| 108 AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault), | |
| 109 AsFPDFWideString(&bsLabel), bPassword, response, length); | |
| 110 } | |
| 111 | |
| 112 void CPDFDoc_Environment::JS_appBeep(int nType) { | |
| 113 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 114 !m_pInfo->m_pJsPlatform->app_beep) { | |
| 115 return; | |
| 116 } | |
| 117 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); | |
| 118 } | |
| 119 | |
| 120 CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { | |
| 121 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 122 !m_pInfo->m_pJsPlatform->Field_browse) { | |
| 123 return CFX_WideString(); | |
| 124 } | |
| 125 const int nRequiredLen = | |
| 126 m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); | |
| 127 if (nRequiredLen <= 0) | |
| 128 return CFX_WideString(); | |
| 129 | |
| 130 std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); | |
| 131 memset(pBuff.get(), 0, nRequiredLen); | |
| 132 const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( | |
| 133 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); | |
| 134 if (nActualLen <= 0 || nActualLen > nRequiredLen) | |
| 135 return CFX_WideString(); | |
| 136 | |
| 137 return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); | |
| 138 } | |
| 139 | |
| 140 CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { | |
| 141 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 142 !m_pInfo->m_pJsPlatform->Doc_getFilePath) { | |
| 143 return CFX_WideString(); | |
| 144 } | |
| 145 const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( | |
| 146 m_pInfo->m_pJsPlatform, nullptr, 0); | |
| 147 if (nRequiredLen <= 0) | |
| 148 return CFX_WideString(); | |
| 149 | |
| 150 std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); | |
| 151 memset(pBuff.get(), 0, nRequiredLen); | |
| 152 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( | |
| 153 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); | |
| 154 if (nActualLen <= 0 || nActualLen > nRequiredLen) | |
| 155 return CFX_WideString(); | |
| 156 | |
| 157 return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); | |
| 158 } | |
| 159 | |
| 160 void CPDFDoc_Environment::JS_docSubmitForm(void* formData, | |
| 161 int length, | |
| 162 const FX_WCHAR* URL) { | |
| 163 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 164 !m_pInfo->m_pJsPlatform->Doc_submitForm) { | |
| 165 return; | |
| 166 } | |
| 167 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); | |
| 168 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, | |
| 169 length, | |
| 170 AsFPDFWideString(&bsDestination)); | |
| 171 } | |
| 172 | |
| 173 void CPDFDoc_Environment::JS_docmailForm(void* mailData, | |
| 174 int length, | |
| 175 FPDF_BOOL bUI, | |
| 176 const FX_WCHAR* To, | |
| 177 const FX_WCHAR* Subject, | |
| 178 const FX_WCHAR* CC, | |
| 179 const FX_WCHAR* BCC, | |
| 180 const FX_WCHAR* Msg) { | |
| 181 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 182 !m_pInfo->m_pJsPlatform->Doc_mail) { | |
| 183 return; | |
| 184 } | |
| 185 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); | |
| 186 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); | |
| 187 CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode(); | |
| 188 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); | |
| 189 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); | |
| 190 m_pInfo->m_pJsPlatform->Doc_mail( | |
| 191 m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo), | |
| 192 AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC), | |
| 193 AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg)); | |
| 194 } | |
| 195 | |
| 196 void CPDFDoc_Environment::JS_docprint(FPDF_BOOL bUI, | |
| 197 int nStart, | |
| 198 int nEnd, | |
| 199 FPDF_BOOL bSilent, | |
| 200 FPDF_BOOL bShrinkToFit, | |
| 201 FPDF_BOOL bPrintAsImage, | |
| 202 FPDF_BOOL bReverse, | |
| 203 FPDF_BOOL bAnnotations) { | |
| 204 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 205 !m_pInfo->m_pJsPlatform->Doc_print) { | |
| 206 return; | |
| 207 } | |
| 208 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, | |
| 209 bSilent, bShrinkToFit, bPrintAsImage, | |
| 210 bReverse, bAnnotations); | |
| 211 } | |
| 212 | |
| 213 void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) { | |
| 214 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | |
| 215 !m_pInfo->m_pJsPlatform->Doc_gotoPage) { | |
| 216 return; | |
| 217 } | |
| 218 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); | |
| 219 } | |
| 220 | |
| 221 IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { | |
| 222 if (!IsJSInitiated()) | |
| 223 return nullptr; | |
| 224 if (!m_pJSRuntime) | |
| 225 m_pJSRuntime.reset(IJS_Runtime::Create(this)); | |
| 226 return m_pJSRuntime.get(); | |
| 227 } | |
| 228 | |
| 229 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { | |
| 230 if (!m_pAnnotHandlerMgr) | |
| 231 m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); | |
| 232 return m_pAnnotHandlerMgr.get(); | |
| 233 } | |
| 234 | |
| 235 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { | |
| 236 if (!m_pActionHandler) | |
| 237 m_pActionHandler.reset(new CPDFSDK_ActionHandler()); | |
| 238 return m_pActionHandler.get(); | |
| 239 } | |
| 240 | |
| 241 CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { | |
| 242 if (!m_pIFormFiller) | |
| 243 m_pIFormFiller.reset(new CFFL_IFormFiller(this)); | |
| 244 return m_pIFormFiller.get(); | |
| 245 } | |
| 246 | |
| 247 // static | |
| 248 CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( | |
| 249 FPDF_FORMHANDLE hHandle) { | |
| 250 CPDFDoc_Environment* pEnv = static_cast<CPDFDoc_Environment*>(hHandle); | |
| 251 return pEnv ? pEnv->GetSDKDocument() : nullptr; | |
| 252 } | |
| 253 | |
| 254 CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, | |
| 255 CPDFDoc_Environment* pEnv) | |
| 256 : m_pDoc(pDoc), | |
| 257 m_pFocusAnnot(nullptr), | |
| 258 m_pEnv(pEnv), | |
| 259 m_bChangeMask(FALSE), | |
| 260 m_bBeingDestroyed(FALSE) {} | |
| 261 | |
| 262 CPDFSDK_Document::~CPDFSDK_Document() { | |
| 263 m_bBeingDestroyed = TRUE; | |
| 264 | |
| 265 for (auto& it : m_pageMap) | |
| 266 it.second->KillFocusAnnotIfNeeded(); | |
| 267 | |
| 268 for (auto& it : m_pageMap) | |
| 269 delete it.second; | |
| 270 m_pageMap.clear(); | |
| 271 } | |
| 272 | |
| 273 CPDFSDK_PageView* CPDFSDK_Document::GetPageView( | |
| 274 UnderlyingPageType* pUnderlyingPage, | |
| 275 bool ReNew) { | |
| 276 auto it = m_pageMap.find(pUnderlyingPage); | |
| 277 if (it != m_pageMap.end()) | |
| 278 return it->second; | |
| 279 | |
| 280 if (!ReNew) | |
| 281 return nullptr; | |
| 282 | |
| 283 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); | |
| 284 m_pageMap[pUnderlyingPage] = pPageView; | |
| 285 // Delay to load all the annotations, to avoid endless loop. | |
| 286 pPageView->LoadFXAnnots(); | |
| 287 return pPageView; | |
| 288 } | |
| 289 | |
| 290 CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { | |
| 291 UnderlyingPageType* pPage = | |
| 292 UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); | |
| 293 return pPage ? GetPageView(pPage, true) : nullptr; | |
| 294 } | |
| 295 | |
| 296 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { | |
| 297 UnderlyingPageType* pTempPage = | |
| 298 UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); | |
| 299 if (!pTempPage) | |
| 300 return nullptr; | |
| 301 | |
| 302 auto it = m_pageMap.find(pTempPage); | |
| 303 return it != m_pageMap.end() ? it->second : nullptr; | |
| 304 } | |
| 305 | |
| 306 void CPDFSDK_Document::ProcJavascriptFun() { | |
| 307 CPDF_Document* pPDFDoc = GetPDFDocument(); | |
| 308 CPDF_DocJSActions docJS(pPDFDoc); | |
| 309 int iCount = docJS.CountJSActions(); | |
| 310 if (iCount < 1) | |
| 311 return; | |
| 312 for (int i = 0; i < iCount; i++) { | |
| 313 CFX_ByteString csJSName; | |
| 314 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); | |
| 315 if (m_pEnv->GetActionHander()) | |
| 316 m_pEnv->GetActionHander()->DoAction_JavaScript( | |
| 317 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); | |
| 318 } | |
| 319 } | |
| 320 | |
| 321 FX_BOOL CPDFSDK_Document::ProcOpenAction() { | |
| 322 if (!m_pDoc) | |
| 323 return FALSE; | |
| 324 | |
| 325 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); | |
| 326 if (!pRoot) | |
| 327 return FALSE; | |
| 328 | |
| 329 CPDF_Object* pOpenAction = pRoot->GetDictBy("OpenAction"); | |
| 330 if (!pOpenAction) | |
| 331 pOpenAction = pRoot->GetArrayBy("OpenAction"); | |
| 332 | |
| 333 if (!pOpenAction) | |
| 334 return FALSE; | |
| 335 | |
| 336 if (pOpenAction->IsArray()) | |
| 337 return TRUE; | |
| 338 | |
| 339 if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { | |
| 340 CPDF_Action action(pDict); | |
| 341 if (m_pEnv->GetActionHander()) | |
| 342 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); | |
| 343 return TRUE; | |
| 344 } | |
| 345 return FALSE; | |
| 346 } | |
| 347 | |
| 348 CPDF_OCContext* CPDFSDK_Document::GetOCContext() { | |
| 349 if (!m_pOccontent) { | |
| 350 m_pOccontent.reset( | |
| 351 new CPDF_OCContext(GetPDFDocument(), CPDF_OCContext::View)); | |
| 352 } | |
| 353 return m_pOccontent.get(); | |
| 354 } | |
| 355 | |
| 356 void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { | |
| 357 auto it = m_pageMap.find(pUnderlyingPage); | |
| 358 if (it == m_pageMap.end()) | |
| 359 return; | |
| 360 | |
| 361 CPDFSDK_PageView* pPageView = it->second; | |
| 362 if (pPageView->IsLocked()) | |
| 363 return; | |
| 364 | |
| 365 // This must happen before we remove |pPageView| from the map because | |
| 366 // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will | |
| 367 // look for this page view in the map, if it doesn't find it a new one will | |
| 368 // be created. We then have two page views pointing to the same page and | |
| 369 // bad things happen. | |
| 370 pPageView->KillFocusAnnotIfNeeded(); | |
| 371 | |
| 372 // Remove the page from the map to make sure we don't accidentally attempt | |
| 373 // to use the |pPageView| while we're cleaning it up. | |
| 374 m_pageMap.erase(it); | |
| 375 | |
| 376 delete pPageView; | |
| 377 } | |
| 378 | |
| 379 UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { | |
| 380 return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); | |
| 381 } | |
| 382 | |
| 383 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { | |
| 384 if (!m_pInterForm) | |
| 385 m_pInterForm.reset(new CPDFSDK_InterForm(this)); | |
| 386 return m_pInterForm.get(); | |
| 387 } | |
| 388 | |
| 389 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, | |
| 390 CPDFSDK_Annot* pAnnot) { | |
| 391 for (const auto& it : m_pageMap) { | |
| 392 CPDFSDK_PageView* pPageView = it.second; | |
| 393 if (pPageView != pSender) { | |
| 394 pPageView->UpdateView(pAnnot); | |
| 395 } | |
| 396 } | |
| 397 } | |
| 398 | |
| 399 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { | |
| 400 return m_pFocusAnnot; | |
| 401 } | |
| 402 | |
| 403 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { | |
| 404 if (m_bBeingDestroyed) | |
| 405 return FALSE; | |
| 406 | |
| 407 if (m_pFocusAnnot == pAnnot) | |
| 408 return TRUE; | |
| 409 | |
| 410 if (m_pFocusAnnot) { | |
| 411 if (!KillFocusAnnot(nFlag)) | |
| 412 return FALSE; | |
| 413 } | |
| 414 | |
| 415 if (!pAnnot) | |
| 416 return FALSE; | |
| 417 | |
| 418 #ifdef PDF_ENABLE_XFA | |
| 419 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; | |
| 420 #endif // PDF_ENABLE_XFA | |
| 421 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | |
| 422 if (pPageView && pPageView->IsValid()) { | |
| 423 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); | |
| 424 if (!m_pFocusAnnot) { | |
| 425 #ifdef PDF_ENABLE_XFA | |
| 426 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) | |
| 427 return FALSE; | |
| 428 #endif // PDF_ENABLE_XFA | |
| 429 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) | |
| 430 return FALSE; | |
| 431 if (!m_pFocusAnnot) { | |
| 432 m_pFocusAnnot = pAnnot; | |
| 433 return TRUE; | |
| 434 } | |
| 435 } | |
| 436 } | |
| 437 return FALSE; | |
| 438 } | |
| 439 | |
| 440 FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { | |
| 441 if (m_pFocusAnnot) { | |
| 442 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); | |
| 443 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; | |
| 444 m_pFocusAnnot = nullptr; | |
| 445 | |
| 446 #ifdef PDF_ENABLE_XFA | |
| 447 if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) | |
| 448 return FALSE; | |
| 449 #endif // PDF_ENABLE_XFA | |
| 450 | |
| 451 if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { | |
| 452 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { | |
| 453 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; | |
| 454 int nFieldType = pWidget->GetFieldType(); | |
| 455 if (FIELDTYPE_TEXTFIELD == nFieldType || | |
| 456 FIELDTYPE_COMBOBOX == nFieldType) { | |
| 457 m_pEnv->FFI_OnSetFieldInputFocus(nullptr, nullptr, 0, FALSE); | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 if (!m_pFocusAnnot) | |
| 462 return TRUE; | |
| 463 } else { | |
| 464 m_pFocusAnnot = pFocusAnnot; | |
| 465 } | |
| 466 } | |
| 467 return FALSE; | |
| 468 } | |
| 469 | |
| 470 void CPDFSDK_Document::OnCloseDocument() { | |
| 471 KillFocusAnnot(); | |
| 472 } | |
| 473 | |
| 474 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { | |
| 475 return GetPDFDocument()->GetUserPermissions() & nFlag; | |
| 476 } | |
| 477 | |
| 478 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { | |
| 479 return m_pEnv->GetJSRuntime(); | |
| 480 } | |
| 481 | |
| 482 CFX_WideString CPDFSDK_Document::GetPath() { | |
| 483 return m_pEnv->JS_docGetFilePath(); | |
| 484 } | |
| 485 | |
| 486 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, | 28 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
| 487 UnderlyingPageType* page) | 29 UnderlyingPageType* page) |
| 488 : m_page(page), | 30 : m_page(page), |
| 489 m_pSDKDoc(pSDKDoc), | 31 m_pSDKDoc(pSDKDoc), |
| 490 m_CaptureWidget(nullptr), | 32 m_CaptureWidget(nullptr), |
| 491 #ifndef PDF_ENABLE_XFA | 33 #ifndef PDF_ENABLE_XFA |
| 492 m_bOwnsPage(false), | 34 m_bOwnsPage(false), |
| 493 #endif // PDF_ENABLE_XFA | 35 #endif // PDF_ENABLE_XFA |
| 494 m_bEnterWidget(FALSE), | 36 m_bEnterWidget(FALSE), |
| 495 m_bExitWidget(FALSE), | 37 m_bExitWidget(FALSE), |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 return pAnnot; | 578 return pAnnot; |
| 1037 } | 579 } |
| 1038 return nullptr; | 580 return nullptr; |
| 1039 } | 581 } |
| 1040 | 582 |
| 1041 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { | 583 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
| 1042 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; | 584 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; |
| 1043 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | 585 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
| 1044 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; | 586 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
| 1045 } | 587 } |
| OLD | NEW |