Handle background / title colors in web-apps.
This commit is contained in:
parent
fbd8abc1c6
commit
229f7a2c15
|
@ -246,17 +246,6 @@ CheckoutProcess::CheckoutProcess(
|
||||||
showForm();
|
showForm();
|
||||||
_panel->toggleProgress(true);
|
_panel->toggleProgress(true);
|
||||||
|
|
||||||
style::PaletteChanged(
|
|
||||||
) | rpl::filter([=] {
|
|
||||||
return !_themeUpdateScheduled;
|
|
||||||
}) | rpl::start_with_next([=] {
|
|
||||||
_themeUpdateScheduled = true;
|
|
||||||
crl::on_main(this, [=] {
|
|
||||||
_themeUpdateScheduled = false;
|
|
||||||
_panel->updateThemeParams(Window::Theme::WebViewParams());
|
|
||||||
});
|
|
||||||
}, _panel->lifetime());
|
|
||||||
|
|
||||||
if (mode == Mode::Payment) {
|
if (mode == Mode::Payment) {
|
||||||
_session->api().cloudPassword().state(
|
_session->api().cloudPassword().state(
|
||||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||||
|
@ -846,4 +835,8 @@ QString CheckoutProcess::panelWebviewDataPath() {
|
||||||
return _session->domain().local().webviewDataPath();
|
return _session->domain().local().webviewDataPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Webview::ThemeParams CheckoutProcess::panelWebviewThemeParams() {
|
||||||
|
return Window::Theme::WebViewParams();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Payments
|
} // namespace Payments
|
||||||
|
|
|
@ -150,6 +150,7 @@ private:
|
||||||
QVariant panelClickHandlerContext() override;
|
QVariant panelClickHandlerContext() override;
|
||||||
|
|
||||||
QString panelWebviewDataPath() override;
|
QString panelWebviewDataPath() override;
|
||||||
|
Webview::ThemeParams panelWebviewThemeParams() override;
|
||||||
|
|
||||||
std::optional<QDate> panelOverrideExpireDateThreshold() override;
|
std::optional<QDate> panelOverrideExpireDateThreshold() override;
|
||||||
|
|
||||||
|
@ -163,7 +164,6 @@ private:
|
||||||
bool _sendFormPending = false;
|
bool _sendFormPending = false;
|
||||||
bool _sendFormFailed = false;
|
bool _sendFormFailed = false;
|
||||||
|
|
||||||
bool _themeUpdateScheduled = false;
|
|
||||||
rpl::lifetime _gettingPasswordState;
|
rpl::lifetime _gettingPasswordState;
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,17 @@ Panel::Panel(not_null<PanelDelegate*> delegate)
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
_delegate->panelCloseSure();
|
_delegate->panelCloseSure();
|
||||||
}, _widget->lifetime());
|
}, _widget->lifetime());
|
||||||
|
|
||||||
|
style::PaletteChanged(
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
return !_themeUpdateScheduled;
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
_themeUpdateScheduled = true;
|
||||||
|
crl::on_main(_widget.get(), [=] {
|
||||||
|
_themeUpdateScheduled = false;
|
||||||
|
updateThemeParams(_delegate->panelWebviewThemeParams());
|
||||||
|
});
|
||||||
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
Panel::~Panel() {
|
Panel::~Panel() {
|
||||||
|
@ -483,11 +494,13 @@ bool Panel::showWebview(
|
||||||
const QString &url,
|
const QString &url,
|
||||||
bool allowBack,
|
bool allowBack,
|
||||||
rpl::producer<QString> bottomText) {
|
rpl::producer<QString> bottomText) {
|
||||||
if (!_webview && !createWebview()) {
|
const auto params = _delegate->panelWebviewThemeParams();
|
||||||
|
if (!_webview && !createWebview(params)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
showWebviewProgress();
|
showWebviewProgress();
|
||||||
_widget->hideLayer(anim::type::instant);
|
_widget->hideLayer(anim::type::instant);
|
||||||
|
updateThemeParams(params);
|
||||||
_webview->window.navigate(url);
|
_webview->window.navigate(url);
|
||||||
_widget->setBackAllowed(allowBack);
|
_widget->setBackAllowed(allowBack);
|
||||||
if (bottomText) {
|
if (bottomText) {
|
||||||
|
@ -511,7 +524,7 @@ bool Panel::showWebview(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Panel::createWebview() {
|
bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
||||||
auto outer = base::make_unique_q<RpWidget>(_widget.get());
|
auto outer = base::make_unique_q<RpWidget>(_widget.get());
|
||||||
const auto container = outer.get();
|
const auto container = outer.get();
|
||||||
_widget->showInner(std::move(outer));
|
_widget->showInner(std::move(outer));
|
||||||
|
@ -532,8 +545,10 @@ bool Panel::createWebview() {
|
||||||
_webview = std::make_unique<WebviewWithLifetime>(
|
_webview = std::make_unique<WebviewWithLifetime>(
|
||||||
container,
|
container,
|
||||||
Webview::WindowConfig{
|
Webview::WindowConfig{
|
||||||
|
.opaqueBg = params.opaqueBg,
|
||||||
.userDataPath = _delegate->panelWebviewDataPath(),
|
.userDataPath = _delegate->panelWebviewDataPath(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto raw = &_webview->window;
|
const auto raw = &_webview->window;
|
||||||
QObject::connect(container, &QObject::destroyed, [=] {
|
QObject::connect(container, &QObject::destroyed, [=] {
|
||||||
if (_webview && &_webview->window == raw) {
|
if (_webview && &_webview->window == raw) {
|
||||||
|
@ -900,6 +915,7 @@ void Panel::updateThemeParams(const Webview::ThemeParams ¶ms) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_webview->window.updateTheme(
|
_webview->window.updateTheme(
|
||||||
|
params.opaqueBg,
|
||||||
params.scrollBg,
|
params.scrollBg,
|
||||||
params.scrollBgOver,
|
params.scrollBgOver,
|
||||||
params.scrollBarBg,
|
params.scrollBarBg,
|
||||||
|
|
|
@ -100,7 +100,7 @@ private:
|
||||||
struct Progress;
|
struct Progress;
|
||||||
struct WebviewWithLifetime;
|
struct WebviewWithLifetime;
|
||||||
|
|
||||||
bool createWebview();
|
bool createWebview(const Webview::ThemeParams ¶ms);
|
||||||
void showWebviewProgress();
|
void showWebviewProgress();
|
||||||
void hideWebviewProgress();
|
void hideWebviewProgress();
|
||||||
void showWebviewError(
|
void showWebviewError(
|
||||||
|
@ -123,6 +123,7 @@ private:
|
||||||
QPointer<EditInformation> _weakEditInformation;
|
QPointer<EditInformation> _weakEditInformation;
|
||||||
QPointer<EditCard> _weakEditCard;
|
QPointer<EditCard> _weakEditCard;
|
||||||
rpl::event_stream<QString> _savedMethodChosen;
|
rpl::event_stream<QString> _savedMethodChosen;
|
||||||
|
bool _themeUpdateScheduled = false;
|
||||||
bool _webviewProgress = false;
|
bool _webviewProgress = false;
|
||||||
bool _testMode = false;
|
bool _testMode = false;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,10 @@ namespace Ui {
|
||||||
class BoxContent;
|
class BoxContent;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Webview {
|
||||||
|
struct ThemeParams;
|
||||||
|
} // namespace Webview
|
||||||
|
|
||||||
namespace Payments::Ui {
|
namespace Payments::Ui {
|
||||||
|
|
||||||
using namespace ::Ui;
|
using namespace ::Ui;
|
||||||
|
@ -56,6 +60,7 @@ public:
|
||||||
virtual QVariant panelClickHandlerContext() = 0;
|
virtual QVariant panelClickHandlerContext() = 0;
|
||||||
|
|
||||||
virtual QString panelWebviewDataPath() = 0;
|
virtual QString panelWebviewDataPath() = 0;
|
||||||
|
virtual Webview::ThemeParams panelWebviewThemeParams() = 0;
|
||||||
|
|
||||||
virtual std::optional<QDate> panelOverrideExpireDateThreshold() = 0;
|
virtual std::optional<QDate> panelOverrideExpireDateThreshold() = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -494,7 +494,7 @@ bool Panel::showWebview(
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const Webview::ThemeParams ¶ms,
|
const Webview::ThemeParams ¶ms,
|
||||||
rpl::producer<QString> bottomText) {
|
rpl::producer<QString> bottomText) {
|
||||||
if (!_webview && !createWebview()) {
|
if (!_webview && !createWebview(params)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto allowBack = false;
|
const auto allowBack = false;
|
||||||
|
@ -555,12 +555,16 @@ bool Panel::showWebview(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Panel::createWebview() {
|
bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
||||||
auto outer = base::make_unique_q<RpWidget>(_widget.get());
|
auto outer = base::make_unique_q<RpWidget>(_widget.get());
|
||||||
const auto container = outer.get();
|
const auto container = outer.get();
|
||||||
_widget->showInner(std::move(outer));
|
_widget->showInner(std::move(outer));
|
||||||
_webviewParent = container;
|
_webviewParent = container;
|
||||||
|
|
||||||
|
container->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
QPainter(container).fillRect(container->rect(), QColor(0, 128, 0, 255));
|
||||||
|
}, container->lifetime());
|
||||||
|
|
||||||
_webviewBottom = std::make_unique<RpWidget>(_widget.get());
|
_webviewBottom = std::make_unique<RpWidget>(_widget.get());
|
||||||
const auto bottom = _webviewBottom.get();
|
const auto bottom = _webviewBottom.get();
|
||||||
bottom->show();
|
bottom->show();
|
||||||
|
@ -580,6 +584,7 @@ bool Panel::createWebview() {
|
||||||
_webview = std::make_unique<WebviewWithLifetime>(
|
_webview = std::make_unique<WebviewWithLifetime>(
|
||||||
container,
|
container,
|
||||||
Webview::WindowConfig{
|
Webview::WindowConfig{
|
||||||
|
.opaqueBg = params.opaqueBg,
|
||||||
.userDataPath = _userDataPath,
|
.userDataPath = _userDataPath,
|
||||||
});
|
});
|
||||||
const auto raw = &_webview->window;
|
const auto raw = &_webview->window;
|
||||||
|
@ -649,6 +654,8 @@ bool Panel::createWebview() {
|
||||||
setupClosingBehaviour(arguments);
|
setupClosingBehaviour(arguments);
|
||||||
} else if (command == "web_app_read_text_from_clipboard") {
|
} else if (command == "web_app_read_text_from_clipboard") {
|
||||||
requestClipboardText(arguments);
|
requestClipboardText(arguments);
|
||||||
|
} else if (command == "web_app_set_header_color") {
|
||||||
|
processHeaderColor(arguments);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1089,6 +1096,22 @@ void Panel::processBackButtonMessage(const QJsonObject &args) {
|
||||||
_widget->setBackAllowed(args["is_visible"].toBool());
|
_widget->setBackAllowed(args["is_visible"].toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Panel::processHeaderColor(const QJsonObject &args) {
|
||||||
|
if (const auto color = ParseColor(args["color"].toString())) {
|
||||||
|
_widget->overrideTitleColor(color);
|
||||||
|
_headerColorLifetime.destroy();
|
||||||
|
} else if (args["color_key"].toString() == u"secondary_bg_color"_q) {
|
||||||
|
_widget->overrideTitleColor(st::boxDividerBg->c);
|
||||||
|
_headerColorLifetime = style::PaletteChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_widget->overrideTitleColor(st::boxDividerBg->c);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_widget->overrideTitleColor(std::nullopt);
|
||||||
|
_headerColorLifetime.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Panel::createMainButton() {
|
void Panel::createMainButton() {
|
||||||
_mainButton = std::make_unique<Button>(
|
_mainButton = std::make_unique<Button>(
|
||||||
_widget.get(),
|
_widget.get(),
|
||||||
|
@ -1179,6 +1202,7 @@ void Panel::updateThemeParams(const Webview::ThemeParams ¶ms) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_webview->window.updateTheme(
|
_webview->window.updateTheme(
|
||||||
|
params.opaqueBg,
|
||||||
params.scrollBg,
|
params.scrollBg,
|
||||||
params.scrollBgOver,
|
params.scrollBgOver,
|
||||||
params.scrollBarBg,
|
params.scrollBarBg,
|
||||||
|
|
|
@ -106,7 +106,7 @@ private:
|
||||||
struct Progress;
|
struct Progress;
|
||||||
struct WebviewWithLifetime;
|
struct WebviewWithLifetime;
|
||||||
|
|
||||||
bool createWebview();
|
bool createWebview(const Webview::ThemeParams ¶ms);
|
||||||
void showWebviewProgress();
|
void showWebviewProgress();
|
||||||
void hideWebviewProgress();
|
void hideWebviewProgress();
|
||||||
void setTitle(rpl::producer<QString> title);
|
void setTitle(rpl::producer<QString> title);
|
||||||
|
@ -114,6 +114,7 @@ private:
|
||||||
void switchInlineQueryMessage(const QJsonObject &args);
|
void switchInlineQueryMessage(const QJsonObject &args);
|
||||||
void processMainButtonMessage(const QJsonObject &args);
|
void processMainButtonMessage(const QJsonObject &args);
|
||||||
void processBackButtonMessage(const QJsonObject &args);
|
void processBackButtonMessage(const QJsonObject &args);
|
||||||
|
void processHeaderColor(const QJsonObject &args);
|
||||||
void openTgLink(const QJsonObject &args);
|
void openTgLink(const QJsonObject &args);
|
||||||
void openExternalLink(const QJsonObject &args);
|
void openExternalLink(const QJsonObject &args);
|
||||||
void openInvoice(const QJsonObject &args);
|
void openInvoice(const QJsonObject &args);
|
||||||
|
@ -153,6 +154,7 @@ private:
|
||||||
mutable crl::time _mainButtonLastClick = 0;
|
mutable crl::time _mainButtonLastClick = 0;
|
||||||
std::unique_ptr<Progress> _progress;
|
std::unique_ptr<Progress> _progress;
|
||||||
rpl::event_stream<> _themeUpdateForced;
|
rpl::event_stream<> _themeUpdateForced;
|
||||||
|
rpl::lifetime _headerColorLifetime;
|
||||||
rpl::lifetime _fgLifetime;
|
rpl::lifetime _fgLifetime;
|
||||||
rpl::lifetime _bgLifetime;
|
rpl::lifetime _bgLifetime;
|
||||||
bool _webviewProgress = false;
|
bool _webviewProgress = false;
|
||||||
|
|
|
@ -1512,6 +1512,7 @@ bool ReadPaletteValues(const QByteArray &content, Fn<bool(QLatin1String name, QL
|
||||||
object.insert(name, '#' + hex(r) + hex(g) + hex(b));
|
object.insert(name, '#' + hex(r) + hex(g) + hex(b));
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
.opaqueBg = st::windowBg->c,
|
||||||
.scrollBg = st::scrollBg->c,
|
.scrollBg = st::scrollBg->c,
|
||||||
.scrollBgOver = st::scrollBgOver->c,
|
.scrollBgOver = st::scrollBgOver->c,
|
||||||
.scrollBarBg = st::scrollBarBg->c,
|
.scrollBarBg = st::scrollBarBg->c,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 552d96a51fa5c8e50f9d6f631055558d99356cb4
|
Subproject commit 0727eb84a67f57b2fcc8c3c29efb5072434cd29f
|
Loading…
Reference in New Issue
Block a user