summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/color.cpp
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2017-10-19 14:29:33 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-19 19:50:07 +0000
commitcbe23dbdff3f6e41843fd99cbf615000b52727ed (patch)
treef2f9e6e5f4dc8818ef15a8f72fdfdab71a848097 /fpdfsdk/javascript/color.cpp
parentc136b3146257d0f12d1347a9f1a4784372e19a56 (diff)
downloadpdfium-cbe23dbdff3f6e41843fd99cbf615000b52727ed.tar.xz
Refactoring JS Callbacks.
This CL updates the fpdfsdk/javascript callbacks to have explicit get/set methods instead of one method which worked differently depending on the mode. This allows better ownership of the passed in params, (get takes a * and set takes a const&). The Value object was changed to have To* and Set methods to make the code clearer compared to the operator<< and operator>> overloading. Bug: Change-Id: Id6ff20a4e3252adfd0a78b643e50b9f095085018 Reviewed-on: https://pdfium-review.googlesource.com/16330 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/color.cpp')
-rw-r--r--fpdfsdk/javascript/color.cpp180
1 files changed, 132 insertions, 48 deletions
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index db860d37df..f1dc26efec 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -21,10 +21,10 @@ JSPropertySpec CJS_Color::PropertySpecs[] = {
{"black", get_black_static, set_black_static},
{"blue", get_blue_static, set_blue_static},
{"cyan", get_cyan_static, set_cyan_static},
- {"dkGray", get_dkGray_static, set_dkGray_static},
+ {"dkGray", get_dark_gray_static, set_dark_gray_static},
{"gray", get_gray_static, set_gray_static},
{"green", get_green_static, set_green_static},
- {"ltGray", get_ltGray_static, set_ltGray_static},
+ {"ltGray", get_light_gray_static, set_light_gray_static},
{"magenta", get_magenta_static, set_magenta_static},
{"red", get_red_static, set_red_static},
{"transparent", get_transparent_static, set_transparent_static},
@@ -130,79 +130,163 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
}
}
-bool color::transparent(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crTransparent);
+bool color::get_transparent(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crTransparent);
}
-bool color::black(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crBlack);
+bool color::set_transparent(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crTransparent);
}
-bool color::white(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crWhite);
+bool color::get_black(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crBlack);
}
-bool color::red(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crRed);
+bool color::set_black(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crBlack);
}
-bool color::green(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crGreen);
+bool color::get_white(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crWhite);
}
-bool color::blue(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crBlue);
+bool color::set_white(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crWhite);
}
-bool color::cyan(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crCyan);
+bool color::get_red(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crRed);
}
-bool color::magenta(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crMagenta);
+bool color::set_red(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crRed);
+}
+
+bool color::get_green(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crGreen);
+}
+
+bool color::set_green(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crGreen);
+}
+
+bool color::get_blue(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crBlue);
+}
+
+bool color::set_blue(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crBlue);
+}
+
+bool color::get_cyan(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crCyan);
+}
+
+bool color::set_cyan(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crCyan);
}
-bool color::yellow(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crYellow);
+bool color::get_magenta(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crMagenta);
}
-bool color::dkGray(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crDKGray);
+bool color::set_magenta(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crMagenta);
}
-bool color::gray(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crGray);
+bool color::get_yellow(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crYellow);
}
-bool color::ltGray(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- WideString& sError) {
- return PropertyHelper(pRuntime, vp, &m_crLTGray);
+bool color::set_yellow(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crYellow);
}
-bool color::PropertyHelper(CJS_Runtime* pRuntime,
- CJS_PropValue& vp,
- CFX_Color* var) {
+bool color::get_dark_gray(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crDKGray);
+}
+
+bool color::set_dark_gray(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crDKGray);
+}
+
+bool color::get_gray(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crGray);
+}
+
+bool color::set_gray(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crGray);
+}
+
+bool color::get_light_gray(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ WideString* sError) {
+ return GetPropertyHelper(pRuntime, vp, &m_crLTGray);
+}
+
+bool color::set_light_gray(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ WideString* sError) {
+ return SetPropertyHelper(pRuntime, vp, &m_crLTGray);
+}
+
+bool color::GetPropertyHelper(CJS_Runtime* pRuntime,
+ CJS_PropValue* vp,
+ CFX_Color* var) {
CJS_Array array;
- if (vp.IsGetting()) {
ConvertPWLColorToArray(pRuntime, *var, &array);
- vp << array;
+ vp->Set(array);
return true;
- }
+}
+
+bool color::SetPropertyHelper(CJS_Runtime* pRuntime,
+ const CJS_PropValue& vp,
+ CFX_Color* var) {
+ CJS_Array array;
if (!vp.GetJSValue()->ConvertToArray(pRuntime, array))
return false;