| Index: Source/core/css/resolver/MatchResult.h
|
| diff --git a/Source/core/css/resolver/MatchResult.h b/Source/core/css/resolver/MatchResult.h
|
| index 8170d451d5f000a2093d6543a17758d4515bea2c..eee39dbff2d505e386f6f0dafcc81b1f317604d5 100644
|
| --- a/Source/core/css/resolver/MatchResult.h
|
| +++ b/Source/core/css/resolver/MatchResult.h
|
| @@ -33,7 +33,7 @@ namespace blink {
|
|
|
| class StylePropertySet;
|
|
|
| -struct MatchedProperties {
|
| +struct CORE_EXPORT MatchedProperties {
|
| ALLOW_ONLY_INLINE_ALLOCATION();
|
| public:
|
| MatchedProperties();
|
| @@ -59,21 +59,99 @@ WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedProperties);
|
|
|
| namespace blink {
|
|
|
| -class MatchResult {
|
| +using MatchedPropertiesVector = WillBeHeapVector<MatchedProperties, 64>;
|
| +
|
| +// MatchedPropertiesRange is used to represent a subset of the matched properties from
|
| +// a given origin, for instance UA rules, author rules, or a shadow tree scope. This is
|
| +// needed because rules from different origins are applied in the opposite order for
|
| +// !important rules, yet in the same order as for normal rules within the same origin.
|
| +
|
| +class MatchedPropertiesRange {
|
| +public:
|
| + MatchedPropertiesRange(MatchedPropertiesVector::const_iterator begin, MatchedPropertiesVector::const_iterator end)
|
| + : m_begin(begin)
|
| + , m_end(end)
|
| + {
|
| + }
|
| +
|
| + MatchedPropertiesVector::const_iterator begin() const { return m_begin; }
|
| + MatchedPropertiesVector::const_iterator end() const { return m_end; }
|
| +
|
| + bool isEmpty() const { return begin() == end(); }
|
| +
|
| +private:
|
| + MatchedPropertiesVector::const_iterator m_begin;
|
| + MatchedPropertiesVector::const_iterator m_end;
|
| +};
|
| +
|
| +class CORE_EXPORT MatchResult {
|
| STACK_ALLOCATED();
|
| public:
|
| void addMatchedProperties(const StylePropertySet* properties, unsigned linkMatchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone);
|
| + bool hasMatchedProperties() const { return m_matchedProperties.size(); }
|
| +
|
| + void finishAddingUARules();
|
| + void finishAddingAuthorRulesForTreeScope();
|
| +
|
| + void setIsCacheable(bool cacheable) { m_isCacheable = cacheable; }
|
| + bool isCacheable() const { return m_isCacheable; }
|
| +
|
| + MatchedPropertiesRange allRules() const { return MatchedPropertiesRange(m_matchedProperties.begin(), m_matchedProperties.end()); }
|
| + MatchedPropertiesRange uaRules() const { return MatchedPropertiesRange(m_matchedProperties.begin(), m_matchedProperties.begin() + m_uaRangeEnd); }
|
| + MatchedPropertiesRange authorRules() const { return MatchedPropertiesRange(m_matchedProperties.begin() + m_uaRangeEnd, m_matchedProperties.end()); }
|
| +
|
| + const MatchedPropertiesVector& matchedProperties() const { return m_matchedProperties; }
|
| +
|
| +private:
|
| + friend class ImportantAuthorRanges;
|
| + friend class ImportantAuthorRangeIterator;
|
| +
|
| + MatchedPropertiesVector m_matchedProperties;
|
| + Vector<unsigned, 16> m_authorRangeEnds;
|
| + unsigned m_uaRangeEnd = 0;
|
| + bool m_isCacheable = true;
|
| +};
|
| +
|
| +class ImportantAuthorRangeIterator {
|
| + STACK_ALLOCATED();
|
| +public:
|
| + ImportantAuthorRangeIterator(const MatchResult& result, int endIndex)
|
| + : m_result(result)
|
| + , m_endIndex(endIndex) { }
|
| +
|
| + MatchedPropertiesRange operator*() const
|
| + {
|
| + ASSERT(m_endIndex >= 0);
|
| + unsigned rangeEnd = m_result.m_authorRangeEnds[m_endIndex];
|
| + unsigned rangeBegin = m_endIndex ? m_result.m_authorRangeEnds[m_endIndex - 1] : m_result.m_uaRangeEnd;
|
| + return MatchedPropertiesRange(m_result.matchedProperties().begin() + rangeBegin, m_result.matchedProperties().begin() + rangeEnd);
|
| + }
|
| +
|
| + ImportantAuthorRangeIterator& operator++()
|
| + {
|
| + ASSERT(m_endIndex >= 0);
|
| + --m_endIndex;
|
| + return *this;
|
| + }
|
| +
|
| + bool operator==(const ImportantAuthorRangeIterator& other) const { return m_endIndex == other.m_endIndex && &m_result == &other.m_result; }
|
| + bool operator!=(const ImportantAuthorRangeIterator& other) const { return !(*this == other); }
|
| +
|
| +private:
|
| + const MatchResult& m_result;
|
| + unsigned m_endIndex;
|
| +};
|
| +
|
| +class ImportantAuthorRanges {
|
| + STACK_ALLOCATED();
|
| +public:
|
| + explicit ImportantAuthorRanges(const MatchResult& result) : m_result(result) { }
|
|
|
| - unsigned begin() const { return 0; }
|
| - unsigned end() const { return matchedProperties.size(); }
|
| - unsigned beginUA() const { return 0; }
|
| - unsigned endUA() const { return uaEnd; }
|
| - unsigned beginAuthor() const { return uaEnd; }
|
| - unsigned endAuthor() const { return matchedProperties.size(); }
|
| + ImportantAuthorRangeIterator begin() const { return ImportantAuthorRangeIterator(m_result, m_result.m_authorRangeEnds.size() - 1); }
|
| + ImportantAuthorRangeIterator end() const { return ImportantAuthorRangeIterator(m_result, -1); }
|
|
|
| - WillBeHeapVector<MatchedProperties, 64> matchedProperties;
|
| - unsigned uaEnd = 0;
|
| - bool isCacheable = true;
|
| +private:
|
| + const MatchResult& m_result;
|
| };
|
|
|
| inline bool operator==(const MatchedProperties& a, const MatchedProperties& b)
|
|
|