Show
Ignore:
Timestamp:
08/06/08 13:29:36 (5 months ago)
Author:
mbensi
Message:

merge with webkit revision 35588

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r424 r431  
    7171#include "Text.h" 
    7272#include "UserAgentStyleSheets.h" 
     73#include "WebKitCSSKeyframeRule.h" 
     74#include "WebKitCSSKeyframesRule.h" 
    7375#include "WebKitCSSTransformValue.h" 
    7476#include "XMLNames.h" 
     
    183185HANDLE_FILL_LAYER_VALUE(mask, Mask, prop, Prop, value) 
    184186 
     187#define HANDLE_ANIMATION_INHERIT_AND_INITIAL(prop, Prop) \ 
     188if (isInherit) { \ 
     189    AnimationList* list = m_style->accessAnimations(); \ 
     190    const AnimationList* parentList = m_parentStyle->animations(); \ 
     191    size_t i = 0; \ 
     192    for ( ; i < parentList->size() && (*parentList)[i]->is##Prop##Set(); ++i) { \ 
     193        if (list->size() <= i) \ 
     194            list->append(Animation::create()); \ 
     195        (*list)[i]->set##Prop((*parentList)[i]->prop()); \ 
     196    } \ 
     197    \ 
     198    /* Reset any remaining layers to not have the property set. */ \ 
     199    for ( ; i < list->size(); ++i) \ 
     200        (*list)[i]->clear##Prop(); \ 
     201} \ 
     202if (isInitial) { \ 
     203    AnimationList* list = m_style->accessAnimations(); \ 
     204    (*list)[0]->set##Prop(RenderStyle::initialAnimation##Prop()); \ 
     205    for (size_t i = 1; i < list->size(); ++i) \ 
     206        (*list)[0]->clear##Prop(); \ 
     207} 
     208 
     209#define HANDLE_ANIMATION_VALUE(prop, Prop, value) { \ 
     210HANDLE_ANIMATION_INHERIT_AND_INITIAL(prop, Prop) \ 
     211if (isInherit || isInitial) \ 
     212    return; \ 
     213AnimationList* list = m_style->accessAnimations(); \ 
     214size_t childIndex = 0; \ 
     215if (value->isValueList()) { \ 
     216    /* Walk each value and put it into a layer, creating new layers as needed. */ \ 
     217    CSSValueList* valueList = static_cast<CSSValueList*>(value); \ 
     218    for (unsigned int i = 0; i < valueList->length(); i++) { \ 
     219        if (childIndex <= list->size()) \ 
     220            list->append(Animation::create()); \ 
     221        mapAnimation##Prop((*list)[childIndex].get(), valueList->itemWithoutBoundsCheck(i)); \ 
     222        ++childIndex; \ 
     223    } \ 
     224} else { \ 
     225    if (list->isEmpty()) \ 
     226        list->append(Animation::create()); \ 
     227    mapAnimation##Prop((*list)[childIndex].get(), value); \ 
     228    childIndex = 1; \ 
     229} \ 
     230for ( ; childIndex < list->size(); ++childIndex) { \ 
     231    /* Reset all remaining layers to not have the property set. */ \ 
     232    (*list)[childIndex]->clear##Prop(); \ 
     233} \ 
     234} 
     235 
    185236#define HANDLE_TRANSITION_INHERIT_AND_INITIAL(prop, Prop) \ 
    186237if (isInherit) { \ 
    187     Transition* currChild = m_style->accessTransitions(); \ 
    188     Transition* prevChild = 0; \ 
    189     const Transition* currParent = m_parentStyle->transitions(); \ 
    190     while (currParent && currParent->is##Prop##Set()) { \ 
    191         if (!currChild) { \ 
    192             /* Need to make a new layer.*/ \ 
    193             currChild = new Transition(); \ 
    194             prevChild->setNext(currChild); \ 
    195         } \ 
    196         currChild->set##Prop(currParent->prop()); \ 
    197         prevChild = currChild; \ 
    198         currChild = prevChild->next(); \ 
    199         currParent = currParent->next(); \ 
     238    AnimationList* list = m_style->accessTransitions(); \ 
     239    const AnimationList* parentList = m_parentStyle->transitions(); \ 
     240    size_t i = 0; \ 
     241    for ( ; i < parentList->size() && (*parentList)[i]->is##Prop##Set(); ++i) { \ 
     242        if (list->size() <= i) \ 
     243            list->append(Animation::create()); \ 
     244        (*list)[i]->set##Prop((*parentList)[i]->prop()); \ 
    200245    } \ 
    201246    \ 
    202     while (currChild) { \ 
    203         /* Reset any remaining layers to not have the property set. */ \ 
    204         currChild->clear##Prop(); \ 
    205         currChild = currChild->next(); \ 
    206     } \ 
    207 } else if (isInitial) { \ 
    208     Transition* currChild = m_style->accessTransitions(); \ 
    209     currChild->set##Prop(RenderStyle::initialTransition##Prop()); \ 
    210     for (currChild = currChild->next(); currChild; currChild = currChild->next()) \ 
    211         currChild->clear##Prop(); \ 
     247    /* Reset any remaining layers to not have the property set. */ \ 
     248    for ( ; i < list->size(); ++i) \ 
     249        (*list)[i]->clear##Prop(); \ 
     250} \ 
     251if (isInitial) { \ 
     252    AnimationList* list = m_style->accessTransitions(); \ 
     253    (*list)[0]->set##Prop(RenderStyle::initialAnimation##Prop()); \ 
     254    for (size_t i = 1; i < list->size(); ++i) \ 
     255        (*list)[0]->clear##Prop(); \ 
    212256} 
    213257 
     
    216260if (isInherit || isInitial) \ 
    217261    return; \ 
    218 Transition* currChild = m_style->accessTransitions(); \ 
    219 Transition* prevChild = 0; \ 
     262AnimationList* list = m_style->accessTransitions(); \ 
     263size_t childIndex = 0; \ 
    220264if (value->isValueList()) { \ 
    221265    /* Walk each value and put it into a layer, creating new layers as needed. */ \ 
    222266    CSSValueList* valueList = static_cast<CSSValueList*>(value); \ 
    223267    for (unsigned int i = 0; i < valueList->length(); i++) { \ 
    224         if (!currChild) { \ 
    225             /* Need to make a new layer to hold this value */ \ 
    226             currChild = new Transition(); \ 
    227             prevChild->setNext(currChild); \ 
    228         } \ 
    229         mapTransition##Prop(currChild, valueList->itemWithoutBoundsCheck(i)); \ 
    230         prevChild = currChild; \ 
    231         currChild = currChild->next(); \ 
     268        if (childIndex <= list->size()) \ 
     269            list->append(Animation::create()); \ 
     270        mapAnimation##Prop((*list)[childIndex].get(), valueList->itemWithoutBoundsCheck(i)); \ 
     271        ++childIndex; \ 
    232272    } \ 
    233273} else { \ 
    234     mapTransition##Prop(currChild, value); \ 
    235     currChild = currChild->next(); \ 
     274    if (list->isEmpty()) \ 
     275        list->append(Animation::create()); \ 
     276    mapAnimation##Prop((*list)[childIndex].get(), value); \ 
     277    childIndex = 1; \ 
    236278} \ 
    237 while (currChild) { \ 
     279for ( ; childIndex < list->size(); ++childIndex) { \ 
    238280    /* Reset all remaining layers to not have the property set. */ \ 
    239     currChild->clear##Prop(); \ 
    240     currChild = currChild->next();
    241 } } 
     281    (*list)[childIndex]->clear##Prop(); \ 
     282}
     283} 
    242284 
    243285#define HANDLE_INHERIT_COND(propID, prop, Prop) \ 
     
    377419} 
    378420 
     421// this is a simplified style setting function for keyframe styles 
     422void CSSStyleSelector::addKeyframeStyle(Document* doc, const WebKitCSSKeyframesRule* rule) 
     423{ 
     424    AtomicString s(rule->name()); 
     425    RefPtr<KeyframeList> list; 
     426    if (m_keyframeRuleMap.contains(s.impl())) 
     427        list = m_keyframeRuleMap.get(s.impl()).get(); 
     428    else { 
     429        list = KeyframeList::create(s); 
     430        m_keyframeRuleMap.add(s.impl(), list); 
     431    } 
     432    list->clear(); 
     433                     
     434    for (unsigned i = 0; i < rule->length(); ++i) { 
     435        const WebKitCSSKeyframeRule* kf = rule->item(i); 
     436        m_style = new (doc->renderArena()) RenderStyle(); 
     437        m_style->ref(); 
     438        CSSMutableStyleDeclaration* decl = kf->style(); 
     439        DeprecatedValueListConstIterator<CSSProperty> end; 
     440        for (DeprecatedValueListConstIterator<CSSProperty> it = decl->valuesIterator(); it != end; ++it) { 
     441            const CSSProperty& current = *it; 
     442            applyProperty(current.id(), current.value()); 
     443            list->addProperty(current.id()); 
     444        } 
     445        list->insert(kf->key(), *m_style); 
     446        m_style->deref(doc->renderArena()); 
     447        m_style = 0; 
     448    } 
     449} 
     450 
    379451void CSSStyleSelector::init() 
    380452{ 
     
    394466    delete m_userStyle; 
    395467    deleteAllValues(m_viewportDependentMediaQueryResults); 
     468    m_keyframeRuleMap.clear(); 
    396469} 
    397470 
     
    874947                return false; 
    875948             
    876             if (style->transitions()
     949            if (style->transitions() || style->animations()
    877950                return false; 
    878951 
     
    13301403    style->adjustMaskLayers(); 
    13311404 
    1332     // Do the same for transitions. 
     1405    // Do the same for animations and transitions. 
     1406    style->adjustAnimations(); 
    13331407    style->adjustTransitions(); 
    13341408 
     
    23252399                        for (CSSSelector* s = rule->selector(); s; s = s->next()) 
    23262400                            addRule(rule, s); 
    2327                     } else if (item->isFontFaceRule() && styleSelector) { 
     2401                    } else if (childItem->isFontFaceRule() && styleSelector) { 
    23282402                        // Add this font face to our set. 
    23292403                        const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(item); 
    23302404                        styleSelector->fontSelector()->addFontFaceRule(fontFaceRule); 
     2405                    } else if (childItem->isKeyframesRule() && styleSelector) { 
     2406                        // Add this keyframe rule to our set. 
     2407                        const WebKitCSSKeyframesRule* keyframesRule = static_cast<WebKitCSSKeyframesRule*>(childItem); 
     2408                        styleSelector->addKeyframeStyle(sheet->doc(), keyframesRule); 
    23312409                    } 
    23322410                }   // for rules 
     
    23412419            if (!variables->media() || medium.eval(variables->media(), styleSelector)) 
    23422420                styleSelector->addVariables(variables); 
     2421        } else if (item->isKeyframesRule()) { 
     2422            WebKitCSSKeyframesRule* r = static_cast<WebKitCSSKeyframesRule*>(item); 
     2423            styleSelector->addKeyframeStyle(sheet->doc(), r); 
    23432424        } 
    23442425    } 
     
    47534834        break; 
    47544835    } 
     4836    case CSSPropertyWebkitAnimation: 
     4837        if (isInitial) 
     4838            m_style->clearAnimations(); 
     4839        else if (isInherit) 
     4840            m_style->inheritAnimations(m_parentStyle->animations()); 
     4841        return; 
     4842    case CSSPropertyWebkitAnimationDelay: 
     4843        HANDLE_ANIMATION_VALUE(delay, Delay, value) 
     4844        return; 
     4845    case CSSPropertyWebkitAnimationDirection: 
     4846        HANDLE_ANIMATION_VALUE(direction, Direction, value) 
     4847        return; 
     4848    case CSSPropertyWebkitAnimationDuration: 
     4849        HANDLE_ANIMATION_VALUE(duration, Duration, value) 
     4850        return; 
     4851    case CSSPropertyWebkitAnimationIterationCount: 
     4852        HANDLE_ANIMATION_VALUE(iterationCount, IterationCount, value) 
     4853        return; 
     4854    case CSSPropertyWebkitAnimationName: 
     4855        HANDLE_ANIMATION_VALUE(name, Name, value) 
     4856        return; 
     4857    case CSSPropertyWebkitAnimationPlayState: 
     4858        HANDLE_ANIMATION_VALUE(playState, PlayState, value) 
     4859        return; 
     4860    case CSSPropertyWebkitAnimationTimingFunction: 
     4861        HANDLE_ANIMATION_VALUE(timingFunction, TimingFunction, value) 
     4862        return; 
    47554863    case CSSPropertyWebkitTransition: 
    47564864        if (isInitial) 
     
    47594867            m_style->inheritTransitions(m_parentStyle->transitions()); 
    47604868        return; 
     4869    case CSSPropertyWebkitTransitionDelay: 
     4870        HANDLE_TRANSITION_VALUE(delay, Delay, value) 
     4871        return; 
    47614872    case CSSPropertyWebkitTransitionDuration: 
    47624873        HANDLE_TRANSITION_VALUE(duration, Duration, value) 
    47634874        return; 
    4764     case CSSPropertyWebkitTransitionRepeatCount
    4765         HANDLE_TRANSITION_VALUE(repeatCount, RepeatCount, value) 
     4875    case CSSPropertyWebkitTransitionProperty
     4876        HANDLE_TRANSITION_VALUE(property, Property, value) 
    47664877        return; 
    47674878    case CSSPropertyWebkitTransitionTimingFunction: 
    47684879        HANDLE_TRANSITION_VALUE(timingFunction, TimingFunction, value) 
    4769         return; 
    4770     case CSSPropertyWebkitTransitionProperty: 
    4771         HANDLE_TRANSITION_VALUE(property, Property, value) 
    47724880        return; 
    47734881    case CSSPropertyInvalid: 
     
    50115119} 
    50125120 
    5013 void CSSStyleSelector::mapTransitionDuration(Transition* transition, CSSValue* value) 
     5121void CSSStyleSelector::mapAnimationDelay(Animation* animation, CSSValue* value) 
    50145122{ 
    50155123    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
    5016         transition->setDuration(RenderStyle::initialTransitionDuration()); 
     5124        animation->setDelay(RenderStyle::initialAnimationDelay()); 
     5125        return; 
     5126    } 
     5127 
     5128    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
     5129    if (primitiveValue->getIdent() == CSSValueNow) 
     5130        animation->setDelay(0); 
     5131    else { 
     5132        if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_S) 
     5133            animation->setDelay(primitiveValue->getFloatValue()); 
     5134        else 
     5135            animation->setDelay(primitiveValue->getFloatValue()/1000.0f); 
     5136    } 
     5137
     5138 
     5139void CSSStyleSelector::mapAnimationDirection(Animation* layer, CSSValue* value) 
     5140
     5141    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
     5142        layer->setDirection(RenderStyle::initialAnimationDirection()); 
     5143        return; 
     5144    } 
     5145 
     5146    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
     5147    layer->setDirection(primitiveValue->getIdent() == CSSValueAlternate); 
     5148
     5149 
     5150void CSSStyleSelector::mapAnimationDuration(Animation* animation, CSSValue* value) 
     5151
     5152    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
     5153        animation->setDuration(RenderStyle::initialAnimationDuration()); 
    50175154        return; 
    50185155    } 
     
    50235160    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
    50245161    if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_S) 
    5025         transition->setDuration(int(1000*primitiveValue->getFloatValue())); 
     5162        animation->setDuration(primitiveValue->getFloatValue()); 
    50265163    else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_MS) 
    5027         transition->setDuration(int(primitiveValue->getFloatValue())); 
    5028 } 
    5029  
    5030 void CSSStyleSelector::mapTransitionRepeatCount(Transition* transition, CSSValue* value) 
     5164        animation->setDuration(primitiveValue->getFloatValue()/1000.0f); 
     5165} 
     5166 
     5167void CSSStyleSelector::mapAnimationIterationCount(Animation* animation, CSSValue* value) 
    50315168{ 
    50325169    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
    5033         transition->setRepeatCount(RenderStyle::initialTransitionRepeatCount()); 
     5170        animation->setIterationCount(RenderStyle::initialAnimationIterationCount()); 
    50345171        return; 
    50355172    } 
     
    50405177    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
    50415178    if (primitiveValue->getIdent() == CSSValueInfinite) 
    5042         transition->setRepeatCount(-1); 
     5179        animation->setIterationCount(-1); 
    50435180    else 
    5044         transition->setRepeatCount(int(primitiveValue->getFloatValue())); 
    5045 } 
    5046  
    5047 void CSSStyleSelector::mapTransitionTimingFunction(Transition* transition, CSSValue* value) 
     5181        animation->setIterationCount(int(primitiveValue->getFloatValue())); 
     5182} 
     5183 
     5184void CSSStyleSelector::mapAnimationName(Animation* layer, CSSValue* value) 
    50485185{ 
    50495186    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
    5050         transition->setTimingFunction(RenderStyle::initialTransitionTimingFunction()); 
    5051         return; 
    5052     } 
    5053  
     5187        layer->setName(RenderStyle::initialAnimationName()); 
     5188        return; 
     5189    } 
     5190 
     5191    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
     5192     
     5193    if (primitiveValue->getIdent() == CSSValueNone) { 
     5194        layer->setIsNoneAnimation(true); 
     5195    } else { 
     5196        layer->setName(primitiveValue->getStringValue()); 
     5197     
     5198        // resolve to the keyframes 
     5199        RefPtr<KeyframeList> keyframe = findKeyframeRule(primitiveValue->getStringValue()); 
     5200        layer->setAnimationKeyframe(keyframe); 
     5201    } 
     5202
     5203 
     5204void CSSStyleSelector::mapAnimationPlayState(Animation* layer, CSSValue* value) 
     5205
     5206    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
     5207        layer->setPlayState(RenderStyle::initialAnimationPlayState()); 
     5208        return; 
     5209    } 
     5210 
     5211    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
     5212    layer->setPlayState((primitiveValue->getIdent() == CSSValuePaused) ? AnimPlayStatePaused : AnimPlayStatePlaying); 
     5213
     5214 
     5215void CSSStyleSelector::mapAnimationProperty(Animation* animation, CSSValue* value) 
     5216
     5217    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
     5218        animation->setProperty(RenderStyle::initialAnimationProperty()); 
     5219        return; 
     5220    } 
     5221 
     5222    if (!value->isPrimitiveValue()) 
     5223        return; 
     5224 
     5225    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
     5226    animation->setProperty(static_cast<CSSPropertyID>(primitiveValue->getIdent())); 
     5227
     5228 
     5229void CSSStyleSelector::mapAnimationTimingFunction(Animation* animation, CSSValue* value) 
     5230
     5231    if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
     5232        animation->setTimingFunction(RenderStyle::initialAnimationTimingFunction()); 
     5233        return; 
     5234    } 
     5235     
    50545236    if (value->isPrimitiveValue()) { 
    50555237        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
    50565238        switch (primitiveValue->getIdent()) { 
    50575239            case CSSValueLinear: 
    5058                 transition->setTimingFunction(TimingFunction(LinearTimingFunction)); 
     5240                animation->setTimingFunction(TimingFunction(LinearTimingFunction)); 
    50595241                break; 
    50605242            case CSSValueEase: 
    5061                 transition->setTimingFunction(TimingFunction()); 
     5243                animation->setTimingFunction(TimingFunction()); 
    50625244                break; 
    50635245            case CSSValueEaseIn: 
    5064                 transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .42, .0, 1.0, 1.0)); 
     5246                animation->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .42, .0, 1.0, 1.0)); 
    50655247                break; 
    50665248            case CSSValueEaseOut: 
    5067                 transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .0, .0, .58, 1.0)); 
     5249                animation->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .0, .0, .58, 1.0)); 
    50685250                break; 
    50695251            case CSSValueEaseInOut: 
    5070                 transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .42, .0, .58, 1.0)); 
    5071                 break; 
    5072         } 
    5073         return; 
    5074     } 
    5075  
    5076     if (value->isTransitionTimingFunctionValue()) { 
     5252                animation->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .42, .0, .58, 1.0)); 
     5253                break; 
     5254        } 
     5255        return; 
     5256    } 
     5257     
     5258    if (value->isTimingFunctionValue()) { 
    50775259        CSSTimingFunctionValue* timingFunction = static_cast<CSSTimingFunctionValue*>(value); 
    5078         transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, timingFunction->x1(), timingFunction->y1(), timingFunction->x2(), timingFunction->y2())); 
    5079     } 
    5080 
    5081  
    5082 void CSSStyleSelector::mapTransitionProperty(Transition* transition, CSSValue* value) 
    5083 
    5084     if (value->cssValueType() == CSSValue::CSS_INITIAL) { 
    5085         transition->setProperty(RenderStyle::initialTransitionProperty()); 
    5086         return; 
    5087     } 
    5088  
    5089     if (!value->isPrimitiveValue()) 
    5090         return; 
    5091  
    5092     CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 
    5093     transition->setProperty(primitiveValue->getIdent()); 
     5260        animation->setTimingFunction(TimingFunction(CubicBezierTimingFunction, timingFunction->x1(), timingFunction->y1(), timingFunction->x2(), timingFunction->y2())); 
     5261    } 
    50945262} 
    50955263