2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* DOM object representing values in DOM computed style */
|
|
|
|
|
|
|
|
#ifndef nsROCSSPrimitiveValue_h___
|
|
|
|
#define nsROCSSPrimitiveValue_h___
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
#include "nsIDOMCSSValue.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMCSSPrimitiveValue.h"
|
2007-07-22 10:58:37 -07:00
|
|
|
#include "nsCSSKeywords.h"
|
2012-10-01 09:49:41 -07:00
|
|
|
#include "CSSValue.h"
|
2013-03-02 16:31:48 -08:00
|
|
|
#include "nsCOMPtr.h"
|
2012-10-01 09:49:41 -07:00
|
|
|
#include "nsCoord.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-03 13:11:34 -07:00
|
|
|
class nsIURI;
|
2012-12-25 19:01:06 -08:00
|
|
|
class nsDOMCSSRect;
|
2010-06-03 13:11:34 -07:00
|
|
|
class nsDOMCSSRGBColor;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-29 09:29:30 -07:00
|
|
|
// There is no CSS_TURN constant on the CSSPrimitiveValue interface,
|
|
|
|
// since that unit is newer than DOM Level 2 Style, and CSS OM will
|
|
|
|
// probably expose CSS values in some other way in the future. We
|
|
|
|
// use this value in mType for "turn"-unit angles, but we define it
|
|
|
|
// here to avoid exposing it to content.
|
|
|
|
#define CSS_TURN 30U
|
|
|
|
// Likewise we have some internal aliases for CSS_NUMBER that we don't
|
|
|
|
// want to expose.
|
|
|
|
#define CSS_NUMBER_INT32 31U
|
|
|
|
#define CSS_NUMBER_UINT32 32U
|
|
|
|
|
2011-09-08 04:15:00 -07:00
|
|
|
/**
|
|
|
|
* Read-only CSS primitive value - a DOM object representing values in DOM
|
|
|
|
* computed style.
|
|
|
|
*/
|
2012-10-01 09:49:41 -07:00
|
|
|
class nsROCSSPrimitiveValue MOZ_FINAL : public mozilla::dom::CSSValue,
|
|
|
|
public nsIDOMCSSPrimitiveValue
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsROCSSPrimitiveValue, mozilla::dom::CSSValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMCSSPrimitiveValue
|
|
|
|
NS_DECL_NSIDOMCSSPRIMITIVEVALUE
|
|
|
|
|
|
|
|
// nsIDOMCSSValue
|
|
|
|
NS_DECL_NSIDOMCSSVALUE
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
// CSSValue
|
|
|
|
virtual void GetCssText(nsString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL;
|
|
|
|
virtual void SetCssText(const nsAString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL;
|
|
|
|
virtual uint16_t CssValueType() const MOZ_OVERRIDE MOZ_FINAL;
|
|
|
|
|
|
|
|
// CSSPrimitiveValue
|
|
|
|
uint16_t PrimitiveType()
|
|
|
|
{
|
2013-07-25 23:02:33 -07:00
|
|
|
// New value types were introduced but not added to CSS OM.
|
|
|
|
// Return CSS_UNKNOWN to avoid exposing CSS_TURN to content.
|
|
|
|
if (mType > CSS_RGBCOLOR) {
|
2014-03-29 09:29:30 -07:00
|
|
|
if (mType == CSS_NUMBER_INT32 || mType == CSS_NUMBER_UINT32) {
|
|
|
|
return CSS_NUMBER;
|
|
|
|
}
|
2013-07-25 23:02:33 -07:00
|
|
|
return CSS_UNKNOWN;
|
|
|
|
}
|
2012-10-01 09:49:41 -07:00
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
void SetFloatValue(uint16_t aUnitType, float aValue,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
float GetFloatValue(uint16_t aUnitType, mozilla::ErrorResult& aRv);
|
|
|
|
void GetStringValue(nsString& aString, mozilla::ErrorResult& aRv);
|
|
|
|
void SetStringValue(uint16_t aUnitType, const nsAString& aString,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
already_AddRefed<nsIDOMCounter> GetCounterValue(mozilla::ErrorResult& aRv);
|
2012-12-26 09:02:37 -08:00
|
|
|
nsDOMCSSRect* GetRectValue(mozilla::ErrorResult& aRv);
|
2012-10-24 17:43:56 -07:00
|
|
|
nsDOMCSSRGBColor *GetRGBColorValue(mozilla::ErrorResult& aRv);
|
2012-10-01 09:49:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsROCSSPrimitiveValue
|
2010-08-13 02:58:04 -07:00
|
|
|
nsROCSSPrimitiveValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-03 13:11:34 -07:00
|
|
|
void SetNumber(float aValue);
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetNumber(int32_t aValue);
|
|
|
|
void SetNumber(uint32_t aValue);
|
2010-06-03 13:11:34 -07:00
|
|
|
void SetPercent(float aValue);
|
2013-07-25 23:02:33 -07:00
|
|
|
void SetDegree(float aValue);
|
|
|
|
void SetGrad(float aValue);
|
|
|
|
void SetRadian(float aValue);
|
|
|
|
void SetTurn(float aValue);
|
2010-06-03 13:11:34 -07:00
|
|
|
void SetAppUnits(nscoord aValue);
|
|
|
|
void SetAppUnits(float aValue);
|
|
|
|
void SetIdent(nsCSSKeyword aKeyword);
|
2007-07-22 10:58:37 -07:00
|
|
|
// FIXME: CSS_STRING should imply a string with "" and a need for escaping.
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetString(const nsACString& aString, uint16_t aType = CSS_STRING);
|
2007-07-22 10:58:37 -07:00
|
|
|
// FIXME: CSS_STRING should imply a string with "" and a need for escaping.
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetString(const nsAString& aString, uint16_t aType = CSS_STRING);
|
2010-06-03 13:11:34 -07:00
|
|
|
void SetURI(nsIURI *aURI);
|
|
|
|
void SetColor(nsDOMCSSRGBColor* aColor);
|
2012-12-25 19:01:06 -08:00
|
|
|
void SetRect(nsDOMCSSRect* aRect);
|
2010-06-03 13:11:34 -07:00
|
|
|
void SetTime(float aValue);
|
|
|
|
void Reset();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject *WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2012-10-01 09:49:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2014-06-26 09:29:05 -07:00
|
|
|
~nsROCSSPrimitiveValue();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mType;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
union {
|
|
|
|
nscoord mAppUnits;
|
|
|
|
float mFloat;
|
2014-03-29 09:29:30 -07:00
|
|
|
int32_t mInt32;
|
|
|
|
uint32_t mUint32;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDOMCSSRGBColor* mColor;
|
2012-12-25 19:01:06 -08:00
|
|
|
nsDOMCSSRect* mRect;
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t* mString;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI* mURI;
|
2009-01-22 17:28:14 -08:00
|
|
|
nsCSSKeyword mKeyword;
|
2007-03-22 10:30:00 -07:00
|
|
|
} mValue;
|
|
|
|
};
|
|
|
|
|
2012-10-24 16:38:52 -07:00
|
|
|
inline nsROCSSPrimitiveValue *mozilla::dom::CSSValue::AsPrimitiveValue()
|
|
|
|
{
|
|
|
|
return CssValueType() == nsIDOMCSSValue::CSS_PRIMITIVE_VALUE ?
|
|
|
|
static_cast<nsROCSSPrimitiveValue*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* nsROCSSPrimitiveValue_h___ */
|
|
|
|
|