Build an HTML5 DragEvent to pass in to the page, to determine whether it will handle a drag-and-drop operation. The limitation is that the body of the page (rather than one of its children) must respond to the drag events. See http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dnd Returns true if the event was canceled, meaning the operation was accepted. Note: If the page is sti
| 354 | // Note: If the page is still loading, this will return false but the event will |
| 355 | // be injected when the load completes. |
| 356 | bool JavaScriptAPI::injectDragAndDropEvent( QString eventName ) |
| 357 | { |
| 358 | // Here we construct a fake DragEvent and inject it into the DOM. |
| 359 | // We try to make it look as much as possible like a true DragEvent. |
| 360 | // We can't actually construct a DragEvent though, because it's not supported |
| 361 | // in the version of QtWebKit that we're using. |
| 362 | QString jsCode = QString( |
| 363 | "(function () {" |
| 364 | " var evt = document.createEvent('UIEvents');" |
| 365 | " evt.initUIEvent('%1', true, true, window, null);" |
| 366 | " evt.screenX = evt.screenY = evt.clientX = evt.clientY = 0;" |
| 367 | " evt.ctrlKey = evt.shiftKey = evt.altKey = evt.metaKey = false;" |
| 368 | " evt.button = 0;" |
| 369 | " evt.relatedTarget = null;" |
| 370 | " evt.dataTransfer = { types: ['Files'], files: [%2] };" |
| 371 | " var canceled = !document.getElementsByTagName('body').item(0).dispatchEvent(evt);" |
| 372 | " return canceled;" |
| 373 | "}());").arg(eventName).arg(_dragAndDropData); |
| 374 | |
| 375 | if(_page->isLoaded()) { |
| 376 | return _page->evaluateJavaScript(jsCode).toBool(); |
| 377 | } else { |
| 378 | _page->addExecuteCode(jsCode); |
| 379 | return false; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // Return true if the page supports having the given items dropped on it. |
| 384 | // We use a simplified version of the HTML5 drag and drop API here. |
nothing calls this directly
no test coverage detected