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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 95 |
| 96 if (!elementShadow && !candidateShadow) | 96 if (!elementShadow && !candidateShadow) |
| 97 return true; | 97 return true; |
| 98 | 98 |
| 99 if (static_cast<bool>(elementShadow) != static_cast<bool>(candidateShadow)) | 99 if (static_cast<bool>(elementShadow) != static_cast<bool>(candidateShadow)) |
| 100 return false; | 100 return false; |
| 101 | 101 |
| 102 return elementShadow->hasSameStyles(candidateShadow); | 102 return elementShadow->hasSameStyles(candidateShadow); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool SharedStyleFinder::sharingCandidateDistributedToSameInsertionPoint(Element& candidate) const | |
| 106 { | |
| 107 Vector<RawPtr<InsertionPoint>, 8> insertionPoints, candidateInsertionPoints; | |
| 108 collectDestinationInsertionPoints(element(), insertionPoints); | |
| 109 collectDestinationInsertionPoints(candidate, candidateInsertionPoints); | |
| 110 if (insertionPoints.size() != candidateInsertionPoints.size()) | |
| 111 return false; | |
| 112 for (size_t i = 0; i < insertionPoints.size(); ++i) { | |
| 113 if (insertionPoints[i] != candidateInsertionPoints[i]) | |
| 114 return false; | |
| 115 } | |
| 116 return true; | |
| 117 } | |
| 118 | |
| 119 bool SharedStyleFinder::canShareStyleWithElement(Element& candidate) const | 105 bool SharedStyleFinder::canShareStyleWithElement(Element& candidate) const |
| 120 { | 106 { |
| 107 ASSERT(candidate.supportsStyleSharing()); | |
| 108 | |
| 121 if (element() == candidate) | 109 if (element() == candidate) |
| 122 return false; | 110 return false; |
| 123 Element* parent = candidate.parentOrShadowHostElement(); | 111 if (candidate.tagQName() != element().tagQName()) |
| 112 return false; | |
| 113 if (candidate.needsStyleRecalc()) | |
| 114 return false; | |
| 124 RenderStyle* style = candidate.renderStyle(); | 115 RenderStyle* style = candidate.renderStyle(); |
| 125 if (!style) | 116 if (!style) |
| 126 return false; | 117 return false; |
| 127 if (!style->isSharable()) | 118 if (!style->isSharable()) |
| 128 return false; | 119 return false; |
| 120 ContainerNode* parent = NodeRenderingTraversal::parent(&candidate); | |
| 129 if (!parent) | 121 if (!parent) |
| 130 return false; | 122 return false; |
| 131 if (element().parentOrShadowHostElement()->renderStyle() != parent->renderSt yle()) | 123 RenderStyle* parentStyle = parent->renderStyle(); |
| 124 if (!parentStyle) | |
| 132 return false; | 125 return false; |
| 133 if (candidate.tagQName() != element().tagQName()) | 126 if (m_renderingParent->renderStyle()->inheritedNotEqual(parentStyle)) |
| 134 return false; | |
| 135 if (candidate.inlineStyle()) | |
|
ojan
2014/12/11 19:35:54
Why don't we need this check? Where do we check th
esprehn
2014/12/11 23:09:58
supportsStyleSharing() contains this check, and we
| |
| 136 return false; | |
| 137 if (candidate.needsStyleRecalc()) | |
| 138 return false; | 127 return false; |
| 139 if (!sharingCandidateHasIdenticalStyleAffectingAttributes(candidate)) | 128 if (!sharingCandidateHasIdenticalStyleAffectingAttributes(candidate)) |
| 140 return false; | 129 return false; |
| 141 if (candidate.hasID() && m_features.hasSelectorForId(candidate.idForStyleRes olution())) | |
|
ojan
2014/12/11 19:35:54
Getting rid of this means we do less work on pages
esprehn
2014/12/11 23:09:59
This is also inside supportsStyleSharing().
| |
| 142 return false; | |
| 143 if (!sharingCandidateCanShareHostStyles(candidate)) | 130 if (!sharingCandidateCanShareHostStyles(candidate)) |
| 144 return false; | 131 return false; |
| 145 if (!sharingCandidateDistributedToSameInsertionPoint(candidate)) | 132 if (!candidate.treeScope().hasSameStyles(element().treeScope())) |
| 146 return false; | 133 return false; |
| 147 if (candidate.isUnresolvedCustomElement() != element().isUnresolvedCustomEle ment()) | 134 if (candidate.isUnresolvedCustomElement() != element().isUnresolvedCustomEle ment()) |
| 148 return false; | 135 return false; |
| 149 | |
| 150 if (element().parentOrShadowHostElement() != parent) { | |
| 151 if (!parent->isStyledElement()) | |
| 152 return false; | |
| 153 if (parent->inlineStyle()) | |
| 154 return false; | |
| 155 if (parent->hasID() && m_features.hasSelectorForId(parent->idForStyleRes olution())) | |
| 156 return false; | |
| 157 } | |
| 158 | |
| 159 return true; | 136 return true; |
| 160 } | 137 } |
| 161 | 138 |
| 162 bool SharedStyleFinder::documentContainsValidCandidate() const | 139 bool SharedStyleFinder::documentContainsValidCandidate() const |
| 163 { | 140 { |
| 164 for (Element* element = document().documentElement(); element; element = Ele mentTraversal::next(*element)) { | 141 for (Element* element = document().documentElement(); element; element = Ele mentTraversal::next(*element)) { |
| 165 if (element->supportsStyleSharing() && canShareStyleWithElement(*element )) | 142 if (element->supportsStyleSharing() && canShareStyleWithElement(*element )) |
| 166 return true; | 143 return true; |
| 167 } | 144 } |
| 168 return false; | 145 return false; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 193 if (!element().supportsStyleSharing()) | 170 if (!element().supportsStyleSharing()) |
| 194 return 0; | 171 return 0; |
| 195 | 172 |
| 196 if (attributesAffectedByRules(element())) { | 173 if (attributesAffectedByRules(element())) { |
| 197 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); | 174 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); |
| 198 return 0; | 175 return 0; |
| 199 } | 176 } |
| 200 | 177 |
| 201 // Cache whether context.element() is affected by any known class selectors. | 178 // Cache whether context.element() is affected by any known class selectors. |
| 202 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy Rules(element()); | 179 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy Rules(element()); |
| 180 m_renderingParent = NodeRenderingTraversal::parent(&element()); | |
| 203 | 181 |
| 204 Element* shareElement = findElementForStyleSharing(); | 182 Element* shareElement = findElementForStyleSharing(); |
| 205 | 183 |
| 206 if (!shareElement) { | 184 if (!shareElement) { |
| 207 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi dateCount && documentContainsValidCandidate()) | 185 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi dateCount && documentContainsValidCandidate()) |
| 208 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); | 186 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); |
| 209 return 0; | 187 return 0; |
| 210 } | 188 } |
| 211 | 189 |
| 212 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); | 190 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); |
| 213 | 191 |
| 214 if (attributesAffectedByRules(*shareElement)) { | 192 if (attributesAffectedByRules(*shareElement)) { |
| 215 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); | 193 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttr ibuteRules); |
| 216 return 0; | 194 return 0; |
| 217 } | 195 } |
| 218 | 196 |
| 219 return shareElement->renderStyle(); | 197 return shareElement->renderStyle(); |
| 220 } | 198 } |
| 221 | 199 |
| 222 } | 200 } |
| OLD | NEW |