Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_contentlayoutitem.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fxfa/layout/cxfa_contentlayoutitem.h"
8
9#include "fxjs/xfa/cjx_object.h"
10#include "third_party/base/check_op.h"
11#include "xfa/fxfa/cxfa_ffwidget.h"
12#include "xfa/fxfa/parser/cxfa_margin.h"
13#include "xfa/fxfa/parser/cxfa_node.h"
14
15CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode,
16 CXFA_FFWidget* pWidget)
17 : CXFA_LayoutItem(pNode, kContentItem), m_pFFWidget(pWidget) {
18 if (m_pFFWidget)
19 m_pFFWidget->SetLayoutItem(this);
20}
21
22CXFA_ContentLayoutItem::~CXFA_ContentLayoutItem() = default;
23
24void CXFA_ContentLayoutItem::Trace(cppgc::Visitor* visitor) const {
25 CXFA_LayoutItem::Trace(visitor);
26 visitor->Trace(m_pPrev);
27 visitor->Trace(m_pNext);
28 visitor->Trace(m_pFFWidget);
29}
30
31CXFA_ContentLayoutItem* CXFA_ContentLayoutItem::GetFirst() {
32 CXFA_ContentLayoutItem* pCurNode = this;
33 while (auto* pPrev = pCurNode->GetPrev())
34 pCurNode = pPrev;
35
36 return pCurNode;
37}
38
39CXFA_ContentLayoutItem* CXFA_ContentLayoutItem::GetLast() {
40 CXFA_ContentLayoutItem* pCurNode = this;
41 while (auto* pNext = pCurNode->GetNext())
42 pCurNode = pNext;
43
44 return pCurNode;
45}
46
47void CXFA_ContentLayoutItem::InsertAfter(CXFA_ContentLayoutItem* pItem) {
48 CHECK_NE(this, pItem);
49 pItem->RemoveSelf();
50 pItem->m_pNext = m_pNext;
51 pItem->m_pPrev = this;
52 m_pNext = pItem;
53 if (pItem->m_pNext)
54 pItem->m_pNext->m_pPrev = pItem;
55}
56
57void CXFA_ContentLayoutItem::RemoveSelf() {
58 if (m_pNext)
59 m_pNext->m_pPrev = m_pPrev;
60 if (m_pPrev)
61 m_pPrev->m_pNext = m_pNext;
62}
63
64CFX_RectF CXFA_ContentLayoutItem::GetRelativeRect() const {
65 return CFX_RectF(m_sPos, m_sSize);
66}
67
68CFX_RectF CXFA_ContentLayoutItem::GetAbsoluteRect() const {
69 CFX_PointF sPos = m_sPos;
70 CFX_SizeF sSize = m_sSize;
71
72 for (CXFA_LayoutItem* pLayoutItem = GetParent(); pLayoutItem;
73 pLayoutItem = pLayoutItem->GetParent()) {
74 if (CXFA_ContentLayoutItem* pContent = pLayoutItem->AsContentLayoutItem()) {
75 sPos += pContent->m_sPos;
76 CXFA_Margin* pMarginNode =
77 pContent->GetFormNode()->GetFirstChildByClass<CXFA_Margin>(
78 XFA_Element::Margin);
79 if (pMarginNode) {
80 sPos += CFX_PointF(pMarginNode->JSObject()->GetMeasureInUnit(
81 XFA_Attribute::LeftInset, XFA_Unit::Pt),
82 pMarginNode->JSObject()->GetMeasureInUnit(
83 XFA_Attribute::TopInset, XFA_Unit::Pt));
84 }
85 continue;
86 }
87
88 if (pLayoutItem->GetFormNode()->GetElementType() ==
89 XFA_Element::ContentArea) {
90 sPos +=
91 CFX_PointF(pLayoutItem->GetFormNode()->JSObject()->GetMeasureInUnit(
93 pLayoutItem->GetFormNode()->JSObject()->GetMeasureInUnit(
95 break;
96 }
97 if (pLayoutItem->GetFormNode()->GetElementType() == XFA_Element::PageArea)
98 break;
99 }
100 return CFX_RectF(sPos, sSize);
101}
102
103size_t CXFA_ContentLayoutItem::GetIndex() const {
104 size_t szIndex = 0;
105 const CXFA_ContentLayoutItem* pCurNode = this;
106 while (auto* pPrev = pCurNode->GetPrev()) {
107 pCurNode = pPrev;
108 ++szIndex;
109 }
110 return szIndex;
111}
void InsertAfter(CXFA_ContentLayoutItem *pNext)
CXFA_ContentLayoutItem * GetPrev() const
CXFA_ContentLayoutItem * GetNext() const
~CXFA_ContentLayoutItem() override
CXFA_ContentLayoutItem * GetLast()
void Trace(cppgc::Visitor *visitor) const override
CXFA_ContentLayoutItem * GetFirst()
CXFA_ContentLayoutItem * AsContentLayoutItem()
CXFA_Node * GetFormNode() const
CXFA_LayoutItem(CXFA_Node *pNode, ItemType type)
XFA_Element GetElementType() const
Definition cxfa_object.h:91
XFA_Unit
Definition fxfa_basic.h:91
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
Definition heap.h:12