OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_MESSAGE_CENTER_BOUNDED_LABEL_H_ | |
6 #define UI_MESSAGE_CENTER_BOUNDED_LABEL_H_ | |
7 | |
8 #include "testing/gtest/include/gtest/gtest_prod.h" | |
9 #include "ui/message_center/message_center_export.h" | |
10 #include "ui/views/controls/label.h" | |
11 | |
12 namespace message_center { | |
13 | |
14 // BoundedLabels display text up to a maximum number of lines, with ellipsis at | |
15 // the end of the last line for any omitted text. The font, text, multiline | |
16 // behavior, character break behavior, elide behavior, and focus border of | |
17 // instances of this views::Label subclass cannot be changed, so the following | |
18 // views::Label methods should never be called with instances of this class: | |
19 // | |
20 // SetFont() | |
21 // SetText() | |
22 // SetMultiLine() | |
23 // SetAllowCharacterBreak() | |
24 // SetElideBehavior() | |
25 // SetHasFocusBorder() | |
26 // | |
27 class MESSAGE_CENTER_EXPORT BoundedLabel : public views::Label { | |
28 public: | |
29 BoundedLabel(string16 text, size_t max_lines); | |
30 BoundedLabel(string16 text, gfx::Font font, size_t max_lines); | |
31 virtual ~BoundedLabel(); | |
32 | |
33 void SetMaxLines(size_t lines); | |
34 size_t GetMaxLines(); | |
35 size_t GetPreferredLines(); | |
36 | |
37 virtual int GetHeightForWidth(int width) OVERRIDE; | |
38 | |
39 protected: | |
40 // Overridden from views::Label. | |
41 virtual gfx::Size GetTextSize() const OVERRIDE; | |
42 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | |
43 virtual void PaintText(gfx::Canvas* canvas, | |
44 const string16& text, | |
45 const gfx::Rect& text_bounds, | |
46 int flags) OVERRIDE; | |
47 | |
48 private: | |
49 friend class BoundedLabelTest; | |
50 | |
51 void Init(size_t max_lines); | |
52 int GetTextFlags() const; | |
53 int GetTextHeightForWidth(int width) const; | |
54 std::vector<string16> SplitLines(int width, size_t max_lines) const; | |
55 | |
56 size_t max_lines_; | |
57 size_t preferred_lines_; | |
58 bool is_preferred_lines_valid_; | |
59 mutable gfx::Size text_size_; | |
60 mutable bool is_text_size_valid_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(BoundedLabel); | |
63 }; | |
64 | |
65 } // namespace message_center | |
66 | |
67 #endif // UI_MESSAGE_CENTER_BOUNDED_LABEL_H_ | |
OLD | NEW |