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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/shadow/MediaRemotingElements.cpp
diff --git a/third_party/WebKit/Source/core/html/shadow/MediaRemotingElements.cpp b/third_party/WebKit/Source/core/html/shadow/MediaRemotingElements.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..698db3bfb68641f1b178fd2319486c66dce74831
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/shadow/MediaRemotingElements.cpp
@@ -0,0 +1,115 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/shadow/MediaRemotingElements.h"
+
+#include "core/dom/ClientRect.h"
+#include "core/dom/Text.h"
+#include "core/dom/shadow/ShadowRoot.h"
+#include "core/events/MouseEvent.h"
+#include "core/html/HTMLVideoElement.h"
+#include "core/input/EventHandler.h"
+#include "platform/text/PlatformLocale.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebLocalizedString.h"
+
+namespace blink {
+
+using namespace HTMLNames;
+
+// ----------------------------
+
+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
+ : public EventListener {
+ public:
+ explicit MouseEventsListener(MediaRemotingDisableButtonElement& element)
+ : EventListener(kCPPEventListenerType), element_(element) {}
+
+ bool operator==(const EventListener& other) const override {
+ return this == &other;
+ }
+
+ void Trace(blink::Visitor* visitor) {
+ visitor->Trace(element_);
+ EventListener::Trace(visitor);
+ }
+
+ private:
+ void handleEvent(ExecutionContext* context, Event* event) override {
+ 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.
+
+ MouseEvent* mouse_event = ToMouseEvent(event);
+ ClientRect* client_rect = element_->getBoundingClientRect();
+ const double x = mouse_event->x();
+ const double y = mouse_event->y();
+ if (x < client_rect->left() || x > client_rect->right() ||
+ y < client_rect->top() || y > client_rect->bottom())
+ return;
+
+ element_->VideoElement().DisableMediaRemoting();
+ event->SetDefaultHandled();
+ event->stopPropagation();
+ element_->GetDocument().removeEventListener(EventTypeNames::click, this,
+ 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.
+ }
+
+ Member<MediaRemotingDisableButtonElement> element_;
+};
+
+MediaRemotingDisableButtonElement::MediaRemotingDisableButtonElement(
+ MediaRemotingInterstitial& interstitial)
+ : HTMLDivElement(interstitial.GetDocument()), interstitial_(interstitial) {
+ listener_ = new MouseEventsListener(*this);
+ SetShadowPseudoId(AtomicString("-internal-media-remoting-disable-button"));
+ text_ = GetDocument().createTextNode(
+ interstitial.VideoElement().GetLocale().QueryString(
+ WebLocalizedString::kMediaRemotingDisableText));
+ 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.
+}
+
+void MediaRemotingDisableButtonElement::OnShown() {
+ GetDocument().addEventListener(EventTypeNames::click, listener_, true);
+}
+
+void MediaRemotingDisableButtonElement::OnHidden() {
+ GetDocument().removeEventListener(EventTypeNames::click, listener_, true);
+}
+
+HTMLVideoElement& MediaRemotingDisableButtonElement::VideoElement() const {
+ return interstitial_->VideoElement();
+}
+
+DEFINE_TRACE(MediaRemotingDisableButtonElement) {
+ visitor->Trace(interstitial_);
+ visitor->Trace(listener_);
+ visitor->Trace(text_);
+ HTMLDivElement::Trace(visitor);
+}
+
+// ----------------------------
+
+MediaRemotingCastMessageElement::MediaRemotingCastMessageElement(
+ MediaRemotingInterstitial& interstitial)
+ : HTMLDivElement(interstitial.GetDocument()) {
+ SetShadowPseudoId(AtomicString("-internal-media-remoting-cast-text-message"));
+ text_ = GetDocument().createTextNode(
+ interstitial.VideoElement().GetLocale().QueryString(
+ WebLocalizedString::kMediaRemotingCastText));
+ AppendChild(text_);
mlamouri (slow - plz ping) 2017/04/13 17:20:51 Same as above.
xjz 2017/04/13 19:12:11 Done.
+}
+
+DEFINE_TRACE(MediaRemotingCastMessageElement) {
+ visitor->Trace(text_);
+ HTMLDivElement::Trace(visitor);
+}
+
+// ----------------------------
+
+MediaRemotingCastIconElement::MediaRemotingCastIconElement(
+ MediaRemotingInterstitial& interstitial)
+ : HTMLDivElement(interstitial.GetDocument()) {
+ SetShadowPseudoId(AtomicString("-internal-media-remoting-cast-icon"));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698