From 0703fa810bc79a335ddfdab3e7661159caf88e2d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 13 Sep 2016 14:52:55 -0400 Subject: [Merge to 54] Add observer for BAAnnots from Javascript This Cl moves the observer code from the CPDFSDK_Widget up into the CPDFSDK_Annot base class and then adds a second observer for CPDFSDK_BAAnnot objects. This allows us to attach an observer to the Annot javascript class which will update its internal pointer to the BAAnnot if the BAAnnot is destroyed by the CPDFSDK_PageView being destroyed. BUG=chromium:642307 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/2333383002 . Review-Url: https://codereview.chromium.org/2306663002 --- fpdfsdk/javascript/Annot.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'fpdfsdk/javascript/Annot.cpp') diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp index df123274d5..95a428a9a5 100644 --- a/fpdfsdk/javascript/Annot.cpp +++ b/fpdfsdk/javascript/Annot.cpp @@ -11,6 +11,14 @@ #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_context.h" +namespace { + +CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) { + return static_cast(annot); +} + +} // namespace + BEGIN_JS_STATIC_CONST(CJS_Annot) END_JS_STATIC_CONST() @@ -32,8 +40,12 @@ Annot::~Annot() {} FX_BOOL Annot::hidden(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { + CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot); + if (!baAnnot) + return FALSE; + if (vp.IsGetting()) { - CPDF_Annot* pPDFAnnot = m_BAAnnot->GetPDFAnnot(); + CPDF_Annot* pPDFAnnot = baAnnot->GetPDFAnnot(); vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()); return TRUE; } @@ -41,7 +53,7 @@ FX_BOOL Annot::hidden(IJS_Context* cc, bool bHidden; vp >> bHidden; - uint32_t flags = m_BAAnnot->GetFlags(); + uint32_t flags = baAnnot->GetFlags(); if (bHidden) { flags |= ANNOTFLAG_HIDDEN; flags |= ANNOTFLAG_INVISIBLE; @@ -53,21 +65,25 @@ FX_BOOL Annot::hidden(IJS_Context* cc, flags &= ~ANNOTFLAG_NOVIEW; flags |= ANNOTFLAG_PRINT; } - m_BAAnnot->SetFlags(flags); + baAnnot->SetFlags(flags); return TRUE; } FX_BOOL Annot::name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { + CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot); + if (!baAnnot) + return FALSE; + if (vp.IsGetting()) { - vp << m_BAAnnot->GetAnnotName(); + vp << baAnnot->GetAnnotName(); return TRUE; } CFX_WideString annotName; vp >> annotName; - m_BAAnnot->SetAnnotName(annotName); + baAnnot->SetAnnotName(annotName); return TRUE; } @@ -80,10 +96,15 @@ FX_BOOL Annot::type(IJS_Context* cc, return FALSE; } - vp << m_BAAnnot->GetType(); + CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot); + if (!baAnnot) + return FALSE; + + vp << baAnnot->GetType(); return TRUE; } void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { - m_BAAnnot = annot; + m_pAnnot = annot; + m_pObserver.reset(new CPDFSDK_Annot::Observer(&m_pAnnot)); } -- cgit v1.2.3