Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/nsDOMCSSValueList.cpp
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 lists of values in DOM computed style */
8
9
#include "nsDOMCSSValueList.h"
10
#include "nsString.h"
11
#include "mozilla/ErrorResult.h"
12
#include "mozilla/Move.h"
13
14
using namespace mozilla;
15
using namespace mozilla::dom;
16
17
nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
18
  : CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
19
0
{
20
0
}
21
22
0
nsDOMCSSValueList::~nsDOMCSSValueList() = default;
23
24
void
25
nsDOMCSSValueList::AppendCSSValue(already_AddRefed<CSSValue> aValue)
26
0
{
27
0
  RefPtr<CSSValue> val = aValue;
28
0
  mCSSValues.AppendElement(std::move(val));
29
0
}
30
31
void
32
nsDOMCSSValueList::GetCssText(nsAString& aCssText)
33
0
{
34
0
  aCssText.Truncate();
35
0
36
0
  uint32_t count = mCSSValues.Length();
37
0
38
0
  nsAutoString separator;
39
0
  if (mCommaDelimited) {
40
0
    separator.AssignLiteral(", ");
41
0
  }
42
0
  else {
43
0
    separator.Assign(char16_t(' '));
44
0
  }
45
0
46
0
  nsAutoString tmpStr;
47
0
  for (uint32_t i = 0; i < count; ++i) {
48
0
    CSSValue *cssValue = mCSSValues[i];
49
0
    NS_ASSERTION(cssValue, "Eek!  Someone filled the value list with null CSSValues!");
50
0
    ErrorResult dummy;
51
0
    if (cssValue) {
52
0
      cssValue->GetCssText(tmpStr, dummy);
53
0
54
0
      if (tmpStr.IsEmpty()) {
55
0
56
#ifdef DEBUG_caillon
57
        NS_ERROR("Eek!  An empty CSSValue!  Bad!");
58
#endif
59
60
0
        continue;
61
0
      }
62
0
63
0
      // If this isn't the first item in the list, then
64
0
      // it's ok to append a separator.
65
0
      if (!aCssText.IsEmpty()) {
66
0
        aCssText.Append(separator);
67
0
      }
68
0
      aCssText.Append(tmpStr);
69
0
    }
70
0
  }
71
0
}
72
73
void
74
nsDOMCSSValueList::GetCssText(nsString& aCssText, ErrorResult& aRv)
75
0
{
76
0
  GetCssText(aCssText);
77
0
}
78
79
void
80
nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv)
81
0
{
82
0
  if (mReadonly) {
83
0
    aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
84
0
    return;
85
0
  }
86
0
87
0
  MOZ_ASSERT_UNREACHABLE("Can't SetCssText yet: please write me!");
88
0
}
89
90
uint16_t
91
nsDOMCSSValueList::CssValueType() const
92
0
{
93
0
  return CSSValue::CSS_VALUE_LIST;
94
0
}