blob: d0c81e03e38c73c3c0753eb016b2c93302d6de21 [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 Sinclair3ebd1212016-03-09 09:59:23 -050010#include <string>
11#include <vector>
12
Dan Sinclairefbc1912016-02-17 16:54:43 -050013#include "fpdfsdk/src/javascript/JS_Define.h"
Tom Sepez9a3f8122015-04-07 15:35:48 -070014
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015class CJS_PublicMethods : public CJS_Object {
16 public:
Lei Zhang9559b7a2015-12-21 11:12:20 -080017 explicit CJS_PublicMethods(v8::Local<v8::Object> pObject)
18 : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070019 ~CJS_PublicMethods() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021 public:
Tom Sepezba038bc2015-10-08 12:03:00 -070022 static FX_BOOL AFNumber_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080023 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024 CJS_Value& vRet,
25 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070026 static FX_BOOL AFNumber_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080027 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 CJS_Value& vRet,
29 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070030 static FX_BOOL AFPercent_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080031 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032 CJS_Value& vRet,
33 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070034 static FX_BOOL AFPercent_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080035 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036 CJS_Value& vRet,
37 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070038 static FX_BOOL AFDate_FormatEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080039 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 CJS_Value& vRet,
41 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070042 static FX_BOOL AFDate_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080043 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 CJS_Value& vRet,
45 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070046 static FX_BOOL AFDate_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080047 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 CJS_Value& vRet,
49 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070050 static FX_BOOL AFDate_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080051 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 CJS_Value& vRet,
53 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070054 static FX_BOOL AFTime_FormatEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080055 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 CJS_Value& vRet,
57 CFX_WideString& sError); //
Tom Sepezba038bc2015-10-08 12:03:00 -070058 static FX_BOOL AFTime_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080059 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 CJS_Value& vRet,
61 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070062 static FX_BOOL AFTime_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080063 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 CJS_Value& vRet,
65 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070066 static FX_BOOL AFTime_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080067 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 CJS_Value& vRet,
69 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070070 static FX_BOOL AFSpecial_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080071 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 CJS_Value& vRet,
73 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070074 static FX_BOOL AFSpecial_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080075 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 CJS_Value& vRet,
77 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070078 static FX_BOOL AFSpecial_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080079 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 CJS_Value& vRet,
81 CFX_WideString& sError); //
Tom Sepezba038bc2015-10-08 12:03:00 -070082 static FX_BOOL AFSimple(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080083 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 CJS_Value& vRet,
85 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070086 static FX_BOOL AFMakeNumber(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080087 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 CJS_Value& vRet,
89 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070090 static FX_BOOL AFSimple_Calculate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080091 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 CJS_Value& vRet,
93 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070094 static FX_BOOL AFRange_Validate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080095 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 CJS_Value& vRet,
97 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070098 static FX_BOOL AFMergeChange(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080099 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 CJS_Value& vRet,
101 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -0700102 static FX_BOOL AFParseDateEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800103 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 CJS_Value& vRet,
105 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -0700106 static FX_BOOL AFExtractNums(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800107 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 CJS_Value& vRet,
109 CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 public:
112 JS_STATIC_GLOBAL_FUN(AFNumber_Format);
113 JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke);
114 JS_STATIC_GLOBAL_FUN(AFPercent_Format);
115 JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke);
116 JS_STATIC_GLOBAL_FUN(AFDate_FormatEx);
117 JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx);
118 JS_STATIC_GLOBAL_FUN(AFDate_Format);
119 JS_STATIC_GLOBAL_FUN(AFDate_Keystroke);
120 JS_STATIC_GLOBAL_FUN(AFTime_FormatEx);
121 JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx);
122 JS_STATIC_GLOBAL_FUN(AFTime_Format);
123 JS_STATIC_GLOBAL_FUN(AFTime_Keystroke);
124 JS_STATIC_GLOBAL_FUN(AFSpecial_Format);
125 JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke);
126 JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx);
127 JS_STATIC_GLOBAL_FUN(AFSimple);
128 JS_STATIC_GLOBAL_FUN(AFMakeNumber);
129 JS_STATIC_GLOBAL_FUN(AFSimple_Calculate);
130 JS_STATIC_GLOBAL_FUN(AFRange_Validate);
131 JS_STATIC_GLOBAL_FUN(AFMergeChange);
132 JS_STATIC_GLOBAL_FUN(AFParseDateEx);
133 JS_STATIC_GLOBAL_FUN(AFExtractNums);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 JS_STATIC_DECLARE_GLOBAL_FUN();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 public:
138 static int ParseStringInteger(const CFX_WideString& string,
139 int nStart,
140 int& nSkip,
141 int nMaxStep);
142 static CFX_WideString ParseStringString(const CFX_WideString& string,
143 int nStart,
144 int& nSkip);
145 static double MakeRegularDate(const CFX_WideString& value,
146 const CFX_WideString& format,
Lei Zhang9559b7a2015-12-21 11:12:20 -0800147 bool* bWrongFormat);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 static CFX_WideString MakeFormatDate(double dDate,
149 const CFX_WideString& format);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 static double ParseNormalDate(const CFX_WideString& value,
Lei Zhang9559b7a2015-12-21 11:12:20 -0800151 bool* bWrongFormat);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 static double MakeInterDate(CFX_WideString strValue);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 public:
155 static CFX_WideString StrLTrim(const FX_WCHAR* pStr);
156 static CFX_WideString StrRTrim(const FX_WCHAR* pStr);
157 static CFX_WideString StrTrim(const FX_WCHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 static CFX_ByteString StrLTrim(const FX_CHAR* pStr);
160 static CFX_ByteString StrRTrim(const FX_CHAR* pStr);
161 static CFX_ByteString StrTrim(const FX_CHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 static FX_BOOL IsNumber(const FX_CHAR* string);
164 static FX_BOOL IsNumber(const FX_WCHAR* string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 static FX_BOOL maskSatisfied(wchar_t c_Change, wchar_t c_Mask);
167 static FX_BOOL isReservedMaskChar(wchar_t ch);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 static double AF_Simple(const FX_WCHAR* sFuction,
170 double dValue1,
171 double dValue2);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700172 static CJS_Array AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173};
174
Tom Sepez37458412015-10-06 11:33:46 -0700175#endif // FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_