layout/style/nsROCSSPrimitiveValue.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsROCSSPrimitiveValue.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* DOM object representing values in DOM computed style */
    1.10 +
    1.11 +#ifndef nsROCSSPrimitiveValue_h___
    1.12 +#define nsROCSSPrimitiveValue_h___
    1.13 +
    1.14 +#include "nsIDOMCSSValue.h"
    1.15 +#include "nsIDOMCSSPrimitiveValue.h"
    1.16 +#include "nsCSSKeywords.h"
    1.17 +#include "CSSValue.h"
    1.18 +#include "nsCOMPtr.h"
    1.19 +#include "nsCoord.h"
    1.20 +
    1.21 +class nsIURI;
    1.22 +class nsDOMCSSRect;
    1.23 +class nsDOMCSSRGBColor;
    1.24 +
    1.25 +// There is no CSS_TURN constant on the CSSPrimitiveValue interface,
    1.26 +// since that unit is newer than DOM Level 2 Style, and CSS OM will
    1.27 +// probably expose CSS values in some other way in the future.  We
    1.28 +// use this value in mType for "turn"-unit angles, but we define it
    1.29 +// here to avoid exposing it to content.
    1.30 +#define CSS_TURN 30U
    1.31 +// Likewise we have some internal aliases for CSS_NUMBER that we don't
    1.32 +// want to expose.
    1.33 +#define CSS_NUMBER_INT32 31U
    1.34 +#define CSS_NUMBER_UINT32 32U
    1.35 +
    1.36 +/**
    1.37 + * Read-only CSS primitive value - a DOM object representing values in DOM
    1.38 + * computed style.
    1.39 + */
    1.40 +class nsROCSSPrimitiveValue MOZ_FINAL : public mozilla::dom::CSSValue,
    1.41 +  public nsIDOMCSSPrimitiveValue
    1.42 +{
    1.43 +public:
    1.44 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.45 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsROCSSPrimitiveValue, mozilla::dom::CSSValue)
    1.46 +
    1.47 +  // nsIDOMCSSPrimitiveValue
    1.48 +  NS_DECL_NSIDOMCSSPRIMITIVEVALUE
    1.49 +
    1.50 +  // nsIDOMCSSValue
    1.51 +  NS_DECL_NSIDOMCSSVALUE
    1.52 +
    1.53 +  // CSSValue
    1.54 +  virtual void GetCssText(nsString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL;
    1.55 +  virtual void SetCssText(const nsAString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL;
    1.56 +  virtual uint16_t CssValueType() const MOZ_OVERRIDE MOZ_FINAL;
    1.57 +
    1.58 +  // CSSPrimitiveValue
    1.59 +  uint16_t PrimitiveType()
    1.60 +  {
    1.61 +    // New value types were introduced but not added to CSS OM.
    1.62 +    // Return CSS_UNKNOWN to avoid exposing CSS_TURN to content.
    1.63 +    if (mType > CSS_RGBCOLOR) {
    1.64 +      if (mType == CSS_NUMBER_INT32 || mType == CSS_NUMBER_UINT32) {
    1.65 +        return CSS_NUMBER;
    1.66 +      }
    1.67 +      return CSS_UNKNOWN;
    1.68 +    }
    1.69 +    return mType;
    1.70 +  }
    1.71 +  void SetFloatValue(uint16_t aUnitType, float aValue,
    1.72 +                     mozilla::ErrorResult& aRv);
    1.73 +  float GetFloatValue(uint16_t aUnitType, mozilla::ErrorResult& aRv);
    1.74 +  void GetStringValue(nsString& aString, mozilla::ErrorResult& aRv);
    1.75 +  void SetStringValue(uint16_t aUnitType, const nsAString& aString,
    1.76 +                      mozilla::ErrorResult& aRv);
    1.77 +  already_AddRefed<nsIDOMCounter> GetCounterValue(mozilla::ErrorResult& aRv);
    1.78 +  nsDOMCSSRect* GetRectValue(mozilla::ErrorResult& aRv);
    1.79 +  nsDOMCSSRGBColor *GetRGBColorValue(mozilla::ErrorResult& aRv);
    1.80 +
    1.81 +  // nsROCSSPrimitiveValue
    1.82 +  nsROCSSPrimitiveValue();
    1.83 +  ~nsROCSSPrimitiveValue();
    1.84 +
    1.85 +  void SetNumber(float aValue);
    1.86 +  void SetNumber(int32_t aValue);
    1.87 +  void SetNumber(uint32_t aValue);
    1.88 +  void SetPercent(float aValue);
    1.89 +  void SetDegree(float aValue);
    1.90 +  void SetGrad(float aValue);
    1.91 +  void SetRadian(float aValue);
    1.92 +  void SetTurn(float aValue);
    1.93 +  void SetAppUnits(nscoord aValue);
    1.94 +  void SetAppUnits(float aValue);
    1.95 +  void SetIdent(nsCSSKeyword aKeyword);
    1.96 +  // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
    1.97 +  void SetString(const nsACString& aString, uint16_t aType = CSS_STRING);
    1.98 +  // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
    1.99 +  void SetString(const nsAString& aString, uint16_t aType = CSS_STRING);
   1.100 +  void SetURI(nsIURI *aURI);
   1.101 +  void SetColor(nsDOMCSSRGBColor* aColor);
   1.102 +  void SetRect(nsDOMCSSRect* aRect);
   1.103 +  void SetTime(float aValue);
   1.104 +  void Reset();
   1.105 +
   1.106 +  nsISupports* GetParentObject() const
   1.107 +  {
   1.108 +    return nullptr;
   1.109 +  }
   1.110 +
   1.111 +  virtual JSObject *WrapObject(JSContext *cx) MOZ_OVERRIDE;
   1.112 +
   1.113 +private:
   1.114 +  uint16_t mType;
   1.115 +
   1.116 +  union {
   1.117 +    nscoord         mAppUnits;
   1.118 +    float           mFloat;
   1.119 +    int32_t         mInt32;
   1.120 +    uint32_t        mUint32;
   1.121 +    nsDOMCSSRGBColor* mColor;
   1.122 +    nsDOMCSSRect*     mRect;
   1.123 +    char16_t*      mString;
   1.124 +    nsIURI*         mURI;
   1.125 +    nsCSSKeyword    mKeyword;
   1.126 +  } mValue;
   1.127 +};
   1.128 +
   1.129 +inline nsROCSSPrimitiveValue *mozilla::dom::CSSValue::AsPrimitiveValue()
   1.130 +{
   1.131 +  return CssValueType() == nsIDOMCSSValue::CSS_PRIMITIVE_VALUE ?
   1.132 +    static_cast<nsROCSSPrimitiveValue*>(this) : nullptr;
   1.133 +}
   1.134 +
   1.135 +#endif /* nsROCSSPrimitiveValue_h___ */
   1.136 +

mercurial