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

Unified Diff: third_party/WebKit/Source/modules/media_controls/MediaDownloadInProductHelpManager.cpp

Issue 2943983003: chrome/blink: Add functionality for in-product help for media elements. (Closed)
Patch Set: .. Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/media_controls/MediaDownloadInProductHelpManager.cpp
diff --git a/third_party/WebKit/Source/modules/media_controls/MediaDownloadInProductHelpManager.cpp b/third_party/WebKit/Source/modules/media_controls/MediaDownloadInProductHelpManager.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d7b2122b85703f2e23284203b40a028779008c6c
--- /dev/null
+++ b/third_party/WebKit/Source/modules/media_controls/MediaDownloadInProductHelpManager.cpp
@@ -0,0 +1,105 @@
+// 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/MediaDownloadInProductHelpManager.h"
+
+#include "core/frame/LocalFrameClient.h"
+#include "modules/media_controls/MediaControlsImpl.h"
+#include "modules/media_controls/elements/MediaControlDownloadButtonElement.h"
+#include "services/service_manager/public/cpp/interface_provider.h"
+
+namespace blink {
+
+MediaDownloadInProductHelpManager::MediaDownloadInProductHelpManager(
+ MediaControlsImpl& controls)
+ : controls_(controls) {}
+
+MediaDownloadInProductHelpManager::~MediaDownloadInProductHelpManager() =
+ default;
+
+void MediaDownloadInProductHelpManager::SetControlsVisibility(bool can_show) {
+ if (controls_can_show_ == can_show)
+ return;
+
+ controls_can_show_ = can_show;
+ StateUpdated();
+}
+
+void MediaDownloadInProductHelpManager::SetDownloadButtonVisibility(
+ bool can_show) {
+ if (button_can_show_ == can_show)
+ return;
+
+ button_can_show_ = can_show;
+ StateUpdated();
+}
+
+void MediaDownloadInProductHelpManager::SetIsPlaying(bool is_playing) {
+ if (is_playing_ == is_playing)
+ return;
+
+ is_playing_ = is_playing;
+ StateUpdated();
+}
+
+bool MediaDownloadInProductHelpManager::IsShowingInProductHelp() const {
+ return media_in_product_help_.is_bound();
+}
+
+void MediaDownloadInProductHelpManager::
+ MaybeDispatchDownloadInProductHelpTrigger() {
+ // Only show in-product-help once for an element.
+ if (media_download_in_product_trigger_observed_)
+ return;
+
+ auto* frame = controls_->GetDocument().GetFrame();
+ if (!frame)
+ return;
+
+ // If the button is not in the viewport, don't show the in-product-help.
+ IntRect button_rect =
+ controls_->DownloadButton().VisibleBoundsInVisualViewport();
+ if (button_rect.IsEmpty())
+ return;
+
+ media_download_in_product_trigger_observed_ = true;
+ frame->Client()->GetInterfaceProvider()->GetInterface(
+ mojo::MakeRequest(&media_in_product_help_));
+ media_in_product_help_.set_connection_error_handler(ConvertToBaseCallback(
+ WTF::Bind(&MediaDownloadInProductHelpManager::DismissInProductHelp,
+ WrapWeakPersistent(this))));
+ DCHECK(media_in_product_help_.is_bound());
+
+ // MaybeShow should always make the controls visible since we early out if
+ // CanShow is false for the controls.
+ controls_->MaybeShow();
+ media_in_product_help_->ShowInProductHelpWidget(button_rect);
+}
+
+void MediaDownloadInProductHelpManager::StateUpdated() {
+ if (CanShowInProductHelp())
+ MaybeDispatchDownloadInProductHelpTrigger();
+ else
+ DismissInProductHelp();
+}
+
+bool MediaDownloadInProductHelpManager::CanShowInProductHelp() const {
+ // In-product help should only be shown if the controls can be made visible,
+ // the download button is wanted and the video is not paused.
+ return controls_can_show_ && button_can_show_ && is_playing_;
+}
+
+void MediaDownloadInProductHelpManager::DismissInProductHelp() {
+ if (!media_in_product_help_.is_bound())
+ return;
+
+ media_in_product_help_.reset();
+ controls_->DidDismissDownloadInProductHelp();
+}
+
+DEFINE_TRACE(MediaDownloadInProductHelpManager) {
+ visitor->Trace(controls_);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698