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

Side by Side Diff: ui/message_center/views/bounded_label.h

Issue 12742005: Added text line limits to collapsed and expanded notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
OLDNEW
(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) const 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 std::vector<string16> SplitLines(int width, size_t max_lines) const;
54
55 size_t max_lines_;
56 size_t preferred_lines_;
57 bool is_preferred_lines_valid_;
58 mutable gfx::Size text_size_;
59 mutable bool is_text_size_valid_;
60
61 DISALLOW_COPY_AND_ASSIGN(BoundedLabel);
62 };
63
64 } // namespace message_center
65
66 #endif // UI_MESSAGE_CENTER_BOUNDED_LABEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698