| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/shadow/MediaControlsWindowEventListener.h" | 5 #include "core/html/shadow/MediaControlsWindowEventListener.h" |
| 6 | 6 |
| 7 #include "core/events/Event.h" | 7 #include "core/events/Event.h" |
| 8 #include "core/frame/LocalDOMWindow.h" | 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "core/html/shadow/MediaControls.h" | 9 #include "core/html/media/MediaControls.h" |
| 10 #include "core/html/shadow/MediaControlElements.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Helper returning the top DOMWindow as a LocalDOMWindow. Returns nullptr if it | 16 // Helper returning the top DOMWindow as a LocalDOMWindow. Returns nullptr if it |
| 16 // is not a LocalDOMWindow. | 17 // is not a LocalDOMWindow. |
| 17 // This does not work with OOPIF. | 18 // This does not work with OOPIF. |
| 18 LocalDOMWindow* getTopLocalDOMWindow(LocalDOMWindow* window) { | 19 LocalDOMWindow* getTopLocalDOMWindow(LocalDOMWindow* window) { |
| 19 if (!window->top() || !window->top()->isLocalDOMWindow()) | 20 if (!window->top() || !window->top()->isLocalDOMWindow()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 bool MediaControlsWindowEventListener::operator==( | 44 bool MediaControlsWindowEventListener::operator==( |
| 44 const EventListener& other) const { | 45 const EventListener& other) const { |
| 45 return this == &other; | 46 return this == &other; |
| 46 } | 47 } |
| 47 | 48 |
| 48 void MediaControlsWindowEventListener::start() { | 49 void MediaControlsWindowEventListener::start() { |
| 49 if (m_isActive) | 50 if (m_isActive) |
| 50 return; | 51 return; |
| 51 | 52 |
| 52 if (LocalDOMWindow* window = m_mediaControls->document().domWindow()) { | 53 if (LocalDOMWindow* window = m_mediaControls->ownerDocument().domWindow()) { |
| 53 window->addEventListener(EventTypeNames::click, this, true); | 54 window->addEventListener(EventTypeNames::click, this, true); |
| 54 | 55 |
| 55 if (LocalDOMWindow* outerWindow = getTopLocalDOMWindow(window)) { | 56 if (LocalDOMWindow* outerWindow = getTopLocalDOMWindow(window)) { |
| 56 if (window != outerWindow) | 57 if (window != outerWindow) |
| 57 outerWindow->addEventListener(EventTypeNames::click, this, true); | 58 outerWindow->addEventListener(EventTypeNames::click, this, true); |
| 58 outerWindow->addEventListener(EventTypeNames::resize, this, true); | 59 outerWindow->addEventListener(EventTypeNames::resize, this, true); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 m_mediaControls->panelElement()->addEventListener(EventTypeNames::click, this, | 63 m_mediaControls->panelElement()->addEventListener(EventTypeNames::click, this, |
| 63 false); | 64 false); |
| 64 m_mediaControls->timelineElement()->addEventListener(EventTypeNames::click, | 65 m_mediaControls->timelineElement()->addEventListener(EventTypeNames::click, |
| 65 this, false); | 66 this, false); |
| 66 m_mediaControls->castButtonElement()->addEventListener(EventTypeNames::click, | 67 m_mediaControls->castButtonElement()->addEventListener(EventTypeNames::click, |
| 67 this, false); | 68 this, false); |
| 68 m_mediaControls->volumeSliderElement()->addEventListener( | 69 m_mediaControls->volumeSliderElement()->addEventListener( |
| 69 EventTypeNames::click, this, false); | 70 EventTypeNames::click, this, false); |
| 70 | 71 |
| 71 m_isActive = true; | 72 m_isActive = true; |
| 72 } | 73 } |
| 73 | 74 |
| 74 void MediaControlsWindowEventListener::stop() { | 75 void MediaControlsWindowEventListener::stop() { |
| 75 if (!m_isActive) | 76 if (!m_isActive) |
| 76 return; | 77 return; |
| 77 | 78 |
| 78 if (LocalDOMWindow* window = m_mediaControls->document().domWindow()) { | 79 if (LocalDOMWindow* window = m_mediaControls->ownerDocument().domWindow()) { |
| 79 window->removeEventListener(EventTypeNames::click, this, true); | 80 window->removeEventListener(EventTypeNames::click, this, true); |
| 80 | 81 |
| 81 if (LocalDOMWindow* outerWindow = getTopLocalDOMWindow(window)) { | 82 if (LocalDOMWindow* outerWindow = getTopLocalDOMWindow(window)) { |
| 82 if (window != outerWindow) | 83 if (window != outerWindow) |
| 83 outerWindow->removeEventListener(EventTypeNames::click, this, true); | 84 outerWindow->removeEventListener(EventTypeNames::click, this, true); |
| 84 outerWindow->removeEventListener(EventTypeNames::resize, this, true); | 85 outerWindow->removeEventListener(EventTypeNames::resize, this, true); |
| 85 } | 86 } |
| 86 | 87 |
| 87 m_isActive = false; | 88 m_isActive = false; |
| 88 } | 89 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 109 return; | 110 return; |
| 110 (*m_callback.get())(); | 111 (*m_callback.get())(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 DEFINE_TRACE(MediaControlsWindowEventListener) { | 114 DEFINE_TRACE(MediaControlsWindowEventListener) { |
| 114 EventListener::trace(visitor); | 115 EventListener::trace(visitor); |
| 115 visitor->trace(m_mediaControls); | 116 visitor->trace(m_mediaControls); |
| 116 } | 117 } |
| 117 | 118 |
| 118 } // namespace blink | 119 } // namespace blink |
| OLD | NEW |