Rename CXFA_LayoutItem methods to match fxcrt::TreeNode.
Minimize disruption when switching to TreeNode.
Only functional change is to re-order the arguments of InsertAfter().
Change-Id: I09c54fd6a2616118c64a9cfc9764233481db3008
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54030
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
index a07e396..12e8a28 100644
--- a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
@@ -709,7 +709,7 @@
bool bOrphanedItem = false;
if (pSecondParent) {
- pSecondParent->AddChild(pSecondLayoutItem);
+ pSecondParent->AppendLastChild(pSecondLayoutItem);
if (fCurTopMargin > 0 && pLayoutItem->GetFirstChild()) {
pSecondParent->m_sSize.height += fCurTopMargin;
for (CXFA_LayoutItem* pParentIter = pSecondParent->GetParent();
@@ -723,7 +723,7 @@
}
}
} else if (pLayoutItem->GetParent()) {
- pLayoutItem->GetParent()->InsertChild(pLayoutItem, pSecondLayoutItem);
+ pLayoutItem->GetParent()->InsertAfter(pSecondLayoutItem, pLayoutItem);
} else {
// Parentless |pLayoutitem| would like to have |pSecondLayoutItem| as a
// sibling, but that would violate the tree invariant. Instead, keep
@@ -748,7 +748,7 @@
pChildItem->m_sPos.y -= fSplitPos - fCurBottomMargin;
pChildItem->m_sPos.y += lHeightForKeep;
pChildItem->m_sPos.y += fAddMarginHeight;
- pSecondLayoutItem->AddChild(pChildItem);
+ pSecondLayoutItem->AppendLastChild(pChildItem);
continue;
}
if (lHeightForKeep < kXFALayoutPrecision) {
@@ -764,19 +764,19 @@
if (pSecondParent)
pSecondParent->m_sSize.height += pPreItem->m_sSize.height;
}
- pSecondLayoutItem->AddChild(pPreItem);
+ pSecondLayoutItem->AppendLastChild(pPreItem);
}
}
pChildItem->m_sPos.y -= fSplitPos;
pChildItem->m_sPos.y += lHeightForKeep;
pChildItem->m_sPos.y += fAddMarginHeight;
- pSecondLayoutItem->AddChild(pChildItem);
+ pSecondLayoutItem->AppendLastChild(pChildItem);
continue;
}
if (fSplitPos + kXFALayoutPrecision >= fCurTopMargin + fCurBottomMargin +
pChildItem->m_sPos.y +
pChildItem->m_sSize.height) {
- pLayoutItem->AddChild(pChildItem);
+ pLayoutItem->AppendLastChild(pChildItem);
if (ExistContainerKeep(pChildItem->GetFormNode(), false))
keepLayoutItems.push_back(pChildItem);
else
@@ -789,10 +789,10 @@
pChildItem, pSecondLayoutItem,
fSplitPos - fCurTopMargin - fCurBottomMargin - pChildItem->m_sPos.y);
fAddMarginHeight = pSecondLayoutItem->m_sSize.height - fOldHeight;
- pLayoutItem->AddChild(pChildItem);
+ pLayoutItem->AppendLastChild(pChildItem);
}
if (bOrphanedItem)
- pLayoutItem->AddChild(pSecondLayoutItem);
+ pLayoutItem->AppendLastChild(pSecondLayoutItem);
}
void CXFA_ItemLayoutProcessor::SplitLayoutItem(float fSplitPos) {
@@ -996,9 +996,9 @@
pCurChildNode, pProcessor->GetCurrentComponentSize()));
CXFA_LayoutItem* pProcessItem = pProcessor->ExtractLayoutItem();
if (!pBeforeItem)
- pPageAreaLayoutItem->AddHeadChild(pProcessItem);
+ pPageAreaLayoutItem->AppendFirstChild(pProcessItem);
else
- pPageAreaLayoutItem->InsertChild(pBeforeItem, pProcessItem);
+ pPageAreaLayoutItem->InsertAfter(pProcessItem, pBeforeItem);
pBeforeItem = pProcessItem;
}
@@ -1017,9 +1017,9 @@
CXFA_LayoutItem* pNextLayoutItem = pLayoutItem->GetNextSibling();
pPageAreaLayoutItem->RemoveChild(pLayoutItem);
if (!pBeforeItem)
- pPageAreaLayoutItem->AddHeadChild(pLayoutItem);
+ pPageAreaLayoutItem->AppendFirstChild(pLayoutItem);
else
- pPageAreaLayoutItem->InsertChild(pBeforeItem, pLayoutItem);
+ pPageAreaLayoutItem->InsertAfter(pLayoutItem, pBeforeItem);
pBeforeItem = pLayoutItem;
pLayoutItem = pNextLayoutItem;
@@ -1117,7 +1117,7 @@
}
}
}
- m_pLayoutItem->AddChild(pProcessor->ExtractLayoutItem());
+ m_pLayoutItem->AppendLastChild(pProcessor->ExtractLayoutItem());
}
XFA_VERSION eVersion = GetFormNode()->GetDocument()->GetCurVersionMode();
@@ -1194,7 +1194,7 @@
if (!pProcessor->HasLayoutItem())
continue;
- m_pLayoutItem->AddChild(pProcessor->ExtractLayoutItem());
+ m_pLayoutItem->AppendLastChild(pProcessor->ExtractLayoutItem());
}
int32_t iRowCount = 0;
@@ -1915,7 +1915,7 @@
if (rgCurLineLayoutItems[0][j]->GetFormNode()->PresenceRequiresSpace())
fCurPos += rgCurLineLayoutItems[0][j]->m_sSize.width;
}
- m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]);
+ m_pLayoutItem->AppendLastChild(rgCurLineLayoutItems[0][j]);
m_fLastRowWidth = fCurPos;
}
fCurPos = (fContentWidthLimit + fGroupWidths[0] - fGroupWidths[1] -
@@ -1932,7 +1932,7 @@
if (rgCurLineLayoutItems[1][j]->GetFormNode()->PresenceRequiresSpace())
fCurPos += rgCurLineLayoutItems[1][j]->m_sSize.width;
}
- m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]);
+ m_pLayoutItem->AppendLastChild(rgCurLineLayoutItems[1][j]);
m_fLastRowWidth = fCurPos;
}
fCurPos = fContentWidthLimit - fGroupWidths[2];
@@ -1947,7 +1947,7 @@
if (rgCurLineLayoutItems[2][j]->GetFormNode()->PresenceRequiresSpace())
fCurPos += rgCurLineLayoutItems[2][j]->m_sSize.width;
}
- m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]);
+ m_pLayoutItem->AppendLastChild(rgCurLineLayoutItems[2][j]);
m_fLastRowWidth = fCurPos;
}
} else {
@@ -1959,7 +1959,7 @@
rgCurLineLayoutItems[0][j]->m_sPos =
CFX_PointF(fCurPos, *fContentCurRowY);
- m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]);
+ m_pLayoutItem->AppendLastChild(rgCurLineLayoutItems[0][j]);
m_fLastRowWidth = fCurPos;
}
fCurPos = (fContentWidthLimit + fGroupWidths[0] + fGroupWidths[1] -
@@ -1971,7 +1971,7 @@
rgCurLineLayoutItems[1][j]->m_sPos =
CFX_PointF(fCurPos, *fContentCurRowY);
- m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]);
+ m_pLayoutItem->AppendLastChild(rgCurLineLayoutItems[1][j]);
m_fLastRowWidth = fCurPos;
}
fCurPos = fContentWidthLimit;
@@ -1981,7 +1981,7 @@
rgCurLineLayoutItems[2][j]->m_sPos =
CFX_PointF(fCurPos, *fContentCurRowY);
- m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]);
+ m_pLayoutItem->AppendLastChild(rgCurLineLayoutItems[2][j]);
m_fLastRowWidth = fCurPos;
}
}
@@ -2160,7 +2160,7 @@
pTrailerLayoutItem->m_sPos.y = m_fLastRowY;
pTrailerLayoutItem->m_sPos.x = m_fLastRowWidth;
m_pLayoutItem->m_sSize.width += pTrailerLayoutItem->m_sSize.width;
- m_pLayoutItem->AddChild(pTrailerLayoutItem);
+ m_pLayoutItem->AppendLastChild(pTrailerLayoutItem);
return;
}
@@ -2194,7 +2194,7 @@
break;
}
m_pLayoutItem->m_sSize.height += fHeight;
- m_pLayoutItem->AddChild(pTrailerLayoutItem);
+ m_pLayoutItem->AppendLastChild(pTrailerLayoutItem);
}
void CXFA_ItemLayoutProcessor::AddLeaderAfterSplit(
@@ -2241,7 +2241,7 @@
break;
}
m_pLayoutItem->m_sSize.height += fHeight;
- m_pLayoutItem->AddChild(pLeaderLayoutItem);
+ m_pLayoutItem->AppendLastChild(pLeaderLayoutItem);
}
void CXFA_ItemLayoutProcessor::AddPendingNode(CXFA_Node* pPendingNode,
diff --git a/xfa/fxfa/layout/cxfa_layoutitem.cpp b/xfa/fxfa/layout/cxfa_layoutitem.cpp
index af586b9..1a7798c 100644
--- a/xfa/fxfa/layout/cxfa_layoutitem.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutitem.cpp
@@ -84,7 +84,7 @@
}
return nullptr;
}
-void CXFA_LayoutItem::AddChild(CXFA_LayoutItem* pChildItem) {
+void CXFA_LayoutItem::AppendLastChild(CXFA_LayoutItem* pChildItem) {
if (pChildItem->m_pParent)
pChildItem->m_pParent->RemoveChild(pChildItem);
@@ -101,7 +101,7 @@
pExistingChildItem->m_pNextSibling = pChildItem;
}
-void CXFA_LayoutItem::AddHeadChild(CXFA_LayoutItem* pChildItem) {
+void CXFA_LayoutItem::AppendFirstChild(CXFA_LayoutItem* pChildItem) {
if (pChildItem->m_pParent)
pChildItem->m_pParent->RemoveChild(pChildItem);
@@ -116,18 +116,19 @@
m_pFirstChild->m_pNextSibling = pExistingChildItem;
}
-void CXFA_LayoutItem::InsertChild(CXFA_LayoutItem* pBeforeItem,
- CXFA_LayoutItem* pChildItem) {
- if (pBeforeItem->m_pParent != this)
+void CXFA_LayoutItem::InsertAfter(CXFA_LayoutItem* pThisChild,
+ CXFA_LayoutItem* pThatChild) {
+ if (pThatChild->m_pParent != this)
return;
- if (pChildItem->m_pParent)
- pChildItem->m_pParent = nullptr;
- pChildItem->m_pParent = this;
+ if (pThisChild->m_pParent)
+ pThisChild->m_pParent = nullptr;
- CXFA_LayoutItem* pExistingChildItem = pBeforeItem->m_pNextSibling;
- pBeforeItem->m_pNextSibling = pChildItem;
- pChildItem->m_pNextSibling = pExistingChildItem;
+ pThisChild->m_pParent = this;
+
+ CXFA_LayoutItem* pExistingChild = pThatChild->m_pNextSibling;
+ pThatChild->m_pNextSibling = pThisChild;
+ pThisChild->m_pNextSibling = pExistingChild;
}
void CXFA_LayoutItem::RemoveChild(CXFA_LayoutItem* pChildItem) {
diff --git a/xfa/fxfa/layout/cxfa_layoutitem.h b/xfa/fxfa/layout/cxfa_layoutitem.h
index c5fd157..3319942 100644
--- a/xfa/fxfa/layout/cxfa_layoutitem.h
+++ b/xfa/fxfa/layout/cxfa_layoutitem.h
@@ -32,10 +32,12 @@
CXFA_Node* GetFormNode() const { return m_pFormNode.Get(); }
void SetFormNode(CXFA_Node* pNode) { m_pFormNode = pNode; }
- void AddChild(CXFA_LayoutItem* pChildItem);
- void AddHeadChild(CXFA_LayoutItem* pChildItem);
+ void AppendLastChild(CXFA_LayoutItem* pChildItem);
+ void AppendFirstChild(CXFA_LayoutItem* pChildItem);
void RemoveChild(CXFA_LayoutItem* pChildItem);
- void InsertChild(CXFA_LayoutItem* pBeforeItem, CXFA_LayoutItem* pChildItem);
+
+ // Insert |pThisChild| after |pThatChild|.
+ void InsertAfter(CXFA_LayoutItem* pThisChild, CXFA_LayoutItem* pThatChild);
protected:
enum ItemType { kViewItem, kContentItem };
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
index c4a3db9..d9c4e11 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
@@ -164,7 +164,7 @@
return;
pParentLayoutItem->RemoveChild(pLayoutItem);
- pParentLayoutItem->AddChild(pLayoutItem);
+ pParentLayoutItem->AppendLastChild(pLayoutItem);
}
void RemoveLayoutItem(CXFA_LayoutItem* pLayoutItem) {
@@ -558,7 +558,8 @@
CXFA_ContentLayoutItem* pContentLayoutItem,
CXFA_ItemLayoutProcessor::Result eStatus) {
if (pContentLayoutItem) {
- GetCurrentViewRecord()->pCurContentArea->AddChild(pContentLayoutItem);
+ GetCurrentViewRecord()->pCurContentArea->AppendLastChild(
+ pContentLayoutItem);
m_bCreateOverFlowPage = false;
}
@@ -604,7 +605,7 @@
CXFA_ViewLayoutItem* pPageSetLayoutItem =
new CXFA_ViewLayoutItem(pPageSet, nullptr);
pPageSet->JSObject()->SetLayoutItem(pPageSetLayoutItem);
- m_pPageSetLayoutItemRoot->AddChild(pPageSetLayoutItem);
+ m_pPageSetLayoutItemRoot->AppendLastChild(pPageSetLayoutItem);
pNewRecord->pCurPageSet = pPageSetLayoutItem;
}
return AppendNewRecord(std::move(pNewRecord));
@@ -645,10 +646,10 @@
while (pPrePageSet->GetNextSibling()) {
pPrePageSet = pPrePageSet->GetNextSibling()->AsViewLayoutItem();
}
- pPrePageSet->GetParent()->InsertChild(pPrePageSet, pPageSetLayoutItem);
+ pPrePageSet->GetParent()->InsertAfter(pPageSetLayoutItem, pPrePageSet);
m_pPageSetCurRoot = pPageSetLayoutItem;
} else {
- pParentPageSetLayout->AddChild(pPageSetLayoutItem);
+ pParentPageSetLayout->AppendLastChild(pPageSetLayoutItem);
}
pNewRecord->pCurPageSet = pPageSetLayoutItem;
return AppendNewRecord(std::move(pNewRecord));
@@ -682,7 +683,7 @@
pNotify->OnPageEvent(pViewItem, XFA_PAGEVIEWEVENT_PostRemoved);
pNewPageAreaLayoutItem = pViewItem;
}
- pNewRecord->pCurPageSet->AddChild(pNewPageAreaLayoutItem);
+ pNewRecord->pCurPageSet->AppendLastChild(pNewPageAreaLayoutItem);
pNewRecord->pCurPageArea = pNewPageAreaLayoutItem;
pNewRecord->pCurContentArea = nullptr;
}
@@ -696,7 +697,7 @@
CXFA_ViewLayoutItem* pNewViewLayoutItem =
new CXFA_ViewLayoutItem(pContentArea, nullptr);
ASSERT(pNewRecord->pCurPageArea);
- pNewRecord->pCurPageArea->AddChild(pNewViewLayoutItem);
+ pNewRecord->pCurPageArea->AppendLastChild(pNewViewLayoutItem);
pNewRecord->pCurContentArea = pNewViewLayoutItem;
}