From 95460d82634a7464670d697b8c9f0d58a298f3a4 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 25 Oct 2017 20:25:04 -0400 Subject: Rename Annot to cjs_annot Thist CL renames Annot.{h|cpp} to cjs_annot.{h|cpp} to better match the primary class. Change-Id: I9c3e2fcbb149d97e90098018f42205568ef179b1 Reviewed-on: https://pdfium-review.googlesource.com/16851 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/javascript/Annot.cpp | 103 ------------------------------------- fpdfsdk/javascript/Annot.h | 44 ---------------- fpdfsdk/javascript/Document.cpp | 2 +- fpdfsdk/javascript/cjs_annot.cpp | 103 +++++++++++++++++++++++++++++++++++++ fpdfsdk/javascript/cjs_annot.h | 44 ++++++++++++++++ fpdfsdk/javascript/cjs_runtime.cpp | 2 +- 6 files changed, 149 insertions(+), 149 deletions(-) delete mode 100644 fpdfsdk/javascript/Annot.cpp delete mode 100644 fpdfsdk/javascript/Annot.h create mode 100644 fpdfsdk/javascript/cjs_annot.cpp create mode 100644 fpdfsdk/javascript/cjs_annot.h (limited to 'fpdfsdk') diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp deleted file mode 100644 index 4240bbc974..0000000000 --- a/fpdfsdk/javascript/Annot.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/javascript/Annot.h" - -#include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" -#include "fpdfsdk/javascript/JS_Value.h" -#include "fpdfsdk/javascript/cjs_event_context.h" - -namespace { - -CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) { - return static_cast(annot); -} - -} // namespace - -JSConstSpec CJS_Annot::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; - -JSPropertySpec CJS_Annot::PropertySpecs[] = { - {"hidden", get_hidden_static, set_hidden_static}, - {"name", get_name_static, set_name_static}, - {"type", get_type_static, set_type_static}, - {0, 0, 0}}; - -JSMethodSpec CJS_Annot::MethodSpecs[] = {{0, 0}}; - -IMPLEMENT_JS_CLASS(CJS_Annot, Annot, Annot) - -Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} - -Annot::~Annot() {} - -CJS_Return Annot::get_hidden(CJS_Runtime* pRuntime) { - if (!m_pAnnot) - return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); - - CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot(); - return CJS_Return(pRuntime->NewBoolean( - CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()))); -} - -CJS_Return Annot::set_hidden(CJS_Runtime* pRuntime, v8::Local vp) { - // May invalidate m_pAnnot. - bool bHidden = pRuntime->ToBoolean(vp); - if (!m_pAnnot) - return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); - - uint32_t flags = ToBAAnnot(m_pAnnot.Get())->GetFlags(); - if (bHidden) { - flags |= ANNOTFLAG_HIDDEN; - flags |= ANNOTFLAG_INVISIBLE; - flags |= ANNOTFLAG_NOVIEW; - flags &= ~ANNOTFLAG_PRINT; - } else { - flags &= ~ANNOTFLAG_HIDDEN; - flags &= ~ANNOTFLAG_INVISIBLE; - flags &= ~ANNOTFLAG_NOVIEW; - flags |= ANNOTFLAG_PRINT; - } - ToBAAnnot(m_pAnnot.Get())->SetFlags(flags); - - return CJS_Return(true); -} - -CJS_Return Annot::get_name(CJS_Runtime* pRuntime) { - if (!m_pAnnot) - return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); - return CJS_Return( - pRuntime->NewString(ToBAAnnot(m_pAnnot.Get())->GetAnnotName().c_str())); -} - -CJS_Return Annot::set_name(CJS_Runtime* pRuntime, v8::Local vp) { - // May invalidate m_pAnnot. - WideString annotName = pRuntime->ToWideString(vp); - if (!m_pAnnot) - return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); - - ToBAAnnot(m_pAnnot.Get())->SetAnnotName(annotName); - return CJS_Return(true); -} - -CJS_Return Annot::get_type(CJS_Runtime* pRuntime) { - if (!m_pAnnot) - return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); - return CJS_Return(pRuntime->NewString( - WideString::FromLocal(CPDF_Annot::AnnotSubtypeToString( - ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype()) - .c_str()) - .c_str())); -} - -CJS_Return Annot::set_type(CJS_Runtime* pRuntime, v8::Local vp) { - return CJS_Return(JSGetStringFromID(IDS_STRING_JSREADONLY)); -} - -void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { - m_pAnnot.Reset(annot); -} diff --git a/fpdfsdk/javascript/Annot.h b/fpdfsdk/javascript/Annot.h deleted file mode 100644 index b7c951b310..0000000000 --- a/fpdfsdk/javascript/Annot.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_JAVASCRIPT_ANNOT_H_ -#define FPDFSDK_JAVASCRIPT_ANNOT_H_ - -#include "fpdfsdk/cpdfsdk_baannot.h" -#include "fpdfsdk/javascript/JS_Define.h" - -class Annot : public CJS_EmbedObj { - public: - explicit Annot(CJS_Object* pJSObject); - ~Annot() override; - - CJS_Return get_hidden(CJS_Runtime* pRuntime); - CJS_Return set_hidden(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_name(CJS_Runtime* pRuntime); - CJS_Return set_name(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_type(CJS_Runtime* pRuntime); - CJS_Return set_type(CJS_Runtime* pRuntime, v8::Local vp); - - void SetSDKAnnot(CPDFSDK_BAAnnot* annot); - - private: - CPDFSDK_Annot::ObservedPtr m_pAnnot; -}; - -class CJS_Annot : public CJS_Object { - public: - explicit CJS_Annot(v8::Local pObject) : CJS_Object(pObject) {} - ~CJS_Annot() override {} - - DECLARE_JS_CLASS(); - JS_STATIC_PROP(hidden, hidden, Annot); - JS_STATIC_PROP(name, name, Annot); - JS_STATIC_PROP(type, type, Annot); -}; - -#endif // FPDFSDK_JAVASCRIPT_ANNOT_H_ diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index fbd7763201..d72f83822b 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -24,7 +24,6 @@ #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" -#include "fpdfsdk/javascript/Annot.h" #include "fpdfsdk/javascript/Field.h" #include "fpdfsdk/javascript/Icon.h" #include "fpdfsdk/javascript/JS_Define.h" @@ -32,6 +31,7 @@ #include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/app.h" +#include "fpdfsdk/javascript/cjs_annot.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_runtime.h" #include "fpdfsdk/javascript/resource.h" diff --git a/fpdfsdk/javascript/cjs_annot.cpp b/fpdfsdk/javascript/cjs_annot.cpp new file mode 100644 index 0000000000..e69f7ceb64 --- /dev/null +++ b/fpdfsdk/javascript/cjs_annot.cpp @@ -0,0 +1,103 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/javascript/cjs_annot.h" + +#include "fpdfsdk/javascript/JS_Define.h" +#include "fpdfsdk/javascript/JS_Object.h" +#include "fpdfsdk/javascript/JS_Value.h" +#include "fpdfsdk/javascript/cjs_event_context.h" + +namespace { + +CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) { + return static_cast(annot); +} + +} // namespace + +JSConstSpec CJS_Annot::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; + +JSPropertySpec CJS_Annot::PropertySpecs[] = { + {"hidden", get_hidden_static, set_hidden_static}, + {"name", get_name_static, set_name_static}, + {"type", get_type_static, set_type_static}, + {0, 0, 0}}; + +JSMethodSpec CJS_Annot::MethodSpecs[] = {{0, 0}}; + +IMPLEMENT_JS_CLASS(CJS_Annot, Annot, Annot) + +Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} + +Annot::~Annot() {} + +CJS_Return Annot::get_hidden(CJS_Runtime* pRuntime) { + if (!m_pAnnot) + return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); + + CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot(); + return CJS_Return(pRuntime->NewBoolean( + CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()))); +} + +CJS_Return Annot::set_hidden(CJS_Runtime* pRuntime, v8::Local vp) { + // May invalidate m_pAnnot. + bool bHidden = pRuntime->ToBoolean(vp); + if (!m_pAnnot) + return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); + + uint32_t flags = ToBAAnnot(m_pAnnot.Get())->GetFlags(); + if (bHidden) { + flags |= ANNOTFLAG_HIDDEN; + flags |= ANNOTFLAG_INVISIBLE; + flags |= ANNOTFLAG_NOVIEW; + flags &= ~ANNOTFLAG_PRINT; + } else { + flags &= ~ANNOTFLAG_HIDDEN; + flags &= ~ANNOTFLAG_INVISIBLE; + flags &= ~ANNOTFLAG_NOVIEW; + flags |= ANNOTFLAG_PRINT; + } + ToBAAnnot(m_pAnnot.Get())->SetFlags(flags); + + return CJS_Return(true); +} + +CJS_Return Annot::get_name(CJS_Runtime* pRuntime) { + if (!m_pAnnot) + return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); + return CJS_Return( + pRuntime->NewString(ToBAAnnot(m_pAnnot.Get())->GetAnnotName().c_str())); +} + +CJS_Return Annot::set_name(CJS_Runtime* pRuntime, v8::Local vp) { + // May invalidate m_pAnnot. + WideString annotName = pRuntime->ToWideString(vp); + if (!m_pAnnot) + return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); + + ToBAAnnot(m_pAnnot.Get())->SetAnnotName(annotName); + return CJS_Return(true); +} + +CJS_Return Annot::get_type(CJS_Runtime* pRuntime) { + if (!m_pAnnot) + return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); + return CJS_Return(pRuntime->NewString( + WideString::FromLocal(CPDF_Annot::AnnotSubtypeToString( + ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype()) + .c_str()) + .c_str())); +} + +CJS_Return Annot::set_type(CJS_Runtime* pRuntime, v8::Local vp) { + return CJS_Return(JSGetStringFromID(IDS_STRING_JSREADONLY)); +} + +void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { + m_pAnnot.Reset(annot); +} diff --git a/fpdfsdk/javascript/cjs_annot.h b/fpdfsdk/javascript/cjs_annot.h new file mode 100644 index 0000000000..d63043147e --- /dev/null +++ b/fpdfsdk/javascript/cjs_annot.h @@ -0,0 +1,44 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_JAVASCRIPT_CJS_ANNOT_H_ +#define FPDFSDK_JAVASCRIPT_CJS_ANNOT_H_ + +#include "fpdfsdk/cpdfsdk_baannot.h" +#include "fpdfsdk/javascript/JS_Define.h" + +class Annot : public CJS_EmbedObj { + public: + explicit Annot(CJS_Object* pJSObject); + ~Annot() override; + + CJS_Return get_hidden(CJS_Runtime* pRuntime); + CJS_Return set_hidden(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_name(CJS_Runtime* pRuntime); + CJS_Return set_name(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_type(CJS_Runtime* pRuntime); + CJS_Return set_type(CJS_Runtime* pRuntime, v8::Local vp); + + void SetSDKAnnot(CPDFSDK_BAAnnot* annot); + + private: + CPDFSDK_Annot::ObservedPtr m_pAnnot; +}; + +class CJS_Annot : public CJS_Object { + public: + explicit CJS_Annot(v8::Local pObject) : CJS_Object(pObject) {} + ~CJS_Annot() override {} + + DECLARE_JS_CLASS(); + JS_STATIC_PROP(hidden, hidden, Annot); + JS_STATIC_PROP(name, name, Annot); + JS_STATIC_PROP(type, type, Annot); +}; + +#endif // FPDFSDK_JAVASCRIPT_CJS_ANNOT_H_ diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index 0209933748..05bdb7c235 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -9,7 +9,6 @@ #include #include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/javascript/Annot.h" #include "fpdfsdk/javascript/Document.h" #include "fpdfsdk/javascript/Field.h" #include "fpdfsdk/javascript/Icon.h" @@ -20,6 +19,7 @@ #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/PublicMethods.h" #include "fpdfsdk/javascript/app.h" +#include "fpdfsdk/javascript/cjs_annot.h" #include "fpdfsdk/javascript/cjs_border.h" #include "fpdfsdk/javascript/cjs_display.h" #include "fpdfsdk/javascript/cjs_event_context.h" -- cgit v1.2.3