Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp

Issue 2123133004: Remove IXFA_Parser, cleanup XFA parser code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/parser/xfa_layout_itemlayout.cpp ('k') | xfa/fxfa/parser/xfa_locale.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" 7 #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h"
8 8
9 #include "xfa/fxfa/app/xfa_ffnotify.h" 9 #include "xfa/fxfa/app/xfa_ffnotify.h"
10 #include "xfa/fxfa/parser/xfa_doclayout.h" 10 #include "xfa/fxfa/parser/xfa_doclayout.h"
11 #include "xfa/fxfa/parser/xfa_document.h" 11 #include "xfa/fxfa/parser/xfa_document.h"
12 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" 12 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h"
13 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" 13 #include "xfa/fxfa/parser/xfa_document_layout_imp.h"
14 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" 14 #include "xfa/fxfa/parser/xfa_layout_appadapter.h"
15 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" 15 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h"
16 #include "xfa/fxfa/parser/xfa_localemgr.h" 16 #include "xfa/fxfa/parser/xfa_localemgr.h"
17 #include "xfa/fxfa/parser/xfa_object.h" 17 #include "xfa/fxfa/parser/xfa_object.h"
18 #include "xfa/fxfa/parser/xfa_parser.h"
19 #include "xfa/fxfa/parser/xfa_parser_imp.h" 18 #include "xfa/fxfa/parser/xfa_parser_imp.h"
20 #include "xfa/fxfa/parser/xfa_script.h" 19 #include "xfa/fxfa/parser/xfa_script.h"
21 #include "xfa/fxfa/parser/xfa_script_imp.h" 20 #include "xfa/fxfa/parser/xfa_script_imp.h"
22 #include "xfa/fxfa/parser/xfa_utils.h" 21 #include "xfa/fxfa/parser/xfa_utils.h"
23 22
24 namespace { 23 namespace {
25 24
26 class PageSetContainerLayoutItem { 25 class PageSetContainerLayoutItem {
27 public: 26 public:
28 static inline CXFA_ContainerLayoutItem* GetFirstChild( 27 static inline CXFA_ContainerLayoutItem* GetFirstChild(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 iCount++; 274 iCount++;
276 if (pPageArea->GetFirstChildByClass(XFA_Element::ContentArea)) { 275 if (pPageArea->GetFirstChildByClass(XFA_Element::ContentArea)) {
277 return TRUE; 276 return TRUE;
278 } 277 }
279 } 278 }
280 } 279 }
281 if (iCount > 0) { 280 if (iCount > 0) {
282 return FALSE; 281 return FALSE;
283 } 282 }
284 CXFA_Document* pDocument = pTemplateNode->GetDocument(); 283 CXFA_Document* pDocument = pTemplateNode->GetDocument();
285 CXFA_Document* pObjFactory = pDocument->GetParser()->GetFactory();
286 pPageArea = m_pTemplatePageSetRoot->GetChild(0, XFA_Element::PageArea); 284 pPageArea = m_pTemplatePageSetRoot->GetChild(0, XFA_Element::PageArea);
287 if (!pPageArea) { 285 if (!pPageArea) {
288 pPageArea = pObjFactory->CreateNode(m_pTemplatePageSetRoot->GetPacketID(), 286 pPageArea = pDocument->CreateNode(m_pTemplatePageSetRoot->GetPacketID(),
289 XFA_Element::PageArea); 287 XFA_Element::PageArea);
290 if (!pPageArea) { 288 if (!pPageArea) {
291 return FALSE; 289 return FALSE;
292 } 290 }
293 m_pTemplatePageSetRoot->InsertChild(pPageArea, nullptr); 291 m_pTemplatePageSetRoot->InsertChild(pPageArea, nullptr);
294 pPageArea->SetFlag(XFA_NodeFlag_Initialized, true); 292 pPageArea->SetFlag(XFA_NodeFlag_Initialized, true);
295 } 293 }
296 CXFA_Node* pContentArea = pPageArea->GetChild(0, XFA_Element::ContentArea); 294 CXFA_Node* pContentArea = pPageArea->GetChild(0, XFA_Element::ContentArea);
297 if (!pContentArea) { 295 if (!pContentArea) {
298 pContentArea = pObjFactory->CreateNode(pPageArea->GetPacketID(), 296 pContentArea = pDocument->CreateNode(pPageArea->GetPacketID(),
299 XFA_Element::ContentArea); 297 XFA_Element::ContentArea);
300 if (!pContentArea) { 298 if (!pContentArea) {
301 return FALSE; 299 return FALSE;
302 } 300 }
303 pPageArea->InsertChild(pContentArea, nullptr); 301 pPageArea->InsertChild(pContentArea, nullptr);
304 pContentArea->SetFlag(XFA_NodeFlag_Initialized, true); 302 pContentArea->SetFlag(XFA_NodeFlag_Initialized, true);
305 pContentArea->SetMeasure(XFA_ATTRIBUTE_X, 303 pContentArea->SetMeasure(XFA_ATTRIBUTE_X,
306 CXFA_Measurement(0.25f, XFA_UNIT_In)); 304 CXFA_Measurement(0.25f, XFA_UNIT_In));
307 pContentArea->SetMeasure(XFA_ATTRIBUTE_Y, 305 pContentArea->SetMeasure(XFA_ATTRIBUTE_Y,
308 CXFA_Measurement(0.25f, XFA_UNIT_In)); 306 CXFA_Measurement(0.25f, XFA_UNIT_In));
309 pContentArea->SetMeasure(XFA_ATTRIBUTE_W, 307 pContentArea->SetMeasure(XFA_ATTRIBUTE_W,
310 CXFA_Measurement(8.0f, XFA_UNIT_In)); 308 CXFA_Measurement(8.0f, XFA_UNIT_In));
311 pContentArea->SetMeasure(XFA_ATTRIBUTE_H, 309 pContentArea->SetMeasure(XFA_ATTRIBUTE_H,
312 CXFA_Measurement(10.5f, XFA_UNIT_In)); 310 CXFA_Measurement(10.5f, XFA_UNIT_In));
313 } 311 }
314 CXFA_Node* pMedium = pPageArea->GetChild(0, XFA_Element::Medium); 312 CXFA_Node* pMedium = pPageArea->GetChild(0, XFA_Element::Medium);
315 if (!pMedium) { 313 if (!pMedium) {
316 pMedium = 314 pMedium =
317 pObjFactory->CreateNode(pPageArea->GetPacketID(), XFA_Element::Medium); 315 pDocument->CreateNode(pPageArea->GetPacketID(), XFA_Element::Medium);
318 if (!pContentArea) { 316 if (!pContentArea) {
319 return FALSE; 317 return FALSE;
320 } 318 }
321 pPageArea->InsertChild(pMedium, nullptr); 319 pPageArea->InsertChild(pMedium, nullptr);
322 pMedium->SetFlag(XFA_NodeFlag_Initialized, true); 320 pMedium->SetFlag(XFA_NodeFlag_Initialized, true);
323 pMedium->SetMeasure(XFA_ATTRIBUTE_Short, 321 pMedium->SetMeasure(XFA_ATTRIBUTE_Short,
324 CXFA_Measurement(8.5f, XFA_UNIT_In)); 322 CXFA_Measurement(8.5f, XFA_UNIT_In));
325 pMedium->SetMeasure(XFA_ATTRIBUTE_Long, 323 pMedium->SetMeasure(XFA_ATTRIBUTE_Long,
326 CXFA_Measurement(11.0f, XFA_UNIT_In)); 324 CXFA_Measurement(11.0f, XFA_UNIT_In));
327 } 325 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 446 }
449 return XFA_LAYOUT_FLOAT_MAX; 447 return XFA_LAYOUT_FLOAT_MAX;
450 } 448 }
451 449
452 FX_BOOL XFA_LayoutPageMgr_RunBreakTestScript(CXFA_Node* pTestScript) { 450 FX_BOOL XFA_LayoutPageMgr_RunBreakTestScript(CXFA_Node* pTestScript) {
453 CFX_WideString wsExpression; 451 CFX_WideString wsExpression;
454 pTestScript->TryContent(wsExpression); 452 pTestScript->TryContent(wsExpression);
455 if (wsExpression.IsEmpty()) { 453 if (wsExpression.IsEmpty()) {
456 return TRUE; 454 return TRUE;
457 } 455 }
458 return pTestScript->GetDocument()->GetParser()->GetNotify()->RunScript( 456 return pTestScript->GetDocument()->GetNotify()->RunScript(
459 pTestScript, pTestScript->GetNodeItem(XFA_NODEITEM_Parent, 457 pTestScript, pTestScript->GetNodeItem(XFA_NODEITEM_Parent,
460 XFA_ObjectType::ContainerNode)); 458 XFA_ObjectType::ContainerNode));
461 } 459 }
462 CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord( 460 CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord(
463 CXFA_Node* pPageNode, 461 CXFA_Node* pPageNode,
464 FX_BOOL bCreateNew) { 462 FX_BOOL bCreateNew) {
465 CXFA_ContainerRecord* pNewRecord = new CXFA_ContainerRecord(); 463 CXFA_ContainerRecord* pNewRecord = new CXFA_ContainerRecord();
466 if (m_pCurrentContainerRecord) { 464 if (m_pCurrentContainerRecord) {
467 if (!IsPageSetRootOrderedOccurrence() || !pPageNode) { 465 if (!IsPageSetRootOrderedOccurrence() || !pPageNode) {
468 *pNewRecord = *GetCurrentContainerRecord(); 466 *pNewRecord = *GetCurrentContainerRecord();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } 527 }
530 void CXFA_LayoutPageMgr::AddPageAreaLayoutItem(CXFA_ContainerRecord* pNewRecord, 528 void CXFA_LayoutPageMgr::AddPageAreaLayoutItem(CXFA_ContainerRecord* pNewRecord,
531 CXFA_Node* pNewPageArea) { 529 CXFA_Node* pNewPageArea) {
532 CXFA_ContainerLayoutItem* pNewPageAreaLayoutItem = nullptr; 530 CXFA_ContainerLayoutItem* pNewPageAreaLayoutItem = nullptr;
533 if (m_PageArray.GetSize() > m_nAvailPages) { 531 if (m_PageArray.GetSize() > m_nAvailPages) {
534 CXFA_ContainerLayoutItem* pContainerItem = m_PageArray[m_nAvailPages]; 532 CXFA_ContainerLayoutItem* pContainerItem = m_PageArray[m_nAvailPages];
535 pContainerItem->m_pFormNode = pNewPageArea; 533 pContainerItem->m_pFormNode = pNewPageArea;
536 m_nAvailPages++; 534 m_nAvailPages++;
537 pNewPageAreaLayoutItem = pContainerItem; 535 pNewPageAreaLayoutItem = pContainerItem;
538 } else { 536 } else {
539 CXFA_FFNotify* pNotify = 537 CXFA_FFNotify* pNotify = pNewPageArea->GetDocument()->GetNotify();
540 pNewPageArea->GetDocument()->GetParser()->GetNotify();
541 CXFA_ContainerLayoutItem* pContainerItem = 538 CXFA_ContainerLayoutItem* pContainerItem =
542 (CXFA_ContainerLayoutItem*)pNotify->OnCreateLayoutItem(pNewPageArea); 539 (CXFA_ContainerLayoutItem*)pNotify->OnCreateLayoutItem(pNewPageArea);
543 m_PageArray.Add(pContainerItem); 540 m_PageArray.Add(pContainerItem);
544 m_nAvailPages++; 541 m_nAvailPages++;
545 pNotify->OnPageEvent(pContainerItem, XFA_PAGEVIEWEVENT_PostRemoved); 542 pNotify->OnPageEvent(pContainerItem, XFA_PAGEVIEWEVENT_PostRemoved);
546 pNewPageAreaLayoutItem = pContainerItem; 543 pNewPageAreaLayoutItem = pContainerItem;
547 } 544 }
548 pNewRecord->pCurPageSet->AddChild(pNewPageAreaLayoutItem); 545 pNewRecord->pCurPageSet->AddChild(pNewPageAreaLayoutItem);
549 pNewRecord->pCurPageArea = pNewPageAreaLayoutItem; 546 pNewRecord->pCurPageArea = pNewPageAreaLayoutItem;
550 pNewRecord->pCurContentArea = nullptr; 547 pNewRecord->pCurContentArea = nullptr;
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 m_rgProposedContainerRecord.RemoveAll(); 1554 m_rgProposedContainerRecord.RemoveAll();
1558 } 1555 }
1559 m_pCurrentContainerRecord = nullptr; 1556 m_pCurrentContainerRecord = nullptr;
1560 m_pCurPageArea = nullptr; 1557 m_pCurPageArea = nullptr;
1561 m_nCurPageCount = 0; 1558 m_nCurPageCount = 0;
1562 m_bCreateOverFlowPage = FALSE; 1559 m_bCreateOverFlowPage = FALSE;
1563 m_pPageSetMap.RemoveAll(); 1560 m_pPageSetMap.RemoveAll();
1564 } 1561 }
1565 CXFA_LayoutItem* CXFA_LayoutPageMgr::FindOrCreateLayoutItem( 1562 CXFA_LayoutItem* CXFA_LayoutPageMgr::FindOrCreateLayoutItem(
1566 CXFA_Node* pFormNode) { 1563 CXFA_Node* pFormNode) {
1567 return pFormNode->GetDocument()->GetParser()->GetNotify()->OnCreateLayoutItem( 1564 return pFormNode->GetDocument()->GetNotify()->OnCreateLayoutItem(pFormNode);
1568 pFormNode);
1569 } 1565 }
1570 1566
1571 void CXFA_LayoutPageMgr::SaveLayoutItem(CXFA_LayoutItem* pParentLayoutItem) { 1567 void CXFA_LayoutPageMgr::SaveLayoutItem(CXFA_LayoutItem* pParentLayoutItem) {
1572 CXFA_LayoutItem* pNextLayoutItem; 1568 CXFA_LayoutItem* pNextLayoutItem;
1573 CXFA_LayoutItem* pCurLayoutItem = pParentLayoutItem->m_pFirstChild; 1569 CXFA_LayoutItem* pCurLayoutItem = pParentLayoutItem->m_pFirstChild;
1574 while (pCurLayoutItem) { 1570 while (pCurLayoutItem) {
1575 pNextLayoutItem = pCurLayoutItem->m_pNextSibling; 1571 pNextLayoutItem = pCurLayoutItem->m_pNextSibling;
1576 if (pCurLayoutItem->IsContentLayoutItem()) { 1572 if (pCurLayoutItem->IsContentLayoutItem()) {
1577 if (pCurLayoutItem->m_pFormNode->HasRemovedChildren()) { 1573 if (pCurLayoutItem->m_pFormNode->HasRemovedChildren()) {
1578 CXFA_FFNotify* pNotify = 1574 CXFA_FFNotify* pNotify =
1579 m_pTemplatePageSetRoot->GetDocument()->GetParser()->GetNotify(); 1575 m_pTemplatePageSetRoot->GetDocument()->GetNotify();
1580 CXFA_LayoutProcessor* pDocLayout = 1576 CXFA_LayoutProcessor* pDocLayout =
1581 m_pTemplatePageSetRoot->GetDocument()->GetDocLayout(); 1577 m_pTemplatePageSetRoot->GetDocument()->GetDocLayout();
1582 if (pCurLayoutItem->m_pFirstChild) { 1578 if (pCurLayoutItem->m_pFirstChild) {
1583 SyncRemoveLayoutItem(pCurLayoutItem, pNotify, pDocLayout); 1579 SyncRemoveLayoutItem(pCurLayoutItem, pNotify, pDocLayout);
1584 } 1580 }
1585 pNotify->OnLayoutItemRemoving(pDocLayout, pCurLayoutItem); 1581 pNotify->OnLayoutItemRemoving(pDocLayout, pCurLayoutItem);
1586 delete pCurLayoutItem; 1582 delete pCurLayoutItem;
1587 pCurLayoutItem = pNextLayoutItem; 1583 pCurLayoutItem = pNextLayoutItem;
1588 continue; 1584 continue;
1589 } 1585 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 return nullptr; 1625 return nullptr;
1630 } else if (pCurNode->GetElementType() == XFA_Element::Overflow) { 1626 } else if (pCurNode->GetElementType() == XFA_Element::Overflow) {
1631 return pCurNode; 1627 return pCurNode;
1632 } 1628 }
1633 } 1629 }
1634 return nullptr; 1630 return nullptr;
1635 } 1631 }
1636 1632
1637 void CXFA_LayoutPageMgr::MergePageSetContents() { 1633 void CXFA_LayoutPageMgr::MergePageSetContents() {
1638 CXFA_Document* pDocument = m_pTemplatePageSetRoot->GetDocument(); 1634 CXFA_Document* pDocument = m_pTemplatePageSetRoot->GetDocument();
1639 CXFA_FFNotify* pNotify = pDocument->GetParser()->GetNotify(); 1635 CXFA_FFNotify* pNotify = pDocument->GetNotify();
1640 CXFA_LayoutProcessor* pDocLayout = pDocument->GetDocLayout(); 1636 CXFA_LayoutProcessor* pDocLayout = pDocument->GetDocLayout();
1641 CXFA_ContainerLayoutItem* pRootLayout = GetRootLayoutItem(); 1637 CXFA_ContainerLayoutItem* pRootLayout = GetRootLayoutItem();
1642 { 1638 {
1643 for (int32_t iIndex = 0; iIndex < pDocument->m_pPendingPageSet.GetSize(); 1639 for (int32_t iIndex = 0; iIndex < pDocument->m_pPendingPageSet.GetSize();
1644 iIndex++) { 1640 iIndex++) {
1645 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> 1641 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode>
1646 sIterator(pDocument->m_pPendingPageSet.GetAt(iIndex)); 1642 sIterator(pDocument->m_pPendingPageSet.GetAt(iIndex));
1647 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; 1643 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode;
1648 pNode = sIterator.MoveToNext()) { 1644 pNode = sIterator.MoveToNext()) {
1649 if (pNode->IsContainerNode()) { 1645 if (pNode->IsContainerNode()) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 default: 1839 default:
1844 break; 1840 break;
1845 } 1841 }
1846 } 1842 }
1847 } 1843 }
1848 } 1844 }
1849 1845
1850 void CXFA_LayoutPageMgr::SyncLayoutData() { 1846 void CXFA_LayoutPageMgr::SyncLayoutData() {
1851 MergePageSetContents(); 1847 MergePageSetContents();
1852 LayoutPageSetContents(); 1848 LayoutPageSetContents();
1853 CXFA_FFNotify* pNotify = 1849 CXFA_FFNotify* pNotify = m_pTemplatePageSetRoot->GetDocument()->GetNotify();
1854 m_pTemplatePageSetRoot->GetDocument()->GetParser()->GetNotify();
1855 int32_t nPageIdx = -1; 1850 int32_t nPageIdx = -1;
1856 CXFA_ContainerLayoutItem* pRootLayoutItem = GetRootLayoutItem(); 1851 CXFA_ContainerLayoutItem* pRootLayoutItem = GetRootLayoutItem();
1857 for (; pRootLayoutItem; 1852 for (; pRootLayoutItem;
1858 pRootLayoutItem = 1853 pRootLayoutItem =
1859 (CXFA_ContainerLayoutItem*)pRootLayoutItem->m_pNextSibling) { 1854 (CXFA_ContainerLayoutItem*)pRootLayoutItem->m_pNextSibling) {
1860 CXFA_NodeIteratorTemplate< 1855 CXFA_NodeIteratorTemplate<
1861 CXFA_ContainerLayoutItem, 1856 CXFA_ContainerLayoutItem,
1862 CXFA_TraverseStrategy_ContentAreaContainerLayoutItem> 1857 CXFA_TraverseStrategy_ContentAreaContainerLayoutItem>
1863 iteratorParent(pRootLayoutItem); 1858 iteratorParent(pRootLayoutItem);
1864 for (CXFA_ContainerLayoutItem* pContainerItem = iteratorParent.GetCurrent(); 1859 for (CXFA_ContainerLayoutItem* pContainerItem = iteratorParent.GetCurrent();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 } 1942 }
1948 pRootLayoutItem = m_pPageSetLayoutItemRoot; 1943 pRootLayoutItem = m_pPageSetLayoutItemRoot;
1949 CXFA_ContainerLayoutItem* pNextLayout = nullptr; 1944 CXFA_ContainerLayoutItem* pNextLayout = nullptr;
1950 for (; pRootLayoutItem; pRootLayoutItem = pNextLayout) { 1945 for (; pRootLayoutItem; pRootLayoutItem = pNextLayout) {
1951 pNextLayout = (CXFA_ContainerLayoutItem*)pRootLayoutItem->m_pNextSibling; 1946 pNextLayout = (CXFA_ContainerLayoutItem*)pRootLayoutItem->m_pNextSibling;
1952 SaveLayoutItem(pRootLayoutItem); 1947 SaveLayoutItem(pRootLayoutItem);
1953 delete pRootLayoutItem; 1948 delete pRootLayoutItem;
1954 } 1949 }
1955 m_pPageSetLayoutItemRoot = nullptr; 1950 m_pPageSetLayoutItemRoot = nullptr;
1956 } 1951 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_layout_itemlayout.cpp ('k') | xfa/fxfa/parser/xfa_locale.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698