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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_
6 #define CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_
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"
15 class AnimationDelegate
;
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.
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).
26 class MediaIndicatorButton
: public views::ImageButton
,
27 public views::ViewTargeterDelegate
{
29 // The MediaIndicatorButton's class name.
30 static const char kViewClassName
[];
32 MediaIndicatorButton();
33 ~MediaIndicatorButton() override
;
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_
;
41 // Updates ImageButton images, starts fade animations, and
42 // activates/deactivates button functionality as appropriate.
43 void TransitionToMediaState(TabMediaState next_state
);
47 const char* GetClassName() const override
;
48 View
* GetTooltipHandlerForPoint(const gfx::Point
& point
) override
;
49 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
50 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
51 void OnPaint(gfx::Canvas
* canvas
) override
;
53 // views::ViewTargeterDelegate
54 bool DoesIntersectRect(const View
* target
,
55 const gfx::Rect
& rect
) const override
;
58 void NotifyClick(const ui::Event
& event
) override
;
61 class FadeAnimationDelegate
;
63 TabMediaState media_state_
;
65 // Media indicator fade-in/out animation (i.e., only on show/hide, not a
66 // continuous animation).
67 scoped_ptr
<gfx::AnimationDelegate
> fade_animation_delegate_
;
68 scoped_ptr
<gfx::Animation
> fade_animation_
;
69 TabMediaState showing_media_state_
;
71 DISALLOW_COPY_AND_ASSIGN(MediaIndicatorButton
);
74 #endif // CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_