summaryrefslogtreecommitdiff
path: root/chromium/ash/system/tray/tray_item_view.h
blob: e0d8ec4d5af6c0f2ed5cc1679b0232d4b0d337e5 (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
// Copyright (c) 2012 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_TRAY_ITEM_VIEW_H_
#define ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_

#include "ash/ash_export.h"
#include "ui/base/animation/animation_delegate.h"
#include "ui/views/view.h"

namespace ui {
class SlideAnimation;
}

namespace views {
class ImageView;
class Label;
}

namespace ash {

class SystemTrayItem;

namespace internal {

// Base-class for items in the tray. It makes sure the widget is updated
// correctly when the visibility/size of the tray item changes. It also adds
// animation when showing/hiding the item in the tray.
class ASH_EXPORT TrayItemView : public views::View,
                                public ui::AnimationDelegate {
 public:
  explicit TrayItemView(SystemTrayItem* owner);
  virtual ~TrayItemView();

  static void DisableAnimationsForTest();

  // Convenience function for creating a child Label or ImageView.
  void CreateLabel();
  void CreateImageView();

  SystemTrayItem* owner() const { return owner_; }
  views::Label* label() const { return label_; }
  views::ImageView* image_view() const { return image_view_; }

  // Overridden from views::View.
  virtual void SetVisible(bool visible) OVERRIDE;
  virtual gfx::Size GetPreferredSize() OVERRIDE;
  virtual int GetHeightForWidth(int width) OVERRIDE;

 protected:
  // Makes sure the widget relayouts after the size/visibility of the view
  // changes.
  void ApplyChange();

  // This should return the desired size of the view. For most views, this
  // returns GetPreferredSize. But since this class overrides GetPreferredSize
  // for animation purposes, we allow a different way to get this size, and do
  // not allow GetPreferredSize to be overridden.
  virtual gfx::Size DesiredSize();

  // The default animation duration is 200ms. But each view can customize this.
  virtual int GetAnimationDurationMS();

 private:
  // Overridden from views::View.
  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;

  // Overridden from ui::AnimationDelegate.
  virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
  virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
  virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE;

  SystemTrayItem* owner_;
  scoped_ptr<ui::SlideAnimation> animation_;
  views::Label* label_;
  views::ImageView* image_view_;

  DISALLOW_COPY_AND_ASSIGN(TrayItemView);
};

}  // namespace internal
}  // namespace ash

#endif  // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_