From 3e46d707a243e91046b3ab0af8f844d7f40f77b4 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 18 Apr 2025 17:48:02 +0300 Subject: #3758 initial chat mention support --- indra/llui/llchatmentionhelper.cpp | 151 +++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 indra/llui/llchatmentionhelper.cpp (limited to 'indra/llui/llchatmentionhelper.cpp') diff --git a/indra/llui/llchatmentionhelper.cpp b/indra/llui/llchatmentionhelper.cpp new file mode 100644 index 0000000000..98d846b947 --- /dev/null +++ b/indra/llui/llchatmentionhelper.cpp @@ -0,0 +1,151 @@ +/** +* @file llchatmentionhelper.cpp +* +* $LicenseInfo:firstyear=2025&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2025, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ + +#include "linden_common.h" + +#include "llchatmentionhelper.h" +#include "llfloater.h" +#include "llfloaterreg.h" +#include "lluictrl.h" + +constexpr char CHAT_MENTION_HELPER_FLOATER[] = "chat_mention_picker"; + +bool LLChatMentionHelper::isActive(const LLUICtrl* ctrl) const +{ + return mHostHandle.get() == ctrl; +} + +bool LLChatMentionHelper::isCursorInNameMention(const LLWString& wtext, S32 cursor_pos, S32* mention_start_pos) +{ + if (cursor_pos <= 0 || cursor_pos > static_cast(wtext.size())) + return false; + + // Find the beginning of the current word + S32 start = cursor_pos - 1; + while (start > 0 && wtext[start - 1] != U32(' ') && wtext[start - 1] != U32('\n')) + { + --start; + } + + if (wtext[start] != U32('@')) + return false; + + if (mention_start_pos) + *mention_start_pos = start; + + S32 word_length = cursor_pos - start; + + if (word_length == 1) + { + return true; + } + + // Get the name after '@' + std::string name = wstring_to_utf8str(wtext.substr(start + 1, word_length - 1)); + LLStringUtil::toLower(name); + for (const auto& av_name : mAvatarNames) + { + if (av_name == name || av_name.find(name) == 0) + { + return true; + } + } + + return false; +} + +void LLChatMentionHelper::showHelper(LLUICtrl* host_ctrl, S32 local_x, S32 local_y, const std::string& av_name, std::function cb) +{ + if (mHelperHandle.isDead()) + { + LLFloater* av_picker_floater = LLFloaterReg::getInstance(CHAT_MENTION_HELPER_FLOATER); + mHelperHandle = av_picker_floater->getHandle(); + mHelperCommitConn = av_picker_floater->setCommitCallback([&](LLUICtrl* ctrl, const LLSD& param) { onCommitName(param.asString()); }); + } + setHostCtrl(host_ctrl); + mNameCommitCb = cb; + + S32 floater_x, floater_y; + if (!host_ctrl->localPointToOtherView(local_x, local_y, &floater_x, &floater_y, gFloaterView)) + { + LL_WARNS() << "Cannot show helper for non-floater controls." << LL_ENDL; + return; + } + + LLFloater* av_picker_floater = mHelperHandle.get(); + LLRect rect = av_picker_floater->getRect(); + rect.setLeftTopAndSize(floater_x, floater_y + rect.getHeight(), rect.getWidth(), rect.getHeight()); + av_picker_floater->setRect(rect); + av_picker_floater->openFloater(LLSD().with("av_name", av_name)); +} + +void LLChatMentionHelper::hideHelper(const LLUICtrl* ctrl) +{ + if ((ctrl && !isActive(ctrl))) + { + return; + } + setHostCtrl(nullptr); +} + +bool LLChatMentionHelper::handleKey(const LLUICtrl* ctrl, KEY key, MASK mask) +{ + if (mHelperHandle.isDead() || !isActive(ctrl)) + { + return false; + } + + return mHelperHandle.get()->handleKey(key, mask, true); +} + +void LLChatMentionHelper::onCommitName(std::string name_url) +{ + if (!mHostHandle.isDead() && mNameCommitCb) + { + mNameCommitCb(name_url); + } +} + +void LLChatMentionHelper::setHostCtrl(LLUICtrl* host_ctrl) +{ + const LLUICtrl* pCurHostCtrl = mHostHandle.get(); + if (pCurHostCtrl != host_ctrl) + { + mHostCtrlFocusLostConn.disconnect(); + mHostHandle.markDead(); + mNameCommitCb = {}; + + if (!mHelperHandle.isDead()) + { + mHelperHandle.get()->closeFloater(); + } + + if (host_ctrl) + { + mHostHandle = host_ctrl->getHandle(); + mHostCtrlFocusLostConn = host_ctrl->setFocusLostCallback(std::bind([&]() { hideHelper(getHostCtrl()); })); + } + } +} -- cgit v1.3 From 1eb34b43fb88a0b7551d9083ab46ba7df2feab14 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 25 Apr 2025 20:22:33 +0300 Subject: #3758 clean up: move EUnderlineLink --- indra/llui/llchatmentionhelper.cpp | 2 +- indra/llui/llchatmentionhelper.h | 2 +- indra/llui/llstyle.h | 8 ++++++++ indra/llui/lltextbase.h | 2 +- indra/llui/llurlentry.cpp | 12 ++++++------ indra/llui/llurlentry.h | 9 ++++----- indra/llui/llurlmatch.cpp | 4 ++-- indra/llui/llurlmatch.h | 14 ++++---------- 8 files changed, 27 insertions(+), 26 deletions(-) (limited to 'indra/llui/llchatmentionhelper.cpp') diff --git a/indra/llui/llchatmentionhelper.cpp b/indra/llui/llchatmentionhelper.cpp index 98d846b947..f7769b2cbe 100644 --- a/indra/llui/llchatmentionhelper.cpp +++ b/indra/llui/llchatmentionhelper.cpp @@ -37,7 +37,7 @@ bool LLChatMentionHelper::isActive(const LLUICtrl* ctrl) const return mHostHandle.get() == ctrl; } -bool LLChatMentionHelper::isCursorInNameMention(const LLWString& wtext, S32 cursor_pos, S32* mention_start_pos) +bool LLChatMentionHelper::isCursorInNameMention(const LLWString& wtext, S32 cursor_pos, S32* mention_start_pos) const { if (cursor_pos <= 0 || cursor_pos > static_cast(wtext.size())) return false; diff --git a/indra/llui/llchatmentionhelper.h b/indra/llui/llchatmentionhelper.h index 4da8c8264e..5f95d06f31 100644 --- a/indra/llui/llchatmentionhelper.h +++ b/indra/llui/llchatmentionhelper.h @@ -42,7 +42,7 @@ class LLChatMentionHelper : public LLSingleton public: bool isActive(const LLUICtrl* ctrl) const; - bool isCursorInNameMention(const LLWString& wtext, S32 cursor_pos, S32* mention_start_pos = nullptr); + bool isCursorInNameMention(const LLWString& wtext, S32 cursor_pos, S32* mention_start_pos = nullptr) const; void showHelper(LLUICtrl* host_ctrl, S32 local_x, S32 local_y, const std::string& av_name, std::function commit_cb); void hideHelper(const LLUICtrl* ctrl = nullptr); diff --git a/indra/llui/llstyle.h b/indra/llui/llstyle.h index 2c86eb6db7..71c3f88109 100644 --- a/indra/llui/llstyle.h +++ b/indra/llui/llstyle.h @@ -54,6 +54,14 @@ public: Params(); }; LLStyle(const Params& p = Params()); + + enum EUnderlineLink + { + UNDERLINE_ALWAYS = 0, + UNDERLINE_ON_HOVER, + UNDERLINE_NEVER + }; + public: const LLUIColor& getColor() const { return mColor; } void setColor(const LLUIColor &color) { mColor = color; } diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h index 897c910c2f..8ca653acb9 100644 --- a/indra/llui/lltextbase.h +++ b/indra/llui/lltextbase.h @@ -611,7 +611,7 @@ protected: bool operator()(const LLTextSegmentPtr& a, const LLTextSegmentPtr& b) const; }; typedef std::multiset segment_set_t; - typedef LLUrlMatch::EUnderlineLink e_underline; + typedef LLStyle::EUnderlineLink e_underline; // member functions LLTextBase(const Params &p); diff --git a/indra/llui/llurlentry.cpp b/indra/llui/llurlentry.cpp index a2062d077e..34138da34d 100644 --- a/indra/llui/llurlentry.cpp +++ b/indra/llui/llurlentry.cpp @@ -666,14 +666,14 @@ std::string LLUrlEntryAgent::getTooltip(const std::string &string) const return LLTrans::getString("TooltipAgentUrl"); } -LLUrlMatch::EUnderlineLink LLUrlEntryAgent::getUnderline(const std::string& string) const +LLStyle::EUnderlineLink LLUrlEntryAgent::getUnderline(const std::string& string) const { std::string url = getUrl(string); if (LLStringUtil::endsWith(url, "/about") || LLStringUtil::endsWith(url, "/inspect")) { - return LLUrlMatch::EUnderlineLink::UNDERLINE_ON_HOVER; + return LLStyle::EUnderlineLink::UNDERLINE_ON_HOVER; } - return LLUrlMatch::EUnderlineLink::UNDERLINE_ALWAYS; + return LLStyle::EUnderlineLink::UNDERLINE_ALWAYS; } std::string LLUrlEntryAgent::getLabel(const std::string &url, const LLUrlLabelCallback &cb) @@ -781,9 +781,9 @@ LLUrlEntryAgentMention::LLUrlEntryAgentMention() mIcon = std::string(); } -LLUrlMatch::EUnderlineLink LLUrlEntryAgentMention::getUnderline(const std::string& string) const +LLStyle::EUnderlineLink LLUrlEntryAgentMention::getUnderline(const std::string& string) const { - return LLUrlMatch::EUnderlineLink::UNDERLINE_NEVER; + return LLStyle::EUnderlineLink::UNDERLINE_NEVER; } LLStyle::Params LLUrlEntryAgentMention::getStyle(const std::string& url) const @@ -1406,7 +1406,7 @@ std::string LLUrlEntrySLLabel::getTooltip(const std::string &string) const return LLUrlEntryBase::getTooltip(string); } -LLUrlMatch::EUnderlineLink LLUrlEntrySLLabel::getUnderline(const std::string& string) const +LLStyle::EUnderlineLink LLUrlEntrySLLabel::getUnderline(const std::string& string) const { std::string url = getUrl(string); LLUrlMatch match; diff --git a/indra/llui/llurlentry.h b/indra/llui/llurlentry.h index df3932b2a0..740e99acfd 100644 --- a/indra/llui/llurlentry.h +++ b/indra/llui/llurlentry.h @@ -34,7 +34,6 @@ #include "llavatarname.h" #include "llhost.h" // for resolving parcel name by parcel id -#include "llurlmatch.h" #include #include @@ -97,7 +96,7 @@ public: /// Return the name of a SL location described by this Url, if any virtual std::string getLocation(const std::string &url) const { return ""; } - virtual LLUrlMatch::EUnderlineLink getUnderline(const std::string& string) const { return LLUrlMatch::EUnderlineLink::UNDERLINE_ALWAYS; } + virtual LLStyle::EUnderlineLink getUnderline(const std::string& string) const { return LLStyle::EUnderlineLink::UNDERLINE_ALWAYS; } virtual bool isTrusted() const { return false; } @@ -233,7 +232,7 @@ public: /*virtual*/ LLStyle::Params getStyle(const std::string &url) const; /*virtual*/ LLUUID getID(const std::string &string) const; - LLUrlMatch::EUnderlineLink getUnderline(const std::string& string) const; + LLStyle::EUnderlineLink getUnderline(const std::string& string) const; protected: /*virtual*/ void callObservers(const std::string &id, const std::string &label, const std::string& icon); @@ -253,7 +252,7 @@ public: LLUrlEntryAgentMention(); LLStyle::Params getStyle(const std::string& url) const; - LLUrlMatch::EUnderlineLink getUnderline(const std::string& string) const; + LLStyle::EUnderlineLink getUnderline(const std::string& string) const; bool getSkipProfileIcon(const std::string& string) const { return true; }; }; @@ -505,7 +504,7 @@ public: /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb); /*virtual*/ std::string getUrl(const std::string &string) const; /*virtual*/ std::string getTooltip(const std::string &string) const; - LLUrlMatch::EUnderlineLink getUnderline(const std::string& string) const; + LLStyle::EUnderlineLink getUnderline(const std::string& string) const; }; /// diff --git a/indra/llui/llurlmatch.cpp b/indra/llui/llurlmatch.cpp index 3e61abe118..f093934ca9 100644 --- a/indra/llui/llurlmatch.cpp +++ b/indra/llui/llurlmatch.cpp @@ -37,7 +37,7 @@ LLUrlMatch::LLUrlMatch() : mIcon(""), mMenuName(""), mLocation(""), - mUnderline(UNDERLINE_ALWAYS), + mUnderline(e_underline::UNDERLINE_ALWAYS), mTrusted(false), mSkipProfileIcon(false) { @@ -47,7 +47,7 @@ void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std const std::string& query, const std::string &tooltip, const std::string &icon, const LLStyle::Params& style, const std::string &menu, const std::string &location, - const LLUUID& id, EUnderlineLink underline, bool trusted, bool skip_icon) + const LLUUID& id, e_underline underline, bool trusted, bool skip_icon) { mStart = start; mEnd = end; diff --git a/indra/llui/llurlmatch.h b/indra/llui/llurlmatch.h index 0c4fe4a782..418a21f963 100644 --- a/indra/llui/llurlmatch.h +++ b/indra/llui/llurlmatch.h @@ -46,13 +46,6 @@ class LLUrlMatch public: LLUrlMatch(); - enum EUnderlineLink - { - UNDERLINE_ALWAYS = 0, - UNDERLINE_ON_HOVER, - UNDERLINE_NEVER - }; - /// return true if this object does not contain a valid Url match yet bool empty() const { return mUrl.empty(); } @@ -86,7 +79,8 @@ public: /// return the SL location that this Url describes, or "" if none. std::string getLocation() const { return mLocation; } - EUnderlineLink getUnderline() const { return mUnderline; } + typedef LLStyle::EUnderlineLink e_underline; + e_underline getUnderline() const { return mUnderline; } /// Return true if Url is trusted. bool isTrusted() const { return mTrusted; } @@ -98,7 +92,7 @@ public: const std::string& query, const std::string &tooltip, const std::string &icon, const LLStyle::Params& style, const std::string &menu, const std::string &location, const LLUUID& id, - EUnderlineLink underline = UNDERLINE_ALWAYS, bool trusted = false, bool skip_icon = false); + e_underline underline = e_underline::UNDERLINE_ALWAYS, bool trusted = false, bool skip_icon = false); const LLUUID& getID() const { return mID; } private: @@ -113,7 +107,7 @@ private: std::string mLocation; LLUUID mID; LLStyle::Params mStyle; - EUnderlineLink mUnderline; + e_underline mUnderline; bool mTrusted; bool mSkipProfileIcon; }; -- cgit v1.3 From 9668d2f0eff761f1de71cea718a46e807f9c00a8 Mon Sep 17 00:00:00 2001 From: Maxim Nikolenko Date: Fri, 9 May 2025 18:46:56 +0300 Subject: #3758 do not reopen avatar picker floater --- indra/llui/llchatmentionhelper.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'indra/llui/llchatmentionhelper.cpp') diff --git a/indra/llui/llchatmentionhelper.cpp b/indra/llui/llchatmentionhelper.cpp index f7769b2cbe..5745389a58 100644 --- a/indra/llui/llchatmentionhelper.cpp +++ b/indra/llui/llchatmentionhelper.cpp @@ -98,7 +98,14 @@ void LLChatMentionHelper::showHelper(LLUICtrl* host_ctrl, S32 local_x, S32 local LLRect rect = av_picker_floater->getRect(); rect.setLeftTopAndSize(floater_x, floater_y + rect.getHeight(), rect.getWidth(), rect.getHeight()); av_picker_floater->setRect(rect); - av_picker_floater->openFloater(LLSD().with("av_name", av_name)); + if (av_picker_floater->isShown()) + { + av_picker_floater->onOpen(LLSD().with("av_name", av_name)); + } + else + { + av_picker_floater->openFloater(LLSD().with("av_name", av_name)); + } } void LLChatMentionHelper::hideHelper(const LLUICtrl* ctrl) -- cgit v1.3