animationbase.cpp

来自「linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自Web」· C++ 代码 · 共 1,080 行 · 第 1/4 页

CPP
1,080
字号
#endif // USE(ACCELERATED_COMPOSITING)class PropertyWrapperShadow : public PropertyWrapperGetter<ShadowData*> {public:    PropertyWrapperShadow(int prop, ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(ShadowData*, bool))        : PropertyWrapperGetter<ShadowData*>(prop, getter)        , m_setter(setter)    {    }    virtual bool equals(const RenderStyle* a, const RenderStyle* b) const    {        ShadowData* shadowA = (a->*m_getter)();        ShadowData* shadowB = (b->*m_getter)();        if (!shadowA && shadowB || shadowA && !shadowB)            return false;        if (shadowA && shadowB && (*shadowA != *shadowB))            return false;        return true;    }    virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const    {        ShadowData* shadowA = (a->*m_getter)();        ShadowData* shadowB = (b->*m_getter)();        ShadowData defaultShadowData(0, 0, 0, Color::transparent);        if (!shadowA)            shadowA = &defaultShadowData;        if (!shadowB)            shadowB = &defaultShadowData;        (dst->*m_setter)(blendFunc(anim, shadowA, shadowB, progress), false);    }private:    void (RenderStyle::*m_setter)(ShadowData*, bool);};class PropertyWrapperMaybeInvalidColor : public PropertyWrapperBase {public:    PropertyWrapperMaybeInvalidColor(int prop, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))        : PropertyWrapperBase(prop)        , m_getter(getter)        , m_setter(setter)    {    }    virtual bool equals(const RenderStyle* a, const RenderStyle* b) const    {        Color fromColor = (a->*m_getter)();        Color toColor = (b->*m_getter)();        if (!fromColor.isValid())            fromColor = a->color();        if (!toColor.isValid())            toColor = b->color();        return fromColor == toColor;    }    virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const    {        Color fromColor = (a->*m_getter)();        Color toColor = (b->*m_getter)();        if (!fromColor.isValid())            fromColor = a->color();        if (!toColor.isValid())            toColor = b->color();        (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));    }private:    const Color& (RenderStyle::*m_getter)() const;    void (RenderStyle::*m_setter)(const Color&);};class ShorthandPropertyWrapper : public PropertyWrapperBase {public:    ShorthandPropertyWrapper(int property, const CSSPropertyLonghand& longhand)        : PropertyWrapperBase(property)    {        for (unsigned i = 0; i < longhand.length(); ++i) {            PropertyWrapperBase* wrapper = wrapperForProperty(longhand.properties()[i]);            if (wrapper)                m_propertyWrappers.append(wrapper);        }    }    virtual bool isShorthandWrapper() const { return true; }    virtual bool equals(const RenderStyle* a, const RenderStyle* b) const    {        Vector<PropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();        for (Vector<PropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it) {            if (!(*it)->equals(a, b))                return false;        }        return true;    }    virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const    {        Vector<PropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();        for (Vector<PropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it)            (*it)->blend(anim, dst, a, b, progress);    }private:    Vector<PropertyWrapperBase*> m_propertyWrappers;};static Vector<PropertyWrapperBase*>* gPropertyWrappers = 0;static int gPropertyWrapperMap[numCSSProperties];static const int cInvalidPropertyWrapperIndex = -1;static void ensurePropertyMap(){    // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last AnimationController is destroyed?    if (gPropertyWrappers == 0) {        gPropertyWrappers = new Vector<PropertyWrapperBase*>();        // build the list of property wrappers to do the comparisons and blends        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom));        gPropertyWrappers->append(new PropertyWrapper<const Color&>(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor));        gPropertyWrappers->append(new PropertyWrapper<const Color&>(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor));        gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyFontSize, &RenderStyle::fontSize, &RenderStyle::setBlendedFontSize));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth));        gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing));        gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing));        gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::lineHeight, &RenderStyle::setLineHeight));        gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset));        gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth));        gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing));        gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX));        gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ));        gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius));        gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius));        gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius));        gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius));        gPropertyWrappers->append(new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoom));        #if USE(ACCELERATED_COMPOSITING)        gPropertyWrappers->append(new PropertyWrapperAcceleratedOpacity());        gPropertyWrappers->append(new PropertyWrapperAcceleratedTransform());#else        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity));        gPropertyWrappers->append(new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform));#endif        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyWebkitColumnRuleColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyWebkitTextStrokeColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyWebkitTextFillColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyBorderLeftColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyBorderRightColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyBorderTopColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyBorderBottomColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor));        gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyOutlineColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor));        // These are for shadows        gPropertyWrappers->append(new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow));        gPropertyWrappers->append(new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow));#if ENABLE(SVG)        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity));        gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity));#endif        // TODO:        //         //  CSSPropertyBackground, CSSPropertyBackgroundPosition        //  CSSPropertyMinWidth, CSSPropertyMaxWidth, CSSPropertyMinHeight, CSSPropertyMaxHeight        //  CSSPropertyTextIndent        //  CSSPropertyVerticalAlign        //  CSSPropertyWebkitBackgroundOrigin        //  CSSPropertyWebkitBackgroundSize        //  CSSPropertyWebkitMaskPosition        //  CSSPropertyWebkitMaskOrigin        //  CSSPropertyWebkitMaskSize        //         // Compound properties that have components that should be animatable:        //         //  CSSPropertyWebkitColumns        //  CSSPropertyWebkitMask        //  CSSPropertyWebkitBoxReflect        // Make sure unused slots have a value        for (unsigned int i = 0; i < static_cast<unsigned int>(numCSSProperties); ++i)            gPropertyWrapperMap[i] = cInvalidPropertyWrapperIndex;        // First we put the non-shorthand property wrappers into the map, so the shorthand-building        // code can find them.        size_t n = gPropertyWrappers->size();        for (unsigned int i = 0; i < n; ++i) {            ASSERT((*gPropertyWrappers)[i]->property() - firstCSSProperty < numCSSProperties);            gPropertyWrapperMap[(*gPropertyWrappers)[i]->property() - firstCSSProperty] = i;        }                // Now add the shorthand wrappers.        addShorthandProperties();    }}static void addPropertyWrapper(int propertyID, PropertyWrapperBase* wrapper){    int propIndex = propertyID - firstCSSProperty;    ASSERT(gPropertyWrapperMap[propIndex] == cInvalidPropertyWrapperIndex);    unsigned wrapperIndex = gPropertyWrappers->size();    gPropertyWrappers->append(wrapper);    gPropertyWrapperMap[propIndex] = wrapperIndex;}static void addShorthandProperties(){    static const int animatableShorthandProperties[] = {        CSSPropertyBackground,      // for background-color        CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,        CSSPropertyBorderColor,         CSSPropertyBorderWidth,        CSSPropertyBorder,        CSSPropertyBorderSpacing,        CSSPropertyMargin,        CSSPropertyOutline,        CSSPropertyPadding,        CSSPropertyWebkitTextStroke,        CSSPropertyWebkitColumnRule,        CSSPropertyWebkitBorderRadius,        CSSPropertyWebkitTransformOrigin    };    for (unsigned i = 0; i < sizeof(animatableShorthandProperties) / sizeof(animatableShorthandProperties[0]); ++i) {        int propertyID = animatableShorthandProperties[i];        CSSPropertyLonghand longhand = longhandForProperty(propertyID);        if (longhand.length() > 0)            addPropertyWrapper(propertyID, new ShorthandPropertyWrapper(propertyID, longhand));    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?