color_util.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_COMMON_COLOR_UTIL_H_
  5. #define ELECTRON_SHELL_COMMON_COLOR_UTIL_H_
  6. #include <string>
  7. #include "third_party/skia/include/core/SkColor.h"
  8. // SkColor is a typedef for uint32_t, this wrapper is to tag an SkColor for
  9. // ease of use in gin converters.
  10. struct WrappedSkColor {
  11. WrappedSkColor() {}
  12. WrappedSkColor(SkColor c) : value(c) {} // NOLINT(runtime/explicit)
  13. SkColor value;
  14. operator SkColor() const { return value; }
  15. };
  16. namespace electron {
  17. // Parses a CSS-style color string from hex, rgb(), rgba(),
  18. // hsl(), hsla(), or color name formats.
  19. SkColor ParseCSSColor(const std::string& color_string);
  20. // Convert color to RGB hex value like "#RRGGBB".
  21. std::string ToRGBHex(SkColor color);
  22. // Convert color to RGBA hex value like "#RRGGBBAA".
  23. std::string ToRGBAHex(SkColor color, bool include_hash = true);
  24. } // namespace electron
  25. #endif // ELECTRON_SHELL_COMMON_COLOR_UTIL_H_