StyleColorInlines.h (2342B)
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 /* Inline functions for StyleColor (aka values::computed::Color) */ 8 9 #ifndef mozilla_StyleColorInlines_h_ 10 #define mozilla_StyleColorInlines_h_ 11 12 #include "mozilla/ServoStyleConsts.h" 13 #include "nsColor.h" 14 #include "nsStyleUtil.h" 15 16 namespace mozilla { 17 18 inline StyleAbsoluteColor StyleAbsoluteColor::FromColor(nscolor aColor) { 19 return StyleAbsoluteColor::SrgbLegacy( 20 NS_GET_R(aColor) / 255.0f, NS_GET_G(aColor) / 255.0f, 21 NS_GET_B(aColor) / 255.0f, NS_GET_A(aColor) / 255.0f); 22 } 23 24 // static 25 inline StyleAbsoluteColor StyleAbsoluteColor::SrgbLegacy(float red, float green, 26 float blue, 27 float alpha) { 28 const auto ToLegacyComponent = [](float aF) { 29 if (MOZ_UNLIKELY(!std::isfinite(aF))) { 30 return 0.0f; 31 } 32 return aF; 33 }; 34 35 return StyleAbsoluteColor{ 36 StyleColorComponents{ToLegacyComponent(red), ToLegacyComponent(green), 37 ToLegacyComponent(blue)}, 38 alpha, StyleColorSpace::Srgb, StyleColorFlags::IS_LEGACY_SRGB}; 39 } 40 41 template <> 42 inline StyleColor StyleColor::FromColor(nscolor aColor) { 43 return StyleColor::Absolute(StyleAbsoluteColor::FromColor(aColor)); 44 } 45 46 template <> 47 inline StyleColor StyleColor::Transparent() { 48 return StyleColor::Absolute(StyleAbsoluteColor::TRANSPARENT_BLACK); 49 } 50 51 template <> 52 inline StyleColor StyleColor::Black() { 53 return StyleColor::Absolute(StyleAbsoluteColor::BLACK); 54 } 55 56 template <> 57 inline StyleColor StyleColor::White() { 58 return StyleColor::Absolute(StyleAbsoluteColor::WHITE); 59 } 60 61 template <> 62 StyleAbsoluteColor StyleColor::ResolveColor(const StyleAbsoluteColor&) const; 63 64 template <> 65 nscolor StyleColor::CalcColor(const StyleAbsoluteColor&) const; 66 67 template <> 68 nscolor StyleColor::CalcColor(nscolor) const; 69 70 template <> 71 nscolor StyleColor::CalcColor(const ComputedStyle&) const; 72 73 template <> 74 nscolor StyleColor::CalcColor(const nsIFrame*) const; 75 76 } // namespace mozilla 77 78 #endif // mozilla_StyleColor_h_