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. 4 5 #ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ 6 #define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ 7 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 13 namespace views { 14 class Label; 15 } 16 17 namespace ash { 18 namespace internal { 19 20 class ViewClickListener; 21 22 // A view that changes background color on hover, and triggers a callback in the 23 // associated ViewClickListener on click. The view can also be forced to 24 // maintain a fixed height. 25 class HoverHighlightView : public ActionableView { 26 public: 27 explicit HoverHighlightView(ViewClickListener* listener); 28 virtual ~HoverHighlightView(); 29 30 // Convenience function for adding an icon and a label. This also sets the 31 // accessible name. 32 void AddIconAndLabel(const gfx::ImageSkia& image, 33 const base::string16& text, 34 gfx::Font::FontStyle style); 35 36 // Convenience function for adding a label with padding on the left for a 37 // blank icon. This also sets the accessible name. 38 // Returns label after parenting it. 39 views::Label* AddLabel(const base::string16& text, 40 gfx::Font::FontStyle style); 41 42 // Convenience function for adding an optional check and a label. In the 43 // absence of a check, padding is added to align with checked items. 44 // Returns label after parenting it. 45 views::Label* AddCheckableLabel(const base::string16& text, 46 gfx::Font::FontStyle style, 47 bool checked); 48 49 // Allows view to expand its height. 50 // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight. 51 void SetExpandable(bool expandable); 52 set_highlight_color(SkColor color)53 void set_highlight_color(SkColor color) { highlight_color_ = color; } set_default_color(SkColor color)54 void set_default_color(SkColor color) { default_color_ = color; } set_text_highlight_color(SkColor c)55 void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; } set_text_default_color(SkColor color)56 void set_text_default_color(SkColor color) { text_default_color_ = color; } 57 text_label()58 views::Label* text_label() { return text_label_; } 59 hover()60 bool hover() const { return hover_; } 61 62 private: 63 // Overridden from ActionableView: 64 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 65 66 // Overridden from views::View. 67 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 68 virtual gfx::Size GetPreferredSize() OVERRIDE; 69 virtual int GetHeightForWidth(int width) OVERRIDE; 70 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 71 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 72 virtual void OnEnabledChanged() OVERRIDE; 73 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 74 virtual void OnFocus() OVERRIDE; 75 76 ViewClickListener* listener_; 77 views::Label* text_label_; 78 SkColor highlight_color_; 79 SkColor default_color_; 80 SkColor text_highlight_color_; 81 SkColor text_default_color_; 82 bool hover_; 83 bool expandable_; 84 bool checkable_; 85 bool checked_; 86 87 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); 88 }; 89 90 } // namespace internal 91 } // namespace ash 92 93 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ 94