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

Unified Diff: fpdfsdk/cpdfsdk_annotiterator.cpp

Issue 2243623002: Split fpdfsdk/fsdk_annothandler.h into individual classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Split fpdfsdk/fsdk_annothandler.h into individual classes. Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: fpdfsdk/cpdfsdk_annotiterator.cpp
diff --git a/fpdfsdk/cpdfsdk_annotiterator.cpp b/fpdfsdk/cpdfsdk_annotiterator.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d3ff50269314f7e3acbb3d8353eae6a52a034416
--- /dev/null
+++ b/fpdfsdk/cpdfsdk_annotiterator.cpp
@@ -0,0 +1,54 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
dsinclair 2016/08/12 03:02:49 nit: 2016
jaepark 2016/08/12 18:09:34 Done.
+// 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/include/cpdfsdk_annotiterator.h"
+
+#include <algorithm>
+
+#include "fpdfsdk/include/cpdfsdk_annot.h"
+#include "fpdfsdk/include/fsdk_mgr.h"
+
+CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
+ bool bReverse)
+ : m_bReverse(bReverse), m_pos(0) {
+ const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
+ m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
+ annots.rend());
+ std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
+ [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
+ return p1->GetLayoutOrder() < p2->GetLayoutOrder();
+ });
+
+ CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
+ if (!pTopMostAnnot)
+ return;
+
+ auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
+ pTopMostAnnot);
+ if (it != m_iteratorAnnotList.end()) {
+ CPDFSDK_Annot* pReaderAnnot = *it;
+ m_iteratorAnnotList.erase(it);
+ m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
+ }
+}
+
+CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
+ if (m_pos < m_iteratorAnnotList.size())
+ return m_iteratorAnnotList[m_pos++];
+ return nullptr;
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
+ if (m_pos < m_iteratorAnnotList.size())
+ return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
+ return nullptr;
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
+ return m_bReverse ? PrevAnnot() : NextAnnot();
+}

Powered by Google App Engine
This is Rietveld 408576698