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/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/html/HTMLAnchorElement.h" | 10 #include "core/html/HTMLAnchorElement.h" |
11 #include "core/html/HTMLMediaElement.h" | 11 #include "core/html/HTMLMediaElement.h" |
12 #include "core/html/media/HTMLMediaElementControlsList.h" | 12 #include "core/html/media/HTMLMediaElementControlsList.h" |
13 #include "core/html/media/HTMLMediaSource.h" | 13 #include "core/html/media/HTMLMediaSource.h" |
14 #include "core/page/Page.h" | 14 #include "core/page/Page.h" |
15 #include "modules/media_controls/MediaControlsImpl.h" | 15 #include "modules/media_controls/MediaControlsImpl.h" |
| 16 #include "modules/media_controls/MediaDownloadInProductHelpManager.h" |
16 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
17 | 18 |
18 namespace blink { | 19 namespace blink { |
19 | 20 |
20 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( | 21 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( |
21 MediaControlsImpl& media_controls) | 22 MediaControlsImpl& media_controls) |
22 : MediaControlInputElement(media_controls, kMediaDownloadButton) { | 23 : MediaControlInputElement(media_controls, kMediaDownloadButton) { |
23 EnsureUserAgentShadowRoot(); | 24 EnsureUserAgentShadowRoot(); |
24 setType(InputTypeNames::button); | 25 setType(InputTypeNames::button); |
25 SetShadowPseudoId(AtomicString("-internal-media-controls-download-button")); | 26 SetShadowPseudoId(AtomicString("-internal-media-controls-download-button")); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 87 |
87 DEFINE_TRACE(MediaControlDownloadButtonElement) { | 88 DEFINE_TRACE(MediaControlDownloadButtonElement) { |
88 visitor->Trace(anchor_); | 89 visitor->Trace(anchor_); |
89 MediaControlInputElement::Trace(visitor); | 90 MediaControlInputElement::Trace(visitor); |
90 } | 91 } |
91 | 92 |
92 const char* MediaControlDownloadButtonElement::GetNameForHistograms() const { | 93 const char* MediaControlDownloadButtonElement::GetNameForHistograms() const { |
93 return IsOverflowElement() ? "DownloadOverflowButton" : "DownloadButton"; | 94 return IsOverflowElement() ? "DownloadOverflowButton" : "DownloadButton"; |
94 } | 95 } |
95 | 96 |
| 97 void MediaControlDownloadButtonElement::UpdateShownState() { |
| 98 MediaControlInputElement::UpdateShownState(); |
| 99 |
| 100 if (GetMediaControls().DownloadInProductHelp()) { |
| 101 GetMediaControls().DownloadInProductHelp()->SetDownloadButtonVisibility( |
| 102 IsWanted() && DoesFit()); |
| 103 } |
| 104 } |
| 105 |
96 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { | 106 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { |
97 const KURL& url = MediaElement().currentSrc(); | 107 const KURL& url = MediaElement().currentSrc(); |
98 if (event->type() == EventTypeNames::click && | 108 if (event->type() == EventTypeNames::click && |
99 !(url.IsNull() || url.IsEmpty())) { | 109 !(url.IsNull() || url.IsEmpty())) { |
100 Platform::Current()->RecordAction( | 110 Platform::Current()->RecordAction( |
101 UserMetricsAction("Media.Controls.Download")); | 111 UserMetricsAction("Media.Controls.Download")); |
102 if (!anchor_) { | 112 if (!anchor_) { |
103 HTMLAnchorElement* anchor = HTMLAnchorElement::Create(GetDocument()); | 113 HTMLAnchorElement* anchor = HTMLAnchorElement::Create(GetDocument()); |
104 anchor->setAttribute(HTMLNames::downloadAttr, ""); | 114 anchor->setAttribute(HTMLNames::downloadAttr, ""); |
105 anchor_ = anchor; | 115 anchor_ = anchor; |
106 } | 116 } |
107 anchor_->SetURL(url); | 117 anchor_->SetURL(url); |
108 anchor_->DispatchSimulatedClick(event); | 118 anchor_->DispatchSimulatedClick(event); |
109 } | 119 } |
110 MediaControlInputElement::DefaultEventHandler(event); | 120 MediaControlInputElement::DefaultEventHandler(event); |
111 } | 121 } |
112 | 122 |
113 } // namespace blink | 123 } // namespace blink |
OLD | NEW |