1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

WebScrollBarManager: Correctly update visibility with javascript

Closes #2182
This commit is contained in:
David Rosca 2017-01-26 17:14:18 +01:00
parent f7005f8d95
commit 7096d3eb88
2 changed files with 20 additions and 4 deletions

View File

@ -64,8 +64,6 @@ void WebScrollBar::updateValues(const QSize &viewport)
setValue(newValue); setValue(newValue);
m_blockScrolling = false; m_blockScrolling = false;
} }
setVisible(maximum() > minimum());
} }
void WebScrollBar::performScroll() void WebScrollBar::performScroll()

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - Qt web browser * QupZilla - Qt web browser
* Copyright (C) 2016 David Rosca <nowrep@gmail.com> * Copyright (C) 2016-2017 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -24,6 +24,7 @@
#include "scripts.h" #include "scripts.h"
#include "settings.h" #include "settings.h"
#include <QPointer>
#include <QPaintEvent> #include <QPaintEvent>
#include <QWebEngineProfile> #include <QWebEngineProfile>
#include <QWebEngineScriptCollection> #include <QWebEngineScriptCollection>
@ -127,9 +128,26 @@ void WebScrollBarManager::addWebView(WebView *view)
}; };
connect(view, &WebView::viewportResized, this, updateValues); connect(view, &WebView::viewportResized, this, updateValues);
connect(view->page(), &WebPage::contentsSizeChanged, this, updateValues);
connect(view->page(), &WebPage::scrollPositionChanged, this, updateValues); connect(view->page(), &WebPage::scrollPositionChanged, this, updateValues);
connect(view->page(), &WebPage::contentsSizeChanged, this, [=]() {
const QString source = QL1S("var out = {"
"vertical: window.innerWidth > document.documentElement.clientWidth,"
"horizontal: window.innerHeight > document.documentElement.clientHeight"
"};out;");
QPointer<WebView> p(view);
view->page()->runJavaScript(source, WebPage::SafeJsWorld, [=](const QVariant &res) {
if (!p) {
return;
}
updateValues();
const QVariantMap map = res.toMap();
data->vscrollbar->setVisible(map.value(QSL("vertical")).toBool());
data->hscrollbar->setVisible(map.value(QSL("horizontal")).toBool());
});
});
connect(view, &WebView::zoomLevelChanged, this, [=]() { connect(view, &WebView::zoomLevelChanged, this, [=]() {
view->page()->runJavaScript(m_scrollbarJs.arg(thickness)); view->page()->runJavaScript(m_scrollbarJs.arg(thickness));
}); });