Move HistoryMedia to HistoryView namespace.

This commit is contained in:
John Preston 2019-08-02 14:21:09 +01:00
parent fd59147b8a
commit 850940116d
61 changed files with 739 additions and 702 deletions

View File

@ -11,18 +11,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_location_manager.h" #include "history/history_location_manager.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/media/history_media_photo.h" #include "history/view/media/history_view_photo.h"
#include "history/media/history_media_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "history/media/history_media_gif.h" #include "history/view/media/history_view_gif.h"
#include "history/media/history_media_video.h" #include "history/view/media/history_view_video.h"
#include "history/media/history_media_document.h" #include "history/view/media/history_view_document.h"
#include "history/media/history_media_contact.h" #include "history/view/media/history_view_contact.h"
#include "history/media/history_media_location.h" #include "history/view/media/history_view_location.h"
#include "history/media/history_media_game.h" #include "history/view/media/history_view_game.h"
#include "history/media/history_media_invoice.h" #include "history/view/media/history_view_invoice.h"
#include "history/media/history_media_call.h" #include "history/view/media/history_view_call.h"
#include "history/media/history_media_web_page.h" #include "history/view/media/history_view_web_page.h"
#include "history/media/history_media_poll.h" #include "history/view/media/history_view_poll.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/image/image_source.h" #include "ui/image/image_source.h"
#include "ui/text_options.h" #include "ui/text_options.h"
@ -237,7 +237,7 @@ TextWithEntities Media::consumedMessageText() const {
return {}; return {};
} }
std::unique_ptr<HistoryMedia> Media::createView( std::unique_ptr<HistoryView::Media> Media::createView(
not_null<HistoryView::Element*> message) { not_null<HistoryView::Element*> message) {
return createView(message, message->data()); return createView(message, message->data());
} }
@ -471,17 +471,17 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
return true; return true;
} }
std::unique_ptr<HistoryMedia> MediaPhoto::createView( std::unique_ptr<HistoryView::Media> MediaPhoto::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
if (_chat) { if (_chat) {
return std::make_unique<HistoryPhoto>( return std::make_unique<HistoryView::Photo>(
message, message,
_chat, _chat,
_photo, _photo,
st::msgServicePhotoWidth); st::msgServicePhotoWidth);
} }
return std::make_unique<HistoryPhoto>( return std::make_unique<HistoryView::Photo>(
message, message,
realParent, realParent,
_photo); _photo);
@ -611,7 +611,10 @@ QString MediaFile::notificationText() const {
QString MediaFile::pinnedTextSubstring() const { QString MediaFile::pinnedTextSubstring() const {
if (const auto sticker = _document->sticker()) { if (const auto sticker = _document->sticker()) {
if (!_emoji.isEmpty()) { if (!_emoji.isEmpty()) {
return tr::lng_action_pinned_media_emoji_sticker(tr::now, lt_emoji, _emoji); return tr::lng_action_pinned_media_emoji_sticker(
tr::now,
lt_emoji,
_emoji);
} }
return tr::lng_action_pinned_media_sticker(tr::now); return tr::lng_action_pinned_media_sticker(tr::now);
} else if (_document->isAnimation()) { } else if (_document->isAnimation()) {
@ -637,7 +640,10 @@ TextForMimeData MediaFile::clipboardText() const {
: QString(); : QString();
if (const auto sticker = _document->sticker()) { if (const auto sticker = _document->sticker()) {
if (!_emoji.isEmpty()) { if (!_emoji.isEmpty()) {
return tr::lng_in_dlg_sticker_emoji(tr::now, lt_emoji, _emoji); return tr::lng_in_dlg_sticker_emoji(
tr::now,
lt_emoji,
_emoji);
} }
return tr::lng_in_dlg_sticker(tr::now); return tr::lng_in_dlg_sticker(tr::now);
} else if (_document->isAnimation()) { } else if (_document->isAnimation()) {
@ -759,20 +765,20 @@ bool MediaFile::updateSentMedia(const MTPMessageMedia &media) {
return true; return true;
} }
std::unique_ptr<HistoryMedia> MediaFile::createView( std::unique_ptr<HistoryView::Media> MediaFile::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
if (_document->sticker()) { if (_document->sticker()) {
return std::make_unique<HistorySticker>(message, _document); return std::make_unique<HistoryView::Sticker>(message, _document);
} else if (_document->isAnimation()) { } else if (_document->isAnimation()) {
return std::make_unique<HistoryGif>(message, _document); return std::make_unique<HistoryView::Gif>(message, _document);
} else if (_document->isVideoFile()) { } else if (_document->isVideoFile()) {
return std::make_unique<HistoryVideo>( return std::make_unique<HistoryView::Video>(
message, message,
realParent, realParent,
_document); _document);
} }
return std::make_unique<HistoryDocument>(message, _document); return std::make_unique<HistoryView::Document>(message, _document);
} }
MediaContact::MediaContact( MediaContact::MediaContact(
@ -818,7 +824,9 @@ QString MediaContact::pinnedTextSubstring() const {
} }
TextForMimeData MediaContact::clipboardText() const { TextForMimeData MediaContact::clipboardText() const {
const auto text = qsl("[ ") + tr::lng_in_dlg_contact(tr::now) + qsl(" ]\n") const auto text = qsl("[ ")
+ tr::lng_in_dlg_contact(tr::now)
+ qsl(" ]\n")
+ tr::lng_full_name( + tr::lng_full_name(
tr::now, tr::now,
lt_first_name, lt_first_name,
@ -850,10 +858,10 @@ bool MediaContact::updateSentMedia(const MTPMessageMedia &media) {
return true; return true;
} }
std::unique_ptr<HistoryMedia> MediaContact::createView( std::unique_ptr<HistoryView::Media> MediaContact::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryContact>( return std::make_unique<HistoryView::Contact>(
message, message,
_contact.userId, _contact.userId,
_contact.firstName, _contact.firstName,
@ -929,10 +937,10 @@ bool MediaLocation::updateSentMedia(const MTPMessageMedia &media) {
return false; return false;
} }
std::unique_ptr<HistoryMedia> MediaLocation::createView( std::unique_ptr<HistoryView::Media> MediaLocation::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryLocation>( return std::make_unique<HistoryView::Location>(
message, message,
_location, _location,
_title, _title,
@ -988,10 +996,10 @@ bool MediaCall::updateSentMedia(const MTPMessageMedia &media) {
return false; return false;
} }
std::unique_ptr<HistoryMedia> MediaCall::createView( std::unique_ptr<HistoryView::Media> MediaCall::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryCall>(message, &_call); return std::make_unique<HistoryView::Call>(message, &_call);
} }
QString MediaCall::Text( QString MediaCall::Text(
@ -1083,10 +1091,10 @@ bool MediaWebPage::updateSentMedia(const MTPMessageMedia &media) {
return false; return false;
} }
std::unique_ptr<HistoryMedia> MediaWebPage::createView( std::unique_ptr<HistoryView::Media> MediaWebPage::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryWebPage>(message, _page); return std::make_unique<HistoryView::WebPage>(message, _page);
} }
MediaGame::MediaGame( MediaGame::MediaGame(
@ -1174,10 +1182,13 @@ bool MediaGame::updateSentMedia(const MTPMessageMedia &media) {
return true; return true;
} }
std::unique_ptr<HistoryMedia> MediaGame::createView( std::unique_ptr<HistoryView::Media> MediaGame::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryGame>(message, _game, _consumedText); return std::make_unique<HistoryView::Game>(
message,
_game,
_consumedText);
} }
MediaInvoice::MediaInvoice( MediaInvoice::MediaInvoice(
@ -1236,10 +1247,10 @@ bool MediaInvoice::updateSentMedia(const MTPMessageMedia &media) {
return true; return true;
} }
std::unique_ptr<HistoryMedia> MediaInvoice::createView( std::unique_ptr<HistoryView::Media> MediaInvoice::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryInvoice>(message, &_invoice); return std::make_unique<HistoryView::Invoice>(message, &_invoice);
} }
MediaPoll::MediaPoll( MediaPoll::MediaPoll(
@ -1299,10 +1310,10 @@ bool MediaPoll::updateSentMedia(const MTPMessageMedia &media) {
return false; return false;
} }
std::unique_ptr<HistoryMedia> MediaPoll::createView( std::unique_ptr<HistoryView::Media> MediaPoll::createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
return std::make_unique<HistoryPoll>(message, _poll); return std::make_unique<HistoryView::Poll>(message, _poll);
} }
} // namespace Data } // namespace Data

View File

@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once #pragma once
class HistoryItem; class HistoryItem;
class HistoryMedia;
namespace base { namespace base {
template <typename Enum> template <typename Enum>
@ -23,6 +22,7 @@ using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
namespace HistoryView { namespace HistoryView {
enum class Context : char; enum class Context : char;
class Element; class Element;
class Media;
} // namespace HistoryView } // namespace HistoryView
namespace Data { namespace Data {
@ -107,10 +107,10 @@ public:
// the media (all media that was generated on client side, for example). // the media (all media that was generated on client side, for example).
virtual bool updateInlineResultMedia(const MTPMessageMedia &media) = 0; virtual bool updateInlineResultMedia(const MTPMessageMedia &media) = 0;
virtual bool updateSentMedia(const MTPMessageMedia &media) = 0; virtual bool updateSentMedia(const MTPMessageMedia &media) = 0;
virtual std::unique_ptr<HistoryMedia> createView( virtual std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) = 0; not_null<HistoryItem*> realParent) = 0;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message); not_null<HistoryView::Element*> message);
private: private:
@ -148,7 +148,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -185,7 +185,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -214,7 +214,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -244,7 +244,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -271,7 +271,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -307,7 +307,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -338,7 +338,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -369,7 +369,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;
@ -396,7 +396,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
std::unique_ptr<HistoryMedia> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
not_null<HistoryItem*> realParent) override; not_null<HistoryItem*> realParent) override;

View File

@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/notifications_manager.h" #include "window/notifications_manager.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "inline_bots/inline_bot_layout_item.h" #include "inline_bots/inline_bot_layout_item.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"

View File

@ -22,7 +22,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace App { // Hackish.. namespace App { // Hackish..
QString formatPhone(QString phone); QString formatPhone(QString phone);
} // namespace App } // namespace App
namespace HistoryView {
QString FillAmountAndCurrency(uint64 amount, const QString &currency); QString FillAmountAndCurrency(uint64 amount, const QString &currency);
} // namespace HistoryView
QString formatSizeText(qint64 size); QString formatSizeText(qint64 size);
QString formatDurationText(qint64 duration); QString formatDurationText(qint64 duration);
@ -1725,7 +1727,7 @@ Utf8String FormatDateTime(
} }
Utf8String FormatMoneyAmount(uint64 amount, const Utf8String &currency) { Utf8String FormatMoneyAmount(uint64 amount, const Utf8String &currency) {
return FillAmountAndCurrency( return HistoryView::FillAmountAndCurrency(
amount, amount,
QString::fromUtf8(currency)).toUtf8(); QString::fromUtf8(currency)).toUtf8();
} }

View File

@ -28,7 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/observer.h" #include "base/observer.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "styles/style_history.h" #include "styles/style_history.h"
#include "data/data_session.h" #include "data/data_session.h"

View File

@ -9,8 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_history.h" #include "styles/style_history.h"
#include "history/history.h" #include "history/history.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/media/history_media_web_page.h" #include "history/view/media/history_view_web_page.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
@ -1627,7 +1627,7 @@ void InnerWidget::performDrag() {
// return; // return;
//} else { //} else {
// auto forwardMimeType = QString(); // auto forwardMimeType = QString();
// auto pressedMedia = static_cast<HistoryMedia*>(nullptr); // auto pressedMedia = static_cast<HistoryView::Media*>(nullptr);
// if (auto pressedItem = App::pressedItem()) { // if (auto pressedItem = App::pressedItem()) {
// pressedMedia = pressedItem->media(); // pressedMedia = pressedItem->media();
// if (_mouseCursorState == CursorState::Date // if (_mouseCursorState == CursorState::Date

View File

@ -22,7 +22,6 @@ class HistoryBlock;
class HistoryItem; class HistoryItem;
class HistoryMessage; class HistoryMessage;
class HistoryService; class HistoryService;
class HistoryMedia;
namespace Main { namespace Main {
class Session; class Session;

View File

@ -13,9 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h" #include "core/crash_reports.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/media/history_media_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "history/media/history_media_web_page.h" #include "history/view/media/history_view_web_page.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
@ -1087,7 +1087,7 @@ void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton but
if (uponSelected) { if (uponSelected) {
_mouseAction = MouseAction::PrepareDrag; // start text drag _mouseAction = MouseAction::PrepareDrag; // start text drag
} else if (!_pressWasInactive) { } else if (!_pressWasInactive) {
if (dynamic_cast<HistorySticker*>(App::pressedItem()->media()) if (dynamic_cast<HistoryView::Sticker*>(App::pressedItem()->media())
|| _mouseCursorState == CursorState::Date) { || _mouseCursorState == CursorState::Date) {
_mouseAction = MouseAction::PrepareDrag; // start sticker drag or by-date drag _mouseAction = MouseAction::PrepareDrag; // start sticker drag or by-date drag
} else { } else {

View File

@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/media/history_media_grouped.h" #include "history/view/media/history_view_media_grouped.h"
#include "history/history_service.h" #include "history/history_service.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history.h" #include "history/history.h"

View File

@ -16,7 +16,6 @@ enum class UnreadMentionType;
struct HistoryMessageReplyMarkup; struct HistoryMessageReplyMarkup;
class ReplyKeyboard; class ReplyKeyboard;
class HistoryMessage; class HistoryMessage;
class HistoryMedia;
namespace base { namespace base {
template <typename Enum> template <typename Enum>

View File

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/media/history_media_document.h" #include "history/view/media/history_view_document.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "media/audio/media_audio.h" #include "media/audio/media_audio.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
@ -922,16 +922,16 @@ HistoryDocumentCaptioned::HistoryDocumentCaptioned()
} }
HistoryDocumentVoicePlayback::HistoryDocumentVoicePlayback( HistoryDocumentVoicePlayback::HistoryDocumentVoicePlayback(
const HistoryDocument *that) const HistoryView::Document *that)
: progress(0., 0.) : progress(0., 0.)
, progressAnimation([=](crl::time now) { , progressAnimation([=](crl::time now) {
const auto nonconst = const_cast<HistoryDocument*>(that); const auto nonconst = const_cast<HistoryView::Document*>(that);
return nonconst->voiceProgressAnimationCallback(now); return nonconst->voiceProgressAnimationCallback(now);
}) { }) {
} }
void HistoryDocumentVoice::ensurePlayback( void HistoryDocumentVoice::ensurePlayback(
const HistoryDocument *that) const { const HistoryView::Document *that) const {
if (!_playback) { if (!_playback) {
_playback = std::make_unique<HistoryDocumentVoicePlayback>(that); _playback = std::make_unique<HistoryDocumentVoicePlayback>(that);
} }

View File

@ -11,11 +11,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
class HistoryDocument;
struct WebPageData; struct WebPageData;
namespace HistoryView { namespace HistoryView {
class Element; class Element;
class Document;
} // namespace HistoryView } // namespace HistoryView
struct HistoryMessageVia : public RuntimeComponent<HistoryMessageVia, HistoryItem> { struct HistoryMessageVia : public RuntimeComponent<HistoryMessageVia, HistoryItem> {
@ -375,7 +375,7 @@ struct HistoryMessageLogEntryOriginal
}; };
class FileClickHandler; class FileClickHandler;
struct HistoryDocumentThumbed : public RuntimeComponent<HistoryDocumentThumbed, HistoryDocument> { struct HistoryDocumentThumbed : public RuntimeComponent<HistoryDocumentThumbed, HistoryView::Document> {
std::shared_ptr<FileClickHandler> _linksavel; std::shared_ptr<FileClickHandler> _linksavel;
std::shared_ptr<FileClickHandler> _linkopenwithl; std::shared_ptr<FileClickHandler> _linkopenwithl;
std::shared_ptr<FileClickHandler> _linkcancell; std::shared_ptr<FileClickHandler> _linkcancell;
@ -385,31 +385,31 @@ struct HistoryDocumentThumbed : public RuntimeComponent<HistoryDocumentThumbed,
mutable QString _link; mutable QString _link;
}; };
struct HistoryDocumentCaptioned : public RuntimeComponent<HistoryDocumentCaptioned, HistoryDocument> { struct HistoryDocumentCaptioned : public RuntimeComponent<HistoryDocumentCaptioned, HistoryView::Document> {
HistoryDocumentCaptioned(); HistoryDocumentCaptioned();
Ui::Text::String _caption; Ui::Text::String _caption;
}; };
struct HistoryDocumentNamed : public RuntimeComponent<HistoryDocumentNamed, HistoryDocument> { struct HistoryDocumentNamed : public RuntimeComponent<HistoryDocumentNamed, HistoryView::Document> {
QString _name; QString _name;
int _namew = 0; int _namew = 0;
}; };
struct HistoryDocumentVoicePlayback { struct HistoryDocumentVoicePlayback {
HistoryDocumentVoicePlayback(const HistoryDocument *that); HistoryDocumentVoicePlayback(const HistoryView::Document *that);
int32 position = 0; int32 position = 0;
anim::value progress; anim::value progress;
Ui::Animations::Basic progressAnimation; Ui::Animations::Basic progressAnimation;
}; };
class HistoryDocumentVoice : public RuntimeComponent<HistoryDocumentVoice, HistoryDocument> { class HistoryDocumentVoice : public RuntimeComponent<HistoryDocumentVoice, HistoryView::Document> {
// We don't use float64 because components should align to pointer even on 32bit systems. // We don't use float64 because components should align to pointer even on 32bit systems.
static constexpr float64 kFloatToIntMultiplier = 65536.; static constexpr float64 kFloatToIntMultiplier = 65536.;
public: public:
void ensurePlayback(const HistoryDocument *interfaces) const; void ensurePlayback(const HistoryView::Document *interfaces) const;
void checkPlaybackFinished() const; void checkPlaybackFinished() const;
mutable std::unique_ptr<HistoryDocumentVoicePlayback> _playback; mutable std::unique_ptr<HistoryDocumentVoicePlayback> _playback;

View File

@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h" #include "apiwrap.h"
#include "layout.h" #include "layout.h"
#include "history/history.h" #include "history/history.h"
#include "history/media/history_media_invoice.h" #include "history/view/media/history_view_invoice.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
@ -669,7 +669,7 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
UpdateComponents(HistoryServicePayment::Bit()); UpdateComponents(HistoryServicePayment::Bit());
auto amount = message.vaction().c_messageActionPaymentSent().vtotal_amount().v; auto amount = message.vaction().c_messageActionPaymentSent().vtotal_amount().v;
auto currency = qs(message.vaction().c_messageActionPaymentSent().vcurrency()); auto currency = qs(message.vaction().c_messageActionPaymentSent().vcurrency());
Get<HistoryServicePayment>()->amount = FillAmountAndCurrency(amount, currency); Get<HistoryServicePayment>()->amount = HistoryView::FillAmountAndCurrency(amount, currency);
} }
if (const auto replyToMsgId = message.vreply_to_msg_id()) { if (const auto replyToMsgId = message.vreply_to_msg_id()) {
if (message.vaction().type() == mtpc_messageActionPinMessage) { if (message.vaction().type() == mtpc_messageActionPinMessage) {

View File

@ -39,7 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/history_drag_area.h" #include "history/history_drag_area.h"
#include "history/history_inner_widget.h" #include "history/history_inner_widget.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"

View File

@ -13,8 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/media/history_media_web_page.h" #include "history/view/media/history_view_web_page.h"
#include "ui/widgets/popup_menu.h" #include "ui/widgets/popup_menu.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"

View File

@ -11,9 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/media/history_media_grouped.h" #include "history/view/media/history_view_media_grouped.h"
#include "history/media/history_media_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "history/history.h" #include "history/history.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "chat_helpers/stickers_emoji_pack.h" #include "chat_helpers/stickers_emoji_pack.h"
@ -224,7 +224,7 @@ QDateTime Element::dateTime() const {
return _dateTime; return _dateTime;
} }
HistoryMedia *Element::media() const { Media *Element::media() const {
return _media.get(); return _media.get();
} }
@ -331,7 +331,7 @@ void Element::refreshMedia() {
_media = nullptr; _media = nullptr;
_flags |= Flag::HiddenByGroup; _flags |= Flag::HiddenByGroup;
} else { } else {
_media = std::make_unique<HistoryGroupedMedia>( _media = std::make_unique<GroupedMedia>(
this, this,
group->items); group->items);
if (!pendingResize()) { if (!pendingResize()) {
@ -345,7 +345,7 @@ void Element::refreshMedia() {
if (_data->media()) { if (_data->media()) {
_media = _data->media()->createView(this); _media = _data->media()->createView(this);
} else if (const auto document = emojiStickers->stickerForEmoji(_data)) { } else if (const auto document = emojiStickers->stickerForEmoji(_data)) {
_media = std::make_unique<HistorySticker>(this, document); _media = std::make_unique<Sticker>(this, document);
} else { } else {
_media = nullptr; _media = nullptr;
} }

View File

@ -15,8 +15,6 @@ class HistoryBlock;
class HistoryItem; class HistoryItem;
class HistoryMessage; class HistoryMessage;
class HistoryService; class HistoryService;
class HistoryMedia;
class HistoryWebPage;
namespace HistoryView { namespace HistoryView {
@ -24,6 +22,7 @@ enum class PointState : char;
enum class InfoDisplayType : char; enum class InfoDisplayType : char;
struct StateRequest; struct StateRequest;
struct TextState; struct TextState;
class Media;
enum class Context : char { enum class Context : char {
History, History,
@ -147,7 +146,7 @@ public:
not_null<ElementDelegate*> delegate() const; not_null<ElementDelegate*> delegate() const;
not_null<HistoryItem*> data() const; not_null<HistoryItem*> data() const;
not_null<History*> history() const; not_null<History*> history() const;
HistoryMedia *media() const; Media *media() const;
Context context() const; Context context() const;
void refreshDataId(); void refreshDataId();
@ -303,7 +302,7 @@ private:
const not_null<ElementDelegate*> _delegate; const not_null<ElementDelegate*> _delegate;
const not_null<HistoryItem*> _data; const not_null<HistoryItem*> _data;
std::unique_ptr<HistoryMedia> _media; std::unique_ptr<Media> _media;
const QDateTime _dateTime; const QDateTime _dateTime;
int _y = 0; int _y = 0;

View File

@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/media/history_media_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "history/view/history_view_context_menu.h" #include "history/view/history_view_context_menu.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
@ -888,7 +888,7 @@ bool ListWidget::requiredToStartDragging(
not_null<Element*> view) const { not_null<Element*> view) const {
if (_mouseCursorState == CursorState::Date) { if (_mouseCursorState == CursorState::Date) {
return true; return true;
} else if (dynamic_cast<HistorySticker*>(view->media()) != nullptr) { } else if (dynamic_cast<Sticker*>(view->media()) != nullptr) {
return true; return true;
} }
return false; return false;

View File

@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/media/history_media_web_page.h" #include "history/view/media/history_view_web_page.h"
#include "history/history.h" #include "history/history.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -1301,11 +1301,11 @@ void Message::initLogEntryOriginal() {
if (const auto log = message()->Get<HistoryMessageLogEntryOriginal>()) { if (const auto log = message()->Get<HistoryMessageLogEntryOriginal>()) {
AddComponents(LogEntryOriginal::Bit()); AddComponents(LogEntryOriginal::Bit());
const auto entry = Get<LogEntryOriginal>(); const auto entry = Get<LogEntryOriginal>();
entry->page = std::make_unique<HistoryWebPage>(this, log->page); entry->page = std::make_unique<WebPage>(this, log->page);
} }
} }
HistoryWebPage *Message::logEntryOriginal() const { WebPage *Message::logEntryOriginal() const {
if (const auto entry = Get<LogEntryOriginal>()) { if (const auto entry = Get<LogEntryOriginal>()) {
return entry->page.get(); return entry->page.get();
} }

View File

@ -14,6 +14,8 @@ struct HistoryMessageEdited;
namespace HistoryView { namespace HistoryView {
class WebPage;
// Special type of Component for the channel actions log. // Special type of Component for the channel actions log.
struct LogEntryOriginal struct LogEntryOriginal
: public RuntimeComponent<LogEntryOriginal, Element> { : public RuntimeComponent<LogEntryOriginal, Element> {
@ -22,7 +24,7 @@ struct LogEntryOriginal
LogEntryOriginal &operator=(LogEntryOriginal &&other); LogEntryOriginal &operator=(LogEntryOriginal &&other);
~LogEntryOriginal(); ~LogEntryOriginal();
std::unique_ptr<HistoryWebPage> page; std::unique_ptr<WebPage> page;
}; };
@ -147,7 +149,7 @@ private:
int timeLeft() const; int timeLeft() const;
int plainMaxWidth() const; int plainMaxWidth() const;
HistoryWebPage *logEntryOriginal() const; WebPage *logEntryOriginal() const;
mutable ClickHandlerPtr _rightActionLink; mutable ClickHandlerPtr _rightActionLink;
mutable ClickHandlerPtr _fastReplyLink; mutable ClickHandlerPtr _fastReplyLink;

View File

@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_service.h" #include "history/history_service.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "data/data_abstract_structure.h" #include "data/data_abstract_structure.h"

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_call.h" #include "history/view/media/history_view_call.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -17,16 +17,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; Call::Call(
} // namespace
HistoryCall::HistoryCall(
not_null<Element*> parent, not_null<Element*> parent,
not_null<Data::Call*> call) not_null<Data::Call*> call)
: HistoryMedia(parent) { : Media(parent) {
_duration = call->duration; _duration = call->duration;
_reason = call->finishReason; _reason = call->finishReason;
@ -48,7 +44,7 @@ HistoryCall::HistoryCall(
} }
} }
QSize HistoryCall::countOptimalSize() { QSize Call::countOptimalSize() {
const auto user = _parent->data()->history()->peer->asUser(); const auto user = _parent->data()->history()->peer->asUser();
_link = std::make_shared<LambdaClickHandler>([=] { _link = std::make_shared<LambdaClickHandler>([=] {
if (user) { if (user) {
@ -64,7 +60,7 @@ QSize HistoryCall::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
void HistoryCall::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Call::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintx = 0, painty = 0, paintw = width(), painth = height(); auto paintx = 0, painty = 0, paintw = width(), painth = height();
@ -102,7 +98,7 @@ void HistoryCall::draw(Painter &p, const QRect &r, TextSelection selection, crl:
icon.paint(p, paintw - st::historyCallIconPosition.x() - icon.width(), st::historyCallIconPosition.y() - topMinus, paintw); icon.paint(p, paintw - st::historyCallIconPosition.x() - icon.width(), st::historyCallIconPosition.y() - topMinus, paintw);
} }
TextState HistoryCall::textState(QPoint point, StateRequest request) const { TextState Call::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (QRect(0, 0, width(), height()).contains(point)) { if (QRect(0, 0, width(), height()).contains(point)) {
result.link = _link; result.link = _link;
@ -110,3 +106,5 @@ TextState HistoryCall::textState(QPoint point, StateRequest request) const {
} }
return result; return result;
} }
} // namespace HistoryView

View File

@ -7,16 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
namespace Data { namespace Data {
enum class CallFinishReason : char; enum class CallFinishReason : char;
struct Call; struct Call;
} // namespace Data } // namespace Data
class HistoryCall : public HistoryMedia { namespace HistoryView {
class Call : public Media {
public: public:
HistoryCall( Call(
not_null<Element*> parent, not_null<Element*> parent,
not_null<Data::Call*> call); not_null<Data::Call*> call);
@ -53,3 +55,5 @@ private:
ClickHandlerPtr _link; ClickHandlerPtr _link;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_contact.h" #include "history/view/media/history_view_contact.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -25,12 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h" #include "main/main_session.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState;
} // namespace
namespace { namespace {
ClickHandlerPtr sendMessageClickHandler(PeerData *peer) { ClickHandlerPtr sendMessageClickHandler(PeerData *peer) {
@ -61,13 +56,13 @@ ClickHandlerPtr addContactClickHandler(not_null<HistoryItem*> item) {
} // namespace } // namespace
HistoryContact::HistoryContact( Contact::Contact(
not_null<Element*> parent, not_null<Element*> parent,
UserId userId, UserId userId,
const QString &first, const QString &first,
const QString &last, const QString &last,
const QString &phone) const QString &phone)
: HistoryMedia(parent) : Media(parent)
, _userId(userId) , _userId(userId)
, _fname(first) , _fname(first)
, _lname(last) , _lname(last)
@ -81,11 +76,11 @@ HistoryContact::HistoryContact(
_phonew = st::normalFont->width(_phone); _phonew = st::normalFont->width(_phone);
} }
HistoryContact::~HistoryContact() { Contact::~Contact() {
history()->owner().unregisterContactView(_userId, _parent); history()->owner().unregisterContactView(_userId, _parent);
} }
void HistoryContact::updateSharedContactUserId(UserId userId) { void Contact::updateSharedContactUserId(UserId userId) {
if (_userId != userId) { if (_userId != userId) {
history()->owner().unregisterContactView(_userId, _parent); history()->owner().unregisterContactView(_userId, _parent);
_userId = userId; _userId = userId;
@ -93,7 +88,7 @@ void HistoryContact::updateSharedContactUserId(UserId userId) {
} }
} }
QSize HistoryContact::countOptimalSize() { QSize Contact::countOptimalSize() {
const auto item = _parent->data(); const auto item = _parent->data();
auto maxWidth = st::msgFileMinWidth; auto maxWidth = st::msgFileMinWidth;
@ -149,7 +144,7 @@ QSize HistoryContact::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
void HistoryContact::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Contact::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintx = 0, painty = 0, paintw = width(), painth = height(); auto paintx = 0, painty = 0, paintw = width(), painth = height();
@ -204,7 +199,7 @@ void HistoryContact::draw(Painter &p, const QRect &r, TextSelection selection, c
p.drawTextLeft(nameleft, statustop, paintw, _phone); p.drawTextLeft(nameleft, statustop, paintw, _phone);
} }
TextState HistoryContact::textState(QPoint point, StateRequest request) const { TextState Contact::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
auto nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0; auto nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0;
@ -223,3 +218,5 @@ TextState HistoryContact::textState(QPoint point, StateRequest request) const {
} }
return result; return result;
} }
} // namespace HistoryView

View File

@ -7,21 +7,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
namespace Ui { namespace Ui {
class EmptyUserpic; class EmptyUserpic;
} // namespace Ui } // namespace Ui
class HistoryContact : public HistoryMedia { namespace HistoryView {
class Contact : public Media {
public: public:
HistoryContact( Contact(
not_null<Element*> parent, not_null<Element*> parent,
UserId userId, UserId userId,
const QString &first, const QString &first,
const QString &last, const QString &last,
const QString &phone); const QString &phone);
~HistoryContact(); ~Contact();
void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override; void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override;
TextState textState(QPoint point, StateRequest request) const override; TextState textState(QPoint point, StateRequest request) const override;
@ -69,3 +71,5 @@ private:
QString _link; QString _link;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_document.h" #include "history/view/media/history_view_document.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -16,25 +16,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace HistoryView {
namespace { namespace {
constexpr auto kAudioVoiceMsgUpdateView = crl::time(100); constexpr auto kAudioVoiceMsgUpdateView = crl::time(100);
using TextState = HistoryView::TextState;
} // namespace } // namespace
HistoryDocument::HistoryDocument( Document::Document(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document) not_null<DocumentData*> document)
: HistoryFileMedia(parent, parent->data()) : File(parent, parent->data())
, _data(document) { , _data(document) {
const auto item = parent->data(); const auto item = parent->data();
auto caption = createCaption(item); auto caption = createCaption(item);
@ -53,19 +52,19 @@ HistoryDocument::HistoryDocument(
} }
} }
float64 HistoryDocument::dataProgress() const { float64 Document::dataProgress() const {
return _data->progress(); return _data->progress();
} }
bool HistoryDocument::dataFinished() const { bool Document::dataFinished() const {
return !_data->loading() && !_data->uploading(); return !_data->loading() && !_data->uploading();
} }
bool HistoryDocument::dataLoaded() const { bool Document::dataLoaded() const {
return _data->loaded(); return _data->loaded();
} }
void HistoryDocument::createComponents(bool caption) { void Document::createComponents(bool caption) {
uint64 mask = 0; uint64 mask = 0;
if (_data->isVoiceMessage()) { if (_data->isVoiceMessage()) {
mask |= HistoryDocumentVoice::Bit(); mask |= HistoryDocumentVoice::Bit();
@ -102,12 +101,12 @@ void HistoryDocument::createComponents(bool caption) {
} }
} }
void HistoryDocument::fillNamedFromData(HistoryDocumentNamed *named) { void Document::fillNamedFromData(HistoryDocumentNamed *named) {
const auto nameString = named->_name = _data->composeNameString(); const auto nameString = named->_name = _data->composeNameString();
named->_namew = st::semiboldFont->width(nameString); named->_namew = st::semiboldFont->width(nameString);
} }
QSize HistoryDocument::countOptimalSize() { QSize Document::countOptimalSize() {
const auto item = _parent->data(); const auto item = _parent->data();
auto captioned = Get<HistoryDocumentCaptioned>(); auto captioned = Get<HistoryDocumentCaptioned>();
@ -180,10 +179,10 @@ QSize HistoryDocument::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryDocument::countCurrentSize(int newWidth) { QSize Document::countCurrentSize(int newWidth) {
auto captioned = Get<HistoryDocumentCaptioned>(); auto captioned = Get<HistoryDocumentCaptioned>();
if (!captioned) { if (!captioned) {
return HistoryFileMedia::countCurrentSize(newWidth); return File::countCurrentSize(newWidth);
} }
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
@ -205,7 +204,7 @@ QSize HistoryDocument::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
const auto cornerDownload = downloadInCorner(); const auto cornerDownload = downloadInCorner();
@ -380,7 +379,7 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection,
// rescale waveform by going in waveform.size * bar_count 1D grid // rescale waveform by going in waveform.size * bar_count 1D grid
auto active = outbg ? (selected ? st::msgWaveformOutActiveSelected : st::msgWaveformOutActive) : (selected ? st::msgWaveformInActiveSelected : st::msgWaveformInActive); auto active = outbg ? (selected ? st::msgWaveformOutActiveSelected : st::msgWaveformOutActive) : (selected ? st::msgWaveformInActiveSelected : st::msgWaveformInActive);
auto inactive = outbg ? (selected ? st::msgWaveformOutInactiveSelected : st::msgWaveformOutInactive) : (selected ? st::msgWaveformInInactiveSelected : st::msgWaveformInInactive); auto inactive = outbg ? (selected ? st::msgWaveformOutInactiveSelected : st::msgWaveformOutInactive) : (selected ? st::msgWaveformInInactiveSelected : st::msgWaveformInInactive);
auto wf_size = wf ? wf->size() : Media::Player::kWaveformSamplesCount; auto wf_size = wf ? wf->size() : ::Media::Player::kWaveformSamplesCount;
auto availw = namewidth + st::msgWaveformSkip; auto availw = namewidth + st::msgWaveformSkip;
auto activew = qRound(availw * progress); auto activew = qRound(availw * progress);
if (!outbg if (!outbg
@ -458,14 +457,14 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection,
} }
} }
bool HistoryDocument::downloadInCorner() const { bool Document::downloadInCorner() const {
return _data->isAudioFile() return _data->isAudioFile()
&& _data->canBeStreamed() && _data->canBeStreamed()
&& !_data->inappPlaybackFailed() && !_data->inappPlaybackFailed()
&& IsServerMsgId(_parent->data()->id); && IsServerMsgId(_parent->data()->id);
} }
void HistoryDocument::drawCornerDownload(Painter &p, bool selected) const { void Document::drawCornerDownload(Painter &p, bool selected) const {
if (_data->loaded() || !downloadInCorner()) { if (_data->loaded() || !downloadInCorner()) {
return; return;
} }
@ -502,7 +501,7 @@ void HistoryDocument::drawCornerDownload(Painter &p, bool selected) const {
} }
} }
TextState HistoryDocument::cornerDownloadTextState( TextState Document::cornerDownloadTextState(
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
@ -520,7 +519,7 @@ TextState HistoryDocument::cornerDownloadTextState(
} }
TextState HistoryDocument::textState(QPoint point, StateRequest request) const { TextState Document::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -576,9 +575,9 @@ TextState HistoryDocument::textState(QPoint point, StateRequest request) const {
auto namewidth = width() - nameleft - nameright; auto namewidth = width() - nameleft - nameright;
auto waveformbottom = st::msgFilePadding.top() - topMinus + st::msgWaveformMax + st::msgWaveformMin; auto waveformbottom = st::msgFilePadding.top() - topMinus + st::msgWaveformMax + st::msgWaveformMin;
if (QRect(nameleft, nametop, namewidth, waveformbottom - nametop).contains(point)) { if (QRect(nameleft, nametop, namewidth, waveformbottom - nametop).contains(point)) {
const auto state = Media::Player::instance()->getState(AudioMsgId::Type::Voice); const auto state = ::Media::Player::instance()->getState(AudioMsgId::Type::Voice);
if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()) if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId())
&& !Media::Player::IsStoppedOrStopping(state.state)) { && !::Media::Player::IsStoppedOrStopping(state.state)) {
if (!voice->seeking()) { if (!voice->seeking()) {
voice->setSeekingStart((point.x() - nameleft) / float64(namewidth)); voice->setSeekingStart((point.x() - nameleft) / float64(namewidth));
} }
@ -617,7 +616,7 @@ TextState HistoryDocument::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
void HistoryDocument::updatePressed(QPoint point) { void Document::updatePressed(QPoint point) {
if (auto voice = Get<HistoryDocumentVoice>()) { if (auto voice = Get<HistoryDocumentVoice>()) {
if (voice->seeking()) { if (voice->seeking()) {
auto nameleft = 0, nameright = 0; auto nameleft = 0, nameright = 0;
@ -634,7 +633,7 @@ void HistoryDocument::updatePressed(QPoint point) {
} }
} }
TextSelection HistoryDocument::adjustSelection( TextSelection Document::adjustSelection(
TextSelection selection, TextSelection selection,
TextSelectType type) const { TextSelectType type) const {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
@ -643,18 +642,18 @@ TextSelection HistoryDocument::adjustSelection(
return selection; return selection;
} }
uint16 HistoryDocument::fullSelectionLength() const { uint16 Document::fullSelectionLength() const {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
return captioned->_caption.length(); return captioned->_caption.length();
} }
return 0; return 0;
} }
bool HistoryDocument::hasTextForCopy() const { bool Document::hasTextForCopy() const {
return Has<HistoryDocumentCaptioned>(); return Has<HistoryDocumentCaptioned>();
} }
TextForMimeData HistoryDocument::selectedText(TextSelection selection) const { TextForMimeData Document::selectedText(TextSelection selection) const {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
const auto &caption = captioned->_caption; const auto &caption = captioned->_caption;
return captioned->_caption.toTextForMimeData(selection); return captioned->_caption.toTextForMimeData(selection);
@ -662,17 +661,17 @@ TextForMimeData HistoryDocument::selectedText(TextSelection selection) const {
return TextForMimeData(); return TextForMimeData();
} }
bool HistoryDocument::uploading() const { bool Document::uploading() const {
return _data->uploading(); return _data->uploading();
} }
void HistoryDocument::setStatusSize(int newSize, qint64 realDuration) const { void Document::setStatusSize(int newSize, qint64 realDuration) const {
auto duration = _data->isSong() auto duration = _data->isSong()
? _data->song()->duration ? _data->song()->duration
: (_data->isVoiceMessage() : (_data->isVoiceMessage()
? _data->voice()->duration ? _data->voice()->duration
: -1); : -1);
HistoryFileMedia::setStatusSize(newSize, _data->size, duration, realDuration); File::setStatusSize(newSize, _data->size, duration, realDuration);
if (auto thumbed = Get<HistoryDocumentThumbed>()) { if (auto thumbed = Get<HistoryDocumentThumbed>()) {
if (_statusSize == FileStatusSizeReady) { if (_statusSize == FileStatusSizeReady) {
thumbed->_link = tr::lng_media_download(tr::now).toUpper(); thumbed->_link = tr::lng_media_download(tr::now).toUpper();
@ -689,7 +688,7 @@ void HistoryDocument::setStatusSize(int newSize, qint64 realDuration) const {
} }
} }
bool HistoryDocument::updateStatusText() const { bool Document::updateStatusText() const {
auto showPause = false; auto showPause = false;
auto statusSize = 0; auto statusSize = 0;
auto realDuration = 0; auto realDuration = 0;
@ -706,9 +705,9 @@ bool HistoryDocument::updateStatusText() const {
} }
if (_data->isVoiceMessage()) { if (_data->isVoiceMessage()) {
const auto state = Media::Player::instance()->getState(AudioMsgId::Type::Voice); const auto state = ::Media::Player::instance()->getState(AudioMsgId::Type::Voice);
if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()) if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId())
&& !Media::Player::IsStoppedOrStopping(state.state)) { && !::Media::Player::IsStoppedOrStopping(state.state)) {
if (auto voice = Get<HistoryDocumentVoice>()) { if (auto voice = Get<HistoryDocumentVoice>()) {
bool was = (voice->_playback != nullptr); bool was = (voice->_playback != nullptr);
voice->ensurePlayback(this); voice->ensurePlayback(this);
@ -727,26 +726,26 @@ bool HistoryDocument::updateStatusText() const {
statusSize = -1 - (state.position / state.frequency); statusSize = -1 - (state.position / state.frequency);
realDuration = (state.length / state.frequency); realDuration = (state.length / state.frequency);
showPause = Media::Player::ShowPauseIcon(state.state); showPause = ::Media::Player::ShowPauseIcon(state.state);
} else { } else {
if (auto voice = Get<HistoryDocumentVoice>()) { if (auto voice = Get<HistoryDocumentVoice>()) {
voice->checkPlaybackFinished(); voice->checkPlaybackFinished();
} }
} }
if (!showPause && (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()))) { if (!showPause && (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()))) {
showPause = Media::Player::instance()->isSeeking(AudioMsgId::Type::Voice); showPause = ::Media::Player::instance()->isSeeking(AudioMsgId::Type::Voice);
} }
} else if (_data->isAudioFile()) { } else if (_data->isAudioFile()) {
const auto state = Media::Player::instance()->getState(AudioMsgId::Type::Song); const auto state = ::Media::Player::instance()->getState(AudioMsgId::Type::Song);
if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()) if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId())
&& !Media::Player::IsStoppedOrStopping(state.state)) { && !::Media::Player::IsStoppedOrStopping(state.state)) {
statusSize = -1 - (state.position / state.frequency); statusSize = -1 - (state.position / state.frequency);
realDuration = (state.length / state.frequency); realDuration = (state.length / state.frequency);
showPause = Media::Player::ShowPauseIcon(state.state); showPause = ::Media::Player::ShowPauseIcon(state.state);
} else { } else {
} }
if (!showPause && (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()))) { if (!showPause && (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()))) {
showPause = Media::Player::instance()->isSeeking(AudioMsgId::Type::Song); showPause = ::Media::Player::instance()->isSeeking(AudioMsgId::Type::Song);
} }
} }
@ -756,15 +755,15 @@ bool HistoryDocument::updateStatusText() const {
return showPause; return showPause;
} }
QMargins HistoryDocument::bubbleMargins() const { QMargins Document::bubbleMargins() const {
return Get<HistoryDocumentThumbed>() ? QMargins(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top(), st::msgFileThumbPadding.left(), st::msgFileThumbPadding.bottom()) : st::msgPadding; return Get<HistoryDocumentThumbed>() ? QMargins(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top(), st::msgFileThumbPadding.left(), st::msgFileThumbPadding.bottom()) : st::msgPadding;
} }
bool HistoryDocument::hideForwardedFrom() const { bool Document::hideForwardedFrom() const {
return _data->isSong(); return _data->isSong();
} }
bool HistoryDocument::voiceProgressAnimationCallback(crl::time now) { bool Document::voiceProgressAnimationCallback(crl::time now) {
if (anim::Disabled()) { if (anim::Disabled()) {
now += (2 * kAudioVoiceMsgUpdateView); now += (2 * kAudioVoiceMsgUpdateView);
} }
@ -785,16 +784,16 @@ bool HistoryDocument::voiceProgressAnimationCallback(crl::time now) {
return false; return false;
} }
void HistoryDocument::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) { void Document::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
if (auto voice = Get<HistoryDocumentVoice>()) { if (auto voice = Get<HistoryDocumentVoice>()) {
if (pressed && p == voice->_seekl && !voice->seeking()) { if (pressed && p == voice->_seekl && !voice->seeking()) {
voice->startSeeking(); voice->startSeeking();
} else if (!pressed && voice->seeking()) { } else if (!pressed && voice->seeking()) {
const auto type = AudioMsgId::Type::Voice; const auto type = AudioMsgId::Type::Voice;
const auto state = Media::Player::instance()->getState(type); const auto state = ::Media::Player::instance()->getState(type);
if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()) && state.length) { if (state.id == AudioMsgId(_data, _parent->data()->fullId(), state.id.externalPlayId()) && state.length) {
const auto currentProgress = voice->seekingCurrent(); const auto currentProgress = voice->seekingCurrent();
Media::Player::instance()->finishSeeking( ::Media::Player::instance()->finishSeeking(
AudioMsgId::Type::Voice, AudioMsgId::Type::Voice,
currentProgress); currentProgress);
@ -805,11 +804,11 @@ void HistoryDocument::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool
voice->stopSeeking(); voice->stopSeeking();
} }
} }
HistoryFileMedia::clickHandlerPressedChanged(p, pressed); File::clickHandlerPressedChanged(p, pressed);
} }
void HistoryDocument::refreshParentId(not_null<HistoryItem*> realParent) { void Document::refreshParentId(not_null<HistoryItem*> realParent) {
HistoryFileMedia::refreshParentId(realParent); File::refreshParentId(realParent);
const auto fullId = realParent->fullId(); const auto fullId = realParent->fullId();
if (auto thumbed = Get<HistoryDocumentThumbed>()) { if (auto thumbed = Get<HistoryDocumentThumbed>()) {
@ -825,7 +824,7 @@ void HistoryDocument::refreshParentId(not_null<HistoryItem*> realParent) {
} }
} }
void HistoryDocument::parentTextUpdated() { void Document::parentTextUpdated() {
auto caption = (_parent->media() == this) auto caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Ui::Text::String(); : Ui::Text::String();
@ -839,9 +838,11 @@ void HistoryDocument::parentTextUpdated() {
history()->owner().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
TextWithEntities HistoryDocument::getCaption() const { TextWithEntities Document::getCaption() const {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
return captioned->_caption.toTextWithEntities(); return captioned->_caption.toTextWithEntities();
} }
return TextWithEntities(); return TextWithEntities();
} }
} // namespace HistoryView

View File

@ -7,16 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media_file.h" #include "history/view/media/history_view_file.h"
#include "base/runtime_composer.h" #include "base/runtime_composer.h"
struct HistoryDocumentNamed; struct HistoryDocumentNamed;
class HistoryDocument namespace HistoryView {
: public HistoryFileMedia
, public RuntimeComposer<HistoryDocument> { class Document
: public File
, public RuntimeComposer<Document> {
public: public:
HistoryDocument( Document(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document); not_null<DocumentData*> document);
@ -85,3 +87,5 @@ private:
not_null<DocumentData*> _data; not_null<DocumentData*> _data;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_file.h" #include "history/view/media/history_view_file.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -15,7 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "styles/style_history.h" #include "styles/style_history.h"
void HistoryFileMedia::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) { namespace HistoryView {
void File::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
if (p == _savel || p == _cancell) { if (p == _savel || p == _cancell) {
if (active && !dataLoaded()) { if (active && !dataLoaded()) {
ensureAnimation(); ensureAnimation();
@ -26,17 +28,17 @@ void HistoryFileMedia::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool
} }
} }
void HistoryFileMedia::thumbAnimationCallback() { void File::thumbAnimationCallback() {
history()->owner().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
void HistoryFileMedia::clickHandlerPressedChanged( void File::clickHandlerPressedChanged(
const ClickHandlerPtr &handler, const ClickHandlerPtr &handler,
bool pressed) { bool pressed) {
history()->owner().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
void HistoryFileMedia::setLinks( void File::setLinks(
FileClickHandlerPtr &&openl, FileClickHandlerPtr &&openl,
FileClickHandlerPtr &&savel, FileClickHandlerPtr &&savel,
FileClickHandlerPtr &&cancell) { FileClickHandlerPtr &&cancell) {
@ -45,14 +47,14 @@ void HistoryFileMedia::setLinks(
_cancell = std::move(cancell); _cancell = std::move(cancell);
} }
void HistoryFileMedia::refreshParentId(not_null<HistoryItem*> realParent) { void File::refreshParentId(not_null<HistoryItem*> realParent) {
const auto contextId = realParent->fullId(); const auto contextId = realParent->fullId();
_openl->setMessageId(contextId); _openl->setMessageId(contextId);
_savel->setMessageId(contextId); _savel->setMessageId(contextId);
_cancell->setMessageId(contextId); _cancell->setMessageId(contextId);
} }
void HistoryFileMedia::setStatusSize(int newSize, int fullSize, int duration, qint64 realDuration) const { void File::setStatusSize(int newSize, int fullSize, int duration, qint64 realDuration) const {
_statusSize = newSize; _statusSize = newSize;
if (_statusSize == FileStatusSizeReady) { if (_statusSize == FileStatusSizeReady) {
_statusText = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize)); _statusText = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize));
@ -67,7 +69,7 @@ void HistoryFileMedia::setStatusSize(int newSize, int fullSize, int duration, qi
} }
} }
void HistoryFileMedia::radialAnimationCallback(crl::time now) const { void File::radialAnimationCallback(crl::time now) const {
const auto updated = [&] { const auto updated = [&] {
return _animation->radial.update( return _animation->radial.update(
dataProgress(), dataProgress(),
@ -82,7 +84,7 @@ void HistoryFileMedia::radialAnimationCallback(crl::time now) const {
} }
} }
void HistoryFileMedia::ensureAnimation() const { void File::ensureAnimation() const {
if (!_animation) { if (!_animation) {
_animation = std::make_unique<AnimationData>([=](crl::time now) { _animation = std::make_unique<AnimationData>([=](crl::time now) {
radialAnimationCallback(now); radialAnimationCallback(now);
@ -90,14 +92,14 @@ void HistoryFileMedia::ensureAnimation() const {
} }
} }
void HistoryFileMedia::checkAnimationFinished() const { void File::checkAnimationFinished() const {
if (_animation && !_animation->a_thumbOver.animating() && !_animation->radial.animating()) { if (_animation && !_animation->a_thumbOver.animating() && !_animation->radial.animating()) {
if (dataLoaded()) { if (dataLoaded()) {
_animation.reset(); _animation.reset();
} }
} }
} }
void HistoryFileMedia::setDocumentLinks( void File::setDocumentLinks(
not_null<DocumentData*> document, not_null<DocumentData*> document,
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
const auto context = realParent->fullId(); const auto context = realParent->fullId();
@ -107,4 +109,6 @@ void HistoryFileMedia::setDocumentLinks(
std::make_shared<DocumentCancelClickHandler>(document, context)); std::make_shared<DocumentCancelClickHandler>(document, context));
} }
HistoryFileMedia::~HistoryFileMedia() = default; File::~File() = default;
} // namespace HistoryView

View File

@ -7,16 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
class HistoryFileMedia : public HistoryMedia { namespace HistoryView {
class File : public Media {
public: public:
HistoryFileMedia( File(
not_null<Element*> parent, not_null<Element*> parent,
not_null<HistoryItem*> realParent) not_null<HistoryItem*> realParent)
: HistoryMedia(parent) : Media(parent)
, _realParent(realParent) { , _realParent(realParent) {
} }
@ -36,7 +38,7 @@ public:
return true; return true;
} }
~HistoryFileMedia(); ~File();
protected: protected:
using FileClickHandlerPtr = std::shared_ptr<FileClickHandler>; using FileClickHandlerPtr = std::shared_ptr<FileClickHandler>;
@ -104,3 +106,5 @@ protected:
mutable std::unique_ptr<AnimationData> _animation; mutable std::unique_ptr<AnimationData> _animation;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_game.h" #include "history/view/media/history_view_game.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -13,24 +13,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_game.h" #include "data/data_game.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; Game::Game(
} // namespace
HistoryGame::HistoryGame(
not_null<Element*> parent, not_null<Element*> parent,
not_null<GameData*> data, not_null<GameData*> data,
const TextWithEntities &consumed) const TextWithEntities &consumed)
: HistoryMedia(parent) : Media(parent)
, _data(data) , _data(data)
, _title(st::msgMinWidth - st::webPageLeft) , _title(st::msgMinWidth - st::webPageLeft)
, _description(st::msgMinWidth - st::webPageLeft) { , _description(st::msgMinWidth - st::webPageLeft) {
@ -43,7 +39,7 @@ HistoryGame::HistoryGame(
history()->owner().registerGameView(_data, _parent); history()->owner().registerGameView(_data, _parent);
} }
QSize HistoryGame::countOptimalSize() { QSize Game::countOptimalSize() {
auto lineHeight = unitedLineHeight(); auto lineHeight = unitedLineHeight();
const auto item = _parent->data(); const auto item = _parent->data();
@ -128,7 +124,7 @@ QSize HistoryGame::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
void HistoryGame::refreshParentId(not_null<HistoryItem*> realParent) { void Game::refreshParentId(not_null<HistoryItem*> realParent) {
if (_openl) { if (_openl) {
_openl->setMessageId(realParent->fullId()); _openl->setMessageId(realParent->fullId());
} }
@ -137,7 +133,7 @@ void HistoryGame::refreshParentId(not_null<HistoryItem*> realParent) {
} }
} }
QSize HistoryGame::countCurrentSize(int newWidth) { QSize Game::countCurrentSize(int newWidth) {
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
auto innerWidth = newWidth - st::msgPadding.left() - st::webPageLeft - st::msgPadding.right(); auto innerWidth = newWidth - st::msgPadding.left() - st::webPageLeft - st::msgPadding.right();
@ -186,17 +182,17 @@ QSize HistoryGame::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
TextSelection HistoryGame::toDescriptionSelection( TextSelection Game::toDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::UnshiftItemSelection(selection, _title); return UnshiftItemSelection(selection, _title);
} }
TextSelection HistoryGame::fromDescriptionSelection( TextSelection Game::fromDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::ShiftItemSelection(selection, _title); return ShiftItemSelection(selection, _title);
} }
void HistoryGame::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Game::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintw = width(), painth = height(); auto paintw = width(), painth = height();
@ -268,7 +264,7 @@ void HistoryGame::draw(Painter &p, const QRect &r, TextSelection selection, crl:
} }
} }
TextState HistoryGame::textState(QPoint point, StateRequest request) const { TextState Game::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -343,7 +339,7 @@ TextState HistoryGame::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
TextSelection HistoryGame::adjustSelection(TextSelection selection, TextSelectType type) const { TextSelection Game::adjustSelection(TextSelection selection, TextSelectType type) const {
if (!_descriptionLines || selection.to <= _title.length()) { if (!_descriptionLines || selection.to <= _title.length()) {
return _title.adjustSelection(selection, type); return _title.adjustSelection(selection, type);
} }
@ -355,19 +351,19 @@ TextSelection HistoryGame::adjustSelection(TextSelection selection, TextSelectTy
return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to }; return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to };
} }
void HistoryGame::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) { void Game::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
if (_attach) { if (_attach) {
_attach->clickHandlerActiveChanged(p, active); _attach->clickHandlerActiveChanged(p, active);
} }
} }
void HistoryGame::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) { void Game::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
if (_attach) { if (_attach) {
_attach->clickHandlerPressedChanged(p, pressed); _attach->clickHandlerPressedChanged(p, pressed);
} }
} }
TextForMimeData HistoryGame::selectedText(TextSelection selection) const { TextForMimeData Game::selectedText(TextSelection selection) const {
auto titleResult = _title.toTextForMimeData(selection); auto titleResult = _title.toTextForMimeData(selection);
auto descriptionResult = _description.toTextForMimeData( auto descriptionResult = _description.toTextForMimeData(
toDescriptionSelection(selection)); toDescriptionSelection(selection));
@ -379,7 +375,7 @@ TextForMimeData HistoryGame::selectedText(TextSelection selection) const {
return titleResult.append('\n').append(std::move(descriptionResult)); return titleResult.append('\n').append(std::move(descriptionResult));
} }
void HistoryGame::playAnimation(bool autoplay) { void Game::playAnimation(bool autoplay) {
if (_attach) { if (_attach) {
if (autoplay) { if (autoplay) {
_attach->autoplayAnimation(); _attach->autoplayAnimation();
@ -389,7 +385,7 @@ void HistoryGame::playAnimation(bool autoplay) {
} }
} }
QMargins HistoryGame::inBubblePadding() const { QMargins Game::inBubblePadding() const {
auto lshift = st::msgPadding.left() + st::webPageLeft; auto lshift = st::msgPadding.left() + st::webPageLeft;
auto rshift = st::msgPadding.right(); auto rshift = st::msgPadding.right();
auto bshift = isBubbleBottom() ? st::msgPadding.left() : st::mediaInBubbleSkip; auto bshift = isBubbleBottom() ? st::msgPadding.left() : st::mediaInBubbleSkip;
@ -397,7 +393,7 @@ QMargins HistoryGame::inBubblePadding() const {
return QMargins(lshift, tshift, rshift, bshift); return QMargins(lshift, tshift, rshift, bshift);
} }
int HistoryGame::bottomInfoPadding() const { int Game::bottomInfoPadding() const {
if (!isBubbleBottom()) return 0; if (!isBubbleBottom()) return 0;
auto result = st::msgDateFont->height; auto result = st::msgDateFont->height;
@ -411,7 +407,7 @@ int HistoryGame::bottomInfoPadding() const {
return result; return result;
} }
void HistoryGame::parentTextUpdated() { void Game::parentTextUpdated() {
if (const auto media = _parent->data()->media()) { if (const auto media = _parent->data()->media()) {
const auto consumed = media->consumedMessageText(); const auto consumed = media->consumedMessageText();
if (!consumed.text.isEmpty()) { if (!consumed.text.isEmpty()) {
@ -426,6 +422,8 @@ void HistoryGame::parentTextUpdated() {
} }
} }
HistoryGame::~HistoryGame() { Game::~Game() {
history()->owner().unregisterGameView(_data, _parent); history()->owner().unregisterGameView(_data, _parent);
} }
} // namespace HistoryView

View File

@ -7,13 +7,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
class ReplyMarkupClickHandler; class ReplyMarkupClickHandler;
class HistoryGame : public HistoryMedia { namespace HistoryView {
class Game : public Media {
public: public:
HistoryGame( Game(
not_null<Element*> parent, not_null<Element*> parent,
not_null<GameData*> data, not_null<GameData*> data,
const TextWithEntities &consumed); const TextWithEntities &consumed);
@ -69,13 +71,13 @@ public:
return true; return true;
} }
HistoryMedia *attach() const { Media *attach() const {
return _attach.get(); return _attach.get();
} }
void parentTextUpdated() override; void parentTextUpdated() override;
~HistoryGame(); ~Game();
private: private:
void playAnimation(bool autoplay) override; void playAnimation(bool autoplay) override;
@ -89,7 +91,7 @@ private:
not_null<GameData*> _data; not_null<GameData*> _data;
std::shared_ptr<ReplyMarkupClickHandler> _openl; std::shared_ptr<ReplyMarkupClickHandler> _openl;
std::unique_ptr<HistoryMedia> _attach; std::unique_ptr<Media> _attach;
int _titleLines, _descriptionLines; int _titleLines, _descriptionLines;
@ -98,3 +100,5 @@ private:
int _gameTagWidth = 0; int _gameTagWidth = 0;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_gif.h" #include "history/view/media/history_view_gif.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -29,12 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h" #include "data/data_document.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState;
} // namespace
namespace { namespace {
constexpr auto kMaxGifForwardedBarLines = 4; constexpr auto kMaxGifForwardedBarLines = 4;
@ -47,10 +42,10 @@ int gifMaxStatusWidth(DocumentData *document) {
} // namespace } // namespace
HistoryGif::HistoryGif( Gif::Gif(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document) not_null<DocumentData*> document)
: HistoryFileMedia(parent, parent->data()) : File(parent, parent->data())
, _data(document) , _data(document)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
const auto item = parent->data(); const auto item = parent->data();
@ -62,7 +57,7 @@ HistoryGif::HistoryGif(
_data->loadThumbnail(item->fullId()); _data->loadThumbnail(item->fullId());
} }
QSize HistoryGif::countOptimalSize() { QSize Gif::countOptimalSize() {
if (_parent->media() != this) { if (_parent->media() != this) {
_caption = Ui::Text::String(); _caption = Ui::Text::String();
} else if (_caption.hasSkipBlock()) { } else if (_caption.hasSkipBlock()) {
@ -70,11 +65,11 @@ QSize HistoryGif::countOptimalSize() {
_parent->skipBlockWidth(), _parent->skipBlockWidth(),
_parent->skipBlockHeight()); _parent->skipBlockHeight());
} }
if (_gif && _gif->state() == Media::Clip::State::Error) { if (_gif && _gif->state() == ::Media::Clip::State::Error) {
if (!_gif->autoplay()) { if (!_gif->autoplay()) {
Ui::show(Box<InformBox>(tr::lng_gif_error(tr::now))); Ui::show(Box<InformBox>(tr::lng_gif_error(tr::now)));
} }
setClipReader(Media::Clip::ReaderPointer::Bad()); setClipReader(::Media::Clip::ReaderPointer::Bad());
} }
const auto maxSize = _data->isVideoMessage() const auto maxSize = _data->isVideoMessage()
@ -123,7 +118,7 @@ QSize HistoryGif::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryGif::countCurrentSize(int newWidth) { QSize Gif::countCurrentSize(int newWidth) {
auto availableWidth = newWidth; auto availableWidth = newWidth;
const auto maxSize = _data->isVideoMessage() const auto maxSize = _data->isVideoMessage()
@ -156,7 +151,7 @@ QSize HistoryGif::countCurrentSize(int newWidth) {
accumulate_max(newWidth, _parent->infoWidth() + 2 * st::msgDateImgDelta + st::msgDateImgPadding.x()); accumulate_max(newWidth, _parent->infoWidth() + 2 * st::msgDateImgDelta + st::msgDateImgPadding.x());
const auto reader = activeRoundPlayer() ? nullptr : currentReader(); const auto reader = activeRoundPlayer() ? nullptr : currentReader();
if (reader) { if (reader) {
const auto own = (reader->mode() == Media::Clip::Reader::Mode::Gif); const auto own = (reader->mode() == ::Media::Clip::Reader::Mode::Gif);
if (own && !reader->started()) { if (own && !reader->started()) {
auto isRound = _data->isVideoMessage(); auto isRound = _data->isVideoMessage();
auto inWebPage = (_parent->media() != this); auto inWebPage = (_parent->media() != this);
@ -215,7 +210,7 @@ QSize HistoryGif::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
QSize HistoryGif::videoSize() const { QSize Gif::videoSize() const {
if (const auto player = activeRoundPlayer()) { if (const auto player = activeRoundPlayer()) {
return player->videoSize(); return player->videoSize();
} else if (const auto reader = currentReader()) { } else if (const auto reader = currentReader()) {
@ -229,11 +224,11 @@ QSize HistoryGif::videoSize() const {
} }
} }
bool HistoryGif::autoplayEnabled() const { bool Gif::autoplayEnabled() const {
return history()->session().settings().autoplayGifs(); return history()->session().settings().autoplayGifs();
} }
void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
const auto item = _parent->data(); const auto item = _parent->data();
@ -311,7 +306,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, crl::
} }
} }
if (player) { if (player) {
auto request = Media::Streaming::FrameRequest(); auto request = ::Media::Streaming::FrameRequest();
request.outer = QSize(usew, painth) * cIntRetinaFactor(); request.outer = QSize(usew, painth) * cIntRetinaFactor();
request.resize = QSize(_thumbw, _thumbh) * cIntRetinaFactor(); request.resize = QSize(_thumbw, _thumbh) * cIntRetinaFactor();
request.corners = roundCorners; request.corners = roundCorners;
@ -537,7 +532,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, crl::
} }
} }
TextState HistoryGif::textState(QPoint point, StateRequest request) const { TextState Gif::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -685,15 +680,15 @@ TextState HistoryGif::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
TextForMimeData HistoryGif::selectedText(TextSelection selection) const { TextForMimeData Gif::selectedText(TextSelection selection) const {
return _caption.toTextForMimeData(selection); return _caption.toTextForMimeData(selection);
} }
bool HistoryGif::uploading() const { bool Gif::uploading() const {
return _data->uploading(); return _data->uploading();
} }
bool HistoryGif::needsBubble() const { bool Gif::needsBubble() const {
if (_data->isVideoMessage()) { if (_data->isVideoMessage()) {
return false; return false;
} }
@ -708,7 +703,7 @@ bool HistoryGif::needsBubble() const {
return false; return false;
} }
int HistoryGif::additionalWidth() const { int Gif::additionalWidth() const {
const auto item = _parent->data(); const auto item = _parent->data();
return additionalWidth( return additionalWidth(
item->Get<HistoryMessageVia>(), item->Get<HistoryMessageVia>(),
@ -716,19 +711,19 @@ int HistoryGif::additionalWidth() const {
item->Get<HistoryMessageForwarded>()); item->Get<HistoryMessageForwarded>());
} }
QString HistoryGif::mediaTypeString() const { QString Gif::mediaTypeString() const {
return _data->isVideoMessage() return _data->isVideoMessage()
? tr::lng_in_dlg_video_message(tr::now) ? tr::lng_in_dlg_video_message(tr::now)
: qsl("GIF"); : qsl("GIF");
} }
bool HistoryGif::isSeparateRoundVideo() const { bool Gif::isSeparateRoundVideo() const {
return _data->isVideoMessage() return _data->isVideoMessage()
&& (_parent->media() == this) && (_parent->media() == this)
&& !_parent->hasBubble(); && !_parent->hasBubble();
} }
void HistoryGif::setStatusSize(int newSize) const { void Gif::setStatusSize(int newSize) const {
if (_data->isVideoMessage()) { if (_data->isVideoMessage()) {
_statusSize = newSize; _statusSize = newSize;
if (newSize < 0) { if (newSize < 0) {
@ -737,11 +732,11 @@ void HistoryGif::setStatusSize(int newSize) const {
_statusText = formatDurationText(_data->getDuration()); _statusText = formatDurationText(_data->getDuration());
} }
} else { } else {
HistoryFileMedia::setStatusSize(newSize, _data->size, -2, 0); File::setStatusSize(newSize, _data->size, -2, 0);
} }
} }
void HistoryGif::updateStatusText() const { void Gif::updateStatusText() const {
auto showPause = false; auto showPause = false;
auto statusSize = 0; auto statusSize = 0;
auto realDuration = 0; auto realDuration = 0;
@ -757,9 +752,9 @@ void HistoryGif::updateStatusText() const {
const auto state = video->prepareLegacyState(); const auto state = video->prepareLegacyState();
if (state.length) { if (state.length) {
auto position = int64(0); auto position = int64(0);
if (Media::Player::IsStoppedAtEnd(state.state)) { if (::Media::Player::IsStoppedAtEnd(state.state)) {
position = state.length; position = state.length;
} else if (!Media::Player::IsStoppedOrStopping(state.state)) { } else if (!::Media::Player::IsStoppedOrStopping(state.state)) {
position = state.position; position = state.position;
} }
statusSize = -1 - int((state.length - position) / state.frequency + 1); statusSize = -1 - int((state.length - position) / state.frequency + 1);
@ -775,7 +770,7 @@ void HistoryGif::updateStatusText() const {
} }
} }
QString HistoryGif::additionalInfoString() const { QString Gif::additionalInfoString() const {
if (_data->isVideoMessage()) { if (_data->isVideoMessage()) {
updateStatusText(); updateStatusText();
return _statusText; return _statusText;
@ -783,18 +778,18 @@ QString HistoryGif::additionalInfoString() const {
return QString(); return QString();
} }
bool HistoryGif::isReadyForOpen() const { bool Gif::isReadyForOpen() const {
return _data->loaded(); return _data->loaded();
} }
void HistoryGif::parentTextUpdated() { void Gif::parentTextUpdated() {
_caption = (_parent->media() == this) _caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Ui::Text::String(); : Ui::Text::String();
history()->owner().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const { int Gif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const {
int result = 0; int result = 0;
if (forwarded) { if (forwarded) {
accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + forwarded->text.maxWidth() + st::msgReplyPadding.right()); accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + forwarded->text.maxWidth() + st::msgReplyPadding.right());
@ -807,20 +802,20 @@ int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessa
return result; return result;
} }
Media::Streaming::Player *HistoryGif::activeRoundPlayer() const { ::Media::Streaming::Player *Gif::activeRoundPlayer() const {
return Media::Player::instance()->roundVideoPlayer(_parent->data()); return ::Media::Player::instance()->roundVideoPlayer(_parent->data());
} }
Media::Clip::Reader *HistoryGif::currentReader() const { ::Media::Clip::Reader *Gif::currentReader() const {
return (_gif && _gif->ready()) ? _gif.get() : nullptr; return (_gif && _gif->ready()) ? _gif.get() : nullptr;
} }
Media::View::PlaybackProgress *HistoryGif::videoPlayback() const { ::Media::View::PlaybackProgress *Gif::videoPlayback() const {
return Media::Player::instance()->roundVideoPlayback(_parent->data()); return ::Media::Player::instance()->roundVideoPlayback(_parent->data());
} }
void HistoryGif::clipCallback(Media::Clip::Notification notification) { void Gif::clipCallback(::Media::Clip::Notification notification) {
using namespace Media::Clip; using namespace ::Media::Clip;
const auto reader = _gif.get(); const auto reader = _gif.get();
if (!reader) { if (!reader) {
@ -852,7 +847,7 @@ void HistoryGif::clipCallback(Media::Clip::Notification notification) {
} }
} }
void HistoryGif::playAnimation(bool autoplay) { void Gif::playAnimation(bool autoplay) {
if (_data->isVideoMessage() && !autoplay) { if (_data->isVideoMessage() && !autoplay) {
return; return;
} else if (_gif && autoplay) { } else if (_gif && autoplay) {
@ -861,14 +856,14 @@ void HistoryGif::playAnimation(bool autoplay) {
Core::App().showDocument(_data, _parent->data()); Core::App().showDocument(_data, _parent->data());
return; return;
} }
using Mode = Media::Clip::Reader::Mode; using Mode = ::Media::Clip::Reader::Mode;
if (_gif) { if (_gif) {
stopAnimation(); stopAnimation();
} else if (_data->loaded(DocumentData::FilePathResolve::Checked)) { } else if (_data->loaded(DocumentData::FilePathResolve::Checked)) {
if (!autoplayEnabled()) { if (!autoplayEnabled()) {
history()->owner().stopAutoplayAnimations(); history()->owner().stopAutoplayAnimations();
} }
setClipReader(Media::Clip::MakeReader( setClipReader(::Media::Clip::MakeReader(
_data, _data,
_parent->data()->fullId(), _parent->data()->fullId(),
[=](auto notification) { clipCallback(notification); }, [=](auto notification) { clipCallback(notification); },
@ -879,7 +874,7 @@ void HistoryGif::playAnimation(bool autoplay) {
} }
} }
void HistoryGif::stopAnimation() { void Gif::stopAnimation() {
if (_gif) { if (_gif) {
clearClipReader(); clearClipReader();
history()->owner().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
@ -887,7 +882,7 @@ void HistoryGif::stopAnimation() {
} }
} }
void HistoryGif::setClipReader(Media::Clip::ReaderPointer gif) { void Gif::setClipReader(::Media::Clip::ReaderPointer gif) {
if (_gif) { if (_gif) {
history()->owner().unregisterAutoplayAnimation(_gif.get()); history()->owner().unregisterAutoplayAnimation(_gif.get());
} }
@ -897,26 +892,28 @@ void HistoryGif::setClipReader(Media::Clip::ReaderPointer gif) {
} }
} }
HistoryGif::~HistoryGif() { Gif::~Gif() {
clearClipReader(); clearClipReader();
} }
float64 HistoryGif::dataProgress() const { float64 Gif::dataProgress() const {
return (_data->uploading() || _parent->data()->id > 0) return (_data->uploading() || _parent->data()->id > 0)
? _data->progress() ? _data->progress()
: 0; : 0;
} }
bool HistoryGif::dataFinished() const { bool Gif::dataFinished() const {
return (_parent->data()->id > 0) return (_parent->data()->id > 0)
? (!_data->loading() && !_data->uploading()) ? (!_data->loading() && !_data->uploading())
: false; : false;
} }
bool HistoryGif::dataLoaded() const { bool Gif::dataLoaded() const {
return (_parent->data()->id > 0) ? _data->loaded() : false; return (_parent->data()->id > 0) ? _data->loaded() : false;
} }
bool HistoryGif::needInfoDisplay() const { bool Gif::needInfoDisplay() const {
return (_parent->data()->id < 0 || _parent->isUnderCursor()); return (_parent->data()->id < 0 || _parent->isUnderCursor());
} }
} // namespace HistoryView

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media_file.h" #include "history/view/media/history_view_file.h"
struct HistoryMessageVia; struct HistoryMessageVia;
struct HistoryMessageReply; struct HistoryMessageReply;
@ -25,9 +25,11 @@ class Player;
} // namespace Streaming } // namespace Streaming
} // namespace Media } // namespace Media
class HistoryGif : public HistoryFileMedia { namespace HistoryView {
class Gif : public File {
public: public:
HistoryGif( Gif(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document); not_null<DocumentData*> document);
@ -72,16 +74,16 @@ public:
void parentTextUpdated() override; void parentTextUpdated() override;
~HistoryGif(); ~Gif();
protected: protected:
float64 dataProgress() const override; float64 dataProgress() const override;
bool dataFinished() const override; bool dataFinished() const override;
bool dataLoaded() const override; bool dataLoaded() const override;
void setClipReader(Media::Clip::ReaderPointer gif); void setClipReader(::Media::Clip::ReaderPointer gif);
void clearClipReader() { void clearClipReader() {
setClipReader(Media::Clip::ReaderPointer()); setClipReader(::Media::Clip::ReaderPointer());
} }
private: private:
@ -90,10 +92,10 @@ private:
QSize countOptimalSize() override; QSize countOptimalSize() override;
QSize countCurrentSize(int newWidth) override; QSize countCurrentSize(int newWidth) override;
QSize videoSize() const; QSize videoSize() const;
Media::Streaming::Player *activeRoundPlayer() const; ::Media::Streaming::Player *activeRoundPlayer() const;
Media::Clip::Reader *currentReader() const; ::Media::Clip::Reader *currentReader() const;
Media::View::PlaybackProgress *videoPlayback() const; ::Media::View::PlaybackProgress *videoPlayback() const;
void clipCallback(Media::Clip::Notification notification); void clipCallback(::Media::Clip::Notification notification);
bool needInfoDisplay() const; bool needInfoDisplay() const;
int additionalWidth( int additionalWidth(
@ -108,9 +110,11 @@ private:
int _thumbw = 1; int _thumbw = 1;
int _thumbh = 1; int _thumbh = 1;
Ui::Text::String _caption; Ui::Text::String _caption;
Media::Clip::ReaderPointer _gif; ::Media::Clip::ReaderPointer _gif;
void setStatusSize(int newSize) const; void setStatusSize(int newSize) const;
void updateStatusText() const; void updateStatusText() const;
}; };
} // namespace HistoryView

View File

@ -5,37 +5,33 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_invoice.h" #include "history/view/media/history_view_invoice.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_photo.h" #include "history/view/media/history_view_photo.h"
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; Invoice::Invoice(
} // namespace
HistoryInvoice::HistoryInvoice(
not_null<Element*> parent, not_null<Element*> parent,
not_null<Data::Invoice*> invoice) not_null<Data::Invoice*> invoice)
: HistoryMedia(parent) : Media(parent)
, _title(st::msgMinWidth) , _title(st::msgMinWidth)
, _description(st::msgMinWidth) , _description(st::msgMinWidth)
, _status(st::msgMinWidth) { , _status(st::msgMinWidth) {
fillFromData(invoice); fillFromData(invoice);
} }
void HistoryInvoice::fillFromData(not_null<Data::Invoice*> invoice) { void Invoice::fillFromData(not_null<Data::Invoice*> invoice) {
if (invoice->photo) { if (invoice->photo) {
_attach = std::make_unique<HistoryPhoto>( _attach = std::make_unique<Photo>(
_parent, _parent,
_parent->data(), _parent->data(),
invoice->photo); invoice->photo);
@ -87,7 +83,7 @@ void HistoryInvoice::fillFromData(not_null<Data::Invoice*> invoice) {
} }
} }
QSize HistoryInvoice::countOptimalSize() { QSize Invoice::countOptimalSize() {
auto lineHeight = unitedLineHeight(); auto lineHeight = unitedLineHeight();
if (_attach) { if (_attach) {
@ -141,7 +137,7 @@ QSize HistoryInvoice::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryInvoice::countCurrentSize(int newWidth) { QSize Invoice::countCurrentSize(int newWidth) {
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
auto innerWidth = newWidth - st::msgPadding.left() - st::msgPadding.right(); auto innerWidth = newWidth - st::msgPadding.left() - st::msgPadding.right();
@ -186,23 +182,23 @@ QSize HistoryInvoice::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
TextSelection HistoryInvoice::toDescriptionSelection( TextSelection Invoice::toDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::UnshiftItemSelection(selection, _title); return UnshiftItemSelection(selection, _title);
} }
TextSelection HistoryInvoice::fromDescriptionSelection( TextSelection Invoice::fromDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::ShiftItemSelection(selection, _title); return ShiftItemSelection(selection, _title);
} }
void HistoryInvoice::refreshParentId(not_null<HistoryItem*> realParent) { void Invoice::refreshParentId(not_null<HistoryItem*> realParent) {
if (_attach) { if (_attach) {
_attach->refreshParentId(realParent); _attach->refreshParentId(realParent);
} }
} }
void HistoryInvoice::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Invoice::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintw = width(), painth = height(); auto paintw = width(), painth = height();
@ -275,7 +271,7 @@ void HistoryInvoice::draw(Painter &p, const QRect &r, TextSelection selection, c
} }
} }
TextState HistoryInvoice::textState(QPoint point, StateRequest request) const { TextState Invoice::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -337,7 +333,7 @@ TextState HistoryInvoice::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
TextSelection HistoryInvoice::adjustSelection(TextSelection selection, TextSelectType type) const { TextSelection Invoice::adjustSelection(TextSelection selection, TextSelectType type) const {
if (!_descriptionHeight || selection.to <= _title.length()) { if (!_descriptionHeight || selection.to <= _title.length()) {
return _title.adjustSelection(selection, type); return _title.adjustSelection(selection, type);
} }
@ -349,19 +345,19 @@ TextSelection HistoryInvoice::adjustSelection(TextSelection selection, TextSelec
return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to }; return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to };
} }
void HistoryInvoice::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) { void Invoice::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
if (_attach) { if (_attach) {
_attach->clickHandlerActiveChanged(p, active); _attach->clickHandlerActiveChanged(p, active);
} }
} }
void HistoryInvoice::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) { void Invoice::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
if (_attach) { if (_attach) {
_attach->clickHandlerPressedChanged(p, pressed); _attach->clickHandlerPressedChanged(p, pressed);
} }
} }
TextForMimeData HistoryInvoice::selectedText(TextSelection selection) const { TextForMimeData Invoice::selectedText(TextSelection selection) const {
auto titleResult = _title.toTextForMimeData(selection); auto titleResult = _title.toTextForMimeData(selection);
auto descriptionResult = _description.toTextForMimeData( auto descriptionResult = _description.toTextForMimeData(
toDescriptionSelection(selection)); toDescriptionSelection(selection));
@ -373,7 +369,7 @@ TextForMimeData HistoryInvoice::selectedText(TextSelection selection) const {
return titleResult.append('\n').append(std::move(descriptionResult)); return titleResult.append('\n').append(std::move(descriptionResult));
} }
QMargins HistoryInvoice::inBubblePadding() const { QMargins Invoice::inBubblePadding() const {
auto lshift = st::msgPadding.left(); auto lshift = st::msgPadding.left();
auto rshift = st::msgPadding.right(); auto rshift = st::msgPadding.right();
auto bshift = isBubbleBottom() ? st::msgPadding.top() : st::mediaInBubbleSkip; auto bshift = isBubbleBottom() ? st::msgPadding.top() : st::mediaInBubbleSkip;
@ -381,7 +377,7 @@ QMargins HistoryInvoice::inBubblePadding() const {
return QMargins(lshift, tshift, rshift, bshift); return QMargins(lshift, tshift, rshift, bshift);
} }
int HistoryInvoice::bottomInfoPadding() const { int Invoice::bottomInfoPadding() const {
if (!isBubbleBottom()) return 0; if (!isBubbleBottom()) return 0;
auto result = st::msgDateFont->height; auto result = st::msgDateFont->height;
@ -442,3 +438,5 @@ QString FillAmountAndCurrency(uint64 amount, const QString &currency) {
//auto amountText = qsl("%1,%2").arg(amountBucks).arg(amountCents, 2, 10, QChar('0')); //auto amountText = qsl("%1,%2").arg(amountBucks).arg(amountCents, 2, 10, QChar('0'));
//return currencyText + amountText; //return currencyText + amountText;
} }
} // namespace HistoryView

View File

@ -7,15 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
namespace Data { namespace Data {
struct Invoice; struct Invoice;
} // namespace Data } // namespace Data
class HistoryInvoice : public HistoryMedia { namespace HistoryView {
class Invoice : public Media {
public: public:
HistoryInvoice( Invoice(
not_null<Element*> parent, not_null<Element*> parent,
not_null<Data::Invoice*> invoice); not_null<Data::Invoice*> invoice);
@ -64,7 +66,7 @@ public:
return false; return false;
} }
HistoryMedia *attach() const { Media *attach() const {
return _attach.get(); return _attach.get();
} }
@ -79,7 +81,7 @@ private:
QMargins inBubblePadding() const; QMargins inBubblePadding() const;
int bottomInfoPadding() const; int bottomInfoPadding() const;
std::unique_ptr<HistoryMedia> _attach; std::unique_ptr<Media> _attach;
int _titleHeight = 0; int _titleHeight = 0;
int _descriptionHeight = 0; int _descriptionHeight = 0;
@ -92,3 +94,5 @@ private:
}; };
QString FillAmountAndCurrency(uint64 amount, const QString &currency); QString FillAmountAndCurrency(uint64 amount, const QString &currency);
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_location.h" #include "history/view/media/history_view_location.h"
#include "layout.h" #include "layout.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
@ -19,18 +19,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_location.h" #include "data/data_location.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; Location::Location(
} // namespace
HistoryLocation::HistoryLocation(
not_null<Element*> parent, not_null<Element*> parent,
not_null<Data::LocationThumbnail*> location, not_null<Data::LocationThumbnail*> location,
const QString &title, const QString &title,
const QString &description) const QString &description)
: HistoryMedia(parent) : Media(parent)
, _data(location) , _data(location)
, _title(st::msgMinWidth) , _title(st::msgMinWidth)
, _description(st::msgMinWidth) , _description(st::msgMinWidth)
@ -51,7 +47,7 @@ HistoryLocation::HistoryLocation(
} }
} }
QSize HistoryLocation::countOptimalSize() { QSize Location::countOptimalSize() {
auto tw = fullWidth(); auto tw = fullWidth();
auto th = fullHeight(); auto th = fullHeight();
if (tw > st::maxMediaSize) { if (tw > st::maxMediaSize) {
@ -79,7 +75,7 @@ QSize HistoryLocation::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryLocation::countCurrentSize(int newWidth) { QSize Location::countCurrentSize(int newWidth) {
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
auto tw = fullWidth(); auto tw = fullWidth();
@ -114,17 +110,17 @@ QSize HistoryLocation::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
TextSelection HistoryLocation::toDescriptionSelection( TextSelection Location::toDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::UnshiftItemSelection(selection, _title); return UnshiftItemSelection(selection, _title);
} }
TextSelection HistoryLocation::fromDescriptionSelection( TextSelection Location::fromDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::ShiftItemSelection(selection, _title); return ShiftItemSelection(selection, _title);
} }
void HistoryLocation::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Location::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintx = 0, painty = 0, paintw = width(), painth = height(); auto paintx = 0, painty = 0, paintw = width(), painth = height();
bool bubble = _parent->hasBubble(); bool bubble = _parent->hasBubble();
@ -195,7 +191,7 @@ void HistoryLocation::draw(Painter &p, const QRect &r, TextSelection selection,
} }
} }
TextState HistoryLocation::textState(QPoint point, StateRequest request) const { TextState Location::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
auto symbolAdd = 0; auto symbolAdd = 0;
@ -267,7 +263,7 @@ TextState HistoryLocation::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
TextSelection HistoryLocation::adjustSelection(TextSelection selection, TextSelectType type) const { TextSelection Location::adjustSelection(TextSelection selection, TextSelectType type) const {
if (_description.isEmpty() || selection.to <= _title.length()) { if (_description.isEmpty() || selection.to <= _title.length()) {
return _title.adjustSelection(selection, type); return _title.adjustSelection(selection, type);
} }
@ -279,7 +275,7 @@ TextSelection HistoryLocation::adjustSelection(TextSelection selection, TextSele
return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to }; return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to };
} }
TextForMimeData HistoryLocation::selectedText(TextSelection selection) const { TextForMimeData Location::selectedText(TextSelection selection) const {
auto titleResult = _title.toTextForMimeData(selection); auto titleResult = _title.toTextForMimeData(selection);
auto descriptionResult = _description.toTextForMimeData( auto descriptionResult = _description.toTextForMimeData(
toDescriptionSelection(selection)); toDescriptionSelection(selection));
@ -291,7 +287,7 @@ TextForMimeData HistoryLocation::selectedText(TextSelection selection) const {
return titleResult.append('\n').append(std::move(descriptionResult)); return titleResult.append('\n').append(std::move(descriptionResult));
} }
bool HistoryLocation::needsBubble() const { bool Location::needsBubble() const {
if (!_title.isEmpty() || !_description.isEmpty()) { if (!_title.isEmpty() || !_description.isEmpty()) {
return true; return true;
} }
@ -303,10 +299,12 @@ bool HistoryLocation::needsBubble() const {
return false; return false;
} }
int HistoryLocation::fullWidth() const { int Location::fullWidth() const {
return st::locationSize.width(); return st::locationSize.width();
} }
int HistoryLocation::fullHeight() const { int Location::fullHeight() const {
return st::locationSize.height(); return st::locationSize.height();
} }
} // namespace HistoryView

View File

@ -7,15 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
namespace Data { namespace Data {
struct LocationThumbnail; struct LocationThumbnail;
} // namespace Data } // namespace Data
class HistoryLocation : public HistoryMedia { namespace HistoryView {
class Location : public Media {
public: public:
HistoryLocation( Location(
not_null<Element*> parent, not_null<Element*> parent,
not_null<Data::LocationThumbnail*> location, not_null<Data::LocationThumbnail*> location,
const QString &title = QString(), const QString &title = QString(),
@ -67,3 +69,5 @@ private:
int fullHeight() const; int fullHeight() const;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
@ -14,30 +14,25 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text_options.h" #include "ui/text_options.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using PointState = HistoryView::PointState; Storage::SharedMediaTypesMask Media::sharedMediaTypes() const {
using TextState = HistoryView::TextState;
} // namespace
Storage::SharedMediaTypesMask HistoryMedia::sharedMediaTypes() const {
return {}; return {};
} }
not_null<History*> HistoryMedia::history() const { not_null<History*> Media::history() const {
return _parent->history(); return _parent->history();
} }
bool HistoryMedia::isDisplayed() const { bool Media::isDisplayed() const {
return true; return true;
} }
QSize HistoryMedia::countCurrentSize(int newWidth) { QSize Media::countCurrentSize(int newWidth) {
return QSize(qMin(newWidth, maxWidth()), minHeight()); return QSize(qMin(newWidth, maxWidth()), minHeight());
} }
Ui::Text::String HistoryMedia::createCaption(not_null<HistoryItem*> item) const { Ui::Text::String Media::createCaption(not_null<HistoryItem*> item) const {
if (item->emptyText()) { if (item->emptyText()) {
return {}; return {};
} }
@ -55,27 +50,25 @@ Ui::Text::String HistoryMedia::createCaption(not_null<HistoryItem*> item) const
return result; return result;
} }
TextSelection HistoryMedia::skipSelection(TextSelection selection) const { TextSelection Media::skipSelection(TextSelection selection) const {
return HistoryView::UnshiftItemSelection( return UnshiftItemSelection(selection, fullSelectionLength());
selection,
fullSelectionLength());
} }
TextSelection HistoryMedia::unskipSelection(TextSelection selection) const { TextSelection Media::unskipSelection(TextSelection selection) const {
return HistoryView::ShiftItemSelection( return ShiftItemSelection(selection, fullSelectionLength());
selection,
fullSelectionLength());
} }
PointState HistoryMedia::pointState(QPoint point) const { PointState Media::pointState(QPoint point) const {
return QRect(0, 0, width(), height()).contains(point) return QRect(0, 0, width(), height()).contains(point)
? PointState::Inside ? PointState::Inside
: PointState::Outside; : PointState::Outside;
} }
TextState HistoryMedia::getStateGrouped( TextState Media::getStateGrouped(
const QRect &geometry, const QRect &geometry,
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
Unexpected("Grouping method call."); Unexpected("Grouping method call.");
} }
} // namespace HistoryView

View File

@ -23,12 +23,12 @@ using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
} // namespace Storage } // namespace Storage
namespace HistoryView { namespace HistoryView {
enum class PointState : char; enum class PointState : char;
enum class CursorState : char; enum class CursorState : char;
enum class InfoDisplayType : char; enum class InfoDisplayType : char;
struct TextState; struct TextState;
struct StateRequest; struct StateRequest;
} // namespace HistoryView
enum class MediaInBubbleState { enum class MediaInBubbleState {
None, None,
@ -37,14 +37,9 @@ enum class MediaInBubbleState {
Bottom, Bottom,
}; };
class HistoryMedia : public HistoryView::Object { class Media : public Object {
public: public:
using Element = HistoryView::Element; Media(not_null<Element*> parent) : _parent(parent) {
using PointState = HistoryView::PointState;
using TextState = HistoryView::TextState;
using StateRequest = HistoryView::StateRequest;
HistoryMedia(not_null<Element*> parent) : _parent(parent) {
} }
[[nodiscard]] not_null<History*> history() const; [[nodiscard]] not_null<History*> history() const;
@ -231,12 +226,9 @@ public:
virtual void parentTextUpdated() { virtual void parentTextUpdated() {
} }
virtual ~HistoryMedia() = default; virtual ~Media() = default;
protected: protected:
using CursorState = HistoryView::CursorState;
using InfoDisplayType = HistoryView::InfoDisplayType;
QSize countCurrentSize(int newWidth) override; QSize countCurrentSize(int newWidth) override;
Ui::Text::String createCaption(not_null<HistoryItem*> item) const; Ui::Text::String createCaption(not_null<HistoryItem*> item) const;
@ -247,3 +239,5 @@ protected:
MediaInBubbleState _inBubbleState = MediaInBubbleState::None; MediaInBubbleState _inBubbleState = MediaInBubbleState::None;
}; };
} // namespace HistoryView

View File

@ -5,20 +5,22 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "layout.h" #include "layout.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/media/history_media_grouped.h" #include "history/view/media/history_view_media_grouped.h"
#include "history/media/history_media_photo.h" #include "history/view/media/history_view_photo.h"
#include "history/media/history_media_gif.h" #include "history/view/media/history_view_gif.h"
#include "history/media/history_media_document.h" #include "history/view/media/history_view_document.h"
#include "history/media/history_media_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "history/media/history_media_video.h" #include "history/view/media/history_view_video.h"
#include "history/media/history_media_wall_paper.h" #include "history/view/media/history_view_wall_paper.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace HistoryView {
int documentMaxStatusWidth(DocumentData *document) { int documentMaxStatusWidth(DocumentData *document) {
auto result = st::normalFont->width(formatDownloadText(document->size, document->size)); auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
const auto duration = document->getDuration(); const auto duration = document->getDuration();
@ -58,33 +60,33 @@ void PaintInterpolatedIcon(
p.restore(); p.restore();
} }
std::unique_ptr<HistoryMedia> CreateAttach( std::unique_ptr<Media> CreateAttach(
not_null<HistoryView::Element*> parent, not_null<Element*> parent,
DocumentData *document, DocumentData *document,
PhotoData *photo, PhotoData *photo,
const std::vector<std::unique_ptr<Data::Media>> &collage, const std::vector<std::unique_ptr<Data::Media>> &collage,
const QString &webpageUrl) { const QString &webpageUrl) {
if (!collage.empty()) { if (!collage.empty()) {
return std::make_unique<HistoryGroupedMedia>(parent, collage); return std::make_unique<GroupedMedia>(parent, collage);
} else if (document) { } else if (document) {
if (document->sticker()) { if (document->sticker()) {
return std::make_unique<HistorySticker>(parent, document); return std::make_unique<Sticker>(parent, document);
} else if (document->isAnimation()) { } else if (document->isAnimation()) {
return std::make_unique<HistoryGif>(parent, document); return std::make_unique<Gif>(parent, document);
} else if (document->isVideoFile()) { } else if (document->isVideoFile()) {
return std::make_unique<HistoryVideo>( return std::make_unique<Video>(
parent, parent,
parent->data(), parent->data(),
document); document);
} else if (document->isWallPaper()) { } else if (document->isWallPaper()) {
return std::make_unique<HistoryWallPaper>( return std::make_unique<WallPaper>(
parent, parent,
document, document,
webpageUrl); webpageUrl);
} }
return std::make_unique<HistoryDocument>(parent, document); return std::make_unique<Document>(parent, document);
} else if (photo) { } else if (photo) {
return std::make_unique<HistoryPhoto>( return std::make_unique<Photo>(
parent, parent,
parent->data(), parent->data(),
photo); photo);
@ -95,3 +97,5 @@ std::unique_ptr<HistoryMedia> CreateAttach(
int unitedLineHeight() { int unitedLineHeight() {
return qMax(st::webPageTitleFont->height, st::webPageDescriptionFont->height); return qMax(st::webPageTitleFont->height, st::webPageDescriptionFont->height);
} }
} // namespace HistoryView

View File

@ -17,7 +17,10 @@ class Media;
class DocumentData; class DocumentData;
class PhotoData; class PhotoData;
class HistoryMedia;
namespace HistoryView {
class Media;
int documentMaxStatusWidth(DocumentData *document); int documentMaxStatusWidth(DocumentData *document);
@ -28,10 +31,12 @@ void PaintInterpolatedIcon(
float64 b_ratio, float64 b_ratio,
QRect rect); QRect rect);
std::unique_ptr<HistoryMedia> CreateAttach( std::unique_ptr<Media> CreateAttach(
not_null<HistoryView::Element*> parent, not_null<Element*> parent,
DocumentData *document, DocumentData *document,
PhotoData *photo, PhotoData *photo,
const std::vector<std::unique_ptr<Data::Media>> &collage = {}, const std::vector<std::unique_ptr<Data::Media>> &collage = {},
const QString &webpageUrl = QString()); const QString &webpageUrl = QString());
int unitedLineHeight(); int unitedLineHeight();
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_grouped.h" #include "history/view/media/history_view_media_grouped.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_message.h" #include "history/history_message.h"
@ -21,25 +21,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "layout.h" #include "layout.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; GroupedMedia::Part::Part(
using PointState = HistoryView::PointState; not_null<Element*> parent,
} // namespace
HistoryGroupedMedia::Part::Part(
not_null<HistoryView::Element*> parent,
not_null<Data::Media*> media) not_null<Data::Media*> media)
: item(media->parent()) : item(media->parent())
, content(media->createView(parent, item)) { , content(media->createView(parent, item)) {
Assert(media->canBeGrouped()); Assert(media->canBeGrouped());
} }
HistoryGroupedMedia::HistoryGroupedMedia( GroupedMedia::GroupedMedia(
not_null<Element*> parent, not_null<Element*> parent,
const std::vector<std::unique_ptr<Data::Media>> &medias) const std::vector<std::unique_ptr<Data::Media>> &medias)
: HistoryMedia(parent) : Media(parent)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
const auto truncated = ranges::view::all( const auto truncated = ranges::view::all(
medias medias
@ -51,10 +46,10 @@ HistoryGroupedMedia::HistoryGroupedMedia(
Ensures(result); Ensures(result);
} }
HistoryGroupedMedia::HistoryGroupedMedia( GroupedMedia::GroupedMedia(
not_null<Element*> parent, not_null<Element*> parent,
const std::vector<not_null<HistoryItem*>> &items) const std::vector<not_null<HistoryItem*>> &items)
: HistoryMedia(parent) : Media(parent)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
const auto medias = ranges::view::all( const auto medias = ranges::view::all(
items items
@ -66,7 +61,7 @@ HistoryGroupedMedia::HistoryGroupedMedia(
Ensures(result); Ensures(result);
} }
QSize HistoryGroupedMedia::countOptimalSize() { QSize GroupedMedia::countOptimalSize() {
if (_caption.hasSkipBlock()) { if (_caption.hasSkipBlock()) {
_caption.updateSkipBlock( _caption.updateSkipBlock(
_parent->skipBlockWidth(), _parent->skipBlockWidth(),
@ -108,7 +103,7 @@ QSize HistoryGroupedMedia::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryGroupedMedia::countCurrentSize(int newWidth) { QSize GroupedMedia::countCurrentSize(int newWidth) {
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
auto newHeight = 0; auto newHeight = 0;
if (newWidth < st::historyGroupWidthMin) { if (newWidth < st::historyGroupWidthMin) {
@ -158,14 +153,14 @@ QSize HistoryGroupedMedia::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
void HistoryGroupedMedia::refreshParentId( void GroupedMedia::refreshParentId(
not_null<HistoryItem*> realParent) { not_null<HistoryItem*> realParent) {
for (const auto &part : _parts) { for (const auto &part : _parts) {
part.content->refreshParentId(part.item); part.content->refreshParentId(part.item);
} }
} }
void HistoryGroupedMedia::draw( void GroupedMedia::draw(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,
TextSelection selection, TextSelection selection,
@ -219,7 +214,7 @@ void HistoryGroupedMedia::draw(
} }
} }
TextState HistoryGroupedMedia::getPartState( TextState GroupedMedia::getPartState(
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
for (const auto &part : _parts) { for (const auto &part : _parts) {
@ -235,7 +230,7 @@ TextState HistoryGroupedMedia::getPartState(
return TextState(_parent->data()); return TextState(_parent->data());
} }
PointState HistoryGroupedMedia::pointState(QPoint point) const { PointState GroupedMedia::pointState(QPoint point) const {
if (!QRect(0, 0, width(), height()).contains(point)) { if (!QRect(0, 0, width(), height()).contains(point)) {
return PointState::Outside; return PointState::Outside;
} }
@ -247,9 +242,7 @@ PointState HistoryGroupedMedia::pointState(QPoint point) const {
return PointState::Inside; return PointState::Inside;
} }
HistoryView::TextState HistoryGroupedMedia::textState( TextState GroupedMedia::textState(QPoint point, StateRequest request) const {
QPoint point,
StateRequest request) const {
auto result = getPartState(point, request); auto result = getPartState(point, request);
if (!result.link && !_caption.isEmpty()) { if (!result.link && !_caption.isEmpty()) {
const auto captionw = width() - st::msgPadding.left() - st::msgPadding.right(); const auto captionw = width() - st::msgPadding.left() - st::msgPadding.right();
@ -279,7 +272,7 @@ HistoryView::TextState HistoryGroupedMedia::textState(
return result; return result;
} }
bool HistoryGroupedMedia::toggleSelectionByHandlerClick( bool GroupedMedia::toggleSelectionByHandlerClick(
const ClickHandlerPtr &p) const { const ClickHandlerPtr &p) const {
for (const auto &part : _parts) { for (const auto &part : _parts) {
if (part.content->toggleSelectionByHandlerClick(p)) { if (part.content->toggleSelectionByHandlerClick(p)) {
@ -289,7 +282,7 @@ bool HistoryGroupedMedia::toggleSelectionByHandlerClick(
return false; return false;
} }
bool HistoryGroupedMedia::dragItemByHandler(const ClickHandlerPtr &p) const { bool GroupedMedia::dragItemByHandler(const ClickHandlerPtr &p) const {
for (const auto &part : _parts) { for (const auto &part : _parts) {
if (part.content->dragItemByHandler(p)) { if (part.content->dragItemByHandler(p)) {
return true; return true;
@ -298,18 +291,18 @@ bool HistoryGroupedMedia::dragItemByHandler(const ClickHandlerPtr &p) const {
return false; return false;
} }
TextSelection HistoryGroupedMedia::adjustSelection( TextSelection GroupedMedia::adjustSelection(
TextSelection selection, TextSelection selection,
TextSelectType type) const { TextSelectType type) const {
return _caption.adjustSelection(selection, type); return _caption.adjustSelection(selection, type);
} }
TextForMimeData HistoryGroupedMedia::selectedText( TextForMimeData GroupedMedia::selectedText(
TextSelection selection) const { TextSelection selection) const {
return _caption.toTextForMimeData(selection); return _caption.toTextForMimeData(selection);
} }
void HistoryGroupedMedia::clickHandlerActiveChanged( void GroupedMedia::clickHandlerActiveChanged(
const ClickHandlerPtr &p, const ClickHandlerPtr &p,
bool active) { bool active) {
for (const auto &part : _parts) { for (const auto &part : _parts) {
@ -317,7 +310,7 @@ void HistoryGroupedMedia::clickHandlerActiveChanged(
} }
} }
void HistoryGroupedMedia::clickHandlerPressedChanged( void GroupedMedia::clickHandlerPressedChanged(
const ClickHandlerPtr &p, const ClickHandlerPtr &p,
bool pressed) { bool pressed) {
for (const auto &part : _parts) { for (const auto &part : _parts) {
@ -330,7 +323,7 @@ void HistoryGroupedMedia::clickHandlerPressedChanged(
} }
template <typename DataMediaRange> template <typename DataMediaRange>
bool HistoryGroupedMedia::applyGroup(const DataMediaRange &medias) { bool GroupedMedia::applyGroup(const DataMediaRange &medias) {
if (validateGroupParts(medias)) { if (validateGroupParts(medias)) {
return true; return true;
} }
@ -347,7 +340,7 @@ bool HistoryGroupedMedia::applyGroup(const DataMediaRange &medias) {
} }
template <typename DataMediaRange> template <typename DataMediaRange>
bool HistoryGroupedMedia::validateGroupParts( bool GroupedMedia::validateGroupParts(
const DataMediaRange &medias) const { const DataMediaRange &medias) const {
auto i = 0; auto i = 0;
const auto count = _parts.size(); const auto count = _parts.size();
@ -360,36 +353,36 @@ bool HistoryGroupedMedia::validateGroupParts(
return (i == count); return (i == count);
} }
not_null<HistoryMedia*> HistoryGroupedMedia::main() const { not_null<Media*> GroupedMedia::main() const {
Expects(!_parts.empty()); Expects(!_parts.empty());
return _parts.back().content.get(); return _parts.back().content.get();
} }
TextWithEntities HistoryGroupedMedia::getCaption() const { TextWithEntities GroupedMedia::getCaption() const {
return main()->getCaption(); return main()->getCaption();
} }
Storage::SharedMediaTypesMask HistoryGroupedMedia::sharedMediaTypes() const { Storage::SharedMediaTypesMask GroupedMedia::sharedMediaTypes() const {
return main()->sharedMediaTypes(); return main()->sharedMediaTypes();
} }
PhotoData *HistoryGroupedMedia::getPhoto() const { PhotoData *GroupedMedia::getPhoto() const {
return main()->getPhoto(); return main()->getPhoto();
} }
DocumentData *HistoryGroupedMedia::getDocument() const { DocumentData *GroupedMedia::getDocument() const {
return main()->getDocument(); return main()->getDocument();
} }
HistoryMessageEdited *HistoryGroupedMedia::displayedEditBadge() const { HistoryMessageEdited *GroupedMedia::displayedEditBadge() const {
if (!_caption.isEmpty()) { if (!_caption.isEmpty()) {
return _parts.front().item->Get<HistoryMessageEdited>(); return _parts.front().item->Get<HistoryMessageEdited>();
} }
return nullptr; return nullptr;
} }
void HistoryGroupedMedia::updateNeedBubbleState() { void GroupedMedia::updateNeedBubbleState() {
const auto captionItem = [&]() -> HistoryItem* { const auto captionItem = [&]() -> HistoryItem* {
auto result = (HistoryItem*)nullptr; auto result = (HistoryItem*)nullptr;
for (const auto &part : _parts) { for (const auto &part : _parts) {
@ -409,15 +402,15 @@ void HistoryGroupedMedia::updateNeedBubbleState() {
_needBubble = computeNeedBubble(); _needBubble = computeNeedBubble();
} }
void HistoryGroupedMedia::parentTextUpdated() { void GroupedMedia::parentTextUpdated() {
history()->owner().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
bool HistoryGroupedMedia::needsBubble() const { bool GroupedMedia::needsBubble() const {
return _needBubble; return _needBubble;
} }
bool HistoryGroupedMedia::computeNeedBubble() const { bool GroupedMedia::computeNeedBubble() const {
if (!_caption.isEmpty()) { if (!_caption.isEmpty()) {
return true; return true;
} }
@ -433,6 +426,8 @@ bool HistoryGroupedMedia::computeNeedBubble() const {
return false; return false;
} }
bool HistoryGroupedMedia::needInfoDisplay() const { bool GroupedMedia::needInfoDisplay() const {
return (_parent->data()->id < 0 || _parent->isUnderCursor()); return (_parent->data()->id < 0 || _parent->isUnderCursor());
} }
} // namespace HistoryView

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_photo.h" #include "data/data_photo.h"
@ -15,14 +15,16 @@ namespace Data {
class Media; class Media;
} // namespace Data } // namespace Data
class HistoryGroupedMedia : public HistoryMedia { namespace HistoryView {
class GroupedMedia : public Media {
public: public:
static constexpr auto kMaxSize = 10; static constexpr auto kMaxSize = 10;
HistoryGroupedMedia( GroupedMedia(
not_null<Element*> parent, not_null<Element*> parent,
const std::vector<std::unique_ptr<Data::Media>> &medias); const std::vector<std::unique_ptr<Data::Media>> &medias);
HistoryGroupedMedia( GroupedMedia(
not_null<Element*> parent, not_null<Element*> parent,
const std::vector<not_null<HistoryItem*>> &items); const std::vector<not_null<HistoryItem*>> &items);
@ -89,11 +91,11 @@ public:
private: private:
struct Part { struct Part {
Part( Part(
not_null<HistoryView::Element*> parent, not_null<Element*> parent,
not_null<Data::Media*> media); not_null<Data::Media*> media);
not_null<HistoryItem*> item; not_null<HistoryItem*> item;
std::unique_ptr<HistoryMedia> content; std::unique_ptr<Media> content;
RectParts sides = RectPart::None; RectParts sides = RectPart::None;
QRect initialGeometry; QRect initialGeometry;
@ -114,7 +116,7 @@ private:
bool needInfoDisplay() const; bool needInfoDisplay() const;
bool computeNeedBubble() const; bool computeNeedBubble() const;
not_null<HistoryMedia*> main() const; not_null<Media*> main() const;
TextState getPartState( TextState getPartState(
QPoint point, QPoint point,
StateRequest request) const; StateRequest request) const;
@ -124,3 +126,5 @@ private:
bool _needBubble = false; bool _needBubble = false;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_photo.h" #include "history/view/media/history_view_photo.h"
#include "layout.h" #include "layout.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/grouped_layout.h" #include "ui/grouped_layout.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -21,35 +21,31 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; Photo::Photo(
} // namespace
HistoryPhoto::HistoryPhoto(
not_null<Element*> parent, not_null<Element*> parent,
not_null<HistoryItem*> realParent, not_null<HistoryItem*> realParent,
not_null<PhotoData*> photo) not_null<PhotoData*> photo)
: HistoryFileMedia(parent, realParent) : File(parent, realParent)
, _data(photo) , _data(photo)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
_caption = createCaption(realParent); _caption = createCaption(realParent);
create(realParent->fullId()); create(realParent->fullId());
} }
HistoryPhoto::HistoryPhoto( Photo::Photo(
not_null<Element*> parent, not_null<Element*> parent,
not_null<PeerData*> chat, not_null<PeerData*> chat,
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
int width) int width)
: HistoryFileMedia(parent, parent->data()) : File(parent, parent->data())
, _data(photo) , _data(photo)
, _serviceWidth(width) { , _serviceWidth(width) {
create(parent->data()->fullId(), chat); create(parent->data()->fullId(), chat);
} }
void HistoryPhoto::create(FullMsgId contextId, PeerData *chat) { void Photo::create(FullMsgId contextId, PeerData *chat) {
setLinks( setLinks(
std::make_shared<PhotoOpenClickHandler>(_data, contextId, chat), std::make_shared<PhotoOpenClickHandler>(_data, contextId, chat),
std::make_shared<PhotoSaveClickHandler>(_data, contextId, chat), std::make_shared<PhotoSaveClickHandler>(_data, contextId, chat),
@ -61,7 +57,7 @@ void HistoryPhoto::create(FullMsgId contextId, PeerData *chat) {
} }
} }
QSize HistoryPhoto::countOptimalSize() { QSize Photo::countOptimalSize() {
if (_parent->media() != this) { if (_parent->media() != this) {
_caption = Ui::Text::String(); _caption = Ui::Text::String();
} else if (_caption.hasSkipBlock()) { } else if (_caption.hasSkipBlock()) {
@ -104,7 +100,7 @@ QSize HistoryPhoto::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryPhoto::countCurrentSize(int newWidth) { QSize Photo::countCurrentSize(int newWidth) {
int tw = ConvertScale(_data->width()), th = ConvertScale(_data->height()); int tw = ConvertScale(_data->width()), th = ConvertScale(_data->height());
if (tw > st::maxMediaSize) { if (tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw; th = (st::maxMediaSize * th) / tw;
@ -144,7 +140,7 @@ QSize HistoryPhoto::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
void HistoryPhoto::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Photo::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
_data->automaticLoad(_realParent->fullId(), _parent->data()); _data->automaticLoad(_realParent->fullId(), _parent->data());
@ -279,7 +275,7 @@ void HistoryPhoto::draw(Painter &p, const QRect &r, TextSelection selection, crl
} }
} }
TextState HistoryPhoto::textState(QPoint point, StateRequest request) const { TextState Photo::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -335,13 +331,13 @@ TextState HistoryPhoto::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
QSize HistoryPhoto::sizeForGrouping() const { QSize Photo::sizeForGrouping() const {
const auto width = _data->width(); const auto width = _data->width();
const auto height = _data->height(); const auto height = _data->height();
return { std::max(width, 1), std::max(height, 1) }; return { std::max(width, 1), std::max(height, 1) };
} }
void HistoryPhoto::drawGrouped( void Photo::drawGrouped(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,
TextSelection selection, TextSelection selection,
@ -448,7 +444,7 @@ void HistoryPhoto::drawGrouped(
} }
} }
TextState HistoryPhoto::getStateGrouped( TextState Photo::getStateGrouped(
const QRect &geometry, const QRect &geometry,
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
@ -466,24 +462,24 @@ TextState HistoryPhoto::getStateGrouped(
: _savel); : _savel);
} }
float64 HistoryPhoto::dataProgress() const { float64 Photo::dataProgress() const {
return _data->progress(); return _data->progress();
} }
bool HistoryPhoto::dataFinished() const { bool Photo::dataFinished() const {
return !_data->loading() return !_data->loading()
&& (!_data->uploading() || _data->waitingForAlbum()); && (!_data->uploading() || _data->waitingForAlbum());
} }
bool HistoryPhoto::dataLoaded() const { bool Photo::dataLoaded() const {
return _data->loaded(); return _data->loaded();
} }
bool HistoryPhoto::needInfoDisplay() const { bool Photo::needInfoDisplay() const {
return (_parent->data()->id < 0 || _parent->isUnderCursor()); return (_parent->data()->id < 0 || _parent->isUnderCursor());
} }
void HistoryPhoto::validateGroupedCache( void Photo::validateGroupedCache(
const QRect &geometry, const QRect &geometry,
RectParts corners, RectParts corners,
not_null<uint64*> cacheKey, not_null<uint64*> cacheKey,
@ -535,11 +531,11 @@ void HistoryPhoto::validateGroupedCache(
*cache = image->pixNoCache(_realParent->fullId(), pixWidth, pixHeight, options, width, height); *cache = image->pixNoCache(_realParent->fullId(), pixWidth, pixHeight, options, width, height);
} }
TextForMimeData HistoryPhoto::selectedText(TextSelection selection) const { TextForMimeData Photo::selectedText(TextSelection selection) const {
return _caption.toTextForMimeData(selection); return _caption.toTextForMimeData(selection);
} }
bool HistoryPhoto::needsBubble() const { bool Photo::needsBubble() const {
if (!_caption.isEmpty()) { if (!_caption.isEmpty()) {
return true; return true;
} }
@ -553,13 +549,15 @@ bool HistoryPhoto::needsBubble() const {
return false; return false;
} }
bool HistoryPhoto::isReadyForOpen() const { bool Photo::isReadyForOpen() const {
return _data->loaded(); return _data->loaded();
} }
void HistoryPhoto::parentTextUpdated() { void Photo::parentTextUpdated() {
_caption = (_parent->media() == this) _caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Ui::Text::String(); : Ui::Text::String();
history()->owner().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
} // namespace HistoryView

View File

@ -7,15 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media_file.h" #include "history/view/media/history_view_file.h"
class HistoryPhoto : public HistoryFileMedia { namespace HistoryView {
class Photo : public File {
public: public:
HistoryPhoto( Photo(
not_null<Element*> parent, not_null<Element*> parent,
not_null<HistoryItem*> realParent, not_null<HistoryItem*> realParent,
not_null<PhotoData*> photo); not_null<PhotoData*> photo);
HistoryPhoto( Photo(
not_null<Element*> parent, not_null<Element*> parent,
not_null<PeerData*> chat, not_null<PeerData*> chat,
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
@ -96,3 +98,5 @@ private:
Ui::Text::String _caption; Ui::Text::String _caption;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_poll.h" #include "history/view/media/history_view_poll.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "history/history.h" #include "history/history.h"
@ -26,10 +26,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_history.h" #include "styles/style_history.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
namespace HistoryView {
namespace { namespace {
using TextState = HistoryView::TextState;
struct PercentCounterItem { struct PercentCounterItem {
int index = 0; int index = 0;
int percent = 0; int percent = 0;
@ -105,18 +104,18 @@ void CountNicePercent(
} // namespace } // namespace
struct HistoryPoll::AnswerAnimation { struct Poll::AnswerAnimation {
anim::value percent; anim::value percent;
anim::value filling; anim::value filling;
anim::value opacity; anim::value opacity;
}; };
struct HistoryPoll::AnswersAnimation { struct Poll::AnswersAnimation {
std::vector<AnswerAnimation> data; std::vector<AnswerAnimation> data;
Ui::Animations::Simple progress; Ui::Animations::Simple progress;
}; };
struct HistoryPoll::SendingAnimation { struct Poll::SendingAnimation {
template <typename Callback> template <typename Callback>
SendingAnimation( SendingAnimation(
const QByteArray &option, const QByteArray &option,
@ -126,7 +125,7 @@ struct HistoryPoll::SendingAnimation {
Ui::InfiniteRadialAnimation animation; Ui::InfiniteRadialAnimation animation;
}; };
struct HistoryPoll::Answer { struct Poll::Answer {
Answer(); Answer();
void fillText(const PollAnswer &original); void fillText(const PollAnswer &original);
@ -144,7 +143,7 @@ struct HistoryPoll::Answer {
}; };
template <typename Callback> template <typename Callback>
HistoryPoll::SendingAnimation::SendingAnimation( Poll::SendingAnimation::SendingAnimation(
const QByteArray &option, const QByteArray &option,
Callback &&callback) Callback &&callback)
: option(option) : option(option)
@ -153,10 +152,10 @@ HistoryPoll::SendingAnimation::SendingAnimation(
st::historyPollRadialAnimation) { st::historyPollRadialAnimation) {
} }
HistoryPoll::Answer::Answer() : text(st::msgMinWidth / 2) { Poll::Answer::Answer() : text(st::msgMinWidth / 2) {
} }
void HistoryPoll::Answer::fillText(const PollAnswer &original) { void Poll::Answer::fillText(const PollAnswer &original) {
if (!text.isEmpty() && text.toString() == original.text) { if (!text.isEmpty() && text.toString() == original.text) {
return; return;
} }
@ -166,16 +165,16 @@ void HistoryPoll::Answer::fillText(const PollAnswer &original) {
Ui::WebpageTextTitleOptions()); Ui::WebpageTextTitleOptions());
} }
HistoryPoll::HistoryPoll( Poll::Poll(
not_null<Element*> parent, not_null<Element*> parent,
not_null<PollData*> poll) not_null<PollData*> poll)
: HistoryMedia(parent) : Media(parent)
, _poll(poll) , _poll(poll)
, _question(st::msgMinWidth / 2) { , _question(st::msgMinWidth / 2) {
history()->owner().registerPollView(_poll, _parent); history()->owner().registerPollView(_poll, _parent);
} }
QSize HistoryPoll::countOptimalSize() { QSize Poll::countOptimalSize() {
updateTexts(); updateTexts();
const auto paddings = st::msgPadding.left() + st::msgPadding.right(); const auto paddings = st::msgPadding.left() + st::msgPadding.right();
@ -214,11 +213,11 @@ QSize HistoryPoll::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
bool HistoryPoll::canVote() const { bool Poll::canVote() const {
return !_voted && !_closed; return !_voted && !_closed;
} }
int HistoryPoll::countAnswerTop( int Poll::countAnswerTop(
const Answer &answer, const Answer &answer,
int innerWidth) const { int innerWidth) const {
auto tshift = st::historyPollQuestionTop; auto tshift = st::historyPollQuestionTop;
@ -246,7 +245,7 @@ int HistoryPoll::countAnswerTop(
return tshift; return tshift;
} }
int HistoryPoll::countAnswerHeight( int Poll::countAnswerHeight(
const Answer &answer, const Answer &answer,
int innerWidth) const { int innerWidth) const {
const auto answerWidth = innerWidth const auto answerWidth = innerWidth
@ -257,7 +256,7 @@ int HistoryPoll::countAnswerHeight(
+ st::historyPollAnswerPadding.bottom(); + st::historyPollAnswerPadding.bottom();
} }
QSize HistoryPoll::countCurrentSize(int newWidth) { QSize Poll::countCurrentSize(int newWidth) {
const auto paddings = st::msgPadding.left() + st::msgPadding.right(); const auto paddings = st::msgPadding.left() + st::msgPadding.right();
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
@ -286,7 +285,7 @@ QSize HistoryPoll::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
void HistoryPoll::updateTexts() { void Poll::updateTexts() {
if (_pollVersion == _poll->version) { if (_pollVersion == _poll->version) {
return; return;
} }
@ -315,7 +314,7 @@ void HistoryPoll::updateTexts() {
} }
} }
void HistoryPoll::updateAnswers() { void Poll::updateAnswers() {
const auto changed = !ranges::equal( const auto changed = !ranges::equal(
_answers, _answers,
_poll->answers, _poll->answers,
@ -345,7 +344,7 @@ void HistoryPoll::updateAnswers() {
resetAnswersAnimation(); resetAnswersAnimation();
} }
ClickHandlerPtr HistoryPoll::createAnswerClickHandler( ClickHandlerPtr Poll::createAnswerClickHandler(
const Answer &answer) const { const Answer &answer) const {
const auto option = answer.option; const auto option = answer.option;
const auto itemId = _parent->data()->fullId(); const auto itemId = _parent->data()->fullId();
@ -354,13 +353,13 @@ ClickHandlerPtr HistoryPoll::createAnswerClickHandler(
}); });
} }
void HistoryPoll::updateVotes() { void Poll::updateVotes() {
_voted = _poll->voted(); _voted = _poll->voted();
updateAnswerVotes(); updateAnswerVotes();
updateTotalVotes(); updateTotalVotes();
} }
void HistoryPoll::checkSendingAnimation() const { void Poll::checkSendingAnimation() const {
const auto &sending = _poll->sendingVote; const auto &sending = _poll->sendingVote;
if (sending.isEmpty() == !_sendingAnimation) { if (sending.isEmpty() == !_sendingAnimation) {
if (_sendingAnimation) { if (_sendingAnimation) {
@ -380,7 +379,7 @@ void HistoryPoll::checkSendingAnimation() const {
_sendingAnimation->animation.start(); _sendingAnimation->animation.start();
} }
void HistoryPoll::updateTotalVotes() { void Poll::updateTotalVotes() {
if (_totalVotes == _poll->totalVoters && !_totalVotesLabel.isEmpty()) { if (_totalVotes == _poll->totalVoters && !_totalVotesLabel.isEmpty()) {
return; return;
} }
@ -391,7 +390,7 @@ void HistoryPoll::updateTotalVotes() {
_totalVotesLabel.setText(st::msgDateTextStyle, string); _totalVotesLabel.setText(st::msgDateTextStyle, string);
} }
void HistoryPoll::updateAnswerVotesFromOriginal( void Poll::updateAnswerVotesFromOriginal(
Answer &answer, Answer &answer,
const PollAnswer &original, const PollAnswer &original,
int percent, int percent,
@ -411,7 +410,7 @@ void HistoryPoll::updateAnswerVotesFromOriginal(
answer.filling = answer.votes / float64(maxVotes); answer.filling = answer.votes / float64(maxVotes);
} }
void HistoryPoll::updateAnswerVotes() { void Poll::updateAnswerVotes() {
if (_poll->answers.size() != _answers.size() if (_poll->answers.size() != _answers.size()
|| _poll->answers.empty()) { || _poll->answers.empty()) {
return; return;
@ -452,7 +451,7 @@ void HistoryPoll::updateAnswerVotes() {
} }
} }
void HistoryPoll::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Poll::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintx = 0, painty = 0, paintw = width(), painth = height(); auto paintx = 0, painty = 0, paintw = width(), painth = height();
@ -522,20 +521,20 @@ void HistoryPoll::draw(Painter &p, const QRect &r, TextSelection selection, crl:
} }
} }
void HistoryPoll::resetAnswersAnimation() const { void Poll::resetAnswersAnimation() const {
_answersAnimation = nullptr; _answersAnimation = nullptr;
if (_poll->sendingVote.isEmpty()) { if (_poll->sendingVote.isEmpty()) {
_sendingAnimation = nullptr; _sendingAnimation = nullptr;
} }
} }
void HistoryPoll::radialAnimationCallback() const { void Poll::radialAnimationCallback() const {
if (!anim::Disabled()) { if (!anim::Disabled()) {
history()->owner().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
} }
int HistoryPoll::paintAnswer( int Poll::paintAnswer(
Painter &p, Painter &p,
const Answer &answer, const Answer &answer,
const AnswerAnimation *animation, const AnswerAnimation *animation,
@ -619,7 +618,7 @@ int HistoryPoll::paintAnswer(
return height; return height;
} }
void HistoryPoll::paintRadio( void Poll::paintRadio(
Painter &p, Painter &p,
const Answer &answer, const Answer &answer,
int left, int left,
@ -665,7 +664,7 @@ void HistoryPoll::paintRadio(
p.setOpacity(o); p.setOpacity(o);
} }
void HistoryPoll::paintPercent( void Poll::paintPercent(
Painter &p, Painter &p,
const QString &percent, const QString &percent,
int percentWidth, int percentWidth,
@ -685,7 +684,7 @@ void HistoryPoll::paintPercent(
p.drawTextLeft(pleft, top + st::historyPollPercentTop, outerWidth, percent, percentWidth); p.drawTextLeft(pleft, top + st::historyPollPercentTop, outerWidth, percent, percentWidth);
} }
void HistoryPoll::paintFilling( void Poll::paintFilling(
Painter &p, Painter &p,
float64 filling, float64 filling,
int left, int left,
@ -714,7 +713,7 @@ void HistoryPoll::paintFilling(
p.drawRoundedRect(aleft, ftop, size, st::historyPollFillingHeight, radius, radius); p.drawRoundedRect(aleft, ftop, size, st::historyPollFillingHeight, radius, radius);
} }
bool HistoryPoll::answerVotesChanged() const { bool Poll::answerVotesChanged() const {
if (_poll->answers.size() != _answers.size() if (_poll->answers.size() != _answers.size()
|| _poll->answers.empty()) { || _poll->answers.empty()) {
return false; return false;
@ -727,7 +726,7 @@ bool HistoryPoll::answerVotesChanged() const {
&PollAnswer::votes); &PollAnswer::votes);
} }
void HistoryPoll::saveStateInAnimation() const { void Poll::saveStateInAnimation() const {
if (_answersAnimation) { if (_answersAnimation) {
return; return;
} }
@ -747,7 +746,7 @@ void HistoryPoll::saveStateInAnimation() const {
convert); convert);
} }
bool HistoryPoll::checkAnimationStart() const { bool Poll::checkAnimationStart() const {
if (_poll->answers.size() != _answers.size()) { if (_poll->answers.size() != _answers.size()) {
// Skip initial changes. // Skip initial changes.
return false; return false;
@ -760,7 +759,7 @@ bool HistoryPoll::checkAnimationStart() const {
return result; return result;
} }
void HistoryPoll::startAnswersAnimation() const { void Poll::startAnswersAnimation() const {
if (!_answersAnimation) { if (!_answersAnimation) {
return; return;
} }
@ -779,7 +778,7 @@ void HistoryPoll::startAnswersAnimation() const {
st::historyPollDuration); st::historyPollDuration);
} }
TextState HistoryPoll::textState(QPoint point, StateRequest request) const { TextState Poll::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (!_poll->sendingVote.isEmpty()) { if (!_poll->sendingVote.isEmpty()) {
return result; return result;
@ -821,7 +820,7 @@ TextState HistoryPoll::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
void HistoryPoll::clickHandlerPressedChanged( void Poll::clickHandlerPressedChanged(
const ClickHandlerPtr &handler, const ClickHandlerPtr &handler,
bool pressed) { bool pressed) {
if (!handler) return; if (!handler) return;
@ -835,7 +834,7 @@ void HistoryPoll::clickHandlerPressedChanged(
} }
} }
void HistoryPoll::toggleRipple(Answer &answer, bool pressed) { void Poll::toggleRipple(Answer &answer, bool pressed) {
if (pressed) { if (pressed) {
const auto outerWidth = width(); const auto outerWidth = width();
const auto innerWidth = outerWidth const auto innerWidth = outerWidth
@ -861,6 +860,8 @@ void HistoryPoll::toggleRipple(Answer &answer, bool pressed) {
} }
} }
HistoryPoll::~HistoryPoll() { Poll::~Poll() {
history()->owner().unregisterPollView(_poll, _parent); history()->owner().unregisterPollView(_poll, _parent);
} }
} // namespace HistoryView

View File

@ -7,13 +7,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
struct PollAnswer; struct PollAnswer;
class HistoryPoll : public HistoryMedia { namespace HistoryView {
class Poll : public Media {
public: public:
HistoryPoll( Poll(
not_null<Element*> parent, not_null<Element*> parent,
not_null<PollData*> poll); not_null<PollData*> poll);
@ -38,7 +40,7 @@ public:
const ClickHandlerPtr &handler, const ClickHandlerPtr &handler,
bool pressed) override; bool pressed) override;
~HistoryPoll(); ~Poll();
private: private:
struct AnswerAnimation; struct AnswerAnimation;
@ -128,3 +130,5 @@ private:
mutable QPoint _lastLinkPoint; mutable QPoint _lastLinkPoint;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "layout.h" #include "layout.h"
#include "boxes/sticker_set_box.h" #include "boxes/sticker_set_box.h"
@ -25,37 +25,32 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lottie/lottie_single_player.h" #include "lottie/lottie_single_player.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace HistoryView {
namespace { namespace {
using TextState = HistoryView::TextState;
double GetEmojiStickerZoom(not_null<Main::Session*> session) { double GetEmojiStickerZoom(not_null<Main::Session*> session) {
return session->appConfig().get<double>("emojies_animated_zoom", 0.625); return session->appConfig().get<double>("emojies_animated_zoom", 0.625);
} }
} // namespace } // namespace
HistorySticker::HistorySticker( Sticker::Sticker(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document) not_null<DocumentData*> document)
: HistoryMedia(parent) : Media(parent)
, _data(document) , _data(document) {
, _emoji(_data->sticker()->alt) {
_data->loadThumbnail(parent->data()->fullId()); _data->loadThumbnail(parent->data()->fullId());
if (const auto emoji = Ui::Emoji::Find(_emoji)) {
_emoji = emoji->text();
}
} }
HistorySticker::~HistorySticker() { Sticker::~Sticker() {
unloadLottie(); unloadLottie();
} }
bool HistorySticker::isEmojiSticker() const { bool Sticker::isEmojiSticker() const {
return (_parent->data()->media() == nullptr); return (_parent->data()->media() == nullptr);
} }
QSize HistorySticker::countOptimalSize() { QSize Sticker::countOptimalSize() {
auto sticker = _data->sticker(); auto sticker = _data->sticker();
if (!_packLink) { if (!_packLink) {
@ -109,7 +104,7 @@ QSize HistorySticker::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistorySticker::countCurrentSize(int newWidth) { QSize Sticker::countCurrentSize(int newWidth) {
const auto item = _parent->data(); const auto item = _parent->data();
accumulate_min(newWidth, maxWidth()); accumulate_min(newWidth, maxWidth());
if (_parent->media() == this) { if (_parent->media() == this) {
@ -129,7 +124,7 @@ QSize HistorySticker::countCurrentSize(int newWidth) {
return { newWidth, minHeight() }; return { newWidth, minHeight() };
} }
void HistorySticker::setupLottie() { void Sticker::setupLottie() {
_lottie = Stickers::LottiePlayerFromDocument( _lottie = Stickers::LottiePlayerFromDocument(
_data, _data,
Stickers::LottieSize::MessageHistory, Stickers::LottieSize::MessageHistory,
@ -147,7 +142,7 @@ void HistorySticker::setupLottie() {
}, _lifetime); }, _lifetime);
} }
void HistorySticker::unloadLottie() { void Sticker::unloadLottie() {
if (!_lottie) { if (!_lottie) {
return; return;
} }
@ -155,7 +150,7 @@ void HistorySticker::unloadLottie() {
_parent->data()->history()->owner().unregisterHeavyViewPart(_parent); _parent->data()->history()->owner().unregisterHeavyViewPart(_parent);
} }
void HistorySticker::draw( void Sticker::draw(
Painter &p, Painter &p,
const QRect &r, const QRect &r,
TextSelection selection, TextSelection selection,
@ -164,7 +159,7 @@ void HistorySticker::draw(
if (!sticker) return; if (!sticker) return;
if (sticker->animated && !_lottie && _data->loaded()) { if (sticker->animated && !_lottie && _data->loaded()) {
const_cast<HistorySticker*>(this)->setupLottie(); const_cast<Sticker*>(this)->setupLottie();
} }
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
@ -301,7 +296,7 @@ void HistorySticker::draw(
} }
} }
TextState HistorySticker::textState(QPoint point, StateRequest request) const { TextState Sticker::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
return result; return result;
@ -376,11 +371,11 @@ TextState HistorySticker::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
bool HistorySticker::needInfoDisplay() const { bool Sticker::needInfoDisplay() const {
return (_parent->data()->id < 0 || _parent->isUnderCursor()); return (_parent->data()->id < 0 || _parent->isUnderCursor());
} }
int HistorySticker::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply) const { int Sticker::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply) const {
int result = 0; int result = 0;
if (via) { if (via) {
accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + via->maxWidth + st::msgReplyPadding.left()); accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + via->maxWidth + st::msgReplyPadding.left());
@ -391,9 +386,11 @@ int HistorySticker::additionalWidth(const HistoryMessageVia *via, const HistoryM
return result; return result;
} }
int HistorySticker::additionalWidth() const { int Sticker::additionalWidth() const {
const auto item = _parent->data(); const auto item = _parent->data();
return additionalWidth( return additionalWidth(
item->Get<HistoryMessageVia>(), item->Get<HistoryMessageVia>(),
item->Get<HistoryMessageReply>()); item->Get<HistoryMessageReply>());
} }
} // namespace HistoryView

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "base/weak_ptr.h" #include "base/weak_ptr.h"
#include "base/timer.h" #include "base/timer.h"
@ -19,12 +19,14 @@ namespace Lottie {
class SinglePlayer; class SinglePlayer;
} // namespace Lottie } // namespace Lottie
class HistorySticker : public HistoryMedia, public base::has_weak_ptr { namespace HistoryView {
class Sticker : public Media, public base::has_weak_ptr {
public: public:
HistorySticker( Sticker(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document); not_null<DocumentData*> document);
~HistorySticker(); ~Sticker();
void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override; void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override;
TextState textState(QPoint point, StateRequest request) const override; TextState textState(QPoint point, StateRequest request) const override;
@ -49,9 +51,6 @@ public:
bool customInfoLayout() const override { bool customInfoLayout() const override {
return true; return true;
} }
QString emoji() const {
return _emoji;
}
bool hidesForwardedInfo() const override { bool hidesForwardedInfo() const override {
return true; return true;
} }
@ -79,11 +78,12 @@ private:
int _pixw = 1; int _pixw = 1;
int _pixh = 1; int _pixh = 1;
ClickHandlerPtr _packLink; ClickHandlerPtr _packLink;
not_null<DocumentData*> _data; DocumentData *_data = nullptr;
QString _emoji;
std::unique_ptr<Lottie::SinglePlayer> _lottie; std::unique_ptr<Lottie::SinglePlayer> _lottie;
mutable bool _lottieOncePlayed = false; mutable bool _lottieOncePlayed = false;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;
}; };
} // namespace HistoryView

View File

@ -5,9 +5,9 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_video.h" #include "history/view/media/history_view_video.h"
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "layout.h" #include "layout.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
@ -21,17 +21,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; Video::Video(
} // namespace
HistoryVideo::HistoryVideo(
not_null<Element*> parent, not_null<Element*> parent,
not_null<HistoryItem*> realParent, not_null<HistoryItem*> realParent,
not_null<DocumentData*> document) not_null<DocumentData*> document)
: HistoryFileMedia(parent, realParent) : File(parent, realParent)
, _data(document) , _data(document)
, _thumbw(1) , _thumbw(1)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
@ -45,7 +41,7 @@ HistoryVideo::HistoryVideo(
_data->loadThumbnail(realParent->fullId()); _data->loadThumbnail(realParent->fullId());
} }
QSize HistoryVideo::sizeForAspectRatio() const { QSize Video::sizeForAspectRatio() const {
// We use size only for aspect ratio and we want to have it // We use size only for aspect ratio and we want to have it
// as close to the thumbnail as possible. // as close to the thumbnail as possible.
//if (!_data->dimensions.isEmpty()) { //if (!_data->dimensions.isEmpty()) {
@ -59,7 +55,7 @@ QSize HistoryVideo::sizeForAspectRatio() const {
return { 1, 1 }; return { 1, 1 };
} }
QSize HistoryVideo::countOptimalDimensions() const { QSize Video::countOptimalDimensions() const {
const auto desired = ConvertScale(_data->dimensions); const auto desired = ConvertScale(_data->dimensions);
const auto size = desired.isEmpty() ? sizeForAspectRatio() : desired; const auto size = desired.isEmpty() ? sizeForAspectRatio() : desired;
auto tw = size.width(); auto tw = size.width();
@ -86,7 +82,7 @@ QSize HistoryVideo::countOptimalDimensions() const {
return QSize(tw, th); return QSize(tw, th);
} }
QSize HistoryVideo::countOptimalSize() { QSize Video::countOptimalSize() {
if (_parent->media() != this) { if (_parent->media() != this) {
_caption = Ui::Text::String(); _caption = Ui::Text::String();
} else if (_caption.hasSkipBlock()) { } else if (_caption.hasSkipBlock()) {
@ -117,7 +113,7 @@ QSize HistoryVideo::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryVideo::countCurrentSize(int newWidth) { QSize Video::countCurrentSize(int newWidth) {
const auto size = countOptimalDimensions(); const auto size = countOptimalDimensions();
auto tw = size.width(); auto tw = size.width();
auto th = size.height(); auto th = size.height();
@ -144,13 +140,13 @@ QSize HistoryVideo::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
bool HistoryVideo::downloadInCorner() const { bool Video::downloadInCorner() const {
return _data->canBeStreamed() return _data->canBeStreamed()
&& !_data->inappPlaybackFailed() && !_data->inappPlaybackFailed()
&& IsServerMsgId(_parent->data()->id); && IsServerMsgId(_parent->data()->id);
} }
void HistoryVideo::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void Video::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
_data->automaticLoad(_realParent->fullId(), _parent->data()); _data->automaticLoad(_realParent->fullId(), _parent->data());
@ -271,7 +267,7 @@ void HistoryVideo::draw(Painter &p, const QRect &r, TextSelection selection, crl
} }
} }
void HistoryVideo::drawCornerStatus(Painter &p, bool selected) const { void Video::drawCornerStatus(Painter &p, bool selected) const {
const auto padding = st::msgDateImgPadding; const auto padding = st::msgDateImgPadding;
const auto radial = _animation && _animation->radial.animating(); const auto radial = _animation && _animation->radial.animating();
const auto cornerDownload = downloadInCorner() && !_data->loaded() && !_data->loadedInMediaCache(); const auto cornerDownload = downloadInCorner() && !_data->loaded() && !_data->loadedInMediaCache();
@ -307,7 +303,7 @@ void HistoryVideo::drawCornerStatus(Painter &p, bool selected) const {
} }
} }
TextState HistoryVideo::cornerStatusTextState( TextState Video::cornerStatusTextState(
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
@ -324,7 +320,7 @@ TextState HistoryVideo::cornerStatusTextState(
return result; return result;
} }
TextState HistoryVideo::textState(QPoint point, StateRequest request) const { TextState Video::textState(QPoint point, StateRequest request) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
return {}; return {};
} }
@ -380,11 +376,11 @@ TextState HistoryVideo::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
QSize HistoryVideo::sizeForGrouping() const { QSize Video::sizeForGrouping() const {
return sizeForAspectRatio(); return sizeForAspectRatio();
} }
void HistoryVideo::drawGrouped( void Video::drawGrouped(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,
TextSelection selection, TextSelection selection,
@ -486,7 +482,7 @@ void HistoryVideo::drawGrouped(
} }
} }
TextState HistoryVideo::getStateGrouped( TextState Video::getStateGrouped(
const QRect &geometry, const QRect &geometry,
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
@ -502,24 +498,24 @@ TextState HistoryVideo::getStateGrouped(
: _savel); : _savel);
} }
bool HistoryVideo::uploading() const { bool Video::uploading() const {
return _data->uploading(); return _data->uploading();
} }
float64 HistoryVideo::dataProgress() const { float64 Video::dataProgress() const {
return _data->progress(); return _data->progress();
} }
bool HistoryVideo::dataFinished() const { bool Video::dataFinished() const {
return !_data->loading() return !_data->loading()
&& (!_data->uploading() || _data->waitingForAlbum()); && (!_data->uploading() || _data->waitingForAlbum());
} }
bool HistoryVideo::dataLoaded() const { bool Video::dataLoaded() const {
return _data->loaded(); return _data->loaded();
} }
void HistoryVideo::validateGroupedCache( void Video::validateGroupedCache(
const QRect &geometry, const QRect &geometry,
RectParts corners, RectParts corners,
not_null<uint64*> cacheKey, not_null<uint64*> cacheKey,
@ -575,15 +571,15 @@ void HistoryVideo::validateGroupedCache(
height); height);
} }
void HistoryVideo::setStatusSize(int newSize) const { void Video::setStatusSize(int newSize) const {
HistoryFileMedia::setStatusSize(newSize, _data->size, _data->getDuration(), 0); File::setStatusSize(newSize, _data->size, _data->getDuration(), 0);
} }
TextForMimeData HistoryVideo::selectedText(TextSelection selection) const { TextForMimeData Video::selectedText(TextSelection selection) const {
return _caption.toTextForMimeData(selection); return _caption.toTextForMimeData(selection);
} }
bool HistoryVideo::needsBubble() const { bool Video::needsBubble() const {
if (!_caption.isEmpty()) { if (!_caption.isEmpty()) {
return true; return true;
} }
@ -595,14 +591,14 @@ bool HistoryVideo::needsBubble() const {
return false; return false;
} }
void HistoryVideo::parentTextUpdated() { void Video::parentTextUpdated() {
_caption = (_parent->media() == this) _caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Ui::Text::String(); : Ui::Text::String();
history()->owner().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
void HistoryVideo::updateStatusText() const { void Video::updateStatusText() const {
auto showPause = false; auto showPause = false;
auto statusSize = 0; auto statusSize = 0;
auto realDuration = 0; auto realDuration = 0;
@ -621,3 +617,5 @@ void HistoryVideo::updateStatusText() const {
setStatusSize(statusSize); setStatusSize(statusSize);
} }
} }
} // namespace HistoryView

View File

@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media_file.h" #include "history/view/media/history_view_file.h"
class HistoryVideo : public HistoryFileMedia { namespace HistoryView {
class Video : public File {
public: public:
HistoryVideo( Video(
not_null<Element*> parent, not_null<Element*> parent,
not_null<HistoryItem*> realParent, not_null<HistoryItem*> realParent,
not_null<DocumentData*> document); not_null<DocumentData*> document);
@ -100,3 +102,5 @@ private:
QString _downloadSize; QString _downloadSize;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_wall_paper.h" #include "history/view/media/history_view_wall_paper.h"
#include "layout.h" #include "layout.h"
#include "history/history_item.h" #include "history/history_item.h"
@ -17,17 +17,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/themes/window_theme.h" #include "window/themes/window_theme.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState; WallPaper::WallPaper(
} // namespace
HistoryWallPaper::HistoryWallPaper(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document, not_null<DocumentData*> document,
const QString &url) const QString &url)
: HistoryFileMedia(parent, parent->data()) : File(parent, parent->data())
, _data(document) { , _data(document) {
Expects(_data->hasThumbnail()); Expects(_data->hasThumbnail());
@ -38,7 +34,7 @@ HistoryWallPaper::HistoryWallPaper(
setStatusSize(FileStatusSizeReady, _data->size, -1, 0); setStatusSize(FileStatusSizeReady, _data->size, -1, 0);
} }
void HistoryWallPaper::fillPatternFieldsFrom(const QString &url) { void WallPaper::fillPatternFieldsFrom(const QString &url) {
const auto paramsPosition = url.indexOf('?'); const auto paramsPosition = url.indexOf('?');
if (paramsPosition < 0) { if (paramsPosition < 0) {
return; return;
@ -53,7 +49,7 @@ void HistoryWallPaper::fillPatternFieldsFrom(const QString &url) {
_background = paper.backgroundColor().value_or(kDefaultBackground); _background = paper.backgroundColor().value_or(kDefaultBackground);
} }
QSize HistoryWallPaper::countOptimalSize() { QSize WallPaper::countOptimalSize() {
auto tw = ConvertScale(_data->thumbnail()->width()); auto tw = ConvertScale(_data->thumbnail()->width());
auto th = ConvertScale(_data->thumbnail()->height()); auto th = ConvertScale(_data->thumbnail()->height());
if (!tw || !th) { if (!tw || !th) {
@ -70,7 +66,7 @@ QSize HistoryWallPaper::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryWallPaper::countCurrentSize(int newWidth) { QSize WallPaper::countCurrentSize(int newWidth) {
auto tw = ConvertScale(_data->thumbnail()->width()); auto tw = ConvertScale(_data->thumbnail()->width());
auto th = ConvertScale(_data->thumbnail()->height()); auto th = ConvertScale(_data->thumbnail()->height());
if (!tw || !th) { if (!tw || !th) {
@ -90,7 +86,7 @@ QSize HistoryWallPaper::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
void HistoryWallPaper::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void WallPaper::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
_data->automaticLoad(_realParent->fullId(), _parent->data()); _data->automaticLoad(_realParent->fullId(), _parent->data());
@ -170,7 +166,7 @@ void HistoryWallPaper::draw(Painter &p, const QRect &r, TextSelection selection,
} }
} }
void HistoryWallPaper::validateThumbnail() const { void WallPaper::validateThumbnail() const {
if (_thumbnailGood > 0) { if (_thumbnailGood > 0) {
return; return;
} }
@ -195,7 +191,7 @@ void HistoryWallPaper::validateThumbnail() const {
} }
} }
void HistoryWallPaper::prepareThumbnailFrom( void WallPaper::prepareThumbnailFrom(
not_null<Image*> image, not_null<Image*> image,
int good) const { int good) const {
Expects(_thumbnailGood <= good); Expects(_thumbnailGood <= good);
@ -230,7 +226,7 @@ void HistoryWallPaper::prepareThumbnailFrom(
_thumbnailGood = good; _thumbnailGood = good;
} }
TextState HistoryWallPaper::textState(QPoint point, StateRequest request) const { TextState WallPaper::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -252,26 +248,28 @@ TextState HistoryWallPaper::textState(QPoint point, StateRequest request) const
return result; return result;
} }
float64 HistoryWallPaper::dataProgress() const { float64 WallPaper::dataProgress() const {
return _data->progress(); return _data->progress();
} }
bool HistoryWallPaper::dataFinished() const { bool WallPaper::dataFinished() const {
return !_data->loading() return !_data->loading()
&& (!_data->uploading() || _data->waitingForAlbum()); && (!_data->uploading() || _data->waitingForAlbum());
} }
bool HistoryWallPaper::dataLoaded() const { bool WallPaper::dataLoaded() const {
return _data->loaded(); return _data->loaded();
} }
bool HistoryWallPaper::isReadyForOpen() const { bool WallPaper::isReadyForOpen() const {
return _data->loaded(); return _data->loaded();
} }
QString HistoryWallPaper::additionalInfoString() const { QString WallPaper::additionalInfoString() const {
// This will force message info (time) to be displayed below // This will force message info (time) to be displayed below
// this attachment in HistoryWebPage media. // this attachment in WebPage media.
static auto result = QString(" "); static auto result = QString(" ");
return result; return result;
} }
} // namespace HistoryView

View File

@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media_file.h" #include "history/view/media/history_view_file.h"
class HistoryWallPaper : public HistoryFileMedia { namespace HistoryView {
class WallPaper : public File {
public: public:
HistoryWallPaper( WallPaper(
not_null<Element*> parent, not_null<Element*> parent,
not_null<DocumentData*> document, not_null<DocumentData*> document,
const QString &url = QString()); const QString &url = QString());
@ -61,3 +63,5 @@ private:
int _intensity = 0; int _intensity = 0;
}; };
} // namespace HistoryView

View File

@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/media/history_media_web_page.h" #include "history/view/media/history_view_web_page.h"
#include "layout.h" #include "layout.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -25,12 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "styles/style_history.h" #include "styles/style_history.h"
namespace { namespace HistoryView {
using TextState = HistoryView::TextState;
} // namespace
namespace { namespace {
constexpr auto kMaxOriginalEntryLines = 8192; constexpr auto kMaxOriginalEntryLines = 8192;
@ -73,17 +68,17 @@ std::vector<std::unique_ptr<Data::Media>> PrepareCollageMedia(
} // namespace } // namespace
HistoryWebPage::HistoryWebPage( WebPage::WebPage(
not_null<Element*> parent, not_null<Element*> parent,
not_null<WebPageData*> data) not_null<WebPageData*> data)
: HistoryMedia(parent) : Media(parent)
, _data(data) , _data(data)
, _title(st::msgMinWidth - st::webPageLeft) , _title(st::msgMinWidth - st::webPageLeft)
, _description(st::msgMinWidth - st::webPageLeft) { , _description(st::msgMinWidth - st::webPageLeft) {
history()->owner().registerWebPageView(_data, _parent); history()->owner().registerWebPageView(_data, _parent);
} }
QSize HistoryWebPage::countOptimalSize() { QSize WebPage::countOptimalSize() {
if (_data->pendingTill) { if (_data->pendingTill) {
return { 0, 0 }; return { 0, 0 };
} }
@ -276,7 +271,7 @@ QSize HistoryWebPage::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
QSize HistoryWebPage::countCurrentSize(int newWidth) { QSize WebPage::countCurrentSize(int newWidth) {
if (_data->pendingTill) { if (_data->pendingTill) {
return { newWidth, minHeight() }; return { newWidth, minHeight() };
} }
@ -373,23 +368,23 @@ QSize HistoryWebPage::countCurrentSize(int newWidth) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
TextSelection HistoryWebPage::toDescriptionSelection( TextSelection WebPage::toDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::UnshiftItemSelection(selection, _title); return UnshiftItemSelection(selection, _title);
} }
TextSelection HistoryWebPage::fromDescriptionSelection( TextSelection WebPage::fromDescriptionSelection(
TextSelection selection) const { TextSelection selection) const {
return HistoryView::ShiftItemSelection(selection, _title); return ShiftItemSelection(selection, _title);
} }
void HistoryWebPage::refreshParentId(not_null<HistoryItem*> realParent) { void WebPage::refreshParentId(not_null<HistoryItem*> realParent) {
if (_attach) { if (_attach) {
_attach->refreshParentId(realParent); _attach->refreshParentId(realParent);
} }
} }
void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const { void WebPage::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintx = 0, painty = 0, paintw = width(), painth = height(); auto paintx = 0, painty = 0, paintw = width(), painth = height();
@ -525,11 +520,11 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, c
} }
} }
bool HistoryWebPage::asArticle() const { bool WebPage::asArticle() const {
return _asArticle && (_data->photo != nullptr); return _asArticle && (_data->photo != nullptr);
} }
TextState HistoryWebPage::textState(QPoint point, StateRequest request) const { TextState WebPage::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) {
@ -615,7 +610,7 @@ TextState HistoryWebPage::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
ClickHandlerPtr HistoryWebPage::replaceAttachLink( ClickHandlerPtr WebPage::replaceAttachLink(
const ClickHandlerPtr &link) const { const ClickHandlerPtr &link) const {
if (!link || !_attach->isReadyForOpen() || !_collage.empty()) { if (!link || !_attach->isReadyForOpen() || !_collage.empty()) {
return link; return link;
@ -639,7 +634,7 @@ ClickHandlerPtr HistoryWebPage::replaceAttachLink(
return link; return link;
} }
TextSelection HistoryWebPage::adjustSelection(TextSelection selection, TextSelectType type) const { TextSelection WebPage::adjustSelection(TextSelection selection, TextSelectType type) const {
if (!_descriptionLines || selection.to <= _title.length()) { if (!_descriptionLines || selection.to <= _title.length()) {
return _title.adjustSelection(selection, type); return _title.adjustSelection(selection, type);
} }
@ -651,25 +646,25 @@ TextSelection HistoryWebPage::adjustSelection(TextSelection selection, TextSelec
return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to }; return { titleSelection.from, fromDescriptionSelection(descriptionSelection).to };
} }
void HistoryWebPage::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) { void WebPage::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
if (_attach) { if (_attach) {
_attach->clickHandlerActiveChanged(p, active); _attach->clickHandlerActiveChanged(p, active);
} }
} }
void HistoryWebPage::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) { void WebPage::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
if (_attach) { if (_attach) {
_attach->clickHandlerPressedChanged(p, pressed); _attach->clickHandlerPressedChanged(p, pressed);
} }
} }
bool HistoryWebPage::enforceBubbleWidth() const { bool WebPage::enforceBubbleWidth() const {
return (_attach != nullptr) return (_attach != nullptr)
&& (_data->document != nullptr) && (_data->document != nullptr)
&& _data->document->isWallPaper(); && _data->document->isWallPaper();
} }
void HistoryWebPage::playAnimation(bool autoplay) { void WebPage::playAnimation(bool autoplay) {
if (_attach) { if (_attach) {
if (autoplay) { if (autoplay) {
_attach->autoplayAnimation(); _attach->autoplayAnimation();
@ -679,13 +674,13 @@ void HistoryWebPage::playAnimation(bool autoplay) {
} }
} }
bool HistoryWebPage::isDisplayed() const { bool WebPage::isDisplayed() const {
const auto item = _parent->data(); const auto item = _parent->data();
return !_data->pendingTill return !_data->pendingTill
&& !item->Has<HistoryMessageLogEntryOriginal>(); && !item->Has<HistoryMessageLogEntryOriginal>();
} }
TextForMimeData HistoryWebPage::selectedText(TextSelection selection) const { TextForMimeData WebPage::selectedText(TextSelection selection) const {
auto titleResult = _title.toTextForMimeData(selection); auto titleResult = _title.toTextForMimeData(selection);
auto descriptionResult = _description.toTextForMimeData( auto descriptionResult = _description.toTextForMimeData(
toDescriptionSelection(selection)); toDescriptionSelection(selection));
@ -698,7 +693,7 @@ TextForMimeData HistoryWebPage::selectedText(TextSelection selection) const {
return titleResult.append('\n').append(std::move(descriptionResult)); return titleResult.append('\n').append(std::move(descriptionResult));
} }
QMargins HistoryWebPage::inBubblePadding() const { QMargins WebPage::inBubblePadding() const {
auto lshift = st::msgPadding.left() + st::webPageLeft; auto lshift = st::msgPadding.left() + st::webPageLeft;
auto rshift = st::msgPadding.right(); auto rshift = st::msgPadding.right();
auto bshift = isBubbleBottom() ? st::msgPadding.left() : st::mediaInBubbleSkip; auto bshift = isBubbleBottom() ? st::msgPadding.left() : st::mediaInBubbleSkip;
@ -706,11 +701,11 @@ QMargins HistoryWebPage::inBubblePadding() const {
return QMargins(lshift, tshift, rshift, bshift); return QMargins(lshift, tshift, rshift, bshift);
} }
bool HistoryWebPage::isLogEntryOriginal() const { bool WebPage::isLogEntryOriginal() const {
return _parent->data()->isLogEntry() && _parent->media() != this; return _parent->data()->isLogEntry() && _parent->media() != this;
} }
int HistoryWebPage::bottomInfoPadding() const { int WebPage::bottomInfoPadding() const {
if (!isBubbleBottom()) return 0; if (!isBubbleBottom()) return 0;
auto result = st::msgDateFont->height; auto result = st::msgDateFont->height;
@ -724,12 +719,14 @@ int HistoryWebPage::bottomInfoPadding() const {
return result; return result;
} }
QString HistoryWebPage::displayedSiteName() const { QString WebPage::displayedSiteName() const {
return (_data->document && _data->document->isWallPaper()) return (_data->document && _data->document->isWallPaper())
? tr::lng_media_chat_background(tr::now) ? tr::lng_media_chat_background(tr::now)
: _data->siteName; : _data->siteName;
} }
HistoryWebPage::~HistoryWebPage() { WebPage::~WebPage() {
history()->owner().unregisterWebPageView(_data, _parent); history()->owner().unregisterWebPageView(_data, _parent);
} }
} // namespace HistoryView

View File

@ -7,15 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
namespace Data { namespace Data {
class Media; class Media;
} // namespace Data } // namespace Data
class HistoryWebPage : public HistoryMedia { namespace HistoryView {
class WebPage : public Media {
public: public:
HistoryWebPage( WebPage(
not_null<Element*> parent, not_null<Element*> parent,
not_null<WebPageData*> data); not_null<WebPageData*> data);
@ -76,11 +78,11 @@ public:
} }
bool enforceBubbleWidth() const override; bool enforceBubbleWidth() const override;
HistoryMedia *attach() const { Media *attach() const {
return _attach.get(); return _attach.get();
} }
~HistoryWebPage(); ~WebPage();
private: private:
void playAnimation(bool autoplay) override; void playAnimation(bool autoplay) override;
@ -100,7 +102,7 @@ private:
not_null<WebPageData*> _data; not_null<WebPageData*> _data;
std::vector<std::unique_ptr<Data::Media>> _collage; std::vector<std::unique_ptr<Data::Media>> _collage;
ClickHandlerPtr _openl; ClickHandlerPtr _openl;
std::unique_ptr<HistoryMedia> _attach; std::unique_ptr<Media> _attach;
bool _asArticle = false; bool _asArticle = false;
int _dataVersion = -1; int _dataVersion = -1;
@ -117,3 +119,5 @@ private:
int _pixh = 0; int _pixh = 0;
}; };
} // namespace HistoryView

View File

@ -1557,7 +1557,7 @@ bool ListWidget::requiredToStartDragging(
if (_mouseCursorState == CursorState::Date) { if (_mouseCursorState == CursorState::Date) {
return true; return true;
} }
// return dynamic_cast<HistorySticker*>(layout->getMedia()); // return dynamic_cast<Sticker*>(layout->getMedia());
return false; return false;
} }
@ -1948,7 +1948,7 @@ void ListWidget::performDrag() {
// return; // return;
//} else { //} else {
// auto forwardMimeType = QString(); // auto forwardMimeType = QString();
// auto pressedMedia = static_cast<HistoryMedia*>(nullptr); // auto pressedMedia = static_cast<HistoryView::Media*>(nullptr);
// if (auto pressedItem = _pressState.layout) { // if (auto pressedItem = _pressState.layout) {
// pressedMedia = pressedItem->getMedia(); // pressedMedia = pressedItem->getMedia();
// if (_mouseCursorState == CursorState::Date || (pressedMedia && pressedMedia->dragItem())) { // if (_mouseCursorState == CursorState::Date || (pressedMedia && pressedMedia->dragItem())) {

View File

@ -47,7 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_widget.h" #include "history/history_widget.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"

View File

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "media/audio/media_audio.h" #include "media/audio/media_audio.h"

View File

@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_web_page.h" #include "data/data_web_page.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "history/history.h" #include "history/history.h"
#include "history/media/history_media.h" #include "history/view/media/history_view_media.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "styles/style_mediaview.h" #include "styles/style_mediaview.h"

View File

@ -13,8 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
#include "styles/style_overview.h" #include "styles/style_overview.h"
class HistoryMedia;
namespace style { namespace style {
struct RoundCheckbox; struct RoundCheckbox;
} // namespace style } // namespace style

View File

@ -274,40 +274,40 @@
<(src_loc)/history/admin_log/history_admin_log_section.h <(src_loc)/history/admin_log/history_admin_log_section.h
//<(src_loc)/history/feed/history_feed_section.cpp //<(src_loc)/history/feed/history_feed_section.cpp
//<(src_loc)/history/feed/history_feed_section.h //<(src_loc)/history/feed/history_feed_section.h
<(src_loc)/history/media/history_media.h <(src_loc)/history/view/media/history_view_call.h
<(src_loc)/history/media/history_media.cpp <(src_loc)/history/view/media/history_view_call.cpp
<(src_loc)/history/media/history_media_call.h <(src_loc)/history/view/media/history_view_contact.h
<(src_loc)/history/media/history_media_call.cpp <(src_loc)/history/view/media/history_view_contact.cpp
<(src_loc)/history/media/history_media_common.h <(src_loc)/history/view/media/history_view_document.h
<(src_loc)/history/media/history_media_common.cpp <(src_loc)/history/view/media/history_view_document.cpp
<(src_loc)/history/media/history_media_contact.h <(src_loc)/history/view/media/history_view_file.h
<(src_loc)/history/media/history_media_contact.cpp <(src_loc)/history/view/media/history_view_file.cpp
<(src_loc)/history/media/history_media_document.h <(src_loc)/history/view/media/history_view_game.h
<(src_loc)/history/media/history_media_document.cpp <(src_loc)/history/view/media/history_view_game.cpp
<(src_loc)/history/media/history_media_file.h <(src_loc)/history/view/media/history_view_gif.h
<(src_loc)/history/media/history_media_file.cpp <(src_loc)/history/view/media/history_view_gif.cpp
<(src_loc)/history/media/history_media_game.h <(src_loc)/history/view/media/history_view_invoice.h
<(src_loc)/history/media/history_media_game.cpp <(src_loc)/history/view/media/history_view_invoice.cpp
<(src_loc)/history/media/history_media_gif.h <(src_loc)/history/view/media/history_view_location.h
<(src_loc)/history/media/history_media_gif.cpp <(src_loc)/history/view/media/history_view_location.cpp
<(src_loc)/history/media/history_media_grouped.h <(src_loc)/history/view/media/history_view_media.h
<(src_loc)/history/media/history_media_grouped.cpp <(src_loc)/history/view/media/history_view_media.cpp
<(src_loc)/history/media/history_media_invoice.h <(src_loc)/history/view/media/history_view_media_common.h
<(src_loc)/history/media/history_media_invoice.cpp <(src_loc)/history/view/media/history_view_media_common.cpp
<(src_loc)/history/media/history_media_location.h <(src_loc)/history/view/media/history_view_media_grouped.h
<(src_loc)/history/media/history_media_location.cpp <(src_loc)/history/view/media/history_view_media_grouped.cpp
<(src_loc)/history/media/history_media_photo.h <(src_loc)/history/view/media/history_view_photo.h
<(src_loc)/history/media/history_media_photo.cpp <(src_loc)/history/view/media/history_view_photo.cpp
<(src_loc)/history/media/history_media_poll.h <(src_loc)/history/view/media/history_view_poll.h
<(src_loc)/history/media/history_media_poll.cpp <(src_loc)/history/view/media/history_view_poll.cpp
<(src_loc)/history/media/history_media_sticker.h <(src_loc)/history/view/media/history_view_sticker.h
<(src_loc)/history/media/history_media_sticker.cpp <(src_loc)/history/view/media/history_view_sticker.cpp
<(src_loc)/history/media/history_media_video.h <(src_loc)/history/view/media/history_view_video.h
<(src_loc)/history/media/history_media_video.cpp <(src_loc)/history/view/media/history_view_video.cpp
<(src_loc)/history/media/history_media_wall_paper.h <(src_loc)/history/view/media/history_view_wall_paper.h
<(src_loc)/history/media/history_media_wall_paper.cpp <(src_loc)/history/view/media/history_view_wall_paper.cpp
<(src_loc)/history/media/history_media_web_page.h <(src_loc)/history/view/media/history_view_web_page.h
<(src_loc)/history/media/history_media_web_page.cpp <(src_loc)/history/view/media/history_view_web_page.cpp
<(src_loc)/history/view/history_view_contact_status.cpp <(src_loc)/history/view/history_view_contact_status.cpp
<(src_loc)/history/view/history_view_contact_status.h <(src_loc)/history/view/history_view_contact_status.h
<(src_loc)/history/view/history_view_context_menu.cpp <(src_loc)/history/view/history_view_context_menu.cpp