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

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: other interface 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/string16.h"
12 #include "ui/base/range/range.h"
13 #include "ui/gfx/size.h"
14 #include "ui/views/controls/link_listener.h"
15 #include "ui/views/view.h"
16
17 namespace views {
18
19 class Link;
20 class StyledLabelListener;
21
22 // A class which can apply mixed styles to a block of text. Currently, text is
23 // always multiline, and the only style that may be applied is linkifying ranges
24 // of text.
25 class VIEWS_EXPORT StyledLabel : public View,
26 public LinkListener {
msw 2013/03/13 03:22:07 nit: fits on the line above.
Evan Stade 2013/03/14 00:30:46 Done.
27 public:
28 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.
29 virtual ~StyledLabel();
30
31 // Marks the given range within |text_| as a link.
32 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
33
34 // View implementation:
35 virtual int GetHeightForWidth(int w) OVERRIDE;
36 virtual void Layout() OVERRIDE;
37
38 // LinkListener implementation:
39 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
40
41 private:
42 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
43 LinkRange(const ui::Range& range) : range(range) {}
44 ~LinkRange() {}
45
46 bool operator<(const LinkRange& other) const;
47
48 ui::Range range;
49 };
50
51 // Calculates how to layout child views, creates them and sets their size
52 // and position. |width| is the horizontal space, in pixels, that the view
53 // has to work with. If |dry_run| is true, the view hierarchy is not touched.
54 // The return value is the height in pixels.
55 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
56
57 // The text to display.
58 string16 text_;
59
60 // The listener that will be informed of link clicks.
61 StyledLabelListener* listener_;
62
63 // The ranges that should be linkified, sorted by start position.
64 std::priority_queue<LinkRange> link_ranges_;
65
66 // A mapping from Link* control to the range it corresponds to in |text_|.
67 std::map<Link*, ui::Range> link_targets_;
68
69 // This variable saves the result of the last GetHeightForWidth call in order
70 // to avoid repeated calculation.
71 gfx::Size calculated_size_;
72 };
73
74 } // namespace views
75
76 #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