v8::Handle<v8::Value> V8Clipboard::setDragImageCallback(const v8::Arguments& args) { INC_STATS("DOM.Clipboard.setDragImage()"); Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); if (!clipboard->isForDragAndDrop()) return v8::Undefined(); if (args.Length() != 3) return V8Proxy::throwError(V8Proxy::SyntaxError, "setDragImage: Invalid number of arguments", args.GetIsolate()); 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 V8Proxy::throwTypeError("setDragImageFromElement: Invalid first argument", args.GetIsolate()); 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(); }
void V8Clipboard::setDragImageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); if (!clipboard->isForDragAndDrop()) return; if (args.Length() != 3) { throwError(v8SyntaxError, "setDragImage: Invalid number of arguments", args.GetIsolate()); return; } int x = toInt32(args[1]); int y = toInt32(args[2]); Node* node = 0; if (V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); if (!node || !node->isElementNode()) { throwTypeError("setDragImageFromElement: Invalid first argument", args.GetIsolate()); return; } if (toElement(node)->hasTagName(HTMLNames::imgTag) && !node->inDocument()) clipboard->setDragImage(toHTMLImageElement(node)->cachedImage(), IntPoint(x, y)); else clipboard->setDragImageElement(node, IntPoint(x, y)); }
JSValue JSClipboard::setDragImage(ExecState* exec) { Clipboard* clipboard = impl(); if (!clipboard->isForDragAndDrop()) return jsUndefined(); // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. if (exec->argumentCount() != 3) return throwError(exec, createSyntaxError(exec, "setDragImage: Invalid number of arguments")); int x = exec->argument(1).toInt32(exec); int y = exec->argument(2).toInt32(exec); // See if they passed us a node Node* node = toNode(exec->argument(0)); if (!node) return throwTypeError(exec); // FIXME: This should probably be a TypeError. if (!node->isElementNode()) return throwError(exec, createSyntaxError(exec, "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(); }