summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_layoutitem.cpp
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2017-02-04 11:12:46 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-02-06 16:52:23 +0000
commite5f4f22e4c67f40123bca91c2213223cc5a12ebd (patch)
tree6edca38b1c3aedeee265917c7b984f5256b3e6f2 /xfa/fxfa/parser/cxfa_layoutitem.cpp
parentaaf0bdc5bf420d08dfcbb049c4511c55eec0dd6c (diff)
downloadpdfium-e5f4f22e4c67f40123bca91c2213223cc5a12ebd.tar.xz
Cleanup xfa layout code
Split XFA layout code into correct files, move static methods into anonymous namespace blocks. Cleanup formatting where possible. Change-Id: Ia342d7db42f947db02a52aa86bfa69e4fda916fd Reviewed-on: https://pdfium-review.googlesource.com/2512 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_layoutitem.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_layoutitem.cpp173
1 files changed, 173 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_layoutitem.cpp b/xfa/fxfa/parser/cxfa_layoutitem.cpp
index 264fe4e1b6..55aa285e2d 100644
--- a/xfa/fxfa/parser/cxfa_layoutitem.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutitem.cpp
@@ -9,6 +9,7 @@
#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_containerlayoutitem.h"
#include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
+#include "xfa/fxfa/parser/cxfa_measurement.h"
void XFA_ReleaseLayoutItem(CXFA_LayoutItem* pLayoutItem) {
CXFA_LayoutItem* pNode = pLayoutItem->m_pFirstChild;
@@ -45,7 +46,179 @@ CXFA_ContainerLayoutItem* CXFA_LayoutItem::AsContainerLayoutItem() {
return IsContainerLayoutItem() ? static_cast<CXFA_ContainerLayoutItem*>(this)
: nullptr;
}
+
CXFA_ContentLayoutItem* CXFA_LayoutItem::AsContentLayoutItem() {
return IsContentLayoutItem() ? static_cast<CXFA_ContentLayoutItem*>(this)
: nullptr;
}
+
+CXFA_ContainerLayoutItem* CXFA_LayoutItem::GetPage() const {
+ for (CXFA_LayoutItem* pCurNode = const_cast<CXFA_LayoutItem*>(this); pCurNode;
+ pCurNode = pCurNode->m_pParent) {
+ if (pCurNode->m_pFormNode->GetElementType() == XFA_Element::PageArea)
+ return static_cast<CXFA_ContainerLayoutItem*>(pCurNode);
+ }
+ return nullptr;
+}
+
+void CXFA_LayoutItem::GetRect(CFX_RectF& rtLayout, bool bRelative) const {
+ ASSERT(m_bIsContentLayoutItem);
+
+ const CXFA_ContentLayoutItem* pThis =
+ static_cast<const CXFA_ContentLayoutItem*>(this);
+ CFX_PointF sPos = pThis->m_sPos;
+ CFX_SizeF sSize = pThis->m_sSize;
+ if (bRelative) {
+ rtLayout.Set(sPos.x, sPos.y, sSize.x, sSize.y);
+ return;
+ }
+
+ for (CXFA_LayoutItem* pLayoutItem = pThis->m_pParent; pLayoutItem;
+ pLayoutItem = pLayoutItem->m_pParent) {
+ if (CXFA_ContentLayoutItem* pContent = pLayoutItem->AsContentLayoutItem()) {
+ sPos += pContent->m_sPos;
+ CXFA_Node* pMarginNode =
+ pLayoutItem->m_pFormNode->GetFirstChildByClass(XFA_Element::Margin);
+ if (pMarginNode) {
+ sPos += CFX_PointF(pMarginNode->GetMeasure(XFA_ATTRIBUTE_LeftInset)
+ .ToUnit(XFA_UNIT_Pt),
+ pMarginNode->GetMeasure(XFA_ATTRIBUTE_TopInset)
+ .ToUnit(XFA_UNIT_Pt));
+ }
+ continue;
+ }
+
+ if (pLayoutItem->m_pFormNode->GetElementType() ==
+ XFA_Element::ContentArea) {
+ sPos += CFX_PointF(pLayoutItem->m_pFormNode->GetMeasure(XFA_ATTRIBUTE_X)
+ .ToUnit(XFA_UNIT_Pt),
+ pLayoutItem->m_pFormNode->GetMeasure(XFA_ATTRIBUTE_Y)
+ .ToUnit(XFA_UNIT_Pt));
+ break;
+ }
+ if (pLayoutItem->m_pFormNode->GetElementType() == XFA_Element::PageArea)
+ break;
+ }
+
+ rtLayout.Set(sPos.x, sPos.y, sSize.x, sSize.y);
+}
+
+CXFA_LayoutItem* CXFA_LayoutItem::GetFirst() {
+ ASSERT(m_bIsContentLayoutItem);
+ CXFA_ContentLayoutItem* pCurNode = static_cast<CXFA_ContentLayoutItem*>(this);
+ while (pCurNode->m_pPrev)
+ pCurNode = pCurNode->m_pPrev;
+
+ return pCurNode;
+}
+
+const CXFA_LayoutItem* CXFA_LayoutItem::GetLast() const {
+ ASSERT(m_bIsContentLayoutItem);
+ const CXFA_ContentLayoutItem* pCurNode =
+ static_cast<const CXFA_ContentLayoutItem*>(this);
+ while (pCurNode->m_pNext)
+ pCurNode = pCurNode->m_pNext;
+
+ return pCurNode;
+}
+
+CXFA_LayoutItem* CXFA_LayoutItem::GetPrev() const {
+ ASSERT(m_bIsContentLayoutItem);
+
+ return static_cast<const CXFA_ContentLayoutItem*>(this)->m_pPrev;
+}
+
+CXFA_LayoutItem* CXFA_LayoutItem::GetNext() const {
+ ASSERT(m_bIsContentLayoutItem);
+ return static_cast<const CXFA_ContentLayoutItem*>(this)->m_pNext;
+}
+
+int32_t CXFA_LayoutItem::GetIndex() const {
+ ASSERT(m_bIsContentLayoutItem);
+ int32_t iIndex = 0;
+ const CXFA_ContentLayoutItem* pCurNode =
+ static_cast<const CXFA_ContentLayoutItem*>(this);
+ while (pCurNode->m_pPrev) {
+ pCurNode = pCurNode->m_pPrev;
+ ++iIndex;
+ }
+ return iIndex;
+}
+
+int32_t CXFA_LayoutItem::GetCount() const {
+ ASSERT(m_bIsContentLayoutItem);
+
+ int32_t iCount = GetIndex() + 1;
+ const CXFA_ContentLayoutItem* pCurNode =
+ static_cast<const CXFA_ContentLayoutItem*>(this);
+ while (pCurNode->m_pNext) {
+ pCurNode = pCurNode->m_pNext;
+ iCount++;
+ }
+ return iCount;
+}
+
+void CXFA_LayoutItem::AddChild(CXFA_LayoutItem* pChildItem) {
+ if (pChildItem->m_pParent)
+ pChildItem->m_pParent->RemoveChild(pChildItem);
+
+ pChildItem->m_pParent = this;
+ if (!m_pFirstChild) {
+ m_pFirstChild = pChildItem;
+ return;
+ }
+
+ CXFA_LayoutItem* pExistingChildItem = m_pFirstChild;
+ while (pExistingChildItem->m_pNextSibling)
+ pExistingChildItem = pExistingChildItem->m_pNextSibling;
+
+ pExistingChildItem->m_pNextSibling = pChildItem;
+}
+
+void CXFA_LayoutItem::AddHeadChild(CXFA_LayoutItem* pChildItem) {
+ if (pChildItem->m_pParent)
+ pChildItem->m_pParent->RemoveChild(pChildItem);
+
+ pChildItem->m_pParent = this;
+ if (!m_pFirstChild) {
+ m_pFirstChild = pChildItem;
+ return;
+ }
+
+ CXFA_LayoutItem* pExistingChildItem = m_pFirstChild;
+ m_pFirstChild = pChildItem;
+ m_pFirstChild->m_pNextSibling = pExistingChildItem;
+}
+
+void CXFA_LayoutItem::InsertChild(CXFA_LayoutItem* pBeforeItem,
+ CXFA_LayoutItem* pChildItem) {
+ if (pBeforeItem->m_pParent != this)
+ return;
+ if (pChildItem->m_pParent)
+ pChildItem->m_pParent = nullptr;
+
+ pChildItem->m_pParent = this;
+
+ CXFA_LayoutItem* pExistingChildItem = pBeforeItem->m_pNextSibling;
+ pBeforeItem->m_pNextSibling = pChildItem;
+ pChildItem->m_pNextSibling = pExistingChildItem;
+}
+
+void CXFA_LayoutItem::RemoveChild(CXFA_LayoutItem* pChildItem) {
+ if (pChildItem->m_pParent != this)
+ return;
+
+ if (m_pFirstChild == pChildItem) {
+ m_pFirstChild = pChildItem->m_pNextSibling;
+ } else {
+ CXFA_LayoutItem* pExistingChildItem = m_pFirstChild;
+ while (pExistingChildItem &&
+ pExistingChildItem->m_pNextSibling != pChildItem) {
+ pExistingChildItem = pExistingChildItem->m_pNextSibling;
+ }
+ if (pExistingChildItem)
+ pExistingChildItem->m_pNextSibling = pChildItem->m_pNextSibling;
+ }
+ pChildItem->m_pNextSibling = nullptr;
+ pChildItem->m_pParent = nullptr;
+}