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 "core/fpdfdoc/cpdf_bookmarktree.h" 8 9 #include <utility> 10 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" 12 #include "core/fpdfapi/parser/cpdf_document.h" 13 CPDF_BookmarkTree(const CPDF_Document * doc)14CPDF_BookmarkTree::CPDF_BookmarkTree(const CPDF_Document* doc) 15 : document_(doc) {} 16 17 CPDF_BookmarkTree::~CPDF_BookmarkTree() = default; 18 GetFirstChild(const CPDF_Bookmark & parent) const19CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( 20 const CPDF_Bookmark& parent) const { 21 const CPDF_Dictionary* parent_dict = parent.GetDict(); 22 if (parent_dict) 23 return CPDF_Bookmark(parent_dict->GetDictFor("First")); 24 25 const CPDF_Dictionary* root = document_->GetRoot(); 26 if (!root) 27 return CPDF_Bookmark(); 28 29 RetainPtr<const CPDF_Dictionary> outlines = root->GetDictFor("Outlines"); 30 return outlines ? CPDF_Bookmark(outlines->GetDictFor("First")) 31 : CPDF_Bookmark(); 32 } 33 GetNextSibling(const CPDF_Bookmark & bookmark) const34CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( 35 const CPDF_Bookmark& bookmark) const { 36 const CPDF_Dictionary* dict = bookmark.GetDict(); 37 if (!dict) 38 return CPDF_Bookmark(); 39 40 RetainPtr<const CPDF_Dictionary> next = dict->GetDictFor("Next"); 41 return next != dict ? CPDF_Bookmark(std::move(next)) : CPDF_Bookmark(); 42 } 43