summaryrefslogtreecommitdiff
path: root/fpdfsdk/fsdk_baseform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fsdk_baseform.cpp')
-rw-r--r--fpdfsdk/fsdk_baseform.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp
index 287c5cf17e..1b1d40b3a0 100644
--- a/fpdfsdk/fsdk_baseform.cpp
+++ b/fpdfsdk/fsdk_baseform.cpp
@@ -28,6 +28,7 @@
#include "fpdfsdk/javascript/ijs_context.h"
#include "fpdfsdk/javascript/ijs_runtime.h"
#include "fpdfsdk/pdfwindow/PWL_Utils.h"
+#include "third_party/base/stl_util.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
@@ -49,6 +50,22 @@ PDFSDK_FieldAction::PDFSDK_FieldAction()
bFieldFull(FALSE),
bRC(TRUE) {}
+CPDFSDK_Widget::Observer::Observer(CPDFSDK_Widget** pWatchedPtr)
+ : m_pWatchedPtr(pWatchedPtr) {
+ (*m_pWatchedPtr)->AddObserver(this);
+}
+
+CPDFSDK_Widget::Observer::~Observer() {
+ if (m_pWatchedPtr)
+ (*m_pWatchedPtr)->RemoveObserver(this);
+}
+
+void CPDFSDK_Widget::Observer::OnWidgetDestroyed() {
+ ASSERT(m_pWatchedPtr);
+ *m_pWatchedPtr = nullptr;
+ m_pWatchedPtr = nullptr;
+}
+
CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
CPDFSDK_PageView* pPageView,
CPDFSDK_InterForm* pInterForm)
@@ -64,7 +81,20 @@ CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
{
}
-CPDFSDK_Widget::~CPDFSDK_Widget() {}
+CPDFSDK_Widget::~CPDFSDK_Widget() {
+ for (auto* pObserver : m_Observers)
+ pObserver->OnWidgetDestroyed();
+}
+
+void CPDFSDK_Widget::AddObserver(Observer* pObserver) {
+ ASSERT(!pdfium::ContainsKey(m_Observers, pObserver));
+ m_Observers.insert(pObserver);
+}
+
+void CPDFSDK_Widget::RemoveObserver(Observer* pObserver) {
+ ASSERT(pdfium::ContainsKey(m_Observers, pObserver));
+ m_Observers.erase(pObserver);
+}
#ifdef PDF_ENABLE_XFA
CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {