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

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: Rebased. 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/shadow/ShadowRoot.h"
9 #include "core/events/MouseEvent.h"
10 #include "core/html/HTMLVideoElement.h"
11 #include "core/input/EventHandler.h"
12 #include "platform/text/PlatformLocale.h"
13 #include "public/platform/WebLocalizedString.h"
14
15 namespace blink {
16
17 using namespace HTMLNames;
18
19 // ----------------------------
20
21 class MediaRemotingExitButtonElement::MouseEventsListener final
22 : public EventListener {
23 public:
24 explicit MouseEventsListener(MediaRemotingExitButtonElement& element)
25 : EventListener(kCPPEventListenerType), element_(element) {}
26
27 bool operator==(const EventListener& other) const override {
28 return this == &other;
29 }
30
31 void Trace(blink::Visitor* visitor) {
32 visitor->Trace(element_);
33 EventListener::Trace(visitor);
34 }
35
36 private:
37 void handleEvent(ExecutionContext* context, Event* event) override {
38 DCHECK_EQ(event->type(), EventTypeNames::click);
39
40 MouseEvent* mouse_event = ToMouseEvent(event);
41 ClientRect* client_rect = element_->getBoundingClientRect();
42 const double x = mouse_event->x();
43 const double y = mouse_event->y();
44 if (x < client_rect->left() || x > client_rect->right() ||
45 y < client_rect->top() || y > client_rect->bottom())
46 return;
47
48 element_->GetVideoElement().DisableMediaRemoting();
49 event->SetDefaultHandled();
50 event->stopPropagation();
51 }
52
53 Member<MediaRemotingExitButtonElement> element_;
54 };
55
56 MediaRemotingExitButtonElement::MediaRemotingExitButtonElement(
57 MediaRemotingInterstitial& interstitial)
58 : HTMLDivElement(interstitial.GetDocument()), interstitial_(interstitial) {
59 listener_ = new MouseEventsListener(*this);
60 SetShadowPseudoId(AtomicString("-internal-media-remoting-disable-button"));
61 setInnerText(interstitial.GetVideoElement().GetLocale().QueryString(
62 WebLocalizedString::kMediaRemotingDisableText),
63 ASSERT_NO_EXCEPTION);
64 }
65
66 void MediaRemotingExitButtonElement::OnShown() {
67 GetDocument().addEventListener(EventTypeNames::click, listener_, true);
68 }
69
70 void MediaRemotingExitButtonElement::OnHidden() {
71 GetDocument().removeEventListener(EventTypeNames::click, listener_, true);
72 }
73
74 HTMLVideoElement& MediaRemotingExitButtonElement::GetVideoElement() const {
75 return interstitial_->GetVideoElement();
76 }
77
78 DEFINE_TRACE(MediaRemotingExitButtonElement) {
79 visitor->Trace(interstitial_);
80 visitor->Trace(listener_);
81 HTMLDivElement::Trace(visitor);
82 }
83
84 // ----------------------------
85
86 MediaRemotingCastMessageElement::MediaRemotingCastMessageElement(
87 MediaRemotingInterstitial& interstitial)
88 : HTMLDivElement(interstitial.GetDocument()) {
89 SetShadowPseudoId(AtomicString("-internal-media-remoting-cast-text-message"));
90 setInnerText(interstitial.GetVideoElement().GetLocale().QueryString(
91 WebLocalizedString::kMediaRemotingCastText),
92 ASSERT_NO_EXCEPTION);
93 }
94
95 // ----------------------------
96
97 MediaRemotingCastIconElement::MediaRemotingCastIconElement(
98 MediaRemotingInterstitial& interstitial)
99 : HTMLDivElement(interstitial.GetDocument()) {
100 SetShadowPseudoId(AtomicString("-internal-media-remoting-cast-icon"));
101 }
102
103 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698