Fix custom emoji pausing in captions.

This commit is contained in:
John Preston 2022-07-01 18:23:30 +04:00
parent 7a10d3d82c
commit 289602528c
13 changed files with 48 additions and 13 deletions

View file

@ -412,6 +412,9 @@ void Element::setY(int y) {
void Element::refreshDataIdHook() { void Element::refreshDataIdHook() {
} }
void Element::customEmojiRepaint() {
}
//void Element::externalLottieProgressing(bool external) const { //void Element::externalLottieProgressing(bool external) const {
// if (const auto media = _media.get()) { // if (const auto media = _media.get()) {
// media->externalLottieProgressing(external); // media->externalLottieProgressing(external);

View file

@ -427,6 +427,8 @@ public:
virtual QRect innerGeometry() const = 0; virtual QRect innerGeometry() const = 0;
virtual void customEmojiRepaint();
[[nodiscard]] ClickHandlerPtr fromPhotoLink() const { [[nodiscard]] ClickHandlerPtr fromPhotoLink() const {
return fromLink(); return fromLink();
} }

View file

@ -849,7 +849,7 @@ void Message::draw(Painter &p, const PaintContext &context) const {
auto mediaPosition = QPoint( auto mediaPosition = QPoint(
inner.left(), inner.left(),
trect.y() + trect.height() - mediaHeight); trect.y() + trect.height() - mediaHeight);
_mediaRepaintScheduled = false;
p.translate(mediaPosition); p.translate(mediaPosition);
media->draw(p, context.translated( media->draw(p, context.translated(
-mediaPosition -mediaPosition
@ -918,6 +918,7 @@ void Message::draw(Painter &p, const PaintContext &context) const {
media->paintBubbleFireworks(p, g, context.now); media->paintBubbleFireworks(p, g, context.now);
} }
} else if (media && media->isDisplayed()) { } else if (media && media->isDisplayed()) {
_mediaRepaintScheduled = false;
p.translate(g.topLeft()); p.translate(g.topLeft());
media->draw(p, context.translated( media->draw(p, context.translated(
-g.topLeft() -g.topLeft()
@ -2823,6 +2824,13 @@ QRect Message::innerGeometry() const {
return result; return result;
} }
void Message::customEmojiRepaint() {
if (!_mediaRepaintScheduled) {
_mediaRepaintScheduled = true;
history()->owner().requestViewRepaint(this);
}
}
QRect Message::countGeometry() const { QRect Message::countGeometry() const {
const auto commentsRoot = (context() == Context::Replies) const auto commentsRoot = (context() == Context::Replies)
&& data()->isDiscussionPost(); && data()->isDiscussionPost();

View file

@ -140,6 +140,8 @@ public:
QRect innerGeometry() const override; QRect innerGeometry() const override;
void customEmojiRepaint() override;
protected: protected:
void refreshDataIdHook() override; void refreshDataIdHook() override;
@ -253,6 +255,7 @@ private:
Ui::Text::String _rightBadge; Ui::Text::String _rightBadge;
int _bubbleWidthLimit = 0; int _bubbleWidthLimit = 0;
mutable bool _heavyCustomEmoji = false; mutable bool _heavyCustomEmoji = false;
mutable bool _mediaRepaintScheduled = false;
BottomInfo _bottomInfo; BottomInfo _bottomInfo;

View file

@ -672,6 +672,7 @@ void Document::draw(
} }
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
p.setPen(stm->historyTextFg); p.setPen(stm->historyTextFg);
applyCustomEmojiPause(p, captioned->_caption);
captioned->_caption.draw(p, st::msgPadding.left(), captiontop, captionw, style::al_left, 0, -1, selection); captioned->_caption.draw(p, st::msgPadding.left(), captiontop, captionw, style::al_left, 0, -1, selection);
} }
} }

View file

@ -36,8 +36,7 @@ Game::Game(
if (!consumed.text.isEmpty()) { if (!consumed.text.isEmpty()) {
const auto context = Core::MarkedTextContext{ const auto context = Core::MarkedTextContext{
.session = &history()->session(), .session = &history()->session(),
.customEmojiRepaint = [=] { .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); },
history()->owner().requestViewRepaint(_parent); },
}; };
_description.setMarkedText( _description.setMarkedText(
st::webPageDescriptionStyle, st::webPageDescriptionStyle,
@ -246,6 +245,7 @@ void Game::draw(Painter &p, const PaintContext &context) const {
if (_description.hasSkipBlock()) { if (_description.hasSkipBlock()) {
endskip = _parent->skipBlockWidth(); endskip = _parent->skipBlockWidth();
} }
applyCustomEmojiPause(p, _description);
_description.drawLeftElided(p, padding.left(), tshift, paintw, width(), _descriptionLines, style::al_left, 0, -1, endskip, false, toDescriptionSelection(context.selection)); _description.drawLeftElided(p, padding.left(), tshift, paintw, width(), _descriptionLines, style::al_left, 0, -1, endskip, false, toDescriptionSelection(context.selection));
tshift += _descriptionLines * lineHeight; tshift += _descriptionLines * lineHeight;
} }
@ -431,8 +431,7 @@ void Game::parentTextUpdated() {
if (!consumed.text.isEmpty()) { if (!consumed.text.isEmpty()) {
const auto context = Core::MarkedTextContext{ const auto context = Core::MarkedTextContext{
.session = &history()->session(), .session = &history()->session(),
.customEmojiRepaint = [=] { .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); },
history()->owner().requestViewRepaint(_parent); },
}; };
_description.setMarkedText( _description.setMarkedText(
st::webPageDescriptionStyle, st::webPageDescriptionStyle,

View file

@ -670,6 +670,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
} }
if (!unwrapped && !_caption.isEmpty()) { if (!unwrapped && !_caption.isEmpty()) {
p.setPen(stm->historyTextFg); p.setPen(stm->historyTextFg);
applyCustomEmojiPause(p, _caption);
_caption.draw(p, st::msgPadding.left(), painty + painth + st::mediaCaptionSkip, captionw, style::al_left, 0, -1, context.selection); _caption.draw(p, st::msgPadding.left(), painty + painth + st::mediaCaptionSkip, captionw, style::al_left, 0, -1, context.selection);
} else if (!inWebPage && !skipDrawingSurrounding) { } else if (!inWebPage && !skipDrawingSurrounding) {
auto fullRight = paintx + usex + usew; auto fullRight = paintx + usex + usew;

View file

@ -191,6 +191,14 @@ void Media::repaint() const {
history()->owner().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
void Media::applyCustomEmojiPause(
Painter &p,
const Ui::Text::String &text) const {
if (text.hasCustomEmoji()) {
p.setInactive(_parent->delegate()->elementIsGifPaused());
}
}
Ui::Text::String Media::createCaption(not_null<HistoryItem*> item) const { Ui::Text::String Media::createCaption(not_null<HistoryItem*> item) const {
if (item->emptyText()) { if (item->emptyText()) {
return {}; return {};
@ -201,8 +209,7 @@ Ui::Text::String Media::createCaption(not_null<HistoryItem*> item) const {
auto result = Ui::Text::String(minResizeWidth); auto result = Ui::Text::String(minResizeWidth);
const auto context = Core::MarkedTextContext{ const auto context = Core::MarkedTextContext{
.session = &history()->session(), .session = &history()->session(),
.customEmojiRepaint = [=] { .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); },
history()->owner().requestViewRepaint(_parent); },
}; };
result.setMarkedText( result.setMarkedText(
st::messageTextStyle, st::messageTextStyle,

View file

@ -329,6 +329,9 @@ protected:
[[nodiscard]] bool usesBubblePattern(const PaintContext &context) const; [[nodiscard]] bool usesBubblePattern(const PaintContext &context) const;
void repaint() const; void repaint() const;
void applyCustomEmojiPause(
Painter &p,
const Ui::Text::String &text) const;
const not_null<Element*> _parent; const not_null<Element*> _parent;
MediaInBubbleState _inBubbleState = MediaInBubbleState::None; MediaInBubbleState _inBubbleState = MediaInBubbleState::None;

View file

@ -344,6 +344,7 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const {
- _caption.countHeight(captionw); - _caption.countHeight(captionw);
const auto stm = context.messageStyle(); const auto stm = context.messageStyle();
p.setPen(stm->historyTextFg); p.setPen(stm->historyTextFg);
applyCustomEmojiPause(p, _caption);
_caption.draw(p, st::msgPadding.left(), captiony, captionw, style::al_left, 0, -1, selection); _caption.draw(p, st::msgPadding.left(), captiony, captionw, style::al_left, 0, -1, selection);
} else if (_parent->media() == this) { } else if (_parent->media() == this) {
auto fullRight = width(); auto fullRight = width();

View file

@ -335,6 +335,7 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
// date // date
if (!_caption.isEmpty()) { if (!_caption.isEmpty()) {
p.setPen(stm->historyTextFg); p.setPen(stm->historyTextFg);
applyCustomEmojiPause(p, _caption);
_caption.draw(p, st::msgPadding.left(), painty + painth + st::mediaCaptionSkip, captionw, style::al_left, 0, -1, context.selection); _caption.draw(p, st::msgPadding.left(), painty + painth + st::mediaCaptionSkip, captionw, style::al_left, 0, -1, context.selection);
} else if (!inWebPage) { } else if (!inWebPage) {
auto fullRight = paintx + paintw; auto fullRight = paintx + paintw;

View file

@ -210,12 +210,11 @@ QSize WebPage::countOptimalSize() {
- st::msgPadding.right() - st::msgPadding.right()
- st::webPageLeft); - st::webPageLeft);
} }
auto context = Core::MarkedTextContext{
.session = &history()->session(),
.customEmojiRepaint = [=] {
history()->owner().requestViewRepaint(_parent); },
};
using MarkedTextContext = Core::MarkedTextContext; using MarkedTextContext = Core::MarkedTextContext;
auto context = MarkedTextContext{
.session = &history()->session(),
.customEmojiRepaint = [=] { _parent->customEmojiRepaint(); },
};
if (_data->siteName == qstr("Twitter")) { if (_data->siteName == qstr("Twitter")) {
context.type = MarkedTextContext::HashtagMentionType::Twitter; context.type = MarkedTextContext::HashtagMentionType::Twitter;
} else if (_data->siteName == qstr("Instagram")) { } else if (_data->siteName == qstr("Instagram")) {
@ -566,6 +565,7 @@ void WebPage::draw(Painter &p, const PaintContext &context) const {
if (_description.hasSkipBlock()) { if (_description.hasSkipBlock()) {
endskip = _parent->skipBlockWidth(); endskip = _parent->skipBlockWidth();
} }
applyCustomEmojiPause(p, _description);
if (_descriptionLines > 0) { if (_descriptionLines > 0) {
_description.drawLeftElided(p, padding.left(), tshift, paintw, width(), _descriptionLines, style::al_left, 0, -1, endskip, false, toDescriptionSelection(context.selection)); _description.drawLeftElided(p, padding.left(), tshift, paintw, width(), _descriptionLines, style::al_left, 0, -1, endskip, false, toDescriptionSelection(context.selection));
tshift += _descriptionLines * lineHeight; tshift += _descriptionLines * lineHeight;

View file

@ -2264,9 +2264,15 @@ void OverlayWidget::refreshCaption() {
const auto base = duration const auto base = duration
? TimestampLinkBase(_document, _message->fullId()) ? TimestampLinkBase(_document, _message->fullId())
: QString(); : QString();
const auto captionRepaint = [=] {
if (_fullScreenVideo || !_controlsOpacity.current()) {
return;
}
update(captionGeometry());
};
const auto context = Core::MarkedTextContext{ const auto context = Core::MarkedTextContext{
.session = &_message->history()->session(), .session = &_message->history()->session(),
.customEmojiRepaint = [=] { update(); }, .customEmojiRepaint = captionRepaint,
}; };
_caption.setMarkedText( _caption.setMarkedText(
st::mediaviewCaptionStyle, st::mediaviewCaptionStyle,