 Chromium Code Reviews
 Chromium Code Reviews Issue 1282243002:
  Prepare for multiple !important author ranges.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 1282243002:
  Prepare for multiple !important author ranges.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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>; | |
| 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 private: | |
| 81 MatchedPropertiesVector::const_iterator m_begin; | |
| 82 MatchedPropertiesVector::const_iterator m_end; | |
| 83 }; | |
| 84 | |
| 62 class MatchResult { | 85 class MatchResult { | 
| 63 STACK_ALLOCATED(); | 86 STACK_ALLOCATED(); | 
| 64 public: | 87 public: | 
| 65 void addMatchedProperties(const StylePropertySet* properties, unsigned linkM atchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone) ; | 88 void addMatchedProperties(const StylePropertySet* properties, unsigned linkM atchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone) ; | 
| 89 bool hasMatchedProperties() const { return m_matchedProperties.size(); } | |
| 66 | 90 | 
| 67 unsigned begin() const { return 0; } | 91 void uaRulesFinished(); | 
| 
kochi
2015/08/11 11:07:35
It sounds a bit strange to have "Finished" suffix
 
rune
2015/08/12 01:13:26
Done.
 | |
| 68 unsigned end() const { return matchedProperties.size(); } | 92 void authorScopeFinished(); | 
| 
kochi
2015/08/11 11:07:35
Ditto, and why "Scope", not "Rules"?
What about f
 
rune
2015/08/12 01:13:26
Done.
 | |
| 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(); } | |
| 73 | 93 | 
| 74 WillBeHeapVector<MatchedProperties, 64> matchedProperties; | 94 void setIsCacheable(bool cacheable) { m_isCacheable = cacheable; } | 
| 75 unsigned uaEnd = 0; | 95 bool isCacheable() const { return m_isCacheable; } | 
| 76 bool isCacheable = true; | 96 | 
| 97 MatchedPropertiesRange allRules() const { return MatchedPropertiesRange(m_ma tchedProperties.begin(), m_matchedProperties.end()); } | |
| 98 MatchedPropertiesRange uaRules() const { return MatchedPropertiesRange(m_mat chedProperties.begin(), m_matchedProperties.begin() + m_uaRangeEnd); } | |
| 99 MatchedPropertiesRange authorRules() const { return MatchedPropertiesRange(m _matchedProperties.begin() + m_uaRangeEnd, m_matchedProperties.end()); } | |
| 100 | |
| 101 const MatchedPropertiesVector& matchedProperties() const { return m_matchedP roperties; } | |
| 102 | |
| 103 private: | |
| 104 friend class ImportantAuthorRanges; | |
| 105 friend class ImportantAuthorRangeIterator; | |
| 106 | |
| 107 MatchedPropertiesVector m_matchedProperties; | |
| 108 Vector<unsigned, 16> m_authorRangeEnd; | |
| 
kochi
2015/08/11 11:07:35
At first I was confused why m_uaRangeEnd is a scal
 
rune
2015/08/12 01:13:26
Done.
 | |
| 109 unsigned m_uaRangeEnd = 0; | |
| 110 bool m_isCacheable = true; | |
| 111 }; | |
| 112 | |
| 113 class ImportantAuthorRangeIterator { | |
| 114 public: | |
| 115 ImportantAuthorRangeIterator(const MatchResult& result, int endIndex) | |
| 116 : m_result(result) | |
| 117 , m_endIndex(endIndex) { } | |
| 118 | |
| 119 MatchedPropertiesRange operator*() const | |
| 120 { | |
| 121 ASSERT(m_endIndex >= 0); | |
| 122 unsigned rangeEnd = m_result.m_authorRangeEnd[m_endIndex]; | |
| 123 unsigned rangeBegin = m_endIndex ? m_result.m_authorRangeEnd[m_endIndex - 1] : m_result.m_uaRangeEnd; | |
| 124 return MatchedPropertiesRange(m_result.matchedProperties().begin() + ran geBegin, m_result.matchedProperties().begin() + rangeEnd); | |
| 125 } | |
| 126 | |
| 127 ImportantAuthorRangeIterator& operator++() | |
| 128 { | |
| 129 ASSERT(m_endIndex >= 0); | |
| 130 --m_endIndex; | |
| 131 return *this; | |
| 132 } | |
| 133 | |
| 134 bool operator!=(const ImportantAuthorRangeIterator& other) const { return m_ endIndex != other.m_endIndex || &m_result != &other.m_result; } | |
| 135 | |
| 136 private: | |
| 137 const MatchResult& m_result; | |
| 138 unsigned m_endIndex; | |
| 139 }; | |
| 140 | |
| 141 class ImportantAuthorRanges { | |
| 142 public: | |
| 143 explicit ImportantAuthorRanges(const MatchResult& result) : m_result(result) { } | |
| 144 | |
| 145 ImportantAuthorRangeIterator begin() const { return ImportantAuthorRangeIter ator(m_result, m_result.m_authorRangeEnd.size() - 1); } | |
| 146 ImportantAuthorRangeIterator end() const { return ImportantAuthorRangeIterat or(m_result, -1); } | |
| 147 | |
| 148 private: | |
| 149 const MatchResult& m_result; | |
| 77 }; | 150 }; | 
| 78 | 151 | 
| 79 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) | 152 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) | 
| 80 { | 153 { | 
| 81 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types. linkMatchType; | 154 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types. linkMatchType; | 
| 82 } | 155 } | 
| 83 | 156 | 
| 84 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) | 157 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) | 
| 85 { | 158 { | 
| 86 return !(a == b); | 159 return !(a == b); | 
| 87 } | 160 } | 
| 88 | 161 | 
| 89 } // namespace blink | 162 } // namespace blink | 
| 90 | 163 | 
| 91 #endif // MatchResult_h | 164 #endif // MatchResult_h | 
| OLD | NEW |