From 5f1a9d6550ce157cc9559c3e3ee6e091c5701189 Mon Sep 17 00:00:00 2001 From: Tristan Dunn Date: Mon, 13 Feb 2012 22:09:18 -0600 Subject: [PATCH] Merge in upstream changes. --- src/Connection.cpp | 20 +++++++++++++++++++- src/Connection.h | 3 +++ src/webkit_server.js | 38 +++++++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/Connection.cpp b/src/Connection.cpp index 98a4047..d3fad6c 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -17,6 +17,8 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) : m_command = NULL; m_pageSuccess = true; m_commandWaiting = false; + m_pageLoadingFromCommand = false; + m_pendingResponse = NULL; connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext())); connect(m_commandParser, SIGNAL(commandReady(QString, QStringList)), this, SLOT(commandReady(QString, QStringList))); connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); @@ -38,6 +40,7 @@ void Connection::startCommand() { if (m_pageSuccess) { m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData()); if (m_command) { + connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand())); connect(m_command, SIGNAL(finished(Response *)), this, @@ -55,16 +58,31 @@ void Connection::startCommand() { } } +void Connection::pageLoadingFromCommand() { + m_pageLoadingFromCommand = true; +} + void Connection::pendingLoadFinished(bool success) { m_pageSuccess = success; if (m_commandWaiting) startCommand(); + if (m_pageLoadingFromCommand) { + m_pageLoadingFromCommand = false; + if (m_pendingResponse) { + writeResponse(m_pendingResponse); + m_pendingResponse = NULL; + } + } } void Connection::finishCommand(Response *response) { + disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand())); m_command->deleteLater(); m_command = NULL; - writeResponse(response); + if (m_pageLoadingFromCommand) + m_pendingResponse = response; + else + writeResponse(response); } void Connection::writeResponse(Response *response) { diff --git a/src/Connection.h b/src/Connection.h index b39d355..e6682e0 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -18,6 +18,7 @@ class Connection : public QObject { void commandReady(QString commandName, QStringList arguments); void finishCommand(Response *response); void pendingLoadFinished(bool success); + void pageLoadingFromCommand(); private: void startCommand(); @@ -32,5 +33,7 @@ class Connection : public QObject { CommandFactory *m_commandFactory; bool m_pageSuccess; bool m_commandWaiting; + bool m_pageLoadingFromCommand; + Response *m_pendingResponse; }; diff --git a/src/webkit_server.js b/src/webkit_server.js index a8f5acc..08b220d 100644 --- a/src/webkit_server.js +++ b/src/webkit_server.js @@ -53,7 +53,26 @@ window.WebKitServer = { return this.nodes[index].tagName.toLowerCase(); }, + submit: function(index) { + return this.nodes[index].submit(); + }, + + mousedown: function(index) { + var mousedownEvent = document.createEvent("MouseEvents"); + mousedownEvent.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + this.nodes[index].dispatchEvent(mousedownEvent); + }, + + mouseup: function(index) { + var mouseupEvent = document.createEvent("MouseEvents"); + mouseupEvent.initMouseEvent("mouseup", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + this.nodes[index].dispatchEvent(mouseupEvent); + }, + click: function(index) { + this.mousedown(index); + this.mouseup(index); + var clickEvent = document.createEvent("MouseEvents"); clickEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); this.nodes[index].dispatchEvent(clickEvent); @@ -128,31 +147,24 @@ window.WebKitServer = { this.trigger(index, "change"); this.trigger(index, "blur"); } else if (type === "checkbox" || type === "radio") { - node.checked = (value == "true"); - - this.trigger(index, "click"); - this.trigger(index, "change"); + if (node.checked != (value === "true")) { + this.click(index); + } } else if (type === "file") { this.lastAttachedFile = value; - this.trigger(index, "click"); + this.click(index); } else { node.value = value; } }, selectOption: function(index) { - var node = this.nodes[index]; - - node.selected = true; - node.setAttribute("selected", "selected"); + this.nodes[index].selected = true; this.trigger(index, "change"); }, unselectOption: function(index) { - var node = this.nodes[index]; - - node.selected = false; - node.removeAttribute("selected"); + this.nodes[index].selected = false; this.trigger(index, "change"); },