Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[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*)(FX_INTPTR)-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 class CXFA_LayoutContext : public CFX_Object\r
34 {\r
35 public:\r
36     CXFA_LayoutContext(): m_prgSpecifiedColumnWidths(NULL)\r
37         , m_fCurColumnWidth(0)\r
38         , m_bCurColumnWidthAvaiable(FALSE)\r
39         , m_pOverflowProcessor(NULL)\r
40         , m_pOverflowNode(NULL)\r
41     {\r
42     }\r
43     ~CXFA_LayoutContext()\r
44     {\r
45         m_pOverflowProcessor = NULL;\r
46     }\r
47     CFX_ArrayTemplate<FX_FLOAT>*        m_prgSpecifiedColumnWidths;\r
48     FX_FLOAT                                            m_fCurColumnWidth;\r
49     FX_BOOL                                                     m_bCurColumnWidthAvaiable;\r
50     CXFA_ItemLayoutProcessor*           m_pOverflowProcessor;\r
51     CXFA_Node*                                          m_pOverflowNode;\r
52 };\r
53 class CXFA_ItemLayoutProcessor : public CFX_Object\r
54 {\r
55 public:\r
56     CXFA_ItemLayoutProcessor(CXFA_Node *pNode, CXFA_LayoutPageMgr* pPageMgr);\r
57     XFA_ItemLayoutProcessorResult DoLayout(FX_BOOL bUseBreakControl, FX_FLOAT fHeightLimit, FX_FLOAT fRealHeight = XFA_LAYOUT_FLOAT_MAX, CXFA_LayoutContext* pContext = NULL);\r
58     void GetCurrentComponentPos(FX_FLOAT& fAbsoluteX, FX_FLOAT& fAbsoluteY);\r
59     void GetCurrentComponentSize(FX_FLOAT& fWidth, FX_FLOAT& fHeight);\r
60     void SetCurrentComponentPos(FX_FLOAT fAbsoluteX, FX_FLOAT fAbsoluteY);\r
61     void SetCurrentComponentSize(FX_FLOAT fWidth, FX_FLOAT fHeight);\r
62     inline CXFA_Node*                   GetFormNode()\r
63     {\r
64         return m_pFormNode;\r
65     }\r
66     inline FX_BOOL                              HasLayoutItem()\r
67     {\r
68         return m_pLayoutItem != NULL;\r
69     }\r
70     CXFA_ContentLayoutItemImpl* ExtractLayoutItem();\r
71 \r
72     static FX_BOOL  IncrementRelayoutNode(CXFA_LayoutProcessor* pLayoutProcessor, CXFA_Node *pNode, CXFA_Node *pParentNode);\r
73     static void         CalculatePositionedContainerPos(CXFA_Node* pNode, FX_FLOAT fWidth, FX_FLOAT fHeight, FX_FLOAT& fAbsoluteX, FX_FLOAT& fAbsoluteY);\r
74     static FX_BOOL      FindLayoutItemSplitPos(CXFA_ContentLayoutItemImpl* pLayoutItem, FX_FLOAT fCurVerticalOffset, FX_FLOAT& fProposedSplitPos, FX_BOOL& bAppChange, FX_BOOL bCalculateMargin = TRUE);\r
75     FX_FLOAT            FindSplitPos(FX_FLOAT fProposedSplitPos);\r
76     void                        SplitLayoutItem(CXFA_ContentLayoutItemImpl* pLayoutItem, CXFA_ContentLayoutItemImpl* pSecondParent, FX_FLOAT fSplitPos);\r
77     void                        SplitLayoutItem(FX_FLOAT fSplitPos);\r
78     FX_BOOL                     JudgePutNextPage(CXFA_ContentLayoutItemImpl* pParentLayoutItem, FX_FLOAT fChildHeight, CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*> &pKeepItems);\r
79     FX_BOOL                     ProcessKeepForSplite(CXFA_ItemLayoutProcessor* pParentProcessor, CXFA_ItemLayoutProcessor* pChildProcessor, XFA_ItemLayoutProcessorResult eRetValue,\r
80                                          CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*>& rgCurLineLayoutItem, FX_FLOAT& fContentCurRowAvailWidth,\r
81                                          FX_FLOAT& fContentCurRowHeight, FX_FLOAT& fContentCurRowY, FX_BOOL& bAddedItemInRow, FX_BOOL& bForceEndPage, XFA_ItemLayoutProcessorResult& result);\r
82     FX_FLOAT            InsertKeepLayoutItems();\r
83     void                        DoLayoutPageArea(CXFA_ContainerLayoutItemImpl* pPageAreaLayoutItem);\r
84     FX_BOOL                     CalculateRowChildPosition(CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*>(&rgCurLineLayoutItems)[3], XFA_ATTRIBUTEENUM eFlowStrategy, FX_BOOL bContainerHeightAutoSize,\r
85             FX_BOOL bContainerWidthAutoSize, FX_FLOAT& fContentCalculatedWidth, FX_FLOAT& fContentCalculatedHeight, FX_FLOAT& fContentCurRowY,\r
86             FX_FLOAT fContentCurRowHeight, FX_FLOAT fContentWidthLimit, FX_BOOL bRootForceTb = FALSE);\r
87     void                        ProcessUnUseOverFlow(CXFA_Node* pLeaderNode, CXFA_Node* pTrailerNode, CXFA_ContentLayoutItemImpl* pTrailerItem, CXFA_Node* pFormNode);\r
88     void                        ProcessUnUseBinds(CXFA_Node* pFormNode);\r
89     FX_BOOL                     IsAddNewRowForTrailer(CXFA_ContentLayoutItemImpl* pTrailerItem);\r
90     FX_BOOL                     JudgeLeaderOrTrailerForOccur(CXFA_Node* pFormNode);\r
91     CXFA_ContentLayoutItemImpl* CreateContentLayoutItem(CXFA_Node* pFormNode);\r
92 protected:\r
93     void        DoLayoutPositionedContainer(CXFA_LayoutContext* pContext = NULL);\r
94     void        DoLayoutTableContainer(CXFA_Node* pLayoutNode);\r
95     XFA_ItemLayoutProcessorResult DoLayoutFlowedContainer(FX_BOOL bUseBreakControl, XFA_ATTRIBUTEENUM eFlowStrategy, FX_FLOAT fHeightLimit, FX_FLOAT fRealHeight, CXFA_LayoutContext* pContext = NULL, FX_BOOL bRootForceTb = FALSE);\r
96     void        DoLayoutField();\r
97     void        XFA_ItemLayoutProcessor_GotoNextContainerNode(CXFA_Node*& pCurActionNode, XFA_ItemLayoutProcessorStages& nCurStage, CXFA_Node* pParentContainer, FX_BOOL bUsePageBreak);\r
98     FX_BOOL ProcessKeepNodesForCheckNext(CXFA_Node*& pCurActionNode, XFA_ItemLayoutProcessorStages& nCurStage, CXFA_Node*& pNextContainer, FX_BOOL& bLastKeepNode);\r
99     FX_BOOL ProcessKeepNodesForBreakBefore(CXFA_Node*& pCurActionNode, XFA_ItemLayoutProcessorStages& nCurStage, CXFA_Node* pContainerNode);\r
100     CXFA_Node* GetSubformSetParent(CXFA_Node* pSubformSet);\r
101 \r
102 public:\r
103     FX_BOOL             m_bKeepBreakFinish;\r
104     FX_BOOL             m_bIsProcessKeep;\r
105     CXFA_Node*  m_pKeepHeadNode;\r
106     CXFA_Node*  m_pKeepTailNode;\r
107     CXFA_Node*                                          m_pFormNode;\r
108     CXFA_ContentLayoutItemImpl*         m_pLayoutItem;\r
109 #ifdef _XFA_LAYOUTITEM_ProcessCACHE_\r
110     CXFA_ContentLayoutItemImpl*         m_pOldLayoutItem;\r
111 #else\r
112     CXFA_LayoutPageMgr*                         m_pPageMgrCreateItem;\r
113 #endif\r
114     CXFA_Node*                                          m_pCurChildNode;\r
115     CXFA_ItemLayoutProcessor*           m_pCurChildPreprocessor;\r
116     XFA_ItemLayoutProcessorStages       m_nCurChildNodeStage;\r
117     FX_FLOAT                                            m_fUsedSize;\r
118     CXFA_LayoutPageMgr*                         m_pPageMgr;\r
119     CFX_PtrList                                         m_rgPendingNodes;\r
120     FX_BOOL                                                     m_bBreakPending;\r
121     CFX_ArrayTemplate<FX_FLOAT>         m_rgSpecifiedColumnWidths;\r
122     CFX_ArrayTemplate<CXFA_ContentLayoutItemImpl*> m_arrayKeepItems;\r
123     CFX_MapPtrToPtr                                     m_PendingNodesCount;\r
124     FX_FLOAT                                            m_fLastRowWidth;\r
125     FX_FLOAT                                            m_fLastRowY;\r
126     FX_FLOAT                                            m_fWidthLimite;\r
127     FX_BOOL                                                     m_bUseInheriated;\r
128     XFA_ItemLayoutProcessorResult   m_ePreProcessRs;\r
129     FX_BOOL                                                     m_bHasAvailHeight;\r
130 };\r
131 FX_BOOL XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode);\r
132 #endif\r