summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorgwigz <gwigz@users.noreply.github.com>2026-06-18 22:04:45 +0100
committerGitHub <noreply@github.com>2026-06-19 00:04:45 +0300
commit2c591b1429f44795aceebd5c6f5ea6907b2a08ea (patch)
tree89f6416ea920acfc381a3f35f23de45ad3b4c98f /indra/llui
parentfc2e96135d0a55df5f3b668298fa72505d39413b (diff)
#5928 Gesture auto-complete, similar to emojis/mentions
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/CMakeLists.txt2
-rw-r--r--indra/llui/llgestureautocompletehelper.cpp168
-rw-r--r--indra/llui/llgestureautocompletehelper.h83
-rw-r--r--indra/llui/lltexteditor.cpp7
4 files changed, 258 insertions, 2 deletions
diff --git a/indra/llui/CMakeLists.txt b/indra/llui/CMakeLists.txt
index 908e94b24c..1c9a16ba41 100644
--- a/indra/llui/CMakeLists.txt
+++ b/indra/llui/CMakeLists.txt
@@ -41,6 +41,7 @@ set(llui_SOURCE_FILES
llfloaterreglistener.cpp
llflyoutbutton.cpp
llfocusmgr.cpp
+ llgestureautocompletehelper.cpp
llfolderview.cpp
llfolderviewitem.cpp
llfolderviewmodel.cpp
@@ -154,6 +155,7 @@ set(llui_HEADER_FILES
llfloaterreglistener.h
llflyoutbutton.h
llfocusmgr.h
+ llgestureautocompletehelper.h
llfolderview.h
llfolderviewitem.h
llfolderviewmodel.h
diff --git a/indra/llui/llgestureautocompletehelper.cpp b/indra/llui/llgestureautocompletehelper.cpp
new file mode 100644
index 0000000000..ca976fff10
--- /dev/null
+++ b/indra/llui/llgestureautocompletehelper.cpp
@@ -0,0 +1,168 @@
+/**
+ * @file llgestureautocompletehelper.cpp
+ *
+ * $LicenseInfo:firstyear=2026&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2026, 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 "llgestureautocompletehelper.h"
+
+#include "llfloater.h"
+#include "llfloaterreg.h"
+#include "llfocusmgr.h"
+#include "lluictrl.h"
+
+constexpr char GESTURE_AUTOCOMPLETE_FLOATER[] = "gesture_autocomplete_picker";
+
+bool LLGestureAutocompleteHelper::isActive(const LLUICtrl* ctrl) const
+{
+ return mHostHandle.get() == ctrl;
+}
+
+void LLGestureAutocompleteHelper::showHelper(
+ LLUICtrl* host_ctrl,
+ const std::vector<Row>& rows,
+ size_t total,
+ const std::string& empty_text,
+ std::function<void(std::string)> commit_cb)
+{
+ if (mHelperHandle.isDead())
+ {
+ LLFloater* helper_floater = LLFloaterReg::getInstance(GESTURE_AUTOCOMPLETE_FLOATER);
+ mHelperHandle = helper_floater->getHandle();
+ mHelperCommitConn = helper_floater->setCommitCallback(
+ [this](LLUICtrl*, const LLSD& param) { onCommitGesture(param.asString()); });
+ }
+
+ setHostCtrl(host_ctrl);
+ mRows = rows;
+ mTotal = total;
+ mEmptyText = empty_text;
+ mGestureCommitCb = commit_cb;
+
+ S32 floater_x, floater_y;
+ LLRect host_rect = host_ctrl->getRect();
+ if (!host_ctrl->localPointToOtherView(0, host_rect.getHeight(), &floater_x, &floater_y, gFloaterView))
+ {
+ LL_WARNS() << "Cannot show gesture autocomplete helper for non-floater controls." << LL_ENDL;
+ return;
+ }
+
+ LLFloater* helper_floater = mHelperHandle.get();
+ LLRect rect = helper_floater->getRect();
+ rect.setLeftTopAndSize(floater_x, floater_y + rect.getHeight(), rect.getWidth(), rect.getHeight());
+ helper_floater->setRect(rect);
+
+ refreshPicker();
+}
+
+void LLGestureAutocompleteHelper::hideHelper(const LLUICtrl* ctrl)
+{
+ if (ctrl && !isActive(ctrl))
+ {
+ return;
+ }
+
+ setHostCtrl(nullptr);
+}
+
+bool LLGestureAutocompleteHelper::handleKey(const LLUICtrl* ctrl, KEY key, MASK mask)
+{
+ if (mHelperHandle.isDead() || !isActive(ctrl))
+ {
+ return false;
+ }
+
+ return mHelperHandle.get()->handleKey(key, mask, true);
+}
+
+void LLGestureAutocompleteHelper::onCommitGesture(const std::string& trigger)
+{
+ if (!mHostHandle.isDead() && mGestureCommitCb)
+ {
+ mGestureCommitCb(trigger);
+ }
+
+ hideHelper(getHostCtrl());
+}
+
+void LLGestureAutocompleteHelper::refreshPicker()
+{
+ if (mHelperHandle.isDead())
+ {
+ return;
+ }
+
+ LLFloater* helper_floater = mHelperHandle.get();
+
+ if (helper_floater->isShown())
+ {
+ helper_floater->onOpen(LLSD());
+ }
+ else
+ {
+ helper_floater->openFloater(LLSD());
+ }
+}
+
+void LLGestureAutocompleteHelper::setHostCtrl(LLUICtrl* host_ctrl)
+{
+ const LLUICtrl* cur_host_ctrl = mHostHandle.get();
+
+ if (cur_host_ctrl != host_ctrl)
+ {
+ mHostCtrlFocusLostConn.disconnect();
+ mHostHandle.markDead();
+ mGestureCommitCb = {};
+ mRows.clear();
+ mEmptyText.clear();
+ mTotal = 0;
+
+ if (!mHelperHandle.isDead())
+ {
+ mHelperHandle.get()->closeFloater();
+ }
+
+ if (host_ctrl)
+ {
+ mHostHandle = host_ctrl->getHandle();
+ mHostCtrlFocusLostConn = host_ctrl->setFocusLostCallback(
+ [this](auto*)
+ {
+ // Scroll list grabs focus on click.
+ // Keep focus on the host when the click was ours.
+ LLFloater* helper_floater = mHelperHandle.get();
+ if (helper_floater && gFocusMgr.childHasKeyboardFocus(helper_floater))
+ {
+ if (LLUICtrl* host = getHostCtrl())
+ {
+ host->setFocus(true);
+ }
+ return;
+ }
+
+ hideHelper(getHostCtrl());
+ });
+ }
+ }
+}
diff --git a/indra/llui/llgestureautocompletehelper.h b/indra/llui/llgestureautocompletehelper.h
new file mode 100644
index 0000000000..53000c0829
--- /dev/null
+++ b/indra/llui/llgestureautocompletehelper.h
@@ -0,0 +1,83 @@
+/**
+ * @file llgestureautocompletehelper.h
+ *
+ * $LicenseInfo:firstyear=2026&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2026, 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$
+ */
+
+#pragma once
+
+#include "llhandle.h"
+#include "llsingleton.h"
+
+#include <boost/signals2.hpp>
+#include <functional>
+#include <string>
+#include <vector>
+
+class LLFloater;
+class LLUICtrl;
+
+class LLGestureAutocompleteHelper : public LLSingleton<LLGestureAutocompleteHelper>
+{
+ LLSINGLETON(LLGestureAutocompleteHelper) {}
+ ~LLGestureAutocompleteHelper() override {}
+
+public:
+ struct Row
+ {
+ std::string value;
+ std::string trigger;
+ std::string name;
+ };
+
+ bool isActive(const LLUICtrl* ctrl) const;
+ void showHelper(
+ LLUICtrl* host_ctrl,
+ const std::vector<Row>& rows,
+ size_t total,
+ const std::string& empty_text,
+ std::function<void(std::string)> commit_cb);
+ void hideHelper(const LLUICtrl* ctrl = nullptr);
+ bool handleKey(const LLUICtrl* ctrl, KEY key, MASK mask);
+ void onCommitGesture(const std::string& trigger);
+
+ const std::vector<Row>& rows() const { return mRows; }
+ size_t total() const { return mTotal; }
+ const std::string& emptyText() const { return mEmptyText; }
+
+protected:
+ void setHostCtrl(LLUICtrl* host_ctrl);
+ LLUICtrl* getHostCtrl() const { return mHostHandle.get(); }
+
+private:
+ void refreshPicker();
+
+ LLHandle<LLUICtrl> mHostHandle;
+ LLHandle<LLFloater> mHelperHandle;
+ boost::signals2::connection mHostCtrlFocusLostConn;
+ boost::signals2::connection mHelperCommitConn;
+ std::function<void(std::string)> mGestureCommitCb;
+
+ std::vector<Row> mRows;
+ std::string mEmptyText;
+ size_t mTotal = 0;
+};
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 7689b93374..5f1302df88 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -61,6 +61,7 @@
#include "lltooltip.h"
#include "llmenugl.h"
#include "llchatmentionhelper.h"
+#include "llgestureautocompletehelper.h"
#include <queue>
#include "llcombobox.h"
@@ -1950,7 +1951,8 @@ bool LLTextEditor::handleKeyHere(KEY key, MASK mask )
// not handled and let the parent take care of field movement.
if (KEY_TAB == key && mTabsToNextField)
{
- return mShowChatMentionPicker && LLChatMentionHelper::instance().handleKey(this, key, mask);
+ return (mShowChatMentionPicker && LLChatMentionHelper::instance().handleKey(this, key, mask))
+ || LLGestureAutocompleteHelper::instance().handleKey(this, key, mask);
}
if (mReadOnly && mScroller)
@@ -1964,7 +1966,8 @@ bool LLTextEditor::handleKeyHere(KEY key, MASK mask )
if (!mReadOnly)
{
if ((mShowEmojiHelper && LLEmojiHelper::instance().handleKey(this, key, mask)) ||
- (mShowChatMentionPicker && LLChatMentionHelper::instance().handleKey(this, key, mask)))
+ (mShowChatMentionPicker && LLChatMentionHelper::instance().handleKey(this, key, mask)) ||
+ LLGestureAutocompleteHelper::instance().handleKey(this, key, mask))
{
return true;
}