| OLD | NEW |
| (Empty) |
| 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/compiler_specific.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "ui/gfx/font.h" | |
| 12 #include "ui/gfx/text_constants.h" | |
| 13 | |
| 14 namespace views { | |
| 15 class Label; | |
| 16 } | |
| 17 | |
| 18 namespace ash { | |
| 19 class ViewClickListener; | |
| 20 | |
| 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 { | |
| 25 public: | |
| 26 explicit HoverHighlightView(ViewClickListener* listener); | |
| 27 ~HoverHighlightView() override; | |
| 28 | |
| 29 // views::View | |
| 30 bool GetTooltipText(const gfx::Point& p, | |
| 31 base::string16* tooltip) const override; | |
| 32 | |
| 33 // Convenience function for adding an icon and a label. This also sets the | |
| 34 // accessible name. | |
| 35 void AddIconAndLabel(const gfx::ImageSkia& image, | |
| 36 const base::string16& text, | |
| 37 bool highlight); | |
| 38 | |
| 39 // Convenience function for adding an icon and a label. This also sets the | |
| 40 // accessible name. The icon has an indent equal to | |
| 41 // kTrayPopupPaddingHorizontal. | |
| 42 void AddIndentedIconAndLabel(const gfx::ImageSkia& image, | |
| 43 const base::string16& text, | |
| 44 bool highlight); | |
| 45 | |
| 46 // Convenience function for adding a label with padding on the left for a | |
| 47 // blank icon. This also sets the accessible name. Returns label after | |
| 48 // parenting it. | |
| 49 views::Label* AddLabel(const base::string16& text, | |
| 50 gfx::HorizontalAlignment alignment, | |
| 51 bool highlight); | |
| 52 | |
| 53 // Convenience function for adding an optional check and a label. In the | |
| 54 // absence of a check, padding is added to align with checked items. | |
| 55 // Returns label after parenting it. | |
| 56 views::Label* AddCheckableLabel(const base::string16& text, | |
| 57 bool highlight, | |
| 58 bool checked); | |
| 59 | |
| 60 // Allows view to expand its height. | |
| 61 // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight. | |
| 62 void SetExpandable(bool expandable); | |
| 63 | |
| 64 void set_highlight_color(SkColor color) { highlight_color_ = color; } | |
| 65 void set_default_color(SkColor color) { default_color_ = color; } | |
| 66 void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; } | |
| 67 void set_text_default_color(SkColor color) { text_default_color_ = color; } | |
| 68 | |
| 69 views::Label* text_label() { return text_label_; } | |
| 70 | |
| 71 bool hover() const { return hover_; } | |
| 72 | |
| 73 void set_tooltip(const base::string16& tooltip) { tooltip_ = tooltip; } | |
| 74 | |
| 75 protected: | |
| 76 // Overridden from views::View. | |
| 77 void GetAccessibleState(ui::AXViewState* state) override; | |
| 78 | |
| 79 // Sets the highlighted color on a text label if |hover| is set. | |
| 80 void SetHoverHighlight(bool hover); | |
| 81 | |
| 82 private: | |
| 83 // Actually adds the icon and label but does not set the layout manager | |
| 84 void DoAddIconAndLabel(const gfx::ImageSkia& image, | |
| 85 const base::string16& text, | |
| 86 bool highlight); | |
| 87 | |
| 88 // Overridden from ActionableView: | |
| 89 bool PerformAction(const ui::Event& event) override; | |
| 90 | |
| 91 // Overridden from views::View. | |
| 92 gfx::Size GetPreferredSize() const override; | |
| 93 int GetHeightForWidth(int width) const override; | |
| 94 void OnMouseEntered(const ui::MouseEvent& event) override; | |
| 95 void OnMouseExited(const ui::MouseEvent& event) override; | |
| 96 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 97 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
| 98 void OnEnabledChanged() override; | |
| 99 void OnPaintBackground(gfx::Canvas* canvas) override; | |
| 100 void OnFocus() override; | |
| 101 | |
| 102 ViewClickListener* listener_; | |
| 103 views::Label* text_label_; | |
| 104 SkColor highlight_color_; | |
| 105 SkColor default_color_; | |
| 106 SkColor text_highlight_color_; | |
| 107 SkColor text_default_color_; | |
| 108 bool hover_; | |
| 109 bool expandable_; | |
| 110 bool checkable_; | |
| 111 bool checked_; | |
| 112 base::string16 tooltip_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); | |
| 115 }; | |
| 116 | |
| 117 } // namespace ash | |
| 118 | |
| 119 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | |
| OLD | NEW |