OLD | NEW |
(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 "core/dom/MediaIPHManager.h" |
| 6 |
| 7 #include "core/dom/Document.h" |
| 8 #include "core/html/HTMLMediaElement.h" |
| 9 #include "platform/heap/GarbageCollected.h" |
| 10 |
| 11 namespace blink { |
| 12 // static |
| 13 MediaIPHManager* MediaIPHManager::Create( |
| 14 std::unique_ptr<WebMediaIPH> media_iph) { |
| 15 return new MediaIPHManager(std::move(media_iph)); |
| 16 } |
| 17 |
| 18 MediaIPHManager::MediaIPHManager(std::unique_ptr<WebMediaIPH> media_iph) |
| 19 : media_iph_(std::move(media_iph)) { |
| 20 media_iph_->BindToClient(this); |
| 21 } |
| 22 |
| 23 MediaIPHManager::~MediaIPHManager() = default; |
| 24 |
| 25 DEFINE_TRACE(MediaIPHManager) { |
| 26 visitor->Trace(active_element_); |
| 27 } |
| 28 |
| 29 bool MediaIPHManager::IPHTriggerObservedOnElement(HTMLMediaElement& element) { |
| 30 if (state_ != IPHState::kNotShowing) |
| 31 return false; |
| 32 |
| 33 active_element_ = &element; |
| 34 state_ = IPHState::kShowing; |
| 35 return true; |
| 36 } |
| 37 |
| 38 void MediaIPHManager::LayoutUpdated() { |
| 39 if (state_ != IPHState::kShowing) |
| 40 return; |
| 41 |
| 42 // If the element was removed or the download button was removed, hide the |
| 43 // IPH widget. |
| 44 IntRect button_rect; |
| 45 if (!active_element_ || |
| 46 !active_element_->GetMediaControls()->GetDownloadButtonRect( |
| 47 button_rect)) { |
| 48 // Request hide and wait for an ack from the browser. |
| 49 state_ = IPHState::kHideRequested; |
| 50 media_iph_->HideMediaDownloadIPH(); |
| 51 return; |
| 52 } |
| 53 |
| 54 media_iph_->ShowMediaDownloadIPH(button_rect); |
| 55 } |
| 56 |
| 57 void MediaIPHManager::DidHideMediaIPHWidget() { |
| 58 if (state_ == IPHState::kNotShowing) |
| 59 return; |
| 60 |
| 61 state_ = IPHState::kNotShowing; |
| 62 if (active_element_) |
| 63 active_element_->GetMediaControls()->IPHDisabled(); |
| 64 active_element_ = nullptr; |
| 65 } |
| 66 |
| 67 } // namespace blink |
OLD | NEW |