1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Move window change handling into WebPageManager

This commit is contained in:
Matthew Horan 2012-04-04 15:40:18 -04:00
parent baf21c99ef
commit bfbda84141
8 changed files with 26 additions and 17 deletions

View file

@ -16,7 +16,6 @@ class Command : public QObject {
signals:
void finished(Response *response);
void windowChanged(WebPage *);
protected:
WebPage *page();

View file

@ -19,7 +19,7 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
m_commandWaiting = false;
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *)));
connect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
void Connection::commandReady(Command *command) {
@ -35,7 +35,6 @@ void Connection::startCommand() {
if (m_pageSuccess) {
m_runningCommand = new PageLoadingCommand(m_queuedCommand, currentPage(), this);
connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
connect(m_queuedCommand, SIGNAL(windowChanged(WebPage *)), this, SLOT(changeWindow(WebPage *)));
m_runningCommand->start();
} else {
writePageLoadFailure();
@ -72,12 +71,6 @@ void Connection::writeResponse(Response *response) {
delete response;
}
void Connection::changeWindow(WebPage *page) {
disconnect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
m_manager->setCurrentPage(page);
connect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
WebPage *Connection::currentPage() {
return m_manager->currentPage();
}

View file

@ -20,7 +20,6 @@ class Connection : public QObject {
void commandReady(Command *command);
void finishCommand(Response *response);
void pendingLoadFinished(bool success);
void changeWindow(WebPage *);
private:
void startCommand();

View file

@ -19,5 +19,5 @@ quint16 Server::server_port() const {
void Server::handleConnection() {
QTcpSocket *socket = m_tcp_server->nextPendingConnection();
new Connection(socket, new WebPageManager(), this);
new Connection(socket, new WebPageManager(this), this);
}

View file

@ -10,6 +10,8 @@
#include <QUuid>
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
m_manager = manager;
setForwardUnsupportedContent(true);
loadJavascript();
setUserStylesheet();
@ -24,13 +26,13 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
this, SLOT(frameCreated(QWebFrame *)));
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
connect(this, SIGNAL(pageFinished(bool)),
m_manager, SLOT(emitPageFinished(bool)));
resetWindowSize();
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
m_uuid = QUuid::createUuid().toString();
m_manager = manager;
}
void WebPage::resetWindowSize() {

View file

@ -2,7 +2,9 @@
#include "WebPage.h"
#include <stdio.h>
WebPageManager::WebPageManager() {
WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
m_currentPage = NULL;
m_ignoreSslErrors = false;
}
void WebPageManager::append(WebPage *value) {
@ -26,3 +28,8 @@ WebPage *WebPageManager::createPage(QObject *parent) {
append(page);
return page;
}
void WebPageManager::emitPageFinished(bool success) {
if (currentPage() == sender())
emit pageFinished(success);
}

View file

@ -5,18 +5,27 @@
class WebPage;
class WebPageManager {
class WebPageManager : public QObject {
Q_OBJECT
public:
WebPageManager();
WebPageManager(QObject *parent = 0);
void append(WebPage *value);
QListIterator<WebPage *> iterator();
void setCurrentPage(WebPage *);
WebPage *currentPage();
WebPage *createPage(QObject *);
public slots:
void emitPageFinished(bool);
signals:
void pageFinished(bool);
private:
QList<WebPage *> m_pages;
WebPage *m_currentPage;
bool m_ignoreSslErrors;
};
#endif // _WEBPAGEMANAGER_H

View file

@ -16,7 +16,7 @@ void WindowFocus::windowNotFound() {
}
void WindowFocus::success(WebPage *page) {
emit windowChanged(page);
((CommandFactory *) parent())->m_manager->setCurrentPage(page);
emit finished(new Response(true));
}