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