OLD | NEW |
| (Empty) |
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/macros.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/browser/ui/tabs/tab_utils.h" | |
11 #include "ui/views/controls/button/image_button.h" | |
12 #include "ui/views/view_targeter_delegate.h" | |
13 | |
14 class Tab; | |
15 | |
16 namespace gfx { | |
17 class Animation; | |
18 class AnimationDelegate; | |
19 } | |
20 | |
21 // This is an ImageButton subclass that serves as both the media indicator icon | |
22 // (audio, tab capture, etc.), and as a mute button. It is meant to only be | |
23 // used as a child view of Tab. | |
24 // | |
25 // When the indicator is transitioned to the audio playing or muting state, the | |
26 // button functionality is enabled and begins handling mouse events. Otherwise, | |
27 // this view behaves like an image and all mouse events will be handled by the | |
28 // Tab (its parent View). | |
29 class MediaIndicatorButton : public views::ImageButton, | |
30 public views::ViewTargeterDelegate { | |
31 public: | |
32 // The MediaIndicatorButton's class name. | |
33 static const char kViewClassName[]; | |
34 | |
35 explicit MediaIndicatorButton(Tab* parent_tab); | |
36 ~MediaIndicatorButton() override; | |
37 | |
38 // Returns the current TabMediaState except, while the indicator image is | |
39 // fading out, returns the prior TabMediaState. | |
40 TabMediaState showing_media_state() const { | |
41 return showing_media_state_; | |
42 } | |
43 | |
44 // Calls ResetImages(), starts fade animations, and activates/deactivates | |
45 // button functionality as appropriate. | |
46 void TransitionToMediaState(TabMediaState next_state); | |
47 | |
48 // Determines whether the MediaIndicatorButton will be clickable for toggling | |
49 // muting. This should be called whenever the active/inactive state of a tab | |
50 // has changed. Internally, TransitionToMediaState() and OnBoundsChanged() | |
51 // calls this when the TabMediaState or the bounds have changed. | |
52 void UpdateEnabledForMuteToggle(); | |
53 | |
54 // Called when the parent tab's button color changes. Determines whether | |
55 // ResetImages() needs to be called. | |
56 void OnParentTabButtonColorChanged(); | |
57 | |
58 protected: | |
59 // views::View: | |
60 const char* GetClassName() const override; | |
61 View* GetTooltipHandlerForPoint(const gfx::Point& point) override; | |
62 bool OnMousePressed(const ui::MouseEvent& event) override; | |
63 bool OnMouseDragged(const ui::MouseEvent& event) override; | |
64 void OnMouseEntered(const ui::MouseEvent& event) override; | |
65 void OnMouseMoved(const ui::MouseEvent& event) override; | |
66 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
67 void OnPaint(gfx::Canvas* canvas) override; | |
68 | |
69 // views::ViewTargeterDelegate | |
70 bool DoesIntersectRect(const View* target, | |
71 const gfx::Rect& rect) const override; | |
72 | |
73 // views::Button: | |
74 void NotifyClick(const ui::Event& event) override; | |
75 | |
76 // views::CustomButton: | |
77 bool IsTriggerableEvent(const ui::Event& event) override; | |
78 | |
79 private: | |
80 friend class MediaIndicatorButtonTest; | |
81 class FadeAnimationDelegate; | |
82 | |
83 // Returns the tab (parent view) of this MediaIndicatorButton. | |
84 Tab* GetTab() const; | |
85 | |
86 // Resets the images to display on the button to reflect |state| and the | |
87 // parent tab's button color. Should be called when either of these changes. | |
88 void ResetImages(TabMediaState state); | |
89 | |
90 Tab* const parent_tab_; | |
91 | |
92 TabMediaState media_state_; | |
93 | |
94 // Media indicator fade-in/out animation (i.e., only on show/hide, not a | |
95 // continuous animation). | |
96 scoped_ptr<gfx::AnimationDelegate> fade_animation_delegate_; | |
97 scoped_ptr<gfx::Animation> fade_animation_; | |
98 TabMediaState showing_media_state_; | |
99 | |
100 DISALLOW_COPY_AND_ASSIGN(MediaIndicatorButton); | |
101 }; | |
102 | |
103 #endif // CHROME_BROWSER_UI_VIEWS_TABS_MEDIA_INDICATOR_BUTTON_H_ | |
OLD | NEW |