| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/fpdfxfa/fpdfxfa_app.h" | 7 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" |
| 8 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" | 8 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
| 9 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" | 9 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" |
| 10 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" | 10 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, | 36 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, |
| 37 CPDFXFA_App* pProvider) | 37 CPDFXFA_App* pProvider) |
| 38 : m_iDocType(DOCTYPE_PDF), | 38 : m_iDocType(DOCTYPE_PDF), |
| 39 m_pPDFDoc(pPDFDoc), | 39 m_pPDFDoc(pPDFDoc), |
| 40 m_pSDKDoc(nullptr), | 40 m_pSDKDoc(nullptr), |
| 41 m_pXFADoc(nullptr), | 41 m_pXFADoc(nullptr), |
| 42 m_pXFADocView(nullptr), | 42 m_pXFADocView(nullptr), |
| 43 m_pApp(pProvider), | 43 m_pApp(pProvider), |
| 44 m_pJSContext(nullptr) { | 44 m_pJSContext(nullptr), |
| 45 } | 45 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), |
| 46 m_nPageCount(0) {} |
| 46 | 47 |
| 47 CPDFXFA_Document::~CPDFXFA_Document() { | 48 CPDFXFA_Document::~CPDFXFA_Document() { |
| 49 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; |
| 50 |
| 48 if (m_pXFADoc) { | 51 if (m_pXFADoc) { |
| 49 IXFA_App* pApp = m_pApp->GetXFAApp(); | 52 IXFA_App* pApp = m_pApp->GetXFAApp(); |
| 50 if (pApp) { | 53 if (pApp) { |
| 51 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); | 54 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); |
| 52 if (pDocHandler) { | 55 if (pDocHandler) { |
| 53 CloseXFADoc(pDocHandler); | 56 CloseXFADoc(pDocHandler); |
| 54 } | 57 } |
| 55 } | 58 } |
| 56 delete m_pXFADoc; | 59 delete m_pXFADoc; |
| 57 } | 60 } |
| 58 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) | 61 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) |
| 59 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); | 62 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); |
| 60 delete m_pSDKDoc; | 63 delete m_pSDKDoc; |
| 61 if (m_pPDFDoc) { | 64 if (m_pPDFDoc) { |
| 62 CPDF_Parser* pParser = m_pPDFDoc->GetParser(); | 65 CPDF_Parser* pParser = m_pPDFDoc->GetParser(); |
| 63 if (pParser) | 66 if (pParser) |
| 64 delete pParser; | 67 delete pParser; |
| 65 else | 68 else |
| 66 delete m_pPDFDoc; | 69 delete m_pPDFDoc; |
| 67 } | 70 } |
| 71 |
| 72 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; |
| 68 } | 73 } |
| 69 | 74 |
| 70 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | 75 FX_BOOL CPDFXFA_Document::LoadXFADoc() { |
| 76 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; |
| 77 |
| 71 if (!m_pPDFDoc) | 78 if (!m_pPDFDoc) |
| 72 return FALSE; | 79 return FALSE; |
| 73 | 80 |
| 74 m_XFAPageList.RemoveAll(); | 81 m_XFAPageList.RemoveAll(); |
| 75 | 82 |
| 76 IXFA_App* pApp = m_pApp->GetXFAApp(); | 83 IXFA_App* pApp = m_pApp->GetXFAApp(); |
| 77 if (!pApp) | 84 if (!pApp) |
| 78 return FALSE; | 85 return FALSE; |
| 79 | 86 |
| 80 m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc); | 87 m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 106 | 113 |
| 107 m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View); | 114 m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View); |
| 108 if (m_pXFADocView->StartLayout() < 0) { | 115 if (m_pXFADocView->StartLayout() < 0) { |
| 109 CloseXFADoc(pDocHandler); | 116 CloseXFADoc(pDocHandler); |
| 110 SetLastError(FPDF_ERR_XFALAYOUT); | 117 SetLastError(FPDF_ERR_XFALAYOUT); |
| 111 return FALSE; | 118 return FALSE; |
| 112 } | 119 } |
| 113 | 120 |
| 114 m_pXFADocView->DoLayout(NULL); | 121 m_pXFADocView->DoLayout(NULL); |
| 115 m_pXFADocView->StopLayout(); | 122 m_pXFADocView->StopLayout(); |
| 123 m_nLoadStatus = FXFA_LOADSTATUS_LOADED; |
| 124 |
| 116 return TRUE; | 125 return TRUE; |
| 117 } | 126 } |
| 118 | 127 |
| 119 int CPDFXFA_Document::GetPageCount() { | 128 int CPDFXFA_Document::GetPageCount() { |
| 120 if (!m_pPDFDoc && !m_pXFADoc) | 129 if (!m_pPDFDoc && !m_pXFADoc) |
| 121 return 0; | 130 return 0; |
| 122 | 131 |
| 123 switch (m_iDocType) { | 132 switch (m_iDocType) { |
| 124 case DOCTYPE_PDF: | 133 case DOCTYPE_PDF: |
| 125 case DOCTYPE_STATIC_XFA: | 134 case DOCTYPE_STATIC_XFA: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { | 147 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { |
| 139 if (page_index < 0) | 148 if (page_index < 0) |
| 140 return nullptr; | 149 return nullptr; |
| 141 CPDFXFA_Page* pPage = nullptr; | 150 CPDFXFA_Page* pPage = nullptr; |
| 142 int nCount = m_XFAPageList.GetSize(); | 151 int nCount = m_XFAPageList.GetSize(); |
| 143 if (nCount > 0 && page_index < nCount) { | 152 if (nCount > 0 && page_index < nCount) { |
| 144 pPage = m_XFAPageList.GetAt(page_index); | 153 pPage = m_XFAPageList.GetAt(page_index); |
| 145 if (pPage) | 154 if (pPage) |
| 146 pPage->AddRef(); | 155 pPage->AddRef(); |
| 147 } else { | 156 } else { |
| 148 m_XFAPageList.SetSize(GetPageCount()); | 157 m_nPageCount = GetPageCount(); |
| 158 m_XFAPageList.SetSize(m_nPageCount); |
| 149 } | 159 } |
| 150 if (pPage) | 160 if (pPage) |
| 151 return pPage; | 161 return pPage; |
| 152 pPage = new CPDFXFA_Page(this, page_index); | 162 pPage = new CPDFXFA_Page(this, page_index); |
| 153 if (!pPage->LoadPage()) { | 163 if (!pPage->LoadPage()) { |
| 154 delete pPage; | 164 delete pPage; |
| 155 return nullptr; | 165 return nullptr; |
| 156 } | 166 } |
| 157 m_XFAPageList.SetAt(page_index, pPage); | 167 m_XFAPageList.SetAt(page_index, pPage); |
| 158 return pPage; | 168 return pPage; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 473 |
| 464 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 474 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 465 if (pEnv == NULL) | 475 if (pEnv == NULL) |
| 466 return FALSE; | 476 return FALSE; |
| 467 | 477 |
| 468 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL); | 478 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL); |
| 469 } | 479 } |
| 470 | 480 |
| 471 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, | 481 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, |
| 472 FX_DWORD dwFlags) { | 482 FX_DWORD dwFlags) { |
| 473 if (!pPageView || (dwFlags != XFA_PAGEVIEWEVENT_PostAdded && | 483 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 474 dwFlags != XFA_PAGEVIEWEVENT_PostRemoved)) { | 484 if (!pEnv) |
| 475 return; | 485 return; |
| 486 |
| 487 if (m_nLoadStatus != FXFA_LOADSTATUS_LOADING && |
| 488 m_nLoadStatus != FXFA_LOADSTATUS_CLOSING && |
| 489 XFA_PAGEVIEWEVENT_StopLayout == dwFlags) { |
| 490 int nNewCount = GetPageCount(); |
| 491 if (nNewCount == m_nPageCount) |
| 492 return; |
| 493 |
| 494 IXFA_DocView* pXFADocView = GetXFADocView(); |
| 495 if (!pXFADocView) |
| 496 return; |
| 497 for (int iPageIter = 0; iPageIter < m_nPageCount; iPageIter++) { |
| 498 CPDFXFA_Page* pPage = m_XFAPageList.GetAt(iPageIter); |
| 499 if (!pPage) |
| 500 continue; |
| 501 m_pSDKDoc->RemovePageView(pPage); |
| 502 IXFA_PageView* pXFAPageView = pXFADocView->GetPageView(iPageIter); |
| 503 pPage->SetXFAPageView(pXFAPageView); |
| 504 if (pXFAPageView) |
| 505 pXFAPageView->LoadPageView(nullptr); |
| 506 } |
| 507 |
| 508 int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED |
| 509 : FXFA_PAGEVIEWEVENT_POSTADDED; |
| 510 int count = FXSYS_abs(nNewCount - m_nPageCount); |
| 511 m_nPageCount = nNewCount; |
| 512 m_XFAPageList.SetSize(nNewCount); |
| 513 pEnv->FFI_PageEvent(count, flag); |
| 476 } | 514 } |
| 477 CPDFXFA_Page* pPage = nullptr; | |
| 478 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 479 if (dwFlags == XFA_PAGEVIEWEVENT_PostAdded) { | |
| 480 int nPageIndex = pPageView->GetPageViewIndex(); | |
| 481 pPage = GetPage(nPageIndex); | |
| 482 if (pPage) | |
| 483 pPage->SetXFAPageView(pPageView); | |
| 484 pEnv->FFI_PageEvent(nPageIndex, dwFlags); | |
| 485 return; | |
| 486 } | |
| 487 pPage = GetPage(pPageView); | |
| 488 if (!pPage) | |
| 489 return; | |
| 490 pEnv->FFI_PageEvent(pPage->GetPageIndex(), dwFlags); | |
| 491 pPage->Release(); | |
| 492 } | 515 } |
| 493 | 516 |
| 494 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget, | 517 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget, |
| 495 CXFA_WidgetAcc* pWidgetData, | 518 CXFA_WidgetAcc* pWidgetData, |
| 496 FX_DWORD dwEvent, | 519 FX_DWORD dwEvent, |
| 497 void* pParam, | 520 void* pParam, |
| 498 void* pAdditional) { | 521 void* pAdditional) { |
| 499 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) | 522 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) |
| 500 return; | 523 return; |
| 501 | 524 |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 } | 1272 } |
| 1250 | 1273 |
| 1251 return _GetHValueByName(szPropName, hValue, | 1274 return _GetHValueByName(szPropName, hValue, |
| 1252 m_pSDKDoc->GetEnv()->GetJSRuntime()); | 1275 m_pSDKDoc->GetEnv()->GetJSRuntime()); |
| 1253 } | 1276 } |
| 1254 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, | 1277 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, |
| 1255 FXJSE_HVALUE hValue, | 1278 FXJSE_HVALUE hValue, |
| 1256 IJS_Runtime* runTime) { | 1279 IJS_Runtime* runTime) { |
| 1257 return runTime->GetHValueByName(utf8Name, hValue); | 1280 return runTime->GetHValueByName(utf8Name, hValue); |
| 1258 } | 1281 } |
| OLD | NEW |