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.
5 #ifndef UI_MESSAGE_CENTER_BOUNDED_LABEL_H_
6 #define UI_MESSAGE_CENTER_BOUNDED_LABEL_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/message_center/message_center_export.h"
14 #include "ui/views/view.h"
22 namespace message_center
{
24 class InnerBoundedLabel
;
26 // BoundedLabels display left aligned text up to a maximum number of lines, with
27 // ellipsis at the end of the last line for any omitted text. BoundedLabel is a
28 // direct subclass of views::Views rather than a subclass of views::Label
29 // because of limitations in views::Label's implementation. See the description
30 // of InnerBoundedLabel in the .cc file for details.
31 class MESSAGE_CENTER_EXPORT BoundedLabel
: public views::View
{
33 BoundedLabel(const string16
& text
, gfx::Font font
, size_t line_limit
);
34 BoundedLabel(const string16
& text
, size_t line_limit
);
35 virtual ~BoundedLabel();
37 void SetLineLimit(size_t lines
);
38 size_t GetLinesForWidth(int width
);
39 size_t GetPreferredLines();
40 size_t GetActualLines();
42 void SetColors(SkColor textColor
, SkColor backgroundColor
);
44 // Overridden from views::View.
45 virtual int GetBaseline() const OVERRIDE
;
46 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
47 virtual int GetHeightForWidth(int w
) OVERRIDE
;
48 virtual void Paint(gfx::Canvas
* canvas
) OVERRIDE
;
49 virtual bool HitTestRect(const gfx::Rect
& rect
) const OVERRIDE
;
50 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
53 // Overridden from views::View.
54 virtual void OnBoundsChanged(const gfx::Rect
& previous_bounds
) OVERRIDE
;
55 virtual void OnNativeThemeChanged(const ui::NativeTheme
* theme
) OVERRIDE
;
58 friend class BoundedLabelTest
;
60 string16
GetWrappedTextForTest(int width
, size_t line_limit
);
62 scoped_ptr
<InnerBoundedLabel
> label_
;
64 DISALLOW_COPY_AND_ASSIGN(BoundedLabel
);
67 } // namespace message_center
69 #endif // UI_MESSAGE_CENTER_BOUNDED_LABEL_H_