Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1 | /* |
| 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. |
| 4 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef MatchResult_h |
| 24 | #define MatchResult_h |
| 25 | |
| 26 | #include "core/css/RuleSet.h" |
| 27 | #include "core/css/SelectorChecker.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 28 | #include "wtf/RefPtr.h" |
| 29 | #include "wtf/Vector.h" |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | class StylePropertySet; |
| 34 | class StyleRule; |
| 35 | |
| 36 | struct RuleRange { |
| 37 | RuleRange(int& firstRuleIndex, int& lastRuleIndex): firstRuleIndex(firstRuleIndex), lastRuleIndex(lastRuleIndex) { } |
| 38 | int& firstRuleIndex; |
| 39 | int& lastRuleIndex; |
| 40 | }; |
| 41 | |
| 42 | struct MatchRanges { |
| 43 | MatchRanges() : firstUARule(-1), lastUARule(-1), firstAuthorRule(-1), lastAuthorRule(-1), firstUserRule(-1), lastUserRule(-1) { } |
| 44 | int firstUARule; |
| 45 | int lastUARule; |
| 46 | int firstAuthorRule; |
| 47 | int lastAuthorRule; |
| 48 | int firstUserRule; |
| 49 | int lastUserRule; |
| 50 | RuleRange UARuleRange() { return RuleRange(firstUARule, lastUARule); } |
| 51 | RuleRange authorRuleRange() { return RuleRange(firstAuthorRule, lastAuthorRule); } |
| 52 | RuleRange userRuleRange() { return RuleRange(firstUserRule, lastUserRule); } |
| 53 | }; |
| 54 | |
| 55 | struct MatchedProperties { |
| 56 | MatchedProperties(); |
| 57 | ~MatchedProperties(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 58 | |
| 59 | RefPtr<StylePropertySet> properties; |
| 60 | union { |
| 61 | struct { |
| 62 | unsigned linkMatchType : 2; |
| 63 | unsigned whitelistType : 2; |
| 64 | }; |
| 65 | // Used to make sure all memory is zero-initialized since we compute the hash over the bytes of this object. |
| 66 | void* possiblyPaddedMember; |
| 67 | }; |
| 68 | }; |
| 69 | |
| 70 | struct MatchResult { |
| 71 | MatchResult() : isCacheable(true) { } |
| 72 | Vector<MatchedProperties, 64> matchedProperties; |
| 73 | Vector<StyleRule*, 64> matchedRules; |
| 74 | MatchRanges ranges; |
| 75 | bool isCacheable; |
| 76 | |
| 77 | void addMatchedProperties(const StylePropertySet* properties, StyleRule* = 0, unsigned linkMatchType = SelectorChecker::MatchAll, PropertyWhitelistType = PropertyWhitelistNone); |
| 78 | }; |
| 79 | |
| 80 | inline bool operator==(const MatchRanges& a, const MatchRanges& b) |
| 81 | { |
| 82 | return a.firstUARule == b.firstUARule |
| 83 | && a.lastUARule == b.lastUARule |
| 84 | && a.firstAuthorRule == b.firstAuthorRule |
| 85 | && a.lastAuthorRule == b.lastAuthorRule |
| 86 | && a.firstUserRule == b.firstUserRule |
| 87 | && a.lastUserRule == b.lastUserRule; |
| 88 | } |
| 89 | |
| 90 | inline bool operator!=(const MatchRanges& a, const MatchRanges& b) |
| 91 | { |
| 92 | return !(a == b); |
| 93 | } |
| 94 | |
| 95 | inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) |
| 96 | { |
| 97 | return a.properties == b.properties && a.linkMatchType == b.linkMatchType; |
| 98 | } |
| 99 | |
| 100 | inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) |
| 101 | { |
| 102 | return !(a == b); |
| 103 | } |
| 104 | |
| 105 | } // namespace WebCore |
| 106 | |
| 107 | #endif // MatchResult_h |