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

Side by Side Diff: fpdfsdk/cpdfsdk_annot.cpp

Issue 2311343003: Make Observers into a templated class (Closed)
Patch Set: Make Annot is-a CPDFSDK_Annot::Observer Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/include/cpdfsdk_annot.h" 7 #include "fpdfsdk/include/cpdfsdk_annot.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "fpdfsdk/include/fsdk_mgr.h" 11 #include "fpdfsdk/include/fsdk_mgr.h"
12 #include "third_party/base/stl_util.h" 12 #include "third_party/base/stl_util.h"
13 13
14 #ifdef PDF_ENABLE_XFA 14 #ifdef PDF_ENABLE_XFA
15 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" 15 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
16 #endif // PDF_ENABLE_XFA 16 #endif // PDF_ENABLE_XFA
17 17
18 namespace { 18 namespace {
19 19
20 const float kMinWidth = 1.0f; 20 const float kMinWidth = 1.0f;
21 const float kMinHeight = 1.0f; 21 const float kMinHeight = 1.0f;
22 22
23 } // namespace 23 } // namespace
24 24
25 CPDFSDK_Annot::Observer::Observer(CPDFSDK_Annot** pWatchedPtr)
26 : m_pWatchedPtr(pWatchedPtr) {
27 (*m_pWatchedPtr)->AddObserver(this);
28 }
29
30 CPDFSDK_Annot::Observer::~Observer() {
31 if (m_pWatchedPtr)
32 (*m_pWatchedPtr)->RemoveObserver(this);
33 }
34
35 void CPDFSDK_Annot::Observer::OnAnnotDestroyed() {
36 ASSERT(m_pWatchedPtr);
37 *m_pWatchedPtr = nullptr;
38 m_pWatchedPtr = nullptr;
39 }
40
41 CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) 25 CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
42 : m_pPageView(pPageView), m_bSelected(FALSE) {} 26 : m_pPageView(pPageView), m_bSelected(FALSE) {}
43 27
44 CPDFSDK_Annot::~CPDFSDK_Annot() { 28 CPDFSDK_Annot::~CPDFSDK_Annot() {}
45 for (auto* pObserver : m_Observers)
46 pObserver->OnAnnotDestroyed();
47 }
48
49 void CPDFSDK_Annot::AddObserver(Observer* pObserver) {
50 ASSERT(!pdfium::ContainsKey(m_Observers, pObserver));
51 m_Observers.insert(pObserver);
52 }
53
54 void CPDFSDK_Annot::RemoveObserver(Observer* pObserver) {
55 ASSERT(pdfium::ContainsKey(m_Observers, pObserver));
56 m_Observers.erase(pObserver);
57 }
58 29
59 #ifdef PDF_ENABLE_XFA 30 #ifdef PDF_ENABLE_XFA
60 31
61 FX_BOOL CPDFSDK_Annot::IsXFAField() { 32 FX_BOOL CPDFSDK_Annot::IsXFAField() {
62 return FALSE; 33 return FALSE;
63 } 34 }
64 35
65 CXFA_FFWidget* CPDFSDK_Annot::GetXFAWidget() const { 36 CXFA_FFWidget* CPDFSDK_Annot::GetXFAWidget() const {
66 return nullptr; 37 return nullptr;
67 } 38 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #ifdef PDF_ENABLE_XFA 89 #ifdef PDF_ENABLE_XFA
119 return GetPDFXFAPage(); 90 return GetPDFXFAPage();
120 #else // PDF_ENABLE_XFA 91 #else // PDF_ENABLE_XFA
121 return GetPDFPage(); 92 return GetPDFPage();
122 #endif // PDF_ENABLE_XFA 93 #endif // PDF_ENABLE_XFA
123 } 94 }
124 95
125 CPDF_Page* CPDFSDK_Annot::GetPDFPage() { 96 CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
126 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr; 97 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr;
127 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698