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

Side by Side 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 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/MediaDownloadInProductHelpManager.h"
6
7 #include "core/frame/LocalFrameClient.h"
8 #include "modules/media_controls/MediaControlsImpl.h"
9 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h"
10 #include "services/service_manager/public/cpp/interface_provider.h"
11
12 namespace blink {
13
14 MediaDownloadInProductHelpManager::MediaDownloadInProductHelpManager(
15 MediaControlsImpl& controls)
16 : controls_(controls) {}
17
18 MediaDownloadInProductHelpManager::~MediaDownloadInProductHelpManager() =
19 default;
20
21 void MediaDownloadInProductHelpManager::SetControlsVisibility(bool can_show) {
22 if (controls_can_show_ == can_show)
23 return;
24
25 controls_can_show_ = can_show;
26 StateUpdated();
27 }
28
29 void MediaDownloadInProductHelpManager::SetDownloadButtonVisibility(
30 bool can_show) {
31 if (button_can_show_ == can_show)
32 return;
33
34 button_can_show_ = can_show;
35 StateUpdated();
36 }
37
38 void MediaDownloadInProductHelpManager::SetIsPlaying(bool is_playing) {
39 if (is_playing_ == is_playing)
40 return;
41
42 is_playing_ = is_playing;
43 StateUpdated();
44 }
45
46 bool MediaDownloadInProductHelpManager::IsShowingInProductHelp() const {
47 return !!media_in_product_help_;
48 }
49
50 void MediaDownloadInProductHelpManager::
51 MaybeDispatchDownloadInProductHelpTrigger() {
52 // Only show in-product-help once for an element.
53 if (media_download_in_product_trigger_observed_)
54 return;
55
56 auto* frame = controls_->GetDocument().GetFrame();
57 if (!frame)
58 return;
59
60 // If the button is not in the viewport, don't show the in-product-help.
61 IntRect button_rect =
62 controls_->DownloadButton().VisibleBoundsInVisualViewport();
63 if (button_rect.IsEmpty())
64 return;
65
66 media_download_in_product_trigger_observed_ = true;
67 media_in_product_help_ =
68 WTF::MakeUnique<mojom::blink::MediaDownloadInProductHelpPtr>();
69 frame->Client()->GetInterfaceProvider()->GetInterface(
70 mojo::MakeRequest(media_in_product_help_.get()));
71 media_in_product_help_->set_connection_error_handler(ConvertToBaseCallback(
72 WTF::Bind(&MediaDownloadInProductHelpManager::DismissInProductHelp,
73 WrapWeakPersistent(this))));
74
75 // MaybeShow should always make the controls visible since we early out if
76 // CanShow is false for the controls.
77 controls_->MaybeShow();
78 (*media_in_product_help_)->ShowInProductHelpWidget(button_rect);
79 }
80
81 void MediaDownloadInProductHelpManager::StateUpdated() {
82 if (CanShowInProductHelp())
83 MaybeDispatchDownloadInProductHelpTrigger();
84 else
85 DismissInProductHelp();
86 }
87
88 bool MediaDownloadInProductHelpManager::CanShowInProductHelp() const {
89 // In-product help should only be shown if the controls can be made visible,
90 // the download button is wanted and the video is not paused.
91 return controls_can_show_ && button_can_show_ && is_playing_;
92 }
93
94 void MediaDownloadInProductHelpManager::DismissInProductHelp() {
95 if (!media_in_product_help_)
96 return;
97
98 media_in_product_help_.reset();
99 controls_->DidDismissDownloadInProductHelp();
100 }
101
102 DEFINE_TRACE(MediaDownloadInProductHelpManager) {
103 visitor->Trace(controls_);
104 }
105
106 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698