Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: ui/views/controls/styled_label.h

Issue 12906002: Add ability to defined ranges with different styles in StyledLabel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/styled_label.cc » ('j') | ui/views/controls/styled_label.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/styled_label.h
diff --git a/ui/views/controls/styled_label.h b/ui/views/controls/styled_label.h
index 3b683d2e4903e992c1ac7be3438df91db6924d37..b7479514500cfaeec8c58ba94ad6e980b668401e 100644
--- a/ui/views/controls/styled_label.h
+++ b/ui/views/controls/styled_label.h
@@ -21,16 +21,38 @@ class Link;
class StyledLabelListener;
// A class which can apply mixed styles to a block of text. Currently, text is
-// always multiline, and the only style that may be applied is linkifying ranges
-// of text.
+// always multiline. Trailing and leading whitespace in text is not supported
+// and will be trimmed on StyledLabel construction.
class VIEWS_EXPORT StyledLabel : public View, public LinkListener {
public:
+ // Parameters that define label style for a styled label's text range.
+ struct RangeStyleInfo {
+ RangeStyleInfo();
+ ~RangeStyleInfo();
+
+ // The font style that will be applied to the range. Should be a bitmask of
+ // values defined in gfx::Font::FontStyle (BOLD, ITALIC, UNDERLINE).
+ int font_style;
+ // Tooltip for the range.
+ string16 tooltip;
+ // If set, the whole range will be put on a single line.
+ bool disable_line_wrapping;
+ // If set, the range will be created as a link.
+ bool linkify;
sky 2013/03/28 16:02:09 How about is_link.
tbarzic 2013/03/28 20:33:58 Done.
+ };
+
+ // Note that any trailing or leading whitespace in |text| will be trimmed.
StyledLabel(const string16& text, StyledLabelListener* listener);
virtual ~StyledLabel();
- // Marks the given range within |text_| as a link.
+ // Marks the given range within |text_| as a link. |range| should be contained
sky 2013/03/28 16:02:09 should->must
tbarzic 2013/03/28 20:33:58 Done.
+ // in |text_|.
void AddLink(const ui::Range& range);
+ // Marks the given range within |text_| with style defined by |style_info|.
+ // |range| should be contained in |text_|.
sky 2013/03/28 16:02:09 should->must
tbarzic 2013/03/28 20:33:58 Done.
+ void AddStyleRange(const ui::Range& range, const RangeStyleInfo& style_info);
+
// View implementation:
virtual gfx::Insets GetInsets() const OVERRIDE;
virtual int GetHeightForWidth(int w) OVERRIDE;
@@ -40,13 +62,18 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener {
virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
private:
- struct LinkRange {
- explicit LinkRange(const ui::Range& range) : range(range) {}
- ~LinkRange() {}
+ struct StyleRange {
+ StyleRange(const ui::Range& range,
+ const RangeStyleInfo& style_info)
+ : range(range),
+ style_info(style_info) {
+ }
+ ~StyleRange() {}
- bool operator<(const LinkRange& other) const;
+ bool operator<(const StyleRange& other) const;
ui::Range range;
+ RangeStyleInfo style_info;
};
// Calculates how to layout child views, creates them and sets their size
@@ -62,10 +89,11 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener {
StyledLabelListener* listener_;
// The ranges that should be linkified, sorted by start position.
- std::priority_queue<LinkRange> link_ranges_;
+ std::priority_queue<StyleRange> style_ranges_;
- // A mapping from Link* control to the range it corresponds to in |text_|.
- std::map<Link*, ui::Range> link_targets_;
+ // A mapping from a view to the range it corresponds to in |text_|. Only views
+ // that correspond to ranges with linkify style set will be added to the map.
+ std::map<View*, ui::Range> link_targets_;
// This variable saves the result of the last GetHeightForWidth call in order
// to avoid repeated calculation.
« no previous file with comments | « no previous file | ui/views/controls/styled_label.cc » ('j') | ui/views/controls/styled_label.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698