tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsCSSValue.h (4518B)


      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 /* representation of simple property values within CSS declarations */
      8 
      9 #ifndef nsCSSValue_h___
     10 #define nsCSSValue_h___
     11 
     12 #include "nsCoord.h"
     13 
     14 struct RawServoCssUrlData;
     15 
     16 namespace mozilla {
     17 struct URLExtraData;
     18 class CSSStyleSheet;
     19 }  // namespace mozilla
     20 
     21 // Forward declaration copied here since ServoBindings.h #includes nsCSSValue.h.
     22 extern "C" {
     23 mozilla::URLExtraData* Servo_CssUrlData_GetExtraData(const RawServoCssUrlData*);
     24 bool Servo_CssUrlData_IsLocalRef(const RawServoCssUrlData* url);
     25 }
     26 
     27 enum nsCSSUnit : uint32_t {
     28  eCSSUnit_Null = 0,  // (n/a) null unit, value is not specified
     29 
     30  eCSSUnit_Percent = 100,  // (1.0 == 100%) value is percentage of
     31                           // something
     32  eCSSUnit_Number = 101,   // value is numeric (usually multiplier,
     33                           // different behavior than percent)
     34 
     35  // Font relative measure
     36  eCSSUnit_EM = 800,               // == current font size (em)
     37  eCSSUnit_XHeight = 801,          // distance from top of lower case x to
     38                                   // baseline (ex)
     39  eCSSUnit_Char = 802,             // number of characters, used for width with
     40                                   // monospace font (ch)
     41  eCSSUnit_RootEM = 803,           // == root element font size (rem)
     42  eCSSUnit_Ideographic = 804,      // == CJK water ideograph width (ic)
     43  eCSSUnit_CapHeight = 805,        // == Capital letter height (cap)
     44  eCSSUnit_LineHeight = 806,       // == Line height (lh)
     45  eCSSUnit_RootLineHeight = 807,   // == Root line height (rlh)
     46  eCSSUnit_RootXHeight = 808,      // == Root x-height (rex)
     47  eCSSUnit_RootChar = 809,         // == Root advance measure (rch)
     48  eCSSUnit_RootIdeographic = 810,  // == Root ideographic advance measure (ric)
     49  eCSSUnit_RootCapHeight = 811,    // == Root capital letter height (rch)
     50 
     51  // Screen relative measure
     52  eCSSUnit_Point = 900,       // 4/3 of a CSS pixel
     53  eCSSUnit_Inch = 901,        // 96 CSS pixels
     54  eCSSUnit_Millimeter = 902,  // 96/25.4 CSS pixels
     55  eCSSUnit_Centimeter = 903,  // 96/2.54 CSS pixels
     56  eCSSUnit_Pica = 904,        // 12 points == 16 CSS pixls
     57  eCSSUnit_Quarter = 905,     // 96/101.6 CSS pixels
     58  eCSSUnit_Pixel = 906,       // CSS pixel unit
     59 
     60  // Viewport percentage lengths
     61  eCSSUnit_VW = 950,
     62  eCSSUnit_VH = 951,
     63  eCSSUnit_VMin = 952,
     64  eCSSUnit_VMax = 953,
     65 
     66  eCSSUnit_LastLength = eCSSUnit_VMax,
     67 };
     68 
     69 struct nsCSSValuePair;
     70 struct nsCSSValuePair_heap;
     71 struct nsCSSValueList;
     72 struct nsCSSValueList_heap;
     73 struct nsCSSValueSharedList;
     74 struct nsCSSValuePairList;
     75 struct nsCSSValuePairList_heap;
     76 
     77 class nsCSSValue {
     78 public:
     79  explicit nsCSSValue() : mUnit(eCSSUnit_Null) {}
     80 
     81  nsCSSValue(float aValue, nsCSSUnit aUnit);
     82  nsCSSValue(const nsCSSValue& aCopy);
     83  nsCSSValue(nsCSSValue&& aOther) : mUnit(aOther.mUnit), mValue(aOther.mValue) {
     84    aOther.mUnit = eCSSUnit_Null;
     85  }
     86 
     87  nsCSSValue& operator=(const nsCSSValue& aCopy);
     88  nsCSSValue& operator=(nsCSSValue&& aCopy);
     89 
     90  bool operator==(const nsCSSValue& aOther) const;
     91  bool operator!=(const nsCSSValue&) const = default;
     92 
     93  nsCSSUnit GetUnit() const { return mUnit; }
     94  bool IsLengthUnit() const {
     95    return eCSSUnit_EM <= mUnit && mUnit <= eCSSUnit_LastLength;
     96  }
     97  /**
     98   * A "pixel" length unit is a some multiple of CSS pixels.
     99   */
    100  static bool IsPixelLengthUnit(nsCSSUnit aUnit) {
    101    return eCSSUnit_Point <= aUnit && aUnit <= eCSSUnit_Pixel;
    102  }
    103  bool IsPixelLengthUnit() const { return IsPixelLengthUnit(mUnit); }
    104  static bool IsPercentLengthUnit(nsCSSUnit aUnit) {
    105    return aUnit == eCSSUnit_Percent;
    106  }
    107  static bool IsFloatUnit(nsCSSUnit aUnit) { return eCSSUnit_Number <= aUnit; }
    108 
    109  float GetPercentValue() const {
    110    MOZ_ASSERT(mUnit == eCSSUnit_Percent, "not a percent value");
    111    return mValue;
    112  }
    113 
    114  float GetFloatValue() const {
    115    MOZ_ASSERT(eCSSUnit_Number <= mUnit, "not a float value");
    116    MOZ_ASSERT(!std::isnan(mValue));
    117    return mValue;
    118  }
    119 
    120  nscoord GetPixelLength() const;
    121 
    122  void Reset() { mUnit = eCSSUnit_Null; }
    123  ~nsCSSValue() { Reset(); }
    124 
    125 public:
    126  void SetPercentValue(float aValue);
    127  void SetFloatValue(float aValue, nsCSSUnit aUnit);
    128 
    129 protected:
    130  nsCSSUnit mUnit;
    131  float mValue;
    132 };
    133 
    134 #endif /* nsCSSValue_h___ */