1 // Copyright 2020 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 ASH_SYSTEM_MEDIA_UNIFIED_MEDIA_CONTROLS_VIEW_H_ 6 #define ASH_SYSTEM_MEDIA_UNIFIED_MEDIA_CONTROLS_VIEW_H_ 7 8 #include "ash/ash_export.h" 9 #include "base/containers/flat_set.h" 10 #include "base/optional.h" 11 #include "services/media_session/public/mojom/media_session.mojom.h" 12 #include "ui/views/controls/button/button.h" 13 #include "ui/views/controls/button/image_button.h" 14 15 namespace gfx { 16 class ImageSkia; 17 } // namespace gfx 18 19 namespace views { 20 class ImageView; 21 class Label; 22 } // namespace views 23 24 namespace ash { 25 26 class UnifiedMediaControlsController; 27 28 // Media controls view displayed in quick settings. 29 class ASH_EXPORT UnifiedMediaControlsView : public views::Button { 30 public: 31 explicit UnifiedMediaControlsView(UnifiedMediaControlsController* controller); 32 ~UnifiedMediaControlsView() override = default; 33 34 void SetIsPlaying(bool playing); 35 void SetArtwork(base::Optional<gfx::ImageSkia> artwork); 36 void SetTitle(const base::string16& title); 37 void SetArtist(const base::string16& artist); 38 void UpdateActionButtonAvailability( 39 const base::flat_set<media_session::mojom::MediaSessionAction>& 40 enabled_actions); 41 42 // views::Button: 43 void OnThemeChanged() override; 44 45 // Show an empty state representing no media is playing. 46 void ShowEmptyState(); 47 48 // Called when receiving new media session, update controls to normal state 49 // if necessary. 50 void OnNewMediaSession(); 51 artwork_view()52 views::ImageView* artwork_view() { return artwork_view_; } 53 54 private: 55 friend class UnifiedMediaControlsControllerTest; 56 57 class MediaActionButton : public views::ImageButton { 58 public: 59 MediaActionButton(UnifiedMediaControlsController* controller, 60 media_session::mojom::MediaSessionAction action, 61 const base::string16& accessible_name); 62 ~MediaActionButton() override = default; 63 64 void SetAction(media_session::mojom::MediaSessionAction action, 65 const base::string16& accessible_name); 66 67 // views::ImageButton: 68 std::unique_ptr<views::InkDrop> CreateInkDrop() override; 69 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 70 const override; 71 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; 72 void OnThemeChanged() override; 73 74 private: 75 void UpdateVectorIcon(); 76 77 // Action that can be taken on the media through the button, it can be paly, 78 // pause or stop the media etc. See MediaSessionAction for all the actions. 79 media_session::mojom::MediaSessionAction action_; 80 }; 81 82 SkPath GetArtworkClipPath(); 83 84 UnifiedMediaControlsController* const controller_ = nullptr; 85 86 views::ImageView* artwork_view_ = nullptr; 87 views::ImageView* drop_down_icon_ = nullptr; 88 views::Label* title_label_ = nullptr; 89 views::Label* artist_label_ = nullptr; 90 MediaActionButton* play_pause_button_ = nullptr; 91 views::View* button_row_ = nullptr; 92 93 bool is_in_empty_state_ = false; 94 }; 95 96 } // namespace ash 97 98 #endif // ASH_SYSTEM_MEDIA_UNIFIED_MEDIA_CONTROLS_VIEW_H_ 99