summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_attachnodelist.cpp
blob: f1fbfa784b9d2e95e9bed2b723ee0996f7c51bd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "xfa/fxfa/parser/cxfa_attachnodelist.h"

#include "third_party/base/numerics/safe_conversions.h"
#include "xfa/fxfa/parser/cxfa_node.h"

CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument,
                                         CXFA_Node* pAttachNode)
    : CXFA_TreeList(pDocument) {
  m_pAttachNode = pAttachNode;
}

size_t CXFA_AttachNodeList::GetLength() {
  return m_pAttachNode->CountChildren(
      XFA_Element::Unknown,
      m_pAttachNode->GetElementType() == XFA_Element::Subform);
}

bool CXFA_AttachNodeList::Append(CXFA_Node* pNode) {
  CXFA_Node* pParent = pNode->GetParent();
  if (pParent)
    pParent->RemoveChild(pNode, true);

  return m_pAttachNode->InsertChild(pNode, nullptr);
}

bool CXFA_AttachNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) {
  CXFA_Node* pParent = pNewNode->GetParent();
  if (pParent)
    pParent->RemoveChild(pNewNode, true);

  return m_pAttachNode->InsertChild(pNewNode, pBeforeNode);
}

bool CXFA_AttachNodeList::Remove(CXFA_Node* pNode) {
  return m_pAttachNode->RemoveChild(pNode, true);
}

CXFA_Node* CXFA_AttachNodeList::Item(size_t index) {
  return m_pAttachNode->GetChild<CXFA_Node>(
      index, XFA_Element::Unknown,
      m_pAttachNode->GetElementType() == XFA_Element::Subform);
}