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

Unified Diff: Source/core/html/shadow/MediaControlElements.cpp

Issue 291163004: Implement media cast buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase to fix merge problem with TestExpectations Created 6 years, 3 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: Source/core/html/shadow/MediaControlElements.cpp
diff --git a/Source/core/html/shadow/MediaControlElements.cpp b/Source/core/html/shadow/MediaControlElements.cpp
index 9a184f89efd4b4c5a0acac0047e90323cfed540a..a9dbcc7d45e5123a8d982bfbca159f26f9936a7b 100644
--- a/Source/core/html/shadow/MediaControlElements.cpp
+++ b/Source/core/html/shadow/MediaControlElements.cpp
@@ -210,6 +210,18 @@ const AtomicString& MediaControlOverlayEnclosureElement::shadowPseudoId() const
return id;
}
+void* MediaControlOverlayEnclosureElement::preDispatchEventHandler(Event* event)
+{
+ // When the media element is clicked or touched we want to make the overlay cast button visible
+ // (if the other requirements are right) even if JavaScript is doing its own handling of the event.
+ // Doing it in preDispatchEventHandler prevents any interference from JavaScript.
+ // Note that we can't simply test for click, since JS handling of touch events can prevent their translation to click events.
+ if (event && (event->type() == EventTypeNames::click || event->type() == EventTypeNames::touchstart) && mediaElement().hasRemoteRoutes() && !mediaElement().shouldShowControls())
+ mediaControls().showOverlayCastButton();
+ return MediaControlDivElement::preDispatchEventHandler(event);
+}
+
+
// ----------------------------
MediaControlMuteButtonElement::MediaControlMuteButtonElement(MediaControls& mediaControls)
@@ -552,6 +564,50 @@ void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen)
// ----------------------------
+MediaControlCastButtonElement::MediaControlCastButtonElement(MediaControls& mediaControls, bool isOverlayButton)
+ : MediaControlInputElement(mediaControls, MediaCastOnButton), m_isOverlayButton(isOverlayButton)
+{
+}
+
+PassRefPtrWillBeRawPtr<MediaControlCastButtonElement> MediaControlCastButtonElement::create(MediaControls& mediaControls, bool isOverlayButton)
+{
+ RefPtrWillBeRawPtr<MediaControlCastButtonElement> button = adoptRefWillBeRefCountedGarbageCollected(new MediaControlCastButtonElement(mediaControls, isOverlayButton));
+ button->ensureUserAgentShadowRoot();
+ button->setType("button");
+ return button.release();
+}
+
+void MediaControlCastButtonElement::defaultEventHandler(Event* event)
+{
+ if (event->type() == EventTypeNames::click) {
+ if (mediaElement().isPlayingRemotely()) {
+ mediaElement().requestRemotePlaybackControl();
+ } else {
+ mediaElement().requestRemotePlayback();
+ }
+ }
+ HTMLInputElement::defaultEventHandler(event);
+}
+
+const AtomicString& MediaControlCastButtonElement::shadowPseudoId() const
+{
+ DEFINE_STATIC_LOCAL(AtomicString, id_nonOverlay, ("-internal-media-controls-cast-button", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(AtomicString, id_overlay, ("-internal-media-controls-overlay-cast-button", AtomicString::ConstructFromLiteral));
+ return m_isOverlayButton ? id_overlay : id_nonOverlay;
+}
+
+void MediaControlCastButtonElement::setIsPlayingRemotely(bool isPlayingRemotely)
+{
+ setDisplayType(isPlayingRemotely ? MediaCastOnButton : MediaCastOffButton);
+}
+
+bool MediaControlCastButtonElement::keepEventInNode(Event* event)
+{
+ return isUserInteractionEvent(event);
+}
+
+// ----------------------------
+
MediaControlTimeRemainingDisplayElement::MediaControlTimeRemainingDisplayElement(MediaControls& mediaControls)
: MediaControlTimeDisplayElement(mediaControls, MediaTimeRemainingDisplay)
{

Powered by Google App Engine
This is Rietveld 408576698