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

Side by Side Diff: ui/views/controls/styled_label.h

Issue 12543032: Add views::RichLabel, a class which creates multi-line text with mixed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add tests 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/controls/styled_label.cc » ('j') | ui/views/controls/styled_label.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_VIEWS_CONTROLS_STYLED_LABEL_H_
6 #define UI_VIEWS_CONTROLS_STYLED_LABEL_H_
7
8 #include <map>
9 #include <queue>
10
11 #include "base/basictypes.h"
12 #include "base/string16.h"
13 #include "ui/base/range/range.h"
14 #include "ui/gfx/size.h"
15 #include "ui/views/controls/link_listener.h"
16 #include "ui/views/view.h"
17
18 namespace views {
19
20 class Link;
21 class StyledLabelListener;
22
23 // A class which can apply mixed styles to a block of text. Currently, text is
24 // always multiline, and the only style that may be applied is linkifying ranges
25 // of text.
26 class VIEWS_EXPORT StyledLabel : public View, public LinkListener {
27 public:
28 StyledLabel(const string16& text, StyledLabelListener* listener);
29 virtual ~StyledLabel();
30
31 // Marks the given range within |text_| as a link.
32 void AddLink(const ui::Range& range);
33
34 // View implementation:
35 virtual gfx::Insets GetInsets() const OVERRIDE;
36 virtual int GetHeightForWidth(int w) OVERRIDE;
37 virtual void Layout() OVERRIDE;
38
39 // LinkListener implementation:
40 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
41
42 private:
43 struct LinkRange {
44 explicit LinkRange(const ui::Range& range) : range(range) {}
45 ~LinkRange() {}
46
47 bool operator<(const LinkRange& other) const;
48
49 ui::Range range;
50 };
51
52 // Calculates how to layout child views, creates them and sets their size
53 // and position. |width| is the horizontal space, in pixels, that the view
54 // has to work with. If |dry_run| is true, the view hierarchy is not touched.
55 // The return value is the height in pixels.
56 int CalculateAndDoLayout(int width, bool dry_run);
57
58 // Calculates the height of a line of text. Currently returns the height of
59 // a link.
60 int CalculateLineHeight();
msw 2013/03/14 23:24:30 nit: make this a static class function or a file-l
Evan Stade 2013/03/15 02:42:27 Done.
61
62 // The text to display.
63 string16 text_;
64
65 // The listener that will be informed of link clicks.
66 StyledLabelListener* listener_;
67
68 // The ranges that should be linkified, sorted by start position.
69 std::priority_queue<LinkRange> link_ranges_;
70
71 // A mapping from Link* control to the range it corresponds to in |text_|.
72 std::map<Link*, ui::Range> link_targets_;
73
74 // This variable saves the result of the last GetHeightForWidth call in order
75 // to avoid repeated calculation.
76 gfx::Size calculated_size_;
77
78 DISALLOW_COPY_AND_ASSIGN(StyledLabel);
79 };
80
81 } // namespace views
82
83 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_
OLDNEW
« 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