This source file includes following definitions.
- removeAll
- hasValue
- copy
- customCSSText
- equals
- equals
- hasFailedOrCanceledSubresources
- cloneForCSSOM
- traceAfterDispatch
#include "config.h"
#include "core/css/CSSValueList.h"
#include "core/css/CSSParserValues.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
CSSValueList::CSSValueList(ClassType classType, ValueListSeparator listSeparator)
: CSSValue(classType)
{
m_valueListSeparator = listSeparator;
}
CSSValueList::CSSValueList(ValueListSeparator listSeparator)
: CSSValue(ValueListClass)
{
m_valueListSeparator = listSeparator;
}
CSSValueList::CSSValueList(CSSParserValueList* parserValues)
: CSSValue(ValueListClass)
{
m_valueListSeparator = SpaceSeparator;
if (parserValues) {
m_values.reserveInitialCapacity(parserValues->size());
for (unsigned i = 0; i < parserValues->size(); ++i)
m_values.uncheckedAppend(parserValues->valueAt(i)->createCSSValue());
}
}
bool CSSValueList::removeAll(CSSValue* val)
{
bool found = false;
for (size_t index = 0; index < m_values.size(); index++) {
RefPtrWillBeMember<CSSValue>& value = m_values.at(index);
if (value && val && value->equals(*val)) {
m_values.remove(index);
found = true;
}
}
return found;
}
bool CSSValueList::hasValue(CSSValue* val) const
{
for (size_t index = 0; index < m_values.size(); index++) {
const RefPtrWillBeMember<CSSValue>& value = m_values.at(index);
if (value && val && value->equals(*val))
return true;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValueList> CSSValueList::copy()
{
RefPtrWillBeRawPtr<CSSValueList> newList = nullptr;
switch (m_valueListSeparator) {
case SpaceSeparator:
newList = createSpaceSeparated();
break;
case CommaSeparator:
newList = createCommaSeparated();
break;
case SlashSeparator:
newList = createSlashSeparated();
break;
default:
ASSERT_NOT_REACHED();
}
for (size_t index = 0; index < m_values.size(); index++)
newList->append(m_values[index]);
return newList.release();
}
String CSSValueList::customCSSText(CSSTextFormattingFlags formattingFlag) const
{
StringBuilder result;
String separator;
switch (m_valueListSeparator) {
case SpaceSeparator:
separator = " ";
break;
case CommaSeparator:
separator = ", ";
break;
case SlashSeparator:
separator = " / ";
break;
default:
ASSERT_NOT_REACHED();
}
unsigned size = m_values.size();
for (unsigned i = 0; i < size; i++) {
if (!result.isEmpty())
result.append(separator);
if (formattingFlag == AlwaysQuoteCSSString && m_values[i]->isPrimitiveValue())
result.append(toCSSPrimitiveValue(m_values[i].get())->customCSSText(AlwaysQuoteCSSString));
else
result.append(m_values[i]->cssText());
}
return result.toString();
}
bool CSSValueList::equals(const CSSValueList& other) const
{
return m_valueListSeparator == other.m_valueListSeparator && compareCSSValueVector(m_values, other.m_values);
}
bool CSSValueList::equals(const CSSValue& other) const
{
if (m_values.size() != 1)
return false;
const RefPtrWillBeMember<CSSValue>& value = m_values[0];
return value && value->equals(other);
}
bool CSSValueList::hasFailedOrCanceledSubresources() const
{
for (unsigned i = 0; i < m_values.size(); ++i) {
if (m_values[i]->hasFailedOrCanceledSubresources())
return true;
}
return false;
}
CSSValueList::CSSValueList(const CSSValueList& cloneFrom)
: CSSValue(cloneFrom.classType(), true)
{
m_valueListSeparator = cloneFrom.m_valueListSeparator;
m_values.resize(cloneFrom.m_values.size());
for (unsigned i = 0; i < m_values.size(); ++i)
m_values[i] = cloneFrom.m_values[i]->cloneForCSSOM();
}
PassRefPtrWillBeRawPtr<CSSValueList> CSSValueList::cloneForCSSOM() const
{
return adoptRefWillBeRefCountedGarbageCollected(new CSSValueList(*this));
}
void CSSValueList::traceAfterDispatch(Visitor* visitor)
{
visitor->trace(m_values);
CSSValue::traceAfterDispatch(visitor);
}
}