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

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, 3 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_.is_bound();
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 frame->Client()->GetInterfaceProvider()->GetInterface(
68 mojo::MakeRequest(&media_in_product_help_));
69 media_in_product_help_.set_connection_error_handler(ConvertToBaseCallback(
70 WTF::Bind(&MediaDownloadInProductHelpManager::DismissInProductHelp,
71 WrapWeakPersistent(this))));
72 DCHECK(media_in_product_help_.is_bound());
73
74 // MaybeShow should always make the controls visible since we early out if
75 // CanShow is false for the controls.
76 controls_->MaybeShow();
77 media_in_product_help_->ShowInProductHelpWidget(button_rect);
78 }
79
80 void MediaDownloadInProductHelpManager::StateUpdated() {
81 if (CanShowInProductHelp())
82 MaybeDispatchDownloadInProductHelpTrigger();
83 else
84 DismissInProductHelp();
85 }
86
87 bool MediaDownloadInProductHelpManager::CanShowInProductHelp() const {
88 // In-product help should only be shown if the controls can be made visible,
89 // the download button is wanted and the video is not paused.
90 return controls_can_show_ && button_can_show_ && is_playing_;
91 }
92
93 void MediaDownloadInProductHelpManager::DismissInProductHelp() {
94 if (!media_in_product_help_.is_bound())
95 return;
96
97 media_in_product_help_.reset();
98 controls_->DidDismissDownloadInProductHelp();
99 }
100
101 DEFINE_TRACE(MediaDownloadInProductHelpManager) {
102 visitor->Trace(controls_);
103 }
104
105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698