Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: Source/core/css/resolver/MatchResult.h

Issue 1224673002: Implement proposed shadow tree cascade order. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added documentation Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 closeOriginOrScope(bool isUAOrigin);
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(); }
73 92
74 WillBeHeapVector<MatchedProperties, 64> matchedProperties; 93 void setIsCacheable(bool cacheable) { m_isCacheable = cacheable; }
75 unsigned uaEnd = 0; 94 bool isCacheable() const { return m_isCacheable; }
76 bool isCacheable = true; 95
96 MatchedPropertiesRange allRules() const { return MatchedPropertiesRange(m_ma tchedProperties.begin(), m_matchedProperties.end()); }
97 MatchedPropertiesRange uaRules() const { return MatchedPropertiesRange(m_mat chedProperties.begin(), m_matchedProperties.begin() + m_rangeEnd.first()); }
98 MatchedPropertiesRange authorRules() const { return MatchedPropertiesRange(m _matchedProperties.begin() + m_rangeEnd.first(), m_matchedProperties.end()); }
99
100 const MatchedPropertiesVector& matchedProperties() const { return m_matchedP roperties; }
101
102 private:
103 friend class ImportantAuthorRanges;
104 friend class ImportantAuthorRangeIterator;
105
106 MatchedPropertiesVector m_matchedProperties;
107
108 // End indices for all MatchedPropertiesRanges of m_matchedProperties.
109 // That is, the index of the first element of the next range. We always
110 // store an end index for UA rules even if we have no UA rules,
111 // hence this vector's length is >= 1. If there are No UA rules, the first
112 // entry will be 0 indicating an empty range.
113 Vector<unsigned, 16> m_rangeEnd;
114
115 bool m_isCacheable = true;
116 };
117
118 class ImportantAuthorRangeIterator {
119 public:
120 ImportantAuthorRangeIterator(const MatchResult& result, unsigned index)
121 : m_result(result)
122 , m_index(index) { }
123
124 MatchedPropertiesRange operator*() const
125 {
126 // index = 0 is the UA rule range.
127 ASSERT(m_index);
128 return MatchedPropertiesRange(m_result.m_matchedProperties.begin() + m_r esult.m_rangeEnd[m_index - 1], m_result.m_matchedProperties.begin() + m_result.m _rangeEnd[m_index]);
129 }
130
131 ImportantAuthorRangeIterator& operator++()
132 {
133 ASSERT(m_index);
134 --m_index;
135 return *this;
136 }
137
138 bool operator!=(const ImportantAuthorRangeIterator& other) const { return m_ index != other.m_index || &m_result != &other.m_result; }
139
140 private:
141 const MatchResult& m_result;
142 unsigned m_index;
143 };
144
145 class ImportantAuthorRanges {
146 public:
147 explicit ImportantAuthorRanges(const MatchResult& result) : m_result(result) { }
148
149 ImportantAuthorRangeIterator begin() const { return ImportantAuthorRangeIter ator(m_result, m_result.m_rangeEnd.size() - 1); }
150 ImportantAuthorRangeIterator end() const { return ImportantAuthorRangeIterat or(m_result, 0); }
151
152 private:
153 const MatchResult& m_result;
77 }; 154 };
78 155
79 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) 156 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b)
80 { 157 {
81 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types. linkMatchType; 158 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types. linkMatchType;
82 } 159 }
83 160
84 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) 161 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b)
85 { 162 {
86 return !(a == b); 163 return !(a == b);
87 } 164 }
88 165
89 } // namespace blink 166 } // namespace blink
90 167
91 #endif // MatchResult_h 168 #endif // MatchResult_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698