diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-02-06 15:31:38 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-06 21:05:27 +0000 |
commit | 10def51edb8758632be9b24476459b0ab6f23c51 (patch) | |
tree | 0c38eb929236bb9a2415e553a6cdc3c76031df43 | |
parent | baf318f298af51bcf1e8719de703773e5e3b94ea (diff) | |
download | pdfium-10def51edb8758632be9b24476459b0ab6f23c51.tar.xz |
More CXFA_ItemLayoutProcessor cleanupchromium/3005
Continuing cleaning up members and methods of CXFA_ItemLayoutProcessor.
Change-Id: Ie74fb83337c85820072b43352b734eafc3a0d5af
Reviewed-on: https://pdfium-review.googlesource.com/2513
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | xfa/fxfa/parser/cxfa_document.cpp | 10 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_layoutprocessor.cpp | 24 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_layout_itemlayout.cpp | 524 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_layout_itemlayout.h | 132 |
5 files changed, 335 insertions, 361 deletions
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index 8ff3c2b06a..adb8eb2e0b 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -105,6 +105,16 @@ CXFA_Document::~CXFA_Document() { PurgeNodes(); } +CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { + if (!m_pLayoutProcessor) + m_pLayoutProcessor = new CXFA_LayoutProcessor(this); + return m_pLayoutProcessor; +} + +CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { + return GetLayoutProcessor(); +} + void CXFA_Document::ClearLayoutData() { delete m_pLayoutProcessor; m_pLayoutProcessor = nullptr; diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index 8e004075ce..1bd4836a7d 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -444,8 +444,8 @@ void CXFA_LayoutPageMgr::SubmitContentItem( m_bCreateOverFlowPage = false; } - if (eStatus != XFA_ItemLayoutProcessorResult_Done) { - if (eStatus == XFA_ItemLayoutProcessorResult_PageFullBreak && + if (eStatus != XFA_ItemLayoutProcessorResult::Done) { + if (eStatus == XFA_ItemLayoutProcessorResult::PageFullBreak && m_CurrentContainerRecordIter == GetTailPosition()) { AppendNewPage(); } @@ -466,7 +466,7 @@ FX_FLOAT CXFA_LayoutPageMgr::GetAvailHeight() { return fAvailHeight; if (m_CurrentContainerRecordIter == m_ProposedContainerRecords.begin()) return 0.0f; - return XFA_LAYOUT_FLOAT_MAX; + return FLT_MAX; } bool XFA_LayoutPageMgr_RunBreakTestScript(CXFA_Node* pTestScript) { diff --git a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp index ea1064a4bc..e179d38985 100644 --- a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp @@ -17,18 +17,6 @@ #include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_utils.h" -CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { - if (!m_pLayoutProcessor) { - m_pLayoutProcessor = new CXFA_LayoutProcessor(this); - ASSERT(m_pLayoutProcessor); - } - return m_pLayoutProcessor; -} - -CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { - return GetLayoutProcessor(); -} - CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) : m_pDocument(pDocument), m_nProgressCounter(0), @@ -80,9 +68,9 @@ int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { FX_FLOAT fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); do { FX_FLOAT fAvailHeight = m_pLayoutPageMgr->GetAvailHeight(); - eStatus = - m_pRootItemLayoutProcessor->DoLayout(true, fAvailHeight, fAvailHeight); - if (eStatus != XFA_ItemLayoutProcessorResult_Done) + eStatus = m_pRootItemLayoutProcessor->DoLayout(true, fAvailHeight, + fAvailHeight, nullptr); + if (eStatus != XFA_ItemLayoutProcessorResult::Done) m_nProgressCounter++; CXFA_ContentLayoutItem* pLayoutItem = @@ -91,16 +79,16 @@ int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { pLayoutItem->m_sPos = CFX_PointF(fPosX, fPosY); m_pLayoutPageMgr->SubmitContentItem(pLayoutItem, eStatus); - } while (eStatus != XFA_ItemLayoutProcessorResult_Done && + } while (eStatus != XFA_ItemLayoutProcessorResult::Done && (!pPause || !pPause->NeedToPauseNow())); - if (eStatus == XFA_ItemLayoutProcessorResult_Done) { + if (eStatus == XFA_ItemLayoutProcessorResult::Done) { m_pLayoutPageMgr->FinishPaginatedPageSets(); m_pLayoutPageMgr->SyncLayoutData(); m_bNeeLayout = false; m_rgChangedContainers.RemoveAll(); } - return 100 * (eStatus == XFA_ItemLayoutProcessorResult_Done + return 100 * (eStatus == XFA_ItemLayoutProcessorResult::Done ? m_nProgressCounter : m_nProgressCounter - 1) / m_nProgressCounter; diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp index cd57d059f8..bc3c06cd49 100644 --- a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp +++ b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp @@ -174,7 +174,7 @@ void RelocateTableRowCells( } FX_FLOAT fContentWidthLimit = - bContainerWidthAutoSize ? XFA_LAYOUT_FLOAT_MAX + bContainerWidthAutoSize ? FLT_MAX : fContainerWidth - fLeftInset - fRightInset; FX_FLOAT fContentCurrentHeight = pLayoutRow->m_sSize.y - fTopInset - fBottomInset; @@ -262,7 +262,7 @@ void RelocateTableRowCells( if (bContainerWidthAutoSize) { FX_FLOAT fChildSuppliedWidth = fCurrentColX; - if (fContentWidthLimit < XFA_LAYOUT_FLOAT_MAX && + if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { fChildSuppliedWidth = fContentWidthLimit; } @@ -446,7 +446,7 @@ FX_FLOAT InsertPendingItems(CXFA_ItemLayoutProcessor* pProcessor, auto pPendingProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>( pProcessor->m_PendingNodes.front(), nullptr); pProcessor->m_PendingNodes.pop_front(); - pPendingProcessor->DoLayout(false, XFA_LAYOUT_FLOAT_MAX); + pPendingProcessor->DoLayout(false, FLT_MAX, FLT_MAX, nullptr); CXFA_ContentLayoutItem* pPendingLayoutItem = pPendingProcessor->HasLayoutItem() ? pPendingProcessor->ExtractLayoutItem() @@ -535,7 +535,7 @@ bool FindBreakNode(CXFA_Node* pContainerNode, case XFA_Element::BreakBefore: { if (bBreakBefore) { pCurActionNode = pBreakNode; - nCurStage = XFA_ItemLayoutProcessorStages_BreakBefore; + nCurStage = XFA_ItemLayoutProcessorStages::BreakBefore; bFindRs = true; } break; @@ -543,7 +543,7 @@ bool FindBreakNode(CXFA_Node* pContainerNode, case XFA_Element::BreakAfter: { if (!bBreakBefore) { pCurActionNode = pBreakNode; - nCurStage = XFA_ItemLayoutProcessorStages_BreakAfter; + nCurStage = XFA_ItemLayoutProcessorStages::BreakAfter; bFindRs = true; } break; @@ -551,9 +551,9 @@ bool FindBreakNode(CXFA_Node* pContainerNode, case XFA_Element::Break: if (pBreakNode->GetEnum(eAttributeType) != XFA_ATTRIBUTEENUM_Auto) { pCurActionNode = pBreakNode; - nCurStage = XFA_ItemLayoutProcessorStages_BreakBefore; + nCurStage = XFA_ItemLayoutProcessorStages::BreakBefore; if (!bBreakBefore) - nCurStage = XFA_ItemLayoutProcessorStages_BreakAfter; + nCurStage = XFA_ItemLayoutProcessorStages::BreakAfter; bFindRs = true; } @@ -618,8 +618,8 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( FX_FLOAT& fContentCurRowHeight, bool& bAddedItemInRow, bool& bForceEndPage, - CXFA_LayoutContext* pLayoutContext = nullptr, - bool bNewRow = false) { + CXFA_LayoutContext* pLayoutContext, + bool bNewRow) { bool bTakeSpace = XFA_ItemLayoutProcessor_IsTakingSpace(pProcessor->m_pFormNode); uint8_t uHAlign = @@ -629,7 +629,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if ((eFlowStrategy != XFA_ATTRIBUTEENUM_Rl_tb && uHAlign < uCurHAlignState) || (eFlowStrategy == XFA_ATTRIBUTEENUM_Rl_tb && uHAlign > uCurHAlignState)) { - return XFA_ItemLayoutProcessorResult_RowFullBreak; + return XFA_ItemLayoutProcessorResult::RowFullBreak; } uCurHAlignState = uHAlign; @@ -662,18 +662,18 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } } - XFA_ItemLayoutProcessorResult eRetValue = XFA_ItemLayoutProcessorResult_Done; + XFA_ItemLayoutProcessorResult eRetValue = XFA_ItemLayoutProcessorResult::Done; if (!bNewRow || - pProcessor->m_ePreProcessRs == XFA_ItemLayoutProcessorResult_Done) { + pProcessor->m_ePreProcessRs == XFA_ItemLayoutProcessorResult::Done) { eRetValue = pProcessor->DoLayout( bTakeSpace ? bUseBreakControl : false, - bUseRealHeight ? fRealHeight - fContentCurRowY : XFA_LAYOUT_FLOAT_MAX, - bIsTransHeight ? fRealHeight - fContentCurRowY : XFA_LAYOUT_FLOAT_MAX, + bUseRealHeight ? fRealHeight - fContentCurRowY : FLT_MAX, + bIsTransHeight ? fRealHeight - fContentCurRowY : FLT_MAX, pLayoutContext); pProcessor->m_ePreProcessRs = eRetValue; } else { eRetValue = pProcessor->m_ePreProcessRs; - pProcessor->m_ePreProcessRs = XFA_ItemLayoutProcessorResult_Done; + pProcessor->m_ePreProcessRs = XFA_ItemLayoutProcessorResult::Done; } if (pProcessor->HasLayoutItem() == false) return eRetValue; @@ -682,14 +682,14 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( FX_FLOAT fChildHeight; pProcessor->GetCurrentComponentSize(fChildWidth, fChildHeight); if (bUseRealHeight && fRealHeight < XFA_LAYOUT_FLOAT_PERCISION) { - fRealHeight = XFA_LAYOUT_FLOAT_MAX; - fAvailHeight = XFA_LAYOUT_FLOAT_MAX; + fRealHeight = FLT_MAX; + fAvailHeight = FLT_MAX; } if (bTakeSpace && (fChildWidth > fContentCurRowAvailWidth + XFA_LAYOUT_FLOAT_PERCISION) && (fContentWidthLimit - fContentCurRowAvailWidth > XFA_LAYOUT_FLOAT_PERCISION)) { - return XFA_ItemLayoutProcessorResult_RowFullBreak; + return XFA_ItemLayoutProcessorResult::RowFullBreak; } CXFA_Node* pOverflowLeaderNode = nullptr; @@ -712,7 +712,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( auto pOverflowLeaderProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(pOverflowTrailerNode, nullptr); - pOverflowLeaderProcessor->DoLayout(false, XFA_LAYOUT_FLOAT_MAX); + pOverflowLeaderProcessor->DoLayout(false, FLT_MAX, FLT_MAX, nullptr); pTrailerLayoutItem = pOverflowLeaderProcessor->HasLayoutItem() ? pOverflowLeaderProcessor->ExtractLayoutItem() @@ -737,7 +737,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( (!bContainerHeightAutoSize && pThis->m_fUsedSize + fAvailHeight + XFA_LAYOUT_FLOAT_PERCISION >= fContainerHeight)) { - if (!bTakeSpace || eRetValue == XFA_ItemLayoutProcessorResult_Done) { + if (!bTakeSpace || eRetValue == XFA_ItemLayoutProcessorResult::Done) { if (pProcessor->m_bUseInheriated) { if (pTrailerLayoutItem) AddTrailerBeforeSplit(pProcessor, fChildHeight, pTrailerLayoutItem, @@ -770,10 +770,10 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (fContentCurRowHeight < fChildHeight) fContentCurRowHeight = fChildHeight; } - return XFA_ItemLayoutProcessorResult_Done; + return XFA_ItemLayoutProcessorResult::Done; } - if (eRetValue == XFA_ItemLayoutProcessorResult_PageFullBreak) { + if (eRetValue == XFA_ItemLayoutProcessorResult::PageFullBreak) { if (pProcessor->m_bUseInheriated) { if (pTrailerLayoutItem) { AddTrailerBeforeSplit(pProcessor, fChildHeight, pTrailerLayoutItem, @@ -815,7 +815,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( XFA_ATTRIBUTEENUM eLayout = pProcessor->m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); if (eLayout == XFA_ATTRIBUTEENUM_Tb && - eRetValue == XFA_ItemLayoutProcessorResult_Done) { + eRetValue == XFA_ItemLayoutProcessorResult::Done) { pProcessor->ProcessUnUseOverFlow(pOverflowLeaderNode, pOverflowTrailerNode, pTrailerLayoutItem, pFormNode); @@ -826,13 +826,13 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (fContentCurRowHeight < fChildHeight) fContentCurRowHeight = fChildHeight; } - return XFA_ItemLayoutProcessorResult_PageFullBreak; + return XFA_ItemLayoutProcessorResult::PageFullBreak; } CXFA_Node* pTempLeaderNode = nullptr; CXFA_Node* pTempTrailerNode = nullptr; if (pThis->m_pPageMgr && !pProcessor->m_bUseInheriated && - eRetValue != XFA_ItemLayoutProcessorResult_PageFullBreak) { + eRetValue != XFA_ItemLayoutProcessorResult::PageFullBreak) { pThis->m_pPageMgr->ProcessOverflow(pFormNode, pTempLeaderNode, pTempTrailerNode, false, true); } @@ -871,7 +871,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( fContentCurRowHeight = fChildHeight; } } - return XFA_ItemLayoutProcessorResult_PageFullBreak; + return XFA_ItemLayoutProcessorResult::PageFullBreak; } if (fContentCurRowY <= XFA_LAYOUT_FLOAT_PERCISION) { @@ -892,7 +892,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pTrailerLayoutItem, pFormNode); pThis->m_bUseInheriated = true; } - return XFA_ItemLayoutProcessorResult_PageFullBreak; + return XFA_ItemLayoutProcessorResult::PageFullBreak; } rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); @@ -902,7 +902,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (fContentCurRowHeight < fChildHeight) fContentCurRowHeight = fChildHeight; } - if (eRetValue == XFA_ItemLayoutProcessorResult_Done) + if (eRetValue == XFA_ItemLayoutProcessorResult::Done) bForceEndPage = false; return eRetValue; @@ -921,11 +921,11 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (pProcessor->JudgeLeaderOrTrailerForOccur(pOverflowLeaderNode)) AddPendingNode(pProcessor, pOverflowLeaderNode, false); - return XFA_ItemLayoutProcessorResult_PageFullBreak; + return XFA_ItemLayoutProcessorResult::PageFullBreak; } - if (eRetValue != XFA_ItemLayoutProcessorResult_Done) - return XFA_ItemLayoutProcessorResult_PageFullBreak; + if (eRetValue != XFA_ItemLayoutProcessorResult::Done) + return XFA_ItemLayoutProcessorResult::PageFullBreak; if (!pFormNode && pLayoutContext) pFormNode = pLayoutContext->m_pOverflowProcessor->m_pFormNode; @@ -938,74 +938,14 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pTrailerLayoutItem, pFormNode); pThis->m_bUseInheriated = true; } - return XFA_ItemLayoutProcessorResult_PageFullBreak; + return XFA_ItemLayoutProcessorResult::PageFullBreak; } -} // namespace - -CXFA_ItemLayoutProcessor::CXFA_ItemLayoutProcessor(CXFA_Node* pNode, - CXFA_LayoutPageMgr* pPageMgr) - : m_bKeepBreakFinish(false), - m_bIsProcessKeep(false), - m_pKeepHeadNode(nullptr), - m_pKeepTailNode(nullptr), - m_pFormNode(pNode), - m_pLayoutItem(nullptr), - m_pOldLayoutItem(nullptr), - m_pCurChildNode(XFA_LAYOUT_INVALIDNODE), - m_pCurChildPreprocessor(nullptr), - m_nCurChildNodeStage(XFA_ItemLayoutProcessorStages_None), - m_fUsedSize(0), - m_pPageMgr(pPageMgr), - m_bBreakPending(true), - m_fLastRowWidth(0), - m_fLastRowY(0), - m_fWidthLimite(0), - m_bUseInheriated(false), - m_ePreProcessRs(XFA_ItemLayoutProcessorResult_Done), - m_bHasAvailHeight(true) { - ASSERT(m_pFormNode && (m_pFormNode->IsContainerNode() || - m_pFormNode->GetElementType() == XFA_Element::Form)); - m_pOldLayoutItem = - (CXFA_ContentLayoutItem*)m_pFormNode->GetUserData(XFA_LAYOUTITEMKEY); -} - -CXFA_ItemLayoutProcessor::~CXFA_ItemLayoutProcessor() {} - -CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem( - CXFA_Node* pFormNode) { - if (!pFormNode) - return nullptr; - - CXFA_ContentLayoutItem* pLayoutItem = nullptr; - if (m_pOldLayoutItem) { - pLayoutItem = m_pOldLayoutItem; - m_pOldLayoutItem = m_pOldLayoutItem->m_pNext; - return pLayoutItem; - } - pLayoutItem = (CXFA_ContentLayoutItem*)pFormNode->GetDocument() - ->GetNotify() - ->OnCreateLayoutItem(pFormNode); - CXFA_ContentLayoutItem* pPrevLayoutItem = - (CXFA_ContentLayoutItem*)pFormNode->GetUserData(XFA_LAYOUTITEMKEY); - if (pPrevLayoutItem) { - while (pPrevLayoutItem->m_pNext) { - pPrevLayoutItem = pPrevLayoutItem->m_pNext; - } - pPrevLayoutItem->m_pNext = pLayoutItem; - pLayoutItem->m_pPrev = pPrevLayoutItem; - } else { - pFormNode->SetUserData(XFA_LAYOUTITEMKEY, pLayoutItem); - } - return pLayoutItem; -} - -bool CXFA_ItemLayoutProcessor::FindLayoutItemSplitPos( - CXFA_ContentLayoutItem* pLayoutItem, - FX_FLOAT fCurVerticalOffset, - FX_FLOAT& fProposedSplitPos, - bool& bAppChange, - bool bCalculateMargin) { +bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, + FX_FLOAT fCurVerticalOffset, + FX_FLOAT& fProposedSplitPos, + bool& bAppChange, + bool bCalculateMargin) { CXFA_Node* pFormNode = pLayoutItem->m_pFormNode; if (fProposedSplitPos > fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION && fProposedSplitPos <= fCurVerticalOffset + pLayoutItem->m_sSize.y - @@ -1084,6 +1024,138 @@ bool CXFA_ItemLayoutProcessor::FindLayoutItemSplitPos( return false; } +void CalculatePositionedContainerPos(CXFA_Node* pNode, + FX_FLOAT fWidth, + FX_FLOAT fHeight, + FX_FLOAT& fAbsoluteX, + FX_FLOAT& fAbsoluteY) { + XFA_ATTRIBUTEENUM eAnchorType = pNode->GetEnum(XFA_ATTRIBUTE_AnchorType); + int32_t nAnchorType = 0; + switch (eAnchorType) { + case XFA_ATTRIBUTEENUM_TopLeft: + nAnchorType = 0; + break; + case XFA_ATTRIBUTEENUM_TopCenter: + nAnchorType = 1; + break; + case XFA_ATTRIBUTEENUM_TopRight: + nAnchorType = 2; + break; + case XFA_ATTRIBUTEENUM_MiddleLeft: + nAnchorType = 3; + break; + case XFA_ATTRIBUTEENUM_MiddleCenter: + nAnchorType = 4; + break; + case XFA_ATTRIBUTEENUM_MiddleRight: + nAnchorType = 5; + break; + case XFA_ATTRIBUTEENUM_BottomLeft: + nAnchorType = 6; + break; + case XFA_ATTRIBUTEENUM_BottomCenter: + nAnchorType = 7; + break; + case XFA_ATTRIBUTEENUM_BottomRight: + nAnchorType = 8; + break; + default: + break; + } + static const uint8_t nNextPos[4][9] = {{0, 1, 2, 3, 4, 5, 6, 7, 8}, + {6, 3, 0, 7, 4, 1, 8, 5, 2}, + {8, 7, 6, 5, 4, 3, 2, 1, 0}, + {2, 5, 8, 1, 4, 7, 0, 3, 6}}; + + FX_FLOAT fAnchorX = pNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); + FX_FLOAT fAnchorY = pNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); + int32_t nRotate = + FXSYS_round(pNode->GetMeasure(XFA_ATTRIBUTE_Rotate).GetValue()); + nRotate = XFA_MapRotation(nRotate) / 90; + int32_t nAbsoluteAnchorType = nNextPos[nRotate][nAnchorType]; + fAbsoluteX = fAnchorX; + fAbsoluteY = fAnchorY; + switch (nAbsoluteAnchorType / 3) { + case 1: + fAbsoluteY -= fHeight / 2; + break; + case 2: + fAbsoluteY -= fHeight; + break; + default: + break; + } + switch (nAbsoluteAnchorType % 3) { + case 1: + fAbsoluteX -= fWidth / 2; + break; + case 2: + fAbsoluteX -= fWidth; + break; + default: + break; + } +} + +} // namespace + +CXFA_ItemLayoutProcessor::CXFA_ItemLayoutProcessor(CXFA_Node* pNode, + CXFA_LayoutPageMgr* pPageMgr) + : m_pFormNode(pNode), + m_pLayoutItem(nullptr), + m_pCurChildNode(XFA_LAYOUT_INVALIDNODE), + m_fUsedSize(0), + m_pPageMgr(pPageMgr), + m_bBreakPending(true), + m_fLastRowWidth(0), + m_fLastRowY(0), + m_bUseInheriated(false), + m_ePreProcessRs(XFA_ItemLayoutProcessorResult::Done), + m_bKeepBreakFinish(false), + m_bIsProcessKeep(false), + m_pKeepHeadNode(nullptr), + m_pKeepTailNode(nullptr), + m_pOldLayoutItem(nullptr), + m_pCurChildPreprocessor(nullptr), + m_nCurChildNodeStage(XFA_ItemLayoutProcessorStages::None), + m_fWidthLimite(0), + m_bHasAvailHeight(true) { + ASSERT(m_pFormNode && (m_pFormNode->IsContainerNode() || + m_pFormNode->GetElementType() == XFA_Element::Form)); + m_pOldLayoutItem = + (CXFA_ContentLayoutItem*)m_pFormNode->GetUserData(XFA_LAYOUTITEMKEY); +} + +CXFA_ItemLayoutProcessor::~CXFA_ItemLayoutProcessor() {} + +CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem( + CXFA_Node* pFormNode) { + if (!pFormNode) + return nullptr; + + CXFA_ContentLayoutItem* pLayoutItem = nullptr; + if (m_pOldLayoutItem) { + pLayoutItem = m_pOldLayoutItem; + m_pOldLayoutItem = m_pOldLayoutItem->m_pNext; + return pLayoutItem; + } + pLayoutItem = (CXFA_ContentLayoutItem*)pFormNode->GetDocument() + ->GetNotify() + ->OnCreateLayoutItem(pFormNode); + CXFA_ContentLayoutItem* pPrevLayoutItem = + (CXFA_ContentLayoutItem*)pFormNode->GetUserData(XFA_LAYOUTITEMKEY); + if (pPrevLayoutItem) { + while (pPrevLayoutItem->m_pNext) + pPrevLayoutItem = pPrevLayoutItem->m_pNext; + + pPrevLayoutItem->m_pNext = pLayoutItem; + pLayoutItem->m_pPrev = pPrevLayoutItem; + } else { + pFormNode->SetUserData(XFA_LAYOUTITEMKEY, pLayoutItem); + } + return pLayoutItem; +} + FX_FLOAT CXFA_ItemLayoutProcessor::FindSplitPos(FX_FLOAT fProposedSplitPos) { ASSERT(m_pLayoutItem); XFA_ATTRIBUTEENUM eLayout = m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); @@ -1188,6 +1260,7 @@ void CXFA_ItemLayoutProcessor::SplitLayoutItem( pSecondLayoutItem->AddChild(pPreItem); } } + pChildItem->m_sPos.y -= fSplitPos; pChildItem->m_sPos.y += lHeightForKeep; pChildItem->m_sPos.y += fAddMarginHeight; @@ -1229,7 +1302,7 @@ CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::ExtractLayoutItem() { pLayoutItem->m_pNextSibling = nullptr; } - if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Done || + if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Done || !ToContentLayoutItem(m_pOldLayoutItem)) { return pLayoutItem; } @@ -1263,13 +1336,13 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( CXFA_Node* pEntireContainer = pParentContainer; CXFA_Node* pChildContainer = XFA_LAYOUT_INVALIDNODE; switch (nCurStage) { - case XFA_ItemLayoutProcessorStages_BreakBefore: - case XFA_ItemLayoutProcessorStages_BreakAfter: { + case XFA_ItemLayoutProcessorStages::BreakBefore: + case XFA_ItemLayoutProcessorStages::BreakAfter: { pChildContainer = pCurActionNode->GetNodeItem(XFA_NODEITEM_Parent); break; } - case XFA_ItemLayoutProcessorStages_Keep: - case XFA_ItemLayoutProcessorStages_Container: + case XFA_ItemLayoutProcessorStages::Keep: + case XFA_ItemLayoutProcessorStages::Container: pChildContainer = pCurActionNode; break; default: @@ -1278,7 +1351,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( } switch (nCurStage) { - case XFA_ItemLayoutProcessorStages_Keep: { + case XFA_ItemLayoutProcessorStages::Keep: { CXFA_Node* pBreakAfterNode = pChildContainer->GetNodeItem(XFA_NODEITEM_FirstChild); if (!m_bKeepBreakFinish && @@ -1287,9 +1360,9 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( } goto CheckNextChildContainer; } - case XFA_ItemLayoutProcessorStages_None: { + case XFA_ItemLayoutProcessorStages::None: { pCurActionNode = XFA_LAYOUT_INVALIDNODE; - case XFA_ItemLayoutProcessorStages_BookendLeader: + case XFA_ItemLayoutProcessorStages::BookendLeader: for (CXFA_Node* pBookendNode = pCurActionNode == XFA_LAYOUT_INVALIDNODE ? pEntireContainer->GetNodeItem(XFA_NODEITEM_FirstChild) @@ -1300,7 +1373,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( case XFA_Element::Bookend: case XFA_Element::Break: pCurActionNode = pBookendNode; - nCurStage = XFA_ItemLayoutProcessorStages_BookendLeader; + nCurStage = XFA_ItemLayoutProcessorStages::BookendLeader; return; default: break; @@ -1309,7 +1382,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( } { pCurActionNode = XFA_LAYOUT_INVALIDNODE; - case XFA_ItemLayoutProcessorStages_BreakBefore: + case XFA_ItemLayoutProcessorStages::BreakBefore: if (pCurActionNode != XFA_LAYOUT_INVALIDNODE) { CXFA_Node* pBreakBeforeNode = pCurActionNode->GetNodeItem(XFA_NODEITEM_NextSibling); @@ -1326,14 +1399,14 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( goto CheckNextChildContainer; } pCurActionNode = pChildContainer; - nCurStage = XFA_ItemLayoutProcessorStages_Container; + nCurStage = XFA_ItemLayoutProcessorStages::Container; return; } goto CheckNextChildContainer; } - case XFA_ItemLayoutProcessorStages_Container: { + case XFA_ItemLayoutProcessorStages::Container: { pCurActionNode = XFA_LAYOUT_INVALIDNODE; - case XFA_ItemLayoutProcessorStages_BreakAfter: { + case XFA_ItemLayoutProcessorStages::BreakAfter: { if (pCurActionNode == XFA_LAYOUT_INVALIDNODE) { CXFA_Node* pBreakAfterNode = pChildContainer->GetNodeItem(XFA_NODEITEM_FirstChild); @@ -1385,15 +1458,15 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( } pCurActionNode = pNextChildContainer; if (m_bIsProcessKeep) - nCurStage = XFA_ItemLayoutProcessorStages_Keep; + nCurStage = XFA_ItemLayoutProcessorStages::Keep; else - nCurStage = XFA_ItemLayoutProcessorStages_Container; + nCurStage = XFA_ItemLayoutProcessorStages::Container; return; } NoMoreChildContainer : { pCurActionNode = XFA_LAYOUT_INVALIDNODE; - case XFA_ItemLayoutProcessorStages_BookendTrailer: + case XFA_ItemLayoutProcessorStages::BookendTrailer: for (CXFA_Node* pBookendNode = pCurActionNode == XFA_LAYOUT_INVALIDNODE ? pEntireContainer->GetNodeItem(XFA_NODEITEM_FirstChild) @@ -1404,7 +1477,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( case XFA_Element::Bookend: case XFA_Element::Break: pCurActionNode = pBookendNode; - nCurStage = XFA_ItemLayoutProcessorStages_BookendTrailer; + nCurStage = XFA_ItemLayoutProcessorStages::BookendTrailer; return; default: break; @@ -1413,7 +1486,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( } default: pCurActionNode = nullptr; - nCurStage = XFA_ItemLayoutProcessorStages_Done; + nCurStage = XFA_ItemLayoutProcessorStages::Done; } } @@ -1467,7 +1540,7 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepNodesForBreakBefore( m_pKeepHeadNode = nullptr; m_pKeepTailNode = nullptr; m_bIsProcessKeep = false; - nCurStage = XFA_ItemLayoutProcessorStages_Container; + nCurStage = XFA_ItemLayoutProcessorStages::Container; return true; } @@ -1482,80 +1555,6 @@ bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode) { ePresence == XFA_ATTRIBUTEENUM_Invisible; } -void CXFA_ItemLayoutProcessor::CalculatePositionedContainerPos( - CXFA_Node* pNode, - FX_FLOAT fWidth, - FX_FLOAT fHeight, - FX_FLOAT& fAbsoluteX, - FX_FLOAT& fAbsoluteY) { - XFA_ATTRIBUTEENUM eAnchorType = pNode->GetEnum(XFA_ATTRIBUTE_AnchorType); - int32_t nAnchorType = 0; - switch (eAnchorType) { - case XFA_ATTRIBUTEENUM_TopLeft: - nAnchorType = 0; - break; - case XFA_ATTRIBUTEENUM_TopCenter: - nAnchorType = 1; - break; - case XFA_ATTRIBUTEENUM_TopRight: - nAnchorType = 2; - break; - case XFA_ATTRIBUTEENUM_MiddleLeft: - nAnchorType = 3; - break; - case XFA_ATTRIBUTEENUM_MiddleCenter: - nAnchorType = 4; - break; - case XFA_ATTRIBUTEENUM_MiddleRight: - nAnchorType = 5; - break; - case XFA_ATTRIBUTEENUM_BottomLeft: - nAnchorType = 6; - break; - case XFA_ATTRIBUTEENUM_BottomCenter: - nAnchorType = 7; - break; - case XFA_ATTRIBUTEENUM_BottomRight: - nAnchorType = 8; - break; - default: - break; - } - static const uint8_t nNextPos[4][9] = {{0, 1, 2, 3, 4, 5, 6, 7, 8}, - {6, 3, 0, 7, 4, 1, 8, 5, 2}, - {8, 7, 6, 5, 4, 3, 2, 1, 0}, - {2, 5, 8, 1, 4, 7, 0, 3, 6}}; - - FX_FLOAT fAnchorX = pNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); - FX_FLOAT fAnchorY = pNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); - int32_t nRotate = - FXSYS_round(pNode->GetMeasure(XFA_ATTRIBUTE_Rotate).GetValue()); - nRotate = XFA_MapRotation(nRotate) / 90; - int32_t nAbsoluteAnchorType = nNextPos[nRotate][nAnchorType]; - fAbsoluteX = fAnchorX; - fAbsoluteY = fAnchorY; - switch (nAbsoluteAnchorType / 3) { - case 1: - fAbsoluteY -= fHeight / 2; - break; - case 2: - fAbsoluteY -= fHeight; - break; - default: - break; - } - switch (nAbsoluteAnchorType % 3) { - case 1: - fAbsoluteX -= fWidth / 2; - break; - case 2: - fAbsoluteX -= fWidth; - break; - default: - break; - } -} - bool CXFA_ItemLayoutProcessor::IncrementRelayoutNode( CXFA_LayoutProcessor* pLayoutProcessor, CXFA_Node* pNode, @@ -1568,20 +1567,20 @@ void CXFA_ItemLayoutProcessor::DoLayoutPageArea( CXFA_Node* pFormNode = pPageAreaLayoutItem->m_pFormNode; CXFA_Node* pCurChildNode = XFA_LAYOUT_INVALIDNODE; XFA_ItemLayoutProcessorStages nCurChildNodeStage = - XFA_ItemLayoutProcessorStages_None; + XFA_ItemLayoutProcessorStages::None; CXFA_LayoutItem* pBeforeItem = nullptr; for (GotoNextContainerNode(pCurChildNode, nCurChildNodeStage, pFormNode, false); pCurChildNode; GotoNextContainerNode(pCurChildNode, nCurChildNodeStage, pFormNode, false)) { - if (nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Container) + if (nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Container) continue; if (pCurChildNode->GetElementType() == XFA_Element::Variables) continue; auto pProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(pCurChildNode, nullptr); - pProcessor->DoLayout(false, XFA_LAYOUT_FLOAT_MAX); + pProcessor->DoLayout(false, FLT_MAX, FLT_MAX, nullptr); if (!pProcessor->HasLayoutItem()) continue; @@ -1654,7 +1653,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( int32_t iColIndex = 0; for (; m_pCurChildNode; GotoNextContainerNode( m_pCurChildNode, m_nCurChildNodeStage, m_pFormNode, false)) { - if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Container) + if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Container) continue; if (m_pCurChildNode->GetElementType() == XFA_Element::Variables) continue; @@ -1681,8 +1680,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( } } - pProcessor->DoLayout(false, XFA_LAYOUT_FLOAT_MAX, XFA_LAYOUT_FLOAT_MAX, - pContext); + pProcessor->DoLayout(false, FLT_MAX, FLT_MAX, pContext); if (!pProcessor->HasLayoutItem()) continue; @@ -1772,7 +1770,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { } FX_FLOAT fContentWidthLimit = - bContainerWidthAutoSize ? XFA_LAYOUT_FLOAT_MAX + bContainerWidthAutoSize ? FLT_MAX : fContainerWidth - fLeftInset - fRightInset; CFX_WideStringC wsColumnWidths; if (pLayoutNode->TryCData(XFA_ATTRIBUTE_ColumnWidths, wsColumnWidths)) { @@ -1806,13 +1804,12 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { m_pCurChildNode, m_nCurChildNodeStage, m_pFormNode, false)) { layoutContext.m_bCurColumnWidthAvaiable = false; layoutContext.m_fCurColumnWidth = 0; - if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Container) + if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Container) continue; auto pProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>( m_pCurChildNode, m_pPageMgr); - pProcessor->DoLayout(false, XFA_LAYOUT_FLOAT_MAX, XFA_LAYOUT_FLOAT_MAX, - pLayoutContext); + pProcessor->DoLayout(false, FLT_MAX, FLT_MAX, pLayoutContext); if (!pProcessor->HasLayoutItem()) continue; @@ -1882,15 +1879,12 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { continue; if (iColCount >= iSpecifiedColumnCount) { - for (int32_t j = 0, - c = iColCount + 1 - m_rgSpecifiedColumnWidths.GetSize(); - j < c; j++) { + int32_t c = iColCount + 1 - m_rgSpecifiedColumnWidths.GetSize(); + for (int32_t j = 0; j < c; j++) m_rgSpecifiedColumnWidths.Add(0); - } } - if (m_rgSpecifiedColumnWidths[iColCount] < XFA_LAYOUT_FLOAT_PERCISION) { + if (m_rgSpecifiedColumnWidths[iColCount] < XFA_LAYOUT_FLOAT_PERCISION) bAutoCol = true; - } if (bAutoCol && m_rgSpecifiedColumnWidths[iColCount] < rgRowItemsWidth[i]) { m_rgSpecifiedColumnWidths[iColCount] = rgRowItemsWidth[i]; @@ -1953,7 +1947,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { if (bContainerWidthAutoSize) { FX_FLOAT fChildSuppliedWidth = pLayoutChild->m_sPos.x + pLayoutChild->m_sSize.x; - if (fContentWidthLimit < XFA_LAYOUT_FLOAT_MAX && + if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { fChildSuppliedWidth = fContentWidthLimit; } @@ -2038,7 +2032,7 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepForSplite( } bAddedItemInRow = true; bForceEndPage = true; - result = XFA_ItemLayoutProcessorResult_PageFullBreak; + result = XFA_ItemLayoutProcessorResult::PageFullBreak; return true; } @@ -2135,7 +2129,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( bool bIsManualBreak = false; if (m_pCurChildPreprocessor) { m_pCurChildPreprocessor->m_ePreProcessRs = - XFA_ItemLayoutProcessorResult_Done; + XFA_ItemLayoutProcessorResult::Done; } CalculateContainerSpecfiedSize(m_pFormNode, fContainerWidth, fContainerHeight, @@ -2178,7 +2172,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset).ToUnit(XFA_UNIT_Pt); } FX_FLOAT fContentWidthLimit = - bContainerWidthAutoSize ? XFA_LAYOUT_FLOAT_MAX + bContainerWidthAutoSize ? FLT_MAX : fContainerWidth - fLeftInset - fRightInset; FX_FLOAT fContentCalculatedWidth = 0; FX_FLOAT fContentCalculatedHeight = 0; @@ -2190,7 +2184,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( FX_FLOAT fContentCurRowY = 0; CXFA_ContentLayoutItem* pLayoutChild = nullptr; if (m_pLayoutItem) { - if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Done && + if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Done && eFlowStrategy != XFA_ATTRIBUTEENUM_Tb) { pLayoutChild = (CXFA_ContentLayoutItem*)m_pLayoutItem->m_pFirstChild; for (CXFA_ContentLayoutItem* pLayoutNext = pLayoutChild; pLayoutNext; @@ -2223,22 +2217,22 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } fContentCurRowY += InsertKeepLayoutItems(); - if (m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages_None) { + if (m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages::None) { GotoNextContainerNode(m_pCurChildNode, m_nCurChildNodeStage, m_pFormNode, true); } fContentCurRowY += InsertPendingItems(this, m_pFormNode); if (m_pCurChildPreprocessor && - m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages_Container) { + m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages::Container) { if (ExistContainerKeep(m_pCurChildPreprocessor->GetFormNode(), false)) { m_pKeepHeadNode = m_pCurChildNode; m_bIsProcessKeep = true; - m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages_Keep; + m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages::Keep; } } - while (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages_Done) { + while (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Done) { FX_FLOAT fContentCurRowHeight = 0; FX_FLOAT fContentCurRowAvailWidth = fContentWidthLimit; m_fWidthLimite = fContentCurRowAvailWidth; @@ -2304,10 +2298,10 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( bool bAddedItemInRow = false; fContentCurRowY += InsertPendingItems(this, m_pFormNode); switch (m_nCurChildNodeStage) { - case XFA_ItemLayoutProcessorStages_Keep: - case XFA_ItemLayoutProcessorStages_None: + case XFA_ItemLayoutProcessorStages::Keep: + case XFA_ItemLayoutProcessorStages::None: break; - case XFA_ItemLayoutProcessorStages_BreakBefore: { + case XFA_ItemLayoutProcessorStages::BreakBefore: { for (int32_t iIndex = 0; iIndex < m_arrayKeepItems.GetSize(); iIndex++) { CXFA_ContentLayoutItem* pItem = m_arrayKeepItems.GetAt(iIndex); @@ -2341,11 +2335,10 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( InsertFlowedItem( this, pTempProcessor.get(), bContainerWidthAutoSize, bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, false, - XFA_LAYOUT_FLOAT_MAX, XFA_LAYOUT_FLOAT_MAX, fContentCurRowY, - fContentWidthLimit, fContentCurRowAvailWidth, - fContentCurRowHeight, bAddedItemInRow, bForceEndPage, - pContext); + uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, + FLT_MAX, fContentCurRowY, fContentWidthLimit, + fContentCurRowAvailWidth, fContentCurRowHeight, + bAddedItemInRow, bForceEndPage, pContext, false); } } GotoNextContainerNode(m_pCurChildNode, m_nCurChildNodeStage, @@ -2354,7 +2347,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( bIsManualBreak = true; goto SuspendAndCreateNewRow; } - case XFA_ItemLayoutProcessorStages_BreakAfter: { + case XFA_ItemLayoutProcessorStages::BreakAfter: { CXFA_Node* pLeaderNode = nullptr; CXFA_Node* pTrailerNode = nullptr; bool bCreatePage = false; @@ -2369,13 +2362,13 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( if (JudgeLeaderOrTrailerForOccur(pTrailerNode)) { auto pTempProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>( pTrailerNode, nullptr); - InsertFlowedItem( - this, pTempProcessor.get(), bContainerWidthAutoSize, - bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, false, - XFA_LAYOUT_FLOAT_MAX, XFA_LAYOUT_FLOAT_MAX, fContentCurRowY, - fContentWidthLimit, fContentCurRowAvailWidth, - fContentCurRowHeight, bAddedItemInRow, bForceEndPage, pContext); + InsertFlowedItem(this, pTempProcessor.get(), + bContainerWidthAutoSize, bContainerHeightAutoSize, + fContainerHeight, eFlowStrategy, uCurHAlignState, + rgCurLineLayoutItems, false, FLT_MAX, FLT_MAX, + fContentCurRowY, fContentWidthLimit, + fContentCurRowAvailWidth, fContentCurRowHeight, + bAddedItemInRow, bForceEndPage, pContext, false); } if (!bCreatePage) { if (JudgeLeaderOrTrailerForOccur(pLeaderNode)) { @@ -2383,7 +2376,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( rgCurLineLayoutItems, eFlowStrategy, bContainerHeightAutoSize, bContainerWidthAutoSize, fContentCalculatedWidth, fContentCalculatedHeight, fContentCurRowY, - fContentCurRowHeight, fContentWidthLimit); + fContentCurRowHeight, fContentWidthLimit, false); rgCurLineLayoutItems->RemoveAll(); auto pTempProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(pLeaderNode, @@ -2391,11 +2384,10 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( InsertFlowedItem( this, pTempProcessor.get(), bContainerWidthAutoSize, bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, false, - XFA_LAYOUT_FLOAT_MAX, XFA_LAYOUT_FLOAT_MAX, fContentCurRowY, - fContentWidthLimit, fContentCurRowAvailWidth, - fContentCurRowHeight, bAddedItemInRow, bForceEndPage, - pContext); + uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, + FLT_MAX, fContentCurRowY, fContentWidthLimit, + fContentCurRowAvailWidth, fContentCurRowHeight, + bAddedItemInRow, bForceEndPage, pContext, false); } } else { if (JudgeLeaderOrTrailerForOccur(pLeaderNode)) @@ -2407,12 +2399,12 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( if (bCreatePage) { bForceEndPage = true; bIsManualBreak = true; - if (m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages_Done) + if (m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages::Done) bBreakDone = true; } goto SuspendAndCreateNewRow; } - case XFA_ItemLayoutProcessorStages_BookendLeader: { + case XFA_ItemLayoutProcessorStages::BookendLeader: { CXFA_Node* pLeaderNode = nullptr; if (m_pCurChildPreprocessor) { pProcessor.reset(m_pCurChildPreprocessor); @@ -2432,7 +2424,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( fAvailHeight, fRealHeight, fContentCurRowY, fContentWidthLimit, fContentCurRowAvailWidth, fContentCurRowHeight, bAddedItemInRow, bForceEndPage, - pContext) != XFA_ItemLayoutProcessorResult_Done) { + pContext, false) != XFA_ItemLayoutProcessorResult::Done) { goto SuspendAndCreateNewRow; } else { pProcessor.reset(); @@ -2440,7 +2432,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } break; } - case XFA_ItemLayoutProcessorStages_BookendTrailer: { + case XFA_ItemLayoutProcessorStages::BookendTrailer: { CXFA_Node* pTrailerNode = nullptr; if (m_pCurChildPreprocessor) { pProcessor.reset(m_pCurChildPreprocessor); @@ -2459,7 +2451,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( fAvailHeight, fRealHeight, fContentCurRowY, fContentWidthLimit, fContentCurRowAvailWidth, fContentCurRowHeight, bAddedItemInRow, bForceEndPage, - pContext) != XFA_ItemLayoutProcessorResult_Done) { + pContext, false) != XFA_ItemLayoutProcessorResult::Done) { goto SuspendAndCreateNewRow; } else { pProcessor.reset(); @@ -2467,7 +2459,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } break; } - case XFA_ItemLayoutProcessorStages_Container: { + case XFA_ItemLayoutProcessorStages::Container: { ASSERT(m_pCurChildNode->IsContainerNode()); if (m_pCurChildNode->GetElementType() == XFA_Element::Variables) break; @@ -2498,13 +2490,13 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( fContentCurRowAvailWidth, fContentCurRowHeight, bAddedItemInRow, bForceEndPage, pContext, bNewRow); switch (rs) { - case XFA_ItemLayoutProcessorResult_ManualBreak: + case XFA_ItemLayoutProcessorResult::ManualBreak: bIsManualBreak = true; - case XFA_ItemLayoutProcessorResult_PageFullBreak: + case XFA_ItemLayoutProcessorResult::PageFullBreak: bForceEndPage = true; - case XFA_ItemLayoutProcessorResult_RowFullBreak: + case XFA_ItemLayoutProcessorResult::RowFullBreak: goto SuspendAndCreateNewRow; - case XFA_ItemLayoutProcessorResult_Done: + case XFA_ItemLayoutProcessorResult::Done: default: fContentCurRowY += InsertPendingItems(pProcessor.get(), m_pCurChildNode); @@ -2512,7 +2504,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } break; } - case XFA_ItemLayoutProcessorStages_Done: + case XFA_ItemLayoutProcessorStages::Done: break; default: break; @@ -2539,8 +2531,9 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( break; } - bool bRetValue = m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages_Done && - m_PendingNodes.empty(); + bool bRetValue = + m_nCurChildNodeStage == XFA_ItemLayoutProcessorStages::Done && + m_PendingNodes.empty(); if (bBreakDone) bRetValue = false; @@ -2564,9 +2557,9 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } return bRetValue - ? XFA_ItemLayoutProcessorResult_Done - : (bIsManualBreak ? XFA_ItemLayoutProcessorResult_ManualBreak - : XFA_ItemLayoutProcessorResult_PageFullBreak); + ? XFA_ItemLayoutProcessorResult::Done + : (bIsManualBreak ? XFA_ItemLayoutProcessorResult::ManualBreak + : XFA_ItemLayoutProcessorResult::PageFullBreak); } bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( @@ -2709,7 +2702,7 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( fContentCurRowY += fContentCurRowHeight; if (bContainerWidthAutoSize) { FX_FLOAT fChildSuppliedWidth = fGroupWidths[0]; - if (fContentWidthLimit < XFA_LAYOUT_FLOAT_MAX && + if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { fChildSuppliedWidth = fContentWidthLimit; } @@ -2787,33 +2780,26 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayout( case XFA_ATTRIBUTEENUM_Rl_row: default: DoLayoutPositionedContainer(pContext); - m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages_Done; - return XFA_ItemLayoutProcessorResult_Done; + m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages::Done; + return XFA_ItemLayoutProcessorResult::Done; case XFA_ATTRIBUTEENUM_Table: DoLayoutTableContainer(pLayoutNode); - m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages_Done; - return XFA_ItemLayoutProcessorResult_Done; + m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages::Done; + return XFA_ItemLayoutProcessorResult::Done; } } case XFA_Element::Draw: case XFA_Element::Field: DoLayoutField(); - m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages_Done; - return XFA_ItemLayoutProcessorResult_Done; + m_nCurChildNodeStage = XFA_ItemLayoutProcessorStages::Done; + return XFA_ItemLayoutProcessorResult::Done; case XFA_Element::ContentArea: - return XFA_ItemLayoutProcessorResult_Done; + return XFA_ItemLayoutProcessorResult::Done; default: - return XFA_ItemLayoutProcessorResult_Done; + return XFA_ItemLayoutProcessorResult::Done; } } -void CXFA_ItemLayoutProcessor::GetCurrentComponentPos(FX_FLOAT& fAbsoluteX, - FX_FLOAT& fAbsoluteY) { - ASSERT(m_pLayoutItem); - fAbsoluteX = m_pLayoutItem->m_sPos.x; - fAbsoluteY = m_pLayoutItem->m_sPos.y; -} - void CXFA_ItemLayoutProcessor::GetCurrentComponentSize(FX_FLOAT& fWidth, FX_FLOAT& fHeight) { ASSERT(m_pLayoutItem); diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.h b/xfa/fxfa/parser/xfa_layout_itemlayout.h index b18706b521..b7b35122df 100644 --- a/xfa/fxfa/parser/xfa_layout_itemlayout.h +++ b/xfa/fxfa/parser/xfa_layout_itemlayout.h @@ -17,7 +17,6 @@ #define XFA_LAYOUT_INVALIDNODE ((CXFA_Node*)(intptr_t)-1) #define XFA_LAYOUT_FLOAT_PERCISION (0.0005f) -#define XFA_LAYOUT_FLOAT_MAX FLT_MAX class CXFA_ContainerLayoutItem; class CXFA_ContentLayoutItem; @@ -26,22 +25,22 @@ class CXFA_LayoutPageMgr; class CXFA_LayoutProcessor; class CXFA_Node; -enum XFA_ItemLayoutProcessorResult { - XFA_ItemLayoutProcessorResult_Done, - XFA_ItemLayoutProcessorResult_PageFullBreak, - XFA_ItemLayoutProcessorResult_RowFullBreak, - XFA_ItemLayoutProcessorResult_ManualBreak, +enum class XFA_ItemLayoutProcessorResult { + Done, + PageFullBreak, + RowFullBreak, + ManualBreak, }; -enum XFA_ItemLayoutProcessorStages { - XFA_ItemLayoutProcessorStages_None, - XFA_ItemLayoutProcessorStages_BookendLeader, - XFA_ItemLayoutProcessorStages_BreakBefore, - XFA_ItemLayoutProcessorStages_Keep, - XFA_ItemLayoutProcessorStages_Container, - XFA_ItemLayoutProcessorStages_BreakAfter, - XFA_ItemLayoutProcessorStages_BookendTrailer, - XFA_ItemLayoutProcessorStages_Done, +enum class XFA_ItemLayoutProcessorStages { + None, + BookendLeader, + BreakBefore, + Keep, + Container, + BreakAfter, + BookendTrailer, + Done, }; class CXFA_LayoutContext { @@ -52,7 +51,8 @@ class CXFA_LayoutContext { m_bCurColumnWidthAvaiable(false), m_pOverflowProcessor(nullptr), m_pOverflowNode(nullptr) {} - ~CXFA_LayoutContext() { m_pOverflowProcessor = nullptr; } + ~CXFA_LayoutContext() {} + CFX_ArrayTemplate<FX_FLOAT>* m_prgSpecifiedColumnWidths; FX_FLOAT m_fCurColumnWidth; bool m_bCurColumnWidthAvaiable; @@ -67,45 +67,25 @@ class CXFA_ItemLayoutProcessor { static bool IncrementRelayoutNode(CXFA_LayoutProcessor* pLayoutProcessor, CXFA_Node* pNode, CXFA_Node* pParentNode); - static void CalculatePositionedContainerPos(CXFA_Node* pNode, - FX_FLOAT fWidth, - FX_FLOAT fHeight, - FX_FLOAT& fAbsoluteX, - FX_FLOAT& fAbsoluteY); - static bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, - FX_FLOAT fCurVerticalOffset, - FX_FLOAT& fProposedSplitPos, - bool& bAppChange, - bool bCalculateMargin); CXFA_ItemLayoutProcessor(CXFA_Node* pNode, CXFA_LayoutPageMgr* pPageMgr); ~CXFA_ItemLayoutProcessor(); - XFA_ItemLayoutProcessorResult DoLayout( - bool bUseBreakControl, - FX_FLOAT fHeightLimit, - FX_FLOAT fRealHeight = XFA_LAYOUT_FLOAT_MAX, - CXFA_LayoutContext* pContext = nullptr); - - void GetCurrentComponentPos(FX_FLOAT& fAbsoluteX, FX_FLOAT& fAbsoluteY); + XFA_ItemLayoutProcessorResult DoLayout(bool bUseBreakControl, + FX_FLOAT fHeightLimit, + FX_FLOAT fRealHeight, + CXFA_LayoutContext* pContext); + void DoLayoutPageArea(CXFA_ContainerLayoutItem* pPageAreaLayoutItem); void GetCurrentComponentSize(FX_FLOAT& fWidth, FX_FLOAT& fHeight); - void SetCurrentComponentPos(FX_FLOAT fAbsoluteX, FX_FLOAT fAbsoluteY); - - void SetCurrentComponentSize(FX_FLOAT fWidth, FX_FLOAT fHeight); CXFA_Node* GetFormNode() { return m_pFormNode; } bool HasLayoutItem() { return !!m_pLayoutItem; } CXFA_ContentLayoutItem* ExtractLayoutItem(); + void SplitLayoutItem(FX_FLOAT fSplitPos); FX_FLOAT FindSplitPos(FX_FLOAT fProposedSplitPos); - void SplitLayoutItem(CXFA_ContentLayoutItem* pLayoutItem, - CXFA_ContentLayoutItem* pSecondParent, - FX_FLOAT fSplitPos); - void SplitLayoutItem(FX_FLOAT fSplitPos); - bool JudgePutNextPage(CXFA_ContentLayoutItem* pParentLayoutItem, - FX_FLOAT fChildHeight, - CFX_ArrayTemplate<CXFA_ContentLayoutItem*>& pKeepItems); + bool ProcessKeepForSplite( CXFA_ItemLayoutProcessor* pParentProcessor, CXFA_ItemLayoutProcessor* pChildProcessor, @@ -117,8 +97,37 @@ class CXFA_ItemLayoutProcessor { bool& bAddedItemInRow, bool& bForceEndPage, XFA_ItemLayoutProcessorResult& result); + void ProcessUnUseOverFlow(CXFA_Node* pLeaderNode, + CXFA_Node* pTrailerNode, + CXFA_ContentLayoutItem* pTrailerItem, + CXFA_Node* pFormNode); + bool IsAddNewRowForTrailer(CXFA_ContentLayoutItem* pTrailerItem); + bool JudgeLeaderOrTrailerForOccur(CXFA_Node* pFormNode); + + CXFA_ContentLayoutItem* CreateContentLayoutItem(CXFA_Node* pFormNode); + + CXFA_Node* m_pFormNode; + CXFA_ContentLayoutItem* m_pLayoutItem; + CXFA_Node* m_pCurChildNode; + FX_FLOAT m_fUsedSize; + CXFA_LayoutPageMgr* m_pPageMgr; + std::list<CXFA_Node*> m_PendingNodes; + bool m_bBreakPending; + CFX_ArrayTemplate<FX_FLOAT> m_rgSpecifiedColumnWidths; + CFX_ArrayTemplate<CXFA_ContentLayoutItem*> m_arrayKeepItems; + FX_FLOAT m_fLastRowWidth; + FX_FLOAT m_fLastRowY; + bool m_bUseInheriated; + XFA_ItemLayoutProcessorResult m_ePreProcessRs; + + private: + void SetCurrentComponentPos(FX_FLOAT fAbsoluteX, FX_FLOAT fAbsoluteY); + void SetCurrentComponentSize(FX_FLOAT fWidth, FX_FLOAT fHeight); + + void SplitLayoutItem(CXFA_ContentLayoutItem* pLayoutItem, + CXFA_ContentLayoutItem* pSecondParent, + FX_FLOAT fSplitPos); FX_FLOAT InsertKeepLayoutItems(); - void DoLayoutPageArea(CXFA_ContainerLayoutItem* pPageAreaLayoutItem); bool CalculateRowChildPosition( CFX_ArrayTemplate<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], XFA_ATTRIBUTEENUM eFlowStrategy, @@ -129,28 +138,23 @@ class CXFA_ItemLayoutProcessor { FX_FLOAT& fContentCurRowY, FX_FLOAT fContentCurRowHeight, FX_FLOAT fContentWidthLimit, - bool bRootForceTb = false); - - void ProcessUnUseOverFlow(CXFA_Node* pLeaderNode, - CXFA_Node* pTrailerNode, - CXFA_ContentLayoutItem* pTrailerItem, - CXFA_Node* pFormNode); + bool bRootForceTb); void ProcessUnUseBinds(CXFA_Node* pFormNode); - bool IsAddNewRowForTrailer(CXFA_ContentLayoutItem* pTrailerItem); - bool JudgeLeaderOrTrailerForOccur(CXFA_Node* pFormNode); - CXFA_ContentLayoutItem* CreateContentLayoutItem(CXFA_Node* pFormNode); + bool JudgePutNextPage(CXFA_ContentLayoutItem* pParentLayoutItem, + FX_FLOAT fChildHeight, + CFX_ArrayTemplate<CXFA_ContentLayoutItem*>& pKeepItems); - private: - void DoLayoutPositionedContainer(CXFA_LayoutContext* pContext = nullptr); + void DoLayoutPositionedContainer(CXFA_LayoutContext* pContext); void DoLayoutTableContainer(CXFA_Node* pLayoutNode); XFA_ItemLayoutProcessorResult DoLayoutFlowedContainer( bool bUseBreakControl, XFA_ATTRIBUTEENUM eFlowStrategy, FX_FLOAT fHeightLimit, FX_FLOAT fRealHeight, - CXFA_LayoutContext* pContext = nullptr, - bool bRootForceTb = false); + CXFA_LayoutContext* pContext, + bool bRootForceTb); void DoLayoutField(); + void GotoNextContainerNode(CXFA_Node*& pCurActionNode, XFA_ItemLayoutProcessorStages& nCurStage, CXFA_Node* pParentContainer, @@ -167,29 +171,15 @@ class CXFA_ItemLayoutProcessor { CXFA_Node* GetSubformSetParent(CXFA_Node* pSubformSet); - public: bool m_bKeepBreakFinish; bool m_bIsProcessKeep; CXFA_Node* m_pKeepHeadNode; CXFA_Node* m_pKeepTailNode; - CXFA_Node* m_pFormNode; - CXFA_ContentLayoutItem* m_pLayoutItem; CXFA_ContentLayoutItem* m_pOldLayoutItem; - CXFA_Node* m_pCurChildNode; CXFA_ItemLayoutProcessor* m_pCurChildPreprocessor; XFA_ItemLayoutProcessorStages m_nCurChildNodeStage; - FX_FLOAT m_fUsedSize; - CXFA_LayoutPageMgr* m_pPageMgr; - std::list<CXFA_Node*> m_PendingNodes; - bool m_bBreakPending; - CFX_ArrayTemplate<FX_FLOAT> m_rgSpecifiedColumnWidths; - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> m_arrayKeepItems; std::map<CXFA_Node*, int32_t> m_PendingNodesCount; - FX_FLOAT m_fLastRowWidth; - FX_FLOAT m_fLastRowY; FX_FLOAT m_fWidthLimite; - bool m_bUseInheriated; - XFA_ItemLayoutProcessorResult m_ePreProcessRs; bool m_bHasAvailHeight; }; |