layout/style/nsDOMCSSValueList.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsDOMCSSValueList.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/* DOM object representing lists of values in DOM computed style */
     1.9 +
    1.10 +#include "nsDOMCSSValueList.h"
    1.11 +#include "mozilla/dom/CSSValueListBinding.h"
    1.12 +#include "nsAutoPtr.h"
    1.13 +
    1.14 +using namespace mozilla;
    1.15 +
    1.16 +nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
    1.17 +  : CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
    1.18 +{
    1.19 +  SetIsDOMBinding();
    1.20 +}
    1.21 +
    1.22 +nsDOMCSSValueList::~nsDOMCSSValueList()
    1.23 +{
    1.24 +}
    1.25 +
    1.26 +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList)
    1.27 +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList)
    1.28 +
    1.29 +// QueryInterface implementation for nsDOMCSSValueList
    1.30 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList)
    1.31 +  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    1.32 +  NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
    1.33 +  NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
    1.34 +  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue)
    1.35 +NS_INTERFACE_MAP_END
    1.36 +
    1.37 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSValueList, mCSSValues)
    1.38 +
    1.39 +JSObject*
    1.40 +nsDOMCSSValueList::WrapObject(JSContext *cx)
    1.41 +{
    1.42 +  return dom::CSSValueListBinding::Wrap(cx, this);
    1.43 +}
    1.44 +
    1.45 +void
    1.46 +nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue)
    1.47 +{
    1.48 +  mCSSValues.AppendElement(aValue);
    1.49 +}
    1.50 +
    1.51 +// nsIDOMCSSValue
    1.52 +
    1.53 +NS_IMETHODIMP
    1.54 +nsDOMCSSValueList::GetCssText(nsAString& aCssText)
    1.55 +{
    1.56 +  aCssText.Truncate();
    1.57 +
    1.58 +  uint32_t count = mCSSValues.Length();
    1.59 +
    1.60 +  nsAutoString separator;
    1.61 +  if (mCommaDelimited) {
    1.62 +    separator.AssignLiteral(", ");
    1.63 +  }
    1.64 +  else {
    1.65 +    separator.Assign(char16_t(' '));
    1.66 +  }
    1.67 +
    1.68 +  nsAutoString tmpStr;
    1.69 +  for (uint32_t i = 0; i < count; ++i) {
    1.70 +    CSSValue *cssValue = mCSSValues[i];
    1.71 +    NS_ASSERTION(cssValue, "Eek!  Someone filled the value list with null CSSValues!");
    1.72 +    ErrorResult dummy;
    1.73 +    if (cssValue) {
    1.74 +      cssValue->GetCssText(tmpStr, dummy);
    1.75 +
    1.76 +      if (tmpStr.IsEmpty()) {
    1.77 +
    1.78 +#ifdef DEBUG_caillon
    1.79 +        NS_ERROR("Eek!  An empty CSSValue!  Bad!");
    1.80 +#endif
    1.81 +
    1.82 +        continue;
    1.83 +      }
    1.84 +
    1.85 +      // If this isn't the first item in the list, then
    1.86 +      // it's ok to append a separator.
    1.87 +      if (!aCssText.IsEmpty()) {
    1.88 +        aCssText.Append(separator);
    1.89 +      }
    1.90 +      aCssText.Append(tmpStr);
    1.91 +    }
    1.92 +  }
    1.93 +
    1.94 +  return NS_OK;
    1.95 +}
    1.96 +
    1.97 +void
    1.98 +nsDOMCSSValueList::GetCssText(nsString& aText, ErrorResult& aRv)
    1.99 +{
   1.100 +  aRv = GetCssText(aText);
   1.101 +}
   1.102 +
   1.103 +NS_IMETHODIMP
   1.104 +nsDOMCSSValueList::SetCssText(const nsAString& aCssText)
   1.105 +{
   1.106 +  if (mReadonly) {
   1.107 +    return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
   1.108 +  }
   1.109 +
   1.110 +  NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
   1.111 +  return NS_OK;
   1.112 +}
   1.113 +
   1.114 +void
   1.115 +nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv)
   1.116 +{
   1.117 +  aRv = SetCssText(aText);
   1.118 +}
   1.119 +
   1.120 +NS_IMETHODIMP
   1.121 +nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType)
   1.122 +{
   1.123 +  NS_ENSURE_ARG_POINTER(aValueType);
   1.124 +  *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
   1.125 +  return NS_OK;
   1.126 +}
   1.127 +
   1.128 +uint16_t
   1.129 +nsDOMCSSValueList::CssValueType() const
   1.130 +{
   1.131 +  return nsIDOMCSSValue::CSS_VALUE_LIST;
   1.132 +}

mercurial