mirror of https://github.com/vitalif/phantomjs
Added onRepaint callback to webpage API.
Enables subscription to RepaintRequested events. When the callback is invoked the time that the repaint was requested as well as the x,y and width,height of the repainted rectangle are provided as parameters. Usage: page.onRepaint = function(time, x, y, width, height) { } https://github.com/ariya/phantomjs/issues/117931.x
parent
9bfe22b428
commit
dca15d7ff6
|
@ -56,6 +56,10 @@ page.onNavigationRequested = ->
|
||||||
console.log "page.onNavigationRequested"
|
console.log "page.onNavigationRequested"
|
||||||
printArgs.apply this, arguments_
|
printArgs.apply this, arguments_
|
||||||
|
|
||||||
|
page.onRepaintRequested = ->
|
||||||
|
console.log "page.onRepaintRequested"
|
||||||
|
printArgs.apply this, arguments_
|
||||||
|
|
||||||
if logResources is true
|
if logResources is true
|
||||||
page.onResourceRequested = ->
|
page.onResourceRequested = ->
|
||||||
console.log "page.onResourceRequested"
|
console.log "page.onResourceRequested"
|
||||||
|
@ -129,4 +133,4 @@ setTimeout (->
|
||||||
setTimeout (->
|
setTimeout (->
|
||||||
phantom.exit()
|
phantom.exit()
|
||||||
), 100
|
), 100
|
||||||
), 20000
|
), 20000
|
||||||
|
|
|
@ -59,6 +59,10 @@ page.onNavigationRequested = function() {
|
||||||
console.log("page.onNavigationRequested");
|
console.log("page.onNavigationRequested");
|
||||||
printArgs.apply(this, arguments);
|
printArgs.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
page.onRepaintRequested = function() {
|
||||||
|
console.log("page.onRepaintRequested");
|
||||||
|
printArgs.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
if (logResources === true) {
|
if (logResources === true) {
|
||||||
page.onResourceRequested = function() {
|
page.onResourceRequested = function() {
|
||||||
|
|
|
@ -110,7 +110,7 @@ function definePageSignalHandler(page, handlers, handlerName, signalName) {
|
||||||
this[signalName].connect(f);
|
this[signalName].connect(f);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
page.__defineGetter__(handlerName, function() {
|
page.__defineGetter__(handlerName, function() {
|
||||||
return !!handlers[handlerName] && typeof handlers[handlerName].callback === "function" ?
|
return !!handlers[handlerName] && typeof handlers[handlerName].callback === "function" ?
|
||||||
handlers[handlerName].callback :
|
handlers[handlerName].callback :
|
||||||
|
@ -142,7 +142,7 @@ function definePageCallbackHandler(page, handlers, handlerName, callbackConstruc
|
||||||
// Callback will receive a "deserialized", normal "arguments" array
|
// Callback will receive a "deserialized", normal "arguments" array
|
||||||
callbackObj.returnValue = f.apply(this, arguments[0]);
|
callbackObj.returnValue = f.apply(this, arguments[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store the new handler for reference
|
// Store the new handler for reference
|
||||||
handlers[handlerName] = {
|
handlers[handlerName] = {
|
||||||
callback: f,
|
callback: f,
|
||||||
|
@ -153,7 +153,7 @@ function definePageCallbackHandler(page, handlers, handlerName, callbackConstruc
|
||||||
callbackObj.called.connect(connector);
|
callbackObj.called.connect(connector);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
page.__defineGetter__(handlerName, function() {
|
page.__defineGetter__(handlerName, function() {
|
||||||
var handlerObj = handlers[handlerName];
|
var handlerObj = handlers[handlerName];
|
||||||
return (!!handlerObj && typeof handlerObj.callback === "function" && typeof handlerObj.connector === "function") ?
|
return (!!handlerObj && typeof handlerObj.callback === "function" && typeof handlerObj.connector === "function") ?
|
||||||
|
@ -248,10 +248,12 @@ function decorateNewPage(opts, page) {
|
||||||
|
|
||||||
definePageSignalHandler(page, handlers, "onNavigationRequested", "navigationRequested");
|
definePageSignalHandler(page, handlers, "onNavigationRequested", "navigationRequested");
|
||||||
|
|
||||||
|
definePageSignalHandler(page, handlers, "onRepaintRequested", "repaintRequested");
|
||||||
|
|
||||||
definePageSignalHandler(page, handlers, "onResourceRequested", "resourceRequested");
|
definePageSignalHandler(page, handlers, "onResourceRequested", "resourceRequested");
|
||||||
|
|
||||||
definePageSignalHandler(page, handlers, "onResourceReceived", "resourceReceived");
|
definePageSignalHandler(page, handlers, "onResourceReceived", "resourceReceived");
|
||||||
|
|
||||||
definePageSignalHandler(page, handlers, "onResourceError", "resourceError");
|
definePageSignalHandler(page, handlers, "onResourceError", "resourceError");
|
||||||
|
|
||||||
definePageSignalHandler(page, handlers, "onResourceTimeout", "resourceTimeout");
|
definePageSignalHandler(page, handlers, "onResourceTimeout", "resourceTimeout");
|
||||||
|
|
|
@ -198,7 +198,7 @@ protected:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bool isNavigationLocked = m_webPage->navigationLocked();
|
bool isNavigationLocked = m_webPage->navigationLocked();
|
||||||
|
|
||||||
emit m_webPage->navigationRequested(
|
emit m_webPage->navigationRequested(
|
||||||
request.url(), //< Requested URL
|
request.url(), //< Requested URL
|
||||||
navigationType, //< Navigation Type
|
navigationType, //< Navigation Type
|
||||||
|
@ -295,7 +295,7 @@ public:
|
||||||
}
|
}
|
||||||
return m_jsPromptCallback;
|
return m_jsPromptCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *getJsInterruptCallback() {
|
QObject *getJsInterruptCallback() {
|
||||||
qDebug() << "WebpageCallbacks - getJsInterruptCallback";
|
qDebug() << "WebpageCallbacks - getJsInterruptCallback";
|
||||||
|
|
||||||
|
@ -363,6 +363,8 @@ WebPage::WebPage(QObject *parent, const QUrl &baseUrl)
|
||||||
connect(m_customWebPage, SIGNAL(loadFinished(bool)), SLOT(finish(bool)), Qt::QueuedConnection);
|
connect(m_customWebPage, SIGNAL(loadFinished(bool)), SLOT(finish(bool)), Qt::QueuedConnection);
|
||||||
connect(m_customWebPage, SIGNAL(windowCloseRequested()), this, SLOT(close()), Qt::QueuedConnection);
|
connect(m_customWebPage, SIGNAL(windowCloseRequested()), this, SLOT(close()), Qt::QueuedConnection);
|
||||||
connect(m_customWebPage, SIGNAL(loadProgress(int)), this, SLOT(updateLoadingProgress(int)));
|
connect(m_customWebPage, SIGNAL(loadProgress(int)), this, SLOT(updateLoadingProgress(int)));
|
||||||
|
connect(m_customWebPage, SIGNAL(repaintRequested(QRect)), this, SLOT(handleRepaintRequested(QRect)), Qt::QueuedConnection);
|
||||||
|
|
||||||
|
|
||||||
// Start with transparent background.
|
// Start with transparent background.
|
||||||
QPalette palette = m_customWebPage->palette();
|
QPalette palette = m_customWebPage->palette();
|
||||||
|
@ -939,12 +941,12 @@ bool WebPage::render(const QString &fileName, const QVariantMap &option)
|
||||||
}
|
}
|
||||||
|
|
||||||
if( tempFileName != "" ){
|
if( tempFileName != "" ){
|
||||||
// cleanup temporary file and render to stdout or stderr
|
// cleanup temporary file and render to stdout or stderr
|
||||||
QFile i(tempFileName);
|
QFile i(tempFileName);
|
||||||
i.open(QIODevice::ReadOnly);
|
i.open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
QByteArray ba = i.readAll();
|
QByteArray ba = i.readAll();
|
||||||
|
|
||||||
System *system = (System*)Phantom::instance()->createSystem();
|
System *system = (System*)Phantom::instance()->createSystem();
|
||||||
if( fileName == STDOUT_FILENAME ){
|
if( fileName == STDOUT_FILENAME ){
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
|
@ -955,7 +957,7 @@ bool WebPage::render(const QString &fileName, const QVariantMap &option)
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
_setmode(_fileno(stdout), O_TEXT);
|
_setmode(_fileno(stdout), O_TEXT);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if( fileName == STDERR_FILENAME ){
|
else if( fileName == STDERR_FILENAME ){
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
|
@ -966,7 +968,7 @@ bool WebPage::render(const QString &fileName, const QVariantMap &option)
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
_setmode(_fileno(stderr), O_TEXT);
|
_setmode(_fileno(stderr), O_TEXT);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
i.close();
|
i.close();
|
||||||
|
@ -1617,6 +1619,12 @@ void WebPage::updateLoadingProgress(int progress)
|
||||||
m_loadingProgress = progress;
|
m_loadingProgress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebPage::handleRepaintRequested(const QRect &dirtyRect)
|
||||||
|
{
|
||||||
|
emit repaintRequested(dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebPage::stopJavaScript()
|
void WebPage::stopJavaScript()
|
||||||
{
|
{
|
||||||
m_shouldInterruptJs = true;
|
m_shouldInterruptJs = true;
|
||||||
|
|
|
@ -477,11 +477,13 @@ signals:
|
||||||
void navigationRequested(const QUrl &url, const QString &navigationType, bool navigationLocked, bool isMainFrame);
|
void navigationRequested(const QUrl &url, const QString &navigationType, bool navigationLocked, bool isMainFrame);
|
||||||
void rawPageCreated(QObject *page);
|
void rawPageCreated(QObject *page);
|
||||||
void closing(QObject *page);
|
void closing(QObject *page);
|
||||||
|
void repaintRequested(const int x, const int y, const int width, const int height);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void finish(bool ok);
|
void finish(bool ok);
|
||||||
void setupFrame(QWebFrame *frame = NULL);
|
void setupFrame(QWebFrame *frame = NULL);
|
||||||
void updateLoadingProgress(int progress);
|
void updateLoadingProgress(int progress);
|
||||||
|
void handleRepaintRequested(const QRect &dirtyRect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage renderImage();
|
QImage renderImage();
|
||||||
|
|
|
@ -1394,11 +1394,11 @@ describe("WebPage object", function() {
|
||||||
|
|
||||||
it("should interrupt a long-running JavaScript code", function() {
|
it("should interrupt a long-running JavaScript code", function() {
|
||||||
var page = new WebPage();
|
var page = new WebPage();
|
||||||
|
|
||||||
page.onLongRunningScript = function() {
|
page.onLongRunningScript = function() {
|
||||||
page.stopJavaScript();
|
page.stopJavaScript();
|
||||||
};
|
};
|
||||||
|
|
||||||
page.open('../test/webpage-spec-frames/forever.html', function(status) {
|
page.open('../test/webpage-spec-frames/forever.html', function(status) {
|
||||||
expect(status).toEqual('success');
|
expect(status).toEqual('success');
|
||||||
});
|
});
|
||||||
|
@ -2025,6 +2025,29 @@ describe('WebPage navigation events', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('WebPage repaint requests', function() {
|
||||||
|
it('should report when a repaint is requested, together with the area being repainted', function () {
|
||||||
|
var page = require("webpage").create();
|
||||||
|
var base = "https://github.com";
|
||||||
|
var isHandled = false;
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
page.onRepaintRequested = function(x, y, width, height) {
|
||||||
|
isHandled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
page.open(base);
|
||||||
|
});
|
||||||
|
|
||||||
|
waits(3000);
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
expect(isHandled).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("WebPage loading/loadingProgress properties", function() {
|
describe("WebPage loading/loadingProgress properties", function() {
|
||||||
var p = require("webpage").create();
|
var p = require("webpage").create();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue