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

Unified Diff: third_party/WebKit/Source/modules/media_controls/elements/MediaControlPlayButtonElement.cpp

Issue 2820633003: Media Controls: move simple buttons to modules/. (Closed)
Patch Set: 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/MediaControlPlayButtonElement.cpp
diff --git a/third_party/WebKit/Source/modules/media_controls/elements/MediaControlPlayButtonElement.cpp b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlPlayButtonElement.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d7e14b73202c924995d2aacbfd976a7a3b077fe0
--- /dev/null
+++ b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlPlayButtonElement.cpp
@@ -0,0 +1,70 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/media_controls/elements/MediaControlPlayButtonElement.h"
+
+#include "core/InputTypeNames.h"
+#include "core/events/Event.h"
+#include "core/html/HTMLMediaElement.h"
+#include "core/html/media/HTMLMediaSource.h"
+#include "modules/media_controls/MediaControlsImpl.h"
+#include "public/platform/Platform.h"
+
+namespace blink {
+
+MediaControlPlayButtonElement::MediaControlPlayButtonElement(
+ MediaControlsImpl& media_controls)
+ : MediaControlInputElement(media_controls, kMediaPlayButton) {
+ EnsureUserAgentShadowRoot();
+ setType(InputTypeNames::button);
+ SetShadowPseudoId(AtomicString("-webkit-media-controls-play-button"));
+}
+
+bool MediaControlPlayButtonElement::WillRespondToMouseClickEvents() {
+ return true;
+}
+
+void MediaControlPlayButtonElement::UpdateDisplayType() {
+ SetDisplayType(MediaElement().paused() ? kMediaPlayButton
+ : kMediaPauseButton);
+ UpdateOverflowString();
+}
+
+WebLocalizedString::Name
+MediaControlPlayButtonElement::GetOverflowStringName() {
+ if (MediaElement().paused())
+ return WebLocalizedString::kOverflowMenuPlay;
+ return WebLocalizedString::kOverflowMenuPause;
+}
+
+bool MediaControlPlayButtonElement::HasOverflowButton() {
+ return true;
+}
+
+void MediaControlPlayButtonElement::DefaultEventHandler(Event* event) {
+ if (event->type() == EventTypeNames::click) {
+ if (MediaElement().paused()) {
+ Platform::Current()->RecordAction(
+ UserMetricsAction("Media.Controls.Play"));
+ } else {
+ Platform::Current()->RecordAction(
+ UserMetricsAction("Media.Controls.Pause"));
+ }
+
+ // Allow play attempts for plain src= media to force a reload in the error
+ // state. This allows potential recovery for transient network and decoder
+ // resource issues.
+ const String& url = MediaElement().currentSrc().GetString();
+ if (MediaElement().error() && !HTMLMediaElement::IsMediaStreamURL(url) &&
+ !HTMLMediaSource::Lookup(url))
+ MediaElement().load();
+
+ MediaElement().TogglePlayState();
+ UpdateDisplayType();
+ event->SetDefaultHandled();
+ }
+ MediaControlInputElement::DefaultEventHandler(event);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698