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

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 | « chrome/browser/ui/views/autofill/autofill_dialog_views.cc ('k') | ui/views/controls/styled_label.cc » ('j') | no next file with comments »
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 70a0515a5a266160dc57ea1de3e963e36e19c152..ec166a49afec64bbc90e115e90e2ac2fd660d9cf 100644
--- a/ui/views/controls/styled_label.h
+++ b/ui/views/controls/styled_label.h
@@ -21,18 +21,44 @@ 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 whitespace in the styled label text is not
+// supported and will be trimmed on StyledLabel construction. Leading
+// whitespace is respected, provided not only whitespace fits in the first line.
+// In this case, leading whitespace is ignored.
class VIEWS_EXPORT StyledLabel : public View, public LinkListener {
public:
+ // Parameters that define label style for a styled label's text range.
+ struct VIEWS_EXPORT RangeStyleInfo {
+ RangeStyleInfo();
+ ~RangeStyleInfo();
+
+ // Creates a range style info with default values for link.
+ static RangeStyleInfo CreateForLink();
+
+ // 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 is_link;
+ };
+
+ // Note that any trailing whitespace in |text| will be trimmed.
StyledLabel(const string16& text, StyledLabelListener* listener);
virtual ~StyledLabel();
// Sets the text to be displayed, and clears any previous styling.
void SetText(const string16& text);
- // Marks the given range within |text_| as a link.
- void AddLink(const ui::Range& range);
+ // Marks the given range within |text_| with style defined by |style_info|.
+ // |range| must be contained in |text_|.
+ void AddStyleRange(const ui::Range& range, const RangeStyleInfo& style_info);
// View implementation:
virtual gfx::Insets GetInsets() const OVERRIDE;
@@ -43,13 +69,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
@@ -65,10 +96,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 is_link 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 | « chrome/browser/ui/views/autofill/autofill_dialog_views.cc ('k') | ui/views/controls/styled_label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698