blob: ebe33b650f8231f627b94749c19ff71952a3ece8 [file] [log] [blame]
dsinclair0b851ff2016-07-21 12:03:01 -07001// 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/parser/cxfa_layoutitem.h"
8
dsinclair6ea5ba02016-08-03 10:20:32 -07009#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair0b851ff2016-07-21 12:03:01 -070010#include "xfa/fxfa/parser/cxfa_containerlayoutitem.h"
11#include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
12
dsinclair6ea5ba02016-08-03 10:20:32 -070013void XFA_ReleaseLayoutItem(CXFA_LayoutItem* pLayoutItem) {
14 CXFA_LayoutItem* pNode = pLayoutItem->m_pFirstChild;
15 CXFA_FFNotify* pNotify = pLayoutItem->m_pFormNode->GetDocument()->GetNotify();
16 CXFA_LayoutProcessor* pDocLayout =
17 pLayoutItem->m_pFormNode->GetDocument()->GetDocLayout();
18 while (pNode) {
19 CXFA_LayoutItem* pNext = pNode->m_pNextSibling;
20 pNode->m_pParent = nullptr;
21 pNotify->OnLayoutItemRemoving(pDocLayout,
22 static_cast<CXFA_LayoutItem*>(pNode));
23 XFA_ReleaseLayoutItem(pNode);
24 pNode = pNext;
25 }
26
27 pNotify->OnLayoutItemRemoving(pDocLayout, pLayoutItem);
28 if (pLayoutItem->m_pFormNode->GetElementType() == XFA_Element::PageArea) {
29 pNotify->OnPageEvent(static_cast<CXFA_ContainerLayoutItem*>(pLayoutItem),
30 XFA_PAGEVIEWEVENT_PostRemoved);
31 }
32 delete pLayoutItem;
33}
34
dsinclair0b851ff2016-07-21 12:03:01 -070035CXFA_LayoutItem::CXFA_LayoutItem(CXFA_Node* pNode, FX_BOOL bIsContentLayoutItem)
36 : m_pFormNode(pNode),
37 m_pParent(nullptr),
38 m_pNextSibling(nullptr),
39 m_pFirstChild(nullptr),
40 m_bIsContentLayoutItem(bIsContentLayoutItem) {}
41
42CXFA_LayoutItem::~CXFA_LayoutItem() {}
43
44CXFA_ContainerLayoutItem* CXFA_LayoutItem::AsContainerLayoutItem() {
45 return IsContainerLayoutItem() ? static_cast<CXFA_ContainerLayoutItem*>(this)
46 : nullptr;
47}
48CXFA_ContentLayoutItem* CXFA_LayoutItem::AsContentLayoutItem() {
49 return IsContentLayoutItem() ? static_cast<CXFA_ContentLayoutItem*>(this)
50 : nullptr;
51}