| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cxfa_layoutprocessor.h" |
| 8 | 8 |
| 9 #include "xfa/fxfa/parser/cxfa_measurement.h" | 9 #include "xfa/fxfa/parser/cxfa_measurement.h" |
| 10 #include "xfa/fxfa/parser/xfa_doclayout.h" | |
| 11 #include "xfa/fxfa/parser/xfa_document.h" | 10 #include "xfa/fxfa/parser/xfa_document.h" |
| 12 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" | 11 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" |
| 13 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" | 12 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" |
| 14 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" | 13 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" |
| 15 #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" | 14 #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" |
| 16 #include "xfa/fxfa/parser/xfa_localemgr.h" | 15 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 17 #include "xfa/fxfa/parser/xfa_object.h" | 16 #include "xfa/fxfa/parser/xfa_object.h" |
| 18 #include "xfa/fxfa/parser/xfa_utils.h" | 17 #include "xfa/fxfa/parser/xfa_utils.h" |
| 19 | 18 |
| 20 CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { | 19 CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { |
| 21 if (!m_pLayoutProcessor) { | 20 if (!m_pLayoutProcessor) { |
| 22 m_pLayoutProcessor = new CXFA_LayoutProcessor(this); | 21 m_pLayoutProcessor = new CXFA_LayoutProcessor(this); |
| 23 ASSERT(m_pLayoutProcessor); | 22 ASSERT(m_pLayoutProcessor); |
| 24 } | 23 } |
| 25 return m_pLayoutProcessor; | 24 return m_pLayoutProcessor; |
| 26 } | 25 } |
| 26 |
| 27 CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { | 27 CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { |
| 28 return GetLayoutProcessor(); | 28 return GetLayoutProcessor(); |
| 29 } | 29 } |
| 30 |
| 30 CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) | 31 CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) |
| 31 : m_pDocument(pDocument), | 32 : m_pDocument(pDocument), |
| 32 m_pRootItemLayoutProcessor(nullptr), | 33 m_pRootItemLayoutProcessor(nullptr), |
| 33 m_pLayoutPageMgr(nullptr), | 34 m_pLayoutPageMgr(nullptr), |
| 34 m_nProgressCounter(0), | 35 m_nProgressCounter(0), |
| 35 m_bNeeLayout(TRUE) {} | 36 m_bNeeLayout(TRUE) {} |
| 37 |
| 36 CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { | 38 CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { |
| 37 ClearLayoutData(); | 39 ClearLayoutData(); |
| 38 } | 40 } |
| 41 |
| 39 CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { | 42 CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { |
| 40 return m_pDocument; | 43 return m_pDocument; |
| 41 } | 44 } |
| 42 | 45 |
| 43 int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) { | 46 int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) { |
| 44 if (!bForceRestart && !IsNeedLayout()) | 47 if (!bForceRestart && !IsNeedLayout()) |
| 45 return 100; | 48 return 100; |
| 46 | 49 |
| 47 delete m_pRootItemLayoutProcessor; | 50 delete m_pRootItemLayoutProcessor; |
| 48 m_pRootItemLayoutProcessor = nullptr; | 51 m_pRootItemLayoutProcessor = nullptr; |
| 49 m_nProgressCounter = 0; | 52 m_nProgressCounter = 0; |
| 50 CXFA_Node* pFormPacketNode = | 53 CXFA_Node* pFormPacketNode = |
| 51 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); | 54 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 52 if (!pFormPacketNode) { | 55 if (!pFormPacketNode) |
| 53 return -1; | 56 return -1; |
| 54 } | 57 |
| 55 CXFA_Node* pFormRoot = | 58 CXFA_Node* pFormRoot = |
| 56 pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform); | 59 pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform); |
| 57 if (!pFormRoot) { | 60 if (!pFormRoot) |
| 58 return -1; | 61 return -1; |
| 59 } | 62 if (!m_pLayoutPageMgr) |
| 60 if (!m_pLayoutPageMgr) { | |
| 61 m_pLayoutPageMgr = new CXFA_LayoutPageMgr(this); | 63 m_pLayoutPageMgr = new CXFA_LayoutPageMgr(this); |
| 62 } | 64 if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot)) |
| 63 if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot)) { | |
| 64 return -1; | 65 return -1; |
| 65 } | 66 if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot)) |
| 66 if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot)) { | |
| 67 return -1; | 67 return -1; |
| 68 } | |
| 69 m_pRootItemLayoutProcessor = | 68 m_pRootItemLayoutProcessor = |
| 70 new CXFA_ItemLayoutProcessor(pFormRoot, m_pLayoutPageMgr); | 69 new CXFA_ItemLayoutProcessor(pFormRoot, m_pLayoutPageMgr); |
| 71 m_nProgressCounter = 1; | 70 m_nProgressCounter = 1; |
| 72 return 0; | 71 return 0; |
| 73 } | 72 } |
| 73 |
| 74 int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { | 74 int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { |
| 75 if (m_nProgressCounter < 1) { | 75 if (m_nProgressCounter < 1) |
| 76 return -1; | 76 return -1; |
| 77 } | 77 |
| 78 XFA_ItemLayoutProcessorResult eStatus; | 78 XFA_ItemLayoutProcessorResult eStatus; |
| 79 CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode(); | 79 CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode(); |
| 80 FX_FLOAT fPosX = pFormNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); | 80 FX_FLOAT fPosX = pFormNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); |
| 81 FX_FLOAT fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); | 81 FX_FLOAT fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); |
| 82 do { | 82 do { |
| 83 FX_FLOAT fAvailHeight = m_pLayoutPageMgr->GetAvailHeight(); | 83 FX_FLOAT fAvailHeight = m_pLayoutPageMgr->GetAvailHeight(); |
| 84 eStatus = | 84 eStatus = |
| 85 m_pRootItemLayoutProcessor->DoLayout(TRUE, fAvailHeight, fAvailHeight); | 85 m_pRootItemLayoutProcessor->DoLayout(TRUE, fAvailHeight, fAvailHeight); |
| 86 if (eStatus != XFA_ItemLayoutProcessorResult_Done) { | 86 if (eStatus != XFA_ItemLayoutProcessorResult_Done) |
| 87 m_nProgressCounter++; | 87 m_nProgressCounter++; |
| 88 } | 88 |
| 89 CXFA_ContentLayoutItem* pLayoutItem = | 89 CXFA_ContentLayoutItem* pLayoutItem = |
| 90 m_pRootItemLayoutProcessor->ExtractLayoutItem(); | 90 m_pRootItemLayoutProcessor->ExtractLayoutItem(); |
| 91 if (pLayoutItem) { | 91 if (pLayoutItem) |
| 92 pLayoutItem->m_sPos = CFX_PointF(fPosX, fPosY); | 92 pLayoutItem->m_sPos = CFX_PointF(fPosX, fPosY); |
| 93 } | 93 |
| 94 m_pLayoutPageMgr->SubmitContentItem(pLayoutItem, eStatus); | 94 m_pLayoutPageMgr->SubmitContentItem(pLayoutItem, eStatus); |
| 95 } while (eStatus != XFA_ItemLayoutProcessorResult_Done && | 95 } while (eStatus != XFA_ItemLayoutProcessorResult_Done && |
| 96 (!pPause || !pPause->NeedToPauseNow())); | 96 (!pPause || !pPause->NeedToPauseNow())); |
| 97 |
| 97 if (eStatus == XFA_ItemLayoutProcessorResult_Done) { | 98 if (eStatus == XFA_ItemLayoutProcessorResult_Done) { |
| 98 m_pLayoutPageMgr->FinishPaginatedPageSets(); | 99 m_pLayoutPageMgr->FinishPaginatedPageSets(); |
| 99 m_pLayoutPageMgr->SyncLayoutData(); | 100 m_pLayoutPageMgr->SyncLayoutData(); |
| 100 m_bNeeLayout = FALSE; | 101 m_bNeeLayout = FALSE; |
| 101 m_rgChangedContainers.RemoveAll(); | 102 m_rgChangedContainers.RemoveAll(); |
| 102 } | 103 } |
| 103 return 100 * (eStatus == XFA_ItemLayoutProcessorResult_Done | 104 return 100 * (eStatus == XFA_ItemLayoutProcessorResult_Done |
| 104 ? m_nProgressCounter | 105 ? m_nProgressCounter |
| 105 : m_nProgressCounter - 1) / | 106 : m_nProgressCounter - 1) / |
| 106 m_nProgressCounter; | 107 m_nProgressCounter; |
| 107 } | 108 } |
| 109 |
| 108 FX_BOOL CXFA_LayoutProcessor::IncrementLayout() { | 110 FX_BOOL CXFA_LayoutProcessor::IncrementLayout() { |
| 109 if (m_bNeeLayout) { | 111 if (m_bNeeLayout) { |
| 110 StartLayout(TRUE); | 112 StartLayout(TRUE); |
| 111 return DoLayout(nullptr) == 100; | 113 return DoLayout(nullptr) == 100; |
| 112 } | 114 } |
| 115 |
| 113 for (int32_t i = 0, c = m_rgChangedContainers.GetSize(); i < c; i++) { | 116 for (int32_t i = 0, c = m_rgChangedContainers.GetSize(); i < c; i++) { |
| 114 CXFA_Node* pNode = m_rgChangedContainers[i]; | 117 CXFA_Node* pNode = m_rgChangedContainers[i]; |
| 115 CXFA_Node* pParentNode = | 118 CXFA_Node* pParentNode = |
| 116 pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); | 119 pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); |
| 117 if (!pParentNode) { | 120 if (!pParentNode) |
| 118 return FALSE; | 121 return FALSE; |
| 119 } | |
| 120 if (!CXFA_ItemLayoutProcessor::IncrementRelayoutNode(this, pNode, | 122 if (!CXFA_ItemLayoutProcessor::IncrementRelayoutNode(this, pNode, |
| 121 pParentNode)) { | 123 pParentNode)) { |
| 122 return FALSE; | 124 return FALSE; |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 m_rgChangedContainers.RemoveAll(); | 127 m_rgChangedContainers.RemoveAll(); |
| 126 return TRUE; | 128 return TRUE; |
| 127 } | 129 } |
| 130 |
| 128 int32_t CXFA_LayoutProcessor::CountPages() const { | 131 int32_t CXFA_LayoutProcessor::CountPages() const { |
| 129 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPageCount() : 0; | 132 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPageCount() : 0; |
| 130 } | 133 } |
| 134 |
| 131 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetPage(int32_t index) const { | 135 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetPage(int32_t index) const { |
| 132 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPage(index) : nullptr; | 136 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPage(index) : nullptr; |
| 133 } | 137 } |
| 138 |
| 134 CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) { | 139 CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) { |
| 135 return static_cast<CXFA_LayoutItem*>( | 140 return static_cast<CXFA_LayoutItem*>( |
| 136 pFormItem->GetUserData(XFA_LAYOUTITEMKEY)); | 141 pFormItem->GetUserData(XFA_LAYOUTITEMKEY)); |
| 137 } | 142 } |
| 143 |
| 138 void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { | 144 void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { |
| 139 if (m_rgChangedContainers.Find(pContainer) < 0) { | 145 if (m_rgChangedContainers.Find(pContainer) < 0) |
| 140 m_rgChangedContainers.Add(pContainer); | 146 m_rgChangedContainers.Add(pContainer); |
| 141 } | |
| 142 } | 147 } |
| 148 |
| 143 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { | 149 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { |
| 144 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr; | 150 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr; |
| 145 } | 151 } |
| 146 | 152 |
| 147 void CXFA_LayoutProcessor::ClearLayoutData() { | 153 void CXFA_LayoutProcessor::ClearLayoutData() { |
| 148 delete m_pLayoutPageMgr; | 154 delete m_pLayoutPageMgr; |
| 149 m_pLayoutPageMgr = nullptr; | 155 m_pLayoutPageMgr = nullptr; |
| 150 delete m_pRootItemLayoutProcessor; | 156 delete m_pRootItemLayoutProcessor; |
| 151 m_pRootItemLayoutProcessor = nullptr; | 157 m_pRootItemLayoutProcessor = nullptr; |
| 152 m_nProgressCounter = 0; | 158 m_nProgressCounter = 0; |
| 153 } | 159 } |
| 154 | 160 |
| 155 FX_BOOL CXFA_LayoutProcessor::IsNeedLayout() { | 161 FX_BOOL CXFA_LayoutProcessor::IsNeedLayout() { |
| 156 return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; | 162 return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; |
| 157 } | 163 } |
| 158 CXFA_LayoutItem::CXFA_LayoutItem(CXFA_Node* pNode, FX_BOOL bIsContentLayoutItem) | |
| 159 : m_pFormNode(pNode), | |
| 160 m_pParent(nullptr), | |
| 161 m_pNextSibling(nullptr), | |
| 162 m_pFirstChild(nullptr), | |
| 163 m_bIsContentLayoutItem(bIsContentLayoutItem) {} | |
| 164 CXFA_LayoutItem::~CXFA_LayoutItem() {} | |
| 165 CXFA_ContainerLayoutItem::CXFA_ContainerLayoutItem(CXFA_Node* pNode) | |
| 166 : CXFA_LayoutItem(pNode, FALSE), m_pOldSubform(nullptr) {} | |
| 167 CXFA_LayoutProcessor* CXFA_ContainerLayoutItem::GetLayout() const { | |
| 168 return m_pFormNode->GetDocument()->GetLayoutProcessor(); | |
| 169 } | |
| 170 int32_t CXFA_ContainerLayoutItem::GetPageIndex() const { | |
| 171 return m_pFormNode->GetDocument() | |
| 172 ->GetLayoutProcessor() | |
| 173 ->GetLayoutPageMgr() | |
| 174 ->GetPageIndex(this); | |
| 175 } | |
| 176 | |
| 177 void CXFA_ContainerLayoutItem::GetPageSize(CFX_SizeF& size) const { | |
| 178 size.clear(); | |
| 179 CXFA_Node* pMedium = m_pFormNode->GetFirstChildByClass(XFA_Element::Medium); | |
| 180 if (!pMedium) | |
| 181 return; | |
| 182 | |
| 183 size = CFX_SizeF(pMedium->GetMeasure(XFA_ATTRIBUTE_Short).ToUnit(XFA_UNIT_Pt), | |
| 184 pMedium->GetMeasure(XFA_ATTRIBUTE_Long).ToUnit(XFA_UNIT_Pt)); | |
| 185 if (pMedium->GetEnum(XFA_ATTRIBUTE_Orientation) == | |
| 186 XFA_ATTRIBUTEENUM_Landscape) { | |
| 187 size = CFX_SizeF(size.y, size.x); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 CXFA_Node* CXFA_ContainerLayoutItem::GetMasterPage() const { | |
| 192 return m_pFormNode; | |
| 193 } | |
| 194 CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode) | |
| 195 : CXFA_LayoutItem(pNode, TRUE), | |
| 196 m_pPrev(nullptr), | |
| 197 m_pNext(nullptr), | |
| 198 m_dwStatus(0) {} | |
| 199 CXFA_ContentLayoutItem::~CXFA_ContentLayoutItem() { | |
| 200 if (m_pFormNode->GetUserData(XFA_LAYOUTITEMKEY) == this) { | |
| 201 m_pFormNode->SetUserData(XFA_LAYOUTITEMKEY, nullptr); | |
| 202 } | |
| 203 } | |
| OLD | NEW |