Changeset 61933 in webkit


Ignore:
Timestamp:
Jun 25, 2010 7:01:29 PM (14 years ago)
Author:
dino@apple.com
Message:

2010-06-25 Dean Jackson <dino@apple.com>

Reviewed by Simon Fraser.

https://bugs.webkit.org/show_bug.cgi?id=41188
Animations should not require 0% and 100% keyframes

When we are generating the animation lists in CSSStyleSelector,
rather than bail if we notice that "from" or "to" are missing, we
now generate synthetic keyframes for those cases.

Tests: animations/missing-from-to-transforms.html

animations/missing-from-to.html
WebCore/manual-tests/animation-with-transition.html

  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::styleForKeyframe):

Moved individual keyframe generation into a new function.

(WebCore::CSSStyleSelector::keyframeStylesForAnimation):

Call the new function above for regular keyframes, and
also check for missing keyframes and generate them if
necessary.

  • css/CSSStyleSelector.h:
Location:
trunk
Files:
5 added
4 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r61932 r61933  
     12010-06-25  Dean Jackson  <dino@apple.com>
     2
     3        Reviewed by Simon Fraser.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=41188
     6        Animations should not require 0% and 100% keyframes
     7
     8        * animations/keyframes-from-missing-expected.txt: Removed.
     9        * animations/keyframes-from-missing.html: Removed.
     10        * animations/keyframes-to-missing-expected.txt: Removed.
     11        * animations/keyframes-to-missing.html: Removed.
     12        * animations/missing-from-to-transforms-expected.txt: Added.
     13        * animations/missing-from-to-transforms.html: Added.
     14        * animations/missing-from-to-expected.txt: Added.
     15        * animations/missing-from-to.html: Added.
     16
    1172010-06-25  Csaba Osztrogonác  <ossy@webkit.org>
    218
  • trunk/WebCore/ChangeLog

    r61925 r61933  
     12010-06-25  Dean Jackson  <dino@apple.com>
     2
     3        Reviewed by Simon Fraser.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=41188
     6        Animations should not require 0% and 100% keyframes
     7
     8        When we are generating the animation lists in CSSStyleSelector,
     9        rather than bail if we notice that "from" or "to" are missing, we
     10        now generate synthetic keyframes for those cases.
     11
     12        Tests: animations/missing-from-to-transforms.html
     13               animations/missing-from-to.html
     14               WebCore/manual-tests/animation-with-transition.html
     15
     16        * css/CSSStyleSelector.cpp:
     17        (WebCore::CSSStyleSelector::styleForKeyframe):
     18                Moved individual keyframe generation into a new function.
     19        (WebCore::CSSStyleSelector::keyframeStylesForAnimation):
     20                Call the new function above for regular keyframes, and
     21                also check for missing keyframes and generate them if
     22                necessary.
     23        * css/CSSStyleSelector.h:
     24
    1252010-06-25  Adam Barth  <abarth@webkit.org>
    226
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r61670 r61933  
    13741374}
    13751375
     1376PassRefPtr<RenderStyle> CSSStyleSelector::styleForKeyframe(const RenderStyle* elementStyle, const WebKitCSSKeyframeRule* keyframeRule, KeyframeList& list)
     1377{
     1378    if (keyframeRule->style())
     1379        addMatchedDeclaration(keyframeRule->style());
     1380
     1381    ASSERT(!m_style);
     1382
     1383    // Create the style
     1384    m_style = RenderStyle::clone(elementStyle);
     1385
     1386    m_lineHeightValue = 0;
     1387
     1388    // We don't need to bother with !important. Since there is only ever one
     1389    // decl, there's nothing to override. So just add the first properties.
     1390    if (keyframeRule->style())
     1391        applyDeclarations<true>(false, 0, m_matchedDecls.size() - 1);
     1392
     1393    // If our font got dirtied, go ahead and update it now.
     1394    if (m_fontDirty)
     1395        updateFont();
     1396
     1397    // Line-height is set when we are sure we decided on the font-size
     1398    if (m_lineHeightValue)
     1399        applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
     1400
     1401    // Now do rest of the properties.
     1402    if (keyframeRule->style())
     1403        applyDeclarations<false>(false, 0, m_matchedDecls.size() - 1);
     1404
     1405    // If our font got dirtied by one of the non-essential font props,
     1406    // go ahead and update it a second time.
     1407    if (m_fontDirty)
     1408        updateFont();
     1409
     1410    // Add all the animating properties to the list
     1411    if (keyframeRule->style()) {
     1412        CSSMutableStyleDeclaration::const_iterator end = keyframeRule->style()->end();
     1413        for (CSSMutableStyleDeclaration::const_iterator it = keyframeRule->style()->begin(); it != end; ++it) {
     1414            int property = (*it).id();
     1415            // Timing-function within keyframes is special, because it is not animated; it just
     1416            // describes the timing function between this keyframe and the next.
     1417            if (property != CSSPropertyWebkitAnimationTimingFunction)
     1418                list.addProperty(property);
     1419        }
     1420    }
     1421
     1422    return m_style.release();
     1423}
     1424
    13761425void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle* elementStyle, KeyframeList& list)
    13771426{
     
    13881437       
    13891438    const WebKitCSSKeyframesRule* rule = m_keyframesRuleMap.find(list.animationName().impl()).get()->second.get();
     1439    RefPtr<RenderStyle> keyframeStyle;
    13901440   
    13911441    // Construct and populate the style for each keyframe
     
    13951445        initForStyleResolve(e);
    13961446       
    1397         const WebKitCSSKeyframeRule* kf = rule->item(i);
    1398         addMatchedDeclaration(kf->style());
    1399 
    1400         ASSERT(!m_style);
    1401 
    1402         // Create the style
    1403         m_style = RenderStyle::clone(elementStyle);
     1447        const WebKitCSSKeyframeRule* keyframeRule = rule->item(i);
    14041448       
    1405         m_lineHeightValue = 0;
    1406        
    1407         // We don't need to bother with !important. Since there is only ever one
    1408         // decl, there's nothing to override. So just add the first properties.
    1409         applyDeclarations<true>(false, 0, m_matchedDecls.size() - 1);
    1410        
    1411         // If our font got dirtied, go ahead and update it now.
    1412         if (m_fontDirty)
    1413             updateFont();
    1414 
    1415         // Line-height is set when we are sure we decided on the font-size
    1416         if (m_lineHeightValue)
    1417             applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
    1418        
    1419         // Now do rest of the properties.
    1420         applyDeclarations<false>(false, 0, m_matchedDecls.size() - 1);
    1421        
    1422         // If our font got dirtied by one of the non-essential font props,
    1423         // go ahead and update it a second time.
    1424         if (m_fontDirty)
    1425             updateFont();
    1426 
    1427         // Add all the animating properties to the list
    1428         CSSMutableStyleDeclaration::const_iterator end = kf->style()->end();
    1429         for (CSSMutableStyleDeclaration::const_iterator it = kf->style()->begin(); it != end; ++it) {
    1430             int property = (*it).id();
    1431             // Timing-function within keyframes is special, because it is not animated; it just
    1432             // describes the timing function between this keyframe and the next.
    1433             if (property != CSSPropertyWebkitAnimationTimingFunction)
    1434                 list.addProperty(property);
    1435         }
    1436        
     1449        keyframeStyle = styleForKeyframe(elementStyle, keyframeRule, list);
     1450
    14371451        // Add this keyframe style to all the indicated key times
    14381452        Vector<float> keys;
    1439         kf->getKeys(keys);
     1453        keyframeRule->getKeys(keys);
    14401454        for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
    14411455            float key = keys[keyIndex];
    1442             list.insert(key, m_style);
    1443         }
    1444         m_style = 0;
    1445     }
    1446    
    1447     // Make sure there is a 0% and a 100% keyframe
    1448     float first = -1;
    1449     float last = -1;
    1450     if (list.size() >= 2) {
    1451         first = list.beginKeyframes()->key();
    1452         last = (list.endKeyframes()-1)->key();
    1453     }
    1454     if (first != 0 || last != 1)
    1455         list.clear();
     1456            list.insert(key, keyframeStyle.get());
     1457        }
     1458        keyframeStyle.release();
     1459    }
     1460   
     1461    // If the 0% keyframe is missing, create it (but only if there is at least one other keyframe)
     1462    int initialListSize = list.size();
     1463    if (initialListSize > 0 && list.beginKeyframes()->key() != 0) {
     1464        RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create();
     1465        keyframe->setKeyText("0%");
     1466        keyframeStyle = styleForKeyframe(elementStyle, keyframe.get(), list);
     1467        list.insert(0, keyframeStyle.release());
     1468    }
     1469
     1470    // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe)
     1471    if (initialListSize > 0 && (list.endKeyframes() - 1)->key() != 1) {
     1472        RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create();
     1473        keyframe->setKeyText("100%");
     1474        keyframeStyle = styleForKeyframe(elementStyle, keyframe.get(), list);
     1475        list.insert(1, keyframeStyle.release());
     1476    }
    14561477}
    14571478
  • trunk/WebCore/css/CSSStyleSelector.h

    r61670 r61933  
    6565class StyleSheetList;
    6666class StyledElement;
     67class WebKitCSSKeyframeRule;
    6768class WebKitCSSKeyframesRule;
    6869
     
    111112
    112113        RenderStyle* style() const { return m_style.get(); }
     114
     115        PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const WebKitCSSKeyframeRule*, KeyframeList&);
    113116
    114117    public:
Note: See TracChangeset for help on using the changeset viewer.