summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-30 21:50:07 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-30 21:50:07 +0000
commit87c1fdcc9a5669e29c4440e2b220587de7134e7a (patch)
treecf890e10d6233205505a0d89eae13b3bd0deba14 /xfa/fxfa/parser/cxfa_contentlayoutitem.cpp
parent649e059f5fe93c0de53aaa48a74068703df46301 (diff)
downloadpdfium-87c1fdcc9a5669e29c4440e2b220587de7134e7a.tar.xz
Don't static_cast<>(this) to subclass in CXFA_LayoutItem methods.chromium/3508
Instead, move the methods to the subclass where they belong. Fix IWYU in CJX_Object.h to fix compilation. Change-Id: I4c71f28235b9cf5000e9ddaf33d6602baf22205f Reviewed-on: https://pdfium-review.googlesource.com/39170 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_contentlayoutitem.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_contentlayoutitem.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp b/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp
index 1ee364b9b7..e763e2d5da 100644
--- a/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp
+++ b/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
#include "fxjs/xfa/cjx_object.h"
+#include "xfa/fxfa/parser/cxfa_margin.h"
#include "xfa/fxfa/parser/cxfa_node.h"
CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode)
@@ -19,3 +20,81 @@ CXFA_ContentLayoutItem::~CXFA_ContentLayoutItem() {
if (m_pFormNode->JSObject()->GetLayoutItem() == this)
m_pFormNode->JSObject()->SetLayoutItem(nullptr);
}
+
+CXFA_ContentLayoutItem* CXFA_ContentLayoutItem::GetFirst() {
+ CXFA_ContentLayoutItem* pCurNode = this;
+ while (pCurNode->m_pPrev)
+ pCurNode = pCurNode->m_pPrev;
+
+ return pCurNode;
+}
+
+CXFA_ContentLayoutItem* CXFA_ContentLayoutItem::GetLast() {
+ CXFA_ContentLayoutItem* pCurNode = this;
+ while (pCurNode->m_pNext)
+ pCurNode = pCurNode->m_pNext;
+
+ return pCurNode;
+}
+
+CFX_RectF CXFA_ContentLayoutItem::GetRect(bool bRelative) const {
+ CFX_PointF sPos = m_sPos;
+ CFX_SizeF sSize = m_sSize;
+ if (bRelative)
+ return CFX_RectF(sPos, sSize);
+
+ for (CXFA_LayoutItem* pLayoutItem = m_pParent; pLayoutItem;
+ pLayoutItem = pLayoutItem->m_pParent) {
+ if (CXFA_ContentLayoutItem* pContent = pLayoutItem->AsContentLayoutItem()) {
+ sPos += pContent->m_sPos;
+ CXFA_Margin* pMarginNode =
+ pContent->m_pFormNode->GetFirstChildByClass<CXFA_Margin>(
+ XFA_Element::Margin);
+ if (pMarginNode) {
+ sPos += CFX_PointF(pMarginNode->JSObject()
+ ->GetMeasure(XFA_Attribute::LeftInset)
+ .ToUnit(XFA_Unit::Pt),
+ pMarginNode->JSObject()
+ ->GetMeasure(XFA_Attribute::TopInset)
+ .ToUnit(XFA_Unit::Pt));
+ }
+ continue;
+ }
+
+ if (pLayoutItem->GetFormNode()->GetElementType() ==
+ XFA_Element::ContentArea) {
+ sPos += CFX_PointF(pLayoutItem->GetFormNode()
+ ->JSObject()
+ ->GetMeasure(XFA_Attribute::X)
+ .ToUnit(XFA_Unit::Pt),
+ pLayoutItem->GetFormNode()
+ ->JSObject()
+ ->GetMeasure(XFA_Attribute::Y)
+ .ToUnit(XFA_Unit::Pt));
+ break;
+ }
+ if (pLayoutItem->GetFormNode()->GetElementType() == XFA_Element::PageArea)
+ break;
+ }
+ return CFX_RectF(sPos, sSize);
+}
+
+int32_t CXFA_ContentLayoutItem::GetIndex() const {
+ int32_t iIndex = 0;
+ const CXFA_ContentLayoutItem* pCurNode = this;
+ while (pCurNode->m_pPrev) {
+ pCurNode = pCurNode->m_pPrev;
+ ++iIndex;
+ }
+ return iIndex;
+}
+
+int32_t CXFA_ContentLayoutItem::GetCount() const {
+ int32_t iCount = GetIndex() + 1;
+ const CXFA_ContentLayoutItem* pCurNode = this;
+ while (pCurNode->m_pNext) {
+ pCurNode = pCurNode->m_pNext;
+ iCount++;
+ }
+ return iCount;
+}