This source file includes following definitions.
- atomicSubstring
- trimTrailingWhitespace
- addValue
- insertValueAt
- deleteValueAt
- stealValues
- createCSSValue
- adoptSelectorVector
- isSimple
- insertTagHistory
- appendTagHistory
- prependTagSelector
- hasHostPseudoSelector
#include "config.h"
#include "core/css/CSSParserValues.h"
#include "core/css/CSSFunctionValue.h"
#include "core/css/CSSSelectorList.h"
#include "core/html/parser/HTMLParserIdioms.h"
namespace WebCore {
using namespace WTF;
AtomicString CSSParserString::atomicSubstring(unsigned position, unsigned length) const
{
ASSERT(m_length >= position + length);
if (is8Bit())
return AtomicString(characters8() + position, length);
return AtomicString(characters16() + position, length);
}
void CSSParserString::trimTrailingWhitespace()
{
if (is8Bit()) {
while (m_length > 0 && isHTMLSpace<LChar>(m_data.characters8[m_length - 1]))
--m_length;
} else {
while (m_length > 0 && isHTMLSpace<UChar>(m_data.characters16[m_length - 1]))
--m_length;
}
}
CSSParserValueList::~CSSParserValueList()
{
size_t numValues = m_values.size();
for (size_t i = 0; i < numValues; i++) {
if (m_values[i].unit == CSSParserValue::Function)
delete m_values[i].function;
else if (m_values[i].unit == CSSParserValue::ValueList)
delete m_values[i].valueList;
}
}
void CSSParserValueList::addValue(const CSSParserValue& v)
{
m_values.append(v);
}
void CSSParserValueList::insertValueAt(unsigned i, const CSSParserValue& v)
{
m_values.insert(i, v);
}
void CSSParserValueList::deleteValueAt(unsigned i)
{
m_values.remove(i);
}
void CSSParserValueList::stealValues(CSSParserValueList& valueList)
{
for (unsigned i = 0; i < valueList.size(); ++i)
m_values.append(*(valueList.valueAt(i)));
valueList.clear();
}
PassRefPtrWillBeRawPtr<CSSValue> CSSParserValue::createCSSValue()
{
if (id)
return CSSPrimitiveValue::createIdentifier(id);
if (unit == CSSParserValue::Operator)
return CSSPrimitiveValue::createParserOperator(iValue);
if (unit == CSSParserValue::Function)
return CSSFunctionValue::create(function);
if (unit == CSSParserValue::ValueList)
return CSSValueList::createFromParserValueList(valueList);
if (unit >= CSSParserValue::Q_EMS)
return CSSPrimitiveValue::createAllowingMarginQuirk(fValue, CSSPrimitiveValue::CSS_EMS);
CSSPrimitiveValue::UnitTypes primitiveUnit = static_cast<CSSPrimitiveValue::UnitTypes>(unit);
switch (primitiveUnit) {
case CSSPrimitiveValue::CSS_IDENT:
case CSSPrimitiveValue::CSS_PROPERTY_ID:
case CSSPrimitiveValue::CSS_VALUE_ID:
return CSSPrimitiveValue::create(string, CSSPrimitiveValue::CSS_PARSER_IDENTIFIER);
case CSSPrimitiveValue::CSS_NUMBER:
return CSSPrimitiveValue::create(fValue, isInt ? CSSPrimitiveValue::CSS_PARSER_INTEGER : CSSPrimitiveValue::CSS_NUMBER);
case CSSPrimitiveValue::CSS_STRING:
case CSSPrimitiveValue::CSS_URI:
case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR:
return CSSPrimitiveValue::create(string, primitiveUnit);
case CSSPrimitiveValue::CSS_PERCENTAGE:
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
case CSSPrimitiveValue::CSS_DEG:
case CSSPrimitiveValue::CSS_RAD:
case CSSPrimitiveValue::CSS_GRAD:
case CSSPrimitiveValue::CSS_MS:
case CSSPrimitiveValue::CSS_S:
case CSSPrimitiveValue::CSS_HZ:
case CSSPrimitiveValue::CSS_KHZ:
case CSSPrimitiveValue::CSS_VW:
case CSSPrimitiveValue::CSS_VH:
case CSSPrimitiveValue::CSS_VMIN:
case CSSPrimitiveValue::CSS_VMAX:
case CSSPrimitiveValue::CSS_TURN:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_FR:
return CSSPrimitiveValue::create(fValue, primitiveUnit);
case CSSPrimitiveValue::CSS_UNKNOWN:
case CSSPrimitiveValue::CSS_DIMENSION:
case CSSPrimitiveValue::CSS_ATTR:
case CSSPrimitiveValue::CSS_COUNTER:
case CSSPrimitiveValue::CSS_RECT:
case CSSPrimitiveValue::CSS_RGBCOLOR:
case CSSPrimitiveValue::CSS_DPPX:
case CSSPrimitiveValue::CSS_DPI:
case CSSPrimitiveValue::CSS_DPCM:
case CSSPrimitiveValue::CSS_PAIR:
case CSSPrimitiveValue::CSS_UNICODE_RANGE:
case CSSPrimitiveValue::CSS_PARSER_INTEGER:
case CSSPrimitiveValue::CSS_PARSER_IDENTIFIER:
case CSSPrimitiveValue::CSS_PARSER_OPERATOR:
case CSSPrimitiveValue::CSS_COUNTER_NAME:
case CSSPrimitiveValue::CSS_SHAPE:
case CSSPrimitiveValue::CSS_QUAD:
case CSSPrimitiveValue::CSS_CALC:
case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER:
case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH:
return nullptr;
}
ASSERT_NOT_REACHED();
return nullptr;
}
CSSParserSelector::CSSParserSelector()
: m_selector(adoptPtr(new CSSSelector()))
{
}
CSSParserSelector::CSSParserSelector(const QualifiedName& tagQName)
: m_selector(adoptPtr(new CSSSelector(tagQName)))
{
}
CSSParserSelector::~CSSParserSelector()
{
if (!m_tagHistory)
return;
Vector<OwnPtr<CSSParserSelector>, 16> toDelete;
OwnPtr<CSSParserSelector> selector = m_tagHistory.release();
while (true) {
OwnPtr<CSSParserSelector> next = selector->m_tagHistory.release();
toDelete.append(selector.release());
if (!next)
break;
selector = next.release();
}
}
void CSSParserSelector::adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector)
{
CSSSelectorList* selectorList = new CSSSelectorList();
selectorList->adoptSelectorVector(selectorVector);
m_selector->setSelectorList(adoptPtr(selectorList));
}
bool CSSParserSelector::isSimple() const
{
if (m_selector->selectorList() || m_selector->matchesPseudoElement())
return false;
if (!m_tagHistory)
return true;
if (m_selector->m_match == CSSSelector::Tag) {
if (m_selector->tagQName().localName() == starAtom)
return m_tagHistory->isSimple();
}
return false;
}
void CSSParserSelector::insertTagHistory(CSSSelector::Relation before, PassOwnPtr<CSSParserSelector> selector, CSSSelector::Relation after)
{
if (m_tagHistory)
selector->setTagHistory(m_tagHistory.release());
setRelation(before);
selector->setRelation(after);
m_tagHistory = selector;
}
void CSSParserSelector::appendTagHistory(CSSSelector::Relation relation, PassOwnPtr<CSSParserSelector> selector)
{
CSSParserSelector* end = this;
while (end->tagHistory())
end = end->tagHistory();
end->setRelation(relation);
end->setTagHistory(selector);
}
void CSSParserSelector::prependTagSelector(const QualifiedName& tagQName, bool tagIsForNamespaceRule)
{
OwnPtr<CSSParserSelector> second = adoptPtr(new CSSParserSelector);
second->m_selector = m_selector.release();
second->m_tagHistory = m_tagHistory.release();
m_tagHistory = second.release();
m_selector = adoptPtr(new CSSSelector(tagQName, tagIsForNamespaceRule));
m_selector->m_relation = CSSSelector::SubSelector;
}
bool CSSParserSelector::hasHostPseudoSelector() const
{
CSSParserSelector* selector = const_cast<CSSParserSelector*>(this);
do {
if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseudoType() == CSSSelector::PseudoHostContext)
return true;
} while ((selector = selector->tagHistory()));
return false;
}
}