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

Side by Side Diff: third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.cpp

Issue 2813103006: Media Controls: move last 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 unified diff | Download patch
OLDNEW
(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/MediaControlCastButtonElement.h"
6
7 #include "core/InputTypeNames.h"
8 #include "core/dom/ClientRect.h"
9 #include "core/events/Event.h"
10 #include "core/html/HTMLMediaElement.h"
11 #include "modules/media_controls/MediaControlsImpl.h"
12 #include "modules/media_controls/elements/MediaControlElementsHelper.h"
13 #include "public/platform/Platform.h"
14
15 namespace blink {
16
17 namespace {
18
19 Element* ElementFromCenter(Element& element) {
20 ClientRect* client_rect = element.getBoundingClientRect();
21 int center_x =
22 static_cast<int>((client_rect->left() + client_rect->right()) / 2);
23 int center_y =
24 static_cast<int>((client_rect->top() + client_rect->bottom()) / 2);
25
26 return element.GetDocument().ElementFromPoint(center_x, center_y);
27 }
28
29 } // anonymous namespace
30
31 MediaControlCastButtonElement::MediaControlCastButtonElement(
32 MediaControlsImpl& media_controls,
33 bool is_overlay_button)
34 : MediaControlInputElement(media_controls, kMediaCastOnButton),
35 is_overlay_button_(is_overlay_button) {
36 EnsureUserAgentShadowRoot();
37 SetShadowPseudoId(is_overlay_button
38 ? "-internal-media-controls-overlay-cast-button"
39 : "-internal-media-controls-cast-button");
40 setType(InputTypeNames::button);
41
42 if (is_overlay_button_)
43 RecordMetrics(CastOverlayMetrics::kCreated);
44 SetIsPlayingRemotely(false);
45 }
46
47 void MediaControlCastButtonElement::TryShowOverlay() {
48 DCHECK(is_overlay_button_);
49
50 SetIsWanted(true);
51 if (ElementFromCenter(*this) != &MediaElement()) {
52 SetIsWanted(false);
53 return;
54 }
55
56 DCHECK(IsWanted());
57 if (!show_use_counted_) {
58 show_use_counted_ = true;
59 RecordMetrics(CastOverlayMetrics::kShown);
60 }
61 }
62
63 void MediaControlCastButtonElement::SetIsPlayingRemotely(
64 bool is_playing_remotely) {
65 if (is_playing_remotely) {
66 if (is_overlay_button_) {
67 SetDisplayType(kMediaOverlayCastOnButton);
68 } else {
69 SetDisplayType(kMediaCastOnButton);
70 }
71 } else {
72 if (is_overlay_button_) {
73 SetDisplayType(kMediaOverlayCastOffButton);
74 } else {
75 SetDisplayType(kMediaCastOffButton);
76 }
77 }
78 UpdateOverflowString();
79 }
80
81 bool MediaControlCastButtonElement::WillRespondToMouseClickEvents() {
82 return true;
83 }
84
85 WebLocalizedString::Name
86 MediaControlCastButtonElement::GetOverflowStringName() {
87 if (MediaElement().IsPlayingRemotely())
88 return WebLocalizedString::kOverflowMenuStopCast;
89 return WebLocalizedString::kOverflowMenuCast;
90 }
91
92 bool MediaControlCastButtonElement::HasOverflowButton() {
93 return true;
94 }
95
96 void MediaControlCastButtonElement::DefaultEventHandler(Event* event) {
97 if (event->type() == EventTypeNames::click) {
98 if (is_overlay_button_) {
99 Platform::Current()->RecordAction(
100 UserMetricsAction("Media.Controls.CastOverlay"));
101 } else {
102 Platform::Current()->RecordAction(
103 UserMetricsAction("Media.Controls.Cast"));
104 }
105
106 if (is_overlay_button_ && !click_use_counted_) {
107 click_use_counted_ = true;
108 RecordMetrics(CastOverlayMetrics::kClicked);
109 }
110 if (MediaElement().IsPlayingRemotely()) {
111 MediaElement().RequestRemotePlaybackControl();
112 } else {
113 MediaElement().RequestRemotePlayback();
114 }
115 }
116 MediaControlInputElement::DefaultEventHandler(event);
117 }
118
119 bool MediaControlCastButtonElement::KeepEventInNode(Event* event) {
120 return MediaControlElementsHelper::IsUserInteractionEvent(event);
121 }
122
123 void MediaControlCastButtonElement::RecordMetrics(CastOverlayMetrics metric) {
124 DCHECK(is_overlay_button_);
125 DEFINE_STATIC_LOCAL(
126 EnumerationHistogram, overlay_histogram,
127 ("Cast.Sender.Overlay", static_cast<int>(CastOverlayMetrics::kCount)));
128 overlay_histogram.Count(static_cast<int>(metric));
129 }
130
131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698