Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaRemotingElements.cpp

Issue 2767823002: Media Remoting: Add interstitial elements to media element shadow dom. (Closed)
Patch Set: Addressed liberato's comments. Changed to use HTMLDivElement instead of HTMLInputElement. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/dom/ClientRect.h"
8 #include "core/dom/Text.h"
9 #include "core/dom/shadow/ShadowRoot.h"
10 #include "core/events/MouseEvent.h"
11 #include "core/html/HTMLVideoElement.h"
12 #include "core/input/EventHandler.h"
13 #include "platform/text/PlatformLocale.h"
14 #include "public/platform/Platform.h"
15 #include "public/platform/WebLocalizedString.h"
16
17 namespace blink {
18
19 using namespace HTMLNames;
20
21 // ----------------------------
22
23 class MediaRemotingDisableButtonElement::MouseEventsListener final
mlamouri (slow - plz ping) 2017/04/13 17:20:51 I looked more into this. The reason why you are no
xjz 2017/04/13 19:12:11 This approach seems not work with vimeo videos. It
24 : public EventListener {
25 public:
26 explicit MouseEventsListener(MediaRemotingDisableButtonElement& element)
27 : EventListener(kCPPEventListenerType), element_(element) {}
28
29 bool operator==(const EventListener& other) const override {
30 return this == &other;
31 }
32
33 void Trace(blink::Visitor* visitor) {
34 visitor->Trace(element_);
35 EventListener::Trace(visitor);
36 }
37
38 private:
39 void handleEvent(ExecutionContext* context, Event* event) override {
40 DCHECK(event->type() == EventTypeNames::click);
mlamouri (slow - plz ping) 2017/04/13 17:20:51 DCHECK_EQ()?
xjz 2017/04/13 19:12:12 Done.
41
42 MouseEvent* mouse_event = ToMouseEvent(event);
43 ClientRect* client_rect = element_->getBoundingClientRect();
44 const double x = mouse_event->x();
45 const double y = mouse_event->y();
46 if (x < client_rect->left() || x > client_rect->right() ||
47 y < client_rect->top() || y > client_rect->bottom())
48 return;
49
50 element_->VideoElement().DisableMediaRemoting();
51 event->SetDefaultHandled();
52 event->stopPropagation();
53 element_->GetDocument().removeEventListener(EventTypeNames::click, this,
54 true);
mlamouri (slow - plz ping) 2017/04/13 17:20:51 Why call removeEventListener()? Wouldn't this be c
xjz 2017/04/13 19:12:12 Done. Removed the call.
55 }
56
57 Member<MediaRemotingDisableButtonElement> element_;
58 };
59
60 MediaRemotingDisableButtonElement::MediaRemotingDisableButtonElement(
61 MediaRemotingInterstitial& interstitial)
62 : HTMLDivElement(interstitial.GetDocument()), interstitial_(interstitial) {
63 listener_ = new MouseEventsListener(*this);
64 SetShadowPseudoId(AtomicString("-internal-media-remoting-disable-button"));
65 text_ = GetDocument().createTextNode(
66 interstitial.VideoElement().GetLocale().QueryString(
67 WebLocalizedString::kMediaRemotingDisableText));
68 AppendChild(text_);
mlamouri (slow - plz ping) 2017/04/13 17:20:51 Why not using setInnerText() and drop the Member<T
xjz 2017/04/13 19:12:11 Done.
69 }
70
71 void MediaRemotingDisableButtonElement::OnShown() {
72 GetDocument().addEventListener(EventTypeNames::click, listener_, true);
73 }
74
75 void MediaRemotingDisableButtonElement::OnHidden() {
76 GetDocument().removeEventListener(EventTypeNames::click, listener_, true);
77 }
78
79 HTMLVideoElement& MediaRemotingDisableButtonElement::VideoElement() const {
80 return interstitial_->VideoElement();
81 }
82
83 DEFINE_TRACE(MediaRemotingDisableButtonElement) {
84 visitor->Trace(interstitial_);
85 visitor->Trace(listener_);
86 visitor->Trace(text_);
87 HTMLDivElement::Trace(visitor);
88 }
89
90 // ----------------------------
91
92 MediaRemotingCastMessageElement::MediaRemotingCastMessageElement(
93 MediaRemotingInterstitial& interstitial)
94 : HTMLDivElement(interstitial.GetDocument()) {
95 SetShadowPseudoId(AtomicString("-internal-media-remoting-cast-text-message"));
96 text_ = GetDocument().createTextNode(
97 interstitial.VideoElement().GetLocale().QueryString(
98 WebLocalizedString::kMediaRemotingCastText));
99 AppendChild(text_);
mlamouri (slow - plz ping) 2017/04/13 17:20:51 Same as above.
xjz 2017/04/13 19:12:11 Done.
100 }
101
102 DEFINE_TRACE(MediaRemotingCastMessageElement) {
103 visitor->Trace(text_);
104 HTMLDivElement::Trace(visitor);
105 }
106
107 // ----------------------------
108
109 MediaRemotingCastIconElement::MediaRemotingCastIconElement(
110 MediaRemotingInterstitial& interstitial)
111 : HTMLDivElement(interstitial.GetDocument()) {
112 SetShadowPseudoId(AtomicString("-internal-media-remoting-cast-icon"));
113 }
114
115 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698