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 "xfa/fxfa/parser/xfa_layout_itemlayout.h" | 7 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "xfa/fxfa/app/xfa_ffnotify.h" | 12 #include "xfa/fxfa/app/xfa_ffnotify.h" |
13 #include "xfa/fxfa/parser/cxfa_occur.h" | 13 #include "xfa/fxfa/parser/cxfa_occur.h" |
14 #include "xfa/fxfa/parser/xfa_doclayout.h" | 14 #include "xfa/fxfa/parser/xfa_doclayout.h" |
15 #include "xfa/fxfa/parser/xfa_document.h" | 15 #include "xfa/fxfa/parser/xfa_document.h" |
16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" | 16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" |
17 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" | 17 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" |
18 #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" | 18 #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" |
19 #include "xfa/fxfa/parser/xfa_localemgr.h" | 19 #include "xfa/fxfa/parser/xfa_localemgr.h" |
20 #include "xfa/fxfa/parser/xfa_object.h" | 20 #include "xfa/fxfa/parser/xfa_object.h" |
21 #include "xfa/fxfa/parser/xfa_parser.h" | |
22 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 21 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
23 #include "xfa/fxfa/parser/xfa_script.h" | 22 #include "xfa/fxfa/parser/xfa_script.h" |
24 #include "xfa/fxfa/parser/xfa_utils.h" | 23 #include "xfa/fxfa/parser/xfa_utils.h" |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 int32_t SeparateStringW(const FX_WCHAR* pStr, | 27 int32_t SeparateStringW(const FX_WCHAR* pStr, |
29 int32_t iStrLen, | 28 int32_t iStrLen, |
30 FX_WCHAR delimiter, | 29 FX_WCHAR delimiter, |
31 CFX_WideStringArray& pieces) { | 30 CFX_WideStringArray& pieces) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (!pFormNode) { | 84 if (!pFormNode) { |
86 return nullptr; | 85 return nullptr; |
87 } | 86 } |
88 CXFA_ContentLayoutItem* pLayoutItem = nullptr; | 87 CXFA_ContentLayoutItem* pLayoutItem = nullptr; |
89 if (m_pOldLayoutItem) { | 88 if (m_pOldLayoutItem) { |
90 pLayoutItem = m_pOldLayoutItem; | 89 pLayoutItem = m_pOldLayoutItem; |
91 m_pOldLayoutItem = m_pOldLayoutItem->m_pNext; | 90 m_pOldLayoutItem = m_pOldLayoutItem->m_pNext; |
92 return pLayoutItem; | 91 return pLayoutItem; |
93 } | 92 } |
94 pLayoutItem = (CXFA_ContentLayoutItem*)pFormNode->GetDocument() | 93 pLayoutItem = (CXFA_ContentLayoutItem*)pFormNode->GetDocument() |
95 ->GetParser() | |
96 ->GetNotify() | 94 ->GetNotify() |
97 ->OnCreateLayoutItem(pFormNode); | 95 ->OnCreateLayoutItem(pFormNode); |
98 CXFA_ContentLayoutItem* pPrevLayoutItem = | 96 CXFA_ContentLayoutItem* pPrevLayoutItem = |
99 (CXFA_ContentLayoutItem*)pFormNode->GetUserData(XFA_LAYOUTITEMKEY); | 97 (CXFA_ContentLayoutItem*)pFormNode->GetUserData(XFA_LAYOUTITEMKEY); |
100 if (pPrevLayoutItem) { | 98 if (pPrevLayoutItem) { |
101 while (pPrevLayoutItem->m_pNext) { | 99 while (pPrevLayoutItem->m_pNext) { |
102 pPrevLayoutItem = pPrevLayoutItem->m_pNext; | 100 pPrevLayoutItem = pPrevLayoutItem->m_pNext; |
103 } | 101 } |
104 pPrevLayoutItem->m_pNext = pLayoutItem; | 102 pPrevLayoutItem->m_pNext = pLayoutItem; |
105 pLayoutItem->m_pPrev = pPrevLayoutItem; | 103 pLayoutItem->m_pPrev = pPrevLayoutItem; |
106 } else { | 104 } else { |
107 pFormNode->SetUserData(XFA_LAYOUTITEMKEY, pLayoutItem); | 105 pFormNode->SetUserData(XFA_LAYOUTITEMKEY, pLayoutItem); |
108 } | 106 } |
109 return pLayoutItem; | 107 return pLayoutItem; |
110 } | 108 } |
111 FX_BOOL CXFA_ItemLayoutProcessor::FindLayoutItemSplitPos( | 109 FX_BOOL CXFA_ItemLayoutProcessor::FindLayoutItemSplitPos( |
112 CXFA_ContentLayoutItem* pLayoutItem, | 110 CXFA_ContentLayoutItem* pLayoutItem, |
113 FX_FLOAT fCurVerticalOffset, | 111 FX_FLOAT fCurVerticalOffset, |
114 FX_FLOAT& fProposedSplitPos, | 112 FX_FLOAT& fProposedSplitPos, |
115 FX_BOOL& bAppChange, | 113 FX_BOOL& bAppChange, |
116 FX_BOOL bCalculateMargin) { | 114 FX_BOOL bCalculateMargin) { |
117 CXFA_Node* pFormNode = pLayoutItem->m_pFormNode; | 115 CXFA_Node* pFormNode = pLayoutItem->m_pFormNode; |
118 if (fProposedSplitPos > fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION && | 116 if (fProposedSplitPos > fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION && |
119 fProposedSplitPos <= fCurVerticalOffset + pLayoutItem->m_sSize.y - | 117 fProposedSplitPos <= fCurVerticalOffset + pLayoutItem->m_sSize.y - |
120 XFA_LAYOUT_FLOAT_PERCISION) { | 118 XFA_LAYOUT_FLOAT_PERCISION) { |
121 switch (pFormNode->GetIntact()) { | 119 switch (pFormNode->GetIntact()) { |
122 case XFA_ATTRIBUTEENUM_None: { | 120 case XFA_ATTRIBUTEENUM_None: { |
123 FX_BOOL bAnyChanged = FALSE; | 121 FX_BOOL bAnyChanged = FALSE; |
124 CXFA_Document* pDocument = pFormNode->GetDocument(); | 122 CXFA_Document* pDocument = pFormNode->GetDocument(); |
125 CXFA_FFNotify* pNotify = pDocument->GetParser()->GetNotify(); | 123 CXFA_FFNotify* pNotify = pDocument->GetNotify(); |
126 FX_FLOAT fCurTopMargin = 0, fCurBottomMargin = 0; | 124 FX_FLOAT fCurTopMargin = 0, fCurBottomMargin = 0; |
127 CXFA_Node* pMarginNode = | 125 CXFA_Node* pMarginNode = |
128 pFormNode->GetFirstChildByClass(XFA_Element::Margin); | 126 pFormNode->GetFirstChildByClass(XFA_Element::Margin); |
129 if (pMarginNode && bCalculateMargin) { | 127 if (pMarginNode && bCalculateMargin) { |
130 fCurTopMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_TopInset) | 128 fCurTopMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_TopInset) |
131 .ToUnit(XFA_UNIT_Pt); | 129 .ToUnit(XFA_UNIT_Pt); |
132 fCurBottomMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset) | 130 fCurBottomMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset) |
133 .ToUnit(XFA_UNIT_Pt); | 131 .ToUnit(XFA_UNIT_Pt); |
134 } | 132 } |
135 FX_BOOL bChanged = TRUE; | 133 FX_BOOL bChanged = TRUE; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 m_pLayoutItem = | 576 m_pLayoutItem = |
579 static_cast<CXFA_ContentLayoutItem*>(pLayoutItem->m_pNextSibling); | 577 static_cast<CXFA_ContentLayoutItem*>(pLayoutItem->m_pNextSibling); |
580 pLayoutItem->m_pNextSibling = nullptr; | 578 pLayoutItem->m_pNextSibling = nullptr; |
581 } | 579 } |
582 if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Done || | 580 if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Done || |
583 !ToContentLayoutItem(m_pOldLayoutItem)) | 581 !ToContentLayoutItem(m_pOldLayoutItem)) |
584 return pLayoutItem; | 582 return pLayoutItem; |
585 if (m_pOldLayoutItem->m_pPrev) | 583 if (m_pOldLayoutItem->m_pPrev) |
586 m_pOldLayoutItem->m_pPrev->m_pNext = nullptr; | 584 m_pOldLayoutItem->m_pPrev->m_pNext = nullptr; |
587 CXFA_FFNotify* pNotify = | 585 CXFA_FFNotify* pNotify = |
588 m_pOldLayoutItem->m_pFormNode->GetDocument()->GetParser()->GetNotify(); | 586 m_pOldLayoutItem->m_pFormNode->GetDocument()->GetNotify(); |
589 CXFA_LayoutProcessor* pDocLayout = | 587 CXFA_LayoutProcessor* pDocLayout = |
590 m_pOldLayoutItem->m_pFormNode->GetDocument()->GetDocLayout(); | 588 m_pOldLayoutItem->m_pFormNode->GetDocument()->GetDocLayout(); |
591 CXFA_ContentLayoutItem* pOldLayoutItem = m_pOldLayoutItem; | 589 CXFA_ContentLayoutItem* pOldLayoutItem = m_pOldLayoutItem; |
592 while (pOldLayoutItem) { | 590 while (pOldLayoutItem) { |
593 CXFA_ContentLayoutItem* pNextOldLayoutItem = pOldLayoutItem->m_pNext; | 591 CXFA_ContentLayoutItem* pNextOldLayoutItem = pOldLayoutItem->m_pNext; |
594 pNotify->OnLayoutItemRemoving(pDocLayout, pOldLayoutItem); | 592 pNotify->OnLayoutItemRemoving(pDocLayout, pOldLayoutItem); |
595 if (pOldLayoutItem->m_pParent) | 593 if (pOldLayoutItem->m_pParent) |
596 pOldLayoutItem->m_pParent->RemoveChild(pOldLayoutItem); | 594 pOldLayoutItem->m_pParent->RemoveChild(pOldLayoutItem); |
597 delete pOldLayoutItem; | 595 delete pOldLayoutItem; |
598 pOldLayoutItem = pNextOldLayoutItem; | 596 pOldLayoutItem = pNextOldLayoutItem; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 default: | 638 default: |
641 break; | 639 break; |
642 } | 640 } |
643 if (bFindRs) { | 641 if (bFindRs) { |
644 break; | 642 break; |
645 } | 643 } |
646 } | 644 } |
647 return bFindRs; | 645 return bFindRs; |
648 } | 646 } |
649 static void XFA_DeleteLayoutGeneratedNode(CXFA_Node* pGenerateNode) { | 647 static void XFA_DeleteLayoutGeneratedNode(CXFA_Node* pGenerateNode) { |
650 CXFA_FFNotify* pNotify = | 648 CXFA_FFNotify* pNotify = pGenerateNode->GetDocument()->GetNotify(); |
651 pGenerateNode->GetDocument()->GetParser()->GetNotify(); | |
652 CXFA_LayoutProcessor* pDocLayout = | 649 CXFA_LayoutProcessor* pDocLayout = |
653 pGenerateNode->GetDocument()->GetDocLayout(); | 650 pGenerateNode->GetDocument()->GetDocLayout(); |
654 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> sIterator( | 651 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> sIterator( |
655 pGenerateNode); | 652 pGenerateNode); |
656 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 653 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
657 pNode = sIterator.MoveToNext()) { | 654 pNode = sIterator.MoveToNext()) { |
658 CXFA_ContentLayoutItem* pCurLayoutItem = | 655 CXFA_ContentLayoutItem* pCurLayoutItem = |
659 (CXFA_ContentLayoutItem*)pNode->GetUserData(XFA_LAYOUTITEMKEY); | 656 (CXFA_ContentLayoutItem*)pNode->GetUserData(XFA_LAYOUTITEMKEY); |
660 CXFA_ContentLayoutItem* pNextLayoutItem = nullptr; | 657 CXFA_ContentLayoutItem* pNextLayoutItem = nullptr; |
661 while (pCurLayoutItem) { | 658 while (pCurLayoutItem) { |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 if (fWidth < -XFA_LAYOUT_FLOAT_PERCISION) { | 1223 if (fWidth < -XFA_LAYOUT_FLOAT_PERCISION) { |
1227 fWidth = pLayoutItem->m_sSize.x; | 1224 fWidth = pLayoutItem->m_sSize.x; |
1228 } | 1225 } |
1229 if (fHeight < -XFA_LAYOUT_FLOAT_PERCISION) { | 1226 if (fHeight < -XFA_LAYOUT_FLOAT_PERCISION) { |
1230 fHeight = pLayoutItem->m_sSize.y; | 1227 fHeight = pLayoutItem->m_sSize.y; |
1231 } | 1228 } |
1232 break; | 1229 break; |
1233 } | 1230 } |
1234 case XFA_Element::Draw: | 1231 case XFA_Element::Draw: |
1235 case XFA_Element::Field: { | 1232 case XFA_Element::Field: { |
1236 pNode->GetDocument()->GetParser()->GetNotify()->StartFieldDrawLayout( | 1233 pNode->GetDocument()->GetNotify()->StartFieldDrawLayout(pNode, fWidth, |
1237 pNode, fWidth, fHeight); | 1234 fHeight); |
1238 break; | 1235 break; |
1239 } | 1236 } |
1240 default: | 1237 default: |
1241 ASSERT(FALSE); | 1238 ASSERT(FALSE); |
1242 } | 1239 } |
1243 } | 1240 } |
1244 static inline void XFA_ItemLayoutProcessor_RelocateTableRowCells( | 1241 static inline void XFA_ItemLayoutProcessor_RelocateTableRowCells( |
1245 CXFA_ContentLayoutItem* pLayoutRow, | 1242 CXFA_ContentLayoutItem* pLayoutRow, |
1246 const CFX_ArrayTemplate<FX_FLOAT>& rgSpecifiedColumnWidths, | 1243 const CFX_ArrayTemplate<FX_FLOAT>& rgSpecifiedColumnWidths, |
1247 XFA_ATTRIBUTEENUM eLayout) { | 1244 XFA_ATTRIBUTEENUM eLayout) { |
(...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2889 void CXFA_ItemLayoutProcessor::DoLayoutField() { | 2886 void CXFA_ItemLayoutProcessor::DoLayoutField() { |
2890 if (m_pLayoutItem) | 2887 if (m_pLayoutItem) |
2891 return; | 2888 return; |
2892 | 2889 |
2893 ASSERT(m_pCurChildNode == XFA_LAYOUT_INVALIDNODE); | 2890 ASSERT(m_pCurChildNode == XFA_LAYOUT_INVALIDNODE); |
2894 m_pLayoutItem = CreateContentLayoutItem(m_pFormNode); | 2891 m_pLayoutItem = CreateContentLayoutItem(m_pFormNode); |
2895 if (!m_pLayoutItem) { | 2892 if (!m_pLayoutItem) { |
2896 return; | 2893 return; |
2897 } | 2894 } |
2898 CXFA_Document* pDocument = m_pFormNode->GetDocument(); | 2895 CXFA_Document* pDocument = m_pFormNode->GetDocument(); |
2899 CXFA_FFNotify* pNotify = pDocument->GetParser()->GetNotify(); | 2896 CXFA_FFNotify* pNotify = pDocument->GetNotify(); |
2900 FX_FLOAT fHeight = -1; | 2897 FX_FLOAT fHeight = -1; |
2901 FX_FLOAT fWidth = -1; | 2898 FX_FLOAT fWidth = -1; |
2902 pNotify->StartFieldDrawLayout(m_pFormNode, fWidth, fHeight); | 2899 pNotify->StartFieldDrawLayout(m_pFormNode, fWidth, fHeight); |
2903 int32_t nRotate = | 2900 int32_t nRotate = |
2904 FXSYS_round(m_pFormNode->GetMeasure(XFA_ATTRIBUTE_Rotate).GetValue()); | 2901 FXSYS_round(m_pFormNode->GetMeasure(XFA_ATTRIBUTE_Rotate).GetValue()); |
2905 nRotate = XFA_MapRotation(nRotate); | 2902 nRotate = XFA_MapRotation(nRotate); |
2906 if (nRotate == 90 || nRotate == 270) { | 2903 if (nRotate == 90 || nRotate == 270) { |
2907 FX_FLOAT fTmp = fWidth; | 2904 FX_FLOAT fTmp = fWidth; |
2908 fWidth = fHeight; | 2905 fWidth = fHeight; |
2909 fHeight = fTmp; | 2906 fHeight = fTmp; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2990 if (iMax < 0) | 2987 if (iMax < 0) |
2991 return TRUE; | 2988 return TRUE; |
2992 | 2989 |
2993 int32_t iCount = m_PendingNodesCount[pTemplate]; | 2990 int32_t iCount = m_PendingNodesCount[pTemplate]; |
2994 if (iCount >= iMax) | 2991 if (iCount >= iMax) |
2995 return FALSE; | 2992 return FALSE; |
2996 | 2993 |
2997 m_PendingNodesCount[pTemplate] = iCount + 1; | 2994 m_PendingNodesCount[pTemplate] = iCount + 1; |
2998 return TRUE; | 2995 return TRUE; |
2999 } | 2996 } |
OLD | NEW |