Index: fpdfsdk/cpdfsdk_pageview.cpp |
diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/cpdfsdk_pageview.cpp |
similarity index 55% |
rename from fpdfsdk/fsdk_mgr.cpp |
rename to fpdfsdk/cpdfsdk_pageview.cpp |
index c8f387e90321967f0d269bfd404ddd6c238a3c3f..ae0d3fa7df8a1011b9ca59f70e94c65834ef6ac9 100644 |
--- a/fpdfsdk/fsdk_mgr.cpp |
+++ b/fpdfsdk/cpdfsdk_pageview.cpp |
@@ -1,38 +1,23 @@ |
-// Copyright 2014 PDFium Authors. All rights reserved. |
+// Copyright 2016 PDFium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
-#include "fpdfsdk/include/fsdk_mgr.h" |
+#include "fpdfsdk/include/cpdfsdk_pageview.h" |
-#include <algorithm> |
-#include <memory> |
- |
-#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
-#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
-#include "core/fpdfdoc/include/cpdf_docjsactions.h" |
+#include "core/fpdfdoc/include/cpdf_annotlist.h" |
#include "core/fpdfdoc/include/cpdf_interform.h" |
-#include "core/fxcrt/include/cfx_retain_ptr.h" |
-#include "core/fxge/include/cfx_renderdevice.h" |
-#include "fpdfsdk/formfiller/cffl_formfiller.h" |
+#include "fpdfsdk/include/cpdfdoc_environment.h" |
+#include "fpdfsdk/include/cpdfsdk_annot.h" |
#include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" |
#include "fpdfsdk/include/cpdfsdk_annotiterator.h" |
#include "fpdfsdk/include/cpdfsdk_interform.h" |
-#include "fpdfsdk/include/cpdfsdk_widget.h" |
-#include "fpdfsdk/include/fsdk_define.h" |
-#include "fpdfsdk/include/ipdfsdk_annothandler.h" |
-#include "fpdfsdk/javascript/ijs_runtime.h" |
-#include "public/fpdf_ext.h" |
-#include "third_party/base/stl_util.h" |
#ifdef PDF_ENABLE_XFA |
-#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" |
-#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" |
-#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" |
#include "xfa/fxfa/include/xfa_ffdocview.h" |
#include "xfa/fxfa/include/xfa_ffpageview.h" |
#include "xfa/fxfa/include/xfa_ffwidgethandler.h" |
@@ -40,449 +25,6 @@ |
#include "xfa/fxgraphics/include/cfx_graphics.h" |
#endif // PDF_ENABLE_XFA |
-#if _FX_OS_ == _FX_ANDROID_ |
-#include "time.h" |
-#else |
-#include <ctime> |
-#endif |
- |
-namespace { |
- |
-// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken |
-// since modifying the result would impact |bsUTF16LE|. |
-FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { |
- return reinterpret_cast<FPDF_WIDESTRING>( |
- bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); |
-} |
- |
-} // namespace |
- |
-CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, |
- FPDF_FORMFILLINFO* pFFinfo) |
- : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { |
- m_pSysHandler.reset(new CFX_SystemHandler(this)); |
-} |
- |
-CPDFDoc_Environment::~CPDFDoc_Environment() { |
-#ifdef PDF_ENABLE_XFA |
- CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
- if (pProvider->m_pEnvList.GetSize() == 0) |
- pProvider->SetJavaScriptInitialized(FALSE); |
-#endif // PDF_ENABLE_XFA |
- if (m_pInfo && m_pInfo->Release) |
- m_pInfo->Release(m_pInfo); |
-} |
- |
-int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, |
- const FX_WCHAR* Title, |
- FX_UINT Type, |
- FX_UINT Icon) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->app_alert) { |
- return -1; |
- } |
- CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
- CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
- return m_pInfo->m_pJsPlatform->app_alert( |
- m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg), |
- AsFPDFWideString(&bsTitle), Type, Icon); |
-} |
- |
-int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, |
- const FX_WCHAR* Title, |
- const FX_WCHAR* Default, |
- const FX_WCHAR* cLabel, |
- FPDF_BOOL bPassword, |
- void* response, |
- int length) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->app_response) { |
- return -1; |
- } |
- CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); |
- CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
- CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); |
- CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); |
- return m_pInfo->m_pJsPlatform->app_response( |
- m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion), |
- AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault), |
- AsFPDFWideString(&bsLabel), bPassword, response, length); |
-} |
- |
-void CPDFDoc_Environment::JS_appBeep(int nType) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->app_beep) { |
- return; |
- } |
- m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); |
-} |
- |
-CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->Field_browse) { |
- return CFX_WideString(); |
- } |
- const int nRequiredLen = |
- m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); |
- if (nRequiredLen <= 0) |
- return CFX_WideString(); |
- |
- std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
- memset(pBuff.get(), 0, nRequiredLen); |
- const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( |
- m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
- if (nActualLen <= 0 || nActualLen > nRequiredLen) |
- return CFX_WideString(); |
- |
- return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); |
-} |
- |
-CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->Doc_getFilePath) { |
- return CFX_WideString(); |
- } |
- const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
- m_pInfo->m_pJsPlatform, nullptr, 0); |
- if (nRequiredLen <= 0) |
- return CFX_WideString(); |
- |
- std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
- memset(pBuff.get(), 0, nRequiredLen); |
- const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
- m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
- if (nActualLen <= 0 || nActualLen > nRequiredLen) |
- return CFX_WideString(); |
- |
- return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); |
-} |
- |
-void CPDFDoc_Environment::JS_docSubmitForm(void* formData, |
- int length, |
- const FX_WCHAR* URL) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->Doc_submitForm) { |
- return; |
- } |
- CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); |
- m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, |
- length, |
- AsFPDFWideString(&bsDestination)); |
-} |
- |
-void CPDFDoc_Environment::JS_docmailForm(void* mailData, |
- int length, |
- FPDF_BOOL bUI, |
- const FX_WCHAR* To, |
- const FX_WCHAR* Subject, |
- const FX_WCHAR* CC, |
- const FX_WCHAR* BCC, |
- const FX_WCHAR* Msg) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->Doc_mail) { |
- return; |
- } |
- CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); |
- CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); |
- CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode(); |
- CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); |
- CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
- m_pInfo->m_pJsPlatform->Doc_mail( |
- m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo), |
- AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC), |
- AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg)); |
-} |
- |
-void CPDFDoc_Environment::JS_docprint(FPDF_BOOL bUI, |
- int nStart, |
- int nEnd, |
- FPDF_BOOL bSilent, |
- FPDF_BOOL bShrinkToFit, |
- FPDF_BOOL bPrintAsImage, |
- FPDF_BOOL bReverse, |
- FPDF_BOOL bAnnotations) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->Doc_print) { |
- return; |
- } |
- m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, |
- bSilent, bShrinkToFit, bPrintAsImage, |
- bReverse, bAnnotations); |
-} |
- |
-void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) { |
- if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
- !m_pInfo->m_pJsPlatform->Doc_gotoPage) { |
- return; |
- } |
- m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); |
-} |
- |
-IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { |
- if (!IsJSInitiated()) |
- return nullptr; |
- if (!m_pJSRuntime) |
- m_pJSRuntime.reset(IJS_Runtime::Create(this)); |
- return m_pJSRuntime.get(); |
-} |
- |
-CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { |
- if (!m_pAnnotHandlerMgr) |
- m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); |
- return m_pAnnotHandlerMgr.get(); |
-} |
- |
-CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { |
- if (!m_pActionHandler) |
- m_pActionHandler.reset(new CPDFSDK_ActionHandler()); |
- return m_pActionHandler.get(); |
-} |
- |
-CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { |
- if (!m_pIFormFiller) |
- m_pIFormFiller.reset(new CFFL_IFormFiller(this)); |
- return m_pIFormFiller.get(); |
-} |
- |
-// static |
-CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( |
- FPDF_FORMHANDLE hHandle) { |
- CPDFDoc_Environment* pEnv = static_cast<CPDFDoc_Environment*>(hHandle); |
- return pEnv ? pEnv->GetSDKDocument() : nullptr; |
-} |
- |
-CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, |
- CPDFDoc_Environment* pEnv) |
- : m_pDoc(pDoc), |
- m_pFocusAnnot(nullptr), |
- m_pEnv(pEnv), |
- m_bChangeMask(FALSE), |
- m_bBeingDestroyed(FALSE) {} |
- |
-CPDFSDK_Document::~CPDFSDK_Document() { |
- m_bBeingDestroyed = TRUE; |
- |
- for (auto& it : m_pageMap) |
- it.second->KillFocusAnnotIfNeeded(); |
- |
- for (auto& it : m_pageMap) |
- delete it.second; |
- m_pageMap.clear(); |
-} |
- |
-CPDFSDK_PageView* CPDFSDK_Document::GetPageView( |
- UnderlyingPageType* pUnderlyingPage, |
- bool ReNew) { |
- auto it = m_pageMap.find(pUnderlyingPage); |
- if (it != m_pageMap.end()) |
- return it->second; |
- |
- if (!ReNew) |
- return nullptr; |
- |
- CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); |
- m_pageMap[pUnderlyingPage] = pPageView; |
- // Delay to load all the annotations, to avoid endless loop. |
- pPageView->LoadFXAnnots(); |
- return pPageView; |
-} |
- |
-CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { |
- UnderlyingPageType* pPage = |
- UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); |
- return pPage ? GetPageView(pPage, true) : nullptr; |
-} |
- |
-CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { |
- UnderlyingPageType* pTempPage = |
- UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); |
- if (!pTempPage) |
- return nullptr; |
- |
- auto it = m_pageMap.find(pTempPage); |
- return it != m_pageMap.end() ? it->second : nullptr; |
-} |
- |
-void CPDFSDK_Document::ProcJavascriptFun() { |
- CPDF_Document* pPDFDoc = GetPDFDocument(); |
- CPDF_DocJSActions docJS(pPDFDoc); |
- int iCount = docJS.CountJSActions(); |
- if (iCount < 1) |
- return; |
- for (int i = 0; i < iCount; i++) { |
- CFX_ByteString csJSName; |
- CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
- if (m_pEnv->GetActionHander()) |
- m_pEnv->GetActionHander()->DoAction_JavaScript( |
- jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); |
- } |
-} |
- |
-FX_BOOL CPDFSDK_Document::ProcOpenAction() { |
- if (!m_pDoc) |
- return FALSE; |
- |
- CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); |
- if (!pRoot) |
- return FALSE; |
- |
- CPDF_Object* pOpenAction = pRoot->GetDictBy("OpenAction"); |
- if (!pOpenAction) |
- pOpenAction = pRoot->GetArrayBy("OpenAction"); |
- |
- if (!pOpenAction) |
- return FALSE; |
- |
- if (pOpenAction->IsArray()) |
- return TRUE; |
- |
- if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { |
- CPDF_Action action(pDict); |
- if (m_pEnv->GetActionHander()) |
- m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); |
- return TRUE; |
- } |
- return FALSE; |
-} |
- |
-CPDF_OCContext* CPDFSDK_Document::GetOCContext() { |
- if (!m_pOccontent) { |
- m_pOccontent.reset( |
- new CPDF_OCContext(GetPDFDocument(), CPDF_OCContext::View)); |
- } |
- return m_pOccontent.get(); |
-} |
- |
-void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { |
- auto it = m_pageMap.find(pUnderlyingPage); |
- if (it == m_pageMap.end()) |
- return; |
- |
- CPDFSDK_PageView* pPageView = it->second; |
- if (pPageView->IsLocked()) |
- return; |
- |
- // This must happen before we remove |pPageView| from the map because |
- // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will |
- // look for this page view in the map, if it doesn't find it a new one will |
- // be created. We then have two page views pointing to the same page and |
- // bad things happen. |
- pPageView->KillFocusAnnotIfNeeded(); |
- |
- // Remove the page from the map to make sure we don't accidentally attempt |
- // to use the |pPageView| while we're cleaning it up. |
- m_pageMap.erase(it); |
- |
- delete pPageView; |
-} |
- |
-UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { |
- return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); |
-} |
- |
-CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { |
- if (!m_pInterForm) |
- m_pInterForm.reset(new CPDFSDK_InterForm(this)); |
- return m_pInterForm.get(); |
-} |
- |
-void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, |
- CPDFSDK_Annot* pAnnot) { |
- for (const auto& it : m_pageMap) { |
- CPDFSDK_PageView* pPageView = it.second; |
- if (pPageView != pSender) { |
- pPageView->UpdateView(pAnnot); |
- } |
- } |
-} |
- |
-CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { |
- return m_pFocusAnnot; |
-} |
- |
-FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { |
- if (m_bBeingDestroyed) |
- return FALSE; |
- |
- if (m_pFocusAnnot == pAnnot) |
- return TRUE; |
- |
- if (m_pFocusAnnot) { |
- if (!KillFocusAnnot(nFlag)) |
- return FALSE; |
- } |
- |
- if (!pAnnot) |
- return FALSE; |
- |
-#ifdef PDF_ENABLE_XFA |
- CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
-#endif // PDF_ENABLE_XFA |
- CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
- if (pPageView && pPageView->IsValid()) { |
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
- if (!m_pFocusAnnot) { |
-#ifdef PDF_ENABLE_XFA |
- if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) |
- return FALSE; |
-#endif // PDF_ENABLE_XFA |
- if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) |
- return FALSE; |
- if (!m_pFocusAnnot) { |
- m_pFocusAnnot = pAnnot; |
- return TRUE; |
- } |
- } |
- } |
- return FALSE; |
-} |
- |
-FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { |
- if (m_pFocusAnnot) { |
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
- CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
- m_pFocusAnnot = nullptr; |
- |
-#ifdef PDF_ENABLE_XFA |
- if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) |
- return FALSE; |
-#endif // PDF_ENABLE_XFA |
- |
- if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
- if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { |
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
- int nFieldType = pWidget->GetFieldType(); |
- if (FIELDTYPE_TEXTFIELD == nFieldType || |
- FIELDTYPE_COMBOBOX == nFieldType) { |
- m_pEnv->FFI_OnSetFieldInputFocus(nullptr, nullptr, 0, FALSE); |
- } |
- } |
- |
- if (!m_pFocusAnnot) |
- return TRUE; |
- } else { |
- m_pFocusAnnot = pFocusAnnot; |
- } |
- } |
- return FALSE; |
-} |
- |
-void CPDFSDK_Document::OnCloseDocument() { |
- KillFocusAnnot(); |
-} |
- |
-FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { |
- return GetPDFDocument()->GetUserPermissions() & nFlag; |
-} |
- |
-IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { |
- return m_pEnv->GetJSRuntime(); |
-} |
- |
-CFX_WideString CPDFSDK_Document::GetPath() { |
- return m_pEnv->JS_docGetFilePath(); |
-} |
- |
CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
UnderlyingPageType* page) |
: m_page(page), |