| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 ruleSet = RuleSet::create(); | 113 ruleSet = RuleSet::create(); |
| 114 ruleSet->addRulesFromSheet(styleSheet.get()); | 114 ruleSet->addRulesFromSheet(styleSheet.get()); |
| 115 | 115 |
| 116 return *ruleSet; | 116 return *ruleSet; |
| 117 } | 117 } |
| 118 | 118 |
| 119 StyleResolver::StyleResolver(Document& document) | 119 StyleResolver::StyleResolver(Document& document) |
| 120 : m_document(document) | 120 : m_document(document) |
| 121 , m_styleResolverStatsSequence(0) | 121 , m_styleResolverStatsSequence(0) |
| 122 , m_accessCount(0) | |
| 123 { | 122 { |
| 124 } | 123 } |
| 125 | 124 |
| 126 void StyleResolver::addToStyleSharingList(Element& element) | 125 void StyleResolver::addToStyleSharingList(Element& element) |
| 127 { | 126 { |
| 128 // Never add elements to the style sharing list if we're not in a recalcStyl
e, | 127 // Never add elements to the style sharing list if we're not in a recalcStyl
e, |
| 129 // otherwise we could leave stale pointers in there. | 128 // otherwise we could leave stale pointers in there. |
| 130 if (!document().inStyleRecalc()) | 129 if (!m_document.inStyleRecalc()) |
| 131 return; | 130 return; |
| 132 ASSERT(element.supportsStyleSharing()); | 131 ASSERT(element.supportsStyleSharing()); |
| 133 INCREMENT_STYLE_STATS_COUNTER(*this, sharedStyleCandidates); | 132 INCREMENT_STYLE_STATS_COUNTER(*this, sharedStyleCandidates); |
| 134 StyleSharingList& list = styleSharingList(); | 133 StyleSharingList& list = styleSharingList(); |
| 135 if (list.size() >= styleSharingListSize) | 134 if (list.size() >= styleSharingListSize) |
| 136 list.removeLast(); | 135 list.removeLast(); |
| 137 list.prepend(&element); | 136 list.prepend(&element); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void StyleResolver::clearStyleSharingList() | 139 void StyleResolver::clearStyleSharingList() |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 documentStyle->setZIndex(0); | 196 documentStyle->setZIndex(0); |
| 198 documentStyle->setUserModify(READ_ONLY); | 197 documentStyle->setUserModify(READ_ONLY); |
| 199 | 198 |
| 200 document.setupFontBuilder(documentStyle.get()); | 199 document.setupFontBuilder(documentStyle.get()); |
| 201 | 200 |
| 202 return documentStyle.release(); | 201 return documentStyle.release(); |
| 203 } | 202 } |
| 204 | 203 |
| 205 void StyleResolver::loadPendingResources(StyleResolverState& state) | 204 void StyleResolver::loadPendingResources(StyleResolverState& state) |
| 206 { | 205 { |
| 207 StyleResourceLoader loader(document().fetcher()); | 206 StyleResourceLoader loader(m_document.fetcher()); |
| 208 loader.loadPendingResources(state.style(), state.elementStyleResources()); | 207 loader.loadPendingResources(state.style(), state.elementStyleResources()); |
| 209 document().styleEngine()->fontSelector()->fontLoader()->loadPendingFonts(); | 208 m_document.styleEngine()->fontSelector()->fontLoader()->loadPendingFonts(); |
| 210 } | 209 } |
| 211 | 210 |
| 212 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
tyle* defaultParent) | 211 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
tyle* defaultParent) |
| 213 { | 212 { |
| 214 ASSERT(document().frame()); | 213 ASSERT(m_document.frame()); |
| 215 ASSERT(document().settings()); | 214 ASSERT(m_document.settings()); |
| 216 | 215 |
| 217 didAccess(); | 216 if (element == m_document.documentElement()) |
| 218 | 217 m_document.setDirectionSetOnDocumentElement(false); |
| 219 if (element == document().documentElement()) | 218 StyleResolverState state(m_document, element, defaultParent); |
| 220 document().setDirectionSetOnDocumentElement(false); | |
| 221 StyleResolverState state(document(), element, defaultParent); | |
| 222 | 219 |
| 223 if (state.parentStyle()) { | 220 if (state.parentStyle()) { |
| 224 SharedStyleFinder styleFinder(state.elementContext(), *this); | 221 SharedStyleFinder styleFinder(state.elementContext(), *this); |
| 225 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle()) | 222 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle()) |
| 226 return sharedStyle.release(); | 223 return sharedStyle.release(); |
| 227 } | 224 } |
| 228 | 225 |
| 229 if (state.parentStyle()) { | 226 if (state.parentStyle()) { |
| 230 state.setStyle(RenderStyle::create()); | 227 state.setStyle(RenderStyle::create()); |
| 231 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme
nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); | 228 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme
nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 260 | 257 |
| 261 // FIXME: The CSSWG wants to specify that the effects of animations are appl
ied before | 258 // FIXME: The CSSWG wants to specify that the effects of animations are appl
ied before |
| 262 // important rules, but this currently happens here as we require adjustment
to have happened | 259 // important rules, but this currently happens here as we require adjustment
to have happened |
| 263 // before deciding which properties to transition. | 260 // before deciding which properties to transition. |
| 264 if (applyAnimatedProperties(state, element)) | 261 if (applyAnimatedProperties(state, element)) |
| 265 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element)
; | 262 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element)
; |
| 266 | 263 |
| 267 setAnimationUpdateIfNeeded(state, *element); | 264 setAnimationUpdateIfNeeded(state, *element); |
| 268 | 265 |
| 269 if (state.style()->hasViewportUnits()) | 266 if (state.style()->hasViewportUnits()) |
| 270 document().setHasViewportUnits(); | 267 m_document.setHasViewportUnits(); |
| 271 | 268 |
| 272 // Now return the style. | 269 // Now return the style. |
| 273 return state.takeStyle(); | 270 return state.takeStyle(); |
| 274 } | 271 } |
| 275 | 272 |
| 276 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const
RenderStyle& elementStyle, RenderStyle* parentStyle, const StyleKeyframe* keyfra
me, const AtomicString& animationName) | 273 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const
RenderStyle& elementStyle, RenderStyle* parentStyle, const StyleKeyframe* keyfra
me, const AtomicString& animationName) |
| 277 { | 274 { |
| 278 ASSERT(document().frame()); | 275 ASSERT(m_document.frame()); |
| 279 ASSERT(document().settings()); | 276 ASSERT(m_document.settings()); |
| 280 | 277 |
| 281 if (element == document().documentElement()) | 278 if (element == m_document.documentElement()) |
| 282 document().setDirectionSetOnDocumentElement(false); | 279 m_document.setDirectionSetOnDocumentElement(false); |
| 283 StyleResolverState state(document(), element, parentStyle); | 280 StyleResolverState state(m_document, element, parentStyle); |
| 284 | 281 |
| 285 MatchResult result; | 282 MatchResult result; |
| 286 result.addMatchedProperties(&keyframe->properties()); | 283 result.addMatchedProperties(&keyframe->properties()); |
| 287 | 284 |
| 288 ASSERT(!state.style()); | 285 ASSERT(!state.style()); |
| 289 | 286 |
| 290 // Create the style | 287 // Create the style |
| 291 state.setStyle(RenderStyle::clone(&elementStyle)); | 288 state.setStyle(RenderStyle::clone(&elementStyle)); |
| 292 state.setLineHeightValue(0); | 289 state.setLineHeightValue(0); |
| 293 | 290 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 306 | 303 |
| 307 // Line-height is set when we are sure we decided on the font-size | 304 // Line-height is set when we are sure we decided on the font-size |
| 308 if (state.lineHeightValue()) | 305 if (state.lineHeightValue()) |
| 309 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig
htValue()); | 306 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig
htValue()); |
| 310 | 307 |
| 311 // Now do rest of the properties. | 308 // Now do rest of the properties. |
| 312 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul
t.matchedProperties.size() - 1, inheritedOnly); | 309 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul
t.matchedProperties.size() - 1, inheritedOnly); |
| 313 | 310 |
| 314 loadPendingResources(state); | 311 loadPendingResources(state); |
| 315 | 312 |
| 316 didAccess(); | |
| 317 | |
| 318 return state.takeStyle(); | 313 return state.takeStyle(); |
| 319 } | 314 } |
| 320 | 315 |
| 321 // This function is used by the WebAnimations JavaScript API method animate(). | 316 // This function is used by the WebAnimations JavaScript API method animate(). |
| 322 // FIXME: Remove this when animate() switches away from resolution-dependent par
sing. | 317 // FIXME: Remove this when animate() switches away from resolution-dependent par
sing. |
| 323 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element
& element, CSSPropertyID property, CSSValue& value) | 318 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element
& element, CSSPropertyID property, CSSValue& value) |
| 324 { | 319 { |
| 325 RefPtr<RenderStyle> style; | 320 RefPtr<RenderStyle> style; |
| 326 if (element.renderStyle()) | 321 if (element.renderStyle()) |
| 327 style = RenderStyle::clone(element.renderStyle()); | 322 style = RenderStyle::clone(element.renderStyle()); |
| 328 else | 323 else |
| 329 style = RenderStyle::create(); | 324 style = RenderStyle::create(); |
| 330 StyleResolverState state(element.document(), &element); | 325 StyleResolverState state(element.document(), &element); |
| 331 state.setStyle(style); | 326 state.setStyle(style); |
| 332 state.fontBuilder().initForStyleResolve(state.document(), state.style()); | 327 state.fontBuilder().initForStyleResolve(state.document(), state.style()); |
| 333 return createAnimatableValueSnapshot(state, property, value); | 328 return createAnimatableValueSnapshot(state, property, value); |
| 334 } | 329 } |
| 335 | 330 |
| 336 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(StyleRe
solverState& state, CSSPropertyID property, CSSValue& value) | 331 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(StyleRe
solverState& state, CSSPropertyID property, CSSValue& value) |
| 337 { | 332 { |
| 338 StyleBuilder::applyProperty(property, state, &value); | 333 StyleBuilder::applyProperty(property, state, &value); |
| 339 return CSSAnimatableValueFactory::create(property, *state.style()); | 334 return CSSAnimatableValueFactory::create(property, *state.style()); |
| 340 } | 335 } |
| 341 | 336 |
| 342 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() | 337 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() |
| 343 { | 338 { |
| 344 StyleResolverState state(document(), 0); | 339 StyleResolverState state(m_document, 0); |
| 345 state.setStyle(RenderStyle::create()); | 340 state.setStyle(RenderStyle::create()); |
| 346 state.fontBuilder().initForStyleResolve(document(), state.style()); | 341 state.fontBuilder().initForStyleResolve(m_document, state.style()); |
| 347 state.style()->setLineHeight(RenderStyle::initialLineHeight()); | 342 state.style()->setLineHeight(RenderStyle::initialLineHeight()); |
| 348 state.setLineHeightValue(0); | 343 state.setLineHeightValue(0); |
| 349 state.fontBuilder().setInitial(); | 344 state.fontBuilder().setInitial(); |
| 350 state.style()->font().update(document().styleEngine()->fontSelector()); | 345 state.style()->font().update(m_document.styleEngine()->fontSelector()); |
| 351 return state.takeStyle(); | 346 return state.takeStyle(); |
| 352 } | 347 } |
| 353 | 348 |
| 354 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) | 349 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) |
| 355 { | 350 { |
| 356 ASSERT(textNode); | 351 ASSERT(textNode); |
| 357 | 352 |
| 358 Node* parentNode = NodeRenderingTraversal::parent(textNode); | 353 Node* parentNode = NodeRenderingTraversal::parent(textNode); |
| 359 if (!parentNode || !parentNode->renderStyle()) | 354 if (!parentNode || !parentNode->renderStyle()) |
| 360 return defaultStyleForElement(); | 355 return defaultStyleForElement(); |
| 361 return parentNode->renderStyle(); | 356 return parentNode->renderStyle(); |
| 362 } | 357 } |
| 363 | 358 |
| 364 void StyleResolver::updateFont(StyleResolverState& state) | 359 void StyleResolver::updateFont(StyleResolverState& state) |
| 365 { | 360 { |
| 366 state.fontBuilder().createFont(document().styleEngine()->fontSelector(), sta
te.parentStyle(), state.style()); | 361 state.fontBuilder().createFont(m_document.styleEngine()->fontSelector(), sta
te.parentStyle(), state.style()); |
| 367 if (state.fontBuilder().fontSizeHasViewportUnits()) | 362 if (state.fontBuilder().fontSizeHasViewportUnits()) |
| 368 state.style()->setHasViewportUnits(); | 363 state.style()->setHasViewportUnits(); |
| 369 } | 364 } |
| 370 | 365 |
| 371 // -----------------------------------------------------------------------------
-------- | 366 // -----------------------------------------------------------------------------
-------- |
| 372 // this is mostly boring stuff on how to apply a certain rule to the renderstyle
... | 367 // this is mostly boring stuff on how to apply a certain rule to the renderstyle
... |
| 373 | 368 |
| 374 bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, Element*
animatingElement) | 369 bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, Element*
animatingElement) |
| 375 { | 370 { |
| 376 const Element* element = state.element(); | 371 const Element* element = state.element(); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 { | 652 { |
| 658 m_styleResolverStatsSequence = 0; | 653 m_styleResolverStatsSequence = 0; |
| 659 m_styleResolverStats.clear(); | 654 m_styleResolverStats.clear(); |
| 660 m_styleResolverStatsTotals.clear(); | 655 m_styleResolverStatsTotals.clear(); |
| 661 } | 656 } |
| 662 | 657 |
| 663 void StyleResolver::printStats() | 658 void StyleResolver::printStats() |
| 664 { | 659 { |
| 665 if (!m_styleResolverStats) | 660 if (!m_styleResolverStats) |
| 666 return; | 661 return; |
| 667 fprintf(stderr, "=== Style Resolver Stats (resolve #%u) (%s) ===\n", ++m_sty
leResolverStatsSequence, document().url().string().utf8().data()); | 662 fprintf(stderr, "=== Style Resolver Stats (resolve #%u) (%s) ===\n", ++m_sty
leResolverStatsSequence, m_document.url().string().utf8().data()); |
| 668 fprintf(stderr, "%s\n", m_styleResolverStats->report().utf8().data()); | 663 fprintf(stderr, "%s\n", m_styleResolverStats->report().utf8().data()); |
| 669 fprintf(stderr, "== Totals ==\n"); | 664 fprintf(stderr, "== Totals ==\n"); |
| 670 fprintf(stderr, "%s\n", m_styleResolverStatsTotals->report().utf8().data()); | 665 fprintf(stderr, "%s\n", m_styleResolverStatsTotals->report().utf8().data()); |
| 671 } | 666 } |
| 672 | 667 |
| 673 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s
ize_t count, RenderStyle* style) | 668 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s
ize_t count, RenderStyle* style) |
| 674 { | 669 { |
| 675 StyleResolverState state(document(), document().documentElement(), style); | 670 StyleResolverState state(m_document, m_document.documentElement(), style); |
| 676 state.setStyle(style); | 671 state.setStyle(style); |
| 677 | 672 |
| 678 state.fontBuilder().initForStyleResolve(document(), style); | 673 state.fontBuilder().initForStyleResolve(m_document, style); |
| 679 | 674 |
| 680 for (size_t i = 0; i < count; ++i) { | 675 for (size_t i = 0; i < count; ++i) { |
| 681 if (properties[i].value) { | 676 if (properties[i].value) { |
| 682 // As described in BUG66291, setting font-size and line-height on a
font may entail a CSSPrimitiveValue::computeLengthDouble call, | 677 // As described in BUG66291, setting font-size and line-height on a
font may entail a CSSPrimitiveValue::computeLengthDouble call, |
| 683 // which assumes the fontMetrics are available for the affected font
, otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). | 678 // which assumes the fontMetrics are available for the affected font
, otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). |
| 684 // The updateFont() call below updates the fontMetrics and ensure th
e proper setting of font-size and line-height. | 679 // The updateFont() call below updates the fontMetrics and ensure th
e proper setting of font-size and line-height. |
| 685 switch (properties[i].property) { | 680 switch (properties[i].property) { |
| 686 case CSSPropertyFontSize: | 681 case CSSPropertyFontSize: |
| 687 case CSSPropertyLineHeight: | 682 case CSSPropertyLineHeight: |
| 688 updateFont(state); | 683 updateFont(state); |
| 689 break; | 684 break; |
| 690 default: | 685 default: |
| 691 break; | 686 break; |
| 692 } | 687 } |
| 693 StyleBuilder::applyProperty(properties[i].property, state, propertie
s[i].value); | 688 StyleBuilder::applyProperty(properties[i].property, state, propertie
s[i].value); |
| 694 } | 689 } |
| 695 } | 690 } |
| 696 } | 691 } |
| 697 | 692 |
| 698 } // namespace blink | 693 } // namespace blink |
| OLD | NEW |