| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/media_controls/elements/MediaControlPlayButtonElement.h" |
| 6 |
| 7 #include "core/InputTypeNames.h" |
| 8 #include "core/events/Event.h" |
| 9 #include "core/html/HTMLMediaElement.h" |
| 10 #include "core/html/media/HTMLMediaSource.h" |
| 11 #include "modules/media_controls/MediaControlsImpl.h" |
| 12 #include "public/platform/Platform.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 MediaControlPlayButtonElement::MediaControlPlayButtonElement( |
| 17 MediaControlsImpl& media_controls) |
| 18 : MediaControlInputElement(media_controls, kMediaPlayButton) { |
| 19 EnsureUserAgentShadowRoot(); |
| 20 setType(InputTypeNames::button); |
| 21 SetShadowPseudoId(AtomicString("-webkit-media-controls-play-button")); |
| 22 } |
| 23 |
| 24 bool MediaControlPlayButtonElement::WillRespondToMouseClickEvents() { |
| 25 return true; |
| 26 } |
| 27 |
| 28 void MediaControlPlayButtonElement::UpdateDisplayType() { |
| 29 SetDisplayType(MediaElement().paused() ? kMediaPlayButton |
| 30 : kMediaPauseButton); |
| 31 UpdateOverflowString(); |
| 32 } |
| 33 |
| 34 WebLocalizedString::Name |
| 35 MediaControlPlayButtonElement::GetOverflowStringName() { |
| 36 if (MediaElement().paused()) |
| 37 return WebLocalizedString::kOverflowMenuPlay; |
| 38 return WebLocalizedString::kOverflowMenuPause; |
| 39 } |
| 40 |
| 41 bool MediaControlPlayButtonElement::HasOverflowButton() { |
| 42 return true; |
| 43 } |
| 44 |
| 45 void MediaControlPlayButtonElement::DefaultEventHandler(Event* event) { |
| 46 if (event->type() == EventTypeNames::click) { |
| 47 if (MediaElement().paused()) { |
| 48 Platform::Current()->RecordAction( |
| 49 UserMetricsAction("Media.Controls.Play")); |
| 50 } else { |
| 51 Platform::Current()->RecordAction( |
| 52 UserMetricsAction("Media.Controls.Pause")); |
| 53 } |
| 54 |
| 55 // Allow play attempts for plain src= media to force a reload in the error |
| 56 // state. This allows potential recovery for transient network and decoder |
| 57 // resource issues. |
| 58 const String& url = MediaElement().currentSrc().GetString(); |
| 59 if (MediaElement().error() && !HTMLMediaElement::IsMediaStreamURL(url) && |
| 60 !HTMLMediaSource::Lookup(url)) |
| 61 MediaElement().load(); |
| 62 |
| 63 MediaElement().TogglePlayState(); |
| 64 UpdateDisplayType(); |
| 65 event->SetDefaultHandled(); |
| 66 } |
| 67 MediaControlInputElement::DefaultEventHandler(event); |
| 68 } |
| 69 |
| 70 } // namespace blink |
| OLD | NEW |