Пример #1
0
RenderSVGResourceMasker* MaskImageOperation::getSVGMasker(RenderElement& renderer)
{
    if (image())
        return nullptr;

    // Identify the element referenced by the fragmentId.
    CachedSVGDocumentReference* svgDocumentReference = cachedSVGDocumentReference();
    Element* elementForMasking = nullptr;
    RenderObject* svgResourceForMasking = nullptr;
    if (svgDocumentReference && svgDocumentReference->document()) {
        SVGDocument* svgDocument = svgDocumentReference->document()->document();
        if (svgDocument && svgDocument->rootElement())
            elementForMasking = svgDocument->rootElement()->getElementById(fragment());
    } else
        elementForMasking = renderer.document().getElementById(fragment());

    if (elementForMasking)
        svgResourceForMasking = elementForMasking->renderer();

    // Check if it's the correct type
    if (svgResourceForMasking && svgResourceForMasking->isSVGResourceContainer() && downcast<RenderSVGResourceContainer>(svgResourceForMasking)->resourceType() == MaskerResourceType)
        return static_cast<RenderSVGResourceMasker*>(svgResourceForMasking);

    return nullptr;
}
Пример #2
0
JSValue jsSVGDocumentRootElement(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSSVGDocument* castedThis = static_cast<JSSVGDocument*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    SVGDocument* imp = static_cast<SVGDocument*>(castedThis->impl());
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->rootElement()));
    return result;
}
Пример #3
0
JSValue* JSSVGDocument::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case RootElementAttrNum: {
        SVGDocument* imp = static_cast<SVGDocument*>(impl());

        return toJS(exec, WTF::getPtr(imp->rootElement()));
    }
    }
    return 0;
}
Пример #4
0
void SVGScriptElement::executeScript(Document *document, StringImpl *jsCode)
{
    if(!document || !jsCode)
        return;
#if 0
    Ecma *ecmaEngine = document->ecmaEngine();
    if(!ecmaEngine)
        return;
                
    KJS::Interpreter::lock();

    // Run script
    KJS::Completion comp = ecmaEngine->evaluate(jsCode.deprecatedString(), ecmaEngine->globalObject());
    if(comp.complType() == KJS::Throw)
    {
        KJS::ExecState *exec = ecmaEngine->globalExec();
        KJS::JSValue *exVal = comp.value();

        int lineno = -1;
        if(exVal->isObject())
        {
            KJS::JSValue *lineVal = static_cast<KJS::JSObject *>(exVal)->get(exec, "line");
            if(lineVal->type() == KJS::NumberType)
                lineno = int(lineVal->toNumber(exec));
        }

        // Fire ERROR_EVENT upon errors...
        SVGDocument *svgDocument = static_cast<SVGDocument *>(document);
        if(svgDocument && document->hasListenerType(ERROR_EVENT))
        {
            RefPtr<Event> event = svgDocument->createEvent("SVGEvents");
            event->initEvent(EventNames::errorEvent, false, false);
            svgDocument->dispatchRecursiveEvent(event.get(), svgDocument->lastChild());
        }

        kdDebug() << "[SVGScriptElement] Evaluation error, line " << (lineno != -1 ? DeprecatedString::number(lineno) : DeprecatedString::fromLatin1("N/A"))  << " " << exVal->toString(exec).deprecatedString() << endl;
    }
    else if(comp.complType() == KJS::ReturnValue)
        kdDebug() << "[SVGScriptElement] Return value: " << comp.value()->toString(ecmaEngine->globalExec()).deprecatedString() << endl;
    else if(comp.complType() == KJS::Normal)
        kdDebug() << "[SVGScriptElement] Evaluated ecma script!" << endl;
    
    KJS::Interpreter::unlock();
#else
    if (jsCode)
        // Hack to close memory leak due to #if 0
        String(jsCode);
#endif
}
Пример #5
0
void MaskImageOperation::notifyFinished(CachedResource* resource)
{
    // The only one notifying us should be the SVG document we hold.
    CachedSVGDocument* cachedSVGDocument = ensureCachedSVGDocumentReference()->document();
    if ((CachedResource*)cachedSVGDocument != resource || !resource) {
        ASSERT_NOT_REACHED();
        return;
    }
    
    // Check if we find a valid masking element in this SVG document.
    SVGDocument* svgDocument = cachedSVGDocument->document();
    bool validMaskFound = false;
    if (svgDocument && svgDocument->rootElement()) {
        // Are we looking for a specific element in the SVG document?
        if (fragment().length()) {
            if (Element* maskingElement = svgDocument->rootElement()->getElementById(fragment())) {
                if (is<SVGMaskElement>(maskingElement))
                    validMaskFound = true;
            }
        }
    }
    
    // If no valid mask was found, this is not a valid SVG document or it specified an invalid fragment identifier.
    // Fallback to the normal way of loading the document in an Image object.
    if (!validMaskFound) {
        // Get the resource loader, acquire the resource buffer and load it into an image.
        ASSERT(cachedSVGDocument->loader());
        if (SubresourceLoader* loader = cachedSVGDocument->loader()) {
            if (SharedBuffer* dataBuffer = loader->resourceData()) {
                m_styleImage = StyleCachedImage::create(new CachedImage(cachedSVGDocument->resourceRequest(), cachedSVGDocument->sessionID()));
                if (m_renderLayerImageClient)
                    m_styleImage->cachedImage()->addClient(m_renderLayerImageClient);
                for (auto itClient : m_rendererImageClients)
                    m_styleImage->addClient(itClient.key);

                m_styleImage->cachedImage()->setResponse(cachedSVGDocument->response());
                m_styleImage->cachedImage()->finishLoading(dataBuffer);

                // Let the cached resource loader of the document which requested this mask keep a handle to this
                // cached image to ensure it only gets deleted when it should.
                if (m_cachedResourceLoader.get())
                    m_cachedResourceLoader->addCachedResource(*m_styleImage->cachedImage());
            }
            
            // Destroy the current SVG document as its no longer needed
            m_cachedSVGDocumentReference = nullptr;
        }
    }
}
Пример #6
0
EncodedJSValue JSC_HOST_CALL jsSVGDocumentPrototypeFunctionCreateEvent(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSSVGDocument::s_info))
        return throwVMTypeError(exec);
    JSSVGDocument* castedThis = static_cast<JSSVGDocument*>(asObject(thisValue));
    SVGDocument* imp = static_cast<SVGDocument*>(castedThis->impl());
    ExceptionCode ec = 0;
    const String& eventType(ustringToString(exec->argument(0).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->createEvent(eventType, ec)));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}
Пример #7
0
JSValue* JSSVGDocumentPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSSVGDocument::info))
      return throwError(exec, TypeError);

    JSSVGDocument* castedThisObj = static_cast<JSSVGDocument*>(thisObj);
    SVGDocument* imp = static_cast<SVGDocument*>(castedThisObj->impl());

    switch (id) {
    case JSSVGDocument::CreateEventFuncNum: {
        ExceptionCode ec = 0;
        String eventType = args[0]->toString(exec);


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createEvent(eventType, ec)));
        setDOMException(exec, ec);
        return result;
    }
    }
    return 0;
}