summaryrefslogtreecommitdiffstats
path: root/ash/system/tray/hover_highlight_view.h
blob: 6b9d1a22a42dada37b43bc1e360a19c348de0b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
#define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_

#include "ash/system/tray/actionable_view.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/gfx/font.h"
#include "ui/gfx/text_constants.h"

namespace views {
class Label;
}

namespace ash {
class ViewClickListener;

// A view that changes background color on hover, and triggers a callback in the
// associated ViewClickListener on click. The view can also be forced to
// maintain a fixed height.
class HoverHighlightView : public ActionableView {
 public:
  explicit HoverHighlightView(ViewClickListener* listener);
  ~HoverHighlightView() override;

  // Convenience function for adding an icon and a label. This also sets the
  // accessible name.
  void AddIconAndLabel(const gfx::ImageSkia& image,
                       const base::string16& text,
                       bool highlight);

  // Convenience function for adding an icon and a label. This also sets the
  // accessible name. The icon has an indent equal to
  // kTrayPopupPaddingHorizontal.
  void AddIndentedIconAndLabel(const gfx::ImageSkia& image,
                               const base::string16& text,
                               bool highlight);

  // Convenience function for adding a label with padding on the left for a
  // blank icon.  This also sets the accessible name. Returns label after
  // parenting it.
  views::Label* AddLabel(const base::string16& text,
                         gfx::HorizontalAlignment alignment,
                         bool highlight);

  // Convenience function for adding an optional check and a label. In the
  // absence of a check, padding is added to align with checked items.
  // Returns label after parenting it.
  views::Label* AddCheckableLabel(const base::string16& text,
                                  bool highlight,
                                  bool checked);

  // Allows view to expand its height.
  // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight.
  void SetExpandable(bool expandable);

  void set_highlight_color(SkColor color) { highlight_color_ = color; }
  void set_default_color(SkColor color) { default_color_ = color; }
  void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; }
  void set_text_default_color(SkColor color) { text_default_color_ = color; }

  views::Label* text_label() { return text_label_; }

  bool hover() const { return hover_; }

 protected:
  // Overridden from views::View.
  void GetAccessibleState(ui::AXViewState* state) override;

  // Sets the highlighted color on a text label if |hover| is set.
  void SetHoverHighlight(bool hover);

 private:
  // Actually adds the icon and label but does not set the layout manager
  void DoAddIconAndLabel(const gfx::ImageSkia& image,
                         const base::string16& text,
                         bool highlight);

  // Overridden from ActionableView:
  bool PerformAction(const ui::Event& event) override;

  // Overridden from views::View.
  gfx::Size GetPreferredSize() const override;
  int GetHeightForWidth(int width) const override;
  void OnMouseEntered(const ui::MouseEvent& event) override;
  void OnMouseExited(const ui::MouseEvent& event) override;
  void OnGestureEvent(ui::GestureEvent* event) override;
  void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
  void OnEnabledChanged() override;
  void OnPaintBackground(gfx::Canvas* canvas) override;
  void OnFocus() override;

  ViewClickListener* listener_;
  views::Label* text_label_;
  SkColor highlight_color_;
  SkColor default_color_;
  SkColor text_highlight_color_;
  SkColor text_default_color_;
  bool hover_;
  bool expandable_;
  bool checkable_;
  bool checked_;

  DISALLOW_COPY_AND_ASSIGN(HoverHighlightView);
};

}  // namespace ash

#endif  // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_