diff options
author | dan sinclair <dsinclair@chromium.org> | 2017-10-19 14:29:33 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-19 19:50:07 +0000 |
commit | cbe23dbdff3f6e41843fd99cbf615000b52727ed (patch) | |
tree | f2f9e6e5f4dc8818ef15a8f72fdfdab71a848097 /fpdfsdk/javascript | |
parent | c136b3146257d0f12d1347a9f1a4784372e19a56 (diff) | |
download | pdfium-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')
-rw-r--r-- | fpdfsdk/javascript/Annot.cpp | 79 | ||||
-rw-r--r-- | fpdfsdk/javascript/Annot.h | 23 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 623 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.h | 309 | ||||
-rw-r--r-- | fpdfsdk/javascript/Field.cpp | 2226 | ||||
-rw-r--r-- | fpdfsdk/javascript/Field.h | 533 | ||||
-rw-r--r-- | fpdfsdk/javascript/Icon.cpp | 15 | ||||
-rw-r--r-- | fpdfsdk/javascript/Icon.h | 8 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Define.h | 53 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Value.cpp | 66 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Value.h | 53 | ||||
-rw-r--r-- | fpdfsdk/javascript/PublicMethods.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/javascript/app.cpp | 210 | ||||
-rw-r--r-- | fpdfsdk/javascript/app.h | 123 | ||||
-rw-r--r-- | fpdfsdk/javascript/color.cpp | 180 | ||||
-rw-r--r-- | fpdfsdk/javascript/color.h | 112 | ||||
-rw-r--r-- | fpdfsdk/javascript/event.cpp | 364 | ||||
-rw-r--r-- | fpdfsdk/javascript/event.h | 185 | ||||
-rw-r--r-- | fpdfsdk/javascript/global.cpp | 139 | ||||
-rw-r--r-- | fpdfsdk/javascript/global.h | 12 |
20 files changed, 3264 insertions, 2059 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); } diff --git a/fpdfsdk/javascript/Annot.h b/fpdfsdk/javascript/Annot.h index d70f96a179..c5fb3f2e1e 100644 --- a/fpdfsdk/javascript/Annot.h +++ b/fpdfsdk/javascript/Annot.h @@ -17,9 +17,20 @@ class Annot : public CJS_EmbedObj { explicit Annot(CJS_Object* pJSObject); ~Annot() override; - bool hidden(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); + bool get_hidden(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_hidden(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_name(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_type(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); void SetSDKAnnot(CPDFSDK_BAAnnot* annot); @@ -33,9 +44,9 @@ class CJS_Annot : public CJS_Object { ~CJS_Annot() override {} DECLARE_JS_CLASS(); - JS_STATIC_PROP(hidden, Annot); - JS_STATIC_PROP(name, Annot); - JS_STATIC_PROP(type, Annot); + 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 5d0f35c1bb..e7dee1cefa 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -66,16 +66,16 @@ JSConstSpec CJS_Document::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; JSPropertySpec CJS_Document::PropertySpecs[] = { {"ADBE", get_ADBE_static, set_ADBE_static}, {"author", get_author_static, set_author_static}, - {"baseURL", get_baseURL_static, set_baseURL_static}, - {"bookmarkRoot", get_bookmarkRoot_static, set_bookmarkRoot_static}, + {"baseURL", get_base_URL_static, set_base_URL_static}, + {"bookmarkRoot", get_bookmark_root_static, set_bookmark_root_static}, {"calculate", get_calculate_static, set_calculate_static}, - {"Collab", get_Collab_static, set_Collab_static}, - {"creationDate", get_creationDate_static, set_creationDate_static}, + {"Collab", get_collab_static, set_collab_static}, + {"creationDate", get_creation_date_static, set_creation_date_static}, {"creator", get_creator_static, set_creator_static}, {"delay", get_delay_static, set_delay_static}, {"dirty", get_dirty_static, set_dirty_static}, - {"documentFileName", get_documentFileName_static, - set_documentFileName_static}, + {"documentFileName", get_document_file_name_static, + set_document_file_name_static}, {"external", get_external_static, set_external_static}, {"filesize", get_filesize_static, set_filesize_static}, {"icons", get_icons_static, set_icons_static}, @@ -83,20 +83,21 @@ JSPropertySpec CJS_Document::PropertySpecs[] = { {"keywords", get_keywords_static, set_keywords_static}, {"layout", get_layout_static, set_layout_static}, {"media", get_media_static, set_media_static}, - {"modDate", get_modDate_static, set_modDate_static}, - {"mouseX", get_mouseX_static, set_mouseX_static}, - {"mouseY", get_mouseY_static, set_mouseY_static}, - {"numFields", get_numFields_static, set_numFields_static}, - {"numPages", get_numPages_static, set_numPages_static}, - {"pageNum", get_pageNum_static, set_pageNum_static}, - {"pageWindowRect", get_pageWindowRect_static, set_pageWindowRect_static}, + {"modDate", get_mod_date_static, set_mod_date_static}, + {"mouseX", get_mouse_x_static, set_mouse_x_static}, + {"mouseY", get_mouse_y_static, set_mouse_y_static}, + {"numFields", get_num_fields_static, set_num_fields_static}, + {"numPages", get_num_pages_static, set_num_pages_static}, + {"pageNum", get_page_num_static, set_page_num_static}, + {"pageWindowRect", get_page_window_rect_static, + set_page_window_rect_static}, {"path", get_path_static, set_path_static}, {"producer", get_producer_static, set_producer_static}, {"subject", get_subject_static, set_subject_static}, {"title", get_title_static, set_title_static}, {"URL", get_URL_static, set_URL_static}, {"zoom", get_zoom_static, set_zoom_static}, - {"zoomType", get_zoomType_static, set_zoomType_static}, + {"zoomType", get_zoom_type_static, set_zoom_type_static}, {0, 0, 0}}; JSMethodSpec CJS_Document::MethodSpecs[] = { @@ -158,72 +159,92 @@ Document::Document(CJS_Object* pJSObject) m_cwBaseURL(L""), m_bDelay(false) {} -Document::~Document() { -} +Document::~Document() {} -// the total number of fileds in document. -bool Document::numFields(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } +// the total number of fields in document. +bool Document::get_num_fields(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - vp << static_cast<int>(pPDFForm->CountFields(WideString())); + vp->Set(static_cast<int>(pPDFForm->CountFields(WideString()))); return true; } -bool Document::dirty(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_num_fields(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Document::get_dirty(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - if (vp.IsGetting()) { - vp << !!m_pFormFillEnv->GetChangeMark(); - return true; + + vp->Set(!!m_pFormFillEnv->GetChangeMark()); + return true; +} + +bool Document::set_dirty(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_pFormFillEnv) { + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + return false; } - bool bChanged = false; - vp >> bChanged; - if (bChanged) - m_pFormFillEnv->SetChangeMark(); - else - m_pFormFillEnv->ClearChangeMark(); + + vp.ToBool() ? m_pFormFillEnv->SetChangeMark() + : m_pFormFillEnv->ClearChangeMark(); return true; } -bool Document::ADBE(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsGetting()) - vp.GetJSValue()->SetNull(pRuntime); +bool Document::get_ADBE(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->GetJSValue()->SetNull(pRuntime); + return true; +} +bool Document::set_ADBE(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } -bool Document::pageNum(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_page_num(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - if (vp.IsGetting()) { - if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) - vp << pPageView->GetPageIndex(); - return true; + + if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) + vp->Set(pPageView->GetPageIndex()); + return true; +} + +bool Document::set_page_num(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_pFormFillEnv) { + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + return false; } + int iPageCount = m_pFormFillEnv->GetPageCount(); - int iPageNum = 0; - vp >> iPageNum; + int iPageNum = vp.ToInt(); if (iPageNum >= 0 && iPageNum < iPageCount) m_pFormFillEnv->JS_docgotoPage(iPageNum); else if (iPageNum >= iPageCount) @@ -675,9 +696,15 @@ void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { m_pFormFillEnv.Reset(pFormFillEnv); } -bool Document::bookmarkRoot(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_bookmark_root(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} + +bool Document::set_bookmark_root(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } @@ -736,23 +763,26 @@ bool Document::mailDoc(CJS_Runtime* pRuntime, return true; } -bool Document::author(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_author(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "Author", sError); } -bool Document::info(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } +bool Document::set_author(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "Author", sError); +} + +bool Document::get_info(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + const auto* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) return false; @@ -805,70 +835,112 @@ bool Document::info(CJS_Runtime* pRuntime, pObj, wsKey, pRuntime->NewBoolean(!!pValueObj->GetInteger())); } } - vp << pObj; + vp->Set(pObj); return true; } +bool Document::set_info(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + bool Document::getPropertyInternal(CJS_Runtime* pRuntime, - CJS_PropValue& vp, + CJS_PropValue* vp, const ByteString& propName, - WideString& sError) { + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) return false; - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextFor(propName); - } else { - if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { - sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); - return false; - } - WideString csProperty; - vp >> csProperty; - pDictionary->SetNewFor<CPDF_String>(propName, PDF_EncodeText(csProperty), - false); - m_pFormFillEnv->SetChangeMark(); + vp->Set(pDictionary->GetUnicodeTextFor(propName)); + return true; +} + +bool Document::setPropertyInternal(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + const ByteString& propName, + WideString* sError) { + if (!m_pFormFillEnv) { + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + return false; } + + CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); + if (!pDictionary) + return false; + + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { + *sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); + return false; + } + WideString csProperty = vp.ToWideString(); + pDictionary->SetNewFor<CPDF_String>(propName, PDF_EncodeText(csProperty), + false); + m_pFormFillEnv->SetChangeMark(); return true; } -bool Document::creationDate(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_creation_date(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "CreationDate", sError); } -bool Document::creator(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_creation_date(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "CreationDate", sError); +} + +bool Document::get_creator(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "Creator", sError); } -bool Document::delay(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_creator(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "Creator", sError); +} + +bool Document::get_delay(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - if (vp.IsGetting()) { - vp << m_bDelay; - return true; + vp->Set(m_bDelay); + return true; +} + +bool Document::set_delay(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_pFormFillEnv) { + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + return false; } + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { - sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); + *sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - vp >> m_bDelay; + + m_bDelay = vp.ToBool(); if (m_bDelay) { m_DelayData.clear(); return true; } + std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; DelayDataToProcess.swap(m_DelayData); for (const auto& pData : DelayDataToProcess) @@ -877,143 +949,210 @@ bool Document::delay(CJS_Runtime* pRuntime, return true; } -bool Document::keywords(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_keywords(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "Keywords", sError); } -bool Document::modDate(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_keywords(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "Keywords", sError); +} + +bool Document::get_mod_date(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "ModDate", sError); } -bool Document::producer(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_mod_date(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "ModDate", sError); +} + +bool Document::get_producer(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "Producer", sError); } -bool Document::subject(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_producer(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "Producer", sError); +} + +bool Document::get_subject(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return getPropertyInternal(pRuntime, vp, "Subject", sError); } -bool Document::title(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_subject(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return setPropertyInternal(pRuntime, vp, "Subject", sError); +} + +bool Document::get_title(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } return getPropertyInternal(pRuntime, vp, "Title", sError); } -bool Document::numPages(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); +bool Document::set_title(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + return setPropertyInternal(pRuntime, vp, "Title", sError); +} + +bool Document::get_num_pages(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - vp << m_pFormFillEnv->GetPageCount(); + vp->Set(m_pFormFillEnv->GetPageCount()); return true; } -bool Document::external(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_num_pages(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Document::get_external(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { // In Chrome case, should always return true. - if (vp.IsGetting()) { - vp << true; - } + vp->Set(true); return true; } -bool Document::filesize(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } - vp << 0; +bool Document::set_external(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } -bool Document::mouseX(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_filesize(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(0); return true; } -bool Document::mouseY(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_filesize(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Document::get_mouse_x(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return true; } -bool Document::URL(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } +bool Document::set_mouse_x(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} + +bool Document::get_mouse_y(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} + +bool Document::set_mouse_y(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} + +bool Document::get_URL(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - vp << m_pFormFillEnv->JS_docGetFilePath(); + vp->Set(m_pFormFillEnv->JS_docGetFilePath()); return true; } -bool Document::baseURL(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsGetting()) { - vp << m_cwBaseURL; - } else { - vp >> m_cwBaseURL; - } +bool Document::set_URL(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Document::get_base_URL(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(m_cwBaseURL); return true; } -bool Document::calculate(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_base_URL(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + m_cwBaseURL = vp.ToWideString(); + return true; +} + +bool Document::get_calculate(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - if (vp.IsGetting()) { - vp << !!pInterForm->IsCalculateEnabled(); - return true; - } - bool bCalculate; - vp >> bCalculate; - pInterForm->EnableCalculate(bCalculate); + vp->Set(!!pInterForm->IsCalculateEnabled()); return true; } -bool Document::documentFileName(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); +bool Document::set_calculate(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_pFormFillEnv) { + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); + pInterForm->EnableCalculate(vp.ToBool()); + return true; +} + +bool Document::get_document_file_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } + WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); size_t i = wsFilePath.GetLength(); for (; i > 0; i--) { @@ -1022,37 +1161,59 @@ bool Document::documentFileName(CJS_Runtime* pRuntime, } if (i > 0 && i < wsFilePath.GetLength()) - vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i); + vp->Set(wsFilePath.GetBuffer(wsFilePath.GetLength()) + i); else - vp << L""; + vp->Set(L""); return true; } -bool Document::path(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } +bool Document::set_document_file_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Document::get_path(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (!m_pFormFillEnv) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); + vp->Set(app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath())); return true; } -bool Document::pageWindowRect(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_path(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Document::get_page_window_rect(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return true; } -bool Document::layout(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::set_page_window_rect(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} + +bool Document::get_layout(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} + +bool Document::set_layout(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } @@ -1226,15 +1387,11 @@ bool Document::addIcon(CJS_Runtime* pRuntime, return true; } -bool Document::icons(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } +bool Document::get_icons(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { if (m_IconNames.empty()) { - vp.GetJSValue()->SetNull(pRuntime); + vp->GetJSValue()->SetNull(pRuntime); return true; } @@ -1253,10 +1410,17 @@ bool Document::icons(CJS_Runtime* pRuntime, Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); } - vp << Icons; + vp->Set(Icons); return true; } +bool Document::set_icons(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + bool Document::getIcon(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, CJS_Value& vRet, @@ -1299,9 +1463,15 @@ bool Document::createDataObject(CJS_Runtime* pRuntime, return true; } -bool Document::media(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_media(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} + +bool Document::set_media(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } @@ -1323,9 +1493,15 @@ bool Document::calculateNow(CJS_Runtime* pRuntime, return true; } -bool Document::Collab(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_collab(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} + +bool Document::set_collab(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } @@ -1524,25 +1700,26 @@ WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex) { return swRet; } -bool Document::zoom(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_zoom(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return true; } -/** -(none, NoVary) -(fitP, FitPage) -(fitW, FitWidth) -(fitH, FitHeight) -(fitV, FitVisibleWidth) -(pref, Preferred) -(refW, ReflowWidth) -*/ +bool Document::set_zoom(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} -bool Document::zoomType(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Document::get_zoom_type(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} +bool Document::set_zoom_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index 3cec9fa4bc..8535cd0fd8 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -50,45 +50,203 @@ class Document : public CJS_EmbedObj { explicit Document(CJS_Object* pJSObject); ~Document() override; - bool ADBE(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool author(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool baseURL(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool bookmarkRoot(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool calculate(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool Collab(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool creationDate(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool creator(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool delay(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool dirty(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool documentFileName(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool external(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool filesize(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool icons(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool info(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool keywords(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool layout(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool media(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool modDate(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool mouseX(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool mouseY(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool numFields(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool numPages(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool pageNum(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool pageWindowRect(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool path(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool producer(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool subject(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool title(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool zoom(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool zoomType(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); + bool get_ADBE(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_ADBE(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_author(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_author(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_base_URL(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_base_URL(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_bookmark_root(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_bookmark_root(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_calculate(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_calculate(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_collab(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_collab(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_creation_date(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_creation_date(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_creator(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_creator(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_delay(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_delay(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_dirty(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_dirty(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_document_file_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_document_file_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_external(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_external(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_filesize(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_filesize(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_icons(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_icons(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_info(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_info(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_keywords(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_keywords(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_layout(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_layout(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_media(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_media(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_mod_date(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_mod_date(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_mouse_x(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_mouse_x(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_mouse_y(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_mouse_y(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_num_fields(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_num_fields(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_num_pages(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_num_pages(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_page_num(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_page_num(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_page_window_rect(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_page_window_rect(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_path(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_path(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_producer(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_producer(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_subject(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_subject(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_title(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_title(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_zoom(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_zoom(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_zoom_type(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_zoom_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_URL(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_URL(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); bool addAnnot(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, @@ -258,7 +416,6 @@ class Document : public CJS_EmbedObj { const std::vector<CJS_Value>& params, CJS_Value& vRet, WideString& sError); - bool URL(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { @@ -274,9 +431,13 @@ class Document : public CJS_EmbedObj { WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); bool getPropertyInternal(CJS_Runtime* pRuntime, - CJS_PropValue& vp, + CJS_PropValue* vp, const ByteString& propName, - WideString& sError); + WideString* sError); + bool setPropertyInternal(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + const ByteString& propName, + WideString* sError); CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; WideString m_cwBaseURL; @@ -296,38 +457,38 @@ class CJS_Document : public CJS_Object { DECLARE_JS_CLASS(); - JS_STATIC_PROP(ADBE, Document); - JS_STATIC_PROP(author, Document); - JS_STATIC_PROP(baseURL, Document); - JS_STATIC_PROP(bookmarkRoot, Document); - JS_STATIC_PROP(calculate, Document); - JS_STATIC_PROP(Collab, Document); - JS_STATIC_PROP(creationDate, Document); - JS_STATIC_PROP(creator, Document); - JS_STATIC_PROP(delay, Document); - JS_STATIC_PROP(dirty, Document); - JS_STATIC_PROP(documentFileName, Document); - JS_STATIC_PROP(external, Document); - JS_STATIC_PROP(filesize, Document); - JS_STATIC_PROP(icons, Document); - JS_STATIC_PROP(info, Document); - JS_STATIC_PROP(keywords, Document); - JS_STATIC_PROP(layout, Document); - JS_STATIC_PROP(media, Document); - JS_STATIC_PROP(modDate, Document); - JS_STATIC_PROP(mouseX, Document); - JS_STATIC_PROP(mouseY, Document); - JS_STATIC_PROP(numFields, Document); - JS_STATIC_PROP(numPages, Document); - JS_STATIC_PROP(pageNum, Document); - JS_STATIC_PROP(pageWindowRect, Document); - JS_STATIC_PROP(path, Document); - JS_STATIC_PROP(producer, Document); - JS_STATIC_PROP(subject, Document); - JS_STATIC_PROP(title, Document); - JS_STATIC_PROP(URL, Document); - JS_STATIC_PROP(zoom, Document); - JS_STATIC_PROP(zoomType, Document); + JS_STATIC_PROP(ADBE, ADBE, Document); + JS_STATIC_PROP(author, author, Document); + JS_STATIC_PROP(baseURL, base_URL, Document); + JS_STATIC_PROP(bookmarkRoot, bookmark_root, Document); + JS_STATIC_PROP(calculate, calculate, Document); + JS_STATIC_PROP(Collab, collab, Document); + JS_STATIC_PROP(creationDate, creation_date, Document); + JS_STATIC_PROP(creator, creator, Document); + JS_STATIC_PROP(delay, delay, Document); + JS_STATIC_PROP(dirty, dirty, Document); + JS_STATIC_PROP(documentFileName, document_file_name, Document); + JS_STATIC_PROP(external, external, Document); + JS_STATIC_PROP(filesize, filesize, Document); + JS_STATIC_PROP(icons, icons, Document); + JS_STATIC_PROP(info, info, Document); + JS_STATIC_PROP(keywords, keywords, Document); + JS_STATIC_PROP(layout, layout, Document); + JS_STATIC_PROP(media, media, Document); + JS_STATIC_PROP(modDate, mod_date, Document); + JS_STATIC_PROP(mouseX, mouse_x, Document); + JS_STATIC_PROP(mouseY, mouse_y, Document); + JS_STATIC_PROP(numFields, num_fields, Document); + JS_STATIC_PROP(numPages, num_pages, Document); + JS_STATIC_PROP(pageNum, page_num, Document); + JS_STATIC_PROP(pageWindowRect, page_window_rect, Document); + JS_STATIC_PROP(path, path, Document); + JS_STATIC_PROP(producer, producer, Document); + JS_STATIC_PROP(subject, subject, Document); + JS_STATIC_PROP(title, title, Document); + JS_STATIC_PROP(URL, URL, Document); + JS_STATIC_PROP(zoom, zoom, Document); + JS_STATIC_PROP(zoomType, zoom_type, Document); JS_STATIC_METHOD(addAnnot, Document); JS_STATIC_METHOD(addField, Document); diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 4e40e6fce5..ce272d5239 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -76,59 +76,65 @@ JSConstSpec CJS_Field::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; JSPropertySpec CJS_Field::PropertySpecs[] = { {"alignment", get_alignment_static, set_alignment_static}, - {"borderStyle", get_borderStyle_static, set_borderStyle_static}, - {"buttonAlignX", get_buttonAlignX_static, set_buttonAlignX_static}, - {"buttonAlignY", get_buttonAlignY_static, set_buttonAlignY_static}, - {"buttonFitBounds", get_buttonFitBounds_static, set_buttonFitBounds_static}, - {"buttonPosition", get_buttonPosition_static, set_buttonPosition_static}, - {"buttonScaleHow", get_buttonScaleHow_static, set_buttonScaleHow_static}, - {"buttonScaleWhen", get_buttonScaleWhen_static, set_buttonScaleWhen_static}, - {"calcOrderIndex", get_calcOrderIndex_static, set_calcOrderIndex_static}, - {"charLimit", get_charLimit_static, set_charLimit_static}, + {"borderStyle", get_border_style_static, set_border_style_static}, + {"buttonAlignX", get_button_align_x_static, set_button_align_x_static}, + {"buttonAlignY", get_button_align_y_static, set_button_align_y_static}, + {"buttonFitBounds", get_button_fit_bounds_static, + set_button_fit_bounds_static}, + {"buttonPosition", get_button_position_static, set_button_position_static}, + {"buttonScaleHow", get_button_scale_how_static, + set_button_scale_how_static}, + {"buttonScaleWhen", get_button_scale_when_static, + set_button_scale_when_static}, + {"calcOrderIndex", get_calc_order_index_static, + set_calc_order_index_static}, + {"charLimit", get_char_limit_static, set_char_limit_static}, {"comb", get_comb_static, set_comb_static}, - {"commitOnSelChange", get_commitOnSelChange_static, - set_commitOnSelChange_static}, - {"currentValueIndices", get_currentValueIndices_static, - set_currentValueIndices_static}, - {"defaultStyle", get_defaultStyle_static, set_defaultStyle_static}, - {"defaultValue", get_defaultValue_static, set_defaultValue_static}, - {"doNotScroll", get_doNotScroll_static, set_doNotScroll_static}, - {"doNotSpellCheck", get_doNotSpellCheck_static, set_doNotSpellCheck_static}, + {"commitOnSelChange", get_commit_on_sel_change_static, + set_commit_on_sel_change_static}, + {"currentValueIndices", get_current_value_indices_static, + set_current_value_indices_static}, + {"defaultStyle", get_default_style_static, set_default_style_static}, + {"defaultValue", get_default_value_static, set_default_value_static}, + {"doNotScroll", get_do_not_scroll_static, set_do_not_scroll_static}, + {"doNotSpellCheck", get_do_not_spell_check_static, + set_do_not_spell_check_static}, {"delay", get_delay_static, set_delay_static}, {"display", get_display_static, set_display_static}, {"doc", get_doc_static, set_doc_static}, {"editable", get_editable_static, set_editable_static}, - {"exportValues", get_exportValues_static, set_exportValues_static}, + {"exportValues", get_export_values_static, set_export_values_static}, {"hidden", get_hidden_static, set_hidden_static}, - {"fileSelect", get_fileSelect_static, set_fileSelect_static}, - {"fillColor", get_fillColor_static, set_fillColor_static}, - {"lineWidth", get_lineWidth_static, set_lineWidth_static}, + {"fileSelect", get_file_select_static, set_file_select_static}, + {"fillColor", get_fill_color_static, set_fill_color_static}, + {"lineWidth", get_line_width_static, set_line_width_static}, {"highlight", get_highlight_static, set_highlight_static}, {"multiline", get_multiline_static, set_multiline_static}, - {"multipleSelection", get_multipleSelection_static, - set_multipleSelection_static}, + {"multipleSelection", get_multiple_selection_static, + set_multiple_selection_static}, {"name", get_name_static, set_name_static}, - {"numItems", get_numItems_static, set_numItems_static}, + {"numItems", get_num_items_static, set_num_items_static}, {"page", get_page_static, set_page_static}, {"password", get_password_static, set_password_static}, {"print", get_print_static, set_print_static}, - {"radiosInUnison", get_radiosInUnison_static, set_radiosInUnison_static}, + {"radiosInUnison", get_radios_in_unison_static, + set_radios_in_unison_static}, {"readonly", get_readonly_static, set_readonly_static}, {"rect", get_rect_static, set_rect_static}, {"required", get_required_static, set_required_static}, - {"richText", get_richText_static, set_richText_static}, - {"richValue", get_richValue_static, set_richValue_static}, + {"richText", get_rich_text_static, set_rich_text_static}, + {"richValue", get_rich_value_static, set_rich_value_static}, {"rotation", get_rotation_static, set_rotation_static}, - {"strokeColor", get_strokeColor_static, set_strokeColor_static}, + {"strokeColor", get_stroke_color_static, set_stroke_color_static}, {"style", get_style_static, set_style_static}, - {"submitName", get_submitName_static, set_submitName_static}, - {"textColor", get_textColor_static, set_textColor_static}, - {"textFont", get_textFont_static, set_textFont_static}, - {"textSize", get_textSize_static, set_textSize_static}, + {"submitName", get_submit_name_static, set_submit_name_static}, + {"textColor", get_text_color_static, set_text_color_static}, + {"textFont", get_text_font_static, set_text_font_static}, + {"textSize", get_text_size_static, set_text_size_static}, {"type", get_type_static, set_type_static}, - {"userName", get_userName_static, set_userName_static}, + {"userName", get_user_name_static, set_user_name_static}, {"value", get_value_static, set_value_static}, - {"valueAsString", get_valueAsString_static, set_valueAsString_static}, + {"valueAsString", get_value_as_string_static, set_value_as_string_static}, {"source", get_source_static, set_source_static}, {0, 0, 0}}; @@ -168,8 +174,7 @@ CJS_DelayData::CJS_DelayData(FIELD_PROP prop, int idx, const WideString& name) CJS_DelayData::~CJS_DelayData() {} -void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { -} +void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {} Field::Field(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), @@ -378,25 +383,11 @@ CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) { return pFormField->GetControl(m_nFormControlIndex); } -bool Field::alignment(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_alignment(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - ByteString alignStr; - vp >> alignStr; - - if (m_bDelay) { - AddDelay_String(FP_ALIGNMENT, alignStr); - } else { - Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, alignStr); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -411,22 +402,38 @@ bool Field::alignment(CJS_Runtime* pRuntime, switch (pFormControl->GetControlAlignment()) { case 1: - vp << L"center"; + vp->Set(L"center"); break; case 0: - vp << L"left"; + vp->Set(L"left"); break; case 2: - vp << L"right"; + vp->Set(L"right"); break; default: - vp << L""; + vp->Set(L""); } - } return true; } +bool Field::set_alignment(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_String(FP_ALIGNMENT, vp.ToByteString()); + } else { + Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToByteString()); + } + return true; +} + void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv, const WideString& swFieldName, int nControlIndex, @@ -434,60 +441,61 @@ void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::borderStyle(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_border_style(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - ByteString strType = ""; - vp >> strType; + CPDF_FormField* pFormField = FieldArray[0]; + if (!pFormField) + return false; - if (m_bDelay) { - AddDelay_String(FP_BORDERSTYLE, strType); - } else { - Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, strType); - } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + CPDFSDK_Widget* pWidget = + GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField)); + if (!pWidget) + return false; - CPDF_FormField* pFormField = FieldArray[0]; - if (!pFormField) - return false; + switch (pWidget->GetBorderStyle()) { + case BorderStyle::SOLID: + vp->Set(L"solid"); + break; + case BorderStyle::DASH: + vp->Set(L"dashed"); + break; + case BorderStyle::BEVELED: + vp->Set(L"beveled"); + break; + case BorderStyle::INSET: + vp->Set(L"inset"); + break; + case BorderStyle::UNDERLINE: + vp->Set(L"underline"); + break; + default: + vp->Set(L""); + break; + } + return true; +} - CPDFSDK_Widget* pWidget = - GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField)); - if (!pWidget) - return false; +bool Field::set_border_style(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); - switch (pWidget->GetBorderStyle()) { - case BorderStyle::SOLID: - vp << L"solid"; - break; - case BorderStyle::DASH: - vp << L"dashed"; - break; - case BorderStyle::BEVELED: - vp << L"beveled"; - break; - case BorderStyle::INSET: - vp << L"inset"; - break; - case BorderStyle::UNDERLINE: - vp << L"underline"; - break; - default: - vp << L""; - break; - } - } + if (!m_bCanSet) + return false; + if (m_bDelay) { + AddDelay_String(FP_BORDERSTYLE, vp.ToByteString()); + } else { + Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToByteString()); + } return true; } @@ -543,45 +551,47 @@ void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::buttonAlignX(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_button_align_x(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - int nVP; - vp >> nVP; + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return false; - if (m_bDelay) { - AddDelay_Int(FP_BUTTONALIGNX, nVP); - } else { - Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return false; - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return false; + CPDF_IconFit IconFit = pFormControl->GetIconFit(); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl) - return false; + float fLeft; + float fBottom; + IconFit.GetIconPosition(fLeft, fBottom); - CPDF_IconFit IconFit = pFormControl->GetIconFit(); + vp->Set(static_cast<int32_t>(fLeft)); + return true; +} - float fLeft, fBottom; - IconFit.GetIconPosition(fLeft, fBottom); +bool Field::set_button_align_x(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); - vp << (int32_t)fLeft; - } + if (!m_bCanSet) + return false; + if (m_bDelay) { + AddDelay_Int(FP_BUTTONALIGNX, vp.ToInt()); + } else { + Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToInt()); + } return true; } @@ -592,43 +602,46 @@ void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonAlignY(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_button_align_y(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - int nVP; - vp >> nVP; + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return false; - if (m_bDelay) { - AddDelay_Int(FP_BUTTONALIGNY, nVP); - } else { - Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return false; - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return false; + CPDF_IconFit IconFit = pFormControl->GetIconFit(); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl) - return false; + float fLeft; + float fBottom; + IconFit.GetIconPosition(fLeft, fBottom); - CPDF_IconFit IconFit = pFormControl->GetIconFit(); + vp->Set(static_cast<int32_t>(fBottom)); + return true; +} + +bool Field::set_button_align_y(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); - float fLeft, fBottom; - IconFit.GetIconPosition(fLeft, fBottom); + if (!m_bCanSet) + return false; - vp << (int32_t)fBottom; + if (m_bDelay) { + AddDelay_Int(FP_BUTTONALIGNY, vp.ToInt()); + } else { + Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToInt()); } return true; @@ -641,25 +654,11 @@ void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonFitBounds(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_button_fit_bounds(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - - if (m_bDelay) { - AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP); - } else { - Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, bVP); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -672,9 +671,24 @@ bool Field::buttonFitBounds(CJS_Runtime* pRuntime, if (!pFormControl) return false; - vp << pFormControl->GetIconFit().GetFittingBounds(); - } + vp->Set(pFormControl->GetIconFit().GetFittingBounds()); + return true; +} + +bool Field::set_button_fit_bounds(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Bool(FP_BUTTONFITBOUNDS, vp.ToBool()); + } else { + Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToBool()); + } return true; } @@ -685,25 +699,11 @@ void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonPosition(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_button_position(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - int nVP; - vp >> nVP; - - if (m_bDelay) { - AddDelay_Int(FP_BUTTONPOSITION, nVP); - } else { - Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -716,7 +716,23 @@ bool Field::buttonPosition(CJS_Runtime* pRuntime, if (!pFormControl) return false; - vp << pFormControl->GetTextPosition(); + vp->Set(pFormControl->GetTextPosition()); + return true; +} + +bool Field::set_button_position(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Int(FP_BUTTONPOSITION, vp.ToInt()); + } else { + Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToInt()); } return true; } @@ -728,25 +744,11 @@ void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonScaleHow(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_button_scale_how(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - int nVP; - vp >> nVP; - - if (m_bDelay) { - AddDelay_Int(FP_BUTTONSCALEHOW, nVP); - } else { - Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -759,13 +761,24 @@ bool Field::buttonScaleHow(CJS_Runtime* pRuntime, if (!pFormControl) return false; - CPDF_IconFit IconFit = pFormControl->GetIconFit(); - if (IconFit.IsProportionalScale()) - vp << (int32_t)0; - else - vp << (int32_t)1; - } + vp->Set(pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1); + return true; +} + +bool Field::set_button_scale_how(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + if (m_bDelay) { + AddDelay_Int(FP_BUTTONSCALEHOW, vp.ToInt()); + } else { + Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToInt()); + } return true; } @@ -776,25 +789,11 @@ void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonScaleWhen(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_button_scale_when(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - int nVP; - vp >> nVP; - - if (m_bDelay) { - AddDelay_Int(FP_BUTTONSCALEWHEN, nVP); - } else { - Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -811,20 +810,35 @@ bool Field::buttonScaleWhen(CJS_Runtime* pRuntime, int ScaleM = IconFit.GetScaleMethod(); switch (ScaleM) { case CPDF_IconFit::Always: - vp << (int32_t)CPDF_IconFit::Always; + vp->Set(static_cast<int32_t>(CPDF_IconFit::Always)); break; case CPDF_IconFit::Bigger: - vp << (int32_t)CPDF_IconFit::Bigger; + vp->Set(static_cast<int32_t>(CPDF_IconFit::Bigger)); break; case CPDF_IconFit::Never: - vp << (int32_t)CPDF_IconFit::Never; + vp->Set(static_cast<int32_t>(CPDF_IconFit::Never)); break; case CPDF_IconFit::Smaller: - vp << (int32_t)CPDF_IconFit::Smaller; + vp->Set(static_cast<int32_t>(CPDF_IconFit::Smaller)); break; } - } + return true; +} +bool Field::set_button_scale_when(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Int(FP_BUTTONSCALEWHEN, vp.ToInt()); + } else { + Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToInt()); + } return true; } @@ -835,25 +849,11 @@ void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::calcOrderIndex(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_calc_order_index(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - int nVP; - vp >> nVP; - - if (m_bDelay) { - AddDelay_Int(FP_CALCORDERINDEX, nVP); - } else { - Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -866,9 +866,25 @@ bool Field::calcOrderIndex(CJS_Runtime* pRuntime, CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); - vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); - } + vp->Set(static_cast<int32_t>( + pInterForm->FindFieldInCalculationOrder(pFormField))); + return true; +} +bool Field::set_calc_order_index(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Int(FP_CALCORDERINDEX, vp.ToInt()); + } else { + Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToInt()); + } return true; } @@ -879,34 +895,36 @@ void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::charLimit(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_char_limit(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - int nVP; - vp >> nVP; + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return false; - if (m_bDelay) { - AddDelay_Int(FP_CHARLIMIT, nVP); - } else { - Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, nVP); - } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + vp->Set(static_cast<int32_t>(pFormField->GetMaxLen())); + return true; +} - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return false; +bool Field::set_char_limit(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; - vp << (int32_t)pFormField->GetMaxLen(); + if (m_bDelay) { + AddDelay_Int(FP_CHARLIMIT, vp.ToInt()); + } else { + Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToInt()); } return true; } @@ -918,35 +936,36 @@ void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::comb(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { +bool Field::get_comb(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - bool bVP; - vp >> bVP; + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return false; - if (m_bDelay) { - AddDelay_Bool(FP_COMB, bVP); - } else { - Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - bVP); - } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB)); + return true; +} - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return false; +bool Field::set_comb(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); - if (pFormField->GetFieldFlags() & FIELDFLAG_COMB) - vp << true; - else - vp << false; + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Bool(FP_COMB, vp.ToBool()); + } else { + Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToBool()); } return true; @@ -959,25 +978,11 @@ void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::commitOnSelChange(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_commit_on_sel_change(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - - if (m_bDelay) { - AddDelay_Bool(FP_COMMITONSELCHANGE, bVP); - } else { - Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, bVP); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -988,12 +993,24 @@ bool Field::commitOnSelChange(CJS_Runtime* pRuntime, return false; } - if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE) - vp << true; - else - vp << false; - } + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)); + return true; +} + +bool Field::set_commit_on_sel_change(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + if (m_bDelay) { + AddDelay_Bool(FP_COMMITONSELCHANGE, vp.ToBool()); + } else { + Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToBool()); + } return true; } @@ -1004,61 +1021,63 @@ void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::currentValueIndices(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; +bool Field::get_current_value_indices(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - std::vector<uint32_t> array; - if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) { - int iSelecting = 0; - vp >> iSelecting; - array.push_back(iSelecting); - } else if (vp.GetJSValue()->IsArrayObject()) { - CJS_Array SelArray; - CJS_Value SelValue(pRuntime); - int iSelecting; - vp >> SelArray; - for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) { - SelArray.GetElement(pRuntime, i, SelValue); - iSelecting = SelValue.ToInt(pRuntime); - array.push_back(iSelecting); - } - } + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && + pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { + return false; + } - if (m_bDelay) { - AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); - } else { - Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, array); - } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + int count = pFormField->CountSelectedItems(); + if (count <= 0) { + vp->Set(-1); + return true; + } + if (count == 1) { + vp->Set(pFormField->GetSelectedIndex(0)); + return true; + } - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && - pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { - return false; - } + CJS_Array SelArray; + for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { + SelArray.SetElement(pRuntime, i, + CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); + } + vp->Set(SelArray); - if (pFormField->CountSelectedItems() == 1) { - vp << pFormField->GetSelectedIndex(0); - } else if (pFormField->CountSelectedItems() > 1) { - CJS_Array SelArray; - for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { - SelArray.SetElement( - pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); - } - vp << SelArray; - } else { - vp << -1; + return true; +} + +bool Field::set_current_value_indices(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + std::vector<uint32_t> array; + if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) { + array.push_back(vp.ToInt()); + } else if (vp.GetJSValue()->IsArrayObject()) { + CJS_Array SelArray = vp.ToArray(); + CJS_Value SelValue(pRuntime); + for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) { + SelArray.GetElement(pRuntime, i, SelValue); + array.push_back(SelValue.ToInt(pRuntime)); } } + if (m_bDelay) { + AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); + } else { + Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, array); + } return true; } @@ -1088,9 +1107,15 @@ void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::defaultStyle(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_default_style(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return false; +} + +bool Field::set_default_style(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } @@ -1100,25 +1125,11 @@ void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::defaultValue(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_default_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - WideString WideStr; - vp >> WideStr; - - if (m_bDelay) { - AddDelay_WideString(FP_DEFAULTVALUE, WideStr); - } else { - Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, WideStr); - } - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1129,7 +1140,23 @@ bool Field::defaultValue(CJS_Runtime* pRuntime, return false; } - vp << pFormField->GetDefaultValue(); + vp->Set(pFormField->GetDefaultValue()); + return true; +} + +bool Field::set_default_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_WideString(FP_DEFAULTVALUE, vp.ToWideString()); + } else { + Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToWideString()); } return true; } @@ -1141,39 +1168,37 @@ void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::doNotScroll(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_do_not_scroll(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; + + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return false; + + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)); + return true; +} + +bool Field::set_do_not_scroll(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { if (!m_bCanSet) return false; - bool bVP; - vp >> bVP; - if (m_bDelay) { - AddDelay_Bool(FP_DONOTSCROLL, bVP); + AddDelay_Bool(FP_DONOTSCROLL, vp.ToBool()); } else { Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, bVP); + m_nFormControlIndex, vp.ToBool()); } - } else { - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; - - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return false; - - if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL) - vp << true; - else - vp << false; - } - return true; } @@ -1184,18 +1209,11 @@ void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::doNotSpellCheck(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_do_not_spell_check(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - } else { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1206,63 +1224,54 @@ bool Field::doNotSpellCheck(CJS_Runtime* pRuntime, return false; } - if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK) - vp << true; - else - vp << false; - } + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)); + return true; +} - return true; +bool Field::set_do_not_spell_check(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + return m_bCanSet; } void Field::SetDelay(bool bDelay) { m_bDelay = bDelay; - if (!m_bDelay) { - if (m_pJSDoc) - m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex); - } + if (m_bDelay) + return; + + if (m_pJSDoc) + m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex); } -bool Field::delay(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsSetting()) { - vp << m_bDelay; - return true; - } +bool Field::get_delay(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(m_bDelay); + return true; +} + +bool Field::set_delay(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { if (!m_bCanSet) return false; - bool bVP; - vp >> bVP; - SetDelay(bVP); + SetDelay(vp.ToBool()); return true; } -bool Field::display(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - int nVP; - vp >> nVP; - if (m_bDelay) { - AddDelay_Int(FP_DISPLAY, nVP); - } else { - Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - nVP); - } - return true; - } +bool Field::get_display(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; CPDF_FormField* pFormField = FieldArray[0]; ASSERT(pFormField); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); @@ -1271,17 +1280,31 @@ bool Field::display(CJS_Runtime* pRuntime, uint32_t dwFlag = pWidget->GetFlags(); if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) { - vp << (int32_t)1; + vp->Set(1); + return true; + } + if (ANNOTFLAG_PRINT & dwFlag) { + if (ANNOTFLAG_NOVIEW & dwFlag) + vp->Set(3); + else + vp->Set(0); } else { - if (ANNOTFLAG_PRINT & dwFlag) { - if (ANNOTFLAG_NOVIEW & dwFlag) { - vp << (int32_t)3; - } else { - vp << (int32_t)0; - } - } else { - vp << (int32_t)2; - } + vp->Set(2); + } + return true; +} + +bool Field::set_display(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Int(FP_DISPLAY, vp.ToInt()); + } else { + Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToInt()); } return true; } @@ -1322,25 +1345,22 @@ void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::doc(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) - return false; - - vp << m_pJSDoc->GetCJSDoc(); +bool Field::get_doc(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(m_pJSDoc->GetCJSDoc()); return true; } -bool Field::editable(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; +bool Field::set_doc(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} - bool bVP; - vp >> bVP; - return true; - } +bool Field::get_editable(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1349,13 +1369,19 @@ bool Field::editable(CJS_Runtime* pRuntime, if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) return false; - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT); + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT)); return true; } -bool Field::exportValues(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_editable(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return m_bCanSet; +} + +bool Field::get_export_values(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1365,8 +1391,6 @@ bool Field::exportValues(CJS_Runtime* pRuntime, pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) { return false; } - if (vp.IsSetting()) - return m_bCanSet && vp.GetJSValue()->IsArrayObject(); CJS_Array ExportValusArray; if (m_nFormControlIndex < 0) { @@ -1389,60 +1413,64 @@ bool Field::exportValues(CJS_Runtime* pRuntime, pRuntime, 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); } - vp << ExportValusArray; + + vp->Set(ExportValusArray); return true; } -bool Field::fileSelect(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_export_values(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && + pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) { return false; + } - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + return m_bCanSet && vp.GetJSValue()->IsArrayObject(); +} - bool bVP; - vp >> bVP; - return true; - } - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT); +bool Field::get_file_select(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; + + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return false; + + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)); return true; } -bool Field::fillColor(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - CJS_Array crArray; +bool Field::set_file_select(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return false; - if (!vp.GetJSValue()->IsArrayObject()) - return false; + return m_bCanSet; +} - vp >> crArray; +bool Field::get_fill_color(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + CJS_Array crArray; + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - CFX_Color color; - color::ConvertArrayToPWLColor(pRuntime, crArray, &color); - if (m_bDelay) { - AddDelay_Color(FP_FILLCOLOR, color); - } else { - Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, color); - } - return true; - } CPDF_FormField* pFormField = FieldArray[0]; ASSERT(pFormField); CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); @@ -1472,8 +1500,34 @@ bool Field::fillColor(CJS_Runtime* pRuntime, } else { return false; } + color::ConvertPWLColorToArray(pRuntime, color, &crArray); - vp << crArray; + vp->Set(crArray); + return true; +} + +bool Field::set_fill_color(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; + + if (!m_bCanSet) + return false; + + if (!vp.GetJSValue()->IsArrayObject()) + return false; + + CJS_Array crArray = vp.ToArray(); + CFX_Color color; + color::ConvertArrayToPWLColor(pRuntime, crArray, &color); + if (m_bDelay) { + AddDelay_Color(FP_FILLCOLOR, color); + } else { + Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + color); + } return true; } @@ -1484,29 +1538,16 @@ void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::hidden(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - if (m_bDelay) { - AddDelay_Bool(FP_HIDDEN, bVP); - } else { - Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - bVP); - } - return true; - } +bool Field::get_hidden(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; CPDF_FormField* pFormField = FieldArray[0]; ASSERT(pFormField); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); @@ -1514,11 +1555,22 @@ bool Field::hidden(CJS_Runtime* pRuntime, return false; uint32_t dwFlags = pWidget->GetFlags(); - if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) - vp << true; - else - vp << false; + vp->Set(ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags); + return true; +} +bool Field::set_hidden(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Bool(FP_HIDDEN, vp.ToBool()); + } else { + Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToBool()); + } return true; } @@ -1530,25 +1582,11 @@ void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv, SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display); } -bool Field::highlight(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_highlight(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - ByteString strMode; - vp >> strMode; - if (m_bDelay) { - AddDelay_String(FP_HIGHLIGHT, strMode); - } else { - Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, strMode); - } - return true; - } std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1564,24 +1602,40 @@ bool Field::highlight(CJS_Runtime* pRuntime, int eHM = pFormControl->GetHighlightingMode(); switch (eHM) { case CPDF_FormControl::None: - vp << L"none"; + vp->Set(L"none"); break; case CPDF_FormControl::Push: - vp << L"push"; + vp->Set(L"push"); break; case CPDF_FormControl::Invert: - vp << L"invert"; + vp->Set(L"invert"); break; case CPDF_FormControl::Outline: - vp << L"outline"; + vp->Set(L"outline"); break; case CPDF_FormControl::Toggle: - vp << L"toggle"; + vp->Set(L"toggle"); break; } return true; } +bool Field::set_highlight(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_String(FP_HIGHLIGHT, vp.ToByteString()); + } else { + Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToByteString()); + } + return true; +} + void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv, const WideString& swFieldName, int nControlIndex, @@ -1589,30 +1643,16 @@ void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::lineWidth(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - int iWidth; - vp >> iWidth; - - if (m_bDelay) { - AddDelay_Int(FP_LINEWIDTH, iWidth); - } else { - Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, iWidth); - } - return true; - } +bool Field::get_line_width(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; CPDF_FormField* pFormField = FieldArray[0]; ASSERT(pFormField); + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return false; @@ -1625,7 +1665,22 @@ bool Field::lineWidth(CJS_Runtime* pRuntime, if (!pWidget) return false; - vp << (int32_t)pWidget->GetBorderWidth(); + vp->Set(pWidget->GetBorderWidth()); + return true; +} + +bool Field::set_line_width(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Int(FP_LINEWIDTH, vp.ToInt()); + } else { + Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToInt()); + } return true; } @@ -1668,26 +1723,11 @@ void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::multiline(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_multiline(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - - if (m_bDelay) { - AddDelay_Bool(FP_MULTILINE, bVP); - } else { - Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, bVP); - } - return true; - } std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1696,39 +1736,38 @@ bool Field::multiline(CJS_Runtime* pRuntime, if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return false; - if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE) - vp << true; - else - vp << false; - + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)); return true; } -void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& swFieldName, - int nControlIndex, - bool b) { - // Not supported. -} - -bool Field::multipleSelection(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_multiline(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { + if (!m_bCanSet) return false; - bool bVP; - vp >> bVP; if (m_bDelay) { - AddDelay_Bool(FP_MULTIPLESELECTION, bVP); + AddDelay_Bool(FP_MULTILINE, vp.ToBool()); } else { - Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, bVP); + Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToBool()); } return true; - } +} + +void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. +} + +bool Field::get_multiple_selection(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1737,7 +1776,24 @@ bool Field::multipleSelection(CJS_Runtime* pRuntime, if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) return false; - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT); + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)); + return true; +} + +bool Field::set_multiple_selection(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Bool(FP_MULTIPLESELECTION, vp.ToBool()); + } else { + Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, vp.ToBool()); + } return true; } @@ -1748,24 +1804,26 @@ void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool Field::get_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; - vp << m_FieldName; + vp->Set(m_FieldName); return true; } -bool Field::numItems(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool Field::set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool Field::get_num_items(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1776,16 +1834,19 @@ bool Field::numItems(CJS_Runtime* pRuntime, return false; } - vp << (int32_t)pFormField->CountOptions(); + vp->Set(pFormField->CountOptions()); return true; } -bool Field::page(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) { - sError = JSGetStringFromID(IDS_STRING_JSREADONLY); - return false; - } +bool Field::set_num_items(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool Field::get_page(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -1797,7 +1858,7 @@ bool Field::page(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { std::vector<CPDFSDK_Annot::ObservedPtr> widgets; m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets); if (widgets.empty()) { - vp << (int32_t)-1; + vp->Set(-1); return true; } @@ -1805,7 +1866,7 @@ bool Field::page(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { int i = 0; for (const auto& pObserved : widgets) { if (!pObserved) { - sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); + *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } @@ -1819,64 +1880,87 @@ bool Field::page(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { ++i; } - vp << PageArray; + vp->Set(PageArray); return true; } -bool Field::password(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_page(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + *sError = JSGetStringFromID(IDS_STRING_JSREADONLY); + return false; +} + +bool Field::get_password(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; + + CPDF_FormField* pFormField = FieldArray[0]; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return false; + + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)); + return true; +} + +bool Field::set_password(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { if (!m_bCanSet) return false; - bool bVP; - vp >> bVP; if (m_bDelay) { - AddDelay_Bool(FP_PASSWORD, bVP); + AddDelay_Bool(FP_PASSWORD, vp.ToBool()); } else { Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - bVP); + vp.ToBool()); } return true; } - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; + void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. + } - CPDF_FormField* pFormField = FieldArray[0]; - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return false; + bool Field::get_print(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD); - return true; -} + CPDF_FormField* pFormField = FieldArray[0]; + CPDFSDK_Widget* pWidget = + pInterForm->GetWidget(GetSmartFieldControl(pFormField)); + if (!pWidget) + return false; -void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& swFieldName, - int nControlIndex, - bool b) { - // Not supported. + vp->Set(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)); + return true; } -bool Field::print(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_print(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; - if (vp.IsSetting()) { if (!m_bCanSet) return false; - bool bVP; - vp >> bVP; - for (CPDF_FormField* pFormField : FieldArray) { if (m_nFormControlIndex < 0) { bool bSet = false; @@ -1884,7 +1968,7 @@ bool Field::print(CJS_Runtime* pRuntime, if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(i))) { uint32_t dwFlags = pWidget->GetFlags(); - if (bVP) + if (vp.ToBool()) dwFlags |= ANNOTFLAG_PRINT; else dwFlags &= ~ANNOTFLAG_PRINT; @@ -1898,117 +1982,81 @@ bool Field::print(CJS_Runtime* pRuntime, if (bSet) UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true); - } else { - if (m_nFormControlIndex >= pFormField->CountControls()) - return false; - if (CPDF_FormControl* pFormControl = - pFormField->GetControl(m_nFormControlIndex)) { - if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { - uint32_t dwFlags = pWidget->GetFlags(); - if (bVP) - dwFlags |= ANNOTFLAG_PRINT; - else - dwFlags &= ~ANNOTFLAG_PRINT; - if (dwFlags != pWidget->GetFlags()) { - pWidget->SetFlags(dwFlags); - UpdateFormControl(m_pFormFillEnv.Get(), - pFormField->GetControl(m_nFormControlIndex), - true, false, true); - } + continue; + } + + if (m_nFormControlIndex >= pFormField->CountControls()) + return false; + if (CPDF_FormControl* pFormControl = + pFormField->GetControl(m_nFormControlIndex)) { + if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { + uint32_t dwFlags = pWidget->GetFlags(); + if (vp.ToBool()) + dwFlags |= ANNOTFLAG_PRINT; + else + dwFlags &= ~ANNOTFLAG_PRINT; + + if (dwFlags != pWidget->GetFlags()) { + pWidget->SetFlags(dwFlags); + UpdateFormControl(m_pFormFillEnv.Get(), + pFormField->GetControl(m_nFormControlIndex), true, + false, true); } } } } return true; - } - - CPDF_FormField* pFormField = FieldArray[0]; - CPDFSDK_Widget* pWidget = - pInterForm->GetWidget(GetSmartFieldControl(pFormField)); - if (!pWidget) - return false; - - vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT); - return true; } -bool Field::radiosInUnison(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_radios_in_unison(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - return true; - } CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) return false; - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON); + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)); return true; } -bool Field::readonly(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_radios_in_unison(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; + return m_bCanSet; +} - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; +bool Field::get_readonly(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - bool bVP; - vp >> bVP; - return true; - } - vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY); + vp->Set(!!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY)); return true; } -bool Field::rect(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - CJS_Value Upper_Leftx(pRuntime); - CJS_Value Upper_Lefty(pRuntime); - CJS_Value Lower_Rightx(pRuntime); - CJS_Value Lower_Righty(pRuntime); - - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - if (!vp.GetJSValue()->IsArrayObject()) - return false; - - CJS_Array rcArray; - vp >> rcArray; - rcArray.GetElement(pRuntime, 0, Upper_Leftx); - rcArray.GetElement(pRuntime, 1, Upper_Lefty); - rcArray.GetElement(pRuntime, 2, Lower_Rightx); - rcArray.GetElement(pRuntime, 3, Lower_Righty); +bool Field::set_readonly(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - float pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime)); - pArray[1] = static_cast<float>(Lower_Righty.ToInt(pRuntime)); - pArray[2] = static_cast<float>(Lower_Rightx.ToInt(pRuntime)); - pArray[3] = static_cast<float>(Upper_Lefty.ToInt(pRuntime)); + return m_bCanSet; +} - CFX_FloatRect crRect(pArray); - if (m_bDelay) { - AddDelay_Rect(FP_RECT, crRect); - } else { - Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - crRect); - } - return true; - } +bool Field::get_rect(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2021,17 +2069,51 @@ bool Field::rect(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { return false; CFX_FloatRect crRect = pWidget->GetRect(); - Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)); - Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)); - Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)); - Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)); - CJS_Array rcArray; - rcArray.SetElement(pRuntime, 0, Upper_Leftx); - rcArray.SetElement(pRuntime, 1, Upper_Lefty); - rcArray.SetElement(pRuntime, 2, Lower_Rightx); - rcArray.SetElement(pRuntime, 3, Lower_Righty); - vp << rcArray; + rcArray.SetElement(pRuntime, 0, + CJS_Value(pRuntime, static_cast<int32_t>(crRect.left))); + rcArray.SetElement(pRuntime, 1, + CJS_Value(pRuntime, static_cast<int32_t>(crRect.top))); + rcArray.SetElement(pRuntime, 2, + CJS_Value(pRuntime, static_cast<int32_t>(crRect.right))); + rcArray.SetElement(pRuntime, 3, + CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom))); + vp->Set(rcArray); + return true; +} + +bool Field::set_rect(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + if (!vp.GetJSValue()->IsArrayObject()) + return false; + + CJS_Value Upper_Leftx(pRuntime); + CJS_Value Upper_Lefty(pRuntime); + CJS_Value Lower_Rightx(pRuntime); + CJS_Value Lower_Righty(pRuntime); + + CJS_Array rcArray = vp.ToArray(); + rcArray.GetElement(pRuntime, 0, Upper_Leftx); + rcArray.GetElement(pRuntime, 1, Upper_Lefty); + rcArray.GetElement(pRuntime, 2, Lower_Rightx); + rcArray.GetElement(pRuntime, 3, Lower_Righty); + + float pArray[4]; + pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime)); + pArray[1] = static_cast<float>(Lower_Righty.ToInt(pRuntime)); + pArray[2] = static_cast<float>(Lower_Rightx.ToInt(pRuntime)); + pArray[3] = static_cast<float>(Upper_Lefty.ToInt(pRuntime)); + + CFX_FloatRect crRect(pArray); + if (m_bDelay) { + AddDelay_Rect(FP_RECT, crRect); + } else { + Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + crRect); + } return true; } @@ -2068,24 +2150,26 @@ void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, if (bSet) UpdateFormField(pFormFillEnv, pFormField, true, true, true); - } else { - if (nControlIndex >= pFormField->CountControls()) - return; - if (CPDF_FormControl* pFormControl = - pFormField->GetControl(nControlIndex)) { - if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { - CFX_FloatRect crRect = rect; - CPDF_Page* pPDFPage = pWidget->GetPDFPage(); - crRect.Intersect(pPDFPage->GetPageBBox()); + continue; + } - if (!crRect.IsEmpty()) { - CFX_FloatRect rcOld = pWidget->GetRect(); - if (crRect.left != rcOld.left || crRect.right != rcOld.right || - crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { - pWidget->SetRect(crRect); - UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); - } + if (nControlIndex >= pFormField->CountControls()) + return; + if (CPDF_FormControl* pFormControl = + pFormField->GetControl(nControlIndex)) { + if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { + CFX_FloatRect crRect = rect; + + CPDF_Page* pPDFPage = pWidget->GetPDFPage(); + crRect.Intersect(pPDFPage->GetPageBBox()); + + if (!crRect.IsEmpty()) { + CFX_FloatRect rcOld = pWidget->GetRect(); + if (crRect.left != rcOld.left || crRect.right != rcOld.right || + crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { + pWidget->SetRect(crRect); + UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); } } } @@ -2093,45 +2177,35 @@ void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::required(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_required(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - bool bVP; - vp >> bVP; - return true; - } CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) return false; - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED); + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)); return true; } -bool Field::richText(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - ASSERT(m_pFormFillEnv); - - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; +bool Field::set_required(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; - bool bVP; - vp >> bVP; - if (m_bDelay) - AddDelay_Bool(FP_RICHTEXT, bVP); + return m_bCanSet; +} - return true; - } +bool Field::get_rich_text(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2141,35 +2215,41 @@ bool Field::richText(CJS_Runtime* pRuntime, if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return false; - vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT); + vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)); return true; } -bool Field::richValue(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_rich_text(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) + AddDelay_Bool(FP_RICHTEXT, vp.ToBool()); + return true; } -bool Field::rotation(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - ASSERT(m_pFormFillEnv); +bool Field::get_rich_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; +bool Field::set_rich_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} + +bool Field::get_rotation(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); - int nVP; - vp >> nVP; - if (m_bDelay) { - AddDelay_Int(FP_ROTATION, nVP); - } else { - Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - nVP); - } - return true; - } std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2179,7 +2259,23 @@ bool Field::rotation(CJS_Runtime* pRuntime, if (!pFormControl) return false; - vp << (int32_t)pFormControl->GetRotation(); + vp->Set(pFormControl->GetRotation()); + return true; +} + +bool Field::set_rotation(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + ASSERT(m_pFormFillEnv); + if (m_bDelay) { + AddDelay_Int(FP_ROTATION, vp.ToInt()); + } else { + Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToInt()); + } return true; } @@ -2190,30 +2286,9 @@ void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::strokeColor(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - CJS_Array crArray; - - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - if (!vp.GetJSValue()->IsArrayObject()) - return false; - - vp >> crArray; - - CFX_Color color; - color::ConvertArrayToPWLColor(pRuntime, crArray, &color); - if (m_bDelay) { - AddDelay_Color(FP_STROKECOLOR, color); - } else { - Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, color); - } - return true; - } +bool Field::get_stroke_color(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2245,8 +2320,30 @@ bool Field::strokeColor(CJS_Runtime* pRuntime, return false; } + CJS_Array crArray; color::ConvertPWLColorToArray(pRuntime, color, &crArray); - vp << crArray; + vp->Set(crArray); + return true; +} + +bool Field::set_stroke_color(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + if (!vp.GetJSValue()->IsArrayObject()) + return false; + + CJS_Array crArray = vp.ToArray(); + CFX_Color color; + color::ConvertArrayToPWLColor(pRuntime, crArray, &color); + if (m_bDelay) { + AddDelay_Color(FP_STROKECOLOR, color); + } else { + Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName, + m_nFormControlIndex, color); + } return true; } @@ -2257,26 +2354,11 @@ void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::style(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_style(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - ByteString csBCaption; - vp >> csBCaption; - - if (m_bDelay) { - AddDelay_String(FP_STYLE, csBCaption); - } else { - Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - csBCaption); - } - return true; - } std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2314,7 +2396,24 @@ bool Field::style(CJS_Runtime* pRuntime, csBCaption = "check"; break; } - vp << csBCaption; + vp->Set(csBCaption); + return true; +} + +bool Field::set_style(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_String(FP_STYLE, vp.ToByteString()); + } else { + Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToByteString()); + } return true; } @@ -2325,36 +2424,21 @@ void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::submitName(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_submit_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return true; } -bool Field::textColor(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - CJS_Array crArray; - - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - if (!vp.GetJSValue()->IsArrayObject()) - return false; - - vp >> crArray; +bool Field::set_submit_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} - CFX_Color color; - color::ConvertArrayToPWLColor(pRuntime, crArray, &color); - if (m_bDelay) { - AddDelay_Color(FP_TEXTCOLOR, color); - } else { - Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, color); - } - return true; - } +bool Field::get_text_color(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2381,8 +2465,31 @@ bool Field::textColor(CJS_Runtime* pRuntime, if (iColorType == CFX_Color::kTransparent) crRet = CFX_Color(CFX_Color::kTransparent); + CJS_Array crArray; color::ConvertPWLColorToArray(pRuntime, crRet, &crArray); - vp << crArray; + vp->Set(crArray); + return true; +} + +bool Field::set_text_color(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + if (!vp.GetJSValue()->IsArrayObject()) + return false; + + CJS_Array crArray = vp.ToArray(); + CFX_Color color; + color::ConvertArrayToPWLColor(pRuntime, crArray, &color); + + if (m_bDelay) { + AddDelay_Color(FP_TEXTCOLOR, color); + } else { + Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + color); + } return true; } @@ -2393,28 +2500,11 @@ void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::textFont(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::get_text_font(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - ByteString csFontName; - vp >> csFontName; - if (csFontName.IsEmpty()) - return false; - - if (m_bDelay) { - AddDelay_String(FP_TEXTFONT, csFontName); - } else { - Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - csFontName); - } - return true; - } std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2434,36 +2524,43 @@ bool Field::textFont(CJS_Runtime* pRuntime, if (!pFont) return false; - vp << pFont->GetBaseFont(); + vp->Set(pFont->GetBaseFont()); return true; } -void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& swFieldName, - int nControlIndex, - const ByteString& string) { - // Not supported. -} - -bool Field::textSize(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_text_font(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { if (!m_bCanSet) return false; - int nVP; - vp >> nVP; + ByteString fontName = vp.ToByteString(); + if (fontName.IsEmpty()) + return false; + if (m_bDelay) { - AddDelay_Int(FP_TEXTSIZE, nVP); + AddDelay_String(FP_TEXTFONT, fontName); } else { - Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - nVP); + Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + fontName); } return true; - } +} + +void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& swFieldName, + int nControlIndex, + const ByteString& string) { + // Not supported. +} + +bool Field::get_text_size(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2477,7 +2574,24 @@ bool Field::textSize(CJS_Runtime* pRuntime, float fFontSize; CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); FieldAppearance.GetFont(&fFontSize); - vp << static_cast<int>(fFontSize); + vp->Set(static_cast<int>(fFontSize)); + return true; +} + +bool Field::set_text_size(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + if (!m_bCanSet) + return false; + + if (m_bDelay) { + AddDelay_Int(FP_TEXTSIZE, vp.ToInt()); + } else { + Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + vp.ToInt()); + } return true; } @@ -2488,10 +2602,9 @@ void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool Field::get_type(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2499,62 +2612,70 @@ bool Field::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { CPDF_FormField* pFormField = FieldArray[0]; switch (pFormField->GetFieldType()) { case FIELDTYPE_UNKNOWN: - vp << L"unknown"; + vp->Set(L"unknown"); break; case FIELDTYPE_PUSHBUTTON: - vp << L"button"; + vp->Set(L"button"); break; case FIELDTYPE_CHECKBOX: - vp << L"checkbox"; + vp->Set(L"checkbox"); break; case FIELDTYPE_RADIOBUTTON: - vp << L"radiobutton"; + vp->Set(L"radiobutton"); break; case FIELDTYPE_COMBOBOX: - vp << L"combobox"; + vp->Set(L"combobox"); break; case FIELDTYPE_LISTBOX: - vp << L"listbox"; + vp->Set(L"listbox"); break; case FIELDTYPE_TEXTFIELD: - vp << L"text"; + vp->Set(L"text"); break; case FIELDTYPE_SIGNATURE: - vp << L"signature"; + vp->Set(L"signature"); break; default: - vp << L"unknown"; + vp->Set(L"unknown"); break; } return true; } -bool Field::userName(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool Field::set_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool Field::get_user_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + ASSERT(m_pFormFillEnv); + + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) + return false; + + vp->Set(FieldArray[0]->GetAlternateName()); + return true; +} + +bool Field::set_user_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { ASSERT(m_pFormFillEnv); - if (vp.IsSetting()) { if (!m_bCanSet) return false; - WideString swName; - vp >> swName; - if (m_bDelay) { - AddDelay_WideString(FP_USERNAME, swName); + AddDelay_WideString(FP_USERNAME, vp.ToWideString()); } else { Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - swName); + vp.ToWideString()); } return true; - } - std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); - if (FieldArray.empty()) - return false; - - vp << FieldArray[0]->GetAlternateName(); - return true; } void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv, @@ -2564,37 +2685,9 @@ void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::value(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - if (!m_bCanSet) - return false; - - std::vector<WideString> strArray; - if (vp.GetJSValue()->IsArrayObject()) { - CJS_Array ValueArray; - vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray); - for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) { - CJS_Value ElementValue(pRuntime); - ValueArray.GetElement(pRuntime, i, ElementValue); - strArray.push_back(ElementValue.ToCFXWideString(pRuntime)); - } - } else { - WideString swValue; - vp >> swValue; - strArray.push_back(swValue); - } - - if (m_bDelay) { - AddDelay_WideStringArray(FP_VALUE, strArray); - } else { - Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - strArray); - } - return true; - } - +bool Field::get_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2604,9 +2697,9 @@ bool Field::value(CJS_Runtime* pRuntime, case FIELDTYPE_PUSHBUTTON: return false; case FIELDTYPE_COMBOBOX: - case FIELDTYPE_TEXTFIELD: { - vp << pFormField->GetValue(); - } break; + case FIELDTYPE_TEXTFIELD: + vp->Set(pFormField->GetValue()); + break; case FIELDTYPE_LISTBOX: { if (pFormField->CountSelectedItems() > 1) { CJS_Array ValueArray; @@ -2622,29 +2715,59 @@ bool Field::value(CJS_Runtime* pRuntime, } ValueArray.SetElement(pRuntime, i, ElementValue); } - vp << ValueArray; + vp->Set(ValueArray); } else { - vp << pFormField->GetValue(); + vp->Set(pFormField->GetValue()); } - } break; + break; + } case FIELDTYPE_CHECKBOX: case FIELDTYPE_RADIOBUTTON: { bool bFind = false; for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { if (pFormField->GetControl(i)->IsChecked()) { - vp << pFormField->GetControl(i)->GetExportValue(); + vp->Set(pFormField->GetControl(i)->GetExportValue()); bFind = true; break; } } if (!bFind) - vp << L"Off"; - } break; + vp->Set(L"Off"); + + break; + } default: - vp << pFormField->GetValue(); + vp->Set(pFormField->GetValue()); break; } - vp.GetJSValue()->MaybeCoerceToNumber(pRuntime); + vp->GetJSValue()->MaybeCoerceToNumber(pRuntime); + return true; +} + +bool Field::set_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + if (!m_bCanSet) + return false; + + std::vector<WideString> strArray; + if (vp.GetJSValue()->IsArrayObject()) { + CJS_Array ValueArray = vp.ToArray(); + for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) { + CJS_Value ElementValue(pRuntime); + ValueArray.GetElement(pRuntime, i, ElementValue); + strArray.push_back(ElementValue.ToCFXWideString(pRuntime)); + } + } else { + strArray.push_back(vp.ToWideString()); + } + + if (m_bDelay) { + AddDelay_WideStringArray(FP_VALUE, strArray); + } else { + Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, + strArray); + } return true; } @@ -2702,12 +2825,9 @@ void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::valueAsString(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool Field::get_value_as_string(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2720,30 +2840,39 @@ bool Field::valueAsString(CJS_Runtime* pRuntime, if (!pFormField->CountControls()) return false; - if (pFormField->GetControl(0)->IsChecked()) - vp << L"Yes"; - else - vp << L"Off"; - } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && - !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) { + vp->Set(pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"); + return true; + } + + if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && + !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) { for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { if (pFormField->GetControl(i)->IsChecked()) { - vp << pFormField->GetControl(i)->GetExportValue().c_str(); + vp->Set(pFormField->GetControl(i)->GetExportValue().c_str()); break; } else { - vp << L"Off"; + vp->Set(L"Off"); } } - } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && - (pFormField->CountSelectedItems() > 1)) { - vp << L""; + return true; + } + + if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && + (pFormField->CountSelectedItems() > 1)) { + vp->Set(L""); } else { - vp << pFormField->GetValue().c_str(); + vp->Set(pFormField->GetValue().c_str()); } return true; } +bool Field::set_value_as_string(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, CJS_Value& vRet, @@ -3174,13 +3303,16 @@ bool Field::signatureValidate(CJS_Runtime* pRuntime, return false; } -bool Field::source(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsGetting()) { - vp << (CJS_Object*)nullptr; - } +bool Field::get_source(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(static_cast<CJS_Object*>(nullptr)); + return true; +} +bool Field::set_source(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h index 69e27d0639..bd90ff74df 100644 --- a/fpdfsdk/javascript/Field.h +++ b/fpdfsdk/javascript/Field.h @@ -77,96 +77,345 @@ class Field : public CJS_EmbedObj { explicit Field(CJS_Object* pJSObject); ~Field() override; - bool alignment(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool borderStyle(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool buttonAlignX(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool buttonAlignY(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool buttonFitBounds(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool buttonPosition(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool buttonScaleHow(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool buttonScaleWhen(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool calcOrderIndex(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool charLimit(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool comb(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool commitOnSelChange(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool currentValueIndices(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool defaultStyle(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool defaultValue(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool doNotScroll(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool doNotSpellCheck(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool delay(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool display(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool doc(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool editable(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool exportValues(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool fileSelect(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool fillColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool hidden(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool highlight(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool lineWidth(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool multiline(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool multipleSelection(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool numItems(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool page(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool password(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool print(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool radiosInUnison(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool readonly(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool rect(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool required(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool richText(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool rotation(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool strokeColor(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool style(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool submitName(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool textColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool textFont(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool textSize(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool userName(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool value(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool valueAsString(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool source(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); + bool get_alignment(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_alignment(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_border_style(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_border_style(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_button_align_x(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_button_align_x(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_button_align_y(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_button_align_y(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_button_fit_bounds(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_button_fit_bounds(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_button_position(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_button_position(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_button_scale_how(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_button_scale_how(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_button_scale_when(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_button_scale_when(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_calc_order_index(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_calc_order_index(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_char_limit(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_char_limit(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_comb(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_comb(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_commit_on_sel_change(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_commit_on_sel_change(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_current_value_indices(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_current_value_indices(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_default_style(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_default_style(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_default_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_default_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_do_not_scroll(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_do_not_scroll(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_do_not_spell_check(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_do_not_spell_check(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_delay(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_delay(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_display(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_display(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_doc(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_doc(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_editable(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_editable(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_export_values(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_export_values(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_file_select(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_file_select(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_fill_color(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_fill_color(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_hidden(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_hidden(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_highlight(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_highlight(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_line_width(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_line_width(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_multiline(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_multiline(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_multiple_selection(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_multiple_selection(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_name(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_num_items(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_num_items(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_page(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_page(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_password(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_password(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_print(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_print(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_radios_in_unison(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_radios_in_unison(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_readonly(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_readonly(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rect(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_rect(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_required(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_required(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rich_text(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_rich_text(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rich_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_rich_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rotation(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_rotation(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_stroke_color(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_stroke_color(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_style(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_style(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_submit_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_submit_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_text_color(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_text_color(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_text_font(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_text_font(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_text_size(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_text_size(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_type(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_user_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_user_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_value(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_value_as_string(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_value_as_string(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_source(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_source(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); bool browseForFileToSubmit(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, @@ -472,58 +721,58 @@ class CJS_Field : public CJS_Object { void InitInstance(IJS_Runtime* pIRuntime) override; DECLARE_JS_CLASS(); - JS_STATIC_PROP(alignment, Field); - JS_STATIC_PROP(borderStyle, Field); - JS_STATIC_PROP(buttonAlignX, Field); - JS_STATIC_PROP(buttonAlignY, Field); - JS_STATIC_PROP(buttonFitBounds, Field); - JS_STATIC_PROP(buttonPosition, Field); - JS_STATIC_PROP(buttonScaleHow, Field); - JS_STATIC_PROP(buttonScaleWhen, Field); - JS_STATIC_PROP(calcOrderIndex, Field); - JS_STATIC_PROP(charLimit, Field); - JS_STATIC_PROP(comb, Field); - JS_STATIC_PROP(commitOnSelChange, Field); - JS_STATIC_PROP(currentValueIndices, Field); - JS_STATIC_PROP(defaultStyle, Field); - JS_STATIC_PROP(defaultValue, Field); - JS_STATIC_PROP(doNotScroll, Field); - JS_STATIC_PROP(doNotSpellCheck, Field); - JS_STATIC_PROP(delay, Field); - JS_STATIC_PROP(display, Field); - JS_STATIC_PROP(doc, Field); - JS_STATIC_PROP(editable, Field); - JS_STATIC_PROP(exportValues, Field); - JS_STATIC_PROP(fileSelect, Field); - JS_STATIC_PROP(fillColor, Field); - JS_STATIC_PROP(hidden, Field); - JS_STATIC_PROP(highlight, Field); - JS_STATIC_PROP(lineWidth, Field); - JS_STATIC_PROP(multiline, Field); - JS_STATIC_PROP(multipleSelection, Field); - JS_STATIC_PROP(name, Field); - JS_STATIC_PROP(numItems, Field); - JS_STATIC_PROP(page, Field); - JS_STATIC_PROP(password, Field); - JS_STATIC_PROP(print, Field); - JS_STATIC_PROP(radiosInUnison, Field); - JS_STATIC_PROP(readonly, Field); - JS_STATIC_PROP(rect, Field); - JS_STATIC_PROP(required, Field); - JS_STATIC_PROP(richText, Field); - JS_STATIC_PROP(richValue, Field); - JS_STATIC_PROP(rotation, Field); - JS_STATIC_PROP(strokeColor, Field); - JS_STATIC_PROP(style, Field); - JS_STATIC_PROP(submitName, Field); - JS_STATIC_PROP(textColor, Field); - JS_STATIC_PROP(textFont, Field); - JS_STATIC_PROP(textSize, Field); - JS_STATIC_PROP(type, Field); - JS_STATIC_PROP(userName, Field); - JS_STATIC_PROP(value, Field); - JS_STATIC_PROP(valueAsString, Field); - JS_STATIC_PROP(source, Field); + JS_STATIC_PROP(alignment, alignment, Field); + JS_STATIC_PROP(borderStyle, border_style, Field); + JS_STATIC_PROP(buttonAlignX, button_align_x, Field); + JS_STATIC_PROP(buttonAlignY, button_align_y, Field); + JS_STATIC_PROP(buttonFitBounds, button_fit_bounds, Field); + JS_STATIC_PROP(buttonPosition, button_position, Field); + JS_STATIC_PROP(buttonScaleHow, button_scale_how, Field); + JS_STATIC_PROP(ButtonScaleWhen, button_scale_when, Field); + JS_STATIC_PROP(calcOrderIndex, calc_order_index, Field); + JS_STATIC_PROP(charLimit, char_limit, Field); + JS_STATIC_PROP(comb, comb, Field); + JS_STATIC_PROP(commitOnSelChange, commit_on_sel_change, Field); + JS_STATIC_PROP(currentValueIndices, current_value_indices, Field); + JS_STATIC_PROP(defaultStyle, default_style, Field); + JS_STATIC_PROP(defaultValue, default_value, Field); + JS_STATIC_PROP(doNotScroll, do_not_scroll, Field); + JS_STATIC_PROP(doNotSpellCheck, do_not_spell_check, Field); + JS_STATIC_PROP(delay, delay, Field); + JS_STATIC_PROP(display, display, Field); + JS_STATIC_PROP(doc, doc, Field); + JS_STATIC_PROP(editable, editable, Field); + JS_STATIC_PROP(exportValues, export_values, Field); + JS_STATIC_PROP(fileSelect, file_select, Field); + JS_STATIC_PROP(fillColor, fill_color, Field); + JS_STATIC_PROP(hidden, hidden, Field); + JS_STATIC_PROP(highlight, highlight, Field); + JS_STATIC_PROP(lineWidth, line_width, Field); + JS_STATIC_PROP(multiline, multiline, Field); + JS_STATIC_PROP(multipleSelection, multiple_selection, Field); + JS_STATIC_PROP(name, name, Field); + JS_STATIC_PROP(numItems, num_items, Field); + JS_STATIC_PROP(page, page, Field); + JS_STATIC_PROP(password, password, Field); + JS_STATIC_PROP(print, print, Field); + JS_STATIC_PROP(radiosInUnison, radios_in_unison, Field); + JS_STATIC_PROP(readonly, readonly, Field); + JS_STATIC_PROP(rect, rect, Field); + JS_STATIC_PROP(required, required, Field); + JS_STATIC_PROP(richText, rich_text, Field); + JS_STATIC_PROP(richValue, rich_value, Field); + JS_STATIC_PROP(rotation, rotation, Field); + JS_STATIC_PROP(strokeColor, stroke_color, Field); + JS_STATIC_PROP(style, style, Field); + JS_STATIC_PROP(submitName, submit_name, Field); + JS_STATIC_PROP(textColor, text_color, Field); + JS_STATIC_PROP(textFont, text_font, Field); + JS_STATIC_PROP(textSize, text_size, Field); + JS_STATIC_PROP(type, type, Field); + JS_STATIC_PROP(userName, user_name, Field); + JS_STATIC_PROP(value, value, Field); + JS_STATIC_PROP(valueAsString, value_as_string, Field); + JS_STATIC_PROP(source, source, Field); JS_STATIC_METHOD(browseForFileToSubmit, Field); JS_STATIC_METHOD(buttonGetCaption, Field); diff --git a/fpdfsdk/javascript/Icon.cpp b/fpdfsdk/javascript/Icon.cpp index 47781dd83a..6083307931 100644 --- a/fpdfsdk/javascript/Icon.cpp +++ b/fpdfsdk/javascript/Icon.cpp @@ -25,10 +25,15 @@ Icon::Icon(CJS_Object* pJSObject) Icon::~Icon() {} -bool Icon::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) - return false; - - vp << m_swIconName; +bool Icon::get_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(m_swIconName); return true; } + +bool Icon::set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} diff --git a/fpdfsdk/javascript/Icon.h b/fpdfsdk/javascript/Icon.h index e856ee9e51..df2e4bdcc3 100644 --- a/fpdfsdk/javascript/Icon.h +++ b/fpdfsdk/javascript/Icon.h @@ -16,7 +16,11 @@ class Icon : public CJS_EmbedObj { explicit Icon(CJS_Object* pJSObject); ~Icon() override; - bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); + bool get_name(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + WideString GetIconName() const { return m_swIconName; } void SetIconName(WideString name) { m_swIconName = name; } @@ -30,7 +34,7 @@ class CJS_Icon : public CJS_Object { ~CJS_Icon() override {} DECLARE_JS_CLASS(); - JS_STATIC_PROP(name, Icon); + JS_STATIC_PROP(name, name, Icon); }; #endif // FPDFSDK_JAVASCRIPT_ICON_H_ diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h index 470a8fe40c..24ce23d64d 100644 --- a/fpdfsdk/javascript/JS_Define.h +++ b/fpdfsdk/javascript/JS_Define.h @@ -34,7 +34,7 @@ struct JSMethodSpec { v8::FunctionCallback pMethodCall; }; -template <class C, bool (C::*M)(CJS_Runtime*, CJS_PropValue&, WideString&)> +template <class C, bool (C::*M)(CJS_Runtime*, CJS_PropValue*, WideString*)> void JSPropGetter(const char* prop_name_string, const char* class_name_string, v8::Local<v8::String> property, @@ -43,15 +43,18 @@ void JSPropGetter(const char* prop_name_string, CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; + CJS_Object* pJSObj = static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(info.Holder())); if (!pJSObj) return; + C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); WideString sError; + CJS_PropValue value(pRuntime); value.StartGetting(); - if (!(pObj->*M)(pRuntime, value, sError)) { + if (!(pObj->*M)(pRuntime, &value, &sError)) { pRuntime->Error( JSFormatErrorString(class_name_string, prop_name_string, sError)); return; @@ -59,7 +62,8 @@ void JSPropGetter(const char* prop_name_string, info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(pRuntime)); } -template <class C, bool (C::*M)(CJS_Runtime*, CJS_PropValue&, WideString&)> +template <class C, + bool (C::*M)(CJS_Runtime*, const CJS_PropValue&, WideString*)> void JSPropSetter(const char* prop_name_string, const char* class_name_string, v8::Local<v8::String> property, @@ -69,32 +73,35 @@ void JSPropSetter(const char* prop_name_string, CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; + CJS_Object* pJSObj = static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(info.Holder())); if (!pJSObj) return; + C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); WideString sError; + CJS_PropValue propValue(pRuntime, CJS_Value(pRuntime, value)); propValue.StartSetting(); - if (!(pObj->*M)(pRuntime, propValue, sError)) { + if (!(pObj->*M)(pRuntime, propValue, &sError)) { pRuntime->Error( JSFormatErrorString(class_name_string, prop_name_string, sError)); } } -#define JS_STATIC_PROP(prop_name, class_name) \ - static void get_##prop_name##_static( \ - v8::Local<v8::String> property, \ - const v8::PropertyCallbackInfo<v8::Value>& info) { \ - JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ - property, info); \ - } \ - static void set_##prop_name##_static( \ - v8::Local<v8::String> property, v8::Local<v8::Value> value, \ - const v8::PropertyCallbackInfo<void>& info) { \ - JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ - property, value, info); \ +#define JS_STATIC_PROP(err_name, prop_name, class_name) \ + static void get_##prop_name##_static( \ + v8::Local<v8::String> property, \ + const v8::PropertyCallbackInfo<v8::Value>& info) { \ + JSPropGetter<class_name, &class_name::get_##prop_name>( \ + #err_name, #class_name, property, info); \ + } \ + static void set_##prop_name##_static( \ + v8::Local<v8::String> property, v8::Local<v8::Value> value, \ + const v8::PropertyCallbackInfo<void>& info) { \ + JSPropSetter<class_name, &class_name::set_##prop_name>( \ + #err_name, #class_name, property, value, info); \ } template <class C, @@ -349,11 +356,11 @@ void JSSpecialPropGet(const char* class_name, v8::String::Utf8Value utf8_value(property); WideString propname = WideString::FromUTF8(ByteStringView(*utf8_value, utf8_value.length())); - WideString sError; + CJS_PropValue value(pRuntime); value.StartGetting(); - if (!pObj->DoProperty(pRuntime, propname.c_str(), value, sError)) { - pRuntime->Error(JSFormatErrorString(class_name, "GetProperty", sError)); + if (!pObj->GetProperty(pRuntime, propname.c_str(), &value)) { + pRuntime->Error(JSFormatErrorString(class_name, "GetProperty", L"")); return; } info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(pRuntime)); @@ -378,11 +385,10 @@ void JSSpecialPropPut(const char* class_name, v8::String::Utf8Value utf8_value(property); WideString propname = WideString::FromUTF8(ByteStringView(*utf8_value, utf8_value.length())); - WideString sError; CJS_PropValue PropValue(pRuntime, CJS_Value(pRuntime, value)); PropValue.StartSetting(); - if (!pObj->DoProperty(pRuntime, propname.c_str(), PropValue, sError)) { - pRuntime->Error(JSFormatErrorString(class_name, "PutProperty", sError)); + if (!pObj->SetProperty(pRuntime, propname.c_str(), PropValue)) { + pRuntime->Error(JSFormatErrorString(class_name, "PutProperty", L"")); } } @@ -404,8 +410,7 @@ void JSSpecialPropDel(const char* class_name, v8::String::Utf8Value utf8_value(property); WideString propname = WideString::FromUTF8(ByteStringView(*utf8_value, utf8_value.length())); - WideString sError; - if (!pObj->DelProperty(pRuntime, propname.c_str(), sError)) { + if (!pObj->DelProperty(pRuntime, propname.c_str())) { ByteString cbName; cbName.Format("%s.%s", class_name, "DelProperty"); // Probably a missing call to JSFX_Error(). diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index ee81102583..6529a9d604 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -338,107 +338,111 @@ CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime, const CJS_Value& value) CJS_PropValue::~CJS_PropValue() {} -void CJS_PropValue::operator<<(int iValue) { +void CJS_PropValue::Set(int iValue) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), iValue); } -void CJS_PropValue::operator>>(int& iValue) const { +int CJS_PropValue::ToInt() const { ASSERT(m_bIsSetting); - iValue = m_Value.ToInt(m_pJSRuntime.Get()); + return m_Value.ToInt(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(bool bValue) { +void CJS_PropValue::Set(bool bValue) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), bValue); } -void CJS_PropValue::operator>>(bool& bValue) const { +bool CJS_PropValue::ToBool() const { ASSERT(m_bIsSetting); - bValue = m_Value.ToBool(m_pJSRuntime.Get()); + return m_Value.ToBool(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(double dValue) { +void CJS_PropValue::Set(double dValue) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), dValue); } -void CJS_PropValue::operator>>(double& dValue) const { +double CJS_PropValue::ToDouble() const { ASSERT(m_bIsSetting); - dValue = m_Value.ToDouble(m_pJSRuntime.Get()); + return m_Value.ToDouble(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(CJS_Object* pObj) { +void CJS_PropValue::Set(CJS_Object* pObj) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), pObj); } -void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { +CJS_Object* CJS_PropValue::ToObject() const { ASSERT(m_bIsSetting); - ppObj = m_Value.ToCJSObject(m_pJSRuntime.Get()); + return m_Value.ToCJSObject(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { +void CJS_PropValue::Set(CJS_Document* pJsDoc) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), pJsDoc); } -void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { +CJS_Document* CJS_PropValue::ToDocument() const { ASSERT(m_bIsSetting); - ppJsDoc = static_cast<CJS_Document*>(m_Value.ToCJSObject(m_pJSRuntime.Get())); + return static_cast<CJS_Document*>(m_Value.ToCJSObject(m_pJSRuntime.Get())); } -void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) { +void CJS_PropValue::Set(v8::Local<v8::Object> pObj) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), pObj); } -void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const { +v8::Local<v8::Object> CJS_PropValue::ToV8Object() const { ASSERT(m_bIsSetting); - ppObj = m_Value.ToV8Object(m_pJSRuntime.Get()); + return m_Value.ToV8Object(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(ByteString str) { +void CJS_PropValue::Set(const ByteString& str) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), str.c_str()); } -void CJS_PropValue::operator>>(ByteString& str) const { +ByteString CJS_PropValue::ToByteString() const { ASSERT(m_bIsSetting); - str = m_Value.ToCFXByteString(m_pJSRuntime.Get()); + return m_Value.ToCFXByteString(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(const wchar_t* str) { +void CJS_PropValue::Set(const wchar_t* str) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), str); } -void CJS_PropValue::operator>>(WideString& wide_string) const { +WideString CJS_PropValue::ToWideString() const { ASSERT(m_bIsSetting); - wide_string = m_Value.ToCFXWideString(m_pJSRuntime.Get()); + return m_Value.ToCFXWideString(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(WideString wide_string) { +void CJS_PropValue::Set(const WideString& wide_string) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), wide_string.c_str()); } -void CJS_PropValue::operator>>(CJS_Array& array) const { +CJS_Array CJS_PropValue::ToArray() const { ASSERT(m_bIsSetting); - m_Value.ConvertToArray(m_pJSRuntime.Get(), array); + CJS_Array ary; + m_Value.ConvertToArray(m_pJSRuntime.Get(), ary); + return ary; } -void CJS_PropValue::operator<<(CJS_Array& array) { +void CJS_PropValue::Set(const CJS_Array& array) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), array.ToV8Array(m_pJSRuntime.Get())); } -void CJS_PropValue::operator>>(CJS_Date& date) const { +CJS_Date CJS_PropValue::ToDate() const { ASSERT(m_bIsSetting); + CJS_Date date; m_Value.ConvertToDate(m_pJSRuntime.Get(), date); + return date; } -void CJS_PropValue::operator<<(CJS_Date& date) { +void CJS_PropValue::Set(const CJS_Date& date) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), date); } @@ -496,6 +500,8 @@ CJS_Date::CJS_Date(CJS_Runtime* pRuntime, int sec) : m_pDate(pRuntime->NewDate(MakeDate(year, mon, day, hour, min, sec, 0))) {} +CJS_Date::CJS_Date(const CJS_Date& other) = default; + CJS_Date::~CJS_Date() {} bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const { diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h index 8c94ca742a..47e8cce98a 100644 --- a/fpdfsdk/javascript/JS_Value.h +++ b/fpdfsdk/javascript/JS_Value.h @@ -90,29 +90,39 @@ class CJS_PropValue { bool IsGetting() const { return !m_bIsSetting; } CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime.Get(); } CJS_Value* GetJSValue() { return &m_Value; } + const CJS_Value* GetJSValue() const { return &m_Value; } // These calls may re-enter JS (and hence invalidate objects). - void operator<<(int val); - void operator>>(int&) const; - void operator<<(bool val); - void operator>>(bool&) const; - void operator<<(double val); - void operator>>(double&) const; - void operator<<(CJS_Object* pObj); - void operator>>(CJS_Object*& ppObj) const; - void operator<<(CJS_Document* pJsDoc); - void operator>>(CJS_Document*& ppJsDoc) const; - void operator<<(ByteString); - void operator>>(ByteString&) const; - void operator<<(WideString); - void operator>>(WideString&) const; - void operator<<(const wchar_t* c_string); - void operator<<(v8::Local<v8::Object>); - void operator>>(v8::Local<v8::Object>&) const; - void operator>>(CJS_Array& array) const; - void operator<<(CJS_Array& array); - void operator<<(CJS_Date& date); - void operator>>(CJS_Date& date) const; + void Set(int val); + int ToInt() const; + + void Set(bool val); + bool ToBool() const; + + void Set(double val); + double ToDouble() const; + + void Set(CJS_Object* pObj); + CJS_Object* ToObject() const; + + void Set(CJS_Document* pJsDoc); + CJS_Document* ToDocument() const; + + void Set(const ByteString&); + ByteString ToByteString() const; + + void Set(const WideString&); + void Set(const wchar_t* c_string); + WideString ToWideString() const; + + void Set(v8::Local<v8::Object>); + v8::Local<v8::Object> ToV8Object() const; + + void Set(const CJS_Array& array); + CJS_Array ToArray() const; + + void Set(const CJS_Date& date); + CJS_Date ToDate() const; private: bool m_bIsSetting; @@ -154,6 +164,7 @@ class CJS_Date { int hour, int min, int sec); + CJS_Date(const CJS_Date&); virtual ~CJS_Date(); void Attach(v8::Local<v8::Date> pDate); diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index af4715987f..775877100e 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -850,9 +850,9 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, CJS_PropValue vProp(pRuntime); vProp.StartGetting(); - vProp << arColor; + vProp.Set(arColor); vProp.StartSetting(); - fTarget->textColor(pRuntime, vProp, sError); // red + fTarget->set_text_color(pRuntime, vProp, &sError); // red } } } else { @@ -869,7 +869,7 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, CJS_PropValue vProp(pRuntime); vProp.StartGetting(); - fTarget->textColor(pRuntime, vProp, sError); + fTarget->get_text_color(pRuntime, &vProp, &sError); CJS_Array aProp; vProp.GetJSValue()->ConvertToArray(pRuntime, aProp); @@ -882,9 +882,9 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, if (crColor != crProp) { CJS_PropValue vProp2(pRuntime); vProp2.StartGetting(); - vProp2 << arColor; + vProp2.Set(arColor); vProp2.StartSetting(); - fTarget->textColor(pRuntime, vProp2, sError); + fTarget->set_text_color(pRuntime, vProp2, &sError); } } } diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index eec468186f..9fac4611a6 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -161,19 +161,20 @@ void TimerObj::SetTimer(GlobalTimer* pTimer) { JSConstSpec CJS_App::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; JSPropertySpec CJS_App::PropertySpecs[] = { - {"activeDocs", get_activeDocs_static, set_activeDocs_static}, + {"activeDocs", get_active_docs_static, set_active_docs_static}, {"calculate", get_calculate_static, set_calculate_static}, - {"formsVersion", get_formsVersion_static, set_formsVersion_static}, + {"formsVersion", get_forms_version_static, set_forms_version_static}, {"fs", get_fs_static, set_fs_static}, {"fullscreen", get_fullscreen_static, set_fullscreen_static}, {"language", get_language_static, set_language_static}, {"media", get_media_static, set_media_static}, {"platform", get_platform_static, set_platform_static}, - {"runtimeHighlight", get_runtimeHighlight_static, - set_runtimeHighlight_static}, - {"viewerType", get_viewerType_static, set_viewerType_static}, - {"viewerVariation", get_viewerVariation_static, set_viewerVariation_static}, - {"viewerVersion", get_viewerVersion_static, set_viewerVersion_static}, + {"runtimeHighlight", get_runtime_highlight_static, + set_runtime_highlight_static}, + {"viewerType", get_viewer_type_static, set_viewer_type_static}, + {"viewerVariation", get_viewer_variation_static, + set_viewer_variation_static}, + {"viewerVersion", get_viewer_version_static, set_viewer_version_static}, {0, 0, 0}}; JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static}, @@ -207,12 +208,9 @@ app::app(CJS_Object* pJSObject) app::~app() { } -bool app::activeDocs(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool app::get_active_docs(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_Document* pJSDocument = nullptr; v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) @@ -221,114 +219,141 @@ bool app::activeDocs(CJS_Runtime* pRuntime, CJS_Array aDocs; aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); if (aDocs.GetLength(pRuntime) > 0) - vp << aDocs; + vp->Set(aDocs); else - vp.GetJSValue()->SetNull(pRuntime); + vp->GetJSValue()->SetNull(pRuntime); return true; } -bool app::calculate(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - bool bVP; - vp >> bVP; - m_bCalculate = bVP; - pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate); - } else { - vp << m_bCalculate; - } +bool app::set_active_docs(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool app::get_calculate(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(m_bCalculate); return true; } -bool app::formsVersion(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsGetting()) { - vp << JS_NUM_FORMSVERSION; - return true; - } +bool app::set_calculate(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + m_bCalculate = vp.ToBool(); + pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate); + return true; +} +bool app::get_forms_version(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(JS_NUM_FORMSVERSION); + return true; +} + +bool app::set_forms_version(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } -bool app::viewerType(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsGetting()) { - vp << JS_STR_VIEWERTYPE; - return true; - } +bool app::get_viewer_type(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(JS_STR_VIEWERTYPE); + return true; +} +bool app::set_viewer_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } -bool app::viewerVariation(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsGetting()) { - vp << JS_STR_VIEWERVARIATION; - return true; - } +bool app::get_viewer_variation(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(JS_STR_VIEWERVARIATION); + return true; +} +bool app::set_viewer_variation(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } -bool app::viewerVersion(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool app::get_viewer_version(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { #ifdef PDF_ENABLE_XFA CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext(); if (pXFAContext->ContainsXFAForm()) { - vp << JS_NUM_VIEWERVERSION_XFA; + vp->Set(JS_NUM_VIEWERVERSION_XFA); return true; } #endif // PDF_ENABLE_XFA - vp << JS_NUM_VIEWERVERSION; + vp->Set(JS_NUM_VIEWERVERSION); return true; } -bool app::platform(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool app::set_viewer_version(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool app::get_platform(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { #ifdef PDF_ENABLE_XFA CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); if (!pFormFillEnv) return false; + WideString platfrom = pFormFillEnv->GetPlatform(); if (!platfrom.IsEmpty()) { - vp << platfrom; + vp->Set(platfrom); return true; } #endif - vp << JS_STR_PLATFORM; + vp->Set(JS_STR_PLATFORM); return true; } -bool app::language(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool app::set_platform(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool app::get_language(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { #ifdef PDF_ENABLE_XFA CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); if (!pFormFillEnv) return false; + WideString language = pFormFillEnv->GetLanguage(); if (!language.IsEmpty()) { - vp << language; + vp->Set(language); return true; } #endif - vp << JS_STR_LANGUAGE; + vp->Set(JS_STR_LANGUAGE); return true; } +bool app::set_language(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + // creates a new fdf object that contains no data // comment: need reader support // note: @@ -441,7 +466,13 @@ bool app::popUpMenuEx(CJS_Runtime* pRuntime, return false; } -bool app::fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { +bool app::get_fs(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError) { + return false; +} + +bool app::set_fs(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } @@ -660,20 +691,29 @@ bool app::launchURL(CJS_Runtime* pRuntime, return true; } -bool app::runtimeHighlight(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - vp >> m_bRuntimeHighLight; - } else { - vp << m_bRuntimeHighLight; - } +bool app::get_runtime_highlight(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + vp->Set(m_bRuntimeHighLight); return true; } -bool app::fullscreen(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool app::set_runtime_highlight(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + m_bRuntimeHighLight = vp.ToBool(); + return true; +} + +bool app::get_fullscreen(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return false; +} + +bool app::set_fullscreen(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } @@ -764,7 +804,15 @@ bool app::response(CJS_Runtime* pRuntime, return true; } -bool app::media(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { +bool app::get_media(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return false; +} + +bool app::set_media(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return false; } diff --git a/fpdfsdk/javascript/app.h b/fpdfsdk/javascript/app.h index e77c8cd57b..8c0ac3aefb 100644 --- a/fpdfsdk/javascript/app.h +++ b/fpdfsdk/javascript/app.h @@ -41,26 +41,85 @@ class app : public CJS_EmbedObj { explicit app(CJS_Object* pJSObject); ~app() override; - bool activeDocs(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool calculate(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool formsVersion(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool fullscreen(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool language(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool media(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool platform(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool runtimeHighlight(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool viewerType(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool viewerVariation(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool viewerVersion(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); + bool get_active_docs(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_active_docs(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_calculate(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_calculate(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_forms_version(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_forms_version(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_fs(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_fs(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_fullscreen(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_fullscreen(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_language(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_language(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_media(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_media(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_platform(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_platform(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_runtime_highlight(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_runtime_highlight(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_viewer_type(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_viewer_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_viewer_variation(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_viewer_variation(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_viewer_version(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_viewer_version(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); bool alert(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, @@ -170,18 +229,18 @@ class CJS_App : public CJS_Object { DECLARE_JS_CLASS(); - JS_STATIC_PROP(activeDocs, app); - JS_STATIC_PROP(calculate, app); - JS_STATIC_PROP(formsVersion, app); - JS_STATIC_PROP(fs, app); - JS_STATIC_PROP(fullscreen, app); - JS_STATIC_PROP(language, app); - JS_STATIC_PROP(media, app); - JS_STATIC_PROP(platform, app); - JS_STATIC_PROP(runtimeHighlight, app); - JS_STATIC_PROP(viewerType, app); - JS_STATIC_PROP(viewerVariation, app); - JS_STATIC_PROP(viewerVersion, app); + JS_STATIC_PROP(activeDocs, active_docs, app); + JS_STATIC_PROP(calculate, calculate, app); + JS_STATIC_PROP(formsVersion, forms_version, app); + JS_STATIC_PROP(fs, fs, app); + JS_STATIC_PROP(fullscreen, fullscreen, app); + JS_STATIC_PROP(language, language, app); + JS_STATIC_PROP(media, media, app); + JS_STATIC_PROP(platform, platform, app); + JS_STATIC_PROP(runtimeHighlight, runtime_highlight, app); + JS_STATIC_PROP(viewerType, viewer_type, app); + JS_STATIC_PROP(viewerVariation, viewer_variation, app); + JS_STATIC_PROP(viewerVersion, viewer_version, app); JS_STATIC_METHOD(alert, app); JS_STATIC_METHOD(beep, app); diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index db860d37df..f1dc26efec 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -21,10 +21,10 @@ JSPropertySpec CJS_Color::PropertySpecs[] = { {"black", get_black_static, set_black_static}, {"blue", get_blue_static, set_blue_static}, {"cyan", get_cyan_static, set_cyan_static}, - {"dkGray", get_dkGray_static, set_dkGray_static}, + {"dkGray", get_dark_gray_static, set_dark_gray_static}, {"gray", get_gray_static, set_gray_static}, {"green", get_green_static, set_green_static}, - {"ltGray", get_ltGray_static, set_ltGray_static}, + {"ltGray", get_light_gray_static, set_light_gray_static}, {"magenta", get_magenta_static, set_magenta_static}, {"red", get_red_static, set_red_static}, {"transparent", get_transparent_static, set_transparent_static}, @@ -130,79 +130,163 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, } } -bool color::transparent(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crTransparent); +bool color::get_transparent(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crTransparent); } -bool color::black(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crBlack); +bool color::set_transparent(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crTransparent); } -bool color::white(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crWhite); +bool color::get_black(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crBlack); } -bool color::red(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crRed); +bool color::set_black(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crBlack); } -bool color::green(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crGreen); +bool color::get_white(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crWhite); } -bool color::blue(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crBlue); +bool color::set_white(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crWhite); } -bool color::cyan(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crCyan); +bool color::get_red(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crRed); } -bool color::magenta(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crMagenta); +bool color::set_red(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crRed); +} + +bool color::get_green(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crGreen); +} + +bool color::set_green(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crGreen); +} + +bool color::get_blue(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crBlue); +} + +bool color::set_blue(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crBlue); +} + +bool color::get_cyan(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crCyan); +} + +bool color::set_cyan(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crCyan); } -bool color::yellow(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crYellow); +bool color::get_magenta(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crMagenta); } -bool color::dkGray(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crDKGray); +bool color::set_magenta(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crMagenta); } -bool color::gray(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crGray); +bool color::get_yellow(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crYellow); } -bool color::ltGray(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - return PropertyHelper(pRuntime, vp, &m_crLTGray); +bool color::set_yellow(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crYellow); } -bool color::PropertyHelper(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - CFX_Color* var) { +bool color::get_dark_gray(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crDKGray); +} + +bool color::set_dark_gray(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crDKGray); +} + +bool color::get_gray(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crGray); +} + +bool color::set_gray(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crGray); +} + +bool color::get_light_gray(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return GetPropertyHelper(pRuntime, vp, &m_crLTGray); +} + +bool color::set_light_gray(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return SetPropertyHelper(pRuntime, vp, &m_crLTGray); +} + +bool color::GetPropertyHelper(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + CFX_Color* var) { CJS_Array array; - if (vp.IsGetting()) { ConvertPWLColorToArray(pRuntime, *var, &array); - vp << array; + vp->Set(array); return true; - } +} + +bool color::SetPropertyHelper(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + CFX_Color* var) { + CJS_Array array; if (!vp.GetJSValue()->ConvertToArray(pRuntime, array)) return false; diff --git a/fpdfsdk/javascript/color.h b/fpdfsdk/javascript/color.h index 5e1e871064..d4ca43a878 100644 --- a/fpdfsdk/javascript/color.h +++ b/fpdfsdk/javascript/color.h @@ -17,20 +17,73 @@ class color : public CJS_EmbedObj { explicit color(CJS_Object* pJSObject); ~color() override; - bool black(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool blue(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool cyan(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool dkGray(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool gray(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool green(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool ltGray(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool magenta(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool red(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool transparent(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool white(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool yellow(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); + bool get_black(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_black(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_blue(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_blue(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_cyan(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_cyan(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_dark_gray(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_dark_gray(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_gray(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_gray(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_green(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_green(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_light_gray(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_light_gray(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_magenta(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_magenta(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_red(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_red(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_transparent(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_transparent(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_white(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_white(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_yellow(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_yellow(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); bool convert(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, @@ -49,7 +102,12 @@ class color : public CJS_EmbedObj { CFX_Color* color); private: - bool PropertyHelper(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_Color* val); + bool GetPropertyHelper(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + CFX_Color* val); + bool SetPropertyHelper(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + CFX_Color* val); CFX_Color m_crTransparent; CFX_Color m_crBlack; @@ -72,18 +130,18 @@ class CJS_Color : public CJS_Object { DECLARE_JS_CLASS(); - JS_STATIC_PROP(black, color); - JS_STATIC_PROP(blue, color); - JS_STATIC_PROP(cyan, color); - JS_STATIC_PROP(dkGray, color); - JS_STATIC_PROP(gray, color); - JS_STATIC_PROP(green, color); - JS_STATIC_PROP(ltGray, color); - JS_STATIC_PROP(magenta, color); - JS_STATIC_PROP(red, color); - JS_STATIC_PROP(transparent, color); - JS_STATIC_PROP(white, color); - JS_STATIC_PROP(yellow, color); + JS_STATIC_PROP(black, black, color); + JS_STATIC_PROP(blue, blue, color); + JS_STATIC_PROP(cyan, cyan, color); + JS_STATIC_PROP(dkGray, dark_gray, color); + JS_STATIC_PROP(gray, gray, color); + JS_STATIC_PROP(green, green, color); + JS_STATIC_PROP(ltGray, light_gray, color); + JS_STATIC_PROP(magenta, magenta, color); + JS_STATIC_PROP(red, red, color); + JS_STATIC_PROP(transparent, transparent, color); + JS_STATIC_PROP(white, white, color); + JS_STATIC_PROP(yellow, yellow, color); JS_STATIC_METHOD(convert, color); JS_STATIC_METHOD(equal, color); diff --git a/fpdfsdk/javascript/event.cpp b/fpdfsdk/javascript/event.cpp index efc704da94..9c2e3f490e 100644 --- a/fpdfsdk/javascript/event.cpp +++ b/fpdfsdk/javascript/event.cpp @@ -17,25 +17,25 @@ JSConstSpec CJS_Event::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; JSPropertySpec CJS_Event::PropertySpecs[] = { {"change", get_change_static, set_change_static}, - {"changeEx", get_changeEx_static, set_changeEx_static}, - {"commitKey", get_commitKey_static, set_commitKey_static}, - {"fieldFull", get_fieldFull_static, set_fieldFull_static}, - {"keyDown", get_keyDown_static, set_keyDown_static}, + {"changeEx", get_change_ex_static, set_change_ex_static}, + {"commitKey", get_commit_key_static, set_commit_key_static}, + {"fieldFull", get_field_full_static, set_field_full_static}, + {"keyDown", get_key_down_static, set_key_down_static}, {"modifier", get_modifier_static, set_modifier_static}, {"name", get_name_static, set_name_static}, {"rc", get_rc_static, set_rc_static}, - {"richChange", get_richChange_static, set_richChange_static}, - {"richChangeEx", get_richChangeEx_static, set_richChangeEx_static}, - {"richValue", get_richValue_static, set_richValue_static}, - {"selEnd", get_selEnd_static, set_selEnd_static}, - {"selStart", get_selStart_static, set_selStart_static}, + {"richChange", get_rich_change_static, set_rich_change_static}, + {"richChangeEx", get_rich_change_ex_static, set_rich_change_ex_static}, + {"richValue", get_rich_value_static, set_rich_value_static}, + {"selEnd", get_sel_end_static, set_sel_end_static}, + {"selStart", get_sel_start_static, set_sel_start_static}, {"shift", get_shift_static, set_shift_static}, {"source", get_source_static, set_source_static}, {"target", get_target_static, set_target_static}, - {"targetName", get_targetName_static, set_targetName_static}, + {"targetName", get_target_name_static, set_target_name_static}, {"type", get_type_static, set_type_static}, {"value", get_value_static, set_value_static}, - {"willCommit", get_willCommit_static, set_willCommit_static}, + {"willCommit", get_will_commit_static, set_will_commit_static}, {0, 0, 0}}; JSMethodSpec CJS_Event::MethodSpecs[] = {{0, 0}}; @@ -46,231 +46,308 @@ event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} event::~event() {} -bool event::change(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::get_change(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - WideString& wChange = pEvent->Change(); - if (vp.IsSetting()) { - if (vp.GetJSValue()->GetType() == CJS_Value::VT_string) - vp >> wChange; - return true; - } - vp << wChange; + vp->Set(pEvent->Change()); return true; } -bool event::changeEx(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_change(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); + if (vp.GetJSValue()->GetType() == CJS_Value::VT_string) { + WideString& wChange = pEvent->Change(); + wChange = vp.ToWideString(); + } + return true; +} + +bool event::get_change_ex(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - vp << pEvent->ChangeEx(); + vp->Set(pEvent->ChangeEx()); return true; } -bool event::commitKey(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_change_ex(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool event::get_commit_key(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - vp << pEvent->CommitKey(); + vp->Set(pEvent->CommitKey()); return true; } -bool event::fieldFull(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::set_commit_key(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool event::get_field_full(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (!vp.IsGetting() && - wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) + if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return false; - vp << pEvent->FieldFull(); + vp->Set(pEvent->FieldFull()); return true; } -bool event::keyDown(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_field_full(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool event::get_key_down(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - - vp << pEvent->KeyDown(); + vp->Set(pEvent->KeyDown()); return true; } -bool event::modifier(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_key_down(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool event::get_modifier(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - - vp << pEvent->Modifier(); + vp->Set(pEvent->Modifier()); return true; } -bool event::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_modifier(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool event::get_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp->Set(pEvent->Name()); + return true; +} + +bool event::set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} - vp << pEvent->Name(); +bool event::get_rc(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp->Set(pEvent->Rc()); return true; } -bool event::rc(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { +bool event::set_rc(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); + pEvent->Rc() = vp.ToBool(); + return true; +} + +bool event::get_rich_change(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + return true; +} - bool& bRc = pEvent->Rc(); - if (vp.IsSetting()) - vp >> bRc; - else - vp << bRc; +bool event::set_rich_change(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return true; +} +bool event::get_rich_change_ex(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return true; } -bool event::richChange(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::set_rich_change_ex(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } -bool event::richChangeEx(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::get_rich_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { return true; } -bool event::richValue(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::set_rich_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { return true; } -bool event::selEnd(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::get_sel_end(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; - int& iSelEnd = pEvent->SelEnd(); - if (vp.IsSetting()) - vp >> iSelEnd; - else - vp << iSelEnd; - + vp->Set(pEvent->SelEnd()); return true; } -bool event::selStart(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::set_sel_end(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; - int& iSelStart = pEvent->SelStart(); - if (vp.IsSetting()) - vp >> iSelStart; - else - vp << iSelStart; - + pEvent->SelEnd() = vp.ToInt(); return true; } -bool event::shift(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool event::get_sel_start(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - vp << pEvent->Shift(); + if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) + return true; + + vp->Set(pEvent->SelStart()); return true; } -bool event::source(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool event::set_sel_start(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - vp << pEvent->Source()->GetJSObject(); + if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) + return true; + + pEvent->SelStart() = vp.ToInt(); return true; } -bool event::target(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; - +bool event::get_shift(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - - vp << pEvent->Target_Field()->GetJSObject(); + vp->Set(pEvent->Shift()); return true; } -bool event::targetName(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_shift(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool event::get_source(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp->Set(pEvent->Source()->GetJSObject()); + return true; +} - vp << pEvent->TargetName(); +bool event::set_source(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool event::get_target(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp->Set(pEvent->Target_Field()->GetJSObject()); return true; } -bool event::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) { - if (!vp.IsGetting()) - return false; +bool event::set_target(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} +bool event::get_target_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp->Set(pEvent->TargetName()); + return true; +} - vp << pEvent->Type(); +bool event::set_target_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool event::get_type(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp->Set(pEvent->Type()); return true; } -bool event::value(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { +bool event::set_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} + +bool event::get_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); @@ -280,24 +357,37 @@ bool event::value(CJS_Runtime* pRuntime, if (!pEvent->m_pValue) return false; - WideString& val = pEvent->Value(); - if (vp.IsSetting()) - vp >> val; - else - vp << val; - + vp->Set(pEvent->Value()); return true; } -bool event::willCommit(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError) { - if (!vp.IsGetting()) +bool event::set_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); + + if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) return false; + if (!pEvent->m_pValue) + return false; + + pEvent->Value() = vp.ToWideString(); + return true; +} + +bool event::get_will_commit(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - - vp << pEvent->WillCommit(); + vp->Set(pEvent->WillCommit()); return true; } + +bool event::set_will_commit(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError) { + return false; +} diff --git a/fpdfsdk/javascript/event.h b/fpdfsdk/javascript/event.h index 857423784e..e67aa2b8af 100644 --- a/fpdfsdk/javascript/event.h +++ b/fpdfsdk/javascript/event.h @@ -15,28 +15,129 @@ class event : public CJS_EmbedObj { ~event() override; public: - bool change(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool changeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool commitKey(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool fieldFull(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool keyDown(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool modifier(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool rc(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool richChange(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool richChangeEx(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - WideString& sError); - bool richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool selEnd(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool selStart(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool shift(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool source(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool target(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool targetName(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool value(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); - bool willCommit(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError); + bool get_change(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_change(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_change_ex(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_change_ex(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_commit_key(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_commit_key(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_field_full(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_field_full(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_key_down(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_key_down(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_modifier(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_modifier(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_name(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rc(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_rc(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rich_change(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_rich_change(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rich_change_ex(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_rich_change_ex(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_rich_value(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_rich_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_sel_end(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_sel_end(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_sel_start(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_sel_start(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_shift(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_shift(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_source(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_source(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_target(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_target(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_target_name(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_target_name(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_type(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_type(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_value(CJS_Runtime* pRuntime, CJS_PropValue* vp, WideString* sError); + bool set_value(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); + + bool get_will_commit(CJS_Runtime* pRuntime, + CJS_PropValue* vp, + WideString* sError); + bool set_will_commit(CJS_Runtime* pRuntime, + const CJS_PropValue& vp, + WideString* sError); }; class CJS_Event : public CJS_Object { @@ -45,26 +146,26 @@ class CJS_Event : public CJS_Object { ~CJS_Event() override {} DECLARE_JS_CLASS(); - JS_STATIC_PROP(change, event); - JS_STATIC_PROP(changeEx, event); - JS_STATIC_PROP(commitKey, event); - JS_STATIC_PROP(fieldFull, event); - JS_STATIC_PROP(keyDown, event); - JS_STATIC_PROP(modifier, event); - JS_STATIC_PROP(name, event); - JS_STATIC_PROP(rc, event); - JS_STATIC_PROP(richChange, event); - JS_STATIC_PROP(richChangeEx, event); - JS_STATIC_PROP(richValue, event); - JS_STATIC_PROP(selEnd, event); - JS_STATIC_PROP(selStart, event); - JS_STATIC_PROP(shift, event); - JS_STATIC_PROP(source, event); - JS_STATIC_PROP(target, event); - JS_STATIC_PROP(targetName, event); - JS_STATIC_PROP(type, event); - JS_STATIC_PROP(value, event); - JS_STATIC_PROP(willCommit, event); + JS_STATIC_PROP(change, change, event); + JS_STATIC_PROP(changeEx, change_ex, event); + JS_STATIC_PROP(commitKey, commit_key, event); + JS_STATIC_PROP(fieldFull, field_full, event); + JS_STATIC_PROP(keyDown, key_down, event); + JS_STATIC_PROP(modifier, modifier, event); + JS_STATIC_PROP(name, name, event); + JS_STATIC_PROP(rc, rc, event); + JS_STATIC_PROP(richChange, rich_change, event); + JS_STATIC_PROP(richChangeEx, rich_change_ex, event); + JS_STATIC_PROP(richValue, rich_value, event); + JS_STATIC_PROP(selEnd, sel_end, event); + JS_STATIC_PROP(selStart, sel_start, event); + JS_STATIC_PROP(shift, shift, event); + JS_STATIC_PROP(source, source, event); + JS_STATIC_PROP(target, target, event); + JS_STATIC_PROP(targetName, target_name, event); + JS_STATIC_PROP(type, type, event); + JS_STATIC_PROP(value, value, event); + JS_STATIC_PROP(willCommit, will_commit, event); }; #endif // FPDFSDK_JAVASCRIPT_EVENT_H_ diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 9827b2aae7..43c461c497 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -66,8 +66,7 @@ bool JSGlobalAlternate::QueryProperty(const wchar_t* propname) { } bool JSGlobalAlternate::DelProperty(CJS_Runtime* pRuntime, - const wchar_t* propname, - WideString& sError) { + const wchar_t* propname) { auto it = m_MapGlobal.find(ByteString::FromUnicode(propname)); if (it == m_MapGlobal.end()) return false; @@ -76,81 +75,73 @@ bool JSGlobalAlternate::DelProperty(CJS_Runtime* pRuntime, return true; } -bool JSGlobalAlternate::DoProperty(CJS_Runtime* pRuntime, - const wchar_t* propname, - CJS_PropValue& vp, - WideString& sError) { - if (vp.IsSetting()) { - ByteString sPropName = ByteString::FromUnicode(propname); - switch (vp.GetJSValue()->GetType()) { - case CJS_Value::VT_number: { - double dData; - vp >> dData; - return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER, dData, - false, "", v8::Local<v8::Object>(), false); - } - case CJS_Value::VT_boolean: { - bool bData; - vp >> bData; - return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0, - bData, "", v8::Local<v8::Object>(), false); - } - case CJS_Value::VT_string: { - ByteString sData; - vp >> sData; - return SetGlobalVariables(sPropName, JS_GlobalDataType::STRING, 0, - false, sData, v8::Local<v8::Object>(), false); - } - case CJS_Value::VT_object: { - v8::Local<v8::Object> pData; - vp >> pData; - return SetGlobalVariables(sPropName, JS_GlobalDataType::OBJECT, 0, - false, "", pData, false); - } - case CJS_Value::VT_null: { - return SetGlobalVariables(sPropName, JS_GlobalDataType::NULLOBJ, 0, - false, "", v8::Local<v8::Object>(), false); - } - case CJS_Value::VT_undefined: { - DelProperty(pRuntime, propname, sError); - return true; - } - default: - break; - } - } else { - auto it = m_MapGlobal.find(ByteString::FromUnicode(propname)); - if (it == m_MapGlobal.end()) { - vp.GetJSValue()->SetNull(pRuntime); +bool JSGlobalAlternate::GetProperty(CJS_Runtime* pRuntime, + const wchar_t* propname, + CJS_PropValue* vp) { + auto it = m_MapGlobal.find(ByteString::FromUnicode(propname)); + if (it == m_MapGlobal.end()) { + vp->GetJSValue()->SetNull(pRuntime); + return true; + } + + JSGlobalData* pData = it->second.get(); + if (pData->bDeleted) { + vp->GetJSValue()->SetNull(pRuntime); + return true; + } + + switch (pData->nType) { + case JS_GlobalDataType::NUMBER: + vp->Set(pData->dData); return true; - } - JSGlobalData* pData = it->second.get(); - if (pData->bDeleted) { - vp.GetJSValue()->SetNull(pRuntime); + case JS_GlobalDataType::BOOLEAN: + vp->Set(pData->bData); + return true; + case JS_GlobalDataType::STRING: + vp->Set(pData->sData); + return true; + case JS_GlobalDataType::OBJECT: { + vp->Set(v8::Local<v8::Object>::New(vp->GetJSRuntime()->GetIsolate(), + pData->pData)); return true; } - switch (pData->nType) { - case JS_GlobalDataType::NUMBER: - vp << pData->dData; - return true; - case JS_GlobalDataType::BOOLEAN: - vp << pData->bData; - return true; - case JS_GlobalDataType::STRING: - vp << pData->sData; - return true; - case JS_GlobalDataType::OBJECT: { - v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( - vp.GetJSRuntime()->GetIsolate(), pData->pData); - vp << obj; - return true; - } - case JS_GlobalDataType::NULLOBJ: - vp.GetJSValue()->SetNull(pRuntime); - return true; - default: - break; - } + case JS_GlobalDataType::NULLOBJ: + vp->GetJSValue()->SetNull(pRuntime); + return true; + default: + break; + } + return false; +} + +bool JSGlobalAlternate::SetProperty(CJS_Runtime* pRuntime, + const wchar_t* propname, + const CJS_PropValue& vp) { + ByteString sPropName = ByteString::FromUnicode(propname); + switch (vp.GetJSValue()->GetType()) { + case CJS_Value::VT_number: + return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER, + vp.ToDouble(), false, "", + v8::Local<v8::Object>(), false); + case CJS_Value::VT_boolean: + return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0, + vp.ToBool(), "", v8::Local<v8::Object>(), + false); + case CJS_Value::VT_string: + return SetGlobalVariables(sPropName, JS_GlobalDataType::STRING, 0, false, + vp.ToByteString(), v8::Local<v8::Object>(), + false); + case CJS_Value::VT_object: + return SetGlobalVariables(sPropName, JS_GlobalDataType::OBJECT, 0, false, + "", vp.ToV8Object(), false); + case CJS_Value::VT_null: + return SetGlobalVariables(sPropName, JS_GlobalDataType::NULLOBJ, 0, false, + "", v8::Local<v8::Object>(), false); + case CJS_Value::VT_undefined: + DelProperty(pRuntime, propname); + return true; + default: + break; } return false; } diff --git a/fpdfsdk/javascript/global.h b/fpdfsdk/javascript/global.h index 5005b2aeed..c741a1a20f 100644 --- a/fpdfsdk/javascript/global.h +++ b/fpdfsdk/javascript/global.h @@ -41,13 +41,13 @@ class JSGlobalAlternate : public CJS_EmbedObj { CJS_Value& vRet, WideString& sError); bool QueryProperty(const wchar_t* propname); - bool DoProperty(CJS_Runtime* pRuntime, - const wchar_t* propname, - CJS_PropValue& vp, - WideString& sError); - bool DelProperty(CJS_Runtime* pRuntime, + bool GetProperty(CJS_Runtime* pRuntime, const wchar_t* propname, - WideString& sError); + CJS_PropValue* vp); + bool SetProperty(CJS_Runtime* pRuntime, + const wchar_t* propname, + const CJS_PropValue& vp); + bool DelProperty(CJS_Runtime* pRuntime, const wchar_t* propname); void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv); private: |