Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/nsROCSSPrimitiveValue.h
Line
Count
Source (jump to first uncovered line)
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
/* DOM object representing values in DOM computed style */
8
9
#ifndef nsROCSSPrimitiveValue_h___
10
#define nsROCSSPrimitiveValue_h___
11
12
#include "nsCSSKeywords.h"
13
#include "CSSValue.h"
14
#include "nsCOMPtr.h"
15
#include "nsCoord.h"
16
17
class nsIURI;
18
class nsDOMCSSRect;
19
class nsDOMCSSRGBColor;
20
21
/**
22
 * Read-only CSS primitive value - a DOM object representing values in DOM
23
 * computed style.
24
 */
25
class nsROCSSPrimitiveValue final : public mozilla::dom::CSSValue
26
{
27
public:
28
  enum : uint16_t {
29
    CSS_UNKNOWN,
30
    CSS_NUMBER,
31
    CSS_PERCENTAGE,
32
    CSS_EMS,
33
    CSS_EXS,
34
    CSS_PX,
35
    CSS_CM,
36
    CSS_MM,
37
    CSS_IN,
38
    CSS_PT,
39
    CSS_PC,
40
    CSS_DEG,
41
    CSS_RAD,
42
    CSS_GRAD,
43
    CSS_MS,
44
    CSS_S,
45
    CSS_HZ,
46
    CSS_KHZ,
47
    CSS_DIMENSION,
48
    CSS_STRING,
49
    CSS_URI,
50
    CSS_IDENT,
51
    CSS_ATTR,
52
    CSS_COUNTER,
53
    CSS_RECT,
54
    CSS_RGBCOLOR,
55
    CSS_TURN,
56
    CSS_NUMBER_INT32,
57
    CSS_NUMBER_UINT32,
58
  };
59
60
  // CSSValue
61
  void GetCssText(nsString& aText, mozilla::ErrorResult& aRv) final;
62
  void SetCssText(const nsAString& aText, mozilla::ErrorResult& aRv) final;
63
  uint16_t CssValueType() const final;
64
65
  // CSSPrimitiveValue
66
  uint16_t PrimitiveType();
67
  void SetFloatValue(uint16_t aUnitType, float aValue,
68
                     mozilla::ErrorResult& aRv);
69
  float GetFloatValue(uint16_t aUnitType, mozilla::ErrorResult& aRv);
70
  void GetStringValue(nsString& aString, mozilla::ErrorResult& aRv);
71
  void SetStringValue(uint16_t aUnitType, const nsAString& aString,
72
                      mozilla::ErrorResult& aRv);
73
  void GetCounterValue(mozilla::ErrorResult& aRv);
74
  nsDOMCSSRect* GetRectValue(mozilla::ErrorResult& aRv);
75
  nsDOMCSSRGBColor *GetRGBColorValue(mozilla::ErrorResult& aRv);
76
77
  // nsROCSSPrimitiveValue
78
  nsROCSSPrimitiveValue();
79
80
  nsresult GetCssText(nsAString& aText);
81
  void SetNumber(float aValue);
82
  void SetNumber(int32_t aValue);
83
  void SetNumber(uint32_t aValue);
84
  void SetPercent(float aValue);
85
  void SetDegree(float aValue);
86
  void SetGrad(float aValue);
87
  void SetRadian(float aValue);
88
  void SetTurn(float aValue);
89
  void SetAppUnits(nscoord aValue);
90
  void SetAppUnits(float aValue);
91
  void SetIdent(nsCSSKeyword aKeyword);
92
  // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
93
  void SetString(const nsACString& aString, uint16_t aType = CSS_STRING);
94
  // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
95
  void SetString(const nsAString& aString, uint16_t aType = CSS_STRING);
96
  void SetURI(nsIURI *aURI);
97
  void SetColor(nsDOMCSSRGBColor* aColor);
98
  void SetRect(nsDOMCSSRect* aRect);
99
  void SetTime(float aValue);
100
  void Reset();
101
102
  virtual ~nsROCSSPrimitiveValue();
103
protected:
104
105
  uint16_t mType;
106
107
  union {
108
    nscoord         mAppUnits;
109
    float           mFloat;
110
    int32_t         mInt32;
111
    uint32_t        mUint32;
112
    // These can't be nsCOMPtr/nsRefPtr's because they are used inside a union.
113
    nsDOMCSSRGBColor* MOZ_OWNING_REF mColor;
114
    nsDOMCSSRect* MOZ_OWNING_REF mRect;
115
    char16_t*      mString;
116
    nsIURI* MOZ_OWNING_REF mURI;
117
    nsCSSKeyword    mKeyword;
118
  } mValue;
119
};
120
121
inline nsROCSSPrimitiveValue*
122
mozilla::dom::CSSValue::AsPrimitiveValue()
123
0
{
124
0
  return CssValueType() == mozilla::dom::CSSValue::CSS_PRIMITIVE_VALUE
125
0
    ? static_cast<nsROCSSPrimitiveValue*>(this) : nullptr;
126
0
}
127
128
#endif /* nsROCSSPrimitiveValue_h___ */