1 // Copyright 2016 PDFium Authors. All rights reserved. 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 <utility> 10 11 #include "fxjs/xfa/cjx_object.h" 12 #include "xfa/fxfa/cxfa_ffpageview.h" 13 #include "xfa/fxfa/layout/cxfa_layoutprocessor.h" 14 #include "xfa/fxfa/layout/cxfa_viewlayoutprocessor.h" 15 #include "xfa/fxfa/parser/cxfa_measurement.h" 16 #include "xfa/fxfa/parser/cxfa_medium.h" 17 #include "xfa/fxfa/parser/cxfa_node.h" 18 CXFA_ViewLayoutItem(CXFA_Node * pNode,std::unique_ptr<CXFA_FFPageView> pPageView)19CXFA_ViewLayoutItem::CXFA_ViewLayoutItem( 20 CXFA_Node* pNode, 21 std::unique_ptr<CXFA_FFPageView> pPageView) 22 : CXFA_LayoutItem(pNode, kViewItem), m_pFFPageView(std::move(pPageView)) { 23 if (m_pFFPageView) 24 m_pFFPageView->SetLayoutItem(this); 25 } 26 ~CXFA_ViewLayoutItem()27CXFA_ViewLayoutItem::~CXFA_ViewLayoutItem() { 28 if (m_pFFPageView) 29 m_pFFPageView->SetLayoutItem(nullptr); 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