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::customEmojiRepaint() {
}
//void Element::externalLottieProgressing(bool external) const {
// if (const auto media = _media.get()) {
// media->externalLottieProgressing(external);

View file

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

View file

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

View file

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

View file

@ -672,6 +672,7 @@ void Document::draw(
}
if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
p.setPen(stm->historyTextFg);
applyCustomEmojiPause(p, captioned->_caption);
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()) {
const auto context = Core::MarkedTextContext{
.session = &history()->session(),
.customEmojiRepaint = [=] {
history()->owner().requestViewRepaint(_parent); },
.customEmojiRepaint = [=] { _parent->customEmojiRepaint(); },
};
_description.setMarkedText(
st::webPageDescriptionStyle,
@ -246,6 +245,7 @@ void Game::draw(Painter &p, const PaintContext &context) const {
if (_description.hasSkipBlock()) {
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));
tshift += _descriptionLines * lineHeight;
}
@ -431,8 +431,7 @@ void Game::parentTextUpdated() {
if (!consumed.text.isEmpty()) {
const auto context = Core::MarkedTextContext{
.session = &history()->session(),
.customEmojiRepaint = [=] {
history()->owner().requestViewRepaint(_parent); },
.customEmojiRepaint = [=] { _parent->customEmojiRepaint(); },
};
_description.setMarkedText(
st::webPageDescriptionStyle,

View file

@ -670,6 +670,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
}
if (!unwrapped && !_caption.isEmpty()) {
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);
} else if (!inWebPage && !skipDrawingSurrounding) {
auto fullRight = paintx + usex + usew;

View file

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

View file

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

View file

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

View file

@ -335,6 +335,7 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
// date
if (!_caption.isEmpty()) {
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);
} else if (!inWebPage) {
auto fullRight = paintx + paintw;

View file

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

View file

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