| 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 14 matching lines...) Expand all Loading... |
| 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "sky/engine/core/css/resolver/StyleResolver.h" | 29 #include "sky/engine/core/css/resolver/StyleResolver.h" |
| 30 | 30 |
| 31 #include "gen/sky/core/CSSPropertyNames.h" | 31 #include "gen/sky/core/CSSPropertyNames.h" |
| 32 #include "gen/sky/core/MediaTypeNames.h" | 32 #include "gen/sky/core/MediaTypeNames.h" |
| 33 #include "gen/sky/core/StylePropertyShorthand.h" | 33 #include "gen/sky/core/StylePropertyShorthand.h" |
| 34 #include "gen/sky/platform/RuntimeEnabledFeatures.h" | 34 #include "gen/sky/platform/RuntimeEnabledFeatures.h" |
| 35 #include "sky/engine/core/animation/ActiveAnimations.h" | |
| 36 #include "sky/engine/core/animation/Animation.h" | |
| 37 #include "sky/engine/core/animation/AnimationTimeline.h" | |
| 38 #include "sky/engine/core/animation/StyleInterpolation.h" | |
| 39 #include "sky/engine/core/animation/animatable/AnimatableValue.h" | |
| 40 #include "sky/engine/core/animation/css/CSSAnimatableValueFactory.h" | |
| 41 #include "sky/engine/core/animation/css/CSSAnimations.h" | |
| 42 #include "sky/engine/core/css/CSSCalculationValue.h" | 35 #include "sky/engine/core/css/CSSCalculationValue.h" |
| 43 #include "sky/engine/core/css/CSSFontSelector.h" | 36 #include "sky/engine/core/css/CSSFontSelector.h" |
| 44 #include "sky/engine/core/css/CSSSelector.h" | 37 #include "sky/engine/core/css/CSSSelector.h" |
| 45 #include "sky/engine/core/css/CSSValueList.h" | 38 #include "sky/engine/core/css/CSSValueList.h" |
| 46 #include "sky/engine/core/css/CSSValuePool.h" | 39 #include "sky/engine/core/css/CSSValuePool.h" |
| 47 #include "sky/engine/core/css/ElementRuleCollector.h" | 40 #include "sky/engine/core/css/ElementRuleCollector.h" |
| 48 #include "sky/engine/core/css/FontFace.h" | 41 #include "sky/engine/core/css/FontFace.h" |
| 49 #include "sky/engine/core/css/MediaQueryEvaluator.h" | 42 #include "sky/engine/core/css/MediaQueryEvaluator.h" |
| 50 #include "sky/engine/core/css/RuleSet.h" | 43 #include "sky/engine/core/css/RuleSet.h" |
| 51 #include "sky/engine/core/css/StylePropertySet.h" | 44 #include "sky/engine/core/css/StylePropertySet.h" |
| 52 #include "sky/engine/core/css/StyleSheetContents.h" | 45 #include "sky/engine/core/css/StyleSheetContents.h" |
| 53 #include "sky/engine/core/css/parser/BisonCSSParser.h" | 46 #include "sky/engine/core/css/parser/BisonCSSParser.h" |
| 54 #include "sky/engine/core/css/resolver/AnimatedStyleBuilder.h" | |
| 55 #include "sky/engine/core/css/resolver/MatchResult.h" | 47 #include "sky/engine/core/css/resolver/MatchResult.h" |
| 56 #include "sky/engine/core/css/resolver/SharedStyleFinder.h" | 48 #include "sky/engine/core/css/resolver/SharedStyleFinder.h" |
| 57 #include "sky/engine/core/css/resolver/StyleAdjuster.h" | 49 #include "sky/engine/core/css/resolver/StyleAdjuster.h" |
| 58 #include "sky/engine/core/css/resolver/StyleBuilder.h" | 50 #include "sky/engine/core/css/resolver/StyleBuilder.h" |
| 59 #include "sky/engine/core/css/resolver/StyleResolverState.h" | 51 #include "sky/engine/core/css/resolver/StyleResolverState.h" |
| 60 #include "sky/engine/core/css/resolver/StyleResolverStats.h" | 52 #include "sky/engine/core/css/resolver/StyleResolverStats.h" |
| 61 #include "sky/engine/core/dom/NodeRenderStyle.h" | 53 #include "sky/engine/core/dom/NodeRenderStyle.h" |
| 62 #include "sky/engine/core/dom/StyleEngine.h" | 54 #include "sky/engine/core/dom/StyleEngine.h" |
| 63 #include "sky/engine/core/dom/Text.h" | 55 #include "sky/engine/core/dom/Text.h" |
| 64 #include "sky/engine/core/dom/shadow/ElementShadow.h" | 56 #include "sky/engine/core/dom/shadow/ElementShadow.h" |
| 65 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 57 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 66 #include "sky/engine/core/frame/FrameView.h" | 58 #include "sky/engine/core/frame/FrameView.h" |
| 67 #include "sky/engine/core/frame/LocalFrame.h" | 59 #include "sky/engine/core/frame/LocalFrame.h" |
| 68 #include "sky/engine/core/rendering/RenderView.h" | 60 #include "sky/engine/core/rendering/RenderView.h" |
| 69 #include "sky/engine/wtf/LeakAnnotations.h" | 61 #include "sky/engine/wtf/LeakAnnotations.h" |
| 70 #include "sky/engine/wtf/StdLibExtras.h" | 62 #include "sky/engine/wtf/StdLibExtras.h" |
| 71 | 63 |
| 72 namespace { | |
| 73 | |
| 74 using namespace blink; | |
| 75 | |
| 76 void setAnimationUpdateIfNeeded(StyleResolverState& state, Element& element) | |
| 77 { | |
| 78 // If any changes to CSS Animations were detected, stash the update away for
application after the | |
| 79 // render object is updated if we're in the appropriate scope. | |
| 80 if (state.animationUpdate()) | |
| 81 element.ensureActiveAnimations().cssAnimations().setPendingUpdate(state.
takeAnimationUpdate()); | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 namespace blink { | 64 namespace blink { |
| 87 | 65 |
| 88 static RuleSet& defaultStyles() | 66 static RuleSet& defaultStyles() |
| 89 { | 67 { |
| 90 DEFINE_STATIC_LOCAL(RefPtr<StyleSheetContents>, styleSheet, ()); | 68 DEFINE_STATIC_LOCAL(RefPtr<StyleSheetContents>, styleSheet, ()); |
| 91 DEFINE_STATIC_LOCAL(OwnPtr<RuleSet>, ruleSet, ()); | 69 DEFINE_STATIC_LOCAL(OwnPtr<RuleSet>, ruleSet, ()); |
| 92 | 70 |
| 93 if (ruleSet) | 71 if (ruleSet) |
| 94 return *ruleSet; | 72 return *ruleSet; |
| 95 | 73 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 199 |
| 222 applyMatchedProperties(state, collector.matchedResult()); | 200 applyMatchedProperties(state, collector.matchedResult()); |
| 223 } | 201 } |
| 224 | 202 |
| 225 // Cache our original display. | 203 // Cache our original display. |
| 226 state.style()->setOriginalDisplay(state.style()->display()); | 204 state.style()->setOriginalDisplay(state.style()->display()); |
| 227 | 205 |
| 228 StyleAdjuster adjuster; | 206 StyleAdjuster adjuster; |
| 229 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element); | 207 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element); |
| 230 | 208 |
| 231 if (applyAnimatedProperties(state, element)) | |
| 232 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element)
; | |
| 233 | |
| 234 setAnimationUpdateIfNeeded(state, *element); | |
| 235 | |
| 236 if (state.style()->hasViewportUnits()) | 209 if (state.style()->hasViewportUnits()) |
| 237 m_document.setHasViewportUnits(); | 210 m_document.setHasViewportUnits(); |
| 238 | 211 |
| 239 // Now return the style. | 212 // Now return the style. |
| 240 return state.takeStyle(); | 213 return state.takeStyle(); |
| 241 } | 214 } |
| 242 | 215 |
| 243 // This function is used by the WebAnimations JavaScript API method animate(). | |
| 244 // FIXME: Remove this when animate() switches away from resolution-dependent par
sing. | |
| 245 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element
& element, CSSPropertyID property, CSSValue& value) | |
| 246 { | |
| 247 RefPtr<RenderStyle> style; | |
| 248 if (element.renderStyle()) | |
| 249 style = RenderStyle::clone(element.renderStyle()); | |
| 250 else | |
| 251 style = RenderStyle::create(); | |
| 252 StyleResolverState state(element.document(), &element); | |
| 253 state.setStyle(style); | |
| 254 state.fontBuilder().initForStyleResolve(state.document(), state.style()); | |
| 255 return createAnimatableValueSnapshot(state, property, value); | |
| 256 } | |
| 257 | |
| 258 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(StyleRe
solverState& state, CSSPropertyID property, CSSValue& value) | |
| 259 { | |
| 260 StyleBuilder::applyProperty(property, state, &value); | |
| 261 return CSSAnimatableValueFactory::create(property, *state.style()); | |
| 262 } | |
| 263 | |
| 264 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() | 216 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() |
| 265 { | 217 { |
| 266 StyleResolverState state(m_document, nullptr); | 218 StyleResolverState state(m_document, nullptr); |
| 267 state.setStyle(RenderStyle::create()); | 219 state.setStyle(RenderStyle::create()); |
| 268 state.fontBuilder().initForStyleResolve(m_document, state.style()); | 220 state.fontBuilder().initForStyleResolve(m_document, state.style()); |
| 269 state.style()->setLineHeight(RenderStyle::initialLineHeight()); | 221 state.style()->setLineHeight(RenderStyle::initialLineHeight()); |
| 270 state.setLineHeightValue(0); | 222 state.setLineHeightValue(0); |
| 271 state.fontBuilder().setInitial(); | 223 state.fontBuilder().setInitial(); |
| 272 state.style()->font().update(m_document.styleEngine()->fontSelector()); | 224 state.style()->font().update(m_document.styleEngine()->fontSelector()); |
| 273 return state.takeStyle(); | 225 return state.takeStyle(); |
| 274 } | 226 } |
| 275 | 227 |
| 276 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) | 228 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) |
| 277 { | 229 { |
| 278 ASSERT(textNode); | 230 ASSERT(textNode); |
| 279 | 231 |
| 280 Node* parentNode = NodeRenderingTraversal::parent(textNode); | 232 Node* parentNode = NodeRenderingTraversal::parent(textNode); |
| 281 if (!parentNode || !parentNode->renderStyle()) | 233 if (!parentNode || !parentNode->renderStyle()) |
| 282 return defaultStyleForElement(); | 234 return defaultStyleForElement(); |
| 283 return parentNode->renderStyle(); | 235 return parentNode->renderStyle(); |
| 284 } | 236 } |
| 285 | 237 |
| 286 void StyleResolver::updateFont(StyleResolverState& state) | 238 void StyleResolver::updateFont(StyleResolverState& state) |
| 287 { | 239 { |
| 288 state.fontBuilder().createFont(m_document.styleEngine()->fontSelector(), sta
te.parentStyle(), state.style()); | 240 state.fontBuilder().createFont(m_document.styleEngine()->fontSelector(), sta
te.parentStyle(), state.style()); |
| 289 if (state.fontBuilder().fontSizeHasViewportUnits()) | 241 if (state.fontBuilder().fontSizeHasViewportUnits()) |
| 290 state.style()->setHasViewportUnits(); | 242 state.style()->setHasViewportUnits(); |
| 291 } | 243 } |
| 292 | 244 |
| 293 // -----------------------------------------------------------------------------
-------- | |
| 294 // this is mostly boring stuff on how to apply a certain rule to the renderstyle
... | |
| 295 | |
| 296 bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, Element*
animatingElement) | |
| 297 { | |
| 298 const Element* element = state.element(); | |
| 299 ASSERT(element); | |
| 300 | |
| 301 // The animating element may be this element, or its pseudo element. It is | |
| 302 // null when calculating the style for a potential pseudo element that has | |
| 303 // yet to be created. | |
| 304 ASSERT(animatingElement == element || !animatingElement || animatingElement-
>parentOrShadowHostElement() == element); | |
| 305 | |
| 306 if (!(animatingElement && animatingElement->hasActiveAnimations()) | |
| 307 && !state.style()->transitions() && !state.style()->animations()) | |
| 308 return false; | |
| 309 | |
| 310 state.setAnimationUpdate(CSSAnimations::calculateUpdate(animatingElement, *e
lement, *state.style(), state.parentStyle())); | |
| 311 if (!state.animationUpdate()) | |
| 312 return false; | |
| 313 | |
| 314 const HashMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolationsFo
rAnimations = state.animationUpdate()->activeInterpolationsForAnimations(); | |
| 315 const HashMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolationsFo
rTransitions = state.animationUpdate()->activeInterpolationsForTransitions(); | |
| 316 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF
orAnimations); | |
| 317 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF
orTransitions); | |
| 318 | |
| 319 updateFont(state); | |
| 320 | |
| 321 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo
rAnimations); | |
| 322 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo
rTransitions); | |
| 323 | |
| 324 ASSERT(!state.fontBuilder().fontDirty()); | |
| 325 | |
| 326 return true; | |
| 327 } | |
| 328 | |
| 329 template <StyleResolver::StyleApplicationPass pass> | |
| 330 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Has
hMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolations) | |
| 331 { | |
| 332 for (HashMap<CSSPropertyID, RefPtr<Interpolation> >::const_iterator iter = a
ctiveInterpolations.begin(); iter != activeInterpolations.end(); ++iter) { | |
| 333 CSSPropertyID property = iter->key; | |
| 334 if (!isPropertyForPass<pass>(property)) | |
| 335 continue; | |
| 336 const StyleInterpolation* interpolation = toStyleInterpolation(iter->val
ue.get()); | |
| 337 interpolation->apply(state); | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 // FIXME: Consider refactoring to create a new class which owns the following | 245 // FIXME: Consider refactoring to create a new class which owns the following |
| 342 // first/last/range properties. | 246 // first/last/range properties. |
| 343 // This method returns the first CSSPropertyId of high priority properties. | 247 // This method returns the first CSSPropertyId of high priority properties. |
| 344 // Other properties can depend on high priority properties. For example, | 248 // Other properties can depend on high priority properties. For example, |
| 345 // border-color property with currentColor value depends on color property. | 249 // border-color property with currentColor value depends on color property. |
| 346 // All high priority properties are obtained by using | 250 // All high priority properties are obtained by using |
| 347 // firstCSSPropertyId<HighPriorityProperties> and | 251 // firstCSSPropertyId<HighPriorityProperties> and |
| 348 // lastCSSPropertyId<HighPriorityProperties>. | 252 // lastCSSPropertyId<HighPriorityProperties>. |
| 349 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::HighPr
iorityProperties>() | 253 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::HighPr
iorityProperties>() |
| 350 { | 254 { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 break; | 442 break; |
| 539 default: | 443 default: |
| 540 break; | 444 break; |
| 541 } | 445 } |
| 542 StyleBuilder::applyProperty(properties[i].property, state, propertie
s[i].value); | 446 StyleBuilder::applyProperty(properties[i].property, state, propertie
s[i].value); |
| 543 } | 447 } |
| 544 } | 448 } |
| 545 } | 449 } |
| 546 | 450 |
| 547 } // namespace blink | 451 } // namespace blink |
| OLD | NEW |