From d20dbaa7d2b5acaf1127a462b98ba9c8e0e5b0f1 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Fri, 1 Feb 2019 08:12:12 -0500 Subject: [PATCH] Feature Request: Allow use of a separate color for linked usernames. The setting is HTMLAgentColor, I will not add this to preferences for now. Note that usernames before the colon in the chat are cached, set before login to change it for everyone or relog. Also hook up getStyle() for the registered urls, cleans up some code in lltexteditor. --- indra/llui/lltexteditor.cpp | 21 +++++++----- indra/llui/llurlentry.cpp | 45 ++++++++++++------------- indra/llui/llurlentry.h | 10 +++--- indra/llui/llurlmatch.cpp | 6 ++-- indra/llui/llurlmatch.h | 6 ++-- indra/llui/llurlregistry.cpp | 4 +-- indra/newview/app_settings/settings.xml | 16 +++++++++ indra/newview/llstylemap.cpp | 2 +- 8 files changed, 65 insertions(+), 45 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 547db779f..4309d2567 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -4268,7 +4268,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s { std::string text = new_text; static LLUICachedControl replace_links("SinguReplaceLinks"); - bool is_link = style && !style->getLinkHREF().empty(); // Don't search for URLs inside a link segment (STORM-358). + bool is_link = style && !style->isLink(); // Don't search for URLs inside a link segment (STORM-358). S32 part = (S32)LLTextParser::WHOLE; if (mReadOnly && mParseHTML && !is_link) // Singu Note: Do not replace html if the user is going to edit it. (Like in profiles) @@ -4276,16 +4276,21 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s LL_RECORD_BLOCK_TIME(FTM_PARSE_HTML); S32 start=0,end=0; LLUrlMatch match; - const auto& link_color = mLinkColor ? *mLinkColor : LLUI::sConfigGroup->getColor4("HTMLLinkColor"); auto append_substr = [&](const size_t& pos, const size_t& count) { appendAndHighlightText(text.substr(pos, count), part, style); }; - auto append_link = [&](const std::string& link) + auto append_link = [&](const std::string& link, LLStyleSP link_style) { - LLStyleSP link_style(style ? new LLStyle(*style) : new LLStyle); - link_style->setColor(link_color); - link_style->setLinkHREF(match.getUrl()); + if (style) // Respect styling + { + const auto& text_style = *style; + link_style->mItalic = text_style.mItalic; + link_style->mBold = text_style.mBold; + link_style->mUnderline = text_style.mUnderline; + } + // Hack around colors looking bad on some backgrounds by allowing setting link color for this editor + if (mLinkColor) link_style->setColor(*mLinkColor); appendAndHighlightText(link, part, link_style, true/*match.underlineOnHoverOnly()*/); }; while (!text.empty() && LLUrlRegistry::instance().findUrl(text, match, @@ -4323,7 +4328,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s }*/ // output the styled url - append_link(label + match.getQuery()); + append_link(label + match.getQuery(), match.getStyle()); bool tooltip_required = !match.getTooltip().empty(); // set the tooltip for the Url label @@ -4359,7 +4364,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s append_substr(start, brackets ? 1 : pos-start); // In the special cases, only link exactly the url, this might not have a protocol so calculate the exact string if (fallback) url = brackets ? text.substr(start+1, text.find(' ', start+2)-start) : text.substr(start, end-start); - append_link(url); // Append the link + append_link(url, match.getStyle()); // Append the link const auto url_end = pos + url.size(); if (fallback == brackets && end > url_end) // Ending text, only in special case if brackets present append_substr(url_end, end-url_end); diff --git a/indra/llui/llurlentry.cpp b/indra/llui/llurlentry.cpp index 0282ae626..2591bbeb8 100644 --- a/indra/llui/llurlentry.cpp +++ b/indra/llui/llurlentry.cpp @@ -69,14 +69,13 @@ std::string LLUrlEntryBase::getIcon(const std::string &url) return mIcon; } -/*LLStyle::Params LLUrlEntryBase::getStyle() const +LLStyleSP LLUrlEntryBase::getStyle() const { - LLStyle::Params style_params; - style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); - style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor"); - style_params.font.style = "UNDERLINE"; + static LLUICachedControl color("HTMLLinkColor"); + LLStyleSP style_params(new LLStyle(true, color, LLStringUtil::null)); + //style_params->mUnderline = true; // Singu Note: We're not gonna bother here, underlining on hover return style_params; -}*/ +} std::string LLUrlEntryBase::getIDStringFromUrl(const std::string &url) const @@ -677,13 +676,12 @@ std::string LLUrlEntryAgent::getLabel(const std::string &url, const LLUrlLabelCa } } -/*LLStyle::Params LLUrlEntryAgent::getStyle() const +LLStyleSP LLUrlEntryAgent::getStyle() const { - LLStyle::Params style_params = LLUrlEntryBase::getStyle(); - style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); - style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor"); + static LLUICachedControl color("HTMLAgentColor"); + LLStyleSP style_params(new LLStyle(true, color, LLStringUtil::null)); return style_params; -}*/ +} std::string localize_slapp_label(const std::string& url, const std::string& full_name) { @@ -788,11 +786,12 @@ std::string LLUrlEntryAgentName::getLabel(const std::string &url, const LLUrlLab } } -/*LLStyle::Params LLUrlEntryAgentName::getStyle() const +LLStyleSP LLUrlEntryAgentName::getStyle() const { - // don't override default colors - return LLStyle::Params().is_link(false); -}*/ + static LLUICachedControl color("HTMLAgentColor"); + LLStyleSP style_params(new LLStyle(true, color, LLStringUtil::null)); + return style_params; +} // // LLUrlEntryAgentCompleteName describes a Second Life agent complete name Url, e.g., @@ -924,13 +923,12 @@ std::string LLUrlEntryGroup::getLabel(const std::string &url, const LLUrlLabelCa } } -/*LLStyle::Params LLUrlEntryGroup::getStyle() const +LLStyleSP LLUrlEntryGroup::getStyle() const { - LLStyle::Params style_params = LLUrlEntryBase::getStyle(); - style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); - style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor"); + LLStyleSP style_params = LLUrlEntryBase::getStyle(); + //style_params->mUnderline = false; // Singu Note: We're not gonna bother here, underlining on hover return style_params; -}*/ +} // @@ -1392,11 +1390,12 @@ std::string LLUrlEntryNoLink::getLabel(const std::string &url, const LLUrlLabelC return getUrl(url); } -/*LLStyle::Params LLUrlEntryNoLink::getStyle() const +LLStyleSP LLUrlEntryNoLink::getStyle() const { // Don't render as URL (i.e. no context menu or hand cursor). - return LLStyle::Params().is_link(false); -}*/ + // Singu Note: What the heck? No, that's misleading!! + return LLUrlEntryBase::getStyle(); +} // diff --git a/indra/llui/llurlentry.h b/indra/llui/llurlentry.h index a772cf8c9..d526ea957 100644 --- a/indra/llui/llurlentry.h +++ b/indra/llui/llurlentry.h @@ -82,7 +82,7 @@ public: virtual std::string getIcon(const std::string &url); /// Return the style to render the displayed text - //virtual LLStyle::Params getStyle() const; + virtual LLStyleSP getStyle() const; /// Given a matched Url, return a tooltip string for the hyperlink virtual std::string getTooltip(const std::string &string) const { return mTooltip; } @@ -232,7 +232,7 @@ public: /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; /*virtual*/ std::string getIcon(const std::string &url) override; /*virtual*/ std::string getTooltip(const std::string &string) const override; - ///*virtual*/ LLStyle::Params getStyle() const override; + /*virtual*/ LLStyleSP getStyle() const override; /*virtual*/ LLUUID getID(const std::string &string) const override; /*virtual*/ bool underlineOnHoverOnly(const std::string &string) const override; protected: @@ -265,7 +265,7 @@ public: } /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; - ///*virtual*/ LLStyle::Params getStyle() const override; + /*virtual*/ LLStyleSP getStyle() const override; protected: // override this to pull out relevant name fields virtual std::string getName(const LLAvatarName& avatar_name) = 0; @@ -332,7 +332,7 @@ class LLUrlEntryGroup : public LLUrlEntryBase public: LLUrlEntryGroup(); /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; - ///*virtual*/ LLStyle::Params getStyle() const override; + /*virtual*/ LLStyleSP getStyle() const override; /*virtual*/ LLUUID getID(const std::string &string) const override; private: void onGroupNameReceived(const LLUUID& id, const std::string& name, bool is_group); @@ -492,7 +492,7 @@ public: LLUrlEntryNoLink(); /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; /*virtual*/ std::string getUrl(const std::string &string) const override; - ///*virtual*/ LLStyle::Params getStyle() const override; + /*virtual*/ LLStyleSP getStyle() const override; }; /// diff --git a/indra/llui/llurlmatch.cpp b/indra/llui/llurlmatch.cpp index 3d4e808ec..717db6280 100644 --- a/indra/llui/llurlmatch.cpp +++ b/indra/llui/llurlmatch.cpp @@ -46,7 +46,7 @@ LLUrlMatch::LLUrlMatch() : void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std::string &label, const std::string& query, const std::string &tooltip, - const std::string &icon, /*const LLStyle::Params& style,*/ + const std::string &icon, const LLStyleSP& style, const std::string &menu, const std::string &location, const LLUUID& id, bool underline_on_hover_only, bool trusted) { @@ -57,8 +57,8 @@ void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std mQuery = query; mTooltip = tooltip; mIcon = icon; - //mStyle = style; - //mStyle.link_href = url; + mStyle = style; + mStyle->setLinkHREF(url); mMenuName = menu; mLocation = location; mID = id; diff --git a/indra/llui/llurlmatch.h b/indra/llui/llurlmatch.h index 67255d3ae..fc0b505ec 100644 --- a/indra/llui/llurlmatch.h +++ b/indra/llui/llurlmatch.h @@ -70,7 +70,7 @@ public: std::string getIcon() const { return mIcon; } /// Return the color to render the displayed text - //LLStyle::Params getStyle() const { return mStyle; } + LLStyleSP getStyle() const { return mStyle; } /// Return the name of a XUI file containing the context menu items std::string getMenuName() const { return mMenuName; } @@ -87,7 +87,7 @@ public: /// Change the contents of this match object (used by LLUrlRegistry) void setValues(U32 start, U32 end, const std::string &url, const std::string &label, const std::string& query, const std::string &tooltip, const std::string &icon, - /*const LLStyle::Params& style,*/ const std::string &menu, + const LLStyleSP& style, const std::string &menu, const std::string &location, const LLUUID& id, bool underline_on_hover_only = false, bool trusted = false); @@ -103,7 +103,7 @@ private: std::string mMenuName; std::string mLocation; LLUUID mID; - //LLStyle::Params mStyle; + LLStyleSP mStyle; bool mUnderlineOnHoverOnly; bool mTrusted; }; diff --git a/indra/llui/llurlregistry.cpp b/indra/llui/llurlregistry.cpp index 92d85ff91..908531b0b 100644 --- a/indra/llui/llurlregistry.cpp +++ b/indra/llui/llurlregistry.cpp @@ -265,7 +265,7 @@ bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LL match_entry->getQuery(url), match_entry->getTooltip(url), match_entry->getIcon(url), - //match_entry->getStyle(), + match_entry->getStyle(), match_entry->getMenuName(), match_entry->getLocation(url), match_entry->getID(url), @@ -302,7 +302,7 @@ bool LLUrlRegistry::findUrl(const LLWString &text, LLUrlMatch &match, const LLUr match.getQuery(), match.getTooltip(), match.getIcon(), - //match.getStyle(), + match.getStyle(), match.getMenuName(), match.getLocation(), match.getID(), diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index c1e976a93..f786da72d 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -9072,6 +9072,22 @@ This should be as low as possible, but too low may break functionality Value 400 + HTMLAgentColor + + Comment + Color of hyperlinked usernames + Persist + 1 + Type + Color4 + Value + + 0.600000023842 + 0.600000023842 + 1.0 + 1.0 + + HTMLLinkColor Comment diff --git a/indra/newview/llstylemap.cpp b/indra/newview/llstylemap.cpp index a0c64505e..21467b768 100644 --- a/indra/newview/llstylemap.cpp +++ b/indra/newview/llstylemap.cpp @@ -58,7 +58,7 @@ const LLStyleSP &LLStyleMap::lookupAgent(const LLUUID &source) LLStyleSP style(new LLStyle); if (source.notNull()) { - style->setColor(gSavedSettings.getColor4("HTMLLinkColor")); + style->setColor(gSavedSettings.getColor4("HTMLAgentColor")); std::string link = llformat("secondlife:///app/agent/%s/about",source.asString().c_str()); style->setLinkHREF(link); }