Exemple #1
0
JSValue* JSClipboard::getValueProperty(ExecState* exec, int token) const
{
    Clipboard* clipboard = impl();
    switch (token) {
        case DropEffect:
            ASSERT(clipboard->isForDragging() || clipboard->dropEffect().isNull());
            return jsStringOrUndefined(clipboard->dropEffect());
        case EffectAllowed:
            ASSERT(clipboard->isForDragging() || clipboard->effectAllowed().isNull());
            return jsStringOrUndefined(clipboard->effectAllowed());
        case Types:
        {
            HashSet<String> types = clipboard->types();
            if (types.isEmpty())
                return jsNull();
            else {
                List list;
                HashSet<String>::const_iterator end = types.end();
                for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it)
                    list.append(jsString(UString(*it)));
                return exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
            }
        }
        default:
            return 0;
    }
}
v8::Handle<v8::Value> V8Clipboard::setDragImageCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.Clipboard.setDragImage()");
    Clipboard* clipboard = V8Clipboard::toNative(args.Holder());

    if (!clipboard->isForDragging())
        return v8::Undefined();

    if (args.Length() != 3)
        return throwError("setDragImage: Invalid number of arguments", V8Proxy::SyntaxError);

    int x = toInt32(args[1]);
    int y = toInt32(args[2]);

    Node* node = 0;
    if (V8Node::HasInstance(args[0]))
        node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0]));

    if (!node || !node->isElementNode())
        return throwError("setDragImageFromElement: Invalid first argument");

    if (static_cast<Element*>(node)->hasLocalName(HTMLNames::imgTag) && !node->inDocument())
        clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
    else
        clipboard->setDragImageElement(node, IntPoint(x, y));

    return v8::Undefined();
}
Exemple #3
0
void JSClipboard::putValueProperty(ExecState* exec, int token, JSValue* value, int /*attr*/)
{
    Clipboard* clipboard = impl();
    switch (token) {
        case DropEffect:
            // can never set this when not for dragging, thus getting always returns NULL string
            if (clipboard->isForDragging())
                clipboard->setDropEffect(value->toString(exec));
            break;
        case EffectAllowed:
            // can never set this when not for dragging, thus getting always returns NULL string
            if (clipboard->isForDragging())
                clipboard->setEffectAllowed(value->toString(exec));
            break;
    }
}
JSValuePtr JSClipboard::setDragImage(ExecState* exec, const ArgList& args)
{
    Clipboard* clipboard = impl();

    if (!clipboard->isForDragging())
        return jsUndefined();

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    if (args.size() != 3)
        return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments");

    int x = args.at(exec, 1).toInt32(exec);
    int y = args.at(exec, 2).toInt32(exec);

    // See if they passed us a node
    Node* node = toNode(args.at(exec, 0));
    if (!node)
        return throwError(exec, TypeError);

    // FIXME: This should probably be a TypeError. 
    if (!node->isElementNode())
        return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");

    if (static_cast<Element*>(node)->hasLocalName(imgTag) && !node->inDocument())
        clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
    else
        clipboard->setDragImageElement(node, IntPoint(x, y));

    return jsUndefined();
}
Exemple #5
0
JSValue* JSClipboardPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSClipboard::info))
        return throwError(exec, TypeError);

    Clipboard* clipboard = static_cast<JSClipboard*>(thisObj)->impl();
    switch (id) {
        case JSClipboard::ClearData:
            if (args.size() == 0) {
                clipboard->clearAllData();
                return jsUndefined();
            } else if (args.size() == 1) {
                clipboard->clearData(args[0]->toString(exec));
                return jsUndefined();
            } else
                return throwError(exec, SyntaxError, "clearData: Invalid number of arguments");
        case JSClipboard::GetData:
        {
            if (args.size() == 1) {
                bool success;
                String result = clipboard->getData(args[0]->toString(exec), success);
                if (success)
                    return jsString(result);
                return jsUndefined();
            } else
                return throwError(exec, SyntaxError, "getData: Invalid number of arguments");
        }
        case JSClipboard::SetData:
            if (args.size() == 2)
                return jsBoolean(clipboard->setData(args[0]->toString(exec), args[1]->toString(exec)));
            return throwError(exec, SyntaxError, "setData: Invalid number of arguments");
        case JSClipboard::SetDragImage:
        {
            if (!clipboard->isForDragging())
                return jsUndefined();

            if (args.size() != 3)
                return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments");

            int x = args[1]->toInt32(exec);
            int y = args[2]->toInt32(exec);

            // See if they passed us a node
            Node* node = toNode(args[0]);
            if (!node)
                return throwError(exec, TypeError);

            if (!node->isElementNode())
                return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");

            if (static_cast<Element*>(node)->hasLocalName(imgTag) &&
                !node->inDocument())
                clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
            else
                clipboard->setDragImageElement(node, IntPoint(x, y));

            return jsUndefined();
        }
    }
    return jsUndefined();
}