• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/parser/cxfa_attachnodelist.h"
8 
9 #include "xfa/fxfa/parser/cxfa_node.h"
10 
CXFA_AttachNodeList(CXFA_Document * pDocument,CXFA_Node * pAttachNode)11 CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument,
12                                          CXFA_Node* pAttachNode)
13     : CXFA_TreeList(pDocument), m_pAttachNode(pAttachNode) {}
14 
15 CXFA_AttachNodeList::~CXFA_AttachNodeList() = default;
16 
Trace(cppgc::Visitor * visitor) const17 void CXFA_AttachNodeList::Trace(cppgc::Visitor* visitor) const {
18   CXFA_TreeList::Trace(visitor);
19   visitor->Trace(m_pAttachNode);
20 }
21 
GetLength()22 size_t CXFA_AttachNodeList::GetLength() {
23   return m_pAttachNode->CountChildren(
24       XFA_Element::Unknown,
25       m_pAttachNode->GetElementType() == XFA_Element::Subform);
26 }
27 
Append(CXFA_Node * pNode)28 bool CXFA_AttachNodeList::Append(CXFA_Node* pNode) {
29   if (pNode->IsAncestorOf(m_pAttachNode))
30     return false;
31 
32   CXFA_Node* pParent = pNode->GetParent();
33   if (pParent)
34     pParent->RemoveChildAndNotify(pNode, true);
35 
36   m_pAttachNode->InsertChildAndNotify(pNode, nullptr);
37   return true;
38 }
39 
Insert(CXFA_Node * pNewNode,CXFA_Node * pBeforeNode)40 bool CXFA_AttachNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) {
41   if (pNewNode->IsAncestorOf(m_pAttachNode))
42     return false;
43 
44   if (pBeforeNode && pBeforeNode->GetParent() != m_pAttachNode)
45     return false;
46 
47   CXFA_Node* pParent = pNewNode->GetParent();
48   if (pParent)
49     pParent->RemoveChildAndNotify(pNewNode, true);
50 
51   m_pAttachNode->InsertChildAndNotify(pNewNode, pBeforeNode);
52   return true;
53 }
54 
Remove(CXFA_Node * pNode)55 void CXFA_AttachNodeList::Remove(CXFA_Node* pNode) {
56   m_pAttachNode->RemoveChildAndNotify(pNode, true);
57 }
58 
Item(size_t index)59 CXFA_Node* CXFA_AttachNodeList::Item(size_t index) {
60   return m_pAttachNode->GetChild<CXFA_Node>(
61       index, XFA_Element::Unknown,
62       m_pAttachNode->GetElementType() == XFA_Element::Subform);
63 }
64