Commit b54a99d9 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Make all CSSSelector data members private

Make all CSSSelector data members private. Previously, some of the data members
such as m_relation / m_match / m_pseudoType were public and accessed directly
from outside the class. The new approach is better because:
- Those members are bit fields so by using getters, we can hide the casts inside
  the getters. The setters can now also check that the bitfield is big enough to
  actually store the enum value.
- When using those in switch() statements, the compiler now complains if we fail
  to test some of the enum values as the value is now an enum, and not merely an
  unsigned integer.
- Some of these members already has getters (e.g. relation(), pseudoType()).
- Better encapsulation.

R=esprehn@chromium.org

Review URL: https://codereview.chromium.org/322803004

git-svn-id: svn://svn.chromium.org/blink/trunk@175994 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 00875ded
......@@ -186,7 +186,7 @@ bool CSSParserSelector::isSimple() const
if (!m_tagHistory)
return true;
if (m_selector->m_match == CSSSelector::Tag) {
if (m_selector->match() == CSSSelector::Tag) {
// We can't check against anyQName() here because namespace may not be nullAtom.
// Example:
// @namespace "http://www.w3.org/2000/svg";
......@@ -224,7 +224,7 @@ void CSSParserSelector::prependTagSelector(const QualifiedName& tagQName, bool t
m_tagHistory = second.release();
m_selector = adoptPtr(new CSSSelector(tagQName, tagIsForNamespaceRule));
m_selector->m_relation = CSSSelector::SubSelector;
m_selector->setRelation(CSSSelector::SubSelector);
}
bool CSSParserSelector::hasHostPseudoSelector() const
......
......@@ -223,8 +223,8 @@ public:
void setValue(const AtomicString& value) { m_selector->setValue(value); }
void setAttribute(const QualifiedName& value) { m_selector->setAttribute(value); }
void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
void setMatch(CSSSelector::Match value) { m_selector->m_match = value; }
void setRelation(CSSSelector::Relation value) { m_selector->m_relation = value; }
void setMatch(CSSSelector::Match value) { m_selector->setMatch(value); }
void setRelation(CSSSelector::Relation value) { m_selector->setRelation(value); }
void setForPage() { m_selector->setForPage(); }
void setRelationIsAffectedByPseudoContent() { m_selector->setRelationIsAffectedByPseudoContent(); }
bool relationIsAffectedByPseudoContent() const { return m_selector->relationIsAffectedByPseudoContent(); }
......
......@@ -736,7 +736,7 @@ void CSSSelector::setSelectorList(PassOwnPtr<CSSSelectorList> selectorList)
static bool validateSubSelector(const CSSSelector* selector)
{
switch (selector->m_match) {
switch (selector->match()) {
case CSSSelector::Tag:
case CSSSelector::Id:
case CSSSelector::Class:
......@@ -749,6 +749,7 @@ static bool validateSubSelector(const CSSSelector* selector)
case CSSSelector::End:
return true;
case CSSSelector::PseudoElement:
case CSSSelector::Unknown:
return false;
case CSSSelector::PagePseudoClass:
case CSSSelector::PseudoClass:
......
......@@ -292,6 +292,18 @@ namespace WebCore {
// FIXME: selectors with no tagHistory() get a relation() of Descendant (and sometimes even SubSelector). It should instead be
// None.
Relation relation() const { return static_cast<Relation>(m_relation); }
void setRelation(Relation relation)
{
m_relation = relation;
ASSERT(static_cast<Relation>(m_relation) == relation); // using a bitfield.
}
Match match() const { return static_cast<Match>(m_match); }
void setMatch(Match match)
{
m_match = match;
ASSERT(static_cast<Match>(m_match) == match); // using a bitfield.
}
bool isLastInSelectorList() const { return m_isLastInSelectorList; }
void setLastInSelectorList() { m_isLastInSelectorList = true; }
......@@ -307,11 +319,10 @@ namespace WebCore {
bool relationIsAffectedByPseudoContent() const { return m_relationIsAffectedByPseudoContent; }
void setRelationIsAffectedByPseudoContent() { m_relationIsAffectedByPseudoContent = true; }
private:
unsigned m_relation : 3; // enum Relation
mutable unsigned m_match : 4; // enum Match
mutable unsigned m_pseudoType : 8; // PseudoType
private:
mutable unsigned m_parsedNth : 1; // Used for :nth-*
unsigned m_isLastInSelectorList : 1;
unsigned m_isLastInTagHistory : 1;
......
......@@ -154,7 +154,7 @@ class SelectorNeedsNamespaceResolutionFunctor {
public:
bool operator()(const CSSSelector& selector)
{
if (selector.m_match == CSSSelector::Tag && selector.tagQName().prefix() != nullAtom && selector.tagQName().prefix() != starAtom)
if (selector.match() == CSSSelector::Tag && selector.tagQName().prefix() != nullAtom && selector.tagQName().prefix() != starAtom)
return true;
if (selector.isAttributeSelector() && selector.attribute().prefix() != nullAtom && selector.attribute().prefix() != starAtom)
return true;
......
......@@ -87,7 +87,7 @@ void PageRuleCollector::matchPageRules(RuleSet* rules)
static bool checkPageSelectorComponents(const CSSSelector* selector, bool isLeftPage, bool isFirstPage, const String& pageName)
{
for (const CSSSelector* component = selector; component; component = component->tagHistory()) {
if (component->m_match == CSSSelector::Tag) {
if (component->match() == CSSSelector::Tag) {
const AtomicString& localName = component->tagQName().localName();
if (localName != starAtom && localName != pageName)
return false;
......
......@@ -44,11 +44,11 @@ namespace WebCore {
static bool isSkippableComponentForInvalidation(const CSSSelector& selector)
{
if (selector.m_match == CSSSelector::Tag
|| selector.m_match == CSSSelector::Id
if (selector.match() == CSSSelector::Tag
|| selector.match() == CSSSelector::Id
|| selector.isAttributeSelector())
return true;
if (selector.m_match == CSSSelector::PseudoElement) {
if (selector.match() == CSSSelector::PseudoElement) {
switch (selector.pseudoType()) {
case CSSSelector::PseudoBefore:
case CSSSelector::PseudoAfter:
......@@ -59,7 +59,7 @@ static bool isSkippableComponentForInvalidation(const CSSSelector& selector)
return selector.isCustomPseudoElement();
}
}
if (selector.m_match != CSSSelector::PseudoClass)
if (selector.match() != CSSSelector::PseudoClass)
return false;
switch (selector.pseudoType()) {
case CSSSelector::PseudoEmpty:
......@@ -123,8 +123,8 @@ RuleFeatureSet::InvalidationSetMode RuleFeatureSet::invalidationSetModeForSelect
bool foundIdent = false;
for (const CSSSelector* component = &selector; component; component = component->tagHistory()) {
if (component->m_match == CSSSelector::Class || component->m_match == CSSSelector::Id
|| (component->m_match == CSSSelector::Tag && component->tagQName().localName() != starAtom)
if (component->match() == CSSSelector::Class || component->match() == CSSSelector::Id
|| (component->match() == CSSSelector::Tag && component->tagQName().localName() != starAtom)
|| component->isAttributeSelector() || component->isCustomPseudoElement()) {
if (!foundDescendantRelation)
foundIdent = true;
......@@ -163,11 +163,11 @@ RuleFeatureSet::InvalidationSetMode RuleFeatureSet::invalidationSetModeForSelect
void RuleFeatureSet::extractInvalidationSetFeature(const CSSSelector& selector, InvalidationSetFeatures& features)
{
if (selector.m_match == CSSSelector::Tag)
if (selector.match() == CSSSelector::Tag)
features.tagName = selector.tagQName().localName();
else if (selector.m_match == CSSSelector::Id)
else if (selector.match() == CSSSelector::Id)
features.id = selector.value();
else if (selector.m_match == CSSSelector::Class)
else if (selector.match() == CSSSelector::Class)
features.classes.append(selector.value());
else if (selector.isAttributeSelector())
features.attributes.append(selector.attribute().localName());
......@@ -186,13 +186,13 @@ RuleFeatureSet::~RuleFeatureSet()
DescendantInvalidationSet* RuleFeatureSet::invalidationSetForSelector(const CSSSelector& selector)
{
if (selector.m_match == CSSSelector::Class)
if (selector.match() == CSSSelector::Class)
return &ensureClassInvalidationSet(selector.value());
if (selector.isAttributeSelector())
return &ensureAttributeInvalidationSet(selector.attribute().localName());
if (selector.m_match == CSSSelector::Id)
if (selector.match() == CSSSelector::Id)
return &ensureIdInvalidationSet(selector.value());
if (selector.m_match == CSSSelector::PseudoClass) {
if (selector.match() == CSSSelector::PseudoClass) {
CSSSelector::PseudoType pseudo = selector.pseudoType();
if (pseudo == CSSSelector::PseudoHover || pseudo == CSSSelector::PseudoActive || pseudo == CSSSelector::PseudoFocus)
return &ensurePseudoInvalidationSet(pseudo);
......
......@@ -53,7 +53,7 @@ using namespace HTMLNames;
static inline bool isSelectorMatchingHTMLBasedOnRuleHash(const CSSSelector& selector)
{
if (selector.m_match == CSSSelector::Tag) {
if (selector.match() == CSSSelector::Tag) {
const AtomicString& selectorNamespace = selector.tagQName().namespaceURI();
if (selectorNamespace != starAtom && selectorNamespace != xhtmlNamespaceURI)
return false;
......@@ -65,7 +65,7 @@ static inline bool isSelectorMatchingHTMLBasedOnRuleHash(const CSSSelector& sele
}
if (SelectorChecker::isCommonPseudoClassSelector(selector))
return true;
return selector.m_match == CSSSelector::Id || selector.m_match == CSSSelector::Class;
return selector.match() == CSSSelector::Id || selector.match() == CSSSelector::Class;
}
static inline bool selectorListContainsUncommonAttributeSelector(const CSSSelector* selector)
......@@ -115,7 +115,7 @@ static inline bool containsUncommonAttributeSelector(const CSSSelector& selector
static inline PropertyWhitelistType determinePropertyWhitelistType(const AddRuleFlags addRuleFlags, const CSSSelector& selector)
{
for (const CSSSelector* component = &selector; component; component = component->tagHistory()) {
if (component->pseudoType() == CSSSelector::PseudoCue || (component->m_match == CSSSelector::PseudoElement && component->value() == TextTrackCue::cueShadowPseudoId()))
if (component->pseudoType() == CSSSelector::PseudoCue || (component->match() == CSSSelector::PseudoElement && component->value() == TextTrackCue::cueShadowPseudoId()))
return PropertyWhitelistCue;
if (component->pseudoType() == CSSSelector::PseudoFirstLetter)
return PropertyWhitelistFirstLetter;
......@@ -151,7 +151,7 @@ void RuleSet::addToRuleSet(const AtomicString& key, PendingRuleMap& map, const R
static void extractValuesforSelector(const CSSSelector* selector, AtomicString& id, AtomicString& className, AtomicString& customPseudoElementName, AtomicString& tagName)
{
switch (selector->m_match) {
switch (selector->match()) {
case CSSSelector::Id:
id = selector->value();
break;
......@@ -162,6 +162,8 @@ static void extractValuesforSelector(const CSSSelector* selector, AtomicString&
if (selector->tagQName().localName() != starAtom)
tagName = selector->tagQName().localName();
break;
default:
break;
}
if (selector->isCustomPseudoElement())
customPseudoElementName = selector->value();
......
......@@ -146,7 +146,7 @@ SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext& con
if (!checkOne(context, siblingTraversalStrategy, &specificity))
return SelectorFailsLocally;
if (context.selector->m_match == CSSSelector::PseudoElement) {
if (context.selector->match() == CSSSelector::PseudoElement) {
if (context.selector->isCustomPseudoElement()) {
if (!matchesCustomPseudoElement(context.element, *context.selector))
return SelectorFailsLocally;
......@@ -231,7 +231,7 @@ SelectorChecker::Match SelectorChecker::matchForSubSelector(const SelectorChecki
nextContext.hasSelectionPseudo = dynamicPseudo == SELECTION;
if ((context.elementStyle || m_mode == CollectingCSSRules || m_mode == CollectingStyleRules || m_mode == QueryingRules) && dynamicPseudo != NOPSEUDO
&& !nextContext.hasSelectionPseudo
&& !(nextContext.hasScrollbarPseudo && nextContext.selector->m_match == CSSSelector::PseudoClass))
&& !(nextContext.hasScrollbarPseudo && nextContext.selector->match() == CSSSelector::PseudoClass))
return SelectorFailsCompletely;
nextContext.isSubSelector = true;
......@@ -540,19 +540,19 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context, const Sib
if (elementIsHostInItsShadowTree && !selector.isHostPseudoClass())
return false;
if (selector.m_match == CSSSelector::Tag)
if (selector.match() == CSSSelector::Tag)
return SelectorChecker::tagMatches(element, selector.tagQName());
if (selector.m_match == CSSSelector::Class)
if (selector.match() == CSSSelector::Class)
return element.hasClass() && element.classNames().contains(selector.value());
if (selector.m_match == CSSSelector::Id)
if (selector.match() == CSSSelector::Id)
return element.hasID() && element.idForStyleResolution() == selector.value();
if (selector.isAttributeSelector())
return anyAttributeMatches(element, static_cast<CSSSelector::Match>(selector.m_match), selector);
return anyAttributeMatches(element, selector.match(), selector);
if (selector.m_match == CSSSelector::PseudoClass) {
if (selector.match() == CSSSelector::PseudoClass) {
// Handle :not up front.
if (selector.pseudoType() == CSSSelector::PseudoNot) {
SelectorCheckingContext subContext(context);
......@@ -997,7 +997,7 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context, const Sib
break;
}
return false;
} else if (selector.m_match == CSSSelector::PseudoElement && selector.pseudoType() == CSSSelector::PseudoCue) {
} else if (selector.match() == CSSSelector::PseudoElement && selector.pseudoType() == CSSSelector::PseudoCue) {
SelectorCheckingContext subContext(context);
subContext.isSubSelector = true;
subContext.behaviorAtBoundary = StaysWithinTreeScope;
......@@ -1027,7 +1027,7 @@ bool SelectorChecker::checkScrollbarPseudoClass(const SelectorCheckingContext& c
if (!scrollbar)
return false;
ASSERT(selector.m_match == CSSSelector::PseudoClass);
ASSERT(selector.match() == CSSSelector::PseudoClass);
switch (selector.pseudoType()) {
case CSSSelector::PseudoEnabled:
return scrollbar->enabled();
......
......@@ -144,7 +144,7 @@ private:
inline bool SelectorChecker::isCommonPseudoClassSelector(const CSSSelector& selector)
{
if (selector.m_match != CSSSelector::PseudoClass)
if (selector.match() != CSSSelector::PseudoClass)
return false;
CSSSelector::PseudoType pseudoType = selector.pseudoType();
return pseudoType == CSSSelector::PseudoLink
......
......@@ -110,7 +110,7 @@ void SelectorFilter::pushParent(Element& parent)
static inline void collectDescendantSelectorIdentifierHashes(const CSSSelector& selector, unsigned*& hash)
{
switch (selector.m_match) {
switch (selector.match()) {
case CSSSelector::Id:
if (!selector.value().isEmpty())
(*hash++) = selector.value().impl()->existingHash() * IdAttributeSalt;
......
......@@ -51,9 +51,9 @@ static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet
// This picks the widest scope, not the narrowest, to minimize the number of found scopes.
for (const CSSSelector* current = selector; current; current = current->tagHistory()) {
// Prefer ids over classes.
if (current->m_match == CSSSelector::Id)
if (current->match() == CSSSelector::Id)
scopeSelector = current;
else if (current->m_match == CSSSelector::Class && (!scopeSelector || scopeSelector->m_match != CSSSelector::Id))
else if (current->match() == CSSSelector::Class && (!scopeSelector || scopeSelector->match() != CSSSelector::Id))
scopeSelector = current;
CSSSelector::Relation relation = current->relation();
// FIXME: it would be better to use setNeedsStyleRecalc for all shadow hosts matching
......@@ -65,8 +65,8 @@ static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet
}
if (!scopeSelector)
return false;
ASSERT(scopeSelector->m_match == CSSSelector::Class || scopeSelector->m_match == CSSSelector::Id);
if (scopeSelector->m_match == CSSSelector::Id)
ASSERT(scopeSelector->match() == CSSSelector::Class || scopeSelector->match() == CSSSelector::Id);
if (scopeSelector->match() == CSSSelector::Id)
idScopes.add(scopeSelector->value().impl());
else
classScopes.add(scopeSelector->value().impl());
......
......@@ -209,7 +209,7 @@ void SelectorDataList::findTraverseRootsAndExecute(ContainerNode& rootNode, type
bool startFromParent = false;
for (const CSSSelector* selector = m_selectors[0]; selector; selector = selector->tagHistory()) {
if (selector->m_match == CSSSelector::Id && !rootNode.document().containsMultipleElementsWithId(selector->value())) {
if (selector->match() == CSSSelector::Id && !rootNode.document().containsMultipleElementsWithId(selector->value())) {
Element* element = rootNode.treeScope().getElementById(selector->value());
ContainerNode* adjustedNode = &rootNode;
if (element && (isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode)))
......@@ -230,7 +230,7 @@ void SelectorDataList::findTraverseRootsAndExecute(ContainerNode& rootNode, type
// If we have both CSSSelector::Id and CSSSelector::Class at the same time, we should use Id
// to find traverse root.
if (!SelectorQueryTrait::shouldOnlyMatchFirstElement && !startFromParent && selector->m_match == CSSSelector::Class) {
if (!SelectorQueryTrait::shouldOnlyMatchFirstElement && !startFromParent && selector->match() == CSSSelector::Class) {
if (isRightmostSelector) {
ClassElementList<AllElements> traverseRoots(rootNode, selector->value());
executeForTraverseRoots<SelectorQueryTrait>(*m_selectors[0], traverseRoots, MatchesTraverseRoots, rootNode, output);
......@@ -396,7 +396,7 @@ void SelectorDataList::executeSlowTraversingShadowTree(ContainerNode& rootNode,
const CSSSelector* SelectorDataList::selectorForIdLookup(const CSSSelector& firstSelector) const
{
for (const CSSSelector* selector = &firstSelector; selector; selector = selector->tagHistory()) {
if (selector->m_match == CSSSelector::Id)
if (selector->match() == CSSSelector::Id)
return selector;
if (selector->relation() != CSSSelector::SubSelector)
break;
......@@ -450,7 +450,7 @@ void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr
if (!firstSelector.tagHistory()) {
// Fast path for querySelector*('.foo'), and querySelector*('div').
switch (firstSelector.m_match) {
switch (firstSelector.match()) {
case CSSSelector::Class:
collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelector.value(), output);
return;
......
......@@ -82,7 +82,7 @@ void HTMLContentElement::parseAttribute(const QualifiedName& name, const AtomicS
static inline bool includesDisallowedPseudoClass(const CSSSelector& selector)
{
return selector.m_match == CSSSelector::PseudoClass && selector.m_pseudoType != CSSSelector::PseudoNot;
return selector.match() == CSSSelector::PseudoClass && selector.pseudoType() != CSSSelector::PseudoNot;
}
bool HTMLContentElement::validateSelect() const
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment