• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef XFA_FXFA_PARSER_CXFA_ITEMLAYOUTPROCESSOR_H_
8 #define XFA_FXFA_PARSER_CXFA_ITEMLAYOUTPROCESSOR_H_
9 
10 #include <float.h>
11 
12 #include <list>
13 #include <map>
14 #include <tuple>
15 #include <vector>
16 
17 #include "core/fxcrt/fx_coordinates.h"
18 #include "xfa/fxfa/fxfa_basic.h"
19 
20 #define XFA_LAYOUT_INVALIDNODE ((CXFA_Node*)(intptr_t)-1)
21 #define XFA_LAYOUT_FLOAT_PERCISION (0.0005f)
22 
23 class CXFA_ContainerLayoutItem;
24 class CXFA_ContentLayoutItem;
25 class CXFA_ItemLayoutProcessor;
26 class CXFA_LayoutContext;
27 class CXFA_LayoutPageMgr;
28 class CXFA_LayoutProcessor;
29 class CXFA_Node;
30 
31 enum class XFA_ItemLayoutProcessorResult {
32   Done,
33   PageFullBreak,
34   RowFullBreak,
35   ManualBreak,
36 };
37 
38 enum class XFA_ItemLayoutProcessorStages {
39   None,
40   BookendLeader,
41   BreakBefore,
42   Keep,
43   Container,
44   BreakAfter,
45   BookendTrailer,
46   Done,
47 };
48 
49 bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode);
50 
51 class CXFA_ItemLayoutProcessor {
52  public:
53   static bool IncrementRelayoutNode(CXFA_LayoutProcessor* pLayoutProcessor,
54                                     CXFA_Node* pNode,
55                                     CXFA_Node* pParentNode);
56 
57   CXFA_ItemLayoutProcessor(CXFA_Node* pNode, CXFA_LayoutPageMgr* pPageMgr);
58   ~CXFA_ItemLayoutProcessor();
59 
60   XFA_ItemLayoutProcessorResult DoLayout(bool bUseBreakControl,
61                                          float fHeightLimit,
62                                          float fRealHeight,
63                                          CXFA_LayoutContext* pContext);
64   void DoLayoutPageArea(CXFA_ContainerLayoutItem* pPageAreaLayoutItem);
65 
66   CFX_SizeF GetCurrentComponentSize();
GetFormNode()67   CXFA_Node* GetFormNode() { return m_pFormNode; }
HasLayoutItem()68   bool HasLayoutItem() const { return !!m_pLayoutItem; }
69   CXFA_ContentLayoutItem* ExtractLayoutItem();
70   void SplitLayoutItem(float fSplitPos);
71 
72   float FindSplitPos(float fProposedSplitPos);
73 
74   bool ProcessKeepForSplit(
75       CXFA_ItemLayoutProcessor* pParentProcessor,
76       CXFA_ItemLayoutProcessor* pChildProcessor,
77       XFA_ItemLayoutProcessorResult eRetValue,
78       std::vector<CXFA_ContentLayoutItem*>* rgCurLineLayoutItem,
79       float* fContentCurRowAvailWidth,
80       float* fContentCurRowHeight,
81       float* fContentCurRowY,
82       bool* bAddedItemInRow,
83       bool* bForceEndPage,
84       XFA_ItemLayoutProcessorResult* result);
85   void ProcessUnUseOverFlow(CXFA_Node* pLeaderNode,
86                             CXFA_Node* pTrailerNode,
87                             CXFA_ContentLayoutItem* pTrailerItem,
88                             CXFA_Node* pFormNode);
89   bool IsAddNewRowForTrailer(CXFA_ContentLayoutItem* pTrailerItem);
90   bool JudgeLeaderOrTrailerForOccur(CXFA_Node* pFormNode);
91 
92   CXFA_ContentLayoutItem* CreateContentLayoutItem(CXFA_Node* pFormNode);
93 
94   CXFA_Node* m_pFormNode;
95   CXFA_ContentLayoutItem* m_pLayoutItem;
96   CXFA_Node* m_pCurChildNode;
97   float m_fUsedSize;
98   CXFA_LayoutPageMgr* m_pPageMgr;
99   std::list<CXFA_Node*> m_PendingNodes;
100   bool m_bBreakPending;
101   std::vector<float> m_rgSpecifiedColumnWidths;
102   std::vector<CXFA_ContentLayoutItem*> m_arrayKeepItems;
103   float m_fLastRowWidth;
104   float m_fLastRowY;
105   bool m_bUseInheriated;
106   XFA_ItemLayoutProcessorResult m_ePreProcessRs;
107 
108  private:
109   void SetCurrentComponentPos(const CFX_PointF& pos);
110   void SetCurrentComponentSize(const CFX_SizeF& size);
111 
112   void SplitLayoutItem(CXFA_ContentLayoutItem* pLayoutItem,
113                        CXFA_ContentLayoutItem* pSecondParent,
114                        float fSplitPos);
115   float InsertKeepLayoutItems();
116   bool CalculateRowChildPosition(
117       std::vector<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3],
118       XFA_AttributeEnum eFlowStrategy,
119       bool bContainerHeightAutoSize,
120       bool bContainerWidthAutoSize,
121       float* fContentCalculatedWidth,
122       float* fContentCalculatedHeight,
123       float* fContentCurRowY,
124       float fContentCurRowHeight,
125       float fContentWidthLimit,
126       bool bRootForceTb);
127   void ProcessUnUseBinds(CXFA_Node* pFormNode);
128   bool JudgePutNextPage(CXFA_ContentLayoutItem* pParentLayoutItem,
129                         float fChildHeight,
130                         std::vector<CXFA_ContentLayoutItem*>* pKeepItems);
131 
132   void DoLayoutPositionedContainer(CXFA_LayoutContext* pContext);
133   void DoLayoutTableContainer(CXFA_Node* pLayoutNode);
134   XFA_ItemLayoutProcessorResult DoLayoutFlowedContainer(
135       bool bUseBreakControl,
136       XFA_AttributeEnum eFlowStrategy,
137       float fHeightLimit,
138       float fRealHeight,
139       CXFA_LayoutContext* pContext,
140       bool bRootForceTb);
141   void DoLayoutField();
142 
143   void GotoNextContainerNode(CXFA_Node*& pCurActionNode,
144                              XFA_ItemLayoutProcessorStages& nCurStage,
145                              CXFA_Node* pParentContainer,
146                              bool bUsePageBreak);
147 
148   bool ProcessKeepNodesForCheckNext(CXFA_Node*& pCurActionNode,
149                                     XFA_ItemLayoutProcessorStages& nCurStage,
150                                     CXFA_Node*& pNextContainer,
151                                     bool& bLastKeepNode);
152 
153   bool ProcessKeepNodesForBreakBefore(CXFA_Node*& pCurActionNode,
154                                       XFA_ItemLayoutProcessorStages& nCurStage,
155                                       CXFA_Node* pContainerNode);
156 
157   CXFA_Node* GetSubformSetParent(CXFA_Node* pSubformSet);
158 
159   bool m_bKeepBreakFinish;
160   bool m_bIsProcessKeep;
161   CXFA_Node* m_pKeepHeadNode;
162   CXFA_Node* m_pKeepTailNode;
163   CXFA_ContentLayoutItem* m_pOldLayoutItem;
164   CXFA_ItemLayoutProcessor* m_pCurChildPreprocessor;
165   XFA_ItemLayoutProcessorStages m_nCurChildNodeStage;
166   std::map<CXFA_Node*, int32_t> m_PendingNodesCount;
167   float m_fWidthLimite;
168   bool m_bHasAvailHeight;
169 };
170 
171 #endif  // XFA_FXFA_PARSER_CXFA_ITEMLAYOUTPROCESSOR_H_
172