tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsDOMCSSValueList.cpp (1761B)


      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 
     11 #include <utility>
     12 
     13 #include "mozilla/ErrorResult.h"
     14 #include "nsString.h"
     15 
     16 using namespace mozilla;
     17 using namespace mozilla::dom;
     18 
     19 nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited)
     20    : CSSValue(), mCommaDelimited(aCommaDelimited) {}
     21 
     22 nsDOMCSSValueList::~nsDOMCSSValueList() = default;
     23 
     24 void nsDOMCSSValueList::AppendCSSValue(already_AddRefed<CSSValue> aValue) {
     25  RefPtr<CSSValue> val = aValue;
     26  mCSSValues.AppendElement(std::move(val));
     27 }
     28 
     29 void nsDOMCSSValueList::GetCssText(nsAString& aCssText) {
     30  aCssText.Truncate();
     31 
     32  uint32_t count = mCSSValues.Length();
     33 
     34  nsAutoString separator;
     35  if (mCommaDelimited) {
     36    separator.AssignLiteral(", ");
     37  } else {
     38    separator.Assign(char16_t(' '));
     39  }
     40 
     41  nsAutoString tmpStr;
     42  for (uint32_t i = 0; i < count; ++i) {
     43    CSSValue* cssValue = mCSSValues[i];
     44    NS_ASSERTION(cssValue,
     45                 "Eek!  Someone filled the value list with null CSSValues!");
     46    if (cssValue) {
     47      cssValue->GetCssText(tmpStr);
     48      if (tmpStr.IsEmpty()) {
     49 #ifdef DEBUG_caillon
     50        NS_ERROR("Eek!  An empty CSSValue!  Bad!");
     51 #endif
     52        continue;
     53      }
     54      // If this isn't the first item in the list, then
     55      // it's ok to append a separator.
     56      if (!aCssText.IsEmpty()) {
     57        aCssText.Append(separator);
     58      }
     59      aCssText.Append(tmpStr);
     60    }
     61  }
     62 }