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_viewlayoutitem.h" 8 9 #include "fxjs/xfa/cjx_object.h" 10 #include "xfa/fxfa/cxfa_ffpageview.h" 11 #include "xfa/fxfa/layout/cxfa_layoutprocessor.h" 12 #include "xfa/fxfa/layout/cxfa_viewlayoutprocessor.h" 13 #include "xfa/fxfa/parser/cxfa_measurement.h" 14 #include "xfa/fxfa/parser/cxfa_medium.h" 15 #include "xfa/fxfa/parser/cxfa_node.h" 16 CXFA_ViewLayoutItem(CXFA_Node * pNode,CXFA_FFPageView * pPageView)17CXFA_ViewLayoutItem::CXFA_ViewLayoutItem(CXFA_Node* pNode, 18 CXFA_FFPageView* pPageView) 19 : CXFA_LayoutItem(pNode, kViewItem), m_pFFPageView(pPageView) { 20 if (m_pFFPageView) 21 m_pFFPageView->SetLayoutItem(this); 22 } 23 24 CXFA_ViewLayoutItem::~CXFA_ViewLayoutItem() = default; 25 Trace(cppgc::Visitor * visitor) const26void CXFA_ViewLayoutItem::Trace(cppgc::Visitor* visitor) const { 27 CXFA_LayoutItem::Trace(visitor); 28 visitor->Trace(m_pOldSubform); 29 visitor->Trace(m_pFFPageView); 30 } 31 GetLayout() const32CXFA_LayoutProcessor* CXFA_ViewLayoutItem::GetLayout() const { 33 return CXFA_LayoutProcessor::FromDocument(GetFormNode()->GetDocument()); 34 } 35 GetPageIndex() const36int32_t CXFA_ViewLayoutItem::GetPageIndex() const { 37 auto* pLayout = 38 CXFA_LayoutProcessor::FromDocument(GetFormNode()->GetDocument()); 39 return pLayout->GetLayoutPageMgr()->GetPageIndex(this); 40 } 41 GetPageSize() const42CFX_SizeF CXFA_ViewLayoutItem::GetPageSize() const { 43 CFX_SizeF size; 44 CXFA_Medium* pMedium = 45 GetFormNode()->GetFirstChildByClass<CXFA_Medium>(XFA_Element::Medium); 46 if (!pMedium) 47 return size; 48 49 size = CFX_SizeF( 50 pMedium->JSObject()->GetMeasureInUnit(XFA_Attribute::Short, XFA_Unit::Pt), 51 pMedium->JSObject()->GetMeasureInUnit(XFA_Attribute::Long, XFA_Unit::Pt)); 52 if (pMedium->JSObject()->GetEnum(XFA_Attribute::Orientation) == 53 XFA_AttributeValue::Landscape) { 54 size = CFX_SizeF(size.height, size.width); 55 } 56 return size; 57 } 58 GetMasterPage() const59CXFA_Node* CXFA_ViewLayoutItem::GetMasterPage() const { 60 return GetFormNode(); 61 } 62 SetOldSubform(CXFA_Node * pSubform)63void CXFA_ViewLayoutItem::SetOldSubform(CXFA_Node* pSubform) { 64 m_pOldSubform = pSubform; 65 } 66