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

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: move IPH to MediaDownloadInProductManager 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::SetControlsState(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::SetDownloadButtonState(bool can_show) {
30 if (button_can_show_ == can_show)
31 return;
32
33 button_can_show_ = can_show;
34 StateUpdated();
35 }
36
37 void MediaDownloadInProductHelpManager::SetPlayState(bool is_playing) {
38 if (is_playing_ == is_playing)
39 return;
40
41 is_playing_ = is_playing;
42 StateUpdated();
43 }
44
45 bool MediaDownloadInProductHelpManager::IsShowingInProductHelp() const {
46 return !!media_in_product_help_;
47 }
48
49 void MediaDownloadInProductHelpManager::
50 MaybeDispatchDownloadInProductHelpTrigger() {
51 // Only show in-product-help once for an element.
52 if (media_download_in_product_trigger_observed_)
53 return;
54
55 auto* frame = controls_->GetDocument().GetFrame();
56 if (!frame)
57 return;
58
59 // If the button is not in the viewport, don't show the in-product-help.
60 IntRect button_rect =
61 controls_->DownloadButton().VisibleBoundsInVisualViewport();
62 if (button_rect.IsEmpty())
mlamouri (slow - plz ping) 2017/08/16 13:09:30 What if it is partially hidden?
Khushal 2017/08/16 19:01:22 That's a good point. I could look at button size a
63 return;
64
65 media_download_in_product_trigger_observed_ = true;
66 media_in_product_help_ =
67 WTF::MakeUnique<mojom::blink::MediaDownloadInProductHelpPtr>();
68 frame->Client()->GetInterfaceProvider()->GetInterface(
69 mojo::MakeRequest(media_in_product_help_.get()));
70 media_in_product_help_->set_connection_error_handler(ConvertToBaseCallback(
71 WTF::Bind(&MediaDownloadInProductHelpManager::DismissInProductHelp,
72 WrapWeakPersistent(this))));
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 // If showing the controls is disabled, we can't make them visible to show the
89 // in-product-help.
90 if (!controls_can_show_)
91 return false;
92
93 // If the download option is not available for this video, no need to show
94 // anything.
95 if (!button_can_show_)
96 return false;
97
98 // Restrict showing in-product-help to when the video is playing.
99 if (!is_playing_)
100 return false;
mlamouri (slow - plz ping) 2017/08/16 13:09:30 You might want to merge this into one `return cont
Khushal 2017/08/16 19:01:22 Done.
101
102 return true;
103 }
104
105 void MediaDownloadInProductHelpManager::DismissInProductHelp() {
106 if (!media_in_product_help_)
107 return;
108
109 media_in_product_help_.reset();
110 controls_->DidDismissDownloadInProductHelp();
111 }
112
113 DEFINE_TRACE(MediaDownloadInProductHelpManager) {
114 visitor->Trace(controls_);
115 }
116
117 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698