media_indicator_button.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2014 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 CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_
6#define CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "chrome/browser/ui/tabs/tab_utils.h"
10#include "ui/views/controls/button/image_button.h"
11#include "ui/views/view_targeter_delegate.h"
12
13namespace gfx {
14class Animation;
15class AnimationDelegate;
16}
17
18// This is an ImageButton subclass that serves as both the media indicator icon
19// (audio, tab capture, etc.), and as a mute button.  It is meant to only be
20// used as a child view of Tab.
21//
22// When the indicator is transitioned to the audio playing or muting state, the
23// button functionality is enabled and begins handling mouse events.  Otherwise,
24// this view behaves like an image and all mouse events will be handled by the
25// Tab (its parent View).
26class MediaIndicatorButton : public views::ImageButton,
27                             public views::ViewTargeterDelegate {
28 public:
29  // The MediaIndicatorButton's class name.
30  static const char kViewClassName[];
31
32  MediaIndicatorButton();
33  virtual ~MediaIndicatorButton();
34
35  // Returns the current TabMediaState except, while the indicator image is
36  // fading out, returns the prior TabMediaState.
37  TabMediaState showing_media_state() const {
38    return showing_media_state_;
39  }
40
41  // Updates ImageButton images, starts fade animations, and
42  // activates/deactivates button functionality as appropriate.
43  void TransitionToMediaState(TabMediaState next_state);
44
45 protected:
46  // views::View:
47  virtual const char* GetClassName() const OVERRIDE;
48  virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE;
49  virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
50  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
51
52  // views::ViewTargeterDelegate
53  virtual bool DoesIntersectRect(const View* target,
54                                 const gfx::Rect& rect) const OVERRIDE;
55
56  // views::Button:
57  virtual void NotifyClick(const ui::Event& event) OVERRIDE;
58
59 private:
60  class FadeAnimationDelegate;
61
62  TabMediaState media_state_;
63
64  // Media indicator fade-in/out animation (i.e., only on show/hide, not a
65  // continuous animation).
66  scoped_ptr<gfx::AnimationDelegate> fade_animation_delegate_;
67  scoped_ptr<gfx::Animation> fade_animation_;
68  TabMediaState showing_media_state_;
69
70  DISALLOW_COPY_AND_ASSIGN(MediaIndicatorButton);
71};
72
73#endif  // CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_
74