1 // 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.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FXJS_CJS_COLOR_H_
8 #define FXJS_CJS_COLOR_H_
9 
10 #include <vector>
11 
12 #include "core/fxge/cfx_color.h"
13 #include "fxjs/cjs_object.h"
14 #include "fxjs/js_define.h"
15 
16 class CJS_Color final : public CJS_Object {
17  public:
18   static int GetObjDefnID();
19   static void DefineJSObjects(CFXJS_Engine* pEngine);
20   static v8::Local<v8::Array> ConvertPWLColorToArray(CJS_Runtime* pRuntime,
21                                                      const CFX_Color& color);
22   static CFX_Color ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
23                                           v8::Local<v8::Array> array);
24 
25   CJS_Color(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
26   ~CJS_Color() override;
27 
28   JS_STATIC_PROP(black, black, CJS_Color)
29   JS_STATIC_PROP(blue, blue, CJS_Color)
30   JS_STATIC_PROP(cyan, cyan, CJS_Color)
31   JS_STATIC_PROP(dkGray, dark_gray, CJS_Color)
32   JS_STATIC_PROP(gray, gray, CJS_Color)
33   JS_STATIC_PROP(green, green, CJS_Color)
34   JS_STATIC_PROP(ltGray, light_gray, CJS_Color)
35   JS_STATIC_PROP(magenta, magenta, CJS_Color)
36   JS_STATIC_PROP(red, red, CJS_Color)
37   JS_STATIC_PROP(transparent, transparent, CJS_Color)
38   JS_STATIC_PROP(white, white, CJS_Color)
39   JS_STATIC_PROP(yellow, yellow, CJS_Color)
40 
41   JS_STATIC_METHOD(convert, CJS_Color)
42   JS_STATIC_METHOD(equal, CJS_Color)
43 
44  private:
45   static int ObjDefnID;
46   static const char kName[];
47   static const JSPropertySpec PropertySpecs[];
48   static const JSMethodSpec MethodSpecs[];
49 
50   CJS_Result get_black(CJS_Runtime* pRuntime);
51   CJS_Result set_black(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
52 
53   CJS_Result get_blue(CJS_Runtime* pRuntime);
54   CJS_Result set_blue(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
55 
56   CJS_Result get_cyan(CJS_Runtime* pRuntime);
57   CJS_Result set_cyan(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
58 
59   CJS_Result get_dark_gray(CJS_Runtime* pRuntime);
60   CJS_Result set_dark_gray(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
61 
62   CJS_Result get_gray(CJS_Runtime* pRuntime);
63   CJS_Result set_gray(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
64 
65   CJS_Result get_green(CJS_Runtime* pRuntime);
66   CJS_Result set_green(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
67 
68   CJS_Result get_light_gray(CJS_Runtime* pRuntime);
69   CJS_Result set_light_gray(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
70 
71   CJS_Result get_magenta(CJS_Runtime* pRuntime);
72   CJS_Result set_magenta(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
73 
74   CJS_Result get_red(CJS_Runtime* pRuntime);
75   CJS_Result set_red(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
76 
77   CJS_Result get_transparent(CJS_Runtime* pRuntime);
78   CJS_Result set_transparent(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
79 
80   CJS_Result get_white(CJS_Runtime* pRuntime);
81   CJS_Result set_white(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
82 
83   CJS_Result get_yellow(CJS_Runtime* pRuntime);
84   CJS_Result set_yellow(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
85 
86   CJS_Result convert(CJS_Runtime* pRuntime,
87                      const std::vector<v8::Local<v8::Value>>& params);
88   CJS_Result equal(CJS_Runtime* pRuntime,
89                    const std::vector<v8::Local<v8::Value>>& params);
90 
91   CJS_Result GetPropertyHelper(CJS_Runtime* pRuntime, CFX_Color* val);
92   CJS_Result SetPropertyHelper(CJS_Runtime* pRuntime,
93                                v8::Local<v8::Value> vp,
94                                CFX_Color* val);
95 
96   CFX_Color m_crTransparent;
97   CFX_Color m_crBlack;
98   CFX_Color m_crWhite;
99   CFX_Color m_crRed;
100   CFX_Color m_crGreen;
101   CFX_Color m_crBlue;
102   CFX_Color m_crCyan;
103   CFX_Color m_crMagenta;
104   CFX_Color m_crYellow;
105   CFX_Color m_crDKGray;
106   CFX_Color m_crGray;
107   CFX_Color m_crLTGray;
108 };
109 
110 #endif  // FXJS_CJS_COLOR_H_
111