Added ability to implement platform-dependent zoom controller for IV.

This commit is contained in:
23rd 2024-10-28 15:28:41 +03:00
parent b7ef5325ac
commit c076daa91f
3 changed files with 30 additions and 4 deletions

View file

@ -1583,8 +1583,13 @@ rpl::producer<int> Settings::ivZoomValue() const {
return _ivZoom.value();
}
void Settings::setIvZoom(int value) {
#ifdef Q_OS_WIN
constexpr auto kMin = 25;
constexpr auto kMax = 500;
#else
constexpr auto kMin = 30;
constexpr auto kMax = 200;
#endif
_ivZoom = std::clamp(value, kMin, kMax);
}

View file

@ -369,10 +369,16 @@ Controller::Controller(
Fn<ShareBoxResult(ShareBoxDescriptor)> showShareBox)
: _delegate(delegate)
, _updateStyles([=] {
const auto zoom = _delegate->ivZoom();
const auto str = Ui::EscapeForScriptString(ComputeStyles(zoom));
if (_webview) {
const auto webviewZoomController = _webview->zoomController();
const auto styleZoom = webviewZoomController
? kDefaultZoom
: _delegate->ivZoom();
const auto str = Ui::EscapeForScriptString(ComputeStyles(styleZoom));
_webview->eval("IV.updateStyles('" + str + "');");
if (webviewZoomController) {
webviewZoomController->setZoom(_delegate->ivZoom());
}
}
})
, _showShareBox(std::move(showShareBox)) {
@ -634,6 +640,17 @@ void Controller::createWebview(const Webview::StorageId &storageId) {
});
const auto raw = _webview.get();
if (const auto webviewZoomController = raw->zoomController()) {
webviewZoomController->zoomValue(
) | rpl::start_with_next([this](int value) {
_delegate->ivSetZoom(value);
}, lifetime());
_delegate->ivZoomValue(
) | rpl::start_with_next([=, this](int value) {
webviewZoomController->setZoom(value);
}, lifetime());
}
window->lifetime().add([=] {
_ready = false;
base::take(_webview);
@ -785,8 +802,12 @@ void Controller::createWebview(const Webview::StorageId &storageId) {
|| index >= _pages.size()) {
return Webview::DataResult::Failed;
}
const auto webviewZoomController = _webview->zoomController();
const auto styleZoom = webviewZoomController
? kDefaultZoom
: _delegate->ivZoom();
return finishWith(
WrapPage(_pages[index], _delegate->ivZoom()),
WrapPage(_pages[index], styleZoom),
"text/html; charset=utf-8");
} else if (id.starts_with("page") && id.ends_with(".json")) {
auto index = 0;

@ -1 +1 @@
Subproject commit e9e85a10e6864e18ffd540df04d7965d0af39500
Subproject commit d5337d58ebe39cffe421c7ce7725d2bfe9d03159