Chromium Code Reviews| OLD | NEW |
|---|---|
| (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, public LinkListener { | |
| 26 public: | |
| 27 explicit StyledLabel(const string16& text, StyledLabelListener* listener); | |
| 28 virtual ~StyledLabel(); | |
| 29 | |
| 30 // Marks the given range within |text_| as a link. | |
| 31 void SetLink(const ui::Range& range); | |
|
sky
2013/03/14 14:43:58
Makybe this should be AddLink since Set implies on
Evan Stade
2013/03/14 19:07:40
Done.
| |
| 32 | |
| 33 // View implementation: | |
| 34 virtual int GetHeightForWidth(int w) OVERRIDE; | |
| 35 virtual void Layout() OVERRIDE; | |
| 36 | |
| 37 // LinkListener implementation: | |
| 38 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE; | |
| 39 | |
| 40 private: | |
| 41 struct LinkRange { | |
| 42 LinkRange(const ui::Range& range) : range(range) {} | |
|
sky
2013/03/14 14:43:58
explicit
Evan Stade
2013/03/14 19:07:40
Done.
| |
| 43 ~LinkRange() {} | |
| 44 | |
| 45 bool operator<(const LinkRange& other) const; | |
| 46 | |
| 47 ui::Range range; | |
| 48 }; | |
| 49 | |
| 50 // Calculates how to layout child views, creates them and sets their size | |
| 51 // and position. |width| is the horizontal space, in pixels, that the view | |
| 52 // has to work with. If |dry_run| is true, the view hierarchy is not touched. | |
| 53 // The return value is the height in pixels. | |
| 54 int CalculateAndDoLayout(int width, bool dry_run); | |
| 55 | |
| 56 // The text to display. | |
| 57 string16 text_; | |
| 58 | |
| 59 // The listener that will be informed of link clicks. | |
| 60 StyledLabelListener* listener_; | |
| 61 | |
| 62 // The ranges that should be linkified, sorted by start position. | |
| 63 std::priority_queue<LinkRange> link_ranges_; | |
| 64 | |
| 65 // A mapping from Link* control to the range it corresponds to in |text_|. | |
| 66 std::map<Link*, ui::Range> link_targets_; | |
| 67 | |
| 68 // This variable saves the result of the last GetHeightForWidth call in order | |
| 69 // to avoid repeated calculation. | |
| 70 gfx::Size calculated_size_; | |
| 71 }; | |
|
sky
2013/03/14 14:43:58
DISALLOW...
Evan Stade
2013/03/14 19:07:40
Done.
| |
| 72 | |
| 73 } // namespace views | |
| 74 | |
| 75 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ | |
| OLD | NEW |