diff options
author | dan sinclair <dsinclair@chromium.org> | 2017-10-25 20:25:04 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-26 16:59:37 +0000 |
commit | 95460d82634a7464670d697b8c9f0d58a298f3a4 (patch) | |
tree | 8e75bed8fed3087bddeb80f60ecf2baee7c46ead /fpdfsdk/javascript/cjs_annot.cpp | |
parent | 993a19931a6ad343310b7d5d076d9e45af0ed528 (diff) | |
download | pdfium-95460d82634a7464670d697b8c9f0d58a298f3a4.tar.xz |
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 <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/cjs_annot.cpp')
-rw-r--r-- | fpdfsdk/javascript/cjs_annot.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
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<CPDFSDK_BAAnnot*>(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<v8::Value> 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<v8::Value> 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<v8::Value> vp) { + return CJS_Return(JSGetStringFromID(IDS_STRING_JSREADONLY)); +} + +void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { + m_pAnnot.Reset(annot); +} |