/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/invoke_queued.h" #include "base/object_ptr.h" #include "base/unique_qptr.h" #include "iv/iv_delegate.h" #include "ui/effects/animations.h" #include "ui/text/text.h" class Painter; namespace Webview { struct DataRequest; class Window; } // namespace Webview namespace Ui { class RpWidget; class RpWindow; class PopupMenu; class FlatLabel; class IconButton; template class FadeWrapScaled; } // namespace Ui namespace Iv { struct Prepared; struct ShareBoxResult { Fn focus; Fn hide; rpl::producer<> destroyRequests; }; struct ShareBoxDescriptor { not_null parent; QString url; }; class Controller final { public: Controller( not_null delegate, Fn showShareBox); ~Controller(); struct Event { enum class Type { Close, Quit, OpenChannel, JoinChannel, OpenPage, OpenLink, OpenLinkExternal, OpenMedia, }; Type type = Type::Close; QString url; QString context; }; void show( const QString &dataPath, Prepared page, base::flat_map> inChannelValues); void update(Prepared page); [[nodiscard]] bool active() const; void showJoinedTooltip(); void minimize(); [[nodiscard]] rpl::producer dataRequests() const { return _dataRequests.events(); } [[nodiscard]] rpl::producer events() const { return _events.events(); } [[nodiscard]] rpl::lifetime &lifetime(); private: void createWindow(); void createWebview(const QString &dataPath); [[nodiscard]] QByteArray navigateScript(int index, const QString &hash); [[nodiscard]] QByteArray reloadScript(int index); void showInWindow(const QString &dataPath, Prepared page); [[nodiscard]] QByteArray fillInChannelValuesScript( base::flat_map> inChannelValues); [[nodiscard]] QByteArray toggleInChannelScript( const QByteArray &id, bool in) const; void processKey(const QString &key, const QString &modifier); void processLink(const QString &url, const QString &context); void initControls(); void updateTitleGeometry(int newWidth) const; void activate(); void setInnerFocus(); void showMenu(); void escape(); void close(); void quit(); [[nodiscard]] QString composeCurrentUrl() const; void showShareMenu(); void destroyShareMenu(); const not_null _delegate; std::unique_ptr _window; std::unique_ptr _subtitleWrap; rpl::variable _subtitleText; std::unique_ptr _subtitle; Ui::Animations::Simple _subtitleLeft; object_ptr _menuToggle = { nullptr }; object_ptr> _back = { nullptr }; base::unique_qptr _menu; Ui::RpWidget *_container = nullptr; std::unique_ptr _webview; rpl::event_stream _dataRequests; rpl::event_stream _events; base::flat_map _inChannelChanged; base::flat_set _inChannelSubscribed; SingleQueuedInvokation _updateStyles; bool _reloadInitialWhenReady = false; bool _subscribedToColors = false; bool _ready = false; rpl::variable _index = -1; QString _hash; Fn _showShareBox; std::unique_ptr _shareWrap; std::unique_ptr _shareContainer; Fn _shareFocus; Fn _shareHide; bool _shareHidesContent = false; std::vector _pages; base::flat_map _indices; QString _navigateToHashWhenReady; int _navigateToIndexWhenReady = -1; rpl::lifetime _lifetime; }; } // namespace Iv