blob: 16cc5bc21abfd309e02bdbc119f3432c2bd66f29 [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
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#ifndef FPDFSDK_JAVASCRIPT_PUBLICMETHODS_H_
8#define FPDFSDK_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 Sinclairf766ad22016-03-14 13:51:24 -040013#include "fpdfsdk/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
Tom Sepezba038bc2015-10-08 12:03:00 -070021 static FX_BOOL AFNumber_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080022 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 CJS_Value& vRet,
24 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070025 static FX_BOOL AFNumber_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080026 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 CJS_Value& vRet,
28 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070029 static FX_BOOL AFPercent_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080030 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 CJS_Value& vRet,
32 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070033 static FX_BOOL AFPercent_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080034 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 CJS_Value& vRet,
36 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070037 static FX_BOOL AFDate_FormatEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080038 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039 CJS_Value& vRet,
40 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070041 static FX_BOOL AFDate_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080042 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 CJS_Value& vRet,
44 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070045 static FX_BOOL AFDate_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080046 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 CJS_Value& vRet,
48 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070049 static FX_BOOL AFDate_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080050 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 CJS_Value& vRet,
52 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070053 static FX_BOOL AFTime_FormatEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080054 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 CJS_Value& vRet,
56 CFX_WideString& sError); //
Tom Sepezba038bc2015-10-08 12:03:00 -070057 static FX_BOOL AFTime_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080058 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 CJS_Value& vRet,
60 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070061 static FX_BOOL AFTime_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080062 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 CJS_Value& vRet,
64 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070065 static FX_BOOL AFTime_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080066 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 CJS_Value& vRet,
68 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070069 static FX_BOOL AFSpecial_Format(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080070 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 CJS_Value& vRet,
72 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070073 static FX_BOOL AFSpecial_Keystroke(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080074 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 CJS_Value& vRet,
76 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070077 static FX_BOOL AFSpecial_KeystrokeEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080078 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 CJS_Value& vRet,
80 CFX_WideString& sError); //
Tom Sepezba038bc2015-10-08 12:03:00 -070081 static FX_BOOL AFSimple(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080082 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 CJS_Value& vRet,
84 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070085 static FX_BOOL AFMakeNumber(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080086 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 CJS_Value& vRet,
88 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070089 static FX_BOOL AFSimple_Calculate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080090 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 CJS_Value& vRet,
92 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070093 static FX_BOOL AFRange_Validate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080094 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 CJS_Value& vRet,
96 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070097 static FX_BOOL AFMergeChange(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080098 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 CJS_Value& vRet,
100 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -0700101 static FX_BOOL AFParseDateEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800102 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 CJS_Value& vRet,
104 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -0700105 static FX_BOOL AFExtractNums(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800106 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 CJS_Value& vRet,
108 CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 JS_STATIC_GLOBAL_FUN(AFNumber_Format);
111 JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke);
112 JS_STATIC_GLOBAL_FUN(AFPercent_Format);
113 JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke);
114 JS_STATIC_GLOBAL_FUN(AFDate_FormatEx);
115 JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx);
116 JS_STATIC_GLOBAL_FUN(AFDate_Format);
117 JS_STATIC_GLOBAL_FUN(AFDate_Keystroke);
118 JS_STATIC_GLOBAL_FUN(AFTime_FormatEx);
119 JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx);
120 JS_STATIC_GLOBAL_FUN(AFTime_Format);
121 JS_STATIC_GLOBAL_FUN(AFTime_Keystroke);
122 JS_STATIC_GLOBAL_FUN(AFSpecial_Format);
123 JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke);
124 JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx);
125 JS_STATIC_GLOBAL_FUN(AFSimple);
126 JS_STATIC_GLOBAL_FUN(AFMakeNumber);
127 JS_STATIC_GLOBAL_FUN(AFSimple_Calculate);
128 JS_STATIC_GLOBAL_FUN(AFRange_Validate);
129 JS_STATIC_GLOBAL_FUN(AFMergeChange);
130 JS_STATIC_GLOBAL_FUN(AFParseDateEx);
131 JS_STATIC_GLOBAL_FUN(AFExtractNums);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 JS_STATIC_DECLARE_GLOBAL_FUN();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 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 static CFX_WideString StrLTrim(const FX_WCHAR* pStr);
152 static CFX_WideString StrRTrim(const FX_WCHAR* pStr);
153 static CFX_WideString StrTrim(const FX_WCHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 static CFX_ByteString StrLTrim(const FX_CHAR* pStr);
156 static CFX_ByteString StrRTrim(const FX_CHAR* pStr);
157 static CFX_ByteString StrTrim(const FX_CHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158
Wei Li614d20a2016-03-15 13:55:12 -0700159 static bool IsNumber(const FX_WCHAR* string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160
Wei Li614d20a2016-03-15 13:55:12 -0700161 static bool maskSatisfied(wchar_t c_Change, wchar_t c_Mask);
162 static bool isReservedMaskChar(wchar_t ch);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 static double AF_Simple(const FX_WCHAR* sFuction,
165 double dValue1,
166 double dValue2);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700167 static CJS_Array AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168};
169
Dan Sinclairf766ad22016-03-14 13:51:24 -0400170#endif // FPDFSDK_JAVASCRIPT_PUBLICMETHODS_H_