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"
|
||||
printArgs.apply this, arguments_
|
||||
|
||||
page.onRepaintRequested = ->
|
||||
console.log "page.onRepaintRequested"
|
||||
printArgs.apply this, arguments_
|
||||
|
||||
if logResources is true
|
||||
page.onResourceRequested = ->
|
||||
console.log "page.onResourceRequested"
|
||||
|
|
|
@ -59,6 +59,10 @@ page.onNavigationRequested = function() {
|
|||
console.log("page.onNavigationRequested");
|
||||
printArgs.apply(this, arguments);
|
||||
};
|
||||
page.onRepaintRequested = function() {
|
||||
console.log("page.onRepaintRequested");
|
||||
printArgs.apply(this, arguments);
|
||||
};
|
||||
|
||||
if (logResources === true) {
|
||||
page.onResourceRequested = function() {
|
||||
|
|
|
@ -248,6 +248,8 @@ function decorateNewPage(opts, page) {
|
|||
|
||||
definePageSignalHandler(page, handlers, "onNavigationRequested", "navigationRequested");
|
||||
|
||||
definePageSignalHandler(page, handlers, "onRepaintRequested", "repaintRequested");
|
||||
|
||||
definePageSignalHandler(page, handlers, "onResourceRequested", "resourceRequested");
|
||||
|
||||
definePageSignalHandler(page, handlers, "onResourceReceived", "resourceReceived");
|
||||
|
|
|
@ -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(windowCloseRequested()), this, SLOT(close()), Qt::QueuedConnection);
|
||||
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.
|
||||
QPalette palette = m_customWebPage->palette();
|
||||
|
@ -1617,6 +1619,12 @@ void WebPage::updateLoadingProgress(int progress)
|
|||
m_loadingProgress = progress;
|
||||
}
|
||||
|
||||
void WebPage::handleRepaintRequested(const QRect &dirtyRect)
|
||||
{
|
||||
emit repaintRequested(dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height());
|
||||
}
|
||||
|
||||
|
||||
void WebPage::stopJavaScript()
|
||||
{
|
||||
m_shouldInterruptJs = true;
|
||||
|
|
|
@ -477,11 +477,13 @@ signals:
|
|||
void navigationRequested(const QUrl &url, const QString &navigationType, bool navigationLocked, bool isMainFrame);
|
||||
void rawPageCreated(QObject *page);
|
||||
void closing(QObject *page);
|
||||
void repaintRequested(const int x, const int y, const int width, const int height);
|
||||
|
||||
private slots:
|
||||
void finish(bool ok);
|
||||
void setupFrame(QWebFrame *frame = NULL);
|
||||
void updateLoadingProgress(int progress);
|
||||
void handleRepaintRequested(const QRect &dirtyRect);
|
||||
|
||||
private:
|
||||
QImage renderImage();
|
||||
|
|
|
@ -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() {
|
||||
var p = require("webpage").create();
|
||||
|
||||
|
|
Loading…
Reference in New Issue