⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgsmilelement.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (C) 2008 Apple Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */#include "config.h"#if ENABLE(SVG_ANIMATION)#include "SVGSMILElement.h"#include "CSSPropertyNames.h"#include "Document.h"#include "Event.h"#include "EventListener.h"#include "FloatConversion.h"#include "FrameView.h"#include "HTMLNames.h"#include "SVGNames.h"#include "SVGParserUtilities.h"#include "SVGSVGElement.h"#include "SVGURIReference.h"#include "SMILTimeContainer.h"#include "XLinkNames.h"#include <math.h>#include <wtf/MathExtras.h>#include <wtf/StdLibExtras.h>#include <wtf/Vector.h>using namespace std;namespace WebCore {    // This is used for duration type time values that can't be negative.static const double invalidCachedTime = -1.;    class ConditionEventListener : public EventListener {public:    static PassRefPtr<ConditionEventListener> create(SVGSMILElement* animation, Element* eventBase, SVGSMILElement::Condition* condition)    {        return adoptRef(new ConditionEventListener(animation, eventBase, condition));    }    void unregister()    {        // If this has only one ref then the event base is dead already and we don't need to remove ourself.        if (!hasOneRef())            m_eventBase->removeEventListener(m_condition->m_name, this, false);    }    virtual void handleEvent(Event* event, bool)     {        m_animation->handleConditionEvent(event, m_condition);    }private:    ConditionEventListener(SVGSMILElement* animation, Element* eventBase, SVGSMILElement::Condition* condition)         : m_animation(animation)        , m_condition(condition)         , m_eventBase(eventBase)    {        m_eventBase->addEventListener(m_condition->m_name, this, false);    }    SVGSMILElement* m_animation;    SVGSMILElement::Condition* m_condition;    Element* m_eventBase;};    SVGSMILElement::Condition::Condition(Type type, BeginOrEnd beginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats)    : m_type(type)    , m_beginOrEnd(beginOrEnd)    , m_baseID(baseID)    , m_name(name)    , m_offset(offset)    , m_repeats(repeats) {}    SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document* doc)    : SVGElement(tagName, doc)    , m_conditionsConnected(false)    , m_hasEndEventConditions(false)    , m_intervalBegin(SMILTime::unresolved())    , m_intervalEnd(SMILTime::unresolved())    , m_previousIntervalBegin(SMILTime::unresolved())    , m_isWaitingForFirstInterval(true)    , m_activeState(Inactive)    , m_lastPercent(0)    , m_lastRepeat(0)    , m_nextProgressTime(0)    , m_documentOrderIndex(0)    , m_cachedDur(invalidCachedTime)    , m_cachedRepeatDur(invalidCachedTime)    , m_cachedRepeatCount(invalidCachedTime)    , m_cachedMin(invalidCachedTime)    , m_cachedMax(invalidCachedTime){}SVGSMILElement::~SVGSMILElement(){    disconnectConditions();    if (m_timeContainer)        m_timeContainer->unschedule(this);}    void SVGSMILElement::insertedIntoDocument(){    SVGElement::insertedIntoDocument();#ifndef NDEBUG    // Verify we are not in <use> instance tree.    for (Node* n = this; n; n = n->parent())        ASSERT(!n->isShadowNode());#endif    SVGSVGElement* owner = ownerSVGElement();    if (!owner)        return;    m_timeContainer = owner->timeContainer();    ASSERT(m_timeContainer);    m_timeContainer->setDocumentOrderIndexesDirty();    reschedule();}void SVGSMILElement::removedFromDocument(){    if (m_timeContainer) {        m_timeContainer->unschedule(this);        m_timeContainer = 0;    }    // Calling disconnectConditions() may kill us if there are syncbase conditions.    // OK, but we don't want to die inside the call.    RefPtr<SVGSMILElement> keepAlive(this);    disconnectConditions();    SVGElement::removedFromDocument();}   void SVGSMILElement::finishParsingChildren(){    SVGElement::finishParsingChildren();    // "If no attribute is present, the default begin value (an offset-value of 0) must be evaluated."    if (!hasAttribute(SVGNames::beginAttr))        m_beginTimes.append(0);    if (m_isWaitingForFirstInterval) {        resolveFirstInterval();        reschedule();    }}SMILTime SVGSMILElement::parseOffsetValue(const String& data){    bool ok;    double result = 0;    String parse = data.stripWhiteSpace();    if (parse.endsWith("h"))        result = parse.left(parse.length() - 1).toDouble(&ok) * 60 * 60;    else if (parse.endsWith("min"))        result = parse.left(parse.length() - 3).toDouble(&ok) * 60;    else if (parse.endsWith("ms"))        result = parse.left(parse.length() - 2).toDouble(&ok) / 1000;    else if (parse.endsWith("s"))        result = parse.left(parse.length() - 1).toDouble(&ok);    else        result = parse.toDouble(&ok);    if (!ok)        return SMILTime::unresolved();    return result;}    SMILTime SVGSMILElement::parseClockValue(const String& data){    if (data.isNull())        return SMILTime::unresolved();        String parse = data.stripWhiteSpace();    DEFINE_STATIC_LOCAL(const AtomicString, indefiniteValue, ("indefinite"));    if (parse == indefiniteValue)        return SMILTime::indefinite();    double result = 0;    bool ok;    int doublePointOne = parse.find(':');    int doublePointTwo = parse.find(':', doublePointOne + 1);    if (doublePointOne == 2 && doublePointTwo == 5 && parse.length() >= 8) {         result += parse.substring(0, 2).toUIntStrict(&ok) * 60 * 60;        if (!ok)            return SMILTime::unresolved();        result += parse.substring(3, 2).toUIntStrict(&ok) * 60;        if (!ok)            return SMILTime::unresolved();        result += parse.substring(6).toDouble(&ok);    } else if (doublePointOne == 2 && doublePointTwo == -1 && parse.length() >= 5) {         result += parse.substring(0, 2).toUIntStrict(&ok) * 60;        if (!ok)            return SMILTime::unresolved();        result += parse.substring(3).toDouble(&ok);    } else        return parseOffsetValue(parse);    if (!ok)        return SMILTime::unresolved();    return result;}    static void sortTimeList(Vector<SMILTime>& timeList){    std::sort(timeList.begin(), timeList.end());}    bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd){    String parseString = value.stripWhiteSpace();        double sign = 1.;    bool ok;    int pos = parseString.find('+');    if (pos == -1) {        pos = parseString.find('-');        if (pos != -1)            sign = -1.;    }    String conditionString;    SMILTime offset = 0;    if (pos == -1)        conditionString = parseString;    else {        conditionString = parseString.left(pos).stripWhiteSpace();        String offsetString = parseString.substring(pos + 1).stripWhiteSpace();        offset = parseOffsetValue(offsetString);        if (offset.isUnresolved())            return false;        offset = offset * sign;    }    if (conditionString.isEmpty())        return false;    pos = conditionString.find('.');        String baseID;    String nameString;    if (pos == -1)        nameString = conditionString;    else {        baseID = conditionString.left(pos);        nameString = conditionString.substring(pos + 1);    }    if (nameString.isEmpty())        return false;    Condition::Type type;    int repeats = -1;    if (nameString.startsWith("repeat(") && nameString.endsWith(")")) {        // FIXME: For repeat events we just need to add the data carrying TimeEvent class and         // fire the events at appropiate times.        repeats = nameString.substring(7, nameString.length() - 8).toUIntStrict(&ok);        if (!ok)            return false;        nameString = "repeat";        type = Condition::EventBase;    } else if (nameString == "begin" || nameString == "end") {        if (baseID.isEmpty())            return false;        type = Condition::Syncbase;    } else if (nameString.startsWith("accesskey(")) {        // FIXME: accesskey() support.        type = Condition::AccessKey;    } else        type = Condition::EventBase;        m_conditions.append(Condition(type, beginOrEnd, baseID, nameString, offset, repeats));    if (type == Condition::EventBase && beginOrEnd == End)        m_hasEndEventConditions = true;    return true;}bool SVGSMILElement::isSMILElement(Node* node){    if (!node)        return false;    return node->hasTagName(SVGNames::setTag) || node->hasTagName(SVGNames::animateTag) || node->hasTagName(SVGNames::animateMotionTag)            || node->hasTagName(SVGNames::animateTransformTag) || node->hasTagName(SVGNames::animateColorTag);}    void SVGSMILElement::parseBeginOrEnd(const String& parseString, BeginOrEnd beginOrEnd){    Vector<SMILTime>& timeList = beginOrEnd == Begin ? m_beginTimes : m_endTimes;    if (beginOrEnd == End)        m_hasEndEventConditions = false;    HashSet<double> existing;

⌨️ 快捷键说明

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