From 5110c4743751145c4ae1934cd1d83bc6c55bb43f Mon Sep 17 00:00:00 2001 From: John Abd-El-Malek Date: Sat, 17 May 2014 22:33:34 -0700 Subject: Initial commit. --- fpdfsdk/include/javascript/Consts.h | 126 +++++ fpdfsdk/include/javascript/Document.h | 282 ++++++++++ fpdfsdk/include/javascript/Field.h | 355 ++++++++++++ fpdfsdk/include/javascript/IJavaScript.h | 112 ++++ fpdfsdk/include/javascript/Icon.h | 42 ++ fpdfsdk/include/javascript/JS_Console.h | 239 ++++++++ fpdfsdk/include/javascript/JS_Context.h | 101 ++++ fpdfsdk/include/javascript/JS_Define.h | 785 +++++++++++++++++++++++++++ fpdfsdk/include/javascript/JS_EventHandler.h | 167 ++++++ fpdfsdk/include/javascript/JS_GlobalData.h | 97 ++++ fpdfsdk/include/javascript/JS_Module.h | 47 ++ fpdfsdk/include/javascript/JS_Object.h | 288 ++++++++++ fpdfsdk/include/javascript/JS_Runtime.h | 70 +++ fpdfsdk/include/javascript/JS_Value.h | 186 +++++++ fpdfsdk/include/javascript/JavaScript.h | 39 ++ fpdfsdk/include/javascript/PublicMethods.h | 101 ++++ fpdfsdk/include/javascript/app.h | 225 ++++++++ fpdfsdk/include/javascript/color.h | 78 +++ fpdfsdk/include/javascript/console.h | 38 ++ fpdfsdk/include/javascript/event.h | 70 +++ fpdfsdk/include/javascript/global.h | 85 +++ fpdfsdk/include/javascript/report.h | 35 ++ fpdfsdk/include/javascript/resource.h | 110 ++++ fpdfsdk/include/javascript/util.h | 45 ++ 24 files changed, 3723 insertions(+) create mode 100644 fpdfsdk/include/javascript/Consts.h create mode 100644 fpdfsdk/include/javascript/Document.h create mode 100644 fpdfsdk/include/javascript/Field.h create mode 100644 fpdfsdk/include/javascript/IJavaScript.h create mode 100644 fpdfsdk/include/javascript/Icon.h create mode 100644 fpdfsdk/include/javascript/JS_Console.h create mode 100644 fpdfsdk/include/javascript/JS_Context.h create mode 100644 fpdfsdk/include/javascript/JS_Define.h create mode 100644 fpdfsdk/include/javascript/JS_EventHandler.h create mode 100644 fpdfsdk/include/javascript/JS_GlobalData.h create mode 100644 fpdfsdk/include/javascript/JS_Module.h create mode 100644 fpdfsdk/include/javascript/JS_Object.h create mode 100644 fpdfsdk/include/javascript/JS_Runtime.h create mode 100644 fpdfsdk/include/javascript/JS_Value.h create mode 100644 fpdfsdk/include/javascript/JavaScript.h create mode 100644 fpdfsdk/include/javascript/PublicMethods.h create mode 100644 fpdfsdk/include/javascript/app.h create mode 100644 fpdfsdk/include/javascript/color.h create mode 100644 fpdfsdk/include/javascript/console.h create mode 100644 fpdfsdk/include/javascript/event.h create mode 100644 fpdfsdk/include/javascript/global.h create mode 100644 fpdfsdk/include/javascript/report.h create mode 100644 fpdfsdk/include/javascript/resource.h create mode 100644 fpdfsdk/include/javascript/util.h (limited to 'fpdfsdk/include/javascript') diff --git a/fpdfsdk/include/javascript/Consts.h b/fpdfsdk/include/javascript/Consts.h new file mode 100644 index 0000000000..32b0217502 --- /dev/null +++ b/fpdfsdk/include/javascript/Consts.h @@ -0,0 +1,126 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _CONSTS_H_ +#define _CONSTS_H_ + +/* ------------------------------ border ------------------------------ */ + +class CJS_Border : public CJS_Object +{ +public: + CJS_Border(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Border(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ display ------------------------------ */ + +class CJS_Display : public CJS_Object +{ +public: + CJS_Display(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Display(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ font ------------------------------ */ + +class CJS_Font : public CJS_Object +{ +public: + CJS_Font(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Font(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ highlight ------------------------------ */ + +class CJS_Highlight : public CJS_Object +{ +public: + CJS_Highlight(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Highlight(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ position ------------------------------ */ + +class CJS_Position : public CJS_Object +{ +public: + CJS_Position(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Position(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ scaleHow ------------------------------ */ + +class CJS_ScaleHow : public CJS_Object +{ +public: + CJS_ScaleHow(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_ScaleHow(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ scaleWhen ------------------------------ */ + +class CJS_ScaleWhen : public CJS_Object +{ +public: + CJS_ScaleWhen(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_ScaleWhen(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ style ------------------------------ */ + +class CJS_Style : public CJS_Object +{ +public: + CJS_Style(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Style(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ zoomtype ------------------------------ */ + +class CJS_Zoomtype : public CJS_Object +{ +public: + CJS_Zoomtype(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Zoomtype(void){}; + + DECLARE_JS_CLASS_CONST(); +}; + +/* ------------------------------ CJS_GlobalConsts ------------------------------ */ + +class CJS_GlobalConsts : public CJS_Object +{ +public: + static int Init(IJS_Runtime* pRuntime); +}; + +/* ------------------------------ CJS_GlobalArrays ------------------------------ */ + +class CJS_GlobalArrays : public CJS_Object +{ +public: + static int Init(IJS_Runtime* pRuntime); +}; + +#endif //_CONSTS_H_ + diff --git a/fpdfsdk/include/javascript/Document.h b/fpdfsdk/include/javascript/Document.h new file mode 100644 index 0000000000..3e9669b8ef --- /dev/null +++ b/fpdfsdk/include/javascript/Document.h @@ -0,0 +1,282 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _DOCUMENT_H_ +#define _DOCUMENT_H_ + + + +class PrintParamsObj : public CJS_EmbedObj +{ +public: + PrintParamsObj(CJS_Object* pJSObject); + virtual ~PrintParamsObj(){} + +public: + FX_BOOL bUI; + int nStart; + int nEnd; + FX_BOOL bSilent; + FX_BOOL bShrinkToFit; + FX_BOOL bPrintAsImage; + FX_BOOL bReverse; + FX_BOOL bAnnotations; +}; + +class CJS_PrintParamsObj : public CJS_Object +{ +public: + CJS_PrintParamsObj(JSFXObject pObject) : CJS_Object(pObject) {} + virtual ~CJS_PrintParamsObj(){} + + DECLARE_JS_CLASS(CJS_PrintParamsObj); +}; + + +class Icon; +class Field; + +struct IconElement +{ + IconElement() : IconName(L""), IconStream(NULL), NextIcon(NULL){} + virtual ~IconElement() + { + } + CFX_WideString IconName; + IconElement* NextIcon; + Icon* IconStream; +}; + +class IconTree +{ +public: + IconTree():m_pHead(NULL), m_pEnd(NULL), m_iLength(0) + { + + } + + virtual ~IconTree() + { + } + +public: + void InsertIconElement(IconElement* pNewIcon); + void DeleteIconElement(CFX_WideString swIconName); + void DeleteIconTree(); + int GetLength(); + IconElement* operator[](int iIndex); + +private: + IconElement* m_pHead; + IconElement* m_pEnd; + int m_iLength; +}; + +struct CJS_DelayData; +struct CJS_DelayAnnot; +struct CJS_AnnotObj; + +class Document : public CJS_EmbedObj +{ +public: + Document(CJS_Object* pJSObject); + virtual ~Document(); + +public: + FX_BOOL ADBE(OBJ_PROP_PARAMS); + FX_BOOL author(OBJ_PROP_PARAMS); + FX_BOOL baseURL(OBJ_PROP_PARAMS); + FX_BOOL bookmarkRoot(OBJ_PROP_PARAMS); + FX_BOOL calculate(OBJ_PROP_PARAMS); + FX_BOOL Collab(OBJ_PROP_PARAMS); + FX_BOOL creationDate(OBJ_PROP_PARAMS); + FX_BOOL creator(OBJ_PROP_PARAMS); + FX_BOOL delay(OBJ_PROP_PARAMS); + FX_BOOL dirty(OBJ_PROP_PARAMS); + FX_BOOL documentFileName(OBJ_PROP_PARAMS); + FX_BOOL external(OBJ_PROP_PARAMS); + FX_BOOL filesize(OBJ_PROP_PARAMS); + FX_BOOL icons(OBJ_PROP_PARAMS); + FX_BOOL info(OBJ_PROP_PARAMS); + FX_BOOL keywords(OBJ_PROP_PARAMS); + FX_BOOL layout(OBJ_PROP_PARAMS); + FX_BOOL media(OBJ_PROP_PARAMS); + FX_BOOL modDate(OBJ_PROP_PARAMS); + FX_BOOL mouseX(OBJ_PROP_PARAMS); + FX_BOOL mouseY(OBJ_PROP_PARAMS); + FX_BOOL numFields(OBJ_PROP_PARAMS); + FX_BOOL numPages(OBJ_PROP_PARAMS); + FX_BOOL pageNum(OBJ_PROP_PARAMS); + FX_BOOL pageWindowRect(OBJ_PROP_PARAMS); + FX_BOOL path(OBJ_PROP_PARAMS); + FX_BOOL producer(OBJ_PROP_PARAMS); + FX_BOOL subject(OBJ_PROP_PARAMS); + FX_BOOL title(OBJ_PROP_PARAMS); + FX_BOOL zoom(OBJ_PROP_PARAMS); + FX_BOOL zoomType(OBJ_PROP_PARAMS); + + FX_BOOL addAnnot(OBJ_METHOD_PARAMS); + FX_BOOL addField(OBJ_METHOD_PARAMS); + FX_BOOL addLink(OBJ_METHOD_PARAMS); + FX_BOOL addIcon(OBJ_METHOD_PARAMS); + FX_BOOL calculateNow(OBJ_METHOD_PARAMS); + FX_BOOL closeDoc(OBJ_METHOD_PARAMS); + FX_BOOL createDataObject(OBJ_METHOD_PARAMS); + FX_BOOL deletePages(OBJ_METHOD_PARAMS); + FX_BOOL exportAsText(OBJ_METHOD_PARAMS); + FX_BOOL exportAsFDF(OBJ_METHOD_PARAMS); + FX_BOOL exportAsXFDF(OBJ_METHOD_PARAMS); + FX_BOOL extractPages(OBJ_METHOD_PARAMS); + FX_BOOL getAnnot(OBJ_METHOD_PARAMS); + FX_BOOL getAnnots(OBJ_METHOD_PARAMS); + FX_BOOL getAnnot3D(OBJ_METHOD_PARAMS); + FX_BOOL getAnnots3D(OBJ_METHOD_PARAMS); + FX_BOOL getField(OBJ_METHOD_PARAMS); + FX_BOOL getIcon(OBJ_METHOD_PARAMS); + FX_BOOL getLinks(OBJ_METHOD_PARAMS); + FX_BOOL getNthFieldName(OBJ_METHOD_PARAMS); + FX_BOOL getOCGs(OBJ_METHOD_PARAMS); + FX_BOOL getPageBox(OBJ_METHOD_PARAMS); + FX_BOOL getPageNthWord(OBJ_METHOD_PARAMS); + FX_BOOL getPageNthWordQuads(OBJ_METHOD_PARAMS); + FX_BOOL getPageNumWords(OBJ_METHOD_PARAMS); + FX_BOOL getPrintParams(OBJ_METHOD_PARAMS); + FX_BOOL getURL(OBJ_METHOD_PARAMS); + FX_BOOL importAnFDF(OBJ_METHOD_PARAMS); + FX_BOOL importAnXFDF(OBJ_METHOD_PARAMS); + FX_BOOL importTextData(OBJ_METHOD_PARAMS); + FX_BOOL insertPages(OBJ_METHOD_PARAMS); + FX_BOOL mailForm(OBJ_METHOD_PARAMS); + FX_BOOL print(OBJ_METHOD_PARAMS); + FX_BOOL removeField(OBJ_METHOD_PARAMS); + FX_BOOL replacePages(OBJ_METHOD_PARAMS); + FX_BOOL resetForm(OBJ_METHOD_PARAMS); + FX_BOOL saveAs(OBJ_METHOD_PARAMS); + FX_BOOL submitForm(OBJ_METHOD_PARAMS); + FX_BOOL mailDoc(OBJ_METHOD_PARAMS); + FX_BOOL removeIcon(OBJ_METHOD_PARAMS); + +public: + void AttachDoc(CPDFSDK_Document* pDoc); + CPDFSDK_Document* GetReaderDoc(); + + static FX_BOOL ExtractFileName(CPDFSDK_Document* pDoc, CFX_ByteString& strFileName); + static FX_BOOL ExtractFolderName(CPDFSDK_Document* pDoc, CFX_ByteString& strFolderName); + +public: + void AddDelayData(CJS_DelayData* pData); + void DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex); + + void AddDelayAnnotData(CJS_AnnotObj *pData); + void DoAnnotDelay(); + void SetIsolate(v8::Isolate* isolate) {m_isolate = isolate;} + +private: + CFX_WideString ReversalStr(CFX_WideString cbFrom); + CFX_WideString CutString(CFX_WideString cbFrom); + bool IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect); + int CountWords(CPDF_TextObject* pTextObj); + CFX_WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); + + FX_BOOL ParserParams(JSObject *pObj,CJS_AnnotObj& annotobj); + +private: + v8::Isolate* m_isolate; + IconTree* m_pIconTree; + CPDFSDK_Document* m_pDocument; + CFX_WideString m_cwBaseURL; + + FX_BOOL m_bDelay; + CFX_ArrayTemplate m_DelayData; + CFX_ArrayTemplate m_DelayAnnotData; +}; + +class CJS_Document : public CJS_Object +{ +public: + CJS_Document(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Document(){}; + + virtual FX_BOOL InitInstance(IFXJS_Context* cc); + + DECLARE_JS_CLASS(CJS_Document); + + 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(zoom, Document); + JS_STATIC_PROP(zoomType, Document); + + JS_STATIC_METHOD(addAnnot,Document); + JS_STATIC_METHOD(addField, Document); + JS_STATIC_METHOD(addLink, Document); + JS_STATIC_METHOD(addIcon, Document); + JS_STATIC_METHOD(calculateNow, Document); + JS_STATIC_METHOD(closeDoc, Document); + JS_STATIC_METHOD(createDataObject, Document); + JS_STATIC_METHOD(deletePages, Document); + JS_STATIC_METHOD(exportAsText, Document); + JS_STATIC_METHOD(exportAsFDF, Document); + JS_STATIC_METHOD(exportAsXFDF, Document); + JS_STATIC_METHOD(extractPages, Document); + JS_STATIC_METHOD(getAnnot, Document); + JS_STATIC_METHOD(getAnnots, Document); + JS_STATIC_METHOD(getAnnot3D, Document); + JS_STATIC_METHOD(getAnnots3D, Document); + JS_STATIC_METHOD(getField, Document); + JS_STATIC_METHOD(getIcon, Document); + JS_STATIC_METHOD(getLinks, Document); + JS_STATIC_METHOD(getNthFieldName, Document); + JS_STATIC_METHOD(getOCGs, Document); + JS_STATIC_METHOD(getPageBox, Document); + JS_STATIC_METHOD(getPageNthWord, Document); + JS_STATIC_METHOD(getPageNthWordQuads, Document); + JS_STATIC_METHOD(getPageNumWords, Document); + JS_STATIC_METHOD(getPrintParams, Document); + JS_STATIC_METHOD(getURL, Document); + JS_STATIC_METHOD(importAnFDF, Document); + JS_STATIC_METHOD(importAnXFDF, Document); + JS_STATIC_METHOD(importTextData, Document); + JS_STATIC_METHOD(insertPages, Document); + JS_STATIC_METHOD(mailForm, Document); + JS_STATIC_METHOD(print, Document); + JS_STATIC_METHOD(removeField, Document); + JS_STATIC_METHOD(replacePages, Document); + JS_STATIC_METHOD(removeIcon, Document); + JS_STATIC_METHOD(resetForm, Document); + JS_STATIC_METHOD(saveAs, Document); + JS_STATIC_METHOD(submitForm, Document); + JS_STATIC_METHOD(mailDoc, Document); +}; + +#endif//_DOCUMENT_H_ + diff --git a/fpdfsdk/include/javascript/Field.h b/fpdfsdk/include/javascript/Field.h new file mode 100644 index 0000000000..1b0bb05a12 --- /dev/null +++ b/fpdfsdk/include/javascript/Field.h @@ -0,0 +1,355 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _FIELD_H_ +#define _FIELD_H_ + +class Document; + +enum FIELD_PROP +{ + FP_ALIGNMENT, + FP_BORDERSTYLE, + FP_BUTTONALIGNX, + FP_BUTTONALIGNY, + FP_BUTTONFITBOUNDS, + FP_BUTTONPOSITION, + FP_BUTTONSCALEHOW, + FP_BUTTONSCALEWHEN, + FP_CALCORDERINDEX, + FP_CHARLIMIT, + FP_COMB, + FP_COMMITONSELCHANGE, + FP_CURRENTVALUEINDICES, + FP_DEFAULTVALUE, + FP_DONOTSCROLL, + FP_DISPLAY, + FP_FILLCOLOR, + FP_HIDDEN, + FP_HIGHLIGHT, + FP_LINEWIDTH, + FP_MULTILINE, + FP_MULTIPLESELECTION, + FP_PASSWORD, + FP_RECT, + FP_RICHTEXT, + FP_RICHVALUE, + FP_ROTATION, + FP_STROKECOLOR, + FP_STYLE, + FP_TEXTCOLOR, + FP_TEXTFONT, + FP_TEXTSIZE, + FP_USERNAME, + FP_VALUE +}; + +class CJS_WideStringArray +{ +public: + CJS_WideStringArray(){} + virtual ~CJS_WideStringArray() + { + for (int i=0,sz=m_Data.GetSize(); i m_Data; +}; + +struct CJS_DelayData +{ + CFX_WideString sFieldName; + int nControlIndex; + enum FIELD_PROP eProp; + FX_INT32 num; + bool b; + CFX_ByteString string; + CFX_WideString widestring; + CPDF_Rect rect; + CPWL_Color color; + CFX_DWordArray wordarray; + CJS_WideStringArray widestringarray; +}; + +class Field : public CJS_EmbedObj +{ +public: + Field(CJS_Object* pJSObject); + virtual ~Field(void); + + FX_BOOL alignment(OBJ_PROP_PARAMS); + FX_BOOL borderStyle(OBJ_PROP_PARAMS); + FX_BOOL buttonAlignX(OBJ_PROP_PARAMS); + FX_BOOL buttonAlignY(OBJ_PROP_PARAMS); + FX_BOOL buttonFitBounds(OBJ_PROP_PARAMS); + FX_BOOL buttonPosition(OBJ_PROP_PARAMS); + FX_BOOL buttonScaleHow(OBJ_PROP_PARAMS); + FX_BOOL buttonScaleWhen(OBJ_PROP_PARAMS); + FX_BOOL calcOrderIndex(OBJ_PROP_PARAMS); + FX_BOOL charLimit(OBJ_PROP_PARAMS); + FX_BOOL comb(OBJ_PROP_PARAMS); + FX_BOOL commitOnSelChange(OBJ_PROP_PARAMS); + FX_BOOL currentValueIndices(OBJ_PROP_PARAMS); + FX_BOOL defaultStyle(OBJ_PROP_PARAMS); + FX_BOOL defaultValue(OBJ_PROP_PARAMS); + FX_BOOL doNotScroll(OBJ_PROP_PARAMS); + FX_BOOL doNotSpellCheck(OBJ_PROP_PARAMS); + FX_BOOL delay(OBJ_PROP_PARAMS); + FX_BOOL display(OBJ_PROP_PARAMS); + FX_BOOL doc(OBJ_PROP_PARAMS); + FX_BOOL editable(OBJ_PROP_PARAMS); + FX_BOOL exportValues(OBJ_PROP_PARAMS); + FX_BOOL fileSelect(OBJ_PROP_PARAMS); + FX_BOOL fillColor(OBJ_PROP_PARAMS); + FX_BOOL hidden(OBJ_PROP_PARAMS); + FX_BOOL highlight(OBJ_PROP_PARAMS); + FX_BOOL lineWidth(OBJ_PROP_PARAMS); + FX_BOOL multiline(OBJ_PROP_PARAMS); + FX_BOOL multipleSelection(OBJ_PROP_PARAMS); + FX_BOOL name(OBJ_PROP_PARAMS); + FX_BOOL numItems(OBJ_PROP_PARAMS); + FX_BOOL page(OBJ_PROP_PARAMS); + FX_BOOL password(OBJ_PROP_PARAMS); + FX_BOOL print(OBJ_PROP_PARAMS); + FX_BOOL radiosInUnison(OBJ_PROP_PARAMS); + FX_BOOL readonly(OBJ_PROP_PARAMS); + FX_BOOL rect(OBJ_PROP_PARAMS); + FX_BOOL required(OBJ_PROP_PARAMS); + FX_BOOL richText(OBJ_PROP_PARAMS); + FX_BOOL richValue(OBJ_PROP_PARAMS); + FX_BOOL rotation(OBJ_PROP_PARAMS); + FX_BOOL strokeColor(OBJ_PROP_PARAMS); + FX_BOOL style(OBJ_PROP_PARAMS); + FX_BOOL submitName(OBJ_PROP_PARAMS); + FX_BOOL textColor(OBJ_PROP_PARAMS); + FX_BOOL textFont(OBJ_PROP_PARAMS); + FX_BOOL textSize(OBJ_PROP_PARAMS); + FX_BOOL type(OBJ_PROP_PARAMS); + FX_BOOL userName(OBJ_PROP_PARAMS); + FX_BOOL value(OBJ_PROP_PARAMS); + FX_BOOL valueAsString(OBJ_PROP_PARAMS); + FX_BOOL source(OBJ_PROP_PARAMS); + + FX_BOOL browseForFileToSubmit(OBJ_METHOD_PARAMS); + FX_BOOL buttonGetCaption(OBJ_METHOD_PARAMS); + FX_BOOL buttonGetIcon(OBJ_METHOD_PARAMS); + FX_BOOL buttonImportIcon(OBJ_METHOD_PARAMS); + FX_BOOL buttonSetCaption(OBJ_METHOD_PARAMS); + FX_BOOL buttonSetIcon(OBJ_METHOD_PARAMS); + FX_BOOL checkThisBox(OBJ_METHOD_PARAMS); + FX_BOOL clearItems(OBJ_METHOD_PARAMS); + FX_BOOL defaultIsChecked(OBJ_METHOD_PARAMS); + FX_BOOL deleteItemAt(OBJ_METHOD_PARAMS); + FX_BOOL getArray(OBJ_METHOD_PARAMS); + FX_BOOL getItemAt(OBJ_METHOD_PARAMS); + FX_BOOL getLock(OBJ_METHOD_PARAMS); + FX_BOOL insertItemAt(OBJ_METHOD_PARAMS); + FX_BOOL isBoxChecked(OBJ_METHOD_PARAMS); + FX_BOOL isDefaultChecked(OBJ_METHOD_PARAMS); + FX_BOOL setAction(OBJ_METHOD_PARAMS); + FX_BOOL setFocus(OBJ_METHOD_PARAMS); + FX_BOOL setItems(OBJ_METHOD_PARAMS); + FX_BOOL setLock(OBJ_METHOD_PARAMS); + FX_BOOL signatureGetModifications(OBJ_METHOD_PARAMS); + FX_BOOL signatureGetSeedValue(OBJ_METHOD_PARAMS); + FX_BOOL signatureInfo(OBJ_METHOD_PARAMS); + FX_BOOL signatureSetSeedValue(OBJ_METHOD_PARAMS); + FX_BOOL signatureSign(OBJ_METHOD_PARAMS); + FX_BOOL signatureValidate(OBJ_METHOD_PARAMS); + +public: + static void SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string); + static void SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string); + static void SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_DWordArray& array); + static void SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex); + static void SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string); + static void SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color); + static void SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string); + static void SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect); + static void SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b); + static void SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex); + static void SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color); + static void SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string); + static void SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color); + static void SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string); + static void SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number); + static void SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string); + static void SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CJS_WideStringArray& strArray); + +public: + static void AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType, + const CFX_WideString& sName, const CPDF_Rect& rcCoords); +public: + static void UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, + FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh); + static void UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl, + FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh); + + static CPDFSDK_Widget* GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl); + static void GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldsArray); + + static void DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData); + +public: + FX_BOOL AttachField(Document* pDocument, const CFX_WideString& csFieldName); + void SetDelay(FX_BOOL bDelay); + void SetIsolate(v8::Isolate* isolate) {m_isolate = isolate;} +protected: + void ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo); + void GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldsArray); + CPDF_FormControl* GetSmartFieldControl(CPDF_FormField* pFormField); + FX_BOOL ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel); + + void AddDelay_Int(enum FIELD_PROP prop, FX_INT32 n); + void AddDelay_Bool(enum FIELD_PROP prop,bool b); + void AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string); + void AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string); + void AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect); + void AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color); + void AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array); + void AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array); + + void DoDelay(); +public: + Document* m_pJSDoc; + CPDFSDK_Document* m_pDocument; + CFX_WideString m_FieldName; + int m_nFormControlIndex; + FX_BOOL m_bCanSet; + + FX_BOOL m_bDelay; + v8::Isolate* m_isolate; +}; + +class CJS_Field : public CJS_Object +{ +public: + CJS_Field(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Field(void){}; + + virtual FX_BOOL InitInstance(IFXJS_Context* cc); + + DECLARE_JS_CLASS(CJS_Field); + + 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_METHOD(browseForFileToSubmit, Field); + JS_STATIC_METHOD(buttonGetCaption, Field); + JS_STATIC_METHOD(buttonGetIcon, Field); + JS_STATIC_METHOD(buttonImportIcon, Field); + JS_STATIC_METHOD(buttonSetCaption, Field); + JS_STATIC_METHOD(buttonSetIcon, Field); + JS_STATIC_METHOD(checkThisBox, Field); + JS_STATIC_METHOD(clearItems, Field); + JS_STATIC_METHOD(defaultIsChecked, Field); + JS_STATIC_METHOD(deleteItemAt, Field); + JS_STATIC_METHOD(getArray, Field); + JS_STATIC_METHOD(getItemAt, Field); + JS_STATIC_METHOD(getLock, Field); + JS_STATIC_METHOD(insertItemAt, Field); + JS_STATIC_METHOD(isBoxChecked, Field); + JS_STATIC_METHOD(isDefaultChecked, Field); + JS_STATIC_METHOD(setAction, Field); + JS_STATIC_METHOD(setFocus, Field); + JS_STATIC_METHOD(setItems, Field); + JS_STATIC_METHOD(setLock, Field); + JS_STATIC_METHOD(signatureGetModifications, Field); + JS_STATIC_METHOD(signatureGetSeedValue, Field); + JS_STATIC_METHOD(signatureInfo, Field); + JS_STATIC_METHOD(signatureSetSeedValue, Field); + JS_STATIC_METHOD(signatureSign, Field); + JS_STATIC_METHOD(signatureValidate, Field); +}; + +#endif //_FIELD_H_ + diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h new file mode 100644 index 0000000000..567ee82651 --- /dev/null +++ b/fpdfsdk/include/javascript/IJavaScript.h @@ -0,0 +1,112 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _IJAVASCRIPT_H_ +#define _IJAVASCRIPT_H_ + +class IFXJS_Context +{ +public: + virtual FX_BOOL Compile(const CFX_WideString& script, CFX_WideString& info) = 0; + virtual FX_BOOL RunScript(const CFX_WideString& script, CFX_WideString& info) = 0; + +public: + virtual void OnApp_Init() = 0; + + virtual void OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName) = 0; + virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc) = 0; + virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc) = 0; + virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc) = 0; + virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc) = 0; + virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc) = 0; + + virtual void OnPage_Open(CPDFSDK_Document* pTarget) = 0; + virtual void OnPage_Close(CPDFSDK_Document* pTarget) = 0; + virtual void OnPage_InView(CPDFSDK_Document* pTarget) = 0; + virtual void OnPage_OutView(CPDFSDK_Document* pTarget) = 0; + + virtual void OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0; + virtual void OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0; + virtual void OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0; + virtual void OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0; + virtual void OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value) = 0; + virtual void OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value) = 0; + + virtual void OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc) = 0; + virtual void OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit) = 0; + virtual void OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx, + FX_BOOL KeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart, FX_BOOL bShift, + CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit, + FX_BOOL bFieldFull, FX_BOOL &bRc) = 0; + virtual void OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, + FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc) = 0; + + virtual void OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + virtual void OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0; + + virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0; + virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget) = 0; + + virtual void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString &) = 0; + virtual void OnBatchExec(CPDFSDK_Document* pTarget) = 0; + virtual void OnConsole_Exec() = 0; + virtual void OnExternal_Exec() = 0; + + virtual void EnableMessageBox(FX_BOOL bEnable) = 0; +}; + +class IFXJS_Runtime +{ +public: + virtual IFXJS_Context* NewContext() = 0; + virtual void ReleaseContext(IFXJS_Context * pContext) = 0; + virtual IFXJS_Context* GetCurrentContext() = 0; + + virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0; + virtual CPDFSDK_Document* GetReaderDocument() = 0; + + virtual void GetObjectNames(CFX_WideStringArray& array) = 0; + virtual void GetObjectConsts(const CFX_WideString& swObjName, CFX_WideStringArray& array) = 0; + virtual void GetObjectProps(const CFX_WideString& swObjName, CFX_WideStringArray& array) = 0; + virtual void GetObjectMethods(const CFX_WideString& swObjName, CFX_WideStringArray& array) = 0; + + virtual void Exit() = 0; + virtual void Enter() = 0; + virtual FX_BOOL IsEntered() = 0; +}; + +class CPDFDoc_Environment; +class CJS_GlobalData; + +class CJS_RuntimeFactory +{ +public: + CJS_RuntimeFactory():m_bInit(FALSE),m_nRef(0),m_pGlobalData(NULL),m_nGlobalDataCount(0) {} + ~CJS_RuntimeFactory(); + IFXJS_Runtime* NewJSRuntime(CPDFDoc_Environment* pApp); + void DeleteJSRuntime(IFXJS_Runtime* pRuntime); + void AddRef(); + void Release(); + + CJS_GlobalData* NewGlobalData(CPDFDoc_Environment* pApp); + void ReleaseGlobalData(); +private: + FX_BOOL m_bInit; + int m_nRef; + CJS_GlobalData* m_pGlobalData; + FX_INT32 m_nGlobalDataCount; +}; + +#endif //_IJAVASCRIPT_H_ + diff --git a/fpdfsdk/include/javascript/Icon.h b/fpdfsdk/include/javascript/Icon.h new file mode 100644 index 0000000000..26fec2ddfd --- /dev/null +++ b/fpdfsdk/include/javascript/Icon.h @@ -0,0 +1,42 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _ICON_H_ +#define _ICON_H_ + +class Icon : public CJS_EmbedObj +{ +public: + Icon(CJS_Object* pJSObject); + virtual ~Icon(); + +public: + FX_BOOL name(OBJ_PROP_PARAMS); + +public: + void SetStream(CPDF_Stream* pIconStream); + CPDF_Stream* GetStream(); + void SetIconName(CFX_WideString name); + CFX_WideString GetIconName(); +private: + CPDF_Stream* m_pIconStream; + CFX_WideString m_swIconName; +}; + +class CJS_Icon : public CJS_Object +{ +public: + CJS_Icon(JSFXObject pObject) : CJS_Object(pObject){}; + virtual ~CJS_Icon(){}; + +public: + DECLARE_JS_CLASS(CJS_Icon); + + JS_STATIC_PROP(name, Icon); +}; + +#endif //_ICON_H_ + diff --git a/fpdfsdk/include/javascript/JS_Console.h b/fpdfsdk/include/javascript/JS_Console.h new file mode 100644 index 0000000000..da842bdde7 --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Console.h @@ -0,0 +1,239 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_CONSOLE_H_ +#define _JS_CONSOLE_H_ + +#include "../res/resource.h" + +#define WST_NONE 0x00 // No size changed +#define WST_LEFT 0x01 // size to left +#define WST_TOP 0x02 // size to top +#define WST_RIGHT 0x04 // size to right +#define WST_BOTTOM 0x08 // size to bottom +#define WST_TOPLEFT (WST_TOP|WST_LEFT) // size to top & left +#define WST_TOPRIGHT (WST_TOP|WST_RIGHT) // size to top & right +#define WST_BOTTOMRIGHT (WST_BOTTOM|WST_RIGHT) // size to bottom & right +#define WST_BOTTOMLEFT (WST_BOTTOM|WST_LEFT) // size to bottom & right + +#ifndef IDC_DLGSIZEBOX +#define IDC_DLGSIZEBOX 50 +#endif /* IDC_DLGSIZEBOX */ + +enum { m_idSizeIcon = IDC_DLGSIZEBOX }; +enum { // possible Control reSize Type + CST_NONE = 0, + CST_RESIZE, // NOMOVE + SIZE, add all delta-size of dlg to control + CST_REPOS, // MOVE(absolutely) + NOSIZE, move control's pos by delta-size + CST_RELATIVE, // MOVE(proportional) + NOSIZE, keep control always at a relative pos + CST_ZOOM, // MOVE + SIZE (both are automatically proportional) + CST_DELTA_ZOOM // MOVE(proportional, set manually) + SIZE(proportional, set manuall) +}; + +// contained class to hold item state +// +class CJS_ItemCtrl +{ +public: + UINT m_nID; + UINT m_stxLeft : 4; // when left resizing ... + UINT m_stxRight : 4; // when right resizing ... + UINT m_styTop : 4; // when top resizing ... + UINT m_styBottom : 4; // when bottom resizing ... + UINT m_bFlickerFree : 1; + UINT m_bInvalidate : 1; // Invalidate ctrl's rect(eg. no-automatical update for static when resize+move) + UINT m_r0 : 14; + CRect m_wRect; + double m_xRatio, m_cxRatio; + double m_yRatio, m_cyRatio; + +protected: + void Assign(const CJS_ItemCtrl& src); + +public: + CJS_ItemCtrl(); + CJS_ItemCtrl(const CJS_ItemCtrl& src); + + HDWP OnSize(HDWP hdwp, int sizeType, CRect *pnCltRect, CRect *poCltRect, CRect *pR0, CWnd *pDlg); + + CJS_ItemCtrl& operator=(const CJS_ItemCtrl& src); +}; + +class CJS_ResizeDlg : public CDialog +{ +// DECLARE_DYNAMIC(CJS_ResizeDlg) +public: + CJS_ResizeDlg(UINT nID,CWnd *pParentWnd = NULL); + virtual ~CJS_ResizeDlg(); + + +public: + std::vector m_Items; // array of controlled items + CRect m_cltRect, m_cltR0; + int m_xMin, m_yMin; + int m_xSt, m_ySt; //step? + UINT m_nDelaySide; //drag side of window + CStatic m_wndSizeIcon; // size icon window + +protected: + void AddControl( UINT nID, int xl, int xr, int yt, int yb, int bFlickerFree = 0, + double xRatio = -1.0, double cxRatio = -1.0, + double yRatio = -1.0, double cyRatio = -1.0 ); + void AllowSizing(int xst, int yst); + void HideSizeIcon(void); + virtual BOOL OnInitDialog(); + + void OnSizing(UINT nSide, LPRECT lpRect); + void OnSize(UINT nType, int cx, int cy); + void OnGetMinMaxInfo(MINMAXINFO *pmmi); + BOOL OnEraseBkgnd(CDC* pDC); + +public: + int UpdateControlRect(UINT nID, CRect *pnr); +}; + + +//------------------------CIconListBox for CWndElementList------------------------------------- + +class CIconListBox : public CListBox +{ +public: + CIconListBox(); + virtual ~CIconListBox(); + +public: + int InsertString(int nIndex, LPCWSTR lpszItem , int nImage); + virtual void ResetContent(); + virtual void GetText(int nIndex, CString& rString); + + virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); + void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct); + int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct); + +protected: + // Generated message map functions + //{{AFX_MSG(CIconListBox) + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + +protected: + struct ItemDatas + { + CString csText; + int nImage; + }; +}; +//----------------------------------CWndElementList-------------------------------------------- +#define IDC_LIST_JS_ELEMENT 10070 + +#define ELEMENT_LIST_WIDTH 140 +#define ELEMENT_LIST_HEIGHT 180 +#define ELEMENT_LIST_TOP_OFFSET 13 + +#define ELEMENT_TYPE_NAME 0 +#define ELEMENT_TYPE_CONST 1 +#define ELEMENT_TYPE_FUN 2 +#define ELEMENT_TYPE_PRO 3 + +class CWndElementList : public CWnd +{ +public: + CWndElementList(); + virtual ~CWndElementList(); + +public: + virtual void OnSize(UINT nType, int cx, int cy); + virtual BOOL Create(CWnd* pParentWnd); + virtual BOOL ShowWindow(int nCmdShow); + void RemoveAllElement(); + void SetElementList(LPCWSTR* pElement, int* pType , int iCount); + void AddElement(CFX_WideString csValue , int nType); + BOOL GetElementSel(CString &csElement); + BOOL SelectNext(); + BOOL SelectPrevious(); + BOOL SelectFirst(); + BOOL SelectLast(); + BOOL SelectNextPage(); + BOOL SelectPreviousPage(); + int GetListHeight(); + +protected: + // Generated message map functions + //{{AFX_MSG(CWndElementList) + afx_msg void OnPaint(); + afx_msg BOOL OnNcActivate(BOOL bActive); + afx_msg void OnSelJSElement(); + afx_msg void OnDblclkJSElement(); + afx_msg void OnDestroy(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +protected: + CIconListBox m_ListBox; + BOOL m_bBlock; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// CJS_ConsoleDlg ¶Ô»°¿ò +class CJS_ConsoleDlg : public CJS_ResizeDlg +{ + DECLARE_DYNAMIC(CJS_ConsoleDlg) + +public: + CJS_ConsoleDlg(CReader_App* pApp, CWnd* pParent); + virtual ~CJS_ConsoleDlg(); + + enum { IDD = IDD_JS_CONSOLE }; + + void Create(); + + void AppendConsoleText(const CFX_WideString& swText); + void SetConsoleText(const CFX_WideString& swText); + CFX_WideString GetConsoleText() const; + CFX_WideString GetScriptText() const; + + BOOL ResetElementList(LPCWSTR lpstrRef); + IFXJS_Runtime* GetJSRuntime(); + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV Ö§³Ö + +protected: + virtual BOOL OnInitDialog(); + virtual void OnCancel(); + + virtual BOOL PreTranslateMessage(MSG* pMsg); + +protected: + // Generated message map functions + //{{AFX_MSG(CJS_ConsoleDlg) + afx_msg void OnBnClickedClear(); + afx_msg void OnBnClickedOk(); + afx_msg void OnBnClickTips(); + afx_msg void OnSizing(UINT nSide, LPRECT lpRect); + afx_msg void OnSize(UINT nType, int cx, int cy); + afx_msg void OnGetMinMaxInfo(MINMAXINFO *pmmi); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); + + afx_msg void OnLButtonDown(UINT nFlags, CPoint point); + afx_msg void OnChangeScriptEdit(WPARAM wParam , LPARAM lParam); + afx_msg void OnMove(int x , int y); + public: + virtual int DoModal(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + +public: + CGW_LineNumberEdit m_edtSC; + BOOL m_bTips; + const UINT m_uTextlimited; + FX_HGLOBAL m_hGlobal; + CReader_App * m_pApp; + CWndElementList m_WndElementList; +}; + +#endif //_JS_CONSOLE_H_ \ No newline at end of file diff --git a/fpdfsdk/include/javascript/JS_Context.h b/fpdfsdk/include/javascript/JS_Context.h new file mode 100644 index 0000000000..0e79169d53 --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Context.h @@ -0,0 +1,101 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_CONTEXT_H_ +#define _JS_CONTEXT_H_ + +class CJS_EventHandler; +class CJS_Runtime; + +class CJS_Context : public IFXJS_Context +{ +public: + CJS_Context(CJS_Runtime* pRuntime); + virtual ~CJS_Context(); + +public: + virtual FX_BOOL Compile(const CFX_WideString& script, CFX_WideString& info); + virtual FX_BOOL RunScript(const CFX_WideString& script, CFX_WideString& info); + +public: + virtual void OnApp_Init(); + + virtual void OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName); + virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc); + virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc); + virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc); + virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc); + virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc); + + virtual void OnPage_Open(CPDFSDK_Document* pTarget); + virtual void OnPage_Close(CPDFSDK_Document* pTarget); + virtual void OnPage_InView(CPDFSDK_Document* pTarget); + virtual void OnPage_OutView(CPDFSDK_Document* pTarget); + + virtual void OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + virtual void OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + virtual void OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + virtual void OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + virtual void OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value); + virtual void OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value); + + virtual void OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc); + virtual void OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit); + virtual void OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx, + FX_BOOL bKeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart, FX_BOOL bShift, + CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit, + FX_BOOL bFieldFull, FX_BOOL &bRc); + virtual void OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, + FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc); + + virtual void OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + virtual void OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + + virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark); + virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget); + + virtual void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName); + virtual void OnBatchExec(CPDFSDK_Document* pTarget); + virtual void OnConsole_Exec(); + virtual void OnExternal_Exec(); + + virtual void EnableMessageBox(FX_BOOL bEnable) {m_bMsgBoxEnable = bEnable;} + FX_BOOL IsMsgBoxEnabled() const {return m_bMsgBoxEnable;} + +public: + CPDFDoc_Environment* GetReaderApp(); + CJS_Runtime* GetJSRuntime(){return m_pRuntime;} + + FX_BOOL DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info); + + CJS_EventHandler* GetEventHandler(){return m_pEventHandler;}; + CPDFSDK_Document* GetReaderDocument(); + +private: + CJS_Runtime* m_pRuntime; + CJS_EventHandler* m_pEventHandler; + + FX_BOOL m_bBusy; + FX_BOOL m_bMsgBoxEnable; +}; + +// static CFX_WideString JSGetStringFromID(CJS_Context* pContext, UINT ID) +// { +// ASSERT(pContext != NULL); +// +// return JS_LoadString(pContext->GetReaderApp(), ID); +// } + +#endif //_JS_CONTEXT_H_ + diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h new file mode 100644 index 0000000000..c86289e640 --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -0,0 +1,785 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_DEFINE_H_ +#define _JS_DEFINE_H_ + +typedef v8::Value JSValue; +typedef v8::Handle JSObject; +typedef v8::Handle JSFXObject; +typedef unsigned JSBool; + +struct JSConstSpec +{ + const wchar_t* pName; + double number; + const wchar_t* string; + FX_BYTE t; //0:double 1:str +}; + +struct JSPropertySpec +{ + const wchar_t* pName; + AccessorGetterCallback pPropGet; + AccessorSetterCallback pPropPut; +}; + +struct JSMethodSpec +{ + const wchar_t* pName; + FunctionCallback pMethodCall; + unsigned nParamNum; +}; + +typedef CFX_WideString JS_ErrorString; + +#define JS_TRUE (unsigned)1 +#define JS_FALSE (unsigned)0 + + +#define CJS_PointsArray CFX_ArrayTemplate +#define CJS_IntArray CFX_ArrayTemplate + +/* ====================================== PUBLIC DEFINE SPEC ============================================== */ +#ifndef __GNUC__ +#define JS_WIDESTRING(widestring) L#widestring +#else +#define JS_WIDESTRING(widestring) L""#widestring +#endif + +#define OBJ_PROP_PARAMS IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError +#define OBJ_METHOD_PARAMS IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError +#define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class_Consts[] = { +#define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_name), pValue, L"", 0}, +#define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_name), 0, JS_WIDESTRING(pValue), 1}, +#define END_JS_STATIC_CONST() {0, 0, 0, 0}}; + +#define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Class_Properties[] = { +#define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_name##_static, set_##prop_name##_static}, +#define END_JS_STATIC_PROP() {0, 0, 0}}; + +#define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Class_Methods[] = { +#define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name), method_name##_static, nargs}, +#define END_JS_STATIC_METHOD() {0, 0, 0}}; +#define MEMLEAKCHECK_1() ((void)0) +#define MEMLEAKCHECK_2(main_name, sub_name) ((void)0) + + +/* +#ifdef _DEBUG +#define MEMLEAKCHECK_1() \ + _CrtMemState state1;\ + _CrtMemCheckpoint(&state1); + +#define MEMLEAKCHECK_2(main_name,sub_name) \ + _CrtMemState state2;\ + _CrtMemCheckpoint(&state2);\ + _CrtMemState diff;\ + _CrtMemDifference(&diff,&state1,&state2);\ + if (diff.lSizes[_NORMAL_BLOCK] > 0)\ + {\ + TRACE("Detected normal block memory leaks in JS Module! [%s.%s]\n",#main_name,#sub_name);\ + _CrtMemDumpStatistics(&diff);\ + } +#else + #define MEMLEAKCHECK_1() ((void)0) + #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0) +#endif +*/ + +/* ======================================== PROP CALLBACK ============================================ */ + +#define JS_STATIC_PROP_GET(prop_name, class_name)\ + static void get_##prop_name##_static(JS_PROPGET_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + CJS_PropValue value(isolate);\ + value.StartGetting();\ + CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ + ASSERT(pJSObj != NULL);\ + class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->prop_name(cc, value, sError);\ + MEMLEAKCHECK_2(class_name, prop_name);\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #prop_name);\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), L"Unknown error is catched!");\ + return ;\ + }\ + if (bRet)\ + {\ + info.GetReturnValue().Set((v8::Handle)value);\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #prop_name);\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ + return ;\ + }\ +} + +#define JS_STATIC_PROP_SET(prop_name, class_name)\ + static void set_##prop_name##_static(JS_PROPPUT_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ + propValue.StartSetting();\ + CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ + ASSERT(pJSObj != NULL);\ + class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->prop_name(cc, propValue, sError);\ + MEMLEAKCHECK_2(class_name, prop_name);\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #prop_name);\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), L"Unknown error is catched!");\ + return ;\ + }\ + if (bRet)\ + {\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #prop_name);\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ + return ;\ + }\ +} + +#define JS_STATIC_PROP(prop_name, class_name)\ +JS_STATIC_PROP_GET(prop_name, class_name);\ +JS_STATIC_PROP_SET(prop_name, class_name) + +/* ========================================= METHOD CALLBACK =========================================== */ + +#define JS_STATIC_METHOD(method_name, class_name)\ + static void method_name##_static(JS_METHOD_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + CJS_Parameters parameters;\ + for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ + {\ + parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ + }\ + CJS_Value valueRes(isolate);\ + CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder());\ + ASSERT(pJSObj != NULL);\ + class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->method_name(cc, parameters, valueRes, sError);\ + MEMLEAKCHECK_2(class_name, method_name);\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #method_name);\ + JS_Error(NULL, CFX_WideString::FromLocal(cbName), L"Unknown error is catched!");\ + return ;\ + }\ + if (bRet)\ + {\ + info.GetReturnValue().Set(valueRes.ToJSValue());\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #method_name);\ + JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ + return ;\ + }\ +} + +/* ===================================== JS CLASS =============================================== */ + +#define DECLARE_JS_CLASS(js_class_name) \ + static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ + static JSBool JSDestructor(JSFXObject obj);\ + static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ + static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ + static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ + static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ + static JSConstSpec JS_Class_Consts[];\ + static JSPropertySpec JS_Class_Properties[];\ + static JSMethodSpec JS_Class_Methods[];\ + static const wchar_t* m_pClassName + +#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ +const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ +JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObject global)\ +{\ + CJS_Object* pObj = FX_NEW js_class_name(obj);\ + pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\ + JS_SetPrivate(NULL,obj,(void*)pObj); \ + pObj->InitInstance(cc);\ + return JS_TRUE;\ +}\ +\ +JSBool js_class_name::JSDestructor(JSFXObject obj) \ +{\ + js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ + ASSERT(pObj != NULL);\ + pObj->ExitInstance();\ + delete pObj;\ + return JS_TRUE;\ +}\ +\ +int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ +{\ + int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eObjType, JSConstructor, JSDestructor, 0);\ + if (nObjDefnID >= 0)\ + {\ + for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1; j=0)\ + {\ + for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1; iGetEmbedObject();\ + ASSERT(pObj != NULL);\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->QueryProperty((FX_LPCWSTR)propname);\ + MEMLEAKCHECK_2(class_name, (FX_LPCWSTR)prop_name);\ + }\ + catch (...)\ + {\ + return ;\ + }\ + if (bRet)\ + {\ + info.GetReturnValue().Set(0x004);\ + return ;\ + }\ + else\ + {\ + info.GetReturnValue().Set(0);\ + return ;\ + }\ + return ;\ +}\ + void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + v8::String::Utf8Value utf8_value(property);\ + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ + CJS_PropValue value(isolate);\ + value.StartGetting();\ + CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ + ASSERT(pJSObj != NULL);\ + class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->DoProperty(cc, (FX_LPCWSTR)propname, value, sError);\ + MEMLEAKCHECK_2(class_name, L"GetProperty");\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, L"GetProperty");\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), L"Unknown error is catched!");\ + return ;\ + }\ + if (bRet)\ + {\ + info.GetReturnValue().Set((v8::Handle)value);\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, L"GetProperty");\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ + return ;\ + }\ + JS_Error(NULL,L"GetProperty", L"Embeded object not found!");\ + return ;\ +}\ + void js_class_name::putprop_##js_class_name##_static(JS_NAMED_PROPPUT_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + v8::String::Utf8Value utf8_value(property);\ + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ + CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ + PropValue.StartSetting();\ + CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ + if(!pJSObj) return;\ + class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->DoProperty(cc, (FX_LPCWSTR)propname, PropValue, sError);\ + MEMLEAKCHECK_2(class_name,L"PutProperty");\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, "PutProperty");\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), L"Unknown error is catched!");\ + return ;\ + }\ + if (bRet)\ + {\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, "PutProperty");\ + JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ + return ;\ + }\ + JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ + return ;\ +}\ + void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + v8::String::Utf8Value utf8_value(property);\ + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ + CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ + ASSERT(pJSObj != NULL);\ + class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->DelProperty(cc, (FX_LPCWSTR)propname, sError);\ + MEMLEAKCHECK_2(class_name,L"DelProperty");\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, "DelProperty");\ + return ;\ + }\ + if (bRet)\ + {\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, "DelProperty");\ + return ;\ + }\ + return ;\ +}\ +JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global)\ +{\ + CJS_Object* pObj = FX_NEW js_class_name(obj);\ + pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\ + JS_SetPrivate(NULL,obj, (void*)pObj); \ + pObj->InitInstance(cc);\ + return JS_TRUE;\ +}\ +\ +JSBool js_class_name::JSDestructor(JSFXObject obj) \ +{\ + js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ + ASSERT(pObj != NULL);\ + pObj->ExitInstance();\ + delete pObj;\ + return JS_TRUE;\ +}\ +\ +int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ +{\ +\ + int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eObjType, JSConstructor, JSDestructor, 0);\ +\ + if (nObjDefnID >= 0)\ + {\ + for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1; j context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + CJS_Parameters parameters;\ + for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ + {\ + parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ + }\ + CJS_Value valueRes(isolate);\ + CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate, info.Holder());\ + ASSERT(pJSObj != NULL);\ + class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ + ASSERT(pObj != NULL);\ + JS_ErrorString sError;\ + FX_BOOL bRet = FALSE;\ + try\ + {\ + MEMLEAKCHECK_1();\ + bRet = pObj->method_name(cc, parameters, valueRes, sError);\ + MEMLEAKCHECK_2(class_name, method_name);\ + }\ + catch (...)\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #method_name);\ + JS_Error(NULL, CFX_WideString::FromLocal(cbName), L"Unknown error is catched!");\ + return ;\ + }\ + if (bRet)\ + {\ + info.GetReturnValue().Set(valueRes.ToJSValue());\ + return ;\ + }\ + else\ + {\ + CFX_ByteString cbName;\ + cbName.Format("%s.%s", #class_name, #method_name);\ + JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ + return ;\ + }\ + JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!");\ + return ;\ +} + +/* ======================================== GLOBAL METHODS ============================================ */ +#define JS_STATIC_GLOBAL_FUN(fun_name) \ +static void fun_name##_static(JS_METHOD_ARGS)\ +{\ + v8::Isolate* isolate = info.GetIsolate();\ + v8::Local context = isolate->GetCurrentContext();\ + v8::Local v = context->GetEmbedderData(1);\ + ASSERT(!v.IsEmpty());\ + if(v.IsEmpty()) return;\ + v8::Handle field = v8::Handle::Cast(v);\ + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ + IFXJS_Context* cc = pRuntime->GetCurrentContext();\ + CJS_Parameters parameters;\ + for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ + {\ + parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ + }\ + CJS_Value valueRes(isolate);\ + JS_ErrorString sError;\ + if (!fun_name(cc, parameters, valueRes, sError))\ + {\ + JS_Error(NULL, JS_WIDESTRING(fun_name), sError);\ + return ;\ + }\ + info.GetReturnValue().Set(valueRes.ToJSValue());\ + return ;\ +} + +#define JS_STATIC_DECLARE_GLOBAL_FUN() \ +static JSMethodSpec global_methods[]; \ +static int Init(IJS_Runtime* pRuntime) + +#define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ +JSMethodSpec js_class_name::global_methods[] = { + +#define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(method_name,nargs) + +#define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() + +#define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ +int js_class_name::Init(IJS_Runtime* pRuntime)\ +{\ + for (int i=0, sz=sizeof(js_class_name::global_methods)/sizeof(JSMethodSpec)-1; i p) +{ + + const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p)); + + if (nHash == JSCONST_nUndefHash) + return VT_undefined; + else if (nHash == JSCONST_nNullHash) + return VT_null; + else if (nHash == JSCONST_nStringHash) + return VT_string; + else if (nHash == JSCONST_nNumberHash) + return VT_number; + else if (nHash == JSCONST_nBoolHash) + return VT_boolean; + else if (nHash == JSCONST_nDateHash) + return VT_date; + else if (nHash == JSCONST_nObjectHash) + return VT_object; + else if (nHash == JSCONST_nFXobjHash) + return VT_fxobject; + + /* + const char * sType = p->getTypeof()->toDchars(); + if (strcmp(sType,VALUE_NAME_STRING) == 0) + return VT_string; + else if (strcmp(sType,VALUE_NAME_NUMBER) == 0) + return VT_number; + else if (strcmp(sType,VALUE_NAME_BOOLEAN) == 0) + return VT_boolean; + else if (strcmp(sType,VALUE_NAME_DATE) == 0) + return VT_date; + else if (strcmp(sType,VALUE_NAME_OBJECT) == 0) + return VT_object; + else if (strcmp(sType,VALUE_NAME_FXOBJ) == 0) + return VT_object; + else if (strcmp(sType,VALUE_NAME_NULL) == 0) + return VT_null; + else if (strcmp(sType,VALUE_NAME_UNDEFINED) == 0) + return VT_undefined; + */ + + return VT_unknown; +} + +#endif //_JS_DEFINE_H_ diff --git a/fpdfsdk/include/javascript/JS_EventHandler.h b/fpdfsdk/include/javascript/JS_EventHandler.h new file mode 100644 index 0000000000..d88c50c06b --- /dev/null +++ b/fpdfsdk/include/javascript/JS_EventHandler.h @@ -0,0 +1,167 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_EVENTHANDLER_H_ +#define _JS_EVENTHANDLER_H_ + +class CJS_Context; +class Field; + +enum JS_EVENT_T +{ + JET_UNKNOWN, + JET_APP_INIT, + JET_DOC_OPEN, + JET_DOC_WILLPRINT, + JET_DOC_DIDPRINT, + JET_DOC_WILLSAVE, + JET_DOC_DIDSAVE, + JET_DOC_WILLCLOSE, + JET_PAGE_OPEN, + JET_PAGE_CLOSE, + JET_PAGE_INVIEW, + JET_PAGE_OUTVIEW, + JET_FIELD_MOUSEDOWN, + JET_FIELD_MOUSEUP, + JET_FIELD_MOUSEENTER, + JET_FIELD_MOUSEEXIT, + JET_FIELD_FOCUS, + JET_FIELD_BLUR, + JET_FIELD_KEYSTROKE, + JET_FIELD_VALIDATE, + JET_FIELD_CALCULATE, + JET_FIELD_FORMAT, + JET_SCREEN_FOCUS, + JET_SCREEN_BLUR, + JET_SCREEN_OPEN, + JET_SCREEN_CLOSE, + JET_SCREEN_MOUSEDOWN, + JET_SCREEN_MOUSEUP, + JET_SCREEN_MOUSEENTER, + JET_SCREEN_MOUSEEXIT, + JET_SCREEN_INVIEW, + JET_SCREEN_OUTVIEW, + JET_BATCH_EXEC, + JET_MENU_EXEC, + JET_CONSOLE_EXEC, + JET_EXTERNAL_EXEC, + JET_BOOKMARK_MOUSEUP, + JET_LINK_MOUSEUP +}; + +class CJS_EventHandler +{ +public: + CJS_EventHandler(CJS_Context * pContext); + virtual ~CJS_EventHandler(); + + void OnApp_Init(); + + void OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName); + void OnDoc_WillPrint(CPDFSDK_Document* pDoc); + void OnDoc_DidPrint(CPDFSDK_Document* pDoc); + void OnDoc_WillSave(CPDFSDK_Document* pDoc); + void OnDoc_DidSave(CPDFSDK_Document* pDoc); + void OnDoc_WillClose(CPDFSDK_Document* pDoc); + + void OnPage_Open(CPDFSDK_Document* pDoc); + void OnPage_Close(CPDFSDK_Document* pDoc); + void OnPage_InView(CPDFSDK_Document* pTarget); + void OnPage_OutView(CPDFSDK_Document* pTarget); + + void OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc); + void OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit); + void OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx, + FX_BOOL KeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart, FX_BOOL bShift, + CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit, + FX_BOOL bFieldFull, FX_BOOL &bRc); + void OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, + FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc); + + void OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + void OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + void OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + void OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); + void OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value); + void OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value); + + void OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + void OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); + + void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark); + void OnLink_MouseUp(CPDFSDK_Document* pTarget); + + void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName); + void OnBatchExec(CPDFSDK_Document *pTarget); + void OnConsole_Exec(); + void OnExternal_Exec(); + +public: + void Initial(JS_EVENT_T type); + void Destroy(); + FX_BOOL IsValid(); + + + CFX_WideString& Change(); + CFX_WideString ChangeEx(); + int CommitKey(); + FX_BOOL FieldFull(); + FX_BOOL KeyDown(); + FX_BOOL Modifier(); + FX_LPCWSTR Name(); + FX_LPCWSTR Type(); + FX_BOOL& Rc(); + int& SelEnd(); + int& SelStart(); + FX_BOOL Shift(); + Field* Source(); + Field* Target_Field(); + CFX_WideString& Value(); + FX_BOOL WillCommit(); + CFX_WideString TargetName(); + + JS_EVENT_T EventType() {return m_eEventType;}; + +public: + CJS_Context* m_pJSContext; + JS_EVENT_T m_eEventType; + FX_BOOL m_bValid; + + CFX_WideString m_strTargetName; + CFX_WideString m_strSourceName; + CFX_WideString* m_pWideStrChange; + CFX_WideString m_WideStrChangeDu; + CFX_WideString m_WideStrChangeEx; + int m_nCommitKey; + FX_BOOL m_bKeyDown; + FX_BOOL m_bModifier; + FX_BOOL m_bShift; + int* m_pISelEnd; + int m_nSelEndDu; + int* m_pISelStart; + int m_nSelStartDu; + FX_BOOL m_bWillCommit; + CFX_WideString* m_pValue; + FX_BOOL m_bFieldFull; + FX_BOOL* m_pbRc; + FX_BOOL m_bRcDu; + + CPDFSDK_Document* m_pSourceDoc; + CPDF_Bookmark* m_pTargetBookMark; + CPDFSDK_Document* m_pTargetDoc; + CPDFSDK_Annot* m_pTargetAnnot; +}; + +#endif //_JS_EVENTHANDLER_H_ + diff --git a/fpdfsdk/include/javascript/JS_GlobalData.h b/fpdfsdk/include/javascript/JS_GlobalData.h new file mode 100644 index 0000000000..97a54024d0 --- /dev/null +++ b/fpdfsdk/include/javascript/JS_GlobalData.h @@ -0,0 +1,97 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_GLOBALDATA_H_ +#define _JS_GLOBALDATA_H_ + +#define JS_GLOBALDATA_TYPE_NUMBER 0 +#define JS_GLOBALDATA_TYPE_BOOLEAN 1 +#define JS_GLOBALDATA_TYPE_STRING 2 +#define JS_GLOBALDATA_TYPE_OBJECT 3 +#define JS_GLOBALDATA_TYPE_NULL 4 + +class CJS_KeyValue; +class CJS_GlobalVariableArray; +class CJS_GlobalData_Element; + +class CJS_GlobalVariableArray +{ +public: + CJS_GlobalVariableArray(); + virtual ~CJS_GlobalVariableArray(); + + void Add(CJS_KeyValue* p); + int Count() const; + CJS_KeyValue* GetAt(int index) const; + void Copy(const CJS_GlobalVariableArray& array); + + void Empty(); + +private: + CFX_ArrayTemplate array; +}; + +class CJS_KeyValue +{ +public: + CJS_KeyValue(){} + virtual ~CJS_KeyValue(){} + + CFX_ByteString sKey; + int nType; //0:int 1:bool 2:string 3:obj + double dData; + bool bData; + CFX_ByteString sData; + CJS_GlobalVariableArray objData; +}; + +class CJS_GlobalData_Element +{ +public: + CJS_GlobalData_Element(){} + virtual ~CJS_GlobalData_Element(){} + + CJS_KeyValue data; + FX_BOOL bPersistent; +}; + +class CJS_GlobalData +{ +public: + CJS_GlobalData(CPDFDoc_Environment* pApp); + virtual ~CJS_GlobalData(); + +public: + void SetGlobalVariableNumber(FX_LPCSTR propname, double dData); + void SetGlobalVariableBoolean(FX_LPCSTR propname, bool bData); + void SetGlobalVariableString(FX_LPCSTR propname, const CFX_ByteString& sData); + void SetGlobalVariableObject(FX_LPCSTR propname, const CJS_GlobalVariableArray& array); + void SetGlobalVariableNull(FX_LPCSTR propname); + + FX_BOOL SetGlobalVariablePersistent(FX_LPCSTR propname, FX_BOOL bPersistent); + FX_BOOL DeleteGlobalVariable(FX_LPCSTR propname); + + FX_INT32 GetSize() const; + CJS_GlobalData_Element* GetAt(int index) const; + +private: + void LoadGlobalPersistentVariables(); + void SaveGlobalPersisitentVariables(); + + CJS_GlobalData_Element* GetGlobalVariable(FX_LPCSTR propname); + int FindGlobalVariable(FX_LPCSTR propname); + + void LoadFileBuffer(FX_LPCWSTR sFilePath, FX_LPBYTE& pBuffer, FX_INT32& nLength); + void WriteFileBuffer(FX_LPCWSTR sFilePath, FX_LPCSTR pBuffer, FX_INT32 nLength); + void MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData); + +private: + CFX_ArrayTemplate m_arrayGlobalData; + CFX_WideString m_sFilePath; + CPDFDoc_Environment* m_pApp; +}; + +#endif //_JS_GLOBALDATA_H_ diff --git a/fpdfsdk/include/javascript/JS_Module.h b/fpdfsdk/include/javascript/JS_Module.h new file mode 100644 index 0000000000..d725f6bc17 --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Module.h @@ -0,0 +1,47 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_MODULE_H_ +#define _JS_MODULE_H_ + +class CJS_GlobalData; +class CJS_ConsoleDlg; + +class CJS_Module : public IReader_Module +{ +public: + CJS_Module(HMODULE hModule, CReader_App* pApp); + virtual ~CJS_Module(); + + virtual void Destroy(){delete this;} + virtual CFX_ByteString GetModuleName(); + +public: + static CJS_Module* GetModule(CReader_App* pApp); + + IFXJS_Runtime* NewJSRuntime(); + CJS_GlobalData* NewGlobalData(); + void ReleaseGlobalData(); + +public: + //console + void ShowConsole(); + void HideConsole(); + void ClearConsole(); + void PrintLineConsole(FX_LPCWSTR string); + +private: + HMODULE m_hModule; + CReader_App* m_pApp; + + FX_BOOL m_bInitial; + CJS_GlobalData* m_pGlobalData; + FX_INT32 m_nGlobalDataCount; + + CJS_ConsoleDlg* m_pConsole; +}; + +#endif //_JS_MODULE_H_ \ No newline at end of file diff --git a/fpdfsdk/include/javascript/JS_Object.h b/fpdfsdk/include/javascript/JS_Object.h new file mode 100644 index 0000000000..8b91f8cd0d --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Object.h @@ -0,0 +1,288 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_OBJECT_H_ +#define _JS_OBJECT_H_ + +class CJS_Object; +class CJS_Timer; +class CJS_Context; + +class CJS_EmbedObj : public CFX_Object +{ +public: + CJS_EmbedObj(CJS_Object* pJSObject); + virtual ~CJS_EmbedObj(); + + virtual void TimerProc(CJS_Timer* pTimer){}; + + CJS_Timer* BeginTimer(CPDFDoc_Environment * pApp, FX_UINT nElapse); + void EndTimer(CJS_Timer* pTimer); + + CJS_Object* GetJSObject(){return m_pJSObject;}; + operator CJS_Object* (){return m_pJSObject;}; + + CPDFSDK_PageView * JSGetPageView(IFXJS_Context* cc); + int MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle = NULL, FX_UINT nType = 0, FX_UINT nIcon = 0); + void Alert(CJS_Context* pContext, FX_LPCWSTR swMsg); + FX_BOOL IsSafeMode(IFXJS_Context* cc); + +protected: + + CJS_Object* m_pJSObject; +}; + +class CJS_Object : public CFX_Object +{ +public: + CJS_Object(JSFXObject pObject); + virtual ~CJS_Object(void); + + void MakeWeak(); + + virtual FX_BOOL IsType(FX_LPCSTR sClassName){return TRUE;}; + virtual CFX_ByteString GetClassName(){return "";}; + + virtual FX_BOOL InitInstance(IFXJS_Context* cc){return TRUE;}; + virtual FX_BOOL ExitInstance(){return TRUE;}; + + operator JSFXObject () {return v8::Local::New(m_pIsolate, m_pObject);} + operator CJS_EmbedObj* (){return m_pEmbedObj;}; + + void SetEmbedObject(CJS_EmbedObj* pObj){m_pEmbedObj = pObj;}; + CJS_EmbedObj * GetEmbedObject(){return m_pEmbedObj;}; + + static CPDFSDK_PageView * JSGetPageView(IFXJS_Context* cc); + static int MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle = NULL, FX_UINT nType = 0,FX_UINT nIcon = 0); + static void Alert(CJS_Context* pContext, FX_LPCWSTR swMsg); + + v8::Isolate* GetIsolate() {return m_pIsolate;} +protected: + CJS_EmbedObj * m_pEmbedObj; + v8::Persistent m_pObject; + v8::Isolate* m_pIsolate; +}; + +struct JS_TIMER_MAP +{ + FX_UINT nID; + CJS_Timer * pTimer; +}; + +typedef CFX_ArrayTemplate CTimerMapArray; + +struct JS_TIMER_MAPARRAY +{ +public: + JS_TIMER_MAPARRAY() + { + } + + ~JS_TIMER_MAPARRAY() + { + Reset(); + } + + void Reset() + { + for (int i=0,sz=m_Array.GetSize(); i=0) + { + if (JS_TIMER_MAP * pMap = m_Array.GetAt(i)) + pMap->pTimer = pTimer; + } + else + { + if (JS_TIMER_MAP * pMap = new JS_TIMER_MAP) + { + pMap->nID = nIndex; + pMap->pTimer = pTimer; + m_Array.Add(pMap); + } + } + } + + CJS_Timer * GetAt(FX_UINT nIndex) + { + int i = Find(nIndex); + + if (i>=0) + { + if (JS_TIMER_MAP * pMap = m_Array.GetAt(i)) + return pMap->pTimer; + } + return NULL; + } + + void RemoveAt(FX_UINT nIndex) + { + int i = Find(nIndex); + + if (i>=0) + { + delete m_Array.GetAt(i); + m_Array.RemoveAt(i); + } + //To prevent potential fake memory leak reported by vc6. + if(m_Array.GetSize() == 0) + m_Array.RemoveAll(); + } + + int Find(FX_UINT nIndex) + { + for (int i=0,sz=m_Array.GetSize(); inID == nIndex) + return i; + } + } + + return -1; + } + + CTimerMapArray m_Array; +}; + +static JS_TIMER_MAPARRAY m_sTimeMap; + +class CJS_Runtime; + +class CJS_Timer +{ +public: + CJS_Timer(CJS_EmbedObj * pObj,CPDFDoc_Environment* pApp): m_pEmbedObj(pObj), + m_nTimerID(0), + m_bProcessing(FALSE), + m_dwStartTime(0), + m_dwTimeOut(0), + m_dwElapse(0), + m_pRuntime(NULL), + m_nType(0), + m_pApp(pApp) + { + } + + virtual ~CJS_Timer() + { + KillJSTimer(); + } + +public: + FX_UINT SetJSTimer(FX_UINT nElapse) + { + if (m_nTimerID)KillJSTimer(); + IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); + m_nTimerID = pHandler->SetTimer(nElapse,TimerProc); + m_sTimeMap.SetAt(m_nTimerID,this); + m_dwElapse = nElapse; + return m_nTimerID; + }; + + void KillJSTimer() + { + if (m_nTimerID) + { + IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); + pHandler->KillTimer(m_nTimerID); + m_sTimeMap.RemoveAt(m_nTimerID); + m_nTimerID = 0; + } + }; + + void SetType(int nType) + { + m_nType = nType; + } + + int GetType() const + { + return m_nType; + } + + void SetStartTime(FX_DWORD dwStartTime) + { + m_dwStartTime = dwStartTime; + } + + FX_DWORD GetStartTime() const + { + return m_dwStartTime; + } + + void SetTimeOut(FX_DWORD dwTimeOut) + { + m_dwTimeOut = dwTimeOut; + } + + FX_DWORD GetTimeOut() const + { + return m_dwTimeOut; + } + + void SetRuntime(CJS_Runtime* pRuntime) + { + m_pRuntime = pRuntime; + } + + CJS_Runtime* GetRuntime() const + { + return m_pRuntime; + } + + void SetJScript(const CFX_WideString& script) + { + m_swJScript = script; + } + + CFX_WideString GetJScript() const + { + return m_swJScript; + } + + static void TimerProc(int idEvent) + { + if (CJS_Timer * pTimer = m_sTimeMap.GetAt(idEvent)) + { + if (!pTimer->m_bProcessing) + { + pTimer->m_bProcessing = TRUE; + if (pTimer->m_pEmbedObj) pTimer->m_pEmbedObj->TimerProc(pTimer); + pTimer->m_bProcessing = FALSE; + } + else + { + // TRACE(L"BUSY!\n"); + } + } + }; + +private: + FX_UINT m_nTimerID; + CJS_EmbedObj* m_pEmbedObj; + FX_BOOL m_bProcessing; + + //data + FX_DWORD m_dwStartTime; + FX_DWORD m_dwTimeOut; + FX_DWORD m_dwElapse; + CJS_Runtime* m_pRuntime; + CFX_WideString m_swJScript; + int m_nType; //0:Interval; 1:TimeOut + + CPDFDoc_Environment* m_pApp; +}; +#endif //_JS_OBJECT_H_ diff --git a/fpdfsdk/include/javascript/JS_Runtime.h b/fpdfsdk/include/javascript/JS_Runtime.h new file mode 100644 index 0000000000..32f845755f --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Runtime.h @@ -0,0 +1,70 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_RUNTIME_H_ +#define _JS_RUNTIME_H_ + +class CJS_FieldEvent +{ +public: + CFX_WideString sTargetName; + JS_EVENT_T eEventType; + CJS_FieldEvent* pNext; +}; + +class CJS_Runtime : public IFXJS_Runtime +{ +public: + CJS_Runtime(CPDFDoc_Environment * pApp); + virtual ~CJS_Runtime(); + + virtual IFXJS_Context * NewContext(); + virtual void ReleaseContext(IFXJS_Context * pContext); + virtual IFXJS_Context* GetCurrentContext(); + + virtual void SetReaderDocument(CPDFSDK_Document *pReaderDoc); + virtual CPDFSDK_Document * GetReaderDocument(){return m_pDocument;} + + virtual void GetObjectNames(CFX_WideStringArray& array); + virtual void GetObjectConsts(const CFX_WideString& swObjName, CFX_WideStringArray& array); + virtual void GetObjectProps(const CFX_WideString& swObjName, CFX_WideStringArray& array); + virtual void GetObjectMethods(const CFX_WideString& swObjName, CFX_WideStringArray& array); + + virtual void Exit(); + virtual void Enter(); + virtual FX_BOOL IsEntered(); + + CPDFDoc_Environment * GetReaderApp(){return m_pApp;} + + FX_BOOL InitJSObjects(); + + FX_BOOL AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType); + void RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType); + void RemoveEventsInLoop(CJS_FieldEvent* pStart); + + void BeginBlock(){m_bBlocking = TRUE;} + void EndBlock(){m_bBlocking = FALSE;} + FX_BOOL IsBlocking(){return m_bBlocking;} + + operator IJS_Runtime*() {return (IJS_Runtime*)m_isolate;} + v8::Isolate* GetIsolate(){return m_isolate;}; + void SetIsolate(v8::Isolate* isolate){m_isolate = isolate;} + + v8::Handle NewJSContext(); +protected: + CFX_ArrayTemplate m_ContextArray; + CPDFDoc_Environment * m_pApp; + CPDFSDK_Document * m_pDocument; + FX_BOOL m_bBlocking; + CJS_FieldEvent* m_pFieldEventPath; + + v8::Isolate* m_isolate; + v8::Persistent m_context; + FX_BOOL m_bRegistered; +}; + +#endif //_JS_RUNTIME_H_ + diff --git a/fpdfsdk/include/javascript/JS_Value.h b/fpdfsdk/include/javascript/JS_Value.h new file mode 100644 index 0000000000..f87f9e1d43 --- /dev/null +++ b/fpdfsdk/include/javascript/JS_Value.h @@ -0,0 +1,186 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JS_VALUE_H_ +#define _JS_VALUE_H_ + +class CJS_Array; +class CJS_Date; + +class CJS_Value +{ +public: + CJS_Value(v8::Isolate* isolate); + CJS_Value(v8::Isolate* isolate, v8::Handle pValue,FXJSVALUETYPE t); + CJS_Value(v8::Isolate* isolate, const int &iValue); + CJS_Value(v8::Isolate* isolate, const double &dValue); + CJS_Value(v8::Isolate* isolate, const float &fValue); + CJS_Value(v8::Isolate* isolate, const bool &bValue); + CJS_Value(v8::Isolate* isolate, JSFXObject); + CJS_Value(v8::Isolate* isolate, CJS_Object *); + CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr); + CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr); + CJS_Value(v8::Isolate* isolate, CJS_Array& array); + + ~CJS_Value(); + + void SetNull(); + void Attach(v8::Handle pValue,FXJSVALUETYPE t); + void Attach(CJS_Value *pValue); + void Detach(); + + + operator int() const; + operator bool() const; + operator double() const; + operator float() const; + operator CJS_Object *() const; + //operator JSFXObject *() const; + operator v8::Handle() const; + operator v8::Handle() const; + operator CFX_WideString() const; + //operator FX_WCHAR *() const; + operator CFX_ByteString() const; + v8::Handle ToJSValue(); + + void operator = (int iValue); + void operator = (bool bValue); + void operator = (double); + void operator = (float); + void operator = (CJS_Object *); + void operator = (v8::Handle); +// void operator = (JSObject *); + void operator = (CJS_Array &); + void operator = (CJS_Date &); + void operator = (FX_LPCWSTR pWstr); + void operator = (FX_LPCSTR pStr); + void operator = (CJS_Value value); + + FX_BOOL IsArrayObject() const; + FX_BOOL IsDateObject() const; + FXJSVALUETYPE GetType() const; + + FX_BOOL ConvertToArray(CJS_Array &) const; + FX_BOOL ConvertToDate(CJS_Date &) const; + + v8::Isolate* GetIsolate() {return m_isolate;} +protected: + v8::Handle m_pValue; + FXJSVALUETYPE m_eType; + v8::Isolate* m_isolate; +}; + +template class CJS_ParametersTmpl : public CFX_ArrayTemplate +{ +public: + void push_back(TYPE newElement){CFX_ArrayTemplate::Add(newElement);} + int size() const{return CFX_ArrayTemplate::GetSize();} +}; +typedef CJS_ParametersTmpl CJS_Parameters; + +class CJS_PropValue: public CJS_Value +{ +public: + CJS_PropValue(const CJS_Value &); + CJS_PropValue(v8::Isolate* isolate); + ~CJS_PropValue(); +public: + FX_BOOL IsSetting(); + FX_BOOL IsGetting(); + void operator<<(int ); + void operator>>(int &) const; + void operator<<(bool); + void operator>>(bool &) const; + void operator<<(double ); + void operator>>(double &) const; + void operator<<(CJS_Object *pObj); + void operator>>(CJS_Object *&ppObj) const; + void operator<<(CFX_ByteString); + void operator>>(CFX_ByteString &) const; + void operator<<(CFX_WideString); + void operator>>(CFX_WideString &) const; + void operator<<(FX_LPCWSTR c_string); + + void operator<<(JSFXObject); + void operator>>(JSFXObject &) const; + + void operator>>(CJS_Array &array) const; + void operator<<(CJS_Array &array); + + void operator<<(CJS_Date &date); + void operator>>(CJS_Date &date) const; + + operator v8::Handle() const; + + void StartSetting(); + void StartGetting(); +private: + FX_BOOL m_bIsSetting; +}; + +class CJS_Array +{ +public: + CJS_Array(v8::Isolate* isolate); + virtual ~CJS_Array(); + + void Attach(v8::Handle pArray); + void GetElement(unsigned index,CJS_Value &value); + void SetElement(unsigned index,CJS_Value value); + int GetLength(); + FX_BOOL IsAttached(); + operator v8::Handle(); + + v8::Isolate* GetIsolate() {return m_isolate;} +private: + v8::Handle m_pArray; + v8::Isolate* m_isolate; +}; + +class CJS_Date +{ +friend class CJS_Value; +public: + CJS_Date(v8::Isolate* isolate); + CJS_Date(v8::Isolate* isolate,double dMsec_time); + CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec); + virtual ~CJS_Date(); + void Attach(v8::Handle pDate); + + int GetYear(); + void SetYear(int iYear); + + int GetMonth(); + void SetMonth(int iMonth); + + int GetDay(); + void SetDay(int iDay); + + int GetHours(); + void SetHours(int iHours); + + int GetMinutes(); + void SetMinutes(int minutes); + + int GetSeconds(); + void SetSeconds(int seconds); + + operator v8::Handle(); + operator double() const; + + CFX_WideString ToString() const; + + static double MakeDate(int year, int mon, int mday,int hour, int min, int sec,int ms); + + FX_BOOL IsValidDate(); + +protected: + v8::Handle m_pDate; + v8::Isolate* m_isolate; +}; + +#endif //_JS_VALUE_H_ + diff --git a/fpdfsdk/include/javascript/JavaScript.h b/fpdfsdk/include/javascript/JavaScript.h new file mode 100644 index 0000000000..d1375cc2f4 --- /dev/null +++ b/fpdfsdk/include/javascript/JavaScript.h @@ -0,0 +1,39 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _JAVASCRIPT_H_ +#define _JAVASCRIPT_H_ + + +#ifndef _INC_PDFAPI + #define _INC_PDFAPI + + #include "../../../core/include/fpdfapi/fpdf_module.h" + #include "../../../core/include/fpdfdoc/fpdf_doc.h" + #include "../../../core/include/fpdfdoc/fpdf_vt.h" + #include "../../../core/include/fxcrt/fx_xml.h" + #include "../../../core/include/fdrm/fx_crypt.h" + #include "../../../core/include/fpdfapi/fpdf_pageobj.h" + #include "../../../core/include/fpdfapi/fpdf_serial.h" + + + #include "../../include/fx_systemhandler.h" +#endif + + +#include "../jsapi/fxjs_v8.h" +#include "../fxedit/fx_edit.h" +#include "../pdfwindow/IPDFWindow.h" +#include "../fsdk_mgr.h" + + +#include +//#pragma warning( disable : 4786) +#include + + +#endif //_JAVASCRIPT_H_ + diff --git a/fpdfsdk/include/javascript/PublicMethods.h b/fpdfsdk/include/javascript/PublicMethods.h new file mode 100644 index 0000000000..a485a9a31a --- /dev/null +++ b/fpdfsdk/include/javascript/PublicMethods.h @@ -0,0 +1,101 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _PUBLICMETHODS_H_ +#define _PUBLICMETHODS_H_ + +class CJS_PublicMethods : public CJS_Object +{ +public: + CJS_PublicMethods(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_PublicMethods(void){}; + +public: + static FX_BOOL AFNumber_Format(OBJ_METHOD_PARAMS); + static FX_BOOL AFNumber_Keystroke(OBJ_METHOD_PARAMS); + static FX_BOOL AFPercent_Format(OBJ_METHOD_PARAMS); + static FX_BOOL AFPercent_Keystroke(OBJ_METHOD_PARAMS); + static FX_BOOL AFDate_FormatEx(OBJ_METHOD_PARAMS); + static FX_BOOL AFDate_KeystrokeEx(OBJ_METHOD_PARAMS); + static FX_BOOL AFDate_Format(OBJ_METHOD_PARAMS); + static FX_BOOL AFDate_Keystroke(OBJ_METHOD_PARAMS); + static FX_BOOL AFTime_FormatEx(OBJ_METHOD_PARAMS); // + static FX_BOOL AFTime_KeystrokeEx(OBJ_METHOD_PARAMS); + static FX_BOOL AFTime_Format(OBJ_METHOD_PARAMS); + static FX_BOOL AFTime_Keystroke(OBJ_METHOD_PARAMS); + static FX_BOOL AFSpecial_Format(OBJ_METHOD_PARAMS); + static FX_BOOL AFSpecial_Keystroke(OBJ_METHOD_PARAMS); + static FX_BOOL AFSpecial_KeystrokeEx(OBJ_METHOD_PARAMS);// + static FX_BOOL AFSimple(OBJ_METHOD_PARAMS); + static FX_BOOL AFMakeNumber(OBJ_METHOD_PARAMS); + static FX_BOOL AFSimple_Calculate(OBJ_METHOD_PARAMS); + static FX_BOOL AFRange_Validate(OBJ_METHOD_PARAMS); + static FX_BOOL AFMergeChange(OBJ_METHOD_PARAMS); + static FX_BOOL AFParseDateEx(OBJ_METHOD_PARAMS); + static FX_BOOL AFExtractNums(OBJ_METHOD_PARAMS); + +public: + JS_STATIC_GLOBAL_FUN(AFNumber_Format); + JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke); + JS_STATIC_GLOBAL_FUN(AFPercent_Format); + JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke); + JS_STATIC_GLOBAL_FUN(AFDate_FormatEx); + JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx); + JS_STATIC_GLOBAL_FUN(AFDate_Format); + JS_STATIC_GLOBAL_FUN(AFDate_Keystroke); + JS_STATIC_GLOBAL_FUN(AFTime_FormatEx); + JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx); + JS_STATIC_GLOBAL_FUN(AFTime_Format); + JS_STATIC_GLOBAL_FUN(AFTime_Keystroke); + JS_STATIC_GLOBAL_FUN(AFSpecial_Format); + JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke); + JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx); + JS_STATIC_GLOBAL_FUN(AFSimple); + JS_STATIC_GLOBAL_FUN(AFMakeNumber); + JS_STATIC_GLOBAL_FUN(AFSimple_Calculate); + JS_STATIC_GLOBAL_FUN(AFRange_Validate); + JS_STATIC_GLOBAL_FUN(AFMergeChange); + JS_STATIC_GLOBAL_FUN(AFParseDateEx); + JS_STATIC_GLOBAL_FUN(AFExtractNums); + + JS_STATIC_DECLARE_GLOBAL_FUN(); + +public: + static int ParseStringInteger(const CFX_WideString & string,int nStart,int & nSkip, int nMaxStep); + static CFX_WideString ParseStringString(const CFX_WideString& string, int nStart, int& nSkip); + static double MakeRegularDate(const CFX_WideString & value,const CFX_WideString & format, FX_BOOL& bWrongFormat); + static CFX_WideString MakeFormatDate(double dDate,const CFX_WideString & format); + static FX_BOOL ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot); + static double ParseStringToNumber(FX_LPCWSTR swSource); + static double ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat); + static double MakeInterDate(CFX_WideString strValue); + static double ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS); + +public: + static CFX_WideString StrLTrim(FX_LPCWSTR pStr); + static CFX_WideString StrRTrim(FX_LPCWSTR pStr); + static CFX_WideString StrTrim(FX_LPCWSTR pStr); + + static CFX_ByteString StrLTrim(FX_LPCSTR pStr); + static CFX_ByteString StrRTrim(FX_LPCSTR pStr); + static CFX_ByteString StrTrim(FX_LPCSTR pStr); + + static FX_BOOL IsNumber(FX_LPCSTR string); + static FX_BOOL IsNumber(FX_LPCWSTR string); + + static FX_BOOL IsDigit(char ch); + static FX_BOOL IsDigit(wchar_t ch); + static FX_BOOL IsAlphabetic(wchar_t ch); + static FX_BOOL IsAlphaNumeric(wchar_t ch); + + static FX_BOOL maskSatisfied(wchar_t c_Change,wchar_t c_Mask); + static FX_BOOL isReservedMaskChar(wchar_t ch); + + static double AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2); + static CJS_Array AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val); +}; + +#endif //_PUBLICMETHODS_H_ diff --git a/fpdfsdk/include/javascript/app.h b/fpdfsdk/include/javascript/app.h new file mode 100644 index 0000000000..35ee401058 --- /dev/null +++ b/fpdfsdk/include/javascript/app.h @@ -0,0 +1,225 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _APP_H_ +#define _APP_H_ + +class CJS_Runtime; + +/* ---------------------------- TimerObj ---------------------------- */ + +class CJS_Timer; + +class TimerObj : public CJS_EmbedObj +{ +public: + TimerObj(CJS_Object* pJSObject); + virtual ~TimerObj(); + +public: + void SetTimer(CJS_Timer* pTimer); + CJS_Timer* GetTimer() const; + +private: + CJS_Timer* m_pTimer; +}; + +class CJS_TimerObj : public CJS_Object +{ +public: + CJS_TimerObj(JSFXObject pObject) : CJS_Object(pObject) {} + virtual ~CJS_TimerObj(){} + + DECLARE_JS_CLASS(CJS_TimerObj); +}; + + +// struct APP_MENUITEM_ARRAY; +// +// struct APP_MENUITEM +// { +// APP_MENUITEM() : oSubMenu(NULL), cName(L""), cReturn(L""), bMarked(false), bEnabled(true) +// { +// } +// CFX_WideString cName; +// CFX_WideString cReturn; +// APP_MENUITEM_ARRAY* oSubMenu; +// bool bMarked; +// bool bEnabled; +// }; + +// struct APP_MENUITEM_ARRAY +// { +// APP_MENUITEM_ARRAY() : m_hMenu(NULL), pContents(NULL), nSize(0) +// { +// +// } +// APP_MENUITEM * pContents; +// HMENU m_hMenu; +// int nSize; +// }; + +// struct APP_MENU; +// struct APP_MENU_ARRAY +// { +// APP_MENU_ARRAY(): +// pContent(NULL) +// { +// } +// +// APP_MENU* pContent; +// }; + +// struct APP_MENU +// { +// APP_MENU():bSubMenu(false), +// SubMenuItems(NULL), +// cwMenuItemName(L""), +// hMenu(NULL), +// iSize(0) +// { +// +// } +// +// APP_MENU(CFX_WideString &cwName): +// cwMenuItemName(cwName), +// bSubMenu(false), +// SubMenuItems(NULL), +// hMenu(NULL), +// iSize(0) +// { +// +// } +// +// CFX_WideString cwMenuItemName; +// bool bSubMenu; +// APP_MENU_ARRAY* SubMenuItems; +// int iSize; +// HMENU hMenu; +// }; + +class app : public CJS_EmbedObj +{ +public: + app(CJS_Object * pJSObject); + virtual ~app(); + +public: + FX_BOOL activeDocs(OBJ_PROP_PARAMS); + FX_BOOL calculate(OBJ_PROP_PARAMS); + FX_BOOL formsVersion(OBJ_PROP_PARAMS); + FX_BOOL fs(OBJ_PROP_PARAMS); + FX_BOOL fullscreen(OBJ_PROP_PARAMS); + FX_BOOL language(OBJ_PROP_PARAMS); + FX_BOOL media(OBJ_PROP_PARAMS); + FX_BOOL platform(OBJ_PROP_PARAMS); + FX_BOOL runtimeHighlight(OBJ_PROP_PARAMS); + FX_BOOL viewerType(OBJ_PROP_PARAMS); + FX_BOOL viewerVariation(OBJ_PROP_PARAMS); + FX_BOOL viewerVersion(OBJ_PROP_PARAMS); + + + FX_BOOL alert(OBJ_METHOD_PARAMS); + FX_BOOL beep(OBJ_METHOD_PARAMS); + FX_BOOL browseForDoc(OBJ_METHOD_PARAMS); + FX_BOOL clearInterval(OBJ_METHOD_PARAMS); + FX_BOOL clearTimeOut(OBJ_METHOD_PARAMS); + FX_BOOL execDialog(OBJ_METHOD_PARAMS); + FX_BOOL execMenuItem(OBJ_METHOD_PARAMS); + FX_BOOL findComponent(OBJ_METHOD_PARAMS); + FX_BOOL goBack(OBJ_METHOD_PARAMS); + FX_BOOL goForward(OBJ_METHOD_PARAMS); + FX_BOOL launchURL(OBJ_METHOD_PARAMS); + FX_BOOL mailMsg(OBJ_METHOD_PARAMS); + FX_BOOL newFDF(OBJ_METHOD_PARAMS); + FX_BOOL newDoc(OBJ_METHOD_PARAMS); + FX_BOOL openDoc(OBJ_METHOD_PARAMS); + FX_BOOL openFDF(OBJ_METHOD_PARAMS); + FX_BOOL popUpMenuEx(OBJ_METHOD_PARAMS); + FX_BOOL popUpMenu(OBJ_METHOD_PARAMS); + FX_BOOL response(OBJ_METHOD_PARAMS); + FX_BOOL setInterval(OBJ_METHOD_PARAMS); + FX_BOOL setTimeOut(OBJ_METHOD_PARAMS); + +private: +// FX_DWORD AppGetTickCount(); + void TimerProc(CJS_Timer* pTimer); + void RunJsScript(CJS_Runtime * pRuntime,const CFX_WideString & wsScript); +// void ParsePopupMenuObj(APP_MENUITEM * ppMenuItem,JSObject * pObj); +// void DeleteMenuItems(APP_MENUITEM_ARRAY * pMenuItems); +// void AddMenuItem(APP_MENUITEM_ARRAY * pMenuItems, HMENU hMenu, MENUITEMINFO MenuItemInfo); +// void InitMenuItemInfo(MENUITEMINFO& MenuItemInfo); +// void DestroyPopUpMenu(); + +// void ParserMenuItem(APP_MENU* pHead, const CJS_Parameters¶ms); +// void AddItemToMenu(APP_MENU* pHead, HMENU hMenu, MENUITEMINFO MenuItemInfo); +// void DestroyMenuItems(APP_MENU* pHead); + +public: + static CFX_WideString SysPathToPDFPath(const CFX_WideString& sOldPath); + static CFX_WideString PDFPathToSysPath(const CFX_WideString& sOldPath); + static CFX_WideString RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath); + + +private: + + bool m_bCalculate; + CJS_Runtime* m_pRuntime; + bool m_bRuntimeHighLight; + + CFX_ArrayTemplate m_aTimer; +// APP_MENU* m_pMenuHead; + +public: +// static CReader_App* s_App; +}; + +class CJS_App : public CJS_Object +{ +public: + CJS_App(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_App(void){}; + + DECLARE_JS_CLASS(CJS_App); + + 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_METHOD(alert, app); + JS_STATIC_METHOD(beep, app); + JS_STATIC_METHOD(browseForDoc, app); + JS_STATIC_METHOD(clearInterval, app); + JS_STATIC_METHOD(clearTimeOut, app); + JS_STATIC_METHOD(execDialog, app); + JS_STATIC_METHOD(execMenuItem, app); + JS_STATIC_METHOD(findComponent, app); + JS_STATIC_METHOD(goBack, app); + JS_STATIC_METHOD(goForward, app); + JS_STATIC_METHOD(launchURL, app); + JS_STATIC_METHOD(mailMsg, app); + JS_STATIC_METHOD(newFDF, app); + JS_STATIC_METHOD(newDoc, app); + JS_STATIC_METHOD(openDoc, app); + JS_STATIC_METHOD(openFDF, app); + JS_STATIC_METHOD(popUpMenuEx, app); + JS_STATIC_METHOD(popUpMenu, app); + JS_STATIC_METHOD(response, app); + JS_STATIC_METHOD(setInterval, app); + JS_STATIC_METHOD(setTimeOut, app); + +}; + +#endif //_APP_H_ diff --git a/fpdfsdk/include/javascript/color.h b/fpdfsdk/include/javascript/color.h new file mode 100644 index 0000000000..1910e16955 --- /dev/null +++ b/fpdfsdk/include/javascript/color.h @@ -0,0 +1,78 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _COLOR_H_ +#define _COLOR_H_ + +class color : public CJS_EmbedObj +{ +public: + color(CJS_Object* pJSObject); + virtual ~color(void); + + FX_BOOL black(OBJ_PROP_PARAMS); + FX_BOOL blue(OBJ_PROP_PARAMS); + FX_BOOL cyan(OBJ_PROP_PARAMS); + FX_BOOL dkGray(OBJ_PROP_PARAMS); + FX_BOOL gray(OBJ_PROP_PARAMS); + FX_BOOL green(OBJ_PROP_PARAMS); + FX_BOOL ltGray(OBJ_PROP_PARAMS); + FX_BOOL magenta(OBJ_PROP_PARAMS); + FX_BOOL red(OBJ_PROP_PARAMS); + FX_BOOL transparent(OBJ_PROP_PARAMS); + FX_BOOL white(OBJ_PROP_PARAMS); + FX_BOOL yellow(OBJ_PROP_PARAMS); + + FX_BOOL convert(OBJ_METHOD_PARAMS); + FX_BOOL equal(OBJ_METHOD_PARAMS); + +public: + static void ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array); + static void ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color); + +private: + CPWL_Color m_crTransparent; + CPWL_Color m_crBlack; + CPWL_Color m_crWhite; + CPWL_Color m_crRed; + CPWL_Color m_crGreen; + CPWL_Color m_crBlue; + CPWL_Color m_crCyan; + CPWL_Color m_crMagenta; + CPWL_Color m_crYellow; + CPWL_Color m_crDKGray; + CPWL_Color m_crGray; + CPWL_Color m_crLTGray; +}; + +class CJS_Color : public CJS_Object +{ +public: + CJS_Color(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Color(void){}; + + DECLARE_JS_CLASS(CJS_Color); + + 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_METHOD(convert,color); + JS_STATIC_METHOD(equal,color); + +}; + +#endif //_COLOR_H_ + diff --git a/fpdfsdk/include/javascript/console.h b/fpdfsdk/include/javascript/console.h new file mode 100644 index 0000000000..98a329367e --- /dev/null +++ b/fpdfsdk/include/javascript/console.h @@ -0,0 +1,38 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _CONSOLE_H_ +#define _CONSOLE_H_ + +class console : public CJS_EmbedObj +{ +public: + console(CJS_Object* pJSObject); + virtual ~console(void); + +public: + FX_BOOL clear(OBJ_METHOD_PARAMS); + FX_BOOL hide(OBJ_METHOD_PARAMS); + FX_BOOL println(OBJ_METHOD_PARAMS); + FX_BOOL show(OBJ_METHOD_PARAMS); +}; + +class CJS_Console : public CJS_Object +{ +public: + CJS_Console(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Console(void){}; + + DECLARE_JS_CLASS(CJS_Console); + + JS_STATIC_METHOD(clear, console); + JS_STATIC_METHOD(hide, console); + JS_STATIC_METHOD(println, console); + JS_STATIC_METHOD(show, console); +}; + +#endif //_CONSOLE_H_ + diff --git a/fpdfsdk/include/javascript/event.h b/fpdfsdk/include/javascript/event.h new file mode 100644 index 0000000000..91f2c65a21 --- /dev/null +++ b/fpdfsdk/include/javascript/event.h @@ -0,0 +1,70 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _EVENT_H_ +#define _EVENT_H_ + +class event : public CJS_EmbedObj +{ +public: + event(CJS_Object * pJSObject); + virtual ~event(void); + +public: + FX_BOOL change(OBJ_PROP_PARAMS); + FX_BOOL changeEx(OBJ_PROP_PARAMS); + FX_BOOL commitKey(OBJ_PROP_PARAMS); + FX_BOOL fieldFull(OBJ_PROP_PARAMS); + FX_BOOL keyDown(OBJ_PROP_PARAMS); + FX_BOOL modifier(OBJ_PROP_PARAMS); + FX_BOOL name(OBJ_PROP_PARAMS); + FX_BOOL rc(OBJ_PROP_PARAMS); + FX_BOOL richChange(OBJ_PROP_PARAMS); + FX_BOOL richChangeEx(OBJ_PROP_PARAMS); + FX_BOOL richValue(OBJ_PROP_PARAMS); + FX_BOOL selEnd(OBJ_PROP_PARAMS); + FX_BOOL selStart(OBJ_PROP_PARAMS); + FX_BOOL shift(OBJ_PROP_PARAMS); + FX_BOOL source(OBJ_PROP_PARAMS); + FX_BOOL target(OBJ_PROP_PARAMS); + FX_BOOL targetName(OBJ_PROP_PARAMS); + FX_BOOL type(OBJ_PROP_PARAMS); + FX_BOOL value(OBJ_PROP_PARAMS); + FX_BOOL willCommit(OBJ_PROP_PARAMS); + +}; + +class CJS_Event : public CJS_Object +{ +public: + CJS_Event(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Event(void){}; + + DECLARE_JS_CLASS(CJS_Event); + + 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); +}; + +#endif //_EVENT_H_ diff --git a/fpdfsdk/include/javascript/global.h b/fpdfsdk/include/javascript/global.h new file mode 100644 index 0000000000..7effd574a0 --- /dev/null +++ b/fpdfsdk/include/javascript/global.h @@ -0,0 +1,85 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ + +class CJS_GlobalData; + +struct js_global_data +{ + js_global_data() + { + nType = 0; + dData = 0; + bData = FALSE; + sData = ""; + bPersistent = FALSE; + bDeleted = FALSE; + } + + ~js_global_data() + { + pData.Reset(); + } + int nType; //0:int 1:bool 2:string 3:obj + double dData; + bool bData; + CFX_ByteString sData; + v8::Persistent pData; + bool bPersistent; + bool bDeleted; +}; + +class global_alternate : public CJS_EmbedObj +{ +public: + global_alternate(CJS_Object* pJSObject); + virtual ~global_alternate(); + +public: + FX_BOOL setPersistent(OBJ_METHOD_PARAMS); + +public: + FX_BOOL QueryProperty(FX_LPCWSTR propname); + FX_BOOL DoProperty(IFXJS_Context* cc, FX_LPCWSTR propname, CJS_PropValue & vp, JS_ErrorString & sError); + FX_BOOL DelProperty(IFXJS_Context* cc, FX_LPCWSTR propname, JS_ErrorString & sError); + + void Initial(CPDFDoc_Environment* pApp); + +private: + void UpdateGlobalPersistentVariables(); + void CommitGlobalPersisitentVariables(); + void DestroyGlobalPersisitentVariables(); + FX_BOOL SetGlobalVariables(FX_LPCSTR propname, int nType, + double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent); + + void ObjectToArray(v8::Handle pObj, CJS_GlobalVariableArray& array); + void PutObjectProperty(v8::Handle obj, CJS_KeyValue* pData); + +private: + CFX_MapByteStringToPtr m_mapGlobal; + CFX_WideString m_sFilePath; + CJS_GlobalData* m_pGlobalData; + CPDFDoc_Environment* m_pApp; +}; + + +class CJS_Global : public CJS_Object +{ +public: + CJS_Global(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Global(void){}; + + virtual FX_BOOL InitInstance(IFXJS_Context* cc); + + DECLARE_SPECIAL_JS_CLASS(CJS_Global); + + JS_SPECIAL_STATIC_METHOD(setPersistent, global_alternate, global); + +}; + +#endif //_GLOBAL_H_ diff --git a/fpdfsdk/include/javascript/report.h b/fpdfsdk/include/javascript/report.h new file mode 100644 index 0000000000..8a4084dac1 --- /dev/null +++ b/fpdfsdk/include/javascript/report.h @@ -0,0 +1,35 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _REPORT_H_ +#define _REPORT_H_ + +class Report : public CJS_EmbedObj +{ +public: + Report(CJS_Object * pJSObject); + virtual ~Report(); + +public: + FX_BOOL save(OBJ_METHOD_PARAMS); + FX_BOOL writeText(OBJ_METHOD_PARAMS); +}; + +class CJS_Report : public CJS_Object +{ +public: + CJS_Report(JSFXObject pObject) : CJS_Object(pObject){}; + virtual ~CJS_Report(){}; + +public: + DECLARE_JS_CLASS(CJS_Report); + + JS_STATIC_METHOD(save, Report) + JS_STATIC_METHOD(writeText, Report); +}; + +#endif //_REPORT_H_ + diff --git a/fpdfsdk/include/javascript/resource.h b/fpdfsdk/include/javascript/resource.h new file mode 100644 index 0000000000..0b7668e908 --- /dev/null +++ b/fpdfsdk/include/javascript/resource.h @@ -0,0 +1,110 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#define IDD_JS_MSGBOX 25600 +#define IDD_RESPONSE 25601 +#define IDC_JS_MSG_TEXT 25602 +#define ID_JS_MSG_OK 25603 +#define ID_JS_MSG_CANCEL 25604 +#define IDC_JS_MSG_ICON 25605 +#define ID_JS_MSG_YES 25606 +#define ID_JS_MSG_NO 25607 +#define IDC_JS_QUESTION 25608 +#define ID_JS_OK 25609 +#define ID_JS_CANCEL 25610 +#define IDC_JS_ANSWER 25611 +#define IDC_JS_EDIT 25612 +#define IDS_STRING_JSALERT 25613 +#define IDS_STRING_JSPARAMERROR 25614 +#define IDS_STRING_JSAFNUMBER_KEYSTROKE 25615 +#define IDS_STRING_JSINPUTERROR 25616 +#define IDS_STRING_JSPARAM_TOOLONG 25617 +#define IDS_STRING_JSPARSEDATE 25618 +#define IDS_STRING_JSRANGE1 25619 +#define IDS_STRING_JSRANGE2 25620 +#define IDS_STRING_JSRANGE3 25621 +#define IDS_STRING_JSRANGE4 25622 +#define IDS_STRING_FILEOPENFAIL 25623 +#define IDS_STRING_JSATTENTION 25624 +#define IDS_STRING_JSSUBMITS 25625 +#define IDS_STRING_JSSUBMITF 25626 +#define IDS_STRING_NOTSUPPORT 25627 +#define IDS_STRING_JSBUSY 25628 +#define IDS_STRING_JSEVENT 25629 +#define IDS_STRING_RUN 25630 +#define IDS_STRING_UNHANDLED 25631 +#define IDS_STRING_JSPRINT1 25632 +#define IDS_STRING_JSPRINT2 25633 +#define IDS_STRING_LAUNCHURL 25634 +#define IDS_JSPARAM_INCORRECT 25635 +#define IDD_JS_CONSOLE 25636 +#define IDS_STRING_SAFEMODEL 25636 +#define IDC_EDTSCRIPT 25637 +#define IDC_BTNCLEAR 25638 +#define IDC_EDTOUTPUT 25639 +#define IDC_CHECK_TIPS 25640 +#define IDC_BTNRUN 25641 + + + +static CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT ID) +{ + switch(ID) + { + case IDS_STRING_JSALERT: + return L"Alert"; + case IDS_STRING_JSPARAMERROR: + return L"The amount of parameters is not correct !"; + case IDS_STRING_JSAFNUMBER_KEYSTROKE: + return L"The input value is invalid."; + case IDS_STRING_JSINPUTERROR: + return L"Input error !"; + case IDS_STRING_JSPARAM_TOOLONG: + return L"The value you are going to input is too long."; + case IDS_STRING_JSPARSEDATE: + return L"The input string can't be parsed to a valid date time (%s)."; + case IDS_STRING_JSRANGE1: + return L"Invalid value: must be greater or equal to %s and less than or equal to %s."; + case IDS_STRING_JSRANGE2: + return L"Invalid value: must be greater or equal to %s."; + case IDS_STRING_JSRANGE3: + return L"Invalid value: must be less than or equal to %s."; + case IDS_STRING_JSRANGE4: + return L"Range Error"; + case IDS_STRING_FILEOPENFAIL: + return L"Opening file failed."; + case IDS_STRING_JSATTENTION: + return L"Attention"; + case IDS_STRING_JSSUBMITS: + return L"Submit form successfully!"; + case IDS_STRING_JSSUBMITF: + return L"Submit form failed!"; + case IDS_STRING_NOTSUPPORT: + return L"Not supported."; + case IDS_STRING_JSBUSY: + return L"System is busy!"; + case IDS_STRING_JSEVENT: + return L"The event of the formfield exists!"; + case IDS_STRING_RUN: + return L"It runs successfully."; + case IDS_STRING_UNHANDLED: + return L"An unhandled error!"; + case IDS_STRING_JSPRINT1: + return L"The second parameter can't convert to Date!"; + case IDS_STRING_JSPRINT2: + return L"The second parameter isn't a valid Date!"; + case IDS_STRING_LAUNCHURL: + return L"The Document is trying to connect to \r\n%s\r\nIf you trust the site, choose OK. If you don't trust the site, choose Cancel."; + case IDS_JSPARAM_INCORRECT: + return L"The parameter you inputted is incorrect!"; + case IDS_STRING_SAFEMODEL: + return L"Secure reading mode"; + default: + return L""; + + } +} + diff --git a/fpdfsdk/include/javascript/util.h b/fpdfsdk/include/javascript/util.h new file mode 100644 index 0000000000..9f4efc3525 --- /dev/null +++ b/fpdfsdk/include/javascript/util.h @@ -0,0 +1,45 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +class util : public CJS_EmbedObj +{ +public: + util(CJS_Object * pJSObject); + virtual ~util(void); + +public: + FX_BOOL printd(OBJ_METHOD_PARAMS); + FX_BOOL printf(OBJ_METHOD_PARAMS); + FX_BOOL printx(OBJ_METHOD_PARAMS); + FX_BOOL scand(OBJ_METHOD_PARAMS); + FX_BOOL byteToChar(OBJ_METHOD_PARAMS); + +public: + static void printd(const std::wstring &cFormat,CJS_Date Date,bool bXFAPicture, std::wstring &cPurpose); + static void printx(const std::string &cFormat,const std::string &cSource, std::string &cPurpose); + static int ParstDataType(std::wstring* sFormat); +}; + +class CJS_Util : public CJS_Object +{ +public: + CJS_Util(JSFXObject pObject) : CJS_Object(pObject) {}; + virtual ~CJS_Util(void){}; + + DECLARE_JS_CLASS(CJS_Util); + + JS_STATIC_METHOD(printd, util); + JS_STATIC_METHOD(printf, util); + JS_STATIC_METHOD(printx, util); + JS_STATIC_METHOD(scand, util); + JS_STATIC_METHOD(byteToChar, util); +}; + +FX_INT64 FX_atoi64(const char *nptr); +#endif //_UTIL_H_ -- cgit v1.2.3