| Index: third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.cpp
|
| diff --git a/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.cpp b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2e0c50d9968e11f12b3f089532a18a3617cc402f
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlCastButtonElement.cpp
|
| @@ -0,0 +1,131 @@
|
| +// 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/MediaControlCastButtonElement.h"
|
| +
|
| +#include "core/InputTypeNames.h"
|
| +#include "core/dom/ClientRect.h"
|
| +#include "core/events/Event.h"
|
| +#include "core/html/HTMLMediaElement.h"
|
| +#include "modules/media_controls/MediaControlsImpl.h"
|
| +#include "modules/media_controls/elements/MediaControlElementsHelper.h"
|
| +#include "public/platform/Platform.h"
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {
|
| +
|
| +Element* ElementFromCenter(Element& element) {
|
| + ClientRect* client_rect = element.getBoundingClientRect();
|
| + int center_x =
|
| + static_cast<int>((client_rect->left() + client_rect->right()) / 2);
|
| + int center_y =
|
| + static_cast<int>((client_rect->top() + client_rect->bottom()) / 2);
|
| +
|
| + return element.GetDocument().ElementFromPoint(center_x, center_y);
|
| +}
|
| +
|
| +} // anonymous namespace
|
| +
|
| +MediaControlCastButtonElement::MediaControlCastButtonElement(
|
| + MediaControlsImpl& media_controls,
|
| + bool is_overlay_button)
|
| + : MediaControlInputElement(media_controls, kMediaCastOnButton),
|
| + is_overlay_button_(is_overlay_button) {
|
| + EnsureUserAgentShadowRoot();
|
| + SetShadowPseudoId(is_overlay_button
|
| + ? "-internal-media-controls-overlay-cast-button"
|
| + : "-internal-media-controls-cast-button");
|
| + setType(InputTypeNames::button);
|
| +
|
| + if (is_overlay_button_)
|
| + RecordMetrics(CastOverlayMetrics::kCreated);
|
| + SetIsPlayingRemotely(false);
|
| +}
|
| +
|
| +void MediaControlCastButtonElement::TryShowOverlay() {
|
| + DCHECK(is_overlay_button_);
|
| +
|
| + SetIsWanted(true);
|
| + if (ElementFromCenter(*this) != &MediaElement()) {
|
| + SetIsWanted(false);
|
| + return;
|
| + }
|
| +
|
| + DCHECK(IsWanted());
|
| + if (!show_use_counted_) {
|
| + show_use_counted_ = true;
|
| + RecordMetrics(CastOverlayMetrics::kShown);
|
| + }
|
| +}
|
| +
|
| +void MediaControlCastButtonElement::SetIsPlayingRemotely(
|
| + bool is_playing_remotely) {
|
| + if (is_playing_remotely) {
|
| + if (is_overlay_button_) {
|
| + SetDisplayType(kMediaOverlayCastOnButton);
|
| + } else {
|
| + SetDisplayType(kMediaCastOnButton);
|
| + }
|
| + } else {
|
| + if (is_overlay_button_) {
|
| + SetDisplayType(kMediaOverlayCastOffButton);
|
| + } else {
|
| + SetDisplayType(kMediaCastOffButton);
|
| + }
|
| + }
|
| + UpdateOverflowString();
|
| +}
|
| +
|
| +bool MediaControlCastButtonElement::WillRespondToMouseClickEvents() {
|
| + return true;
|
| +}
|
| +
|
| +WebLocalizedString::Name
|
| +MediaControlCastButtonElement::GetOverflowStringName() {
|
| + if (MediaElement().IsPlayingRemotely())
|
| + return WebLocalizedString::kOverflowMenuStopCast;
|
| + return WebLocalizedString::kOverflowMenuCast;
|
| +}
|
| +
|
| +bool MediaControlCastButtonElement::HasOverflowButton() {
|
| + return true;
|
| +}
|
| +
|
| +void MediaControlCastButtonElement::DefaultEventHandler(Event* event) {
|
| + if (event->type() == EventTypeNames::click) {
|
| + if (is_overlay_button_) {
|
| + Platform::Current()->RecordAction(
|
| + UserMetricsAction("Media.Controls.CastOverlay"));
|
| + } else {
|
| + Platform::Current()->RecordAction(
|
| + UserMetricsAction("Media.Controls.Cast"));
|
| + }
|
| +
|
| + if (is_overlay_button_ && !click_use_counted_) {
|
| + click_use_counted_ = true;
|
| + RecordMetrics(CastOverlayMetrics::kClicked);
|
| + }
|
| + if (MediaElement().IsPlayingRemotely()) {
|
| + MediaElement().RequestRemotePlaybackControl();
|
| + } else {
|
| + MediaElement().RequestRemotePlayback();
|
| + }
|
| + }
|
| + MediaControlInputElement::DefaultEventHandler(event);
|
| +}
|
| +
|
| +bool MediaControlCastButtonElement::KeepEventInNode(Event* event) {
|
| + return MediaControlElementsHelper::IsUserInteractionEvent(event);
|
| +}
|
| +
|
| +void MediaControlCastButtonElement::RecordMetrics(CastOverlayMetrics metric) {
|
| + DCHECK(is_overlay_button_);
|
| + DEFINE_STATIC_LOCAL(
|
| + EnumerationHistogram, overlay_histogram,
|
| + ("Cast.Sender.Overlay", static_cast<int>(CastOverlayMetrics::kCount)));
|
| + overlay_histogram.Count(static_cast<int>(metric));
|
| +}
|
| +
|
| +} // namespace blink
|
|
|