diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2015-02-25 17:02:06 -0500 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2015-02-25 17:02:06 -0500 |
commit | 2ab9678455ce2e894273cae1efd2e10f4aaee42b (patch) | |
tree | ce679a7b789d75a3d36816438c5a2fd5a5edfd1a /indra/llui | |
parent | d2de97ad8e84eedd42f4a0fe5b258617a96f154b (diff) | |
parent | 9b45bc992edf8d049d8a1abe2e778870a493295a (diff) |
merge
Diffstat (limited to 'indra/llui')
-rwxr-xr-x | indra/llui/llmenugl.cpp | 72 | ||||
-rwxr-xr-x | indra/llui/lltextbase.cpp | 18 | ||||
-rwxr-xr-x | indra/llui/lltextbase.h | 1 | ||||
-rwxr-xr-x | indra/llui/lltextutil.h | 10 | ||||
-rwxr-xr-x | indra/llui/llurlentry.cpp | 27 | ||||
-rwxr-xr-x | indra/llui/llurlentry.h | 17 | ||||
-rwxr-xr-x | indra/llui/llurlmatch.cpp | 6 | ||||
-rwxr-xr-x | indra/llui/llurlmatch.h | 6 | ||||
-rwxr-xr-x | indra/llui/llurlregistry.cpp | 13 |
9 files changed, 126 insertions, 44 deletions
diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp index d3ed4a1286..31df853ab4 100755 --- a/indra/llui/llmenugl.cpp +++ b/indra/llui/llmenugl.cpp @@ -60,6 +60,7 @@ #include "v2math.h" #include <set> #include <boost/tokenizer.hpp> +#include <boost/foreach.hpp> // static LLMenuHolderGL *LLMenuGL::sMenuContainer = NULL; @@ -2038,15 +2039,7 @@ void LLMenuGL::arrange( void ) // torn off menus are not constrained to the size of the screen U32 max_width = getTornOff() ? U32_MAX : menu_region_rect.getWidth(); - U32 max_height = U32_MAX; - if (!getTornOff()) - { - max_height = getRect().mTop - menu_region_rect.mBottom; - if (menu_region_rect.mTop - getRect().mTop > (S32)max_height) - { - max_height = menu_region_rect.mTop - getRect().mTop; - } - } + U32 max_height = getTornOff() ? U32_MAX: menu_region_rect.getHeight(); // *FIX: create the item first and then ask for its dimensions? S32 spillover_item_width = PLAIN_PAD_PIXELS + LLFontGL::getFontSansSerif()->getWidth( std::string("More") ); // *TODO: Translate @@ -2104,13 +2097,15 @@ void LLMenuGL::arrange( void ) } else { + BOOST_FOREACH(LLMenuItemGL* itemp, mItems) + { + // do first so LLMenuGLItemCall can call on_visible to determine if visible + itemp->buildDrawLabel(); + } item_list_t::iterator item_iter; for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) { - // do first so LLMenuGLItemCall can call on_visible to determine if visible - (*item_iter)->buildDrawLabel(); - if ((*item_iter)->getVisible()) { if (!getTornOff() @@ -2118,34 +2113,43 @@ void LLMenuGL::arrange( void ) && *item_iter != mSpilloverBranch && height + (*item_iter)->getNominalHeight() > max_height - spillover_item_height) { - // no room for any more items - createSpilloverBranch(); - - std::vector<LLMenuItemGL*> items_to_remove; - std::copy(item_iter, mItems.end(), std::back_inserter(items_to_remove)); - std::vector<LLMenuItemGL*>::iterator spillover_iter; - for (spillover_iter= items_to_remove.begin(); spillover_iter != items_to_remove.end(); ++spillover_iter) + // don't show only one item + int visible_items = 0; + item_list_t::iterator count_iter; + for (count_iter = item_iter; count_iter != mItems.end(); ++count_iter) { - LLMenuItemGL* itemp = (*spillover_iter); - removeChild(itemp); - mSpilloverMenu->addChild(itemp); + if((*count_iter)->getVisible()) + visible_items++; } + if (visible_items>1) + { + // no room for any more items + createSpilloverBranch(); + std::vector<LLMenuItemGL*> items_to_remove; + std::copy(item_iter, mItems.end(), std::back_inserter(items_to_remove)); + std::vector<LLMenuItemGL*>::iterator spillover_iter; + for (spillover_iter= items_to_remove.begin(); spillover_iter != items_to_remove.end(); ++spillover_iter) + { + LLMenuItemGL* itemp = (*spillover_iter); + removeChild(itemp); + mSpilloverMenu->addChild(itemp); + } - addChild(mSpilloverBranch); - height += mSpilloverBranch->getNominalHeight(); - width = llmax( width, mSpilloverBranch->getNominalWidth() ); + addChild(mSpilloverBranch); - break; - } - else - { - // track our rect - height += (*item_iter)->getNominalHeight(); - width = llmax( width, (*item_iter)->getNominalWidth() ); + height += mSpilloverBranch->getNominalHeight(); + width = llmax( width, mSpilloverBranch->getNominalWidth() ); + + break; + } } + // track our rect + height += (*item_iter)->getNominalHeight(); + width = llmax( width, (*item_iter)->getNominalWidth() ); + if (mScrollable) { // Determining visible items boundaries @@ -2369,7 +2373,9 @@ void LLMenuGL::createSpilloverBranch() branch_params.label = label; branch_params.branch = mSpilloverMenu; branch_params.font.style = "italic"; - + branch_params.highlight_bg_color=LLUIColorTable::instance().getColor("MenuItemHighlightBgColor"); + branch_params.highlight_fg_color=LLUIColorTable::instance().getColor("MenuItemHighlightFgColor"); + branch_params.enabled_color=LLUIColorTable::instance().getColor("MenuItemEnabledColor"); mSpilloverBranch = LLUICtrlFactory::create<LLMenuItemBranchGL>(branch_params); } diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index 9b125a85b9..09f923e74f 100755 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -38,6 +38,7 @@ #include "lltextutil.h" #include "lltooltip.h" #include "lluictrl.h" +#include "lluriparser.h" #include "llurlaction.h" #include "llurlregistry.h" #include "llview.h" @@ -2019,6 +2020,8 @@ static LLUIImagePtr image_from_icon_name(const std::string& icon_name) static LLTrace::BlockTimerStatHandle FTM_PARSE_HTML("Parse HTML"); + + void LLTextBase::appendTextImpl(const std::string &new_text, const LLStyle::Params& input_params) { LLStyle::Params style_params(input_params); @@ -2055,7 +2058,12 @@ void LLTextBase::appendTextImpl(const std::string &new_text, const LLStyle::Para std::string subtext=text.substr(0,start); appendAndHighlightText(subtext, part, style_params); } + + // add icon before url if need + LLTextUtil::processUrlMatch(&match, this, isContentTrusted() || match.isTrusted()); + // output the styled Url + //appendAndHighlightTextImpl(label, part, link_params, match.underlineOnHoverOnly()); appendAndHighlightTextImpl(match.getLabel(), part, link_params, match.underlineOnHoverOnly()); // set the tooltip for the Url label @@ -2063,14 +2071,12 @@ void LLTextBase::appendTextImpl(const std::string &new_text, const LLStyle::Para { segment_set_t::iterator it = getSegIterContaining(getLength()-1); if (it != mSegments.end()) - { - LLTextSegmentPtr segment = *it; - segment->setToolTip(match.getTooltip()); - } + { + LLTextSegmentPtr segment = *it; + segment->setToolTip(match.getTooltip()); + } } - LLTextUtil::processUrlMatch(&match,this,isContentTrusted()); - // move on to the rest of the text after the Url if (end < (S32)text.length()) { diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h index 738b4d5b8e..dfc10923f3 100755 --- a/indra/llui/lltextbase.h +++ b/indra/llui/lltextbase.h @@ -590,6 +590,7 @@ protected: void appendTextImpl(const std::string &new_text, const LLStyle::Params& input_params = LLStyle::Params()); void appendAndHighlightTextImpl(const std::string &new_text, S32 highlight_part, const LLStyle::Params& style_params, bool underline_on_hover_only = false); + S32 normalizeUri(std::string& uri); protected: diff --git a/indra/llui/lltextutil.h b/indra/llui/lltextutil.h index 798f14d086..1be81ffd62 100755 --- a/indra/llui/lltextutil.h +++ b/indra/llui/lltextutil.h @@ -64,7 +64,15 @@ namespace LLTextUtil */ const std::string& formatPhoneNumber(const std::string& phone_str); - bool processUrlMatch(LLUrlMatch* match,LLTextBase* text_base, bool is_content_trusted); + /** + * Adds icon before url if need. + * + * @param[in] match an object with results of matching + * @param[in] text_base pointer to UI text object + * @param[in] is_content_trusted true if context is trusted + * @return reference to string with formatted phone number + */ + bool processUrlMatch(LLUrlMatch* match, LLTextBase* text_base, bool is_content_trusted); class TextHelpers { diff --git a/indra/llui/llurlentry.cpp b/indra/llui/llurlentry.cpp index be583c83d8..c06d6144b9 100755 --- a/indra/llui/llurlentry.cpp +++ b/indra/llui/llurlentry.cpp @@ -31,6 +31,7 @@ #include "lluri.h" #include "llurlmatch.h" #include "llurlregistry.h" +#include "lluriparser.h" #include "llavatarnamecache.h" #include "llcachename.h" @@ -38,6 +39,8 @@ #include "lluicolortable.h" #include "message.h" +#include "uriparser/Uri.h" + #define APP_HEADER_REGEX "((x-grid-location-info://[-\\w\\.]+/app)|(secondlife:///app))" // Utility functions @@ -342,6 +345,30 @@ std::string LLUrlEntrySLURL::getLocation(const std::string &url) const } // +// LLUrlEntrySeconlifeURLs Describes *secondlife.com and *lindenlab.com urls to substitute icon 'hand.png' before link +// +LLUrlEntrySeconlifeURL::LLUrlEntrySeconlifeURL() +{ + mPattern = boost::regex("\\b(https?://)?([-\\w\\.]*\\.)?(secondlife|lindenlab)\\.com(:\\d{1,5})?(/\\S*)?\\b", + boost::regex::perl|boost::regex::icase); + + mIcon = "Hand"; + mMenuName = "menu_url_http.xml"; +} + +std::string LLUrlEntrySeconlifeURL::getLabel(const std::string &url, const LLUrlLabelCallback &cb) +{ + LLUriParser up(url); + up.extractParts(); + return up.host(); +} + +std::string LLUrlEntrySeconlifeURL::getTooltip(const std::string &url) const +{ + return url; +} + +// // LLUrlEntryAgent Describes a Second Life agent Url, e.g., // secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/about // x-grid-location-info://lincoln.lindenlab.com/app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/about diff --git a/indra/llui/llurlentry.h b/indra/llui/llurlentry.h index ffcd45dfde..1cb11cdb1c 100755 --- a/indra/llui/llurlentry.h +++ b/indra/llui/llurlentry.h @@ -96,6 +96,8 @@ public: /// Should this link text be underlined only when mouse is hovered over it? virtual bool underlineOnHoverOnly(const std::string &string) const { return false; } + virtual bool isTrusted() const { return false; } + virtual LLUUID getID(const std::string &string) const { return LLUUID::null; } bool isLinkDisabled() const; @@ -168,6 +170,21 @@ public: }; /// +/// LLUrlEntrySeconlifeURLs Describes *secondlife.com and *lindenlab.com Urls +/// +class LLUrlEntrySeconlifeURL : public LLUrlEntryBase +{ +public: + LLUrlEntrySeconlifeURL(); + bool isTrusted() const { return true; } + /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb); + /*virtual*/ std::string getTooltip(const std::string &url) const; + +private: + std::string mLabel; +}; + +/// /// LLUrlEntryAgent Describes a Second Life agent Url, e.g., /// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/about class LLUrlEntryAgent : public LLUrlEntryBase diff --git a/indra/llui/llurlmatch.cpp b/indra/llui/llurlmatch.cpp index c1f1382a9f..016d1ca92d 100755 --- a/indra/llui/llurlmatch.cpp +++ b/indra/llui/llurlmatch.cpp @@ -37,7 +37,8 @@ LLUrlMatch::LLUrlMatch() : mIcon(""), mMenuName(""), mLocation(""), - mUnderlineOnHoverOnly(false) + mUnderlineOnHoverOnly(false), + mTrusted(false) { } @@ -45,7 +46,7 @@ void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std::string &label, const std::string &tooltip, const std::string &icon, const LLStyle::Params& style, const std::string &menu, const std::string &location, - const LLUUID& id, bool underline_on_hover_only) + const LLUUID& id, bool underline_on_hover_only, bool trusted) { mStart = start; mEnd = end; @@ -59,4 +60,5 @@ void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, mLocation = location; mID = id; mUnderlineOnHoverOnly = underline_on_hover_only; + mTrusted = trusted; } diff --git a/indra/llui/llurlmatch.h b/indra/llui/llurlmatch.h index 2818f45207..9f8960b32f 100755 --- a/indra/llui/llurlmatch.h +++ b/indra/llui/llurlmatch.h @@ -80,12 +80,15 @@ public: /// Should this link text be underlined only when mouse is hovered over it? bool underlineOnHoverOnly() const { return mUnderlineOnHoverOnly; } + /// Return true if Url is trusted. + bool isTrusted() const { return mTrusted; } + /// 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 &tooltip, const std::string &icon, const LLStyle::Params& style, const std::string &menu, const std::string &location, const LLUUID& id, - bool underline_on_hover_only = false ); + bool underline_on_hover_only = false, bool trusted = false ); const LLUUID& getID() const { return mID; } private: @@ -100,6 +103,7 @@ private: LLUUID mID; LLStyle::Params mStyle; bool mUnderlineOnHoverOnly; + bool mTrusted; }; #endif diff --git a/indra/llui/llurlregistry.cpp b/indra/llui/llurlregistry.cpp index ef0789e0e4..9e8d8d01f1 100755 --- a/indra/llui/llurlregistry.cpp +++ b/indra/llui/llurlregistry.cpp @@ -27,6 +27,7 @@ #include "linden_common.h" #include "llurlregistry.h" +#include "lluriparser.h" #include <boost/regex.hpp> @@ -44,6 +45,10 @@ LLUrlRegistry::LLUrlRegistry() mUrlEntryIcon = new LLUrlEntryIcon(); registerUrl(mUrlEntryIcon); registerUrl(new LLUrlEntrySLURL()); + + // decorated links for host names like: secondlife.com and lindenlab.com + registerUrl(new LLUrlEntrySeconlifeURL()); + registerUrl(new LLUrlEntryHTTP()); mUrlEntryHTTPLabel = new LLUrlEntryHTTPLabel(); registerUrl(mUrlEntryHTTPLabel); @@ -203,6 +208,11 @@ bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LL { // fill in the LLUrlMatch object and return it std::string url = text.substr(match_start, match_end - match_start + 1); + + LLUriParser up(url); + up.normalize(); + url = up.normalizedUri(); + match.setValues(match_start, match_end, match_entry->getUrl(url), match_entry->getLabel(url, cb), @@ -212,7 +222,8 @@ bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LL match_entry->getMenuName(), match_entry->getLocation(url), match_entry->getID(url), - match_entry->underlineOnHoverOnly(url)); + match_entry->underlineOnHoverOnly(url), + match_entry->isTrusted()); return true; } |