Fix geometry applying in webview windows.

This commit is contained in:
John Preston 2024-05-20 13:34:05 +04:00
parent 6734f99ba8
commit 2bdc204c47
4 changed files with 43 additions and 30 deletions

View file

@ -534,12 +534,15 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
const auto bottom = _webviewBottom.get();
bottom->show();
bottom->heightValue(
) | rpl::start_with_next([=](int height) {
const auto inner = _widget->innerGeometry();
rpl::combine(
container->geometryValue() | rpl::map([=] {
return _widget->innerGeometry();
}),
bottom->heightValue()
) | rpl::start_with_next([=](QRect inner, int height) {
bottom->move(inner.x(), inner.y() + inner.height() - height);
container->resize(inner.width(), inner.height() - height);
bottom->resizeToWidth(inner.width());
_footerHeight = bottom->height();
}, bottom->lifetime());
container->show();
@ -584,10 +587,12 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
});
});
container->geometryValue(
) | rpl::start_with_next([=](QRect geometry) {
if (raw->widget()) {
raw->widget()->setGeometry(geometry);
rpl::combine(
container->geometryValue(),
_footerHeight.value()
) | rpl::start_with_next([=](QRect geometry, int footer) {
if (const auto view = raw->widget()) {
view->setGeometry(geometry.marginsRemoved({ 0, 0, 0, footer }));
}
}, _webview->lifetime);

View file

@ -115,11 +115,13 @@ private:
[[nodiscard]] bool progressWithBackground() const;
[[nodiscard]] QRect progressRect() const;
void setupProgressGeometry();
void updateFooterHeight();
const not_null<PanelDelegate*> _delegate;
std::unique_ptr<SeparatePanel> _widget;
std::unique_ptr<WebviewWithLifetime> _webview;
std::unique_ptr<RpWidget> _webviewBottom;
rpl::variable<int> _footerHeight;
std::unique_ptr<Progress> _progress;
QPointer<Checkbox> _saveWebviewInformation;
QPointer<FormSummary> _weakFormSummary;

View file

@ -570,17 +570,15 @@ void Panel::createWebviewBottom() {
label->show();
_webviewBottom->resize(_webviewBottom->width(), height);
bottom->heightValue(
) | rpl::start_with_next([=](int height) {
const auto inner = _widget->innerGeometry();
if (_mainButton && !_mainButton->isHidden()) {
height = _mainButton->height();
}
rpl::combine(
_webviewParent->geometryValue() | rpl::map([=] {
return _widget->innerGeometry();
}),
bottom->heightValue()
) | rpl::start_with_next([=](QRect inner, int height) {
bottom->move(inner.x(), inner.y() + inner.height() - height);
if (const auto container = _webviewParent.data()) {
container->setFixedSize(inner.width(), inner.height() - height);
}
bottom->resizeToWidth(inner.width());
updateFooterHeight();
}, bottom->lifetime());
}
@ -636,10 +634,13 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
});
});
container->geometryValue(
) | rpl::start_with_next([=](QRect geometry) {
if (raw->widget()) {
raw->widget()->setGeometry(geometry);
updateFooterHeight();
rpl::combine(
container->geometryValue(),
_footerHeight.value()
) | rpl::start_with_next([=](QRect geometry, int footer) {
if (const auto view = raw->widget()) {
view->setGeometry(geometry.marginsRemoved({ 0, 0, 0, footer }));
}
}, _webview->lifetime);
@ -1185,22 +1186,25 @@ void Panel::createMainButton() {
button->hide();
rpl::combine(
_webviewParent->geometryValue() | rpl::map([=] {
return _widget->innerGeometry();
}),
button->shownValue(),
button->heightValue()
) | rpl::start_with_next([=](bool shown, int height) {
const auto inner = _widget->innerGeometry();
if (!shown) {
height = _webviewBottom->height();
}
) | rpl::start_with_next([=](QRect inner, bool shown, int height) {
button->move(inner.x(), inner.y() + inner.height() - height);
if (const auto raw = _webviewParent.data()) {
raw->setFixedSize(inner.width(), inner.height() - height);
}
button->resizeToWidth(inner.width());
_webviewBottom->setVisible(!shown);
updateFooterHeight();
}, button->lifetime());
}
void Panel::updateFooterHeight() {
_footerHeight = (_mainButton && !_mainButton->isHidden())
? _mainButton->height()
: _webviewBottom->height();
}
void Panel::showBox(object_ptr<BoxContent> box) {
if (const auto widget = _webview ? _webview->window.widget() : nullptr) {
const auto hideNow = !widget->isHidden();

View file

@ -143,6 +143,7 @@ private:
[[nodiscard]] bool progressWithBackground() const;
[[nodiscard]] QRect progressRect() const;
void setupProgressGeometry();
void updateFooterHeight();
Webview::StorageId _storageId;
const not_null<Delegate*> _delegate;
@ -153,9 +154,10 @@ private:
std::unique_ptr<WebviewWithLifetime> _webview;
std::unique_ptr<RpWidget> _webviewBottom;
rpl::variable<QString> _bottomText;
QPointer<QWidget> _webviewParent;
QPointer<RpWidget> _webviewParent;
std::unique_ptr<Button> _mainButton;
mutable crl::time _mainButtonLastClick = 0;
rpl::variable<int> _footerHeight = 0;
std::unique_ptr<Progress> _progress;
rpl::event_stream<> _themeUpdateForced;
rpl::lifetime _headerColorLifetime;