| 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/MediaControlMuteButtonElement.h" |
| 6 |
| 7 #include "core/InputTypeNames.h" |
| 8 #include "core/events/Event.h" |
| 9 #include "core/html/HTMLMediaElement.h" |
| 10 #include "modules/media_controls/MediaControlsImpl.h" |
| 11 #include "public/platform/Platform.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 MediaControlMuteButtonElement::MediaControlMuteButtonElement( |
| 16 MediaControlsImpl& media_controls) |
| 17 : MediaControlInputElement(media_controls, kMediaMuteButton) { |
| 18 EnsureUserAgentShadowRoot(); |
| 19 setType(InputTypeNames::button); |
| 20 SetShadowPseudoId(AtomicString("-webkit-media-controls-mute-button")); |
| 21 } |
| 22 |
| 23 bool MediaControlMuteButtonElement::WillRespondToMouseClickEvents() { |
| 24 return true; |
| 25 } |
| 26 |
| 27 void MediaControlMuteButtonElement::UpdateDisplayType() { |
| 28 // TODO(mlamouri): checking for volume == 0 because the mute button will look |
| 29 // 'muted' when the volume is 0 even if the element is not muted. This allows |
| 30 // the painting and the display type to actually match. |
| 31 SetDisplayType((MediaElement().muted() || MediaElement().volume() == 0) |
| 32 ? kMediaUnMuteButton |
| 33 : kMediaMuteButton); |
| 34 UpdateOverflowString(); |
| 35 } |
| 36 |
| 37 WebLocalizedString::Name |
| 38 MediaControlMuteButtonElement::GetOverflowStringName() { |
| 39 if (MediaElement().muted()) |
| 40 return WebLocalizedString::kOverflowMenuUnmute; |
| 41 return WebLocalizedString::kOverflowMenuMute; |
| 42 } |
| 43 |
| 44 bool MediaControlMuteButtonElement::HasOverflowButton() { |
| 45 return true; |
| 46 } |
| 47 |
| 48 void MediaControlMuteButtonElement::DefaultEventHandler(Event* event) { |
| 49 if (event->type() == EventTypeNames::click) { |
| 50 if (MediaElement().muted()) { |
| 51 Platform::Current()->RecordAction( |
| 52 UserMetricsAction("Media.Controls.Unmute")); |
| 53 } else { |
| 54 Platform::Current()->RecordAction( |
| 55 UserMetricsAction("Media.Controls.Mute")); |
| 56 } |
| 57 |
| 58 MediaElement().setMuted(!MediaElement().muted()); |
| 59 event->SetDefaultHandled(); |
| 60 } |
| 61 |
| 62 MediaControlInputElement::DefaultEventHandler(event); |
| 63 } |
| 64 |
| 65 } // namespace blink |
| OLD | NEW |