summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/Annot.cpp
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2017-10-19 14:29:33 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-19 19:50:07 +0000
commitcbe23dbdff3f6e41843fd99cbf615000b52727ed (patch)
treef2f9e6e5f4dc8818ef15a8f72fdfdab71a848097 /fpdfsdk/javascript/Annot.cpp
parentc136b3146257d0f12d1347a9f1a4784372e19a56 (diff)
downloadpdfium-cbe23dbdff3f6e41843fd99cbf615000b52727ed.tar.xz
Refactoring JS Callbacks.
This CL updates the fpdfsdk/javascript callbacks to have explicit get/set methods instead of one method which worked differently depending on the mode. This allows better ownership of the passed in params, (get takes a * and set takes a const&). The Value object was changed to have To* and Set methods to make the code clearer compared to the operator<< and operator>> overloading. Bug: Change-Id: Id6ff20a4e3252adfd0a78b643e50b9f095085018 Reviewed-on: https://pdfium-review.googlesource.com/16330 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/Annot.cpp')
-rw-r--r--fpdfsdk/javascript/Annot.cpp79
1 files changed, 46 insertions, 33 deletions
diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp
index 9cc5d0ff1a..0fb83e051b 100644
--- a/fpdfsdk/javascript/Annot.cpp
+++ b/fpdfsdk/javascript/Annot.cpp
@@ -35,23 +35,25 @@ Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {}
Annot::~Annot() {}
-bool Annot::hidden(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- if (vp.IsGetting()) {
- if (!m_pAnnot) {
- sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
- return false;
- }
- CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot();
- vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict());
- return true;
+bool Annot::get_hidden(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ if (!m_pAnnot) {
+ *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
+ return false;
}
- bool bHidden;
- vp >> bHidden; // May invalidate m_pAnnot.
+ CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot();
+ vp->Set(CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()));
+ return true;
+}
+
+bool Annot::set_hidden(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ bool bHidden = vp.ToBool(); // May invalidate m_pAnnot.
if (!m_pAnnot) {
- sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
+ *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
@@ -68,23 +70,28 @@ bool Annot::hidden(CJS_Runtime* pRuntime,
flags |= ANNOTFLAG_PRINT;
}
ToBAAnnot(m_pAnnot.Get())->SetFlags(flags);
+
return true;
}
-bool Annot::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
- if (vp.IsGetting()) {
- if (!m_pAnnot) {
- sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
- return false;
- }
- vp << ToBAAnnot(m_pAnnot.Get())->GetAnnotName();
- return true;
+bool Annot::get_name(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ if (!m_pAnnot) {
+ *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
+ return false;
}
- WideString annotName;
- vp >> annotName; // May invalidate m_pAnnot.
+ vp->Set(ToBAAnnot(m_pAnnot.Get())->GetAnnotName());
+ return true;
+}
+
+bool Annot::set_name(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ WideString annotName = vp.ToWideString(); // May invalidate m_pAnnot.
if (!m_pAnnot) {
- sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
+ *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
@@ -92,20 +99,26 @@ bool Annot::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
return true;
}
-bool Annot::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
- if (vp.IsSetting()) {
- sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
- return false;
- }
+bool Annot::get_type(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
if (!m_pAnnot) {
- sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
+ *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
- vp << CPDF_Annot::AnnotSubtypeToString(
- ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype());
+
+ vp->Set(CPDF_Annot::AnnotSubtypeToString(
+ ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype()));
return true;
}
+bool Annot::set_type(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ *sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
+ return false;
+}
+
void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) {
m_pAnnot.Reset(annot);
}