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); | |
mlamouri (slow - plz ping)
2017/04/10 13:44:22
Why text instead of button?
xjz
2017/04/11 04:29:44
I did try button type at first, but the css didn't
xjz
2017/04/13 00:08:48
After a chat with miu@, we decide to use a div ele
| |
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); | |
73 } | |
74 | |
75 void MediaRemotingDisableButtonElement::onHidden() { | |
76 document().removeEventListener(EventTypeNames::click, m_listener, true); | |
77 } | |
78 | |
79 HTMLVideoElement& MediaRemotingDisableButtonElement::videoElement() const { | |
80 return m_interstitialElements->videoElement(); | |
81 } | |
82 | |
83 DEFINE_TRACE(MediaRemotingDisableButtonElement) { | |
84 visitor->trace(m_interstitialElements); | |
85 visitor->trace(m_listener); | |
86 HTMLInputElement::trace(visitor); | |
87 } | |
88 | |
89 // ---------------------------- | |
90 | |
91 MediaRemotingCastIconElement::MediaRemotingCastIconElement( | |
92 MediaRemotingInterstitialElements& remotingInterstitial) | |
93 : HTMLInputElement(remotingInterstitial.document(), false) { | |
94 ensureUserAgentShadowRoot(); | |
95 setType(InputTypeNames::button); | |
96 setShadowPseudoId(AtomicString("-internal-media-remoting-cast-icon")); | |
97 } | |
98 | |
99 // ---------------------------- | |
100 | |
101 MediaRemotingBackgroundImageElement::MediaRemotingBackgroundImageElement( | |
102 MediaRemotingInterstitial& remotingInterstitial) | |
103 : HTMLInputElement(remotingInterstitial.document(), false), | |
104 m_interstitial(remotingInterstitial) { | |
105 ensureUserAgentShadowRoot(); | |
106 setType(InputTypeNames::image); | |
107 setShadowPseudoId(AtomicString("-internal-media-remoting-background-image")); | |
108 const AtomicString& posterUrl = | |
109 m_interstitial->videoElement().getAttribute(posterAttr); | |
110 if (posterUrl.isEmpty()) | |
111 hide(); | |
112 else | |
113 setAttribute(srcAttr, posterUrl); | |
114 } | |
115 | |
116 void MediaRemotingBackgroundImageElement::show() { | |
117 removeInlineStyleProperty(CSSPropertyDisplay); | |
118 } | |
119 | |
120 void MediaRemotingBackgroundImageElement::hide() { | |
121 setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | |
122 } | |
123 | |
124 void MediaRemotingBackgroundImageElement::onPosterImageChanged() { | |
125 const AtomicString& posterUrl = | |
126 m_interstitial->videoElement().getAttribute(posterAttr); | |
127 if (posterUrl.isEmpty()) { | |
128 hide(); | |
129 } else { | |
130 setAttribute(srcAttr, posterUrl); | |
131 if (m_interstitial->shouldShow()) { | |
132 hide(); | |
133 show(); | |
mlamouri (slow - plz ping)
2017/04/10 13:44:22
Did you mean to just call show()?
Though, it soun
xjz
2017/04/11 04:29:44
Removed. Thanks! :)
| |
134 } | |
135 } | |
136 } | |
137 | |
138 DEFINE_TRACE(MediaRemotingBackgroundImageElement) { | |
139 visitor->trace(m_interstitial); | |
140 HTMLInputElement::trace(visitor); | |
141 } | |
142 | |
143 } // namespace blink | |
OLD | NEW |