2011-04-19 03:16:25 -04:00
|
|
|
#include "FrameFocus.h"
|
2012-07-08 15:04:30 -04:00
|
|
|
#include "SocketCommand.h"
|
2011-04-19 03:16:25 -04:00
|
|
|
#include "WebPage.h"
|
2012-04-04 18:18:17 -04:00
|
|
|
#include "WebPageManager.h"
|
2011-04-19 03:16:25 -04:00
|
|
|
|
2012-07-08 15:04:30 -04:00
|
|
|
FrameFocus::FrameFocus(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
|
2011-04-19 03:16:25 -04:00
|
|
|
}
|
|
|
|
|
2012-03-16 19:58:58 -04:00
|
|
|
void FrameFocus::start() {
|
2011-04-20 19:02:20 -04:00
|
|
|
findFrames();
|
2012-03-16 19:58:58 -04:00
|
|
|
switch(arguments().length()) {
|
2011-04-20 19:02:20 -04:00
|
|
|
case 1:
|
2012-03-16 19:58:58 -04:00
|
|
|
focusId(arguments()[0]);
|
2011-04-20 19:02:20 -04:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-03-16 19:58:58 -04:00
|
|
|
focusIndex(arguments()[1].toInt());
|
2011-04-20 19:02:20 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
focusParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameFocus::findFrames() {
|
|
|
|
frames = page()->currentFrame()->childFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameFocus::focusIndex(int index) {
|
|
|
|
if (isFrameAtIndex(index)) {
|
|
|
|
frames[index]->setFocus();
|
|
|
|
success();
|
2011-04-20 01:42:20 -04:00
|
|
|
} else {
|
2011-04-20 19:02:20 -04:00
|
|
|
frameNotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameFocus::isFrameAtIndex(int index) {
|
|
|
|
return 0 <= index && index < frames.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameFocus::focusId(QString name) {
|
|
|
|
for (int i = 0; i < frames.length(); i++) {
|
|
|
|
if (frames[i]->frameName().compare(name) == 0) {
|
|
|
|
frames[i]->setFocus();
|
|
|
|
success();
|
|
|
|
return;
|
2011-04-20 01:42:20 -04:00
|
|
|
}
|
|
|
|
}
|
2011-04-20 19:02:20 -04:00
|
|
|
|
|
|
|
frameNotFound();
|
2011-04-19 03:16:25 -04:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:02:20 -04:00
|
|
|
void FrameFocus::focusParent() {
|
|
|
|
if (page()->currentFrame()->parentFrame() == 0) {
|
2012-12-12 01:47:54 -05:00
|
|
|
emitFinished(false, QString("Already at parent frame."));
|
2011-04-20 19:02:20 -04:00
|
|
|
} else {
|
|
|
|
page()->currentFrame()->parentFrame()->setFocus();
|
|
|
|
success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameFocus::frameNotFound() {
|
2012-12-12 01:47:54 -05:00
|
|
|
emitFinished(false, QString("Unable to locate frame. "));
|
2011-04-20 19:02:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameFocus::success() {
|
2012-12-12 01:47:54 -05:00
|
|
|
emitFinished(true);
|
2011-04-20 19:02:20 -04:00
|
|
|
}
|