OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | 5 #ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ |
6 #define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | 6 #define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ |
7 | 7 |
8 #include "ash/system/tray/actionable_view.h" | 8 #include "ash/system/tray/actionable_view.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "ui/gfx/font.h" | 11 #include "ui/gfx/font.h" |
12 #include "ui/gfx/text_constants.h" | 12 #include "ui/gfx/text_constants.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 class Label; | 15 class Label; |
16 } | 16 } |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 class ViewClickListener; | 19 class ViewClickListener; |
20 | 20 |
21 // A view that changes background color on hover, and triggers a callback in the | 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 | 22 // associated ViewClickListener on click. The view can also be forced to |
23 // maintain a fixed height. | 23 // maintain a fixed height. |
24 class HoverHighlightView : public ActionableView { | 24 class HoverHighlightView : public ActionableView { |
25 public: | 25 public: |
26 explicit HoverHighlightView(ViewClickListener* listener); | 26 explicit HoverHighlightView(ViewClickListener* listener); |
27 virtual ~HoverHighlightView(); | 27 ~HoverHighlightView() override; |
28 | 28 |
29 // Convenience function for adding an icon and a label. This also sets the | 29 // Convenience function for adding an icon and a label. This also sets the |
30 // accessible name. | 30 // accessible name. |
31 void AddIconAndLabel(const gfx::ImageSkia& image, | 31 void AddIconAndLabel(const gfx::ImageSkia& image, |
32 const base::string16& text, | 32 const base::string16& text, |
33 gfx::Font::FontStyle style); | 33 gfx::Font::FontStyle style); |
34 | 34 |
35 // Convenience function for adding a label with padding on the left for a | 35 // Convenience function for adding a label with padding on the left for a |
36 // blank icon. This also sets the accessible name. | 36 // blank icon. This also sets the accessible name. |
37 // Returns label after parenting it. | 37 // Returns label after parenting it. |
(...skipping 16 matching lines...) Expand all Loading... |
54 void set_default_color(SkColor color) { default_color_ = color; } | 54 void set_default_color(SkColor color) { default_color_ = color; } |
55 void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; } | 55 void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; } |
56 void set_text_default_color(SkColor color) { text_default_color_ = color; } | 56 void set_text_default_color(SkColor color) { text_default_color_ = color; } |
57 | 57 |
58 views::Label* text_label() { return text_label_; } | 58 views::Label* text_label() { return text_label_; } |
59 | 59 |
60 bool hover() const { return hover_; } | 60 bool hover() const { return hover_; } |
61 | 61 |
62 protected: | 62 protected: |
63 // Overridden from views::View. | 63 // Overridden from views::View. |
64 virtual void GetAccessibleState(ui::AXViewState* state) override; | 64 void GetAccessibleState(ui::AXViewState* state) override; |
65 | 65 |
66 private: | 66 private: |
67 // Sets the highlighted color on a text label if |hover| is set. | 67 // Sets the highlighted color on a text label if |hover| is set. |
68 void SetHoverHighlight(bool hover); | 68 void SetHoverHighlight(bool hover); |
69 | 69 |
70 // Overridden from ActionableView: | 70 // Overridden from ActionableView: |
71 virtual bool PerformAction(const ui::Event& event) override; | 71 bool PerformAction(const ui::Event& event) override; |
72 | 72 |
73 // Overridden from views::View. | 73 // Overridden from views::View. |
74 virtual gfx::Size GetPreferredSize() const override; | 74 gfx::Size GetPreferredSize() const override; |
75 virtual int GetHeightForWidth(int width) const override; | 75 int GetHeightForWidth(int width) const override; |
76 virtual void OnMouseEntered(const ui::MouseEvent& event) override; | 76 void OnMouseEntered(const ui::MouseEvent& event) override; |
77 virtual void OnMouseExited(const ui::MouseEvent& event) override; | 77 void OnMouseExited(const ui::MouseEvent& event) override; |
78 virtual void OnGestureEvent(ui::GestureEvent* event) override; | 78 void OnGestureEvent(ui::GestureEvent* event) override; |
79 virtual void OnEnabledChanged() override; | 79 void OnEnabledChanged() override; |
80 virtual void OnPaintBackground(gfx::Canvas* canvas) override; | 80 void OnPaintBackground(gfx::Canvas* canvas) override; |
81 virtual void OnFocus() override; | 81 void OnFocus() override; |
82 | 82 |
83 ViewClickListener* listener_; | 83 ViewClickListener* listener_; |
84 views::Label* text_label_; | 84 views::Label* text_label_; |
85 SkColor highlight_color_; | 85 SkColor highlight_color_; |
86 SkColor default_color_; | 86 SkColor default_color_; |
87 SkColor text_highlight_color_; | 87 SkColor text_highlight_color_; |
88 SkColor text_default_color_; | 88 SkColor text_default_color_; |
89 bool hover_; | 89 bool hover_; |
90 bool expandable_; | 90 bool expandable_; |
91 bool checkable_; | 91 bool checkable_; |
92 bool checked_; | 92 bool checked_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); | 94 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); |
95 }; | 95 }; |
96 | 96 |
97 } // namespace ash | 97 } // namespace ash |
98 | 98 |
99 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | 99 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ |
OLD | NEW |