blob: aa9be94ec716082cabf333245ce8c26ef5dbe7cd [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez37458412015-10-06 11:33:46 -07007#ifndef FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_
8#define FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Dan Sinclairefbc1912016-02-17 16:54:43 -050010#include "fpdfsdk/src/javascript/JS_Define.h"
Tom Sepez9a3f8122015-04-07 15:35:48 -070011
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012class CJS_PublicMethods : public CJS_Object {
13 public:
Lei Zhang9559b7a2015-12-21 11:12:20 -080014 explicit CJS_PublicMethods(v8::Local<v8::Object> pObject)
15 : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070016 ~CJS_PublicMethods() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
Nico Weber9d8ec5a2015-08-04 13:00:21 -070018 public:
Tom Sepezba038bc2015-10-08 12:03:00 -070019 static FX_BOOL AFNumber_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080020 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021 CJS_Value& vRet,
22 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070023 static FX_BOOL AFNumber_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080024 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025 CJS_Value& vRet,
26 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070027 static FX_BOOL AFPercent_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080028 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 CJS_Value& vRet,
30 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070031 static FX_BOOL AFPercent_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080032 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 CJS_Value& vRet,
34 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070035 static FX_BOOL AFDate_FormatEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080036 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 CJS_Value& vRet,
38 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070039 static FX_BOOL AFDate_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080040 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 CJS_Value& vRet,
42 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070043 static FX_BOOL AFDate_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080044 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 CJS_Value& vRet,
46 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070047 static FX_BOOL AFDate_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080048 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 CJS_Value& vRet,
50 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070051 static FX_BOOL AFTime_FormatEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080052 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 CJS_Value& vRet,
54 CFX_WideString& sError); //
Tom Sepezba038bc2015-10-08 12:03:00 -070055 static FX_BOOL AFTime_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080056 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 CJS_Value& vRet,
58 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070059 static FX_BOOL AFTime_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080060 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 CJS_Value& vRet,
62 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070063 static FX_BOOL AFTime_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080064 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 CJS_Value& vRet,
66 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070067 static FX_BOOL AFSpecial_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080068 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 CJS_Value& vRet,
70 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070071 static FX_BOOL AFSpecial_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080072 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 CJS_Value& vRet,
74 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070075 static FX_BOOL AFSpecial_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080076 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 CJS_Value& vRet,
78 CFX_WideString& sError); //
Tom Sepezba038bc2015-10-08 12:03:00 -070079 static FX_BOOL AFSimple(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080080 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 CJS_Value& vRet,
82 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070083 static FX_BOOL AFMakeNumber(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080084 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 CJS_Value& vRet,
86 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070087 static FX_BOOL AFSimple_Calculate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080088 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 CJS_Value& vRet,
90 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070091 static FX_BOOL AFRange_Validate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080092 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 CJS_Value& vRet,
94 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070095 static FX_BOOL AFMergeChange(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080096 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 CJS_Value& vRet,
98 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070099 static FX_BOOL AFParseDateEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800100 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 CJS_Value& vRet,
102 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -0700103 static FX_BOOL AFExtractNums(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800104 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 CJS_Value& vRet,
106 CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 public:
109 JS_STATIC_GLOBAL_FUN(AFNumber_Format);
110 JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke);
111 JS_STATIC_GLOBAL_FUN(AFPercent_Format);
112 JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke);
113 JS_STATIC_GLOBAL_FUN(AFDate_FormatEx);
114 JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx);
115 JS_STATIC_GLOBAL_FUN(AFDate_Format);
116 JS_STATIC_GLOBAL_FUN(AFDate_Keystroke);
117 JS_STATIC_GLOBAL_FUN(AFTime_FormatEx);
118 JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx);
119 JS_STATIC_GLOBAL_FUN(AFTime_Format);
120 JS_STATIC_GLOBAL_FUN(AFTime_Keystroke);
121 JS_STATIC_GLOBAL_FUN(AFSpecial_Format);
122 JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke);
123 JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx);
124 JS_STATIC_GLOBAL_FUN(AFSimple);
125 JS_STATIC_GLOBAL_FUN(AFMakeNumber);
126 JS_STATIC_GLOBAL_FUN(AFSimple_Calculate);
127 JS_STATIC_GLOBAL_FUN(AFRange_Validate);
128 JS_STATIC_GLOBAL_FUN(AFMergeChange);
129 JS_STATIC_GLOBAL_FUN(AFParseDateEx);
130 JS_STATIC_GLOBAL_FUN(AFExtractNums);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 JS_STATIC_DECLARE_GLOBAL_FUN();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700133
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 public:
135 static int ParseStringInteger(const CFX_WideString& string,
136 int nStart,
137 int& nSkip,
138 int nMaxStep);
139 static CFX_WideString ParseStringString(const CFX_WideString& string,
140 int nStart,
141 int& nSkip);
142 static double MakeRegularDate(const CFX_WideString& value,
143 const CFX_WideString& format,
Lei Zhang9559b7a2015-12-21 11:12:20 -0800144 bool* bWrongFormat);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 static CFX_WideString MakeFormatDate(double dDate,
146 const CFX_WideString& format);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 static double ParseNormalDate(const CFX_WideString& value,
Lei Zhang9559b7a2015-12-21 11:12:20 -0800148 bool* bWrongFormat);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 static double MakeInterDate(CFX_WideString strValue);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 public:
152 static CFX_WideString StrLTrim(const FX_WCHAR* pStr);
153 static CFX_WideString StrRTrim(const FX_WCHAR* pStr);
154 static CFX_WideString StrTrim(const FX_WCHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 static CFX_ByteString StrLTrim(const FX_CHAR* pStr);
157 static CFX_ByteString StrRTrim(const FX_CHAR* pStr);
158 static CFX_ByteString StrTrim(const FX_CHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 static FX_BOOL IsNumber(const FX_CHAR* string);
161 static FX_BOOL IsNumber(const FX_WCHAR* string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 static FX_BOOL maskSatisfied(wchar_t c_Change, wchar_t c_Mask);
164 static FX_BOOL isReservedMaskChar(wchar_t ch);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 static double AF_Simple(const FX_WCHAR* sFuction,
167 double dValue1,
168 double dValue2);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700169 static CJS_Array AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170};
171
Tom Sepez37458412015-10-06 11:33:46 -0700172#endif // FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_