| | 187 | #define HANDLE_ANIMATION_INHERIT_AND_INITIAL(prop, Prop) \ |
|---|
| | 188 | if (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 | } \ |
|---|
| | 202 | if (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) { \ |
|---|
| | 210 | HANDLE_ANIMATION_INHERIT_AND_INITIAL(prop, Prop) \ |
|---|
| | 211 | if (isInherit || isInitial) \ |
|---|
| | 212 | return; \ |
|---|
| | 213 | AnimationList* list = m_style->accessAnimations(); \ |
|---|
| | 214 | size_t childIndex = 0; \ |
|---|
| | 215 | if (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 | } \ |
|---|
| | 230 | for ( ; childIndex < list->size(); ++childIndex) { \ |
|---|
| | 231 | /* Reset all remaining layers to not have the property set. */ \ |
|---|
| | 232 | (*list)[childIndex]->clear##Prop(); \ |
|---|
| | 233 | } \ |
|---|
| | 234 | } |
|---|
| | 235 | |
|---|
| 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()); \ |
|---|
| 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 | } \ |
|---|
| | 251 | if (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(); \ |
|---|
| 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; \ |
|---|
| | 421 | // this is a simplified style setting function for keyframe styles |
|---|
| | 422 | void 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 | |
|---|
| | 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; |
|---|
| 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 | |
|---|
| | 5139 | void 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 | |
|---|
| | 5150 | void CSSStyleSelector::mapAnimationDuration(Animation* animation, CSSValue* value) |
|---|
| | 5151 | { |
|---|
| | 5152 | if (value->cssValueType() == CSSValue::CSS_INITIAL) { |
|---|
| | 5153 | animation->setDuration(RenderStyle::initialAnimationDuration()); |
|---|
| 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 | |
|---|
| | 5204 | void 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 | |
|---|
| | 5215 | void 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 | |
|---|
| | 5229 | void CSSStyleSelector::mapAnimationTimingFunction(Animation* animation, CSSValue* value) |
|---|
| | 5230 | { |
|---|
| | 5231 | if (value->cssValueType() == CSSValue::CSS_INITIAL) { |
|---|
| | 5232 | animation->setTimingFunction(RenderStyle::initialAnimationTimingFunction()); |
|---|
| | 5233 | return; |
|---|
| | 5234 | } |
|---|
| | 5235 | |
|---|
| 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 | } |
|---|