diff options
author | tsepez <tsepez@chromium.org> | 2017-01-11 14:03:54 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2017-01-11 14:03:54 -0800 |
commit | d805eec52f6ac574918748c4270873e7e5cde596 (patch) | |
tree | 3dec3245638de8600bd9a213887be92cc53a1d76 /fpdfsdk/cpdfsdk_annotiteration.cpp | |
parent | 5e3121beff936df1b0af3749447eeda1666d5d76 (diff) | |
download | pdfium-d805eec52f6ac574918748c4270873e7e5cde596.tar.xz |
Use observed pointers in CPDFSDK_AnnotIterator.chromium/2979
Rename to CPDFSDK_AnnotIteration, as it is now an ordered set of
annots, and not the iterator itself.
Review-Url: https://codereview.chromium.org/2626073005
Diffstat (limited to 'fpdfsdk/cpdfsdk_annotiteration.cpp')
-rw-r--r-- | fpdfsdk/cpdfsdk_annotiteration.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/fpdfsdk/cpdfsdk_annotiteration.cpp b/fpdfsdk/cpdfsdk_annotiteration.cpp new file mode 100644 index 0000000000..dd99ade509 --- /dev/null +++ b/fpdfsdk/cpdfsdk_annotiteration.cpp @@ -0,0 +1,40 @@ +// Copyright 2017 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 "fpdfsdk/cpdfsdk_annotiteration.h" + +#include <algorithm> +#include <utility> + +#include "fpdfsdk/cpdfsdk_annot.h" +#include "fpdfsdk/cpdfsdk_pageview.h" + +CPDFSDK_AnnotIteration::CPDFSDK_AnnotIteration(CPDFSDK_PageView* pPageView, + bool bReverse) { + // Copying/sorting ObservedPtrs is expensive, so do it once at the end. + std::vector<CPDFSDK_Annot*> copiedList = pPageView->GetAnnotList(); + std::stable_sort(copiedList.begin(), copiedList.end(), + [](const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) { + return p1->GetLayoutOrder() < p2->GetLayoutOrder(); + }); + + CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); + if (pTopMostAnnot) { + auto it = std::find(copiedList.begin(), copiedList.end(), pTopMostAnnot); + if (it != copiedList.end()) { + copiedList.erase(it); + copiedList.insert(copiedList.begin(), pTopMostAnnot); + } + } + if (bReverse) + std::reverse(copiedList.begin(), copiedList.end()); + + m_List.reserve(copiedList.size()); + for (const auto& pAnnot : copiedList) + m_List.emplace_back(pAnnot); +} + +CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() {} |