This source file includes following definitions.
- add
- clear
- collectFeaturesFromSelector
- checkSelectorsForClassChange
- checkSelectorsForClassChange
#include "config.h"
#include "core/dom/shadow/SelectRuleFeatureSet.h"
#include "core/css/CSSSelector.h"
#include "wtf/BitVector.h"
namespace WebCore {
SelectRuleFeatureSet::SelectRuleFeatureSet()
: m_featureFlags(0)
{
}
void SelectRuleFeatureSet::add(const SelectRuleFeatureSet& featureSet)
{
m_cssRuleFeatureSet.add(featureSet.m_cssRuleFeatureSet);
m_featureFlags |= featureSet.m_featureFlags;
}
void SelectRuleFeatureSet::clear()
{
m_cssRuleFeatureSet.clear();
m_featureFlags = 0;
}
void SelectRuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector)
{
m_cssRuleFeatureSet.collectFeaturesFromSelector(selector);
switch (selector.pseudoType()) {
case CSSSelector::PseudoChecked:
setSelectRuleFeature(AffectedSelectorChecked);
break;
case CSSSelector::PseudoEnabled:
setSelectRuleFeature(AffectedSelectorEnabled);
break;
case CSSSelector::PseudoDisabled:
setSelectRuleFeature(AffectedSelectorDisabled);
break;
case CSSSelector::PseudoIndeterminate:
setSelectRuleFeature(AffectedSelectorIndeterminate);
break;
case CSSSelector::PseudoLink:
setSelectRuleFeature(AffectedSelectorLink);
break;
case CSSSelector::PseudoTarget:
setSelectRuleFeature(AffectedSelectorTarget);
break;
case CSSSelector::PseudoVisited:
setSelectRuleFeature(AffectedSelectorVisited);
break;
default:
break;
}
}
bool SelectRuleFeatureSet::checkSelectorsForClassChange(const SpaceSplitString& changedClasses) const
{
unsigned changedSize = changedClasses.size();
for (unsigned i = 0; i < changedSize; ++i) {
if (hasSelectorForClass(changedClasses[i]))
return true;
}
return false;
}
bool SelectRuleFeatureSet::checkSelectorsForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses) const
{
if (!oldClasses.size())
return checkSelectorsForClassChange(newClasses);
BitVector remainingClassBits;
remainingClassBits.ensureSize(oldClasses.size());
for (unsigned i = 0; i < newClasses.size(); ++i) {
bool found = false;
for (unsigned j = 0; j < oldClasses.size(); ++j) {
if (newClasses[i] == oldClasses[j]) {
remainingClassBits.quickSet(j);
found = true;
}
}
if (!found) {
if (hasSelectorForClass(newClasses[i]))
return true;
}
}
for (unsigned i = 0; i < oldClasses.size(); ++i) {
if (remainingClassBits.quickGet(i))
continue;
if (hasSelectorForClass(oldClasses[i]))
return true;
}
return false;
}
}