| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "sky/engine/core/dom/SpaceSplitString.h" | 41 #include "sky/engine/core/dom/SpaceSplitString.h" |
| 42 #include "sky/engine/core/dom/shadow/ElementShadow.h" | 42 #include "sky/engine/core/dom/shadow/ElementShadow.h" |
| 43 #include "sky/engine/core/dom/shadow/InsertionPoint.h" | 43 #include "sky/engine/core/dom/shadow/InsertionPoint.h" |
| 44 #include "sky/engine/core/html/HTMLElement.h" | 44 #include "sky/engine/core/html/HTMLElement.h" |
| 45 #include "sky/engine/core/rendering/style/RenderStyle.h" | 45 #include "sky/engine/core/rendering/style/RenderStyle.h" |
| 46 #include "sky/engine/wtf/HashSet.h" | 46 #include "sky/engine/wtf/HashSet.h" |
| 47 #include "sky/engine/wtf/text/AtomicString.h" | 47 #include "sky/engine/wtf/text/AtomicString.h" |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 bool SharedStyleFinder::classNamesAffectedByRules(const SpaceSplitString& classN
ames) const | 51 bool SharedStyleFinder::classNamesAffectedByRules(const Element& element) const |
| 52 { | 52 { |
| 53 const SpaceSplitString& classNames = element.classNames(); |
| 53 unsigned count = classNames.size(); | 54 unsigned count = classNames.size(); |
| 54 for (unsigned i = 0; i < count; ++i) { | 55 for (unsigned i = 0; i < count; ++i) { |
| 55 if (m_features.hasSelectorForClass(classNames[i])) | 56 if (m_features.hasSelectorForClass(classNames[i])) |
| 56 return true; | 57 return true; |
| 57 } | 58 } |
| 58 return false; | 59 return false; |
| 59 } | 60 } |
| 60 | 61 |
| 62 bool SharedStyleFinder::attributesAffectedByRules(const Element& element) const |
| 63 { |
| 64 for (auto& attribute : element.attributesWithoutUpdate()) { |
| 65 if (m_features.hasSelectorForAttribute(attribute.localName())) |
| 66 return true; |
| 67 } |
| 68 return false; |
| 69 } |
| 70 |
| 61 bool SharedStyleFinder::sharingCandidateHasIdenticalStyleAffectingAttributes(Ele
ment& candidate) const | 71 bool SharedStyleFinder::sharingCandidateHasIdenticalStyleAffectingAttributes(Ele
ment& candidate) const |
| 62 { | 72 { |
| 63 if (element().sharesSameElementData(candidate)) | 73 if (element().sharesSameElementData(candidate)) |
| 64 return true; | 74 return true; |
| 65 if (element().getAttribute(HTMLNames::langAttr) != candidate.getAttribute(HT
MLNames::langAttr)) | 75 if (element().getAttribute(HTMLNames::langAttr) != candidate.getAttribute(HT
MLNames::langAttr)) |
| 66 return false; | 76 return false; |
| 67 | 77 |
| 68 if (!m_elementAffectedByClassRules) { | 78 if (!m_elementAffectedByClassRules) { |
| 69 if (candidate.hasClass() && classNamesAffectedByRules(candidate.classNam
es())) | 79 if (candidate.hasClass() && classNamesAffectedByRules(candidate)) |
| 70 return false; | 80 return false; |
| 71 } else if (candidate.hasClass()) { | 81 } else if (candidate.hasClass()) { |
| 72 if (element().classNames() != candidate.classNames()) | 82 if (element().classNames() != candidate.classNames()) |
| 73 return false; | 83 return false; |
| 74 } else { | 84 } else { |
| 75 return false; | 85 return false; |
| 76 } | 86 } |
| 77 | 87 |
| 78 return true; | 88 return true; |
| 79 } | 89 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Move the element to the front of the LRU | 179 // Move the element to the front of the LRU |
| 170 styleSharingList.remove(it); | 180 styleSharingList.remove(it); |
| 171 styleSharingList.prepend(&candidate); | 181 styleSharingList.prepend(&candidate); |
| 172 } | 182 } |
| 173 return &candidate; | 183 return &candidate; |
| 174 } | 184 } |
| 175 m_styleResolver.addToStyleSharingList(element()); | 185 m_styleResolver.addToStyleSharingList(element()); |
| 176 return 0; | 186 return 0; |
| 177 } | 187 } |
| 178 | 188 |
| 179 bool SharedStyleFinder::matchesRuleSet(RuleSet* ruleSet) | |
| 180 { | |
| 181 if (!ruleSet) | |
| 182 return false; | |
| 183 ElementRuleCollector collector(m_context); | |
| 184 return collector.hasAnyMatchingRules(ruleSet); | |
| 185 } | |
| 186 | |
| 187 RenderStyle* SharedStyleFinder::findSharedStyle() | 189 RenderStyle* SharedStyleFinder::findSharedStyle() |
| 188 { | 190 { |
| 189 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleLookups); | 191 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleLookups); |
| 190 | 192 |
| 191 if (!element().supportsStyleSharing()) | 193 if (!element().supportsStyleSharing()) |
| 192 return 0; | 194 return 0; |
| 193 | 195 |
| 196 if (attributesAffectedByRules(element())) { |
| 197 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr
ibuteRules); |
| 198 return 0; |
| 199 } |
| 200 |
| 194 // Cache whether context.element() is affected by any known class selectors. | 201 // Cache whether context.element() is affected by any known class selectors. |
| 195 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy
Rules(element().classNames()); | 202 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy
Rules(element()); |
| 196 | 203 |
| 197 Element* shareElement = findElementForStyleSharing(); | 204 Element* shareElement = findElementForStyleSharing(); |
| 198 | 205 |
| 199 if (!shareElement) { | 206 if (!shareElement) { |
| 200 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi
dateCount && documentContainsValidCandidate()) | 207 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi
dateCount && documentContainsValidCandidate()) |
| 201 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); | 208 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); |
| 202 return 0; | 209 return 0; |
| 203 } | 210 } |
| 204 | 211 |
| 205 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); | 212 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); |
| 206 | 213 |
| 207 if (matchesRuleSet(m_attributeRuleSet)) { | 214 if (attributesAffectedByRules(*shareElement)) { |
| 208 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr
ibuteRules); | 215 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr
ibuteRules); |
| 209 return 0; | 216 return 0; |
| 210 } | 217 } |
| 211 | 218 |
| 212 return shareElement->renderStyle(); | 219 return shareElement->renderStyle(); |
| 213 } | 220 } |
| 214 | 221 |
| 215 } | 222 } |
| OLD | NEW |