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

Unified Diff: third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.cpp

Issue 2382233002: Hide overflow menu/closed caption list when clicking outside the list (Closed)
Patch Set: applied Mounir's comments Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.cpp
diff --git a/third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.cpp b/third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4f266eceb3cd9708b378312ee24b463e341769f3
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.cpp
@@ -0,0 +1,84 @@
+// Copyright 2016 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/MediaControlsWindowEventListener.h"
+
+#include "core/events/Event.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "core/html/HTMLMediaElement.h"
+#include "core/html/shadow/MediaControls.h"
+
+namespace blink {
+
+MediaControlsWindowEventListener* MediaControlsWindowEventListener::create(
+ MediaControls* mediaControls,
+ std::unique_ptr<Callback> callback) {
+ return new MediaControlsWindowEventListener(mediaControls,
+ std::move(callback));
+}
+
+MediaControlsWindowEventListener::MediaControlsWindowEventListener(
+ MediaControls* mediaControls,
+ std::unique_ptr<Callback> callback)
+ : EventListener(CPPEventListenerType),
+ m_mediaControls(mediaControls),
+ m_callback(std::move(callback)),
+ m_isActive(false) {
+ DCHECK(m_callback);
+}
+
+bool MediaControlsWindowEventListener::operator==(
+ const EventListener& other) const {
+ return this == &other;
+}
+
+void MediaControlsWindowEventListener::start() {
+ if (m_isActive)
+ return;
+
+ if (LocalDOMWindow* window = getLocalDOMWindow()) {
+ window->addEventListener(EventTypeNames::click, this, false);
+ m_isActive = true;
+ }
+}
+
+void MediaControlsWindowEventListener::stop() {
+ if (!m_isActive)
+ return;
+
+ if (LocalDOMWindow* window = getLocalDOMWindow())
+ window->removeEventListener(EventTypeNames::click, this, false);
+ m_isActive = false;
+}
+
+void MediaControlsWindowEventListener::handleEvent(
+ ExecutionContext* executionContext,
+ Event* event) {
+ DCHECK(event->type() == EventTypeNames::click);
+ handleClickEvent();
+}
+
+void MediaControlsWindowEventListener::handleClickEvent() {
+ if (!m_isActive)
+ return;
+ (*m_callback.get())();
+}
+
+LocalDOMWindow* MediaControlsWindowEventListener::getLocalDOMWindow() const {
+ LocalDOMWindow* window =
+ m_mediaControls->mediaElement().document().domWindow();
+
+ while (window && window != window->parent() && window->parent() &&
+ window->parent()->isLocalDOMWindow())
+ window = static_cast<LocalDOMWindow*>(window->parent());
+
+ return window;
+}
+
+DEFINE_TRACE(MediaControlsWindowEventListener) {
+ EventListener::trace(visitor);
+ visitor->trace(m_mediaControls);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/html/shadow/MediaControlsWindowEventListener.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698