Chromium Code Reviews| 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 AttributeCollection attributes = element.attributesWithoutUpdate(); | |
| 65 AttributeCollection::iterator end = attributes.end(); | |
| 66 for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it) { | |
|
ojan
2014/12/10 23:22:58
Can you use C++11 iterators here? I think the synt
| |
| 67 if (m_features.hasSelectorForAttribute(it->localName())) | |
| 68 return true; | |
| 69 } | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 61 bool SharedStyleFinder::sharingCandidateHasIdenticalStyleAffectingAttributes(Ele ment& candidate) const | 73 bool SharedStyleFinder::sharingCandidateHasIdenticalStyleAffectingAttributes(Ele ment& candidate) const |
| 62 { | 74 { |
| 63 if (element().sharesSameElementData(candidate)) | 75 if (element().sharesSameElementData(candidate)) |
| 64 return true; | 76 return true; |
| 65 if (element().getAttribute(HTMLNames::langAttr) != candidate.getAttribute(HT MLNames::langAttr)) | 77 if (element().getAttribute(HTMLNames::langAttr) != candidate.getAttribute(HT MLNames::langAttr)) |
| 66 return false; | 78 return false; |
| 67 | 79 |
| 68 if (!m_elementAffectedByClassRules) { | 80 if (!m_elementAffectedByClassRules) { |
| 69 if (candidate.hasClass() && classNamesAffectedByRules(candidate.classNam es())) | 81 if (candidate.hasClass() && classNamesAffectedByRules(candidate)) |
| 70 return false; | 82 return false; |
| 71 } else if (candidate.hasClass()) { | 83 } else if (candidate.hasClass()) { |
| 72 if (element().classNames() != candidate.classNames()) | 84 if (element().classNames() != candidate.classNames()) |
| 73 return false; | 85 return false; |
| 74 } else { | 86 } else { |
| 75 return false; | 87 return false; |
| 76 } | 88 } |
| 77 | 89 |
| 78 return true; | 90 return true; |
| 79 } | 91 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 // Move the element to the front of the LRU | 181 // Move the element to the front of the LRU |
| 170 styleSharingList.remove(it); | 182 styleSharingList.remove(it); |
| 171 styleSharingList.prepend(&candidate); | 183 styleSharingList.prepend(&candidate); |
| 172 } | 184 } |
| 173 return &candidate; | 185 return &candidate; |
| 174 } | 186 } |
| 175 m_styleResolver.addToStyleSharingList(element()); | 187 m_styleResolver.addToStyleSharingList(element()); |
| 176 return 0; | 188 return 0; |
| 177 } | 189 } |
| 178 | 190 |
| 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() | 191 RenderStyle* SharedStyleFinder::findSharedStyle() |
| 188 { | 192 { |
| 189 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleLookups); | 193 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleLookups); |
| 190 | 194 |
| 191 if (!element().supportsStyleSharing()) | 195 if (!element().supportsStyleSharing()) |
| 192 return 0; | 196 return 0; |
| 193 | 197 |
| 198 if (attributesAffectedByRules(element())) { | |
| 199 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); | |
| 200 return 0; | |
| 201 } | |
| 202 | |
| 194 // Cache whether context.element() is affected by any known class selectors. | 203 // Cache whether context.element() is affected by any known class selectors. |
| 195 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy Rules(element().classNames()); | 204 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy Rules(element()); |
| 196 | 205 |
| 197 Element* shareElement = findElementForStyleSharing(); | 206 Element* shareElement = findElementForStyleSharing(); |
| 198 | 207 |
| 199 if (!shareElement) { | 208 if (!shareElement) { |
| 200 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi dateCount && documentContainsValidCandidate()) | 209 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi dateCount && documentContainsValidCandidate()) |
| 201 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); | 210 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); |
| 202 return 0; | 211 return 0; |
| 203 } | 212 } |
| 204 | 213 |
| 205 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); | 214 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); |
| 206 | 215 |
| 207 if (matchesRuleSet(m_attributeRuleSet)) { | 216 if (attributesAffectedByRules(*shareElement)) { |
| 208 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); | 217 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); |
| 209 return 0; | 218 return 0; |
| 210 } | 219 } |
| 211 | 220 |
| 212 return shareElement->renderStyle(); | 221 return shareElement->renderStyle(); |
| 213 } | 222 } |
| 214 | 223 |
| 215 } | 224 } |
| OLD | NEW |