15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/ash_export.h"
9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/animation_delegate.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/view.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace gfx {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SlideAnimation;
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImageView;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Label;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SystemTrayItem;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Base-class for items in the tray. It makes sure the widget is updated
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// correctly when the visibility/size of the tray item changes. It also adds
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// animation when showing/hiding the item in the tray.
27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass ASH_EXPORT TrayItemView : public views::View,
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                public gfx::AnimationDelegate {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit TrayItemView(SystemTrayItem* owner);
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~TrayItemView();
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  static void DisableAnimationsForTest();
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Convenience function for creating a child Label or ImageView.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CreateLabel();
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CreateImageView();
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SystemTrayItem* owner() const { return owner_; }
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::Label* label() const { return label_; }
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::ImageView* image_view() const { return image_view_; }
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from views::View.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetVisible(bool visible) OVERRIDE;
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual gfx::Size GetPreferredSize() const OVERRIDE;
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual int GetHeightForWidth(int width) const OVERRIDE;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Makes sure the widget relayouts after the size/visibility of the view
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // changes.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ApplyChange();
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This should return the desired size of the view. For most views, this
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returns GetPreferredSize. But since this class overrides GetPreferredSize
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for animation purposes, we allow a different way to get this size, and do
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not allow GetPreferredSize to be overridden.
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual gfx::Size DesiredSize() const;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The default animation duration is 200ms. But each view can customize this.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int GetAnimationDurationMS();
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from views::View.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Overridden from gfx::AnimationDelegate.
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SystemTrayItem* owner_;
72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<gfx::SlideAnimation> animation_;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Label* label_;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::ImageView* image_view_;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TrayItemView);
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_
82