Chromium Code Reviews| 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/html/shadow/MediaRemotingElements.h" | |
| 6 | |
| 7 #include "core/InputTypeNames.h" | |
| 8 #include "core/dom/ClientRect.h" | |
| 9 #include "core/dom/Text.h" | |
| 10 #include "core/dom/shadow/ShadowRoot.h" | |
| 11 #include "core/events/MouseEvent.h" | |
| 12 #include "core/html/HTMLVideoElement.h" | |
| 13 #include "core/input/EventHandler.h" | |
| 14 #include "platform/text/PlatformLocale.h" | |
| 15 #include "public/platform/Platform.h" | |
| 16 #include "public/platform/WebLocalizedString.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 using namespace HTMLNames; | |
| 21 | |
| 22 class MediaRemotingDisableButtonElement::MouseEventsListener final | |
| 23 : public EventListener { | |
| 24 public: | |
| 25 explicit MouseEventsListener(MediaRemotingDisableButtonElement& element) | |
| 26 : EventListener(CPPEventListenerType), m_element(element) {} | |
| 27 | |
| 28 bool operator==(const EventListener& other) const override { | |
| 29 return this == &other; | |
| 30 } | |
| 31 | |
| 32 void trace(blink::Visitor* visitor) { | |
| 33 visitor->trace(m_element); | |
| 34 EventListener::trace(visitor); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 void handleEvent(ExecutionContext* context, Event* event) override { | |
| 39 DCHECK(event->type() == EventTypeNames::click); | |
| 40 | |
| 41 MouseEvent* mouseEvent = toMouseEvent(event); | |
| 42 ClientRect* clientRect = m_element->getBoundingClientRect(); | |
| 43 const double x = mouseEvent->x(); | |
| 44 const double y = mouseEvent->y(); | |
| 45 if (x < clientRect->left() || x > clientRect->right() || | |
| 46 y < clientRect->top() || y > clientRect->bottom()) | |
| 47 return; | |
| 48 | |
| 49 m_element->videoElement().disableMediaRemoting(); | |
| 50 event->setDefaultHandled(); | |
| 51 event->stopPropagation(); | |
| 52 m_element->document().removeEventListener(EventTypeNames::click, this, | |
| 53 true); | |
| 54 } | |
| 55 | |
| 56 Member<MediaRemotingDisableButtonElement> m_element; | |
| 57 }; | |
| 58 | |
| 59 MediaRemotingDisableButtonElement::MediaRemotingDisableButtonElement( | |
| 60 MediaRemotingInterstitialElements& interstitialElements) | |
| 61 : HTMLInputElement(interstitialElements.document(), false), | |
| 62 m_interstitialElements(interstitialElements) { | |
| 63 m_listener = new MouseEventsListener(*this); | |
| 64 ensureUserAgentShadowRoot(); | |
| 65 setType(InputTypeNames::text); | |
| 66 setValue(interstitialElements.videoElement().locale().queryString( | |
| 67 WebLocalizedString::MediaRemotingDisableText)); | |
| 68 setShadowPseudoId(AtomicString("-internal-media-remoting-disable-button")); | |
| 69 } | |
| 70 | |
| 71 void MediaRemotingDisableButtonElement::onShown() { | |
| 72 document().addEventListener(EventTypeNames::click, m_listener, true); | |
|
mlamouri (slow - plz ping)
2017/04/07 13:18:34
Can't you use `defaultEventHandler()` from HTMLInp
xjz
2017/04/07 23:07:01
Using 'defaultEventHandler()' does not work for we
mlamouri (slow - plz ping)
2017/04/10 13:44:22
I agree that because the event is only there when
xjz
2017/04/11 04:29:44
I did try preDispatchEventHandler and it didn't wo
| |
| 73 } | |
| 74 | |
| 75 void MediaRemotingDisableButtonElement::onHidden() { | |
| 76 document().removeEventListener(EventTypeNames::click, m_listener, true); | |
| 77 } | |
| 78 | |
| 79 DEFINE_TRACE(MediaRemotingDisableButtonElement) { | |
| 80 visitor->trace(m_interstitialElements); | |
| 81 visitor->trace(m_listener); | |
| 82 HTMLInputElement::trace(visitor); | |
| 83 } | |
| 84 | |
| 85 // ---------------------------- | |
| 86 | |
| 87 MediaRemotingCastIconElement::MediaRemotingCastIconElement( | |
| 88 MediaRemotingInterstitialElements& remotingInterstitial) | |
| 89 : HTMLInputElement(remotingInterstitial.document(), false) { | |
| 90 ensureUserAgentShadowRoot(); | |
| 91 setType(InputTypeNames::button); | |
| 92 setShadowPseudoId(AtomicString("-internal-media-remoting-cast-icon")); | |
| 93 } | |
| 94 | |
| 95 // ---------------------------- | |
| 96 | |
| 97 MediaRemotingBackgroundImageElement::MediaRemotingBackgroundImageElement( | |
| 98 MediaRemotingInterstitial& remotingInterstitial) | |
| 99 : HTMLInputElement(remotingInterstitial.document(), false), | |
| 100 m_interstitial(remotingInterstitial) { | |
| 101 ensureUserAgentShadowRoot(); | |
| 102 setType(InputTypeNames::image); | |
| 103 setShadowPseudoId(AtomicString("-internal-media-remoting-background-image")); | |
| 104 const AtomicString& posterUrl = | |
| 105 m_interstitial->videoElement().getAttribute(posterAttr); | |
| 106 if (posterUrl.isEmpty()) | |
| 107 hide(); | |
| 108 else | |
| 109 setAttribute(srcAttr, posterUrl); | |
|
mlamouri (slow - plz ping)
2017/04/07 13:18:35
Stupid question but would it work to change HTMLVi
xjz
2017/04/07 23:07:01
Yes, we can use this approach to show original pos
| |
| 110 } | |
| 111 | |
| 112 void MediaRemotingBackgroundImageElement::show() { | |
| 113 removeInlineStyleProperty(CSSPropertyDisplay); | |
| 114 } | |
| 115 | |
| 116 void MediaRemotingBackgroundImageElement::hide() { | |
| 117 setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | |
| 118 } | |
| 119 | |
| 120 void MediaRemotingBackgroundImageElement::onPosterImageChanged() { | |
| 121 const AtomicString& posterUrl = | |
| 122 m_interstitial->videoElement().getAttribute(posterAttr); | |
| 123 if (posterUrl.isEmpty()) { | |
| 124 hide(); | |
| 125 } else { | |
| 126 setAttribute(srcAttr, posterUrl); | |
| 127 if (m_interstitial->shouldShow()) { | |
| 128 hide(); | |
| 129 show(); | |
| 130 } | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 DEFINE_TRACE(MediaRemotingBackgroundImageElement) { | |
| 135 visitor->trace(m_interstitial); | |
| 136 HTMLInputElement::trace(visitor); | |
| 137 } | |
| 138 | |
| 139 } // namespace blink | |
| OLD | NEW |