1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* represent a color combines a numeric color and currentcolor */ 8 9 #ifndef mozilla_StyleComplexColor_h_ 10 #define mozilla_StyleComplexColor_h_ 11 12 #include "nsColor.h" 13 14 namespace mozilla { 15 16 /** 17 * This struct represents a combined color from a numeric color and 18 * the current foreground color (currentcolor keyword). 19 * Conceptually, the formula is "color * (1 - p) + currentcolor * p" 20 * where p is mForegroundRatio. See mozilla::LinearBlendColors for 21 * the actual algorithm. 22 */ 23 struct StyleComplexColor 24 { 25 nscolor mColor; 26 uint8_t mForegroundRatio; 27 FromColorStyleComplexColor28 static StyleComplexColor FromColor(nscolor aColor) { return {aColor, 0}; } CurrentColorStyleComplexColor29 static StyleComplexColor CurrentColor() { return {NS_RGBA(0, 0, 0, 0), 255}; } 30 IsNumericColorStyleComplexColor31 bool IsNumericColor() const { return mForegroundRatio == 0; } IsCurrentColorStyleComplexColor32 bool IsCurrentColor() const { return mForegroundRatio == 255; } 33 34 bool operator==(const StyleComplexColor& aOther) const { 35 return mForegroundRatio == aOther.mForegroundRatio && 36 (IsCurrentColor() || mColor == aOther.mColor); 37 } 38 bool operator!=(const StyleComplexColor& aOther) const { 39 return !(*this == aOther); 40 } 41 }; 42 43 } 44 45 #endif // mozilla_StyleComplexColor_h_ 46