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

Side by Side Diff: fpdfsdk/javascript/Annot.cpp

Issue 2306663002: Add observer for BAAnnots from Javascript (Closed)
Patch Set: Review updates 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/javascript/Annot.h" 7 #include "fpdfsdk/javascript/Annot.h"
8 8
9 #include "fpdfsdk/javascript/JS_Define.h" 9 #include "fpdfsdk/javascript/JS_Define.h"
10 #include "fpdfsdk/javascript/JS_Object.h" 10 #include "fpdfsdk/javascript/JS_Object.h"
11 #include "fpdfsdk/javascript/JS_Value.h" 11 #include "fpdfsdk/javascript/JS_Value.h"
12 #include "fpdfsdk/javascript/cjs_context.h" 12 #include "fpdfsdk/javascript/cjs_context.h"
13 13
14 namespace {
15
16 CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) {
17 return static_cast<CPDFSDK_BAAnnot*>(annot);
18 }
19
20 } // namespace
21
14 BEGIN_JS_STATIC_CONST(CJS_Annot) 22 BEGIN_JS_STATIC_CONST(CJS_Annot)
15 END_JS_STATIC_CONST() 23 END_JS_STATIC_CONST()
16 24
17 BEGIN_JS_STATIC_PROP(CJS_Annot) 25 BEGIN_JS_STATIC_PROP(CJS_Annot)
18 JS_STATIC_PROP_ENTRY(hidden) 26 JS_STATIC_PROP_ENTRY(hidden)
19 JS_STATIC_PROP_ENTRY(name) 27 JS_STATIC_PROP_ENTRY(name)
20 JS_STATIC_PROP_ENTRY(type) 28 JS_STATIC_PROP_ENTRY(type)
21 END_JS_STATIC_PROP() 29 END_JS_STATIC_PROP()
22 30
23 BEGIN_JS_STATIC_METHOD(CJS_Annot) 31 BEGIN_JS_STATIC_METHOD(CJS_Annot)
24 END_JS_STATIC_METHOD() 32 END_JS_STATIC_METHOD()
25 33
26 IMPLEMENT_JS_CLASS(CJS_Annot, Annot) 34 IMPLEMENT_JS_CLASS(CJS_Annot, Annot)
27 35
28 Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} 36 Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {}
29 37
30 Annot::~Annot() {} 38 Annot::~Annot() {}
31 39
32 FX_BOOL Annot::hidden(IJS_Context* cc, 40 FX_BOOL Annot::hidden(IJS_Context* cc,
33 CJS_PropValue& vp, 41 CJS_PropValue& vp,
34 CFX_WideString& sError) { 42 CFX_WideString& sError) {
43 CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot);
44 if (!baAnnot)
45 return FALSE;
46
35 if (vp.IsGetting()) { 47 if (vp.IsGetting()) {
36 CPDF_Annot* pPDFAnnot = m_BAAnnot->GetPDFAnnot(); 48 CPDF_Annot* pPDFAnnot = baAnnot->GetPDFAnnot();
37 vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()); 49 vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict());
38 return TRUE; 50 return TRUE;
39 } 51 }
40 52
41 bool bHidden; 53 bool bHidden;
42 vp >> bHidden; 54 vp >> bHidden;
43 55
44 uint32_t flags = m_BAAnnot->GetFlags(); 56 uint32_t flags = baAnnot->GetFlags();
45 if (bHidden) { 57 if (bHidden) {
46 flags |= ANNOTFLAG_HIDDEN; 58 flags |= ANNOTFLAG_HIDDEN;
47 flags |= ANNOTFLAG_INVISIBLE; 59 flags |= ANNOTFLAG_INVISIBLE;
48 flags |= ANNOTFLAG_NOVIEW; 60 flags |= ANNOTFLAG_NOVIEW;
49 flags &= ~ANNOTFLAG_PRINT; 61 flags &= ~ANNOTFLAG_PRINT;
50 } else { 62 } else {
51 flags &= ~ANNOTFLAG_HIDDEN; 63 flags &= ~ANNOTFLAG_HIDDEN;
52 flags &= ~ANNOTFLAG_INVISIBLE; 64 flags &= ~ANNOTFLAG_INVISIBLE;
53 flags &= ~ANNOTFLAG_NOVIEW; 65 flags &= ~ANNOTFLAG_NOVIEW;
54 flags |= ANNOTFLAG_PRINT; 66 flags |= ANNOTFLAG_PRINT;
55 } 67 }
56 m_BAAnnot->SetFlags(flags); 68 baAnnot->SetFlags(flags);
57 return TRUE; 69 return TRUE;
58 } 70 }
59 71
60 FX_BOOL Annot::name(IJS_Context* cc, 72 FX_BOOL Annot::name(IJS_Context* cc,
61 CJS_PropValue& vp, 73 CJS_PropValue& vp,
62 CFX_WideString& sError) { 74 CFX_WideString& sError) {
75 CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot);
76 if (!baAnnot)
77 return FALSE;
78
63 if (vp.IsGetting()) { 79 if (vp.IsGetting()) {
64 vp << m_BAAnnot->GetAnnotName(); 80 vp << baAnnot->GetAnnotName();
65 return TRUE; 81 return TRUE;
66 } 82 }
67 83
68 CFX_WideString annotName; 84 CFX_WideString annotName;
69 vp >> annotName; 85 vp >> annotName;
70 m_BAAnnot->SetAnnotName(annotName); 86 baAnnot->SetAnnotName(annotName);
71 return TRUE; 87 return TRUE;
72 } 88 }
73 89
74 FX_BOOL Annot::type(IJS_Context* cc, 90 FX_BOOL Annot::type(IJS_Context* cc,
75 CJS_PropValue& vp, 91 CJS_PropValue& vp,
76 CFX_WideString& sError) { 92 CFX_WideString& sError) {
77 if (vp.IsSetting()) { 93 if (vp.IsSetting()) {
78 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 94 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
79 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); 95 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
80 return FALSE; 96 return FALSE;
81 } 97 }
82 98
83 vp << CPDF_Annot::AnnotSubtypeToString(m_BAAnnot->GetAnnotSubtype()); 99 CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot);
100 if (!baAnnot)
101 return FALSE;
102
103 vp << CPDF_Annot::AnnotSubtypeToString(baAnnot->GetAnnotSubtype());
84 return TRUE; 104 return TRUE;
85 } 105 }
86 106
87 void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { 107 void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) {
88 m_BAAnnot = annot; 108 m_pAnnot = annot;
109 m_pObserver.reset(new CPDFSDK_Annot::Observer(&m_pAnnot));
89 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698