Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / xfa / src / fxfa / src / parser / xfa_layout_itemlayout.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _XFA_LAYOUT_ITEMLAYOUT_H_\r
8 #define _XFA_LAYOUT_ITEMLAYOUT_H_\r
9 #define XFA_LAYOUT_INVALIDNODE ((CXFA_Node*)(intptr_t)-1)\r
10 #define XFA_LAYOUT_FLOAT_PERCISION (0.0005f)\r
11 #include "float.h"\r
12 #define XFA_LAYOUT_FLOAT_MAX    FLT_MAX\r
13 class CXFA_ItemLayoutProcessor;\r
14 class CXFA_LayoutPageMgr;\r
15 class CXFA_ContainerLayoutItemImpl;\r
16 class CXFA_ContentLayoutItemImpl;\r
17 enum XFA_ItemLayoutProcessorResult {\r
18     XFA_ItemLayoutProcessorResult_Done,\r
19     XFA_ItemLayoutProcessorResult_PageFullBreak,\r
20     XFA_ItemLayoutProcessorResult_RowFullBreak,\r
21     XFA_ItemLayoutProcessorResult_ManualBreak,\r
22 };\r
23 enum XFA_ItemLayoutProcessorStages {\r
24     XFA_ItemLayoutProcessorStages_None,\r
25     XFA_ItemLayoutProcessorStages_BookendLeader,\r
26     XFA_ItemLayoutProcessorStages_BreakBefore,\r
27     XFA_ItemLayoutProcessorStages_Keep,\r
28     XFA_ItemLayoutProcessorStages_Container,\r
29     XFA_ItemLayoutProcessorStages_BreakAfter,\r
30     XFA_ItemLayoutProcessorStages_BookendTrailer,\r
31     XFA_ItemLayoutProcessorStages_Done,\r
32 };\r
33 \r
34 class CXFA_LayoutContext\r
35 {\r
36 public:\r
37     CXFA_LayoutContext(): m_prgSpecifiedColumnWidths(NULL)\r
38         , m_fCurColumnWidth(0)\r
39         , m_bCurColumnWidthAvaiable(FALSE)\r
40         , m_pOverflowProcessor(NULL)\r
41         , m_pOverflowNode(NULL)\r
42     {\r
43     }\r
44     ~CXFA_LayoutContext()\r
45     {\r
46         m_pOverflowProcessor = NULL;\r
47     }\r
48     CFX_ArrayTemplate<FX_FLOAT>*    m_prgSpecifiedColumnWidths;\r
49     FX_FLOAT                        m_fCurColumnWidth;\r
50     FX_BOOL                         m_bCurColumnWidthAvaiable;\r
51     CXFA_ItemLayoutProcessor*       m_pOverflowProcessor;\r
52     CXFA_Node*                      m_pOverflowNode;\r
53 };\r
54 \r
55 class CXFA_ItemLayoutProcessor\r
56 {\r
57 public:\r
58     CXFA_ItemLayoutProcessor(CXFA_Node *pNode, CXFA_LayoutPageMgr* pPageMgr);\r
59 \r
60     XFA_ItemLayoutProcessorResult   DoLayout(FX_BOOL bUseBreakControl, \r
61                                              FX_FLOAT fHeightLimit,\r
62                                              FX_FLOAT fRealHeight = XFA_LAYOUT_FLOAT_MAX,\r
63                                              CXFA_LayoutContext* pContext = NULL);\r
64 \r
65     void                            GetCurrentComponentPos(FX_FLOAT& fAbsoluteX,\r
66                                                            FX_FLOAT& fAbsoluteY);\r
67 \r
68     void                            GetCurrentComponentSize(FX_FLOAT& fWidth, \r
69                                                             FX_FLOAT& fHeight);\r
70 \r
71     void                            SetCurrentComponentPos(FX_FLOAT fAbsoluteX,\r
72                                                            FX_FLOAT fAbsoluteY);\r
73 \r
74     void                            SetCurrentComponentSize(FX_FLOAT fWidth,\r
75                                                             FX_FLOAT fHeight);\r
76     inline CXFA_Node*               GetFormNode()\r
77     {\r
78         return m_pFormNode;\r
79     }\r
80     inline FX_BOOL                  HasLayoutItem()\r
81     {\r
82         return m_pLayoutItem != NULL;\r
83     }\r
84     CXFA_ContentLayoutItemImpl*     ExtractLayoutItem();\r
85 \r
86     static FX_BOOL      IncrementRelayoutNode(CXFA_LayoutProcessor* pLayoutProcessor, \r
87                                               CXFA_Node *pNode, CXFA_Node *pParentNode);\r
88     static void         CalculatePositionedContainerPos(CXFA_Node* pNode, FX_FLOAT fWidth,\r
89                                                         FX_FLOAT fHeight, FX_FLOAT& fAbsoluteX,\r
90                                                         FX_FLOAT& fAbsoluteY);\r
91     static FX_BOOL      FindLayoutItemSplitPos(CXFA_ContentLayoutItemImpl* pLayoutItem,\r
92                                                FX_FLOAT fCurVerticalOffset, FX_FLOAT& fProposedSplitPos,\r
93                                                FX_BOOL& bAppChange, FX_BOOL bCalculateMargin = TRUE);\r
94     FX_FLOAT            FindSplitPos(FX_FLOAT fProposedSplitPos);\r
95     void                SplitLayoutItem(CXFA_ContentLayoutItemImpl* pLayoutItem,\r
96                                         CXFA_ContentLayoutItemImpl* pSecondParent,\r
97                                         FX_FLOAT fSplitPos);\r
98     void                SplitLayoutItem(FX_FLOAT fSplitPos);\r
99     FX_BOOL             JudgePutNextPage(CXFA_ContentLayoutItemImpl* pParentLayoutItem,\r
100                                          FX_FLOAT fChildHeight, \r
101                                          CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*> &pKeepItems);\r
102     FX_BOOL             ProcessKeepForSplite(CXFA_ItemLayoutProcessor* pParentProcessor,\r
103                                              CXFA_ItemLayoutProcessor* pChildProcessor,\r
104                                              XFA_ItemLayoutProcessorResult eRetValue,\r
105                                              CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*>& rgCurLineLayoutItem,\r
106                                              FX_FLOAT& fContentCurRowAvailWidth,\r
107                                              FX_FLOAT& fContentCurRowHeight,\r
108                                              FX_FLOAT& fContentCurRowY,\r
109                                              FX_BOOL& bAddedItemInRow,\r
110                                              FX_BOOL& bForceEndPage,\r
111                                              XFA_ItemLayoutProcessorResult& result);\r
112     FX_FLOAT            InsertKeepLayoutItems();\r
113     void                DoLayoutPageArea(CXFA_ContainerLayoutItemImpl* pPageAreaLayoutItem);\r
114     FX_BOOL             CalculateRowChildPosition(CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*>(&rgCurLineLayoutItems)[3],\r
115                                                   XFA_ATTRIBUTEENUM eFlowStrategy,\r
116                                                   FX_BOOL bContainerHeightAutoSize,\r
117                                                   FX_BOOL bContainerWidthAutoSize,\r
118                                                   FX_FLOAT& fContentCalculatedWidth,\r
119                                                   FX_FLOAT& fContentCalculatedHeight,\r
120                                                   FX_FLOAT& fContentCurRowY,\r
121                                                   FX_FLOAT fContentCurRowHeight,\r
122                                                   FX_FLOAT fContentWidthLimit,\r
123                                                   FX_BOOL bRootForceTb = FALSE);\r
124 \r
125     void                ProcessUnUseOverFlow(CXFA_Node* pLeaderNode,\r
126                                              CXFA_Node* pTrailerNode,\r
127                                              CXFA_ContentLayoutItemImpl* pTrailerItem,\r
128                                              CXFA_Node* pFormNode);\r
129     void                ProcessUnUseBinds(CXFA_Node* pFormNode);\r
130     FX_BOOL             IsAddNewRowForTrailer(CXFA_ContentLayoutItemImpl* pTrailerItem);\r
131     FX_BOOL             JudgeLeaderOrTrailerForOccur(CXFA_Node* pFormNode);\r
132     CXFA_ContentLayoutItemImpl* CreateContentLayoutItem(CXFA_Node* pFormNode);\r
133 protected:\r
134 \r
135     void        DoLayoutPositionedContainer(CXFA_LayoutContext* pContext = NULL);\r
136     void        DoLayoutTableContainer(CXFA_Node* pLayoutNode);\r
137     XFA_ItemLayoutProcessorResult DoLayoutFlowedContainer(FX_BOOL bUseBreakControl,\r
138                                                           XFA_ATTRIBUTEENUM eFlowStrategy,\r
139                                                           FX_FLOAT fHeightLimit,\r
140                                                           FX_FLOAT fRealHeight,\r
141                                                           CXFA_LayoutContext* pContext = NULL,\r
142                                                           FX_BOOL bRootForceTb = FALSE);\r
143     void        DoLayoutField();\r
144     void        XFA_ItemLayoutProcessor_GotoNextContainerNode(CXFA_Node*& pCurActionNode,\r
145                                                               XFA_ItemLayoutProcessorStages& nCurStage,\r
146                                                               CXFA_Node* pParentContainer,\r
147                                                               FX_BOOL bUsePageBreak);\r
148 \r
149     FX_BOOL     ProcessKeepNodesForCheckNext(CXFA_Node*& pCurActionNode,\r
150                                              XFA_ItemLayoutProcessorStages& nCurStage,\r
151                                              CXFA_Node*& pNextContainer,\r
152                                              FX_BOOL& bLastKeepNode);\r
153 \r
154     FX_BOOL     ProcessKeepNodesForBreakBefore(CXFA_Node*& pCurActionNode,\r
155                                                XFA_ItemLayoutProcessorStages& nCurStage,\r
156                                                CXFA_Node* pContainerNode);\r
157 \r
158     CXFA_Node*  GetSubformSetParent(CXFA_Node* pSubformSet);\r
159 \r
160 public:\r
161     FX_BOOL                                         m_bKeepBreakFinish;\r
162     FX_BOOL                                         m_bIsProcessKeep;\r
163     CXFA_Node*                                      m_pKeepHeadNode;\r
164     CXFA_Node*                                      m_pKeepTailNode;\r
165     CXFA_Node*                                      m_pFormNode;\r
166     CXFA_ContentLayoutItemImpl*                     m_pLayoutItem;\r
167 #ifdef _XFA_LAYOUTITEM_ProcessCACHE_\r
168     CXFA_ContentLayoutItemImpl*                     m_pOldLayoutItem;\r
169 #else\r
170     CXFA_LayoutPageMgr*                             m_pPageMgrCreateItem;\r
171 #endif\r
172     CXFA_Node*                                      m_pCurChildNode;\r
173     CXFA_ItemLayoutProcessor*                       m_pCurChildPreprocessor;\r
174     XFA_ItemLayoutProcessorStages                   m_nCurChildNodeStage;\r
175     FX_FLOAT                                        m_fUsedSize;\r
176     CXFA_LayoutPageMgr*                             m_pPageMgr;\r
177     CFX_PtrList                                     m_rgPendingNodes;\r
178     FX_BOOL                                         m_bBreakPending;\r
179     CFX_ArrayTemplate<FX_FLOAT>                     m_rgSpecifiedColumnWidths;\r
180     CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*>  m_arrayKeepItems;\r
181     CFX_MapPtrToPtr                                 m_PendingNodesCount;\r
182     FX_FLOAT                                        m_fLastRowWidth;\r
183     FX_FLOAT                                        m_fLastRowY;\r
184     FX_FLOAT                                        m_fWidthLimite;\r
185     FX_BOOL                                         m_bUseInheriated;\r
186     XFA_ItemLayoutProcessorResult                   m_ePreProcessRs;\r
187     FX_BOOL                                         m_bHasAvailHeight;\r
188 };\r
189 FX_BOOL XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode);\r
190 #endif\r