StyleComplexColor.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* represent a color combines a numeric color and currentcolor */
  6. #ifndef mozilla_StyleComplexColor_h_
  7. #define mozilla_StyleComplexColor_h_
  8. #include "nsColor.h"
  9. namespace mozilla {
  10. /**
  11. * This struct represents a combined color from a numeric color and
  12. * the current foreground color (currentcolor keyword).
  13. * Conceptually, the formula is "color * (1 - p) + currentcolor * p"
  14. * where p is mForegroundRatio. See mozilla::LinearBlendColors for
  15. * the actual algorithm.
  16. */
  17. struct StyleComplexColor
  18. {
  19. nscolor mColor;
  20. uint8_t mForegroundRatio;
  21. // Whether the complex color represents a computed-value time auto
  22. // value. This is only a flag indicating that this value should not
  23. // be interpolatable with other colors, while other fields still
  24. // represents the actual used color of this value.
  25. bool mIsAuto;
  26. static StyleComplexColor FromColor(nscolor aColor) {
  27. return {aColor, 0, false};
  28. }
  29. static StyleComplexColor CurrentColor() {
  30. return {NS_RGBA(0, 0, 0, 0), 255, false};
  31. }
  32. static StyleComplexColor Auto() {
  33. return {NS_RGBA(0, 0, 0, 0), 255, true};
  34. }
  35. bool IsNumericColor() const { return mForegroundRatio == 0; }
  36. bool IsCurrentColor() const { return mForegroundRatio == 255; }
  37. bool operator==(const StyleComplexColor& aOther) const {
  38. return mForegroundRatio == aOther.mForegroundRatio &&
  39. (IsCurrentColor() || mColor == aOther.mColor) &&
  40. mIsAuto == aOther.mIsAuto;
  41. }
  42. bool operator!=(const StyleComplexColor& aOther) const {
  43. return !(*this == aOther);
  44. }
  45. };
  46. }
  47. #endif // mozilla_StyleComplexColor_h_