Skip to content

Commit

Permalink
Merge in upstream changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Feb 14, 2012
1 parent 3baf732 commit 5f1a9d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/Connection.cpp
Expand Up @@ -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)));
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/Connection.h
Expand Up @@ -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();
Expand All @@ -32,5 +33,7 @@ class Connection : public QObject {
CommandFactory *m_commandFactory;
bool m_pageSuccess;
bool m_commandWaiting;
bool m_pageLoadingFromCommand;
Response *m_pendingResponse;
};

38 changes: 25 additions & 13 deletions src/webkit_server.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
},

Expand Down

0 comments on commit 5f1a9d6

Please sign in to comment.