| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "core/css/RuleSet.h" | 26 #include "core/css/RuleSet.h" |
| 27 #include "core/css/SelectorChecker.h" | 27 #include "core/css/SelectorChecker.h" |
| 28 #include "platform/heap/Handle.h" | 28 #include "platform/heap/Handle.h" |
| 29 #include "wtf/RefPtr.h" | 29 #include "wtf/RefPtr.h" |
| 30 #include "wtf/Vector.h" | 30 #include "wtf/Vector.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 class StylePropertySet; | 34 class StylePropertySet; |
| 35 | 35 |
| 36 struct CORE_EXPORT MatchedProperties { | 36 struct MatchedProperties { |
| 37 ALLOW_ONLY_INLINE_ALLOCATION(); | 37 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 38 public: | 38 public: |
| 39 MatchedProperties(); | 39 MatchedProperties(); |
| 40 ~MatchedProperties(); | 40 ~MatchedProperties(); |
| 41 | 41 |
| 42 DECLARE_TRACE(); | 42 DECLARE_TRACE(); |
| 43 | 43 |
| 44 RefPtrWillBeMember<StylePropertySet> properties; | 44 RefPtrWillBeMember<StylePropertySet> properties; |
| 45 | 45 |
| 46 union { | 46 union { |
| 47 struct { | 47 struct { |
| 48 unsigned linkMatchType : 2; | 48 unsigned linkMatchType : 2; |
| 49 unsigned whitelistType : 2; | 49 unsigned whitelistType : 2; |
| 50 } m_types; | 50 } m_types; |
| 51 // Used to make sure all memory is zero-initialized since we compute the
hash over the bytes of this object. | 51 // Used to make sure all memory is zero-initialized since we compute the
hash over the bytes of this object. |
| 52 void* possiblyPaddedMember; | 52 void* possiblyPaddedMember; |
| 53 }; | 53 }; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 } // namespace blink | 56 } // namespace blink |
| 57 | 57 |
| 58 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedProperties); | 58 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedProperties); |
| 59 | 59 |
| 60 namespace blink { | 60 namespace blink { |
| 61 | 61 |
| 62 using MatchedPropertiesVector = WillBeHeapVector<MatchedProperties, 64>; | 62 class MatchResult { |
| 63 | |
| 64 // MatchedPropertiesRange is used to represent a subset of the matched propertie
s from | |
| 65 // a given origin, for instance UA rules, author rules, or a shadow tree scope.
This is | |
| 66 // needed because rules from different origins are applied in the opposite order
for | |
| 67 // !important rules, yet in the same order as for normal rules within the same o
rigin. | |
| 68 | |
| 69 class MatchedPropertiesRange { | |
| 70 public: | |
| 71 MatchedPropertiesRange(MatchedPropertiesVector::const_iterator begin, Matche
dPropertiesVector::const_iterator end) | |
| 72 : m_begin(begin) | |
| 73 , m_end(end) | |
| 74 { | |
| 75 } | |
| 76 | |
| 77 MatchedPropertiesVector::const_iterator begin() const { return m_begin; } | |
| 78 MatchedPropertiesVector::const_iterator end() const { return m_end; } | |
| 79 | |
| 80 bool isEmpty() const { return begin() == end(); } | |
| 81 | |
| 82 private: | |
| 83 MatchedPropertiesVector::const_iterator m_begin; | |
| 84 MatchedPropertiesVector::const_iterator m_end; | |
| 85 }; | |
| 86 | |
| 87 class CORE_EXPORT MatchResult { | |
| 88 STACK_ALLOCATED(); | 63 STACK_ALLOCATED(); |
| 89 public: | 64 public: |
| 90 void addMatchedProperties(const StylePropertySet* properties, unsigned linkM
atchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone)
; | 65 void addMatchedProperties(const StylePropertySet* properties, unsigned linkM
atchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone)
; |
| 91 bool hasMatchedProperties() const { return m_matchedProperties.size(); } | |
| 92 | 66 |
| 93 void finishAddingUARules(); | 67 unsigned begin() const { return 0; } |
| 94 void finishAddingAuthorRulesForTreeScope(); | 68 unsigned end() const { return matchedProperties.size(); } |
| 69 unsigned beginUA() const { return 0; } |
| 70 unsigned endUA() const { return uaEnd; } |
| 71 unsigned beginAuthor() const { return uaEnd; } |
| 72 unsigned endAuthor() const { return matchedProperties.size(); } |
| 95 | 73 |
| 96 void setIsCacheable(bool cacheable) { m_isCacheable = cacheable; } | 74 WillBeHeapVector<MatchedProperties, 64> matchedProperties; |
| 97 bool isCacheable() const { return m_isCacheable; } | 75 unsigned uaEnd = 0; |
| 98 | 76 bool isCacheable = true; |
| 99 MatchedPropertiesRange allRules() const { return MatchedPropertiesRange(m_ma
tchedProperties.begin(), m_matchedProperties.end()); } | |
| 100 MatchedPropertiesRange uaRules() const { return MatchedPropertiesRange(m_mat
chedProperties.begin(), m_matchedProperties.begin() + m_uaRangeEnd); } | |
| 101 MatchedPropertiesRange authorRules() const { return MatchedPropertiesRange(m
_matchedProperties.begin() + m_uaRangeEnd, m_matchedProperties.end()); } | |
| 102 | |
| 103 const MatchedPropertiesVector& matchedProperties() const { return m_matchedP
roperties; } | |
| 104 | |
| 105 private: | |
| 106 friend class ImportantAuthorRanges; | |
| 107 friend class ImportantAuthorRangeIterator; | |
| 108 | |
| 109 MatchedPropertiesVector m_matchedProperties; | |
| 110 Vector<unsigned, 16> m_authorRangeEnds; | |
| 111 unsigned m_uaRangeEnd = 0; | |
| 112 bool m_isCacheable = true; | |
| 113 }; | |
| 114 | |
| 115 class ImportantAuthorRangeIterator { | |
| 116 public: | |
| 117 ImportantAuthorRangeIterator(const MatchResult& result, int endIndex) | |
| 118 : m_result(result) | |
| 119 , m_endIndex(endIndex) { } | |
| 120 | |
| 121 MatchedPropertiesRange operator*() const | |
| 122 { | |
| 123 ASSERT(m_endIndex >= 0); | |
| 124 unsigned rangeEnd = m_result.m_authorRangeEnds[m_endIndex]; | |
| 125 unsigned rangeBegin = m_endIndex ? m_result.m_authorRangeEnds[m_endIndex
- 1] : m_result.m_uaRangeEnd; | |
| 126 return MatchedPropertiesRange(m_result.matchedProperties().begin() + ran
geBegin, m_result.matchedProperties().begin() + rangeEnd); | |
| 127 } | |
| 128 | |
| 129 ImportantAuthorRangeIterator& operator++() | |
| 130 { | |
| 131 ASSERT(m_endIndex >= 0); | |
| 132 --m_endIndex; | |
| 133 return *this; | |
| 134 } | |
| 135 | |
| 136 bool operator==(const ImportantAuthorRangeIterator& other) const { return m_
endIndex == other.m_endIndex && &m_result == &other.m_result; } | |
| 137 bool operator!=(const ImportantAuthorRangeIterator& other) const { return !(
*this == other); } | |
| 138 | |
| 139 private: | |
| 140 const MatchResult& m_result; | |
| 141 unsigned m_endIndex; | |
| 142 }; | |
| 143 | |
| 144 class ImportantAuthorRanges { | |
| 145 public: | |
| 146 explicit ImportantAuthorRanges(const MatchResult& result) : m_result(result)
{ } | |
| 147 | |
| 148 ImportantAuthorRangeIterator begin() const { return ImportantAuthorRangeIter
ator(m_result, m_result.m_authorRangeEnds.size() - 1); } | |
| 149 ImportantAuthorRangeIterator end() const { return ImportantAuthorRangeIterat
or(m_result, -1); } | |
| 150 | |
| 151 private: | |
| 152 const MatchResult& m_result; | |
| 153 }; | 77 }; |
| 154 | 78 |
| 155 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) | 79 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) |
| 156 { | 80 { |
| 157 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types.
linkMatchType; | 81 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types.
linkMatchType; |
| 158 } | 82 } |
| 159 | 83 |
| 160 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) | 84 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) |
| 161 { | 85 { |
| 162 return !(a == b); | 86 return !(a == b); |
| 163 } | 87 } |
| 164 | 88 |
| 165 } // namespace blink | 89 } // namespace blink |
| 166 | 90 |
| 167 #endif // MatchResult_h | 91 #endif // MatchResult_h |
| OLD | NEW |