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 ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
6 #define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
8 #include "ash/system/tray/actionable_view.h"
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "ui/gfx/font.h"
12 #include "ui/gfx/text_constants.h"
19 class ViewClickListener
;
21 // A view that changes background color on hover, and triggers a callback in the
22 // associated ViewClickListener on click. The view can also be forced to
23 // maintain a fixed height.
24 class HoverHighlightView
: public ActionableView
{
26 explicit HoverHighlightView(ViewClickListener
* listener
);
27 ~HoverHighlightView() override
;
29 // Convenience function for adding an icon and a label. This also sets the
31 void AddIconAndLabel(const gfx::ImageSkia
& image
,
32 const base::string16
& text
,
35 // Convenience function for adding an icon and a label. This also sets the
36 // accessible name. The icon has an indent equal to
37 // kTrayPopupPaddingHorizontal.
38 void AddIndentedIconAndLabel(const gfx::ImageSkia
& image
,
39 const base::string16
& text
,
42 // Convenience function for adding a label with padding on the left for a
43 // blank icon. This also sets the accessible name. Returns label after
45 views::Label
* AddLabel(const base::string16
& text
,
46 gfx::HorizontalAlignment alignment
,
49 // Convenience function for adding an optional check and a label. In the
50 // absence of a check, padding is added to align with checked items.
51 // Returns label after parenting it.
52 views::Label
* AddCheckableLabel(const base::string16
& text
,
56 // Allows view to expand its height.
57 // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight.
58 void SetExpandable(bool expandable
);
60 void set_highlight_color(SkColor color
) { highlight_color_
= color
; }
61 void set_default_color(SkColor color
) { default_color_
= color
; }
62 void set_text_highlight_color(SkColor c
) { text_highlight_color_
= c
; }
63 void set_text_default_color(SkColor color
) { text_default_color_
= color
; }
65 views::Label
* text_label() { return text_label_
; }
67 bool hover() const { return hover_
; }
70 // Overridden from views::View.
71 void GetAccessibleState(ui::AXViewState
* state
) override
;
73 // Sets the highlighted color on a text label if |hover| is set.
74 void SetHoverHighlight(bool hover
);
77 // Actually adds the icon and label but does not set the layout manager
78 void DoAddIconAndLabel(const gfx::ImageSkia
& image
,
79 const base::string16
& text
,
82 // Overridden from ActionableView:
83 bool PerformAction(const ui::Event
& event
) override
;
85 // Overridden from views::View.
86 gfx::Size
GetPreferredSize() const override
;
87 int GetHeightForWidth(int width
) const override
;
88 void OnMouseEntered(const ui::MouseEvent
& event
) override
;
89 void OnMouseExited(const ui::MouseEvent
& event
) override
;
90 void OnGestureEvent(ui::GestureEvent
* event
) override
;
91 void OnBoundsChanged(const gfx::Rect
& previous_bounds
) override
;
92 void OnEnabledChanged() override
;
93 void OnPaintBackground(gfx::Canvas
* canvas
) override
;
94 void OnFocus() override
;
96 ViewClickListener
* listener_
;
97 views::Label
* text_label_
;
98 SkColor highlight_color_
;
99 SkColor default_color_
;
100 SkColor text_highlight_color_
;
101 SkColor text_default_color_
;
107 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView
);
112 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_