OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 MediaControlCastButtonElement_h | 5 #ifndef MediaControlCastButtonElement_h |
6 #define MediaControlCastButtonElement_h | 6 #define MediaControlCastButtonElement_h |
7 | 7 |
| 8 #include "core/events/EventListener.h" |
8 #include "core/html/shadow/MediaControlElementTypes.h" | 9 #include "core/html/shadow/MediaControlElementTypes.h" |
| 10 #include "modules/remoteplayback/RemotePlayback.h" |
9 | 11 |
10 namespace blink { | 12 namespace blink { |
11 | 13 |
12 class Event; | 14 class Event; |
13 class MediaControlsImpl; | 15 class MediaControlsImpl; |
14 | 16 |
15 class MediaControlCastButtonElement final : public MediaControlInputElement { | 17 class MediaControlCastButtonElement final : public MediaControlInputElement { |
16 public: | 18 public: |
17 MediaControlCastButtonElement(MediaControlsImpl&, bool is_overlay_button); | 19 MediaControlCastButtonElement(MediaControlsImpl&, bool is_overlay_button); |
18 | 20 |
19 // This will show a cast button if it is not covered by another element. | 21 // If set to true, will show the button as long as the media element can be |
20 // This MUST be called for cast button elements that are overlay elements. | 22 // played remotely (and the button is not covered by another element, if it's |
21 void TryShowOverlay(); | 23 // an overlay). Will hide the button and stop watching for remote playback |
22 | 24 // availability if set to false. |
23 void SetIsPlayingRemotely(bool); | 25 void SetIsWanted(bool) override; |
24 | 26 |
25 // MediaControlInputElement overrides. | 27 // MediaControlInputElement overrides. |
26 bool WillRespondToMouseClickEvents() override; | 28 bool WillRespondToMouseClickEvents() override; |
27 WebLocalizedString::Name GetOverflowStringName() override; | 29 WebLocalizedString::Name GetOverflowStringName() override; |
28 bool HasOverflowButton() override; | 30 bool HasOverflowButton() override; |
29 | 31 |
| 32 DECLARE_VIRTUAL_TRACE(); |
| 33 |
30 private: | 34 private: |
31 // This is used for UMA histogram (Cast.Sender.Overlay). New values should | 35 // This is used for UMA histogram (Cast.Sender.Overlay). New values should |
32 // be appended only and must be added before |Count|. | 36 // be appended only and must be added before |Count|. |
33 enum class CastOverlayMetrics { | 37 enum class CastOverlayMetrics { |
34 kCreated = 0, | 38 kCreated = 0, |
35 kShown, | 39 kShown, |
36 kClicked, | 40 kClicked, |
37 kCount // Keep last. | 41 kCount // Keep last. |
38 }; | 42 }; |
39 | 43 |
| 44 // An event listener attached to the RemotePlayback object of the media |
| 45 // element to handle state changes and update the button look. |
| 46 class RemotePlaybackEventListener : public EventListener { |
| 47 public: |
| 48 explicit RemotePlaybackEventListener(MediaControlCastButtonElement*); |
| 49 ~RemotePlaybackEventListener() = default; |
| 50 |
| 51 void handleEvent(ExecutionContext*, Event*) override; |
| 52 bool operator==(const EventListener& other) const override; |
| 53 |
| 54 DECLARE_VIRTUAL_TRACE(); |
| 55 |
| 56 private: |
| 57 Member<MediaControlCastButtonElement> cast_button_; |
| 58 }; |
| 59 |
40 void DefaultEventHandler(Event*) override; | 60 void DefaultEventHandler(Event*) override; |
41 bool KeepEventInNode(Event*) override; | 61 bool KeepEventInNode(Event*) override; |
42 | 62 |
| 63 // Whether the media element is being played remotely at the moment. |
| 64 bool IsPlayingRemotely() const; |
| 65 |
| 66 // Updates the way the button is displayed (connected or not, overlay or not). |
| 67 void UpdateDisplayType(); |
| 68 |
| 69 // Shows the button when all the conditions are met: |
| 70 // - the MediaControlsImpl wants the button to be shown; |
| 71 // - there're available remote playback devices; |
| 72 // - the element is allowed to play remotely; |
| 73 // - the button will NOT be obscured by another element (overlay). |
| 74 void UpdateVisibility(); |
| 75 |
| 76 // Returns true if the button can be shown modulo the remote playback devices |
| 77 // availability. Not const for implementation reasons. |
| 78 bool ShouldShow(); |
| 79 |
43 void RecordMetrics(CastOverlayMetrics); | 80 void RecordMetrics(CastOverlayMetrics); |
44 | 81 |
45 bool is_overlay_button_; | 82 bool is_overlay_button_; |
46 | 83 |
| 84 // Keeps track of whether the button needs to be shown from the |
| 85 // MediaControlsImpl perspective. |
| 86 bool is_wanted_by_controls_ = false; |
| 87 |
| 88 // The index of the availability callback registered with |remote_playback_| |
| 89 // or -1 if the callback is not registered. |
| 90 int availability_callback_id_ = -1; |
| 91 |
47 // UMA related boolean. They are used to prevent counting something twice | 92 // UMA related boolean. They are used to prevent counting something twice |
48 // for the same media element. | 93 // for the same media element. |
49 bool click_use_counted_ = false; | 94 bool click_use_counted_ = false; |
50 bool show_use_counted_ = false; | 95 bool show_use_counted_ = false; |
| 96 |
| 97 Member<RemotePlayback> remote_playback_; |
| 98 Member<RemotePlaybackEventListener> remote_playback_event_listener_; |
51 }; | 99 }; |
52 | 100 |
53 } // namespace blink | 101 } // namespace blink |
54 | 102 |
55 #endif // MediaControlCastButtonElement_h | 103 #endif // MediaControlCastButtonElement_h |
OLD | NEW |