#include "config.h"
#include "RuleFeature.h"
#include "CSSSelector.h"
namespace WebCore {
void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector)
{
if (selector->m_match == CSSSelector::Id)
idsInRules.add(selector->value().impl());
else if (selector->m_match == CSSSelector::Class)
classesInRules.add(selector->value().impl());
else if (selector->isAttributeSelector())
attrsInRules.add(selector->attribute().localName().impl());
else if (selector->m_match == CSSSelector::PseudoElement) {
switch (selector->pseudoElementType()) {
case CSSSelector::PseudoElementFirstLine:
usesFirstLineRules = true;
break;
case CSSSelector::PseudoElementFirstLetter:
usesFirstLetterRules = true;
break;
case CSSSelector::PseudoElementBefore:
case CSSSelector::PseudoElementAfter:
usesBeforeAfterRules = true;
break;
default:
break;
}
}
}
void RuleFeatureSet::add(const RuleFeatureSet& other)
{
HashSet<AtomicStringImpl*>::const_iterator end = other.idsInRules.end();
for (HashSet<AtomicStringImpl*>::const_iterator it = other.idsInRules.begin(); it != end; ++it)
idsInRules.add(*it);
end = other.classesInRules.end();
for (HashSet<AtomicStringImpl*>::const_iterator it = other.classesInRules.begin(); it != end; ++it)
classesInRules.add(*it);
end = other.attrsInRules.end();
for (HashSet<AtomicStringImpl*>::const_iterator it = other.attrsInRules.begin(); it != end; ++it)
attrsInRules.add(*it);
siblingRules.appendVector(other.siblingRules);
uncommonAttributeRules.appendVector(other.uncommonAttributeRules);
usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules;
usesFirstLetterRules = usesFirstLetterRules || other.usesFirstLetterRules;
usesBeforeAfterRules = usesBeforeAfterRules || other.usesBeforeAfterRules;
}
void RuleFeatureSet::clear()
{
idsInRules.clear();
classesInRules.clear();
attrsInRules.clear();
siblingRules.clear();
uncommonAttributeRules.clear();
usesFirstLineRules = false;
usesFirstLetterRules = false;
usesBeforeAfterRules = false;
}
}