2016-01-10 15:28:35 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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 */
|
|
|
|
|
|
|
|
#include "nsROCSSPrimitiveValue.h"
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
#include "mozilla/dom/CSSPrimitiveValueBinding.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
2009-03-05 20:05:01 -08:00
|
|
|
#include "nsStyleUtil.h"
|
2010-06-03 13:11:34 -07:00
|
|
|
#include "nsDOMCSSRGBColor.h"
|
2012-12-25 19:01:06 -08:00
|
|
|
#include "nsDOMCSSRect.h"
|
2012-07-29 21:29:41 -07:00
|
|
|
#include "nsIURI.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-08-13 02:58:04 -07:00
|
|
|
nsROCSSPrimitiveValue::nsROCSSPrimitiveValue()
|
2012-10-01 09:49:41 -07:00
|
|
|
: CSSValue(), mType(CSS_PX)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mValue.mAppUnits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsROCSSPrimitiveValue::~nsROCSSPrimitiveValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsROCSSPrimitiveValue)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsROCSSPrimitiveValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsROCSSPrimitiveValue)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsROCSSPrimitiveValue)
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsROCSSPrimitiveValue)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsROCSSPrimitiveValue)
|
|
|
|
if (tmp->mType == CSS_URI) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mValue.mURI)
|
|
|
|
} else if (tmp->mType == CSS_RGBCOLOR) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mValue.mColor)
|
|
|
|
} else if (tmp->mType == CSS_RECT) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mValue.mRect)
|
|
|
|
}
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-10-01 09:49:41 -07:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsROCSSPrimitiveValue)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
tmp->Reset();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
nsROCSSPrimitiveValue::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2012-10-01 09:49:41 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return dom::CSSPrimitiveValueBinding::Wrap(cx, this, aGivenProto);
|
2012-10-01 09:49:41 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMCSSValue
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
nsAutoString tmpStr;
|
|
|
|
aCssText.Truncate();
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case CSS_PX :
|
|
|
|
{
|
|
|
|
float val = nsPresContext::AppUnitsToFloatCSSPixels(mValue.mAppUnits);
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(val, tmpStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
tmpStr.AppendLiteral("px");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_IDENT :
|
|
|
|
{
|
2009-01-22 17:28:14 -08:00
|
|
|
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(mValue.mKeyword),
|
|
|
|
tmpStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_STRING :
|
2007-07-22 10:58:37 -07:00
|
|
|
case CSS_COUNTER : /* FIXME: COUNTER should use an object */
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
tmpStr.Append(mValue.mString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_URI :
|
|
|
|
{
|
|
|
|
if (mValue.mURI) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString specUTF8;
|
2009-03-05 20:05:01 -08:00
|
|
|
mValue.mURI->GetSpec(specUTF8);
|
|
|
|
|
|
|
|
tmpStr.AssignLiteral("url(");
|
|
|
|
nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(specUTF8),
|
|
|
|
tmpStr);
|
2014-05-21 20:48:51 -07:00
|
|
|
tmpStr.Append(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-10-17 12:33:57 -07:00
|
|
|
// http://dev.w3.org/csswg/css3-values/#attr defines
|
|
|
|
// 'about:invalid' as the default value for url attributes,
|
|
|
|
// so let's also use it here as the default computed value
|
|
|
|
// for invalid URLs.
|
2014-05-26 11:54:10 -07:00
|
|
|
tmpStr.AssignLiteral(MOZ_UTF16("url(about:invalid)"));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-07-22 10:58:37 -07:00
|
|
|
case CSS_ATTR :
|
|
|
|
{
|
|
|
|
tmpStr.AppendLiteral("attr(");
|
|
|
|
tmpStr.Append(mValue.mString);
|
2014-01-04 07:02:17 -08:00
|
|
|
tmpStr.Append(char16_t(')'));
|
2007-07-22 10:58:37 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case CSS_PERCENTAGE :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat * 100, tmpStr);
|
2014-01-04 07:02:17 -08:00
|
|
|
tmpStr.Append(char16_t('%'));
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_NUMBER :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-03-29 09:29:30 -07:00
|
|
|
case CSS_NUMBER_INT32 :
|
|
|
|
{
|
|
|
|
tmpStr.AppendInt(mValue.mInt32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_NUMBER_UINT32 :
|
|
|
|
{
|
|
|
|
tmpStr.AppendInt(mValue.mUint32);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-25 23:02:33 -07:00
|
|
|
case CSS_DEG :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
|
2013-07-25 23:02:33 -07:00
|
|
|
tmpStr.AppendLiteral("deg");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_GRAD :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
|
2013-07-25 23:02:33 -07:00
|
|
|
tmpStr.AppendLiteral("grad");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_RAD :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
|
2013-07-25 23:02:33 -07:00
|
|
|
tmpStr.AppendLiteral("rad");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_TURN :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
|
2013-07-25 23:02:33 -07:00
|
|
|
tmpStr.AppendLiteral("turn");
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case CSS_RECT :
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mValue.mRect, "mValue.mRect should never be null");
|
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
|
|
|
nsCOMPtr<nsIDOMCSSPrimitiveValue> sideCSSValue;
|
|
|
|
nsAutoString sideValue;
|
|
|
|
tmpStr.AssignLiteral("rect(");
|
|
|
|
// get the top
|
|
|
|
result = mValue.mRect->GetTop(getter_AddRefs(sideCSSValue));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
result = sideCSSValue->GetCssText(sideValue);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
tmpStr.Append(sideValue + comma);
|
|
|
|
// get the right
|
|
|
|
result = mValue.mRect->GetRight(getter_AddRefs(sideCSSValue));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
result = sideCSSValue->GetCssText(sideValue);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
tmpStr.Append(sideValue + comma);
|
|
|
|
// get the bottom
|
|
|
|
result = mValue.mRect->GetBottom(getter_AddRefs(sideCSSValue));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
result = sideCSSValue->GetCssText(sideValue);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
tmpStr.Append(sideValue + comma);
|
|
|
|
// get the left
|
|
|
|
result = mValue.mRect->GetLeft(getter_AddRefs(sideCSSValue));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
result = sideCSSValue->GetCssText(sideValue);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
tmpStr.Append(sideValue + NS_LITERAL_STRING(")"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_RGBCOLOR :
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
|
2012-12-14 01:32:07 -08:00
|
|
|
ErrorResult error;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
|
|
|
nsAutoString colorValue;
|
|
|
|
if (mValue.mColor->HasAlpha())
|
|
|
|
tmpStr.AssignLiteral("rgba(");
|
|
|
|
else
|
|
|
|
tmpStr.AssignLiteral("rgb(");
|
|
|
|
|
|
|
|
// get the red component
|
2012-12-14 01:32:07 -08:00
|
|
|
mValue.mColor->Red()->GetCssText(colorValue, error);
|
|
|
|
if (error.Failed())
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
tmpStr.Append(colorValue + comma);
|
|
|
|
|
|
|
|
// get the green component
|
2012-12-14 01:32:07 -08:00
|
|
|
mValue.mColor->Green()->GetCssText(colorValue, error);
|
|
|
|
if (error.Failed())
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
tmpStr.Append(colorValue + comma);
|
|
|
|
|
|
|
|
// get the blue component
|
2012-12-14 01:32:07 -08:00
|
|
|
mValue.mColor->Blue()->GetCssText(colorValue, error);
|
|
|
|
if (error.Failed())
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
tmpStr.Append(colorValue);
|
|
|
|
|
|
|
|
if (mValue.mColor->HasAlpha()) {
|
|
|
|
// get the alpha component
|
2012-12-14 01:32:07 -08:00
|
|
|
mValue.mColor->Alpha()->GetCssText(colorValue, error);
|
|
|
|
if (error.Failed())
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
tmpStr.Append(comma + colorValue);
|
|
|
|
}
|
|
|
|
|
2014-05-21 20:48:50 -07:00
|
|
|
tmpStr.Append(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_S :
|
|
|
|
{
|
2013-11-20 17:00:57 -08:00
|
|
|
nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
|
2014-05-21 20:48:51 -07:00
|
|
|
tmpStr.Append('s');
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CSS_CM :
|
|
|
|
case CSS_MM :
|
|
|
|
case CSS_IN :
|
|
|
|
case CSS_PT :
|
|
|
|
case CSS_PC :
|
|
|
|
case CSS_UNKNOWN :
|
|
|
|
case CSS_EMS :
|
|
|
|
case CSS_EXS :
|
|
|
|
case CSS_MS :
|
|
|
|
case CSS_HZ :
|
|
|
|
case CSS_KHZ :
|
|
|
|
case CSS_DIMENSION :
|
|
|
|
NS_ERROR("We have a bogus value set. This should not happen");
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
aCssText.Assign(tmpStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::GetCssText(nsString& aText, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = GetCssText(aText);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsROCSSPrimitiveValue::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetCssText(const nsAString& aText, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = SetCssText(aText);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::GetCssValueType(uint16_t* aValueType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aValueType);
|
|
|
|
*aValueType = nsIDOMCSSValue::CSS_PRIMITIVE_VALUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
uint16_t
|
|
|
|
nsROCSSPrimitiveValue::CssValueType() const
|
|
|
|
{
|
|
|
|
return nsIDOMCSSValue::CSS_PRIMITIVE_VALUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMCSSPrimitiveValue
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::GetPrimitiveType(uint16_t* aPrimitiveType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrimitiveType);
|
2014-03-29 09:29:30 -07:00
|
|
|
*aPrimitiveType = PrimitiveType();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::SetFloatValue(uint16_t aUnitType, float aFloatValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetFloatValue(uint16_t aType, float aVal,
|
|
|
|
ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-01 09:49:41 -07:00
|
|
|
aRv = SetFloatValue(aType, aVal);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
float
|
|
|
|
nsROCSSPrimitiveValue::GetFloatValue(uint16_t aUnitType, ErrorResult& aRv)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aUnitType) {
|
|
|
|
case CSS_PX :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PX) {
|
|
|
|
return nsPresContext::AppUnitsToFloatCSSPixels(mValue.mAppUnits);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_CM :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PX) {
|
|
|
|
return mValue.mAppUnits * CM_PER_INCH_FLOAT /
|
|
|
|
nsPresContext::AppUnitsPerCSSInch();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_MM :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PX) {
|
|
|
|
return mValue.mAppUnits * MM_PER_INCH_FLOAT /
|
|
|
|
nsPresContext::AppUnitsPerCSSInch();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_IN :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PX) {
|
|
|
|
return mValue.mAppUnits / nsPresContext::AppUnitsPerCSSInch();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_PT :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PX) {
|
|
|
|
return mValue.mAppUnits * POINTS_PER_INCH_FLOAT /
|
|
|
|
nsPresContext::AppUnitsPerCSSInch();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_PC :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PX) {
|
|
|
|
return mValue.mAppUnits * 6.0f /
|
|
|
|
nsPresContext::AppUnitsPerCSSInch();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_PERCENTAGE :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_PERCENTAGE) {
|
|
|
|
return mValue.mFloat * 100;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_NUMBER :
|
2012-10-01 09:49:41 -07:00
|
|
|
if (mType == CSS_NUMBER) {
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
2014-03-29 09:29:30 -07:00
|
|
|
if (mType == CSS_NUMBER_INT32) {
|
|
|
|
return mValue.mInt32;
|
|
|
|
}
|
|
|
|
if (mType == CSS_NUMBER_UINT32) {
|
|
|
|
return mValue.mUint32;
|
|
|
|
}
|
2012-10-01 09:49:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_UNKNOWN :
|
|
|
|
case CSS_EMS :
|
|
|
|
case CSS_EXS :
|
|
|
|
case CSS_DEG :
|
|
|
|
case CSS_RAD :
|
|
|
|
case CSS_GRAD :
|
|
|
|
case CSS_MS :
|
|
|
|
case CSS_S :
|
|
|
|
case CSS_HZ :
|
|
|
|
case CSS_KHZ :
|
|
|
|
case CSS_DIMENSION :
|
|
|
|
case CSS_STRING :
|
|
|
|
case CSS_URI :
|
|
|
|
case CSS_IDENT :
|
|
|
|
case CSS_ATTR :
|
|
|
|
case CSS_COUNTER :
|
|
|
|
case CSS_RECT :
|
|
|
|
case CSS_RGBCOLOR :
|
2012-10-01 09:49:41 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsROCSSPrimitiveValue::GetFloatValue(uint16_t aType, float *aVal)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aVal = GetFloatValue(aType, rv);
|
2015-04-27 06:18:51 -07:00
|
|
|
return rv.StealNSResult();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::SetStringValue(uint16_t aStringType,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAString& aStringValue)
|
|
|
|
{
|
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetStringValue(uint16_t aType, const nsAString& aString,
|
|
|
|
mozilla::ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsROCSSPrimitiveValue::GetStringValue(nsAString& aReturn)
|
|
|
|
{
|
|
|
|
switch (mType) {
|
|
|
|
case CSS_IDENT:
|
2009-01-22 17:28:14 -08:00
|
|
|
CopyUTF8toUTF16(nsCSSKeywords::GetStringValue(mValue.mKeyword), aReturn);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case CSS_STRING:
|
2007-07-22 10:58:37 -07:00
|
|
|
case CSS_ATTR:
|
2007-03-22 10:30:00 -07:00
|
|
|
aReturn.Assign(mValue.mString);
|
|
|
|
break;
|
|
|
|
case CSS_URI: {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mValue.mURI)
|
|
|
|
mValue.mURI->GetSpec(spec);
|
|
|
|
CopyUTF8toUTF16(spec, aReturn);
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
aReturn.Truncate();
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::GetStringValue(nsString& aString, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = GetStringValue(aString);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsROCSSPrimitiveValue::GetCounterValue(nsIDOMCounter** aReturn)
|
|
|
|
{
|
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
already_AddRefed<nsIDOMCounter>
|
|
|
|
nsROCSSPrimitiveValue::GetCounterValue(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-26 09:02:37 -08:00
|
|
|
nsDOMCSSRect*
|
2012-10-01 09:49:41 -07:00
|
|
|
nsROCSSPrimitiveValue::GetRectValue(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mType != CSS_RECT) {
|
2012-10-01 09:49:41 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-10-01 09:49:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mValue.mRect, "mValue.mRect should never be null");
|
2012-10-01 09:49:41 -07:00
|
|
|
return mValue.mRect;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsROCSSPrimitiveValue::GetRectValue(nsIDOMRect** aRect)
|
|
|
|
{
|
|
|
|
ErrorResult error;
|
2012-12-26 09:02:37 -08:00
|
|
|
NS_IF_ADDREF(*aRect = GetRectValue(error));
|
2015-04-27 06:18:51 -07:00
|
|
|
return error.StealNSResult();
|
2012-10-01 09:49:41 -07:00
|
|
|
}
|
|
|
|
|
2012-10-24 17:43:56 -07:00
|
|
|
nsDOMCSSRGBColor*
|
2012-10-01 09:49:41 -07:00
|
|
|
nsROCSSPrimitiveValue::GetRGBColorValue(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mType != CSS_RGBCOLOR) {
|
2012-10-01 09:49:41 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-10-24 17:43:56 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
|
2012-10-01 09:49:41 -07:00
|
|
|
return mValue.mColor;
|
2010-06-03 13:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetNumber(float aValue)
|
|
|
|
{
|
2016-01-10 15:28:35 -08:00
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_NUMBER;
|
2010-06-03 13:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::SetNumber(int32_t aValue)
|
2010-06-03 13:11:34 -07:00
|
|
|
{
|
|
|
|
Reset();
|
2014-03-29 09:29:30 -07:00
|
|
|
mValue.mInt32 = aValue;
|
|
|
|
mType = CSS_NUMBER_INT32;
|
2010-06-03 13:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::SetNumber(uint32_t aValue)
|
2010-06-03 13:11:34 -07:00
|
|
|
{
|
|
|
|
Reset();
|
2014-03-29 09:29:30 -07:00
|
|
|
mValue.mUint32 = aValue;
|
|
|
|
mType = CSS_NUMBER_UINT32;
|
2010-06-03 13:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetPercent(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_PERCENTAGE;
|
|
|
|
}
|
|
|
|
|
2013-07-25 23:02:33 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetDegree(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_DEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetGrad(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_GRAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetRadian(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_RAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetTurn(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_TURN;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:11:34 -07:00
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetAppUnits(nscoord aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mAppUnits = aValue;
|
|
|
|
mType = CSS_PX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetAppUnits(float aValue)
|
|
|
|
{
|
|
|
|
SetAppUnits(NSToCoordRound(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetIdent(nsCSSKeyword aKeyword)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aKeyword != eCSSKeyword_UNKNOWN &&
|
|
|
|
0 <= aKeyword && aKeyword < eCSSKeyword_COUNT,
|
|
|
|
"bad keyword");
|
|
|
|
Reset();
|
|
|
|
mValue.mKeyword = aKeyword;
|
|
|
|
mType = CSS_IDENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: CSS_STRING should imply a string with "" and a need for escaping.
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::SetString(const nsACString& aString, uint16_t aType)
|
2010-06-03 13:11:34 -07:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
|
|
|
if (mValue.mString) {
|
|
|
|
mType = aType;
|
|
|
|
} else {
|
|
|
|
// XXXcaa We should probably let the caller know we are out of memory
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: CSS_STRING should imply a string with "" and a need for escaping.
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsROCSSPrimitiveValue::SetString(const nsAString& aString, uint16_t aType)
|
2010-06-03 13:11:34 -07:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
|
|
|
if (mValue.mString) {
|
|
|
|
mType = aType;
|
|
|
|
} else {
|
|
|
|
// XXXcaa We should probably let the caller know we are out of memory
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetURI(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mURI = aURI;
|
|
|
|
NS_IF_ADDREF(mValue.mURI);
|
|
|
|
mType = CSS_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetColor(nsDOMCSSRGBColor* aColor)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aColor, "Null RGBColor being set!");
|
|
|
|
Reset();
|
|
|
|
mValue.mColor = aColor;
|
|
|
|
if (mValue.mColor) {
|
|
|
|
NS_ADDREF(mValue.mColor);
|
|
|
|
mType = CSS_RGBCOLOR;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:11:34 -07:00
|
|
|
void
|
2012-12-25 19:01:06 -08:00
|
|
|
nsROCSSPrimitiveValue::SetRect(nsDOMCSSRect* aRect)
|
2010-06-03 13:11:34 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRect, "Null rect being set!");
|
|
|
|
Reset();
|
|
|
|
mValue.mRect = aRect;
|
|
|
|
if (mValue.mRect) {
|
|
|
|
NS_ADDREF(mValue.mRect);
|
|
|
|
mType = CSS_RECT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::SetTime(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_S;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsROCSSPrimitiveValue::Reset()
|
|
|
|
{
|
|
|
|
switch (mType) {
|
|
|
|
case CSS_IDENT:
|
|
|
|
break;
|
|
|
|
case CSS_STRING:
|
|
|
|
case CSS_ATTR:
|
|
|
|
case CSS_COUNTER: // FIXME: Counter should use an object
|
|
|
|
NS_ASSERTION(mValue.mString, "Null string should never happen");
|
2015-03-26 17:01:12 -07:00
|
|
|
free(mValue.mString);
|
2012-07-30 07:20:58 -07:00
|
|
|
mValue.mString = nullptr;
|
2010-06-03 13:11:34 -07:00
|
|
|
break;
|
|
|
|
case CSS_URI:
|
|
|
|
NS_IF_RELEASE(mValue.mURI);
|
|
|
|
break;
|
|
|
|
case CSS_RECT:
|
|
|
|
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
|
|
|
|
NS_RELEASE(mValue.mRect);
|
|
|
|
break;
|
|
|
|
case CSS_RGBCOLOR:
|
|
|
|
NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
|
|
|
|
NS_RELEASE(mValue.mColor);
|
|
|
|
break;
|
|
|
|
}
|
2012-12-18 18:29:23 -08:00
|
|
|
|
|
|
|
mType = CSS_UNKNOWN;
|
2010-06-03 13:11:34 -07:00
|
|
|
}
|