Chromium Code Reviews| Index: ui/views/controls/styled_label.h | 
| diff --git a/ui/views/controls/styled_label.h b/ui/views/controls/styled_label.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..4779f75eef980153ed4e68646cbbfb4272b629e3 | 
| --- /dev/null | 
| +++ b/ui/views/controls/styled_label.h | 
| @@ -0,0 +1,76 @@ | 
| +// Copyright 2013 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef UI_VIEWS_CONTROLS_STYLED_LABEL_H_ | 
| +#define UI_VIEWS_CONTROLS_STYLED_LABEL_H_ | 
| + | 
| +#include <map> | 
| +#include <queue> | 
| + | 
| +#include "base/string16.h" | 
| +#include "ui/base/range/range.h" | 
| +#include "ui/gfx/size.h" | 
| +#include "ui/views/controls/link_listener.h" | 
| +#include "ui/views/view.h" | 
| + | 
| +namespace views { | 
| + | 
| +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. | 
| +class VIEWS_EXPORT StyledLabel : public View, | 
| + public LinkListener { | 
| 
 
msw
2013/03/13 03:22:07
nit: fits on the line above.
 
Evan Stade
2013/03/14 00:30:46
Done.
 
 | 
| + public: | 
| + explicit StyledLabel(const string16& text, StyledLabelListener* listener); | 
| 
 
msw
2013/03/13 03:22:07
Could you take a LinkListener instead and nix Styl
 
Evan Stade
2013/03/14 00:30:46
no, see below.
 
 | 
| + virtual ~StyledLabel(); | 
| + | 
| + // Marks the given range within |text_| as a link. | 
| + void SetLink(const ui::Range& range); | 
| 
 
msw
2013/03/13 03:22:07
Shouldn't this let users supply the associated Lin
 
Evan Stade
2013/03/14 00:30:46
No. The fact that this class uses a Link view is a
 
sky
2013/03/14 14:43:58
That is definitely the case, but making this class
 
Evan Stade
2013/03/14 19:07:40
there's not always going to be a GURL associated w
 
msw
2013/03/14 23:24:30
Hmm, I see your point. I guess tracking links by r
 
 | 
| + | 
| + // View implementation: | 
| + virtual int GetHeightForWidth(int w) OVERRIDE; | 
| + virtual void Layout() OVERRIDE; | 
| + | 
| + // LinkListener implementation: | 
| + virtual void LinkClicked(Link* source, int event_flags) OVERRIDE; | 
| + | 
| + private: | 
| + struct LinkRange { | 
| 
 
msw
2013/03/13 03:22:07
Try replacing LinkRange, link_ranges_, & link_targ
 
Evan Stade
2013/03/14 00:30:46
I tried doing this, but it's not pretty because ui
 
 | 
| + LinkRange(const ui::Range& range) : range(range) {} | 
| + ~LinkRange() {} | 
| + | 
| + bool operator<(const LinkRange& other) const; | 
| + | 
| + ui::Range range; | 
| + }; | 
| + | 
| + // Calculates how to layout child views, creates them and sets their size | 
| + // and position. |width| is the horizontal space, in pixels, that the view | 
| + // has to work with. If |dry_run| is true, the view hierarchy is not touched. | 
| + // The return value is the height in pixels. | 
| + int CalculateAndDoLayout(int width, bool dry_run); | 
| 
 
msw
2013/03/13 03:22:07
nit: Maybe GetHeightForWidthAndLayout with s/dry_r
 
Evan Stade
2013/03/14 00:30:46
I prefer the current naming but can change it if y
 
 | 
| + | 
| + // The text to display. | 
| + string16 text_; | 
| + | 
| + // The listener that will be informed of link clicks. | 
| + StyledLabelListener* listener_; | 
| + | 
| + // The ranges that should be linkified, sorted by start position. | 
| + std::priority_queue<LinkRange> link_ranges_; | 
| + | 
| + // A mapping from Link* control to the range it corresponds to in |text_|. | 
| + std::map<Link*, ui::Range> link_targets_; | 
| + | 
| + // This variable saves the result of the last GetHeightForWidth call in order | 
| + // to avoid repeated calculation. | 
| + gfx::Size calculated_size_; | 
| +}; | 
| + | 
| +} // namespace views | 
| + | 
| +#endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ |