diff --git a/Telegram/Resources/bot_webview_shell_html/page.css b/Telegram/Resources/bot_webview_shell_html/page.css index 1f88873cfa..ba184f5733 100644 --- a/Telegram/Resources/bot_webview_shell_html/page.css +++ b/Telegram/Resources/bot_webview_shell_html/page.css @@ -84,6 +84,9 @@ select { var(--shadow-pad-bottom) var(--shadow-pad-left); } +#root.no-window-alpha #scene { + background: #eeeeee; +} #shell { position: relative; width: 100%; @@ -99,6 +102,10 @@ select { 0 8px 14px -5px rgba(0, 0, 0, 0.20); overflow: hidden; } +#root.no-window-alpha #shell { + box-shadow: none; + border: 1px solid rgba(0, 0, 0, 0.10); +} #header { flex: 0 0 auto; min-height: var(--header-height); diff --git a/Telegram/Resources/bot_webview_shell_html/page.js b/Telegram/Resources/bot_webview_shell_html/page.js index fb9f370578..c1bee1e0d6 100644 --- a/Telegram/Resources/bot_webview_shell_html/page.js +++ b/Telegram/Resources/bot_webview_shell_html/page.js @@ -36,6 +36,9 @@ secondary: null } }; + if (window.TelegramDesktopWindowAlphaSupported === false) { + root.classList.add('no-window-alpha'); + } const shellAssets = { icons: Object.create(null), titleMenuIcon: null, diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index baff887947..e05a0701e6 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/ripple_animation.h" #include "ui/layers/box_content.h" #include "ui/layers/standalone_layer_stack.h" +#include "ui/platform/ui_platform_utility.h" #include "ui/round_rect.h" #include "ui/style/style_core_palette.h" #include "ui/text/format_values.h" @@ -1638,10 +1639,28 @@ void Panel::setExternalShellBlocked(bool blocked) { } } +Panel::ExternalShellAnchor Panel::externalShellAnchor() const { + if (!_webview) { + return {}; + } + const auto transientParent = _webview->window.winId(); + if (!transientParent) { + return {}; + } + return { + .anchorGeometry = Ui::Platform::ForeignWindowGeometry( + transientParent), + .transientParent = transientParent, + }; +} + Webview::PopupResult Panel::showBlockingPopup(Webview::PopupArgs &&args) { if (!_externalShell) { return Webview::ShowBlockingPopup(std::move(args)); } + const auto anchor = externalShellAnchor(); + args.anchorGeometry = anchor.anchorGeometry; + args.transientParent = anchor.transientParent; args.parent = nullptr; setExternalShellBlocked(true); const auto weak = base::make_weak(this); @@ -1720,6 +1739,9 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { .mode = _externalShell ? Webview::WindowMode::External : Webview::WindowMode::Embedded, + .windowMargins = _externalShell + ? st::botWebViewShellShadowPadding + : QMargins(), }); const auto raw = &_webview->window; @@ -1959,6 +1981,9 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { }); if (_externalShell) { raw->setDialogHandler([=](Webview::DialogArgs args) { + const auto anchor = externalShellAnchor(); + args.anchorGeometry = anchor.anchorGeometry; + args.transientParent = anchor.transientParent; args.parent = nullptr; setExternalShellBlocked(true); const auto weak = base::make_weak(this); @@ -2956,6 +2981,10 @@ void Panel::showBox( LayerOptions options, anim::type animated) { if (_externalShell) { + const auto anchor = externalShellAnchor(); + _externalLayer->setAnchor( + anchor.anchorGeometry, + anchor.transientParent); _externalLayer->showBox(std::move(box), options, animated); return; } diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h index 6e222f6f27..edfb2ac94e 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rect_part.h" #include "webview/webview_common.h" #include +#include #include #include @@ -203,6 +204,10 @@ private: std::optional body; std::optional bottom; }; + struct ExternalShellAnchor { + std::optional anchorGeometry; + void *transientParent = nullptr; + }; class Button; struct Progress; struct WebviewWithLifetime; @@ -229,6 +234,7 @@ private: void applyExternalShellFullscreen(bool fullscreen); void sendExternalShellChrome(); void setExternalShellBlocked(bool blocked); + [[nodiscard]] ExternalShellAnchor externalShellAnchor() const; Webview::PopupResult showBlockingPopup(Webview::PopupArgs &&args); void createWebviewBottom(); void showWebviewProgress(); diff --git a/Telegram/SourceFiles/ui/layers/standalone_layer_stack.cpp b/Telegram/SourceFiles/ui/layers/standalone_layer_stack.cpp index 3f15cc97a6..345ed2968a 100644 --- a/Telegram/SourceFiles/ui/layers/standalone_layer_stack.cpp +++ b/Telegram/SourceFiles/ui/layers/standalone_layer_stack.cpp @@ -104,7 +104,10 @@ void StandaloneLayerStack::showBox( } else if (!_entries.empty()) { _entries.back().panel->hideForStacking(); } - auto panel = base::make_unique_q(); + auto panel = base::make_unique_q(SeparatePanelArgs{ + .anchorGeometry = _anchorGeometry, + .transientParent = _transientParent, + }); panel->setWindowFlag(Qt::WindowStaysOnTopHint, false); panel->setAttribute(Qt::WA_DeleteOnClose, false); panel->setTitleHeight(0); @@ -158,6 +161,13 @@ void StandaloneLayerStack::hideLayers(anim::type animated) { } } +void StandaloneLayerStack::setAnchor( + std::optional geometry, + void *transientParent) { + _anchorGeometry = std::move(geometry); + _transientParent = transientParent; +} + ShowFactory StandaloneLayerStack::showFactory() { const auto weak = base::make_weak(this); return [weak]() -> ShowPtr { @@ -166,6 +176,9 @@ ShowFactory StandaloneLayerStack::showFactory() { } std::optional StandaloneLayerStack::layerOuterSize() { + if (_anchorGeometry) { + return _anchorGeometry->size(); + } if (const auto screen = QGuiApplication::primaryScreen()) { return screen->availableGeometry().size(); } diff --git a/Telegram/SourceFiles/ui/layers/standalone_layer_stack.h b/Telegram/SourceFiles/ui/layers/standalone_layer_stack.h index cf3841d348..31b202433f 100644 --- a/Telegram/SourceFiles/ui/layers/standalone_layer_stack.h +++ b/Telegram/SourceFiles/ui/layers/standalone_layer_stack.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #include "ui/layers/layer_widget.h" +#include #include #include @@ -43,6 +44,7 @@ public: LayerOptions options, anim::type animated) override; void hideLayers(anim::type animated) override; + void setAnchor(std::optional geometry, void *transientParent); ShowFactory showFactory() override; std::optional layerOuterSize() override; bool centerWithinOuter() override { @@ -72,6 +74,8 @@ private: void hideAllPanels(); std::vector _entries; + std::optional _anchorGeometry; + void *_transientParent = nullptr; rpl::event_stream<> _boxAdded; rpl::event_stream<> _boxClosed; diff --git a/Telegram/lib_webview b/Telegram/lib_webview index 2dfc2a5375..8cf2331876 160000 --- a/Telegram/lib_webview +++ b/Telegram/lib_webview @@ -1 +1 @@ -Subproject commit 2dfc2a53758998297a33534bbe01f2a78ef7d2eb +Subproject commit 8cf2331876d05fbf06301c5313e5568553a06fe2