From 2fb7bdc803fd346d77dcd22b0ed9642397a806f4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 24 May 2023 21:20:18 +0400 Subject: [PATCH] Skip refocus InputField::Inner if field unfocused. I hope this fixes #26223. --- .../calls/group/calls_group_panel.cpp | 58 ++++++++++++----- .../calls/group/calls_group_panel.h | 5 ++ .../view/export_view_panel_controller.cpp | 2 +- .../SourceFiles/main/session/session_show.cpp | 28 ++++---- Telegram/SourceFiles/mainwindow.cpp | 18 +----- Telegram/SourceFiles/mainwindow.h | 19 ++---- .../payments/ui/payments_panel.cpp | 2 +- .../ui/chat/attach/attach_bot_webview.cpp | 2 +- .../SourceFiles/window/window_controller.cpp | 41 ++++++------ .../SourceFiles/window/window_controller.h | 35 +++++----- .../window/window_session_controller.cpp | 64 ++++++++++--------- .../window/window_session_controller.h | 6 +- Telegram/lib_ui | 2 +- 13 files changed, 152 insertions(+), 130 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index 31758718d..454d658ed 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -80,11 +80,13 @@ public: explicit Show(not_null panel); ~Show(); - void showBox( - object_ptr content, - Ui::LayerOptions options - = Ui::LayerOption::KeepOther) const override; - void hideLayer() const override; + void showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const override; [[nodiscard]] not_null toastParent() const override; [[nodiscard]] bool valid() const override; operator bool() const override; @@ -102,19 +104,27 @@ Show::Show(not_null panel) Show::~Show() = default; -void Show::showBox( - object_ptr content, - Ui::LayerOptions options) const { - if (const auto panel = _panel.get()) { - panel->showBox(std::move(content), options); +void Show::showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const { + using UniqueLayer = std::unique_ptr; + using ObjectBox = object_ptr; + if (auto layerWidget = std::get_if(&layer)) { + if (const auto panel = _panel.get()) { + panel->showLayer(std::move(*layerWidget), options, animated); + } + } else if (auto box = std::get_if(&layer)) { + if (const auto panel = _panel.get()) { + panel->showBox(std::move(*box), options, animated); + } + } else if (const auto panel = _panel.get()) { + panel->hideLayer(animated); } -} - -void Show::hideLayer() const { - if (const auto panel = _panel.get()) { - panel->hideLayer(); - } -} + } not_null Show::toastParent() const { const auto panel = _panel.get(); @@ -1527,6 +1537,20 @@ void Panel::showBox( _layerBg->showBox(std::move(box), options, animated); } +void Panel::showLayer( + std::unique_ptr layer, + Ui::LayerOptions options, + anim::type animated) { + hideStickedTooltip(StickedTooltipHide::Unavailable); + if (window()->width() < st::groupCallWidth + || window()->height() < st::groupCallWidth) { + window()->resize( + std::max(window()->width(), st::groupCallWidth), + std::max(window()->height(), st::groupCallWidth)); + } + _layerBg->showLayer(std::move(layer), options, animated); +} + void Panel::hideLayer(anim::type animated) { _layerBg->hideAll(animated); } diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.h b/Telegram/SourceFiles/calls/group/calls_group_panel.h index 2a05232c5..8fab14540 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.h +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.h @@ -34,6 +34,7 @@ class GroupCall; namespace Ui { class BoxContent; +class LayerWidget; enum class LayerOption; using LayerOptions = base::flags; class AbstractButton; @@ -106,6 +107,10 @@ public: object_ptr box, Ui::LayerOptions options, anim::type animated = anim::type::normal); + void showLayer( + std::unique_ptr layer, + Ui::LayerOptions options, + anim::type animated = anim::type::normal); void hideLayer(anim::type animated = anim::type::normal); [[nodiscard]] bool isLayerShown() const; diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index 24293ca84..4aef9c36e 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -156,7 +156,7 @@ PanelController::~PanelController() { saveSettings(); } if (_panel) { - _panel->destroyLayer(); + _panel->hideLayer(anim::type::instant); } } diff --git a/Telegram/SourceFiles/main/session/session_show.cpp b/Telegram/SourceFiles/main/session/session_show.cpp index bbd0b4284..a9914e87d 100644 --- a/Telegram/SourceFiles/main/session/session_show.cpp +++ b/Telegram/SourceFiles/main/session/session_show.cpp @@ -16,11 +16,13 @@ public: std::shared_ptr show, not_null session); - void showBox( - object_ptr content, - Ui::LayerOptions options - = Ui::LayerOption::KeepOther) const override; - void hideLayer() const override; + void showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const override; not_null toastParent() const override; bool valid() const override; operator bool() const override; @@ -40,14 +42,14 @@ SimpleSessionShow::SimpleSessionShow( , _session(session) { } -void SimpleSessionShow::showBox( - object_ptr content, - Ui::LayerOptions options) const { - _show->showBox(std::move(content), options); -} - -void SimpleSessionShow::hideLayer() const { - _show->hideLayer(); +void SimpleSessionShow::showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const { + _show->showOrHideBoxOrLayer(std::move(layer), options, animated); } not_null SimpleSessionShow::toastParent() const { diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 3447c00b9..e96a5c248 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -407,7 +407,7 @@ MainWidget *MainWindow::sessionContent() const { return _main.data(); } -void MainWindow::showBoxOrLayer( +void MainWindow::showOrHideBoxOrLayer( std::variant< v::null_t, object_ptr, @@ -419,7 +419,7 @@ void MainWindow::showBoxOrLayer( if (auto layerWidget = std::get_if(&layer)) { ensureLayerCreated(); _layer->showLayer(std::move(*layerWidget), options, animated); - } else if (auto box = std::get_if(&layer); *box != nullptr) { + } else if (auto box = std::get_if(&layer)) { ensureLayerCreated(); _layer->showBox(std::move(*box), options, animated); } else { @@ -435,20 +435,6 @@ void MainWindow::showBoxOrLayer( } } -void MainWindow::ui_showBox( - object_ptr box, - Ui::LayerOptions options, - anim::type animated) { - showBoxOrLayer(std::move(box), options, animated); -} - -void MainWindow::showLayer( - std::unique_ptr &&layer, - Ui::LayerOptions options, - anim::type animated) { - showBoxOrLayer(std::move(layer), options, animated); -} - bool MainWindow::ui_isLayerShown() const { return _layer != nullptr; } diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 37e501269..5b6926e69 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -83,8 +83,11 @@ public: [[nodiscard]] QPixmap grabForSlideAnimation(); - void showLayer( - std::unique_ptr &&layer, + void showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, Ui::LayerOptions options, anim::type animated); void showSpecialLayer( @@ -93,10 +96,6 @@ public: bool showSectionInExistingLayer( not_null memento, const Window::SectionShow ¶ms); - void ui_showBox( - object_ptr box, - Ui::LayerOptions options, - anim::type animated); void ui_hideSettingsAndLayer(anim::type animated); void ui_removeLayerBlackout(); [[nodiscard]] bool ui_isLayerShown() const; @@ -122,14 +121,6 @@ private: void ensureLayerCreated(); void destroyLayer(); - void showBoxOrLayer( - std::variant< - v::null_t, - object_ptr, - std::unique_ptr> &&layer, - Ui::LayerOptions options, - anim::type animated); - void themeUpdated(const Window::Theme::BackgroundUpdate &data); QPoint _lastMousePosition; diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.cpp b/Telegram/SourceFiles/payments/ui/payments_panel.cpp index e68fab149..0ee46d64a 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_panel.cpp @@ -487,7 +487,7 @@ bool Panel::showWebview( return false; } showWebviewProgress(); - _widget->destroyLayer(); + _widget->hideLayer(anim::type::instant); _webview->window.navigate(url); _widget->setBackAllowed(allowBack); if (bottomText) { diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index c00a2b278..1930c5484 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -510,7 +510,7 @@ bool Panel::showWebview( } const auto allowBack = false; showWebviewProgress(); - _widget->destroyLayer(); + _widget->hideLayer(anim::type::instant); updateThemeParams(params); _webview->window.navigate(url); _widget->setBackAllowed(allowBack); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index ca6f48b3d..7f5bd3c2d 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -45,11 +45,13 @@ class Show final : public Ui::Show { public: explicit Show(not_null window); - void showBox( - object_ptr content, - Ui::LayerOptions options - = Ui::LayerOption::KeepOther) const override; - void hideLayer() const override; + void showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const override; [[nodiscard]] not_null toastParent() const override; [[nodiscard]] bool valid() const override; operator bool() const override; @@ -63,19 +65,18 @@ Show::Show(not_null window) : _window(base::make_weak(window)) { } -void Show::showBox( - object_ptr content, - Ui::LayerOptions options) const { +void Show::showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const { if (const auto window = _window.get()) { - window->show(std::move(content), options); - } -} - -void Show::hideLayer() const { - if (const auto window = _window.get()) { - window->show( - object_ptr{ nullptr }, - Ui::LayerOption::CloseOther); + window->widget()->showOrHideBoxOrLayer( + std::move(layer), + options, + animated); } } @@ -408,14 +409,14 @@ void Controller::showLayer( std::unique_ptr &&layer, Ui::LayerOptions options, anim::type animated) { - _widget.showLayer(std::move(layer), options, animated); + _widget.showOrHideBoxOrLayer(std::move(layer), options, animated); } void Controller::showBox( object_ptr content, Ui::LayerOptions options, anim::type animated) { - _widget.ui_showBox(std::move(content), options, animated); + _widget.showOrHideBoxOrLayer(std::move(content), options, animated); } void Controller::showRightColumn(object_ptr widget) { @@ -423,7 +424,7 @@ void Controller::showRightColumn(object_ptr widget) { } void Controller::hideLayer(anim::type animated) { - _widget.ui_showBox({ nullptr }, Ui::LayerOption::CloseOther, animated); + _widget.showOrHideBoxOrLayer(v::null, Ui::LayerOption::CloseOther, animated); } void Controller::hideSettingsAndLayer(anim::type animated) { diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 62abd54bb..787cae3a0 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -86,31 +86,38 @@ public: [[nodiscard]] int verticalShadowTop() const; - template - QPointer show( - object_ptr content, - Ui::LayerOptions options = Ui::LayerOption::KeepOther, - anim::type animated = anim::type::normal) { - const auto result = QPointer(content.data()); - showBox(std::move(content), options, animated); - return result; - } - void showToast(Ui::Toast::Config &&config); void showToast(TextWithEntities &&text, crl::time duration = 0); void showToast(const QString &text, crl::time duration = 0); + void showRightColumn(object_ptr widget); + + void showBox( + object_ptr content, + Ui::LayerOptions options, + anim::type animated); void showLayer( std::unique_ptr &&layer, Ui::LayerOptions options, anim::type animated = anim::type::normal); - void showRightColumn(object_ptr widget); - void hideLayer(anim::type animated = anim::type::normal); void hideSettingsAndLayer(anim::type animated = anim::type::normal); [[nodiscard]] bool isLayerShown() const; + template < + typename BoxType, + typename = std::enable_if_t< + std::is_base_of_v>> + QPointer show( + object_ptr content, + Ui::LayerOptions options = Ui::LayerOption::KeepOther, + anim::type animated = anim::type()) { + auto result = QPointer(content.data()); + showBox(std::move(content), options, animated); + return result; + } + void activate(); void reActivate(); void updateIsActiveFocus(); @@ -162,10 +169,6 @@ private: void setupSideBar(); void sideBarChanged(); - void showBox( - object_ptr content, - Ui::LayerOptions options, - anim::type animated); void checkThemeEditor(); void checkLockByTerms(); void showTermsDecline(); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index d40800ef7..601463962 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -111,13 +111,16 @@ constexpr auto kMaxChatEntryHistorySize = 50; class MainWindowShow final : public ChatHelpers::Show { public: - explicit MainWindowShow(not_null navigation); + explicit MainWindowShow(not_null controller); + + void showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const override; - void showBox( - object_ptr content, - Ui::LayerOptions options - = Ui::LayerOption::KeepOther) const override; - void hideLayer() const override; not_null toastParent() const override; bool valid() const override; operator bool() const override; @@ -144,24 +147,22 @@ private: }; -MainWindowShow::MainWindowShow( - not_null navigation) -: _window(base::make_weak(navigation->parentController())) { +MainWindowShow::MainWindowShow(not_null controller) +: _window(base::make_weak(controller)) { } -void MainWindowShow::showBox( - object_ptr content, - Ui::LayerOptions options) const { +void MainWindowShow::showOrHideBoxOrLayer( + std::variant< + v::null_t, + object_ptr, + std::unique_ptr> &&layer, + Ui::LayerOptions options, + anim::type animated) const { if (const auto window = _window.get()) { - window->show(std::move(content), options); - } -} - -void MainWindowShow::hideLayer() const { - if (const auto window = _window.get()) { - window->show( - object_ptr{ nullptr }, - Ui::LayerOption::CloseOther); + window->window().widget()->showOrHideBoxOrLayer( + std::move(layer), + options, + animated); } } @@ -395,8 +396,7 @@ void SessionNavigation::resolveChannelById( return; } const auto fail = crl::guard(this, [=] { - MainWindowShow(this).showToast( - tr::lng_error_post_link_invalid(tr::now)); + uiShow()->showToast(tr::lng_error_post_link_invalid(tr::now)); }); _api.request(base::take(_resolveRequestId)).cancel(); _resolveRequestId = _api.request(MTPchannels_GetChannels( @@ -594,8 +594,7 @@ void SessionNavigation::joinVoiceChatFromLink( Expects(info.voicechatHash.has_value()); const auto bad = crl::guard(this, [=] { - MainWindowShow(this).showToast( - tr::lng_group_invite_bad_link(tr::now)); + uiShow()->showToast(tr::lng_group_invite_bad_link(tr::now)); }); const auto hash = *info.voicechatHash; _api.request(base::take(_resolveRequestId)).cancel(); @@ -824,23 +823,23 @@ void SessionNavigation::showPollResults( auto SessionNavigation::showToast(Ui::Toast::Config &&config) -> base::weak_ptr { - return MainWindowShow(this).showToast(std::move(config)); + return uiShow()->showToast(std::move(config)); } auto SessionNavigation::showToast(const QString &text, crl::time duration) -> base::weak_ptr { - return MainWindowShow(this).showToast(text); + return uiShow()->showToast(text); } auto SessionNavigation::showToast( TextWithEntities &&text, crl::time duration) -> base::weak_ptr { - return MainWindowShow(this).showToast(std::move(text)); + return uiShow()->showToast(std::move(text)); } std::shared_ptr SessionNavigation::uiShow() { - return std::make_shared(this); + return parentController()->uiShow(); } struct SessionController::CachedThemeKey { @@ -2485,6 +2484,13 @@ bool SessionController::contentOverlapped(QWidget *w, QPaintEvent *e) { return widget()->contentOverlapped(w, e); } +std::shared_ptr SessionController::uiShow() { + if (!_cachedShow) { + _cachedShow = std::make_shared(this); + } + return _cachedShow; +} + SessionController::~SessionController() { resetFakeUnreadWhileOpened(); } diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 70b3c7716..5258e7b8e 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -278,7 +278,7 @@ public: const QString &text, crl::time duration = 0); - [[nodiscard]] std::shared_ptr uiShow(); + [[nodiscard]] virtual std::shared_ptr uiShow(); private: void resolvePhone( @@ -591,6 +591,8 @@ public: [[nodiscard]] bool contentOverlapped(QWidget *w, QPaintEvent *e); + [[nodiscard]] std::shared_ptr uiShow() override; + [[nodiscard]] rpl::lifetime &lifetime() { return _lifetime; } @@ -641,6 +643,8 @@ private: const std::unique_ptr _emojiInteractions; const bool _isPrimary = false; + mutable std::shared_ptr _cachedShow; + QString _authedName; using SendingAnimation = Ui::MessageSendingAnimationController; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 303a07f94..a7d503188 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 303a07f9461524dc6debf86ae04d0ee6d3134eb6 +Subproject commit a7d503188918904d12a069bca7d3f6c92b9fb553