viewer#2270 The "More" button does not close the "Choose emoji" floater

master
Andrey Kleshchev 2024-10-08 22:10:50 +03:00 committed by Andrey Kleshchev
parent 28638b31af
commit 5608c3998d
6 changed files with 72 additions and 2 deletions

View File

@ -99,6 +99,7 @@ void LLEmojiHelper::showHelper(LLUICtrl* hostctrl_p, S32 local_x, S32 local_y, c
LLFloater* pHelperFloater = LLFloaterReg::getInstance(DEFAULT_EMOJI_HELPER_FLOATER);
mHelperHandle = pHelperFloater->getHandle();
mHelperCommitConn = pHelperFloater->setCommitCallback(std::bind([&](const LLSD& sdValue) { onCommitEmoji(utf8str_to_wstring(sdValue.asStringRef())[0]); }, std::placeholders::_2));
mHelperCloseConn = pHelperFloater->setCloseCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCloseHelper(ctrl, param); });
}
setHostCtrl(hostctrl_p);
mEmojiCommitCb = cb;
@ -148,6 +149,16 @@ void LLEmojiHelper::onCommitEmoji(llwchar emoji)
}
}
void LLEmojiHelper::onCloseHelper(LLUICtrl* ctrl, const LLSD& param)
{
mCloseSignal(ctrl, param);
}
boost::signals2::connection LLEmojiHelper::setCloseCallback(const commit_signal_t::slot_type& cb)
{
return mCloseSignal.connect(cb);
}
void LLEmojiHelper::setHostCtrl(LLUICtrl* hostctrl_p)
{
const LLUICtrl* pCurHostCtrl = mHostHandle.get();

View File

@ -51,16 +51,23 @@ public:
// Eventing
bool handleKey(const LLUICtrl* ctrl_p, KEY key, MASK mask);
void onCommitEmoji(llwchar emoji);
void onCloseHelper(LLUICtrl* ctrl, const LLSD& param);
typedef boost::signals2::signal<void(LLUICtrl* ctrl, const LLSD& param)> commit_signal_t;
boost::signals2::connection setCloseCallback(const commit_signal_t::slot_type& cb);
protected:
LLUICtrl* getHostCtrl() const { return mHostHandle.get(); }
void setHostCtrl(LLUICtrl* hostctrl_p);
private:
commit_signal_t mCloseSignal;
LLHandle<LLUICtrl> mHostHandle;
LLHandle<LLFloater> mHelperHandle;
boost::signals2::connection mHostCtrlFocusLostConn;
boost::signals2::connection mHelperCommitConn;
boost::signals2::connection mHelperCloseConn;
std::function<void(llwchar)> mEmojiCommitCb;
bool mIsHideDisabled;
};

View File

@ -1211,6 +1211,14 @@ void LLTextEditor::showEmojiHelper()
LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, LLStringUtil::null, cb);
}
void LLTextEditor::hideEmojiHelper()
{
if (mShowEmojiHelper)
{
LLEmojiHelper::instance().hideHelper(this);
}
}
void LLTextEditor::tryToShowEmojiHelper()
{
if (mReadOnly || !mShowEmojiHelper)

View File

@ -207,6 +207,7 @@ public:
bool getShowContextMenu() const { return mShowContextMenu; }
void showEmojiHelper();
void hideEmojiHelper();
void setShowEmojiHelper(bool show);
bool getShowEmojiHelper() const { return mShowEmojiHelper; }

View File

@ -39,6 +39,7 @@
#include "llchicletbar.h"
#include "lldraghandle.h"
#include "llemojidictionary.h"
#include "llemojihelper.h"
#include "llfloaterreg.h"
#include "llfloateremojipicker.h"
#include "llfloaterimsession.h"
@ -300,6 +301,8 @@ bool LLFloaterIMSessionTab::postBuild()
mEmojiPickerShowBtn = getChild<LLButton>("emoji_picker_show_btn");
mEmojiPickerShowBtn->setClickedCallback([this](LLUICtrl*, const LLSD&) { onEmojiPickerShowBtnClicked(); });
mEmojiPickerShowBtn->setMouseDownCallback([this](LLUICtrl*, const LLSD&) { onEmojiPickerShowBtnDown(); });
mEmojiCloseConn = LLEmojiHelper::instance().setCloseCallback([this](LLUICtrl*, const LLSD&) { onEmojiPickerClosed(); });
mGearBtn = getChild<LLButton>("gear_btn");
mAddBtn = getChild<LLButton>("add_btn");
@ -532,8 +535,43 @@ void LLFloaterIMSessionTab::onEmojiRecentPanelToggleBtnClicked()
void LLFloaterIMSessionTab::onEmojiPickerShowBtnClicked()
{
mInputEditor->setFocus(true);
mInputEditor->showEmojiHelper();
if (!mEmojiPickerShowBtn->getToggleState())
{
mInputEditor->hideEmojiHelper();
mInputEditor->setFocus(true);
mInputEditor->showEmojiHelper();
mEmojiPickerShowBtn->setToggleState(true); // in case hideEmojiHelper closed a visible instance
}
else
{
mInputEditor->hideEmojiHelper();
mEmojiPickerShowBtn->setToggleState(false);
}
}
void LLFloaterIMSessionTab::onEmojiPickerShowBtnDown()
{
if (mEmojiHelperLastCallbackFrame == LLFrameTimer::getFrameCount())
{
// Helper gets closed by focus lost event on Down before before onEmojiPickerShowBtnDown
// triggers.
// If this condition is true, user pressed button and it was 'toggled' during press,
// restore 'toggled' state so that button will not reopen helper.
mEmojiPickerShowBtn->setToggleState(true);
}
}
void LLFloaterIMSessionTab::onEmojiPickerClosed()
{
if (mEmojiPickerShowBtn->getToggleState())
{
mEmojiPickerShowBtn->setToggleState(false);
// Helper gets closed by focus lost event on Down before onEmojiPickerShowBtnDown
// triggers. If mEmojiHelperLastCallbackFrame is set and matches Down, means close
// was triggered by user's press.
// A bit hacky, but I can't think of a better way to handle this without rewriting helper.
mEmojiHelperLastCallbackFrame = LLFrameTimer::getFrameCount();
}
}
void LLFloaterIMSessionTab::initEmojiRecentPanel()

View File

@ -235,6 +235,8 @@ private:
void onEmojiRecentPanelToggleBtnClicked();
void onEmojiPickerShowBtnClicked();
void onEmojiPickerShowBtnDown();
void onEmojiPickerClosed();
void initEmojiRecentPanel();
void onEmojiRecentPanelFocusReceived();
void onEmojiRecentPanelFocusLost();
@ -249,6 +251,9 @@ private:
S32 mInputEditorPad;
S32 mChatLayoutPanelHeight;
S32 mFloaterHeight;
boost::signals2::connection mEmojiCloseConn;
U32 mEmojiHelperLastCallbackFrame = { 0 };
};