OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/media_controls/elements/MediaControlCastButtonElement.h" | 5 #include "modules/media_controls/elements/MediaControlCastButtonElement.h" |
6 | 6 |
7 #include "core/InputTypeNames.h" | 7 #include "core/InputTypeNames.h" |
8 #include "core/dom/ClientRect.h" | 8 #include "core/dom/ClientRect.h" |
9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
10 #include "core/html/HTMLMediaElement.h" | 10 #include "core/html/HTMLMediaElement.h" |
11 #include "modules/media_controls/MediaControlsImpl.h" | 11 #include "modules/media_controls/MediaControlsImpl.h" |
12 #include "modules/media_controls/elements/MediaControlElementsHelper.h" | 12 #include "modules/media_controls/elements/MediaControlElementsHelper.h" |
| 13 #include "modules/remoteplayback/HTMLMediaElementRemotePlayback.h" |
| 14 #include "modules/remoteplayback/RemotePlayback.h" |
13 #include "platform/Histogram.h" | 15 #include "platform/Histogram.h" |
14 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
15 | 17 |
16 namespace blink { | 18 namespace blink { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 Element* ElementFromCenter(Element& element) { | 22 Element* ElementFromCenter(Element& element) { |
21 ClientRect* client_rect = element.getBoundingClientRect(); | 23 ClientRect* client_rect = element.getBoundingClientRect(); |
22 int center_x = | 24 int center_x = |
(...skipping 12 matching lines...) Expand all Loading... |
35 : MediaControlInputElement(media_controls, kMediaCastOnButton), | 37 : MediaControlInputElement(media_controls, kMediaCastOnButton), |
36 is_overlay_button_(is_overlay_button) { | 38 is_overlay_button_(is_overlay_button) { |
37 EnsureUserAgentShadowRoot(); | 39 EnsureUserAgentShadowRoot(); |
38 SetShadowPseudoId(is_overlay_button | 40 SetShadowPseudoId(is_overlay_button |
39 ? "-internal-media-controls-overlay-cast-button" | 41 ? "-internal-media-controls-overlay-cast-button" |
40 : "-internal-media-controls-cast-button"); | 42 : "-internal-media-controls-cast-button"); |
41 setType(InputTypeNames::button); | 43 setType(InputTypeNames::button); |
42 | 44 |
43 if (is_overlay_button_) | 45 if (is_overlay_button_) |
44 RecordMetrics(CastOverlayMetrics::kCreated); | 46 RecordMetrics(CastOverlayMetrics::kCreated); |
45 SetIsPlayingRemotely(false); | 47 UpdateDisplayType(); |
46 } | 48 } |
47 | 49 |
48 void MediaControlCastButtonElement::TryShowOverlay() { | 50 void MediaControlCastButtonElement::TryShowOverlay() { |
49 DCHECK(is_overlay_button_); | 51 DCHECK(is_overlay_button_); |
50 | 52 |
51 SetIsWanted(true); | 53 SetIsWanted(true); |
52 if (ElementFromCenter(*this) != &MediaElement()) { | 54 if (ElementFromCenter(*this) != &MediaElement()) { |
53 SetIsWanted(false); | 55 SetIsWanted(false); |
54 return; | 56 return; |
55 } | 57 } |
56 | 58 |
57 DCHECK(IsWanted()); | 59 DCHECK(IsWanted()); |
58 if (!show_use_counted_) { | 60 if (!show_use_counted_) { |
59 show_use_counted_ = true; | 61 show_use_counted_ = true; |
60 RecordMetrics(CastOverlayMetrics::kShown); | 62 RecordMetrics(CastOverlayMetrics::kShown); |
61 } | 63 } |
62 } | 64 } |
63 | 65 |
64 void MediaControlCastButtonElement::SetIsPlayingRemotely( | 66 void MediaControlCastButtonElement::UpdateDisplayType() { |
65 bool is_playing_remotely) { | 67 if (IsPlayingRemotely()) { |
66 if (is_playing_remotely) { | |
67 if (is_overlay_button_) { | 68 if (is_overlay_button_) { |
68 SetDisplayType(kMediaOverlayCastOnButton); | 69 SetDisplayType(kMediaOverlayCastOnButton); |
69 } else { | 70 } else { |
70 SetDisplayType(kMediaCastOnButton); | 71 SetDisplayType(kMediaCastOnButton); |
71 } | 72 } |
72 } else { | 73 } else { |
73 if (is_overlay_button_) { | 74 if (is_overlay_button_) { |
74 SetDisplayType(kMediaOverlayCastOffButton); | 75 SetDisplayType(kMediaOverlayCastOffButton); |
75 } else { | 76 } else { |
76 SetDisplayType(kMediaCastOffButton); | 77 SetDisplayType(kMediaCastOffButton); |
77 } | 78 } |
78 } | 79 } |
79 UpdateOverflowString(); | 80 UpdateOverflowString(); |
80 } | 81 } |
81 | 82 |
82 bool MediaControlCastButtonElement::WillRespondToMouseClickEvents() { | 83 bool MediaControlCastButtonElement::WillRespondToMouseClickEvents() { |
83 return true; | 84 return true; |
84 } | 85 } |
85 | 86 |
86 WebLocalizedString::Name | 87 WebLocalizedString::Name |
87 MediaControlCastButtonElement::GetOverflowStringName() { | 88 MediaControlCastButtonElement::GetOverflowStringName() { |
88 if (MediaElement().IsPlayingRemotely()) | 89 if (IsPlayingRemotely()) |
89 return WebLocalizedString::kOverflowMenuStopCast; | 90 return WebLocalizedString::kOverflowMenuStopCast; |
90 return WebLocalizedString::kOverflowMenuCast; | 91 return WebLocalizedString::kOverflowMenuCast; |
91 } | 92 } |
92 | 93 |
93 bool MediaControlCastButtonElement::HasOverflowButton() { | 94 bool MediaControlCastButtonElement::HasOverflowButton() { |
94 return true; | 95 return true; |
95 } | 96 } |
96 | 97 |
97 void MediaControlCastButtonElement::DefaultEventHandler(Event* event) { | 98 void MediaControlCastButtonElement::DefaultEventHandler(Event* event) { |
98 if (event->type() == EventTypeNames::click) { | 99 if (event->type() == EventTypeNames::click) { |
99 if (is_overlay_button_) { | 100 if (is_overlay_button_) { |
100 Platform::Current()->RecordAction( | 101 Platform::Current()->RecordAction( |
101 UserMetricsAction("Media.Controls.CastOverlay")); | 102 UserMetricsAction("Media.Controls.CastOverlay")); |
102 } else { | 103 } else { |
103 Platform::Current()->RecordAction( | 104 Platform::Current()->RecordAction( |
104 UserMetricsAction("Media.Controls.Cast")); | 105 UserMetricsAction("Media.Controls.Cast")); |
105 } | 106 } |
106 | 107 |
107 if (is_overlay_button_ && !click_use_counted_) { | 108 if (is_overlay_button_ && !click_use_counted_) { |
108 click_use_counted_ = true; | 109 click_use_counted_ = true; |
109 RecordMetrics(CastOverlayMetrics::kClicked); | 110 RecordMetrics(CastOverlayMetrics::kClicked); |
110 } | 111 } |
111 if (MediaElement().IsPlayingRemotely()) { | 112 RemotePlayback* remote = |
112 MediaElement().RequestRemotePlaybackControl(); | 113 HTMLMediaElementRemotePlayback::remote(MediaElement()); |
113 } else { | 114 if (remote) |
114 MediaElement().RequestRemotePlayback(); | 115 remote->PromptInternal(); |
115 } | |
116 } | 116 } |
117 MediaControlInputElement::DefaultEventHandler(event); | 117 MediaControlInputElement::DefaultEventHandler(event); |
118 } | 118 } |
119 | 119 |
120 bool MediaControlCastButtonElement::KeepEventInNode(Event* event) { | 120 bool MediaControlCastButtonElement::KeepEventInNode(Event* event) { |
121 return MediaControlElementsHelper::IsUserInteractionEvent(event); | 121 return MediaControlElementsHelper::IsUserInteractionEvent(event); |
122 } | 122 } |
123 | 123 |
124 void MediaControlCastButtonElement::RecordMetrics(CastOverlayMetrics metric) { | 124 void MediaControlCastButtonElement::RecordMetrics(CastOverlayMetrics metric) { |
125 DCHECK(is_overlay_button_); | 125 DCHECK(is_overlay_button_); |
126 DEFINE_STATIC_LOCAL( | 126 DEFINE_STATIC_LOCAL( |
127 EnumerationHistogram, overlay_histogram, | 127 EnumerationHistogram, overlay_histogram, |
128 ("Cast.Sender.Overlay", static_cast<int>(CastOverlayMetrics::kCount))); | 128 ("Cast.Sender.Overlay", static_cast<int>(CastOverlayMetrics::kCount))); |
129 overlay_histogram.Count(static_cast<int>(metric)); | 129 overlay_histogram.Count(static_cast<int>(metric)); |
130 } | 130 } |
131 | 131 |
| 132 bool MediaControlCastButtonElement::IsPlayingRemotely() const { |
| 133 RemotePlayback* remote = |
| 134 HTMLMediaElementRemotePlayback::remote(MediaElement()); |
| 135 return remote && remote->GetState() != WebRemotePlaybackState::kDisconnected; |
| 136 } |
| 137 |
132 } // namespace blink | 138 } // namespace blink |
OLD | NEW |