Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.h

Issue 2782373002: Remove MediaControls methods needed for the Cast button (Closed)
Patch Set: Unified watch availability code. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.h
diff --git a/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.h b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.h
index c640a8e01091c018eb116d0ac4552c3963fbad6b..e9f59094f3f24ca55a6f4efd09b46a4dace5aec3 100644
--- a/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.h
+++ b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.h
@@ -5,7 +5,9 @@
#ifndef MediaControlCastButtonElement_h
#define MediaControlCastButtonElement_h
+#include "core/events/EventListener.h"
#include "core/html/shadow/MediaControlElementTypes.h"
+#include "modules/remoteplayback/RemotePlayback.h"
namespace blink {
@@ -16,17 +18,19 @@ class MediaControlCastButtonElement final : public MediaControlInputElement {
public:
MediaControlCastButtonElement(MediaControlsImpl&, bool is_overlay_button);
- // This will show a cast button if it is not covered by another element.
- // This MUST be called for cast button elements that are overlay elements.
- void TryShowOverlay();
-
- void SetIsPlayingRemotely(bool);
+ // If set to true, will show the button as long as the media element can be
+ // played remotely (and the button is not covered by another element, if it's
+ // an overlay). Will hide the button and stop watching for remote playback
+ // availability if set to false.
+ void SetIsWanted(bool) override;
// MediaControlInputElement overrides.
bool WillRespondToMouseClickEvents() override;
WebLocalizedString::Name GetOverflowStringName() override;
bool HasOverflowButton() override;
+ DECLARE_VIRTUAL_TRACE();
+
private:
// This is used for UMA histogram (Cast.Sender.Overlay). New values should
// be appended only and must be added before |Count|.
@@ -37,17 +41,65 @@ class MediaControlCastButtonElement final : public MediaControlInputElement {
kCount // Keep last.
};
+ // An event listener attached to the RemotePlayback object of the media
+ // element to handle state changes and update the button look.
+ class RemotePlaybackEventListener : public EventListener {
+ public:
+ explicit RemotePlaybackEventListener(MediaControlCastButtonElement*);
+ ~RemotePlaybackEventListener() = default;
+
+ void handleEvent(ExecutionContext*, Event*) override;
+ bool operator==(const EventListener& other) const override;
+
+ DECLARE_VIRTUAL_TRACE();
+
+ private:
+ Member<MediaControlCastButtonElement> cast_button_;
+ };
+
void DefaultEventHandler(Event*) override;
bool KeepEventInNode(Event*) override;
+ // Whether the media element is being played remotely at the moment.
+ bool IsPlayingRemotely() const;
+
+ // Returns the element currently layed out under the center of the button.
+ Element* UnderlyingElement();
+
+ // Updates the way the button is displayed (connected or not, overlay or not).
+ void UpdateDisplayType();
+
+ // Shows or hides the button as specified and record metrics if needed.
+ void UpdateVisibility(bool visibility);
+
+ // Handles remote playback availability changes. Shows the button if there are
+ // remote playback devices, MediaControlsImpl wants to show the button and
+ // ShouldShow() returns true. Otherwise, hides it.
+ void OnRemotePlaybackAvailabilityChanged();
+
+ // Returns true if the button can be shown modulo the remote playback devices
+ // availability. Not const for implementation reasons.
+ bool ShouldShow();
+
void RecordMetrics(CastOverlayMetrics);
bool is_overlay_button_;
+ // Keeps track of whether the button needs to be shown from the
+ // MediaControlsImpl perspective.
+ bool is_wanted_by_controls_ = false;
+
+ // The index of the availability callback registered with |remote_playback_|
+ // or -1 if the callback is not registered.
+ int availability_callback_id_ = -1;
+
// UMA related boolean. They are used to prevent counting something twice
// for the same media element.
bool click_use_counted_ = false;
bool show_use_counted_ = false;
+
+ Member<RemotePlayback> remote_playback_;
+ Member<RemotePlaybackEventListener> remote_playback_event_listener_;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698