| 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..6fdc63f9171f46014ad67422b9bc07d81e475cbd 100644
|
| --- a/ui/views/controls/styled_label.h
|
| +++ b/ui/views/controls/styled_label.h
|
| @@ -21,15 +21,41 @@ 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 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();
|
|
|
| - // 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;
|
| @@ -40,13 +66,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 +93,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.
|
|
|