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_document_layout_imp.h" | 7 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" |
8 | 8 |
9 #include "xfa/fxfa/parser/xfa_basic_imp.h" | 9 #include "xfa/fxfa/parser/xfa_basic_imp.h" |
10 #include "xfa/fxfa/parser/xfa_doclayout.h" | 10 #include "xfa/fxfa/parser/xfa_doclayout.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 m_pLayoutProcessor = new CXFA_LayoutProcessor(this); | 24 m_pLayoutProcessor = new CXFA_LayoutProcessor(this); |
25 ASSERT(m_pLayoutProcessor); | 25 ASSERT(m_pLayoutProcessor); |
26 } | 26 } |
27 return m_pLayoutProcessor; | 27 return m_pLayoutProcessor; |
28 } | 28 } |
29 CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { | 29 CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { |
30 return GetLayoutProcessor(); | 30 return GetLayoutProcessor(); |
31 } | 31 } |
32 CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) | 32 CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) |
33 : m_pDocument(pDocument), | 33 : m_pDocument(pDocument), |
34 m_pRootItemLayoutProcessor(NULL), | 34 m_pRootItemLayoutProcessor(nullptr), |
35 m_pLayoutPageMgr(NULL), | 35 m_pLayoutPageMgr(nullptr), |
36 m_nProgressCounter(0), | 36 m_nProgressCounter(0), |
37 m_bNeeLayout(TRUE) {} | 37 m_bNeeLayout(TRUE) {} |
38 CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { | 38 CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { |
39 ClearLayoutData(); | 39 ClearLayoutData(); |
40 } | 40 } |
41 CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { | 41 CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { |
42 return m_pDocument; | 42 return m_pDocument; |
43 } | 43 } |
44 | 44 |
45 int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) { | 45 int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 m_rgChangedContainers.RemoveAll(); | 103 m_rgChangedContainers.RemoveAll(); |
104 } | 104 } |
105 return 100 * (eStatus == XFA_ItemLayoutProcessorResult_Done | 105 return 100 * (eStatus == XFA_ItemLayoutProcessorResult_Done |
106 ? m_nProgressCounter | 106 ? m_nProgressCounter |
107 : m_nProgressCounter - 1) / | 107 : m_nProgressCounter - 1) / |
108 m_nProgressCounter; | 108 m_nProgressCounter; |
109 } | 109 } |
110 FX_BOOL CXFA_LayoutProcessor::IncrementLayout() { | 110 FX_BOOL CXFA_LayoutProcessor::IncrementLayout() { |
111 if (m_bNeeLayout) { | 111 if (m_bNeeLayout) { |
112 StartLayout(TRUE); | 112 StartLayout(TRUE); |
113 return DoLayout(NULL) == 100; | 113 return DoLayout(nullptr) == 100; |
114 } | 114 } |
115 for (int32_t i = 0, c = m_rgChangedContainers.GetSize(); i < c; i++) { | 115 for (int32_t i = 0, c = m_rgChangedContainers.GetSize(); i < c; i++) { |
116 CXFA_Node* pNode = m_rgChangedContainers[i]; | 116 CXFA_Node* pNode = m_rgChangedContainers[i]; |
117 CXFA_Node* pParentNode = | 117 CXFA_Node* pParentNode = |
118 pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); | 118 pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); |
119 if (!pParentNode) { | 119 if (!pParentNode) { |
120 return FALSE; | 120 return FALSE; |
121 } | 121 } |
122 if (!CXFA_ItemLayoutProcessor::IncrementRelayoutNode(this, pNode, | 122 if (!CXFA_ItemLayoutProcessor::IncrementRelayoutNode(this, pNode, |
123 pParentNode)) { | 123 pParentNode)) { |
124 return FALSE; | 124 return FALSE; |
125 } | 125 } |
126 } | 126 } |
127 m_rgChangedContainers.RemoveAll(); | 127 m_rgChangedContainers.RemoveAll(); |
128 return TRUE; | 128 return TRUE; |
129 } | 129 } |
130 int32_t CXFA_LayoutProcessor::CountPages() const { | 130 int32_t CXFA_LayoutProcessor::CountPages() const { |
131 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPageCount() : 0; | 131 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPageCount() : 0; |
132 } | 132 } |
133 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetPage(int32_t index) const { | 133 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetPage(int32_t index) const { |
134 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPage(index) : NULL; | 134 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPage(index) : nullptr; |
135 } | 135 } |
136 CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) { | 136 CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) { |
137 return static_cast<CXFA_LayoutItem*>( | 137 return static_cast<CXFA_LayoutItem*>( |
138 pFormItem->GetUserData(XFA_LAYOUTITEMKEY)); | 138 pFormItem->GetUserData(XFA_LAYOUTITEMKEY)); |
139 } | 139 } |
140 void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { | 140 void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { |
141 if (m_rgChangedContainers.Find(pContainer) < 0) { | 141 if (m_rgChangedContainers.Find(pContainer) < 0) { |
142 m_rgChangedContainers.Add(pContainer); | 142 m_rgChangedContainers.Add(pContainer); |
143 } | 143 } |
144 } | 144 } |
145 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { | 145 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { |
146 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : NULL; | 146 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr; |
147 } | 147 } |
148 | 148 |
149 void CXFA_LayoutProcessor::ClearLayoutData() { | 149 void CXFA_LayoutProcessor::ClearLayoutData() { |
150 delete m_pLayoutPageMgr; | 150 delete m_pLayoutPageMgr; |
151 m_pLayoutPageMgr = nullptr; | 151 m_pLayoutPageMgr = nullptr; |
152 delete m_pRootItemLayoutProcessor; | 152 delete m_pRootItemLayoutProcessor; |
153 m_pRootItemLayoutProcessor = nullptr; | 153 m_pRootItemLayoutProcessor = nullptr; |
154 m_nProgressCounter = 0; | 154 m_nProgressCounter = 0; |
155 } | 155 } |
156 | 156 |
157 FX_BOOL CXFA_LayoutProcessor::IsNeedLayout() { | 157 FX_BOOL CXFA_LayoutProcessor::IsNeedLayout() { |
158 return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; | 158 return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; |
159 } | 159 } |
160 CXFA_LayoutItem::CXFA_LayoutItem(CXFA_Node* pNode, FX_BOOL bIsContentLayoutItem) | 160 CXFA_LayoutItem::CXFA_LayoutItem(CXFA_Node* pNode, FX_BOOL bIsContentLayoutItem) |
161 : m_pFormNode(pNode), | 161 : m_pFormNode(pNode), |
162 m_pParent(NULL), | 162 m_pParent(nullptr), |
163 m_pNextSibling(NULL), | 163 m_pNextSibling(nullptr), |
164 m_pFirstChild(NULL), | 164 m_pFirstChild(nullptr), |
165 m_bIsContentLayoutItem(bIsContentLayoutItem) {} | 165 m_bIsContentLayoutItem(bIsContentLayoutItem) {} |
166 CXFA_LayoutItem::~CXFA_LayoutItem() {} | 166 CXFA_LayoutItem::~CXFA_LayoutItem() {} |
167 CXFA_ContainerLayoutItem::CXFA_ContainerLayoutItem(CXFA_Node* pNode) | 167 CXFA_ContainerLayoutItem::CXFA_ContainerLayoutItem(CXFA_Node* pNode) |
168 : CXFA_LayoutItem(pNode, FALSE), m_pOldSubform(NULL) {} | 168 : CXFA_LayoutItem(pNode, FALSE), m_pOldSubform(nullptr) {} |
169 CXFA_LayoutProcessor* CXFA_ContainerLayoutItem::GetLayout() const { | 169 CXFA_LayoutProcessor* CXFA_ContainerLayoutItem::GetLayout() const { |
170 return m_pFormNode->GetDocument()->GetLayoutProcessor(); | 170 return m_pFormNode->GetDocument()->GetLayoutProcessor(); |
171 } | 171 } |
172 int32_t CXFA_ContainerLayoutItem::GetPageIndex() const { | 172 int32_t CXFA_ContainerLayoutItem::GetPageIndex() const { |
173 return m_pFormNode->GetDocument() | 173 return m_pFormNode->GetDocument() |
174 ->GetLayoutProcessor() | 174 ->GetLayoutProcessor() |
175 ->GetLayoutPageMgr() | 175 ->GetLayoutPageMgr() |
176 ->GetPageIndex(this); | 176 ->GetPageIndex(this); |
177 } | 177 } |
178 | 178 |
179 void CXFA_ContainerLayoutItem::GetPageSize(CFX_SizeF& size) const { | 179 void CXFA_ContainerLayoutItem::GetPageSize(CFX_SizeF& size) const { |
180 size.clear(); | 180 size.clear(); |
181 CXFA_Node* pMedium = m_pFormNode->GetFirstChildByClass(XFA_Element::Medium); | 181 CXFA_Node* pMedium = m_pFormNode->GetFirstChildByClass(XFA_Element::Medium); |
182 if (!pMedium) | 182 if (!pMedium) |
183 return; | 183 return; |
184 | 184 |
185 size = CFX_SizeF(pMedium->GetMeasure(XFA_ATTRIBUTE_Short).ToUnit(XFA_UNIT_Pt), | 185 size = CFX_SizeF(pMedium->GetMeasure(XFA_ATTRIBUTE_Short).ToUnit(XFA_UNIT_Pt), |
186 pMedium->GetMeasure(XFA_ATTRIBUTE_Long).ToUnit(XFA_UNIT_Pt)); | 186 pMedium->GetMeasure(XFA_ATTRIBUTE_Long).ToUnit(XFA_UNIT_Pt)); |
187 if (pMedium->GetEnum(XFA_ATTRIBUTE_Orientation) == | 187 if (pMedium->GetEnum(XFA_ATTRIBUTE_Orientation) == |
188 XFA_ATTRIBUTEENUM_Landscape) { | 188 XFA_ATTRIBUTEENUM_Landscape) { |
189 size = CFX_SizeF(size.y, size.x); | 189 size = CFX_SizeF(size.y, size.x); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 CXFA_Node* CXFA_ContainerLayoutItem::GetMasterPage() const { | 193 CXFA_Node* CXFA_ContainerLayoutItem::GetMasterPage() const { |
194 return m_pFormNode; | 194 return m_pFormNode; |
195 } | 195 } |
196 CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode) | 196 CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode) |
197 : CXFA_LayoutItem(pNode, TRUE), | 197 : CXFA_LayoutItem(pNode, TRUE), |
198 m_pPrev(NULL), | 198 m_pPrev(nullptr), |
199 m_pNext(NULL), | 199 m_pNext(nullptr), |
200 m_dwStatus(0) {} | 200 m_dwStatus(0) {} |
201 CXFA_ContentLayoutItem::~CXFA_ContentLayoutItem() { | 201 CXFA_ContentLayoutItem::~CXFA_ContentLayoutItem() { |
202 if (m_pFormNode->GetUserData(XFA_LAYOUTITEMKEY) == this) { | 202 if (m_pFormNode->GetUserData(XFA_LAYOUTITEMKEY) == this) { |
203 m_pFormNode->SetUserData(XFA_LAYOUTITEMKEY, NULL); | 203 m_pFormNode->SetUserData(XFA_LAYOUTITEMKEY, nullptr); |
204 } | 204 } |
205 } | 205 } |
OLD | NEW |