OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h" | 5 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h" |
6 | 6 |
7 #include "core/InputTypeNames.h" | 7 #include "core/InputTypeNames.h" |
8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
9 #include "core/frame/LocalFrameClient.h" | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
Looks like you don't need this include anymore.
Khushal
2017/08/16 19:01:23
Done.
| |
9 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
10 #include "core/html/HTMLAnchorElement.h" | 11 #include "core/html/HTMLAnchorElement.h" |
11 #include "core/html/HTMLMediaElement.h" | 12 #include "core/html/HTMLMediaElement.h" |
12 #include "core/html/media/HTMLMediaElementControlsList.h" | 13 #include "core/html/media/HTMLMediaElementControlsList.h" |
13 #include "core/html/media/HTMLMediaSource.h" | 14 #include "core/html/media/HTMLMediaSource.h" |
14 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
15 #include "modules/media_controls/MediaControlsImpl.h" | 16 #include "modules/media_controls/MediaControlsImpl.h" |
17 #include "modules/media_controls/MediaDownloadInProductHelpManager.h" | |
18 #include "platform/wtf/Functional.h" | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
Do you still need Functional.h?
Khushal
2017/08/16 19:01:22
Nope.
| |
16 #include "public/platform/Platform.h" | 19 #include "public/platform/Platform.h" |
17 | 20 |
18 namespace blink { | 21 namespace blink { |
19 | 22 |
20 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( | 23 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( |
21 MediaControlsImpl& media_controls) | 24 MediaControlsImpl& media_controls) |
22 : MediaControlInputElement(media_controls, kMediaDownloadButton) { | 25 : MediaControlInputElement(media_controls, kMediaDownloadButton) { |
23 EnsureUserAgentShadowRoot(); | 26 EnsureUserAgentShadowRoot(); |
24 setType(InputTypeNames::button); | 27 setType(InputTypeNames::button); |
25 SetShadowPseudoId(AtomicString("-internal-media-controls-download-button")); | 28 SetShadowPseudoId(AtomicString("-internal-media-controls-download-button")); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 89 |
87 DEFINE_TRACE(MediaControlDownloadButtonElement) { | 90 DEFINE_TRACE(MediaControlDownloadButtonElement) { |
88 visitor->Trace(anchor_); | 91 visitor->Trace(anchor_); |
89 MediaControlInputElement::Trace(visitor); | 92 MediaControlInputElement::Trace(visitor); |
90 } | 93 } |
91 | 94 |
92 const char* MediaControlDownloadButtonElement::GetNameForHistograms() const { | 95 const char* MediaControlDownloadButtonElement::GetNameForHistograms() const { |
93 return IsOverflowElement() ? "DownloadOverflowButton" : "DownloadButton"; | 96 return IsOverflowElement() ? "DownloadOverflowButton" : "DownloadButton"; |
94 } | 97 } |
95 | 98 |
99 void MediaControlDownloadButtonElement::UpdateShownState() { | |
100 MediaControlInputElement::UpdateShownState(); | |
101 | |
102 auto* iph_manager = static_cast<MediaControlsImpl&>(GetMediaControls()) | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
You shouldn't have to static_cast anymore. Also, d
Khushal
2017/08/16 19:01:22
That's great. Remove the auto. I had it earlier be
| |
103 .DownloadInProductHelp(); | |
104 if (iph_manager) | |
105 iph_manager->SetDownloadButtonState(IsWanted() && DoesFit()); | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
Maybe you should call this `SetDownloadButtonVisib
Khushal
2017/08/16 19:01:23
Done.
| |
106 } | |
107 | |
96 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { | 108 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { |
97 const KURL& url = MediaElement().currentSrc(); | 109 const KURL& url = MediaElement().currentSrc(); |
98 if (event->type() == EventTypeNames::click && | 110 if (event->type() == EventTypeNames::click && |
99 !(url.IsNull() || url.IsEmpty())) { | 111 !(url.IsNull() || url.IsEmpty())) { |
100 Platform::Current()->RecordAction( | 112 Platform::Current()->RecordAction( |
101 UserMetricsAction("Media.Controls.Download")); | 113 UserMetricsAction("Media.Controls.Download")); |
102 if (!anchor_) { | 114 if (!anchor_) { |
103 HTMLAnchorElement* anchor = HTMLAnchorElement::Create(GetDocument()); | 115 HTMLAnchorElement* anchor = HTMLAnchorElement::Create(GetDocument()); |
104 anchor->setAttribute(HTMLNames::downloadAttr, ""); | 116 anchor->setAttribute(HTMLNames::downloadAttr, ""); |
105 anchor_ = anchor; | 117 anchor_ = anchor; |
106 } | 118 } |
107 anchor_->SetURL(url); | 119 anchor_->SetURL(url); |
108 anchor_->DispatchSimulatedClick(event); | 120 anchor_->DispatchSimulatedClick(event); |
109 } | 121 } |
110 MediaControlInputElement::DefaultEventHandler(event); | 122 MediaControlInputElement::DefaultEventHandler(event); |
111 } | 123 } |
112 | 124 |
113 } // namespace blink | 125 } // namespace blink |
OLD | NEW |