📄 cssselector.cpp
字号:
m_pseudoType = PseudoScrollbar; } else if (m_value == scrollbarButton) { element = true; m_pseudoType = PseudoScrollbarButton; } else if (m_value == scrollbarCorner) { element = true; m_pseudoType = PseudoScrollbarCorner; } else if (m_value == scrollbarThumb) { element = true; m_pseudoType = PseudoScrollbarThumb; } else if (m_value == scrollbarTrack) { element = true; m_pseudoType = PseudoScrollbarTrack; } else if (m_value == scrollbarTrackPiece) { element = true; m_pseudoType = PseudoScrollbarTrackPiece; } else if (m_value == cornerPresent) m_pseudoType = PseudoCornerPresent; else if (m_value == searchCancelButton) { m_pseudoType = PseudoSearchCancelButton; element = true; } else if (m_value == searchDecoration) { m_pseudoType = PseudoSearchDecoration; element = true; } else if (m_value == searchResultsDecoration) { m_pseudoType = PseudoSearchResultsDecoration; element = true; } else if (m_value == searchResultsButton) { m_pseudoType = PseudoSearchResultsButton; element = true; } else if (m_value == selection) { m_pseudoType = PseudoSelection; element = true; } else if (m_value == sliderThumb) { m_pseudoType = PseudoSliderThumb; element = true; } else if (m_value == target) m_pseudoType = PseudoTarget; else if (m_value == visited) m_pseudoType = PseudoVisited; if (m_match == PseudoClass && element) { if (!compat) m_pseudoType = PseudoUnknown; else m_match = PseudoElement; } else if (m_match == PseudoElement && !element) m_pseudoType = PseudoUnknown;}bool CSSSelector::operator==(const CSSSelector& other){ const CSSSelector* sel1 = this; const CSSSelector* sel2 = &other; while (sel1 && sel2) { if (sel1->m_tag != sel2->m_tag || sel1->attribute() != sel2->attribute() || sel1->relation() != sel2->relation() || sel1->m_match != sel2->m_match || sel1->m_value != sel2->m_value || sel1->pseudoType() != sel2->pseudoType() || sel1->argument() != sel2->argument()) return false; sel1 = sel1->tagHistory(); sel2 = sel2->tagHistory(); } if (sel1 || sel2) return false; return true;}String CSSSelector::selectorText() const{ String str = ""; const AtomicString& prefix = m_tag.prefix(); const AtomicString& localName = m_tag.localName(); if (m_match == CSSSelector::None || !prefix.isNull() || localName != starAtom) { if (prefix.isNull()) str = localName; else str = prefix + "|" + localName; } const CSSSelector* cs = this; while (true) { if (cs->m_match == CSSSelector::Id) { str += "#"; str += cs->m_value; } else if (cs->m_match == CSSSelector::Class) { str += "."; str += cs->m_value; } else if (cs->m_match == CSSSelector::PseudoClass) { str += ":"; str += cs->m_value; if (cs->pseudoType() == PseudoNot) { if (CSSSelector* subSel = cs->simpleSelector()) str += subSel->selectorText(); str += ")"; } else if (cs->pseudoType() == PseudoLang || cs->pseudoType() == PseudoNthChild || cs->pseudoType() == PseudoNthLastChild || cs->pseudoType() == PseudoNthOfType || cs->pseudoType() == PseudoNthLastOfType) { str += cs->argument(); str += ")"; } } else if (cs->m_match == CSSSelector::PseudoElement) { str += "::"; str += cs->m_value; } else if (cs->hasAttribute()) { str += "["; const AtomicString& prefix = cs->attribute().prefix(); if (!prefix.isNull()) str += prefix + "|"; str += cs->attribute().localName(); switch (cs->m_match) { case CSSSelector::Exact: str += "="; break; case CSSSelector::Set: // set has no operator or value, just the attrName str += "]"; break; case CSSSelector::List: str += "~="; break; case CSSSelector::Hyphen: str += "|="; break; case CSSSelector::Begin: str += "^="; break; case CSSSelector::End: str += "$="; break; case CSSSelector::Contain: str += "*="; break; default: break; } if (cs->m_match != CSSSelector::Set) { str += "\""; str += cs->m_value; str += "\"]"; } } if (cs->relation() != CSSSelector::SubSelector || !cs->tagHistory()) break; cs = cs->tagHistory(); } if (CSSSelector* tagHistory = cs->tagHistory()) { String tagHistoryText = tagHistory->selectorText(); if (cs->relation() == CSSSelector::DirectAdjacent) str = tagHistoryText + " + " + str; else if (cs->relation() == CSSSelector::IndirectAdjacent) str = tagHistoryText + " ~ " + str; else if (cs->relation() == CSSSelector::Child) str = tagHistoryText + " > " + str; else // Descendant str = tagHistoryText + " " + str; } return str;} void CSSSelector::setTagHistory(CSSSelector* tagHistory) { if (m_hasRareData) m_data.m_rareData->m_tagHistory.set(tagHistory); else m_data.m_tagHistory = tagHistory; }const QualifiedName& CSSSelector::attribute() const{ switch (m_match) { case Id: return idAttr; case Class: return classAttr; default: return m_hasRareData ? m_data.m_rareData->m_attribute : anyQName(); }}void CSSSelector::setAttribute(const QualifiedName& value) { createRareData(); m_data.m_rareData->m_attribute = value; } void CSSSelector::setArgument(const AtomicString& value) { createRareData(); m_data.m_rareData->m_argument = value; }void CSSSelector::setSimpleSelector(CSSSelector* value){ createRareData(); m_data.m_rareData->m_simpleSelector.set(value); }bool CSSSelector::parseNth(){ if (!m_hasRareData) return false; if (m_parsedNth) return true; m_parsedNth = m_data.m_rareData->parseNth(); return m_parsedNth;}bool CSSSelector::matchNth(int count){ ASSERT(m_hasRareData); return m_data.m_rareData->matchNth(count);}// a helper function for parsing nth-argumentsbool CSSSelector::RareData::parseNth(){ const String& argument = m_argument; if (argument.isEmpty()) return false; m_a = 0; m_b = 0; if (argument == "odd") { m_a = 2; m_b = 1; } else if (argument == "even") { m_a = 2; m_b = 0; } else { int n = argument.find('n'); if (n != -1) { if (argument[0] == '-') { if (n == 1) m_a = -1; // -n == -1n else m_a = argument.substring(0, n).toInt(); } else if (!n) m_a = 1; // n == 1n else m_a = argument.substring(0, n).toInt(); int p = argument.find('+', n); if (p != -1) m_b = argument.substring(p + 1, argument.length() - p - 1).toInt(); else { p = argument.find('-', n); m_b = -argument.substring(p + 1, argument.length() - p - 1).toInt(); } } else m_b = argument.toInt(); } return true;}// a helper function for checking nth-argumentsbool CSSSelector::RareData::matchNth(int count){ if (!m_a) return count == m_b; else if (m_a > 0) { if (count < m_b) return false; return (count - m_b) % m_a == 0; } else { if (count > m_b) return false; return (m_b - count) % (-m_a) == 0; }} } // namespace WebCore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -