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

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

Issue 1282243002: Prepare for multiple !important author ranges. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Missing STACK_ALLOCATED() 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
« no previous file with comments | « Source/core/css/ElementRuleCollector.cpp ('k') | Source/core/css/resolver/MatchResult.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 15 matching lines...) Expand all
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 MatchedProperties { 36 struct CORE_EXPORT 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 class MatchResult { 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 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 {
63 STACK_ALLOCATED(); 88 STACK_ALLOCATED();
64 public: 89 public:
65 void addMatchedProperties(const StylePropertySet* properties, unsigned linkM atchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone) ; 90 void addMatchedProperties(const StylePropertySet* properties, unsigned linkM atchType = CSSSelector::MatchAll, PropertyWhitelistType = PropertyWhitelistNone) ;
91 bool hasMatchedProperties() const { return m_matchedProperties.size(); }
66 92
67 unsigned begin() const { return 0; } 93 void finishAddingUARules();
68 unsigned end() const { return matchedProperties.size(); } 94 void finishAddingAuthorRulesForTreeScope();
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 95
74 WillBeHeapVector<MatchedProperties, 64> matchedProperties; 96 void setIsCacheable(bool cacheable) { m_isCacheable = cacheable; }
75 unsigned uaEnd = 0; 97 bool isCacheable() const { return m_isCacheable; }
76 bool isCacheable = true; 98
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 STACK_ALLOCATED();
117 public:
118 ImportantAuthorRangeIterator(const MatchResult& result, int endIndex)
119 : m_result(result)
120 , m_endIndex(endIndex) { }
121
122 MatchedPropertiesRange operator*() const
123 {
124 ASSERT(m_endIndex >= 0);
125 unsigned rangeEnd = m_result.m_authorRangeEnds[m_endIndex];
126 unsigned rangeBegin = m_endIndex ? m_result.m_authorRangeEnds[m_endIndex - 1] : m_result.m_uaRangeEnd;
127 return MatchedPropertiesRange(m_result.matchedProperties().begin() + ran geBegin, m_result.matchedProperties().begin() + rangeEnd);
128 }
129
130 ImportantAuthorRangeIterator& operator++()
131 {
132 ASSERT(m_endIndex >= 0);
133 --m_endIndex;
134 return *this;
135 }
136
137 bool operator==(const ImportantAuthorRangeIterator& other) const { return m_ endIndex == other.m_endIndex && &m_result == &other.m_result; }
138 bool operator!=(const ImportantAuthorRangeIterator& other) const { return !( *this == other); }
139
140 private:
141 const MatchResult& m_result;
142 unsigned m_endIndex;
143 };
144
145 class ImportantAuthorRanges {
146 STACK_ALLOCATED();
147 public:
148 explicit ImportantAuthorRanges(const MatchResult& result) : m_result(result) { }
149
150 ImportantAuthorRangeIterator begin() const { return ImportantAuthorRangeIter ator(m_result, m_result.m_authorRangeEnds.size() - 1); }
151 ImportantAuthorRangeIterator end() const { return ImportantAuthorRangeIterat or(m_result, -1); }
152
153 private:
154 const MatchResult& m_result;
77 }; 155 };
78 156
79 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) 157 inline bool operator==(const MatchedProperties& a, const MatchedProperties& b)
80 { 158 {
81 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types. linkMatchType; 159 return a.properties == b.properties && a.m_types.linkMatchType == b.m_types. linkMatchType;
82 } 160 }
83 161
84 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) 162 inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b)
85 { 163 {
86 return !(a == b); 164 return !(a == b);
87 } 165 }
88 166
89 } // namespace blink 167 } // namespace blink
90 168
91 #endif // MatchResult_h 169 #endif // MatchResult_h
OLDNEW
« no previous file with comments | « Source/core/css/ElementRuleCollector.cpp ('k') | Source/core/css/resolver/MatchResult.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698