Chromium Code Reviews| 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" |
| 11 #include "fpdfsdk/include/fsdk_define.h" | 11 #include "fpdfsdk/include/fsdk_define.h" |
| 12 #include "fpdfsdk/include/fsdk_mgr.h" | 12 #include "fpdfsdk/include/fsdk_mgr.h" |
| 13 #include "fpdfsdk/include/javascript/IJavaScript.h" | 13 #include "fpdfsdk/include/javascript/IJavaScript.h" |
| 14 #include "public/fpdf_formfill.h" | 14 #include "public/fpdf_formfill.h" |
| 15 | 15 |
| 16 #define IDS_XFA_Validate_Input \ | 16 #define IDS_XFA_Validate_Input \ |
| 17 "At least one required field was empty. Please fill in the required " \ | 17 "At least one required field was empty. Please fill in the required " \ |
| 18 "fields\r\n(highlighted) before continuing." | 18 "fields\r\n(highlighted) before continuing." |
| 19 | 19 |
| 20 // submit | 20 // submit |
| 21 #define FXFA_CONFIG 0x00000001 | 21 #define FXFA_CONFIG 0x00000001 |
| 22 #define FXFA_TEMPLATE 0x00000010 | 22 #define FXFA_TEMPLATE 0x00000010 |
| 23 #define FXFA_LOCALESET 0x00000100 | 23 #define FXFA_LOCALESET 0x00000100 |
| 24 #define FXFA_DATASETS 0x00001000 | 24 #define FXFA_DATASETS 0x00001000 |
| 25 #define FXFA_XMPMETA 0x00010000 | 25 #define FXFA_XMPMETA 0x00010000 |
| 26 #define FXFA_XFDF 0x00100000 | 26 #define FXFA_XFDF 0x00100000 |
| 27 #define FXFA_FORM 0x01000000 | 27 #define FXFA_FORM 0x01000000 |
| 28 #define FXFA_PDF 0x10000000 | 28 #define FXFA_PDF 0x10000000 |
| 29 | 29 |
| 30 #define FXFA_LOADSTATUS_PRELOAD 0 | |
|
Tom Sepez
2016/03/17 00:23:57
can we make this an enum nested in the class?
Jim Wang
2016/03/17 05:00:43
Done.
| |
| 31 #define FXFA_LOADSTATUS_LOADING 1 | |
| 32 #define FXFA_LOADSTATUS_LOADED 2 | |
| 33 #define FXFA_LOADSTATUS_CLOSING 3 | |
| 34 #define FXFA_LOADSTATUS_CLOSED 4 | |
| 35 | |
| 30 #ifndef _WIN32 | 36 #ifndef _WIN32 |
| 31 extern void SetLastError(int err); | 37 extern void SetLastError(int err); |
| 32 | 38 |
| 33 extern int GetLastError(); | 39 extern int GetLastError(); |
| 34 #endif | 40 #endif |
| 35 | 41 |
| 36 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, | 42 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, |
| 37 CPDFXFA_App* pProvider) | 43 CPDFXFA_App* pProvider) |
| 38 : m_iDocType(DOCTYPE_PDF), | 44 : m_iDocType(DOCTYPE_PDF), |
| 39 m_pPDFDoc(pPDFDoc), | 45 m_pPDFDoc(pPDFDoc), |
| 40 m_pSDKDoc(nullptr), | 46 m_pSDKDoc(nullptr), |
| 41 m_pXFADoc(nullptr), | 47 m_pXFADoc(nullptr), |
| 42 m_pXFADocView(nullptr), | 48 m_pXFADocView(nullptr), |
| 43 m_pApp(pProvider), | 49 m_pApp(pProvider), |
| 44 m_pJSContext(nullptr) { | 50 m_pJSContext(nullptr), |
| 45 } | 51 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), |
| 52 m_nPageCount(0) {} | |
| 46 | 53 |
| 47 CPDFXFA_Document::~CPDFXFA_Document() { | 54 CPDFXFA_Document::~CPDFXFA_Document() { |
| 55 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; | |
| 56 | |
| 48 if (m_pXFADoc) { | 57 if (m_pXFADoc) { |
| 49 IXFA_App* pApp = m_pApp->GetXFAApp(); | 58 IXFA_App* pApp = m_pApp->GetXFAApp(); |
| 50 if (pApp) { | 59 if (pApp) { |
| 51 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); | 60 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); |
| 52 if (pDocHandler) { | 61 if (pDocHandler) { |
| 53 CloseXFADoc(pDocHandler); | 62 CloseXFADoc(pDocHandler); |
| 54 } | 63 } |
| 55 } | 64 } |
| 56 delete m_pXFADoc; | 65 delete m_pXFADoc; |
| 57 } | 66 } |
| 58 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) | 67 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) |
| 59 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); | 68 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); |
| 60 delete m_pSDKDoc; | 69 delete m_pSDKDoc; |
| 61 if (m_pPDFDoc) { | 70 if (m_pPDFDoc) { |
| 62 CPDF_Parser* pParser = m_pPDFDoc->GetParser(); | 71 CPDF_Parser* pParser = m_pPDFDoc->GetParser(); |
| 63 if (pParser) | 72 if (pParser) |
| 64 delete pParser; | 73 delete pParser; |
| 65 else | 74 else |
| 66 delete m_pPDFDoc; | 75 delete m_pPDFDoc; |
| 67 } | 76 } |
| 77 | |
| 78 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; | |
| 68 } | 79 } |
| 69 | 80 |
| 70 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | 81 FX_BOOL CPDFXFA_Document::LoadXFADoc() { |
| 82 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; | |
| 83 | |
| 71 if (!m_pPDFDoc) | 84 if (!m_pPDFDoc) |
| 72 return FALSE; | 85 return FALSE; |
| 73 | 86 |
| 74 m_XFAPageList.RemoveAll(); | 87 m_XFAPageList.RemoveAll(); |
| 75 | 88 |
| 76 IXFA_App* pApp = m_pApp->GetXFAApp(); | 89 IXFA_App* pApp = m_pApp->GetXFAApp(); |
| 77 if (!pApp) | 90 if (!pApp) |
| 78 return FALSE; | 91 return FALSE; |
| 79 | 92 |
| 80 m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc); | 93 m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 106 | 119 |
| 107 m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View); | 120 m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View); |
| 108 if (m_pXFADocView->StartLayout() < 0) { | 121 if (m_pXFADocView->StartLayout() < 0) { |
| 109 CloseXFADoc(pDocHandler); | 122 CloseXFADoc(pDocHandler); |
| 110 SetLastError(FPDF_ERR_XFALAYOUT); | 123 SetLastError(FPDF_ERR_XFALAYOUT); |
| 111 return FALSE; | 124 return FALSE; |
| 112 } | 125 } |
| 113 | 126 |
| 114 m_pXFADocView->DoLayout(NULL); | 127 m_pXFADocView->DoLayout(NULL); |
| 115 m_pXFADocView->StopLayout(); | 128 m_pXFADocView->StopLayout(); |
| 129 m_nLoadStatus = FXFA_LOADSTATUS_LOADED; | |
| 130 | |
| 116 return TRUE; | 131 return TRUE; |
| 117 } | 132 } |
| 118 | 133 |
| 119 int CPDFXFA_Document::GetPageCount() { | 134 int CPDFXFA_Document::GetPageCount() { |
| 120 if (!m_pPDFDoc && !m_pXFADoc) | 135 if (!m_pPDFDoc && !m_pXFADoc) |
| 121 return 0; | 136 return 0; |
| 122 | 137 |
| 123 switch (m_iDocType) { | 138 switch (m_iDocType) { |
| 124 case DOCTYPE_PDF: | 139 case DOCTYPE_PDF: |
| 125 case DOCTYPE_STATIC_XFA: | 140 case DOCTYPE_STATIC_XFA: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 138 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { | 153 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { |
| 139 if (page_index < 0) | 154 if (page_index < 0) |
| 140 return nullptr; | 155 return nullptr; |
| 141 CPDFXFA_Page* pPage = nullptr; | 156 CPDFXFA_Page* pPage = nullptr; |
| 142 int nCount = m_XFAPageList.GetSize(); | 157 int nCount = m_XFAPageList.GetSize(); |
| 143 if (nCount > 0 && page_index < nCount) { | 158 if (nCount > 0 && page_index < nCount) { |
| 144 pPage = m_XFAPageList.GetAt(page_index); | 159 pPage = m_XFAPageList.GetAt(page_index); |
| 145 if (pPage) | 160 if (pPage) |
| 146 pPage->AddRef(); | 161 pPage->AddRef(); |
| 147 } else { | 162 } else { |
| 148 m_XFAPageList.SetSize(GetPageCount()); | 163 m_nPageCount = GetPageCount(); |
| 164 m_XFAPageList.SetSize(m_nPageCount); | |
| 149 } | 165 } |
| 150 if (pPage) | 166 if (pPage) |
| 151 return pPage; | 167 return pPage; |
| 152 pPage = new CPDFXFA_Page(this, page_index); | 168 pPage = new CPDFXFA_Page(this, page_index); |
| 153 if (!pPage->LoadPage()) { | 169 if (!pPage->LoadPage()) { |
| 154 delete pPage; | 170 delete pPage; |
| 155 return nullptr; | 171 return nullptr; |
| 156 } | 172 } |
| 157 m_XFAPageList.SetAt(page_index, pPage); | 173 m_XFAPageList.SetAt(page_index, pPage); |
| 158 return pPage; | 174 return pPage; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 | 479 |
| 464 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 480 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 465 if (pEnv == NULL) | 481 if (pEnv == NULL) |
| 466 return FALSE; | 482 return FALSE; |
| 467 | 483 |
| 468 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL); | 484 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL); |
| 469 } | 485 } |
| 470 | 486 |
| 471 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, | 487 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, |
| 472 FX_DWORD dwFlags) { | 488 FX_DWORD dwFlags) { |
| 473 if (!pPageView || (dwFlags != XFA_PAGEVIEWEVENT_PostAdded && | 489 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 474 dwFlags != XFA_PAGEVIEWEVENT_PostRemoved)) { | 490 if (!pEnv) |
| 475 return; | 491 return; |
| 492 CPDFXFA_Page* pPage = nullptr; | |
|
Tom Sepez
2016/03/17 00:23:57
This gets shadowed at line 505. We don't need thi
Jim Wang
2016/03/17 05:00:43
Done.
| |
| 493 | |
| 494 if (FXFA_LOADSTATUS_LOADING != m_nLoadStatus && | |
|
Tom Sepez
2016/03/17 00:23:57
Nit: prefer m_nLoadStatus != XFA_LOADSTATUS_LOADIN
Jim Wang
2016/03/17 05:00:43
Done.
| |
| 495 FXFA_LOADSTATUS_CLOSING != m_nLoadStatus && | |
| 496 XFA_PAGEVIEWEVENT_StopLayout == dwFlags) { | |
| 497 int nNewCount = GetPageCount(); | |
| 498 if (nNewCount == m_nPageCount) | |
| 499 return; | |
| 500 | |
| 501 IXFA_DocView* pXFADocView = GetXFADocView(); | |
| 502 if (!pXFADocView) | |
| 503 return; | |
| 504 for (int iPageIter = 0; iPageIter < m_nPageCount; iPageIter++) { | |
| 505 CPDFXFA_Page* pPage = m_XFAPageList.GetAt(iPageIter); | |
| 506 if (!pPage) | |
| 507 continue; | |
| 508 m_pSDKDoc->RemovePageView(pPage); | |
| 509 IXFA_PageView* pXFAPageView = pXFADocView->GetPageView(iPageIter); | |
| 510 pPage->SetXFAPageView(pXFAPageView); | |
| 511 if (pXFAPageView) | |
| 512 pXFAPageView->LoadPageView(nullptr); | |
| 513 } | |
| 514 | |
| 515 int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED | |
| 516 : FXFA_PAGEVIEWEVENT_POSTADDED; | |
| 517 int count = FXSYS_abs(nNewCount - m_nPageCount); | |
| 518 m_nPageCount = nNewCount; | |
| 519 m_XFAPageList.SetSize(nNewCount); | |
| 520 pEnv->FFI_PageEvent(count, flag); | |
| 476 } | 521 } |
| 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 } | 522 } |
| 493 | 523 |
| 494 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget, | 524 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget, |
| 495 CXFA_WidgetAcc* pWidgetData, | 525 CXFA_WidgetAcc* pWidgetData, |
| 496 FX_DWORD dwEvent, | 526 FX_DWORD dwEvent, |
| 497 void* pParam, | 527 void* pParam, |
| 498 void* pAdditional) { | 528 void* pAdditional) { |
| 499 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) | 529 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) |
| 500 return; | 530 return; |
| 501 | 531 |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1249 } | 1279 } |
| 1250 | 1280 |
| 1251 return _GetHValueByName(szPropName, hValue, | 1281 return _GetHValueByName(szPropName, hValue, |
| 1252 m_pSDKDoc->GetEnv()->GetJSRuntime()); | 1282 m_pSDKDoc->GetEnv()->GetJSRuntime()); |
| 1253 } | 1283 } |
| 1254 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, | 1284 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, |
| 1255 FXJSE_HVALUE hValue, | 1285 FXJSE_HVALUE hValue, |
| 1256 IJS_Runtime* runTime) { | 1286 IJS_Runtime* runTime) { |
| 1257 return runTime->GetHValueByName(utf8Name, hValue); | 1287 return runTime->GetHValueByName(utf8Name, hValue); |
| 1258 } | 1288 } |
| OLD | NEW |