Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: fpdfsdk/cpdfsdk_annotiterator.cpp

Issue 2626073005: Use observed pointers in CPDFSDK_AnnotIterator. (Closed)
Patch Set: remove local Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/cpdfsdk_annotiterator.h ('k') | fpdfsdk/cpdfsdk_baannot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // 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 "fpdfsdk/cpdfsdk_annotiterator.h"
8
9 #include <algorithm>
10
11 #include "fpdfsdk/cpdfsdk_annot.h"
12 #include "fpdfsdk/cpdfsdk_pageview.h"
13
14 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
15 bool bReverse)
16 : m_bReverse(bReverse), m_pos(0) {
17 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
18 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
19 annots.rend());
20 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
21 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
22 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
23 });
24
25 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
26 if (!pTopMostAnnot)
27 return;
28
29 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
30 pTopMostAnnot);
31 if (it != m_iteratorAnnotList.end()) {
32 CPDFSDK_Annot* pReaderAnnot = *it;
33 m_iteratorAnnotList.erase(it);
34 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
35 }
36 }
37
38 CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {}
39
40 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
41 if (m_pos < m_iteratorAnnotList.size())
42 return m_iteratorAnnotList[m_pos++];
43 return nullptr;
44 }
45
46 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
47 if (m_pos < m_iteratorAnnotList.size())
48 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
49 return nullptr;
50 }
51
52 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
53 return m_bReverse ? PrevAnnot() : NextAnnot();
54 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_annotiterator.h ('k') | fpdfsdk/cpdfsdk_baannot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698