OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "config.h" |
| 6 #include "core/frame/DeviceSingleWindowEventController.h" |
| 7 |
| 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/DOMWindow.h" |
| 10 #include "core/page/Page.h" |
| 11 |
| 12 namespace WebCore { |
| 13 |
| 14 DeviceSingleWindowEventController::DeviceSingleWindowEventController(Document& d
ocument) |
| 15 : DeviceEventControllerBase(document.page()) |
| 16 , DOMWindowLifecycleObserver(document.domWindow()) |
| 17 , m_needsCheckingNullEvents(true) |
| 18 , m_document(document) |
| 19 { |
| 20 } |
| 21 |
| 22 DeviceSingleWindowEventController::~DeviceSingleWindowEventController() |
| 23 { |
| 24 } |
| 25 |
| 26 void DeviceSingleWindowEventController::didUpdateData() |
| 27 { |
| 28 dispatchDeviceEvent(lastEvent()); |
| 29 } |
| 30 |
| 31 void DeviceSingleWindowEventController::dispatchDeviceEvent(PassRefPtrWillBeRawP
tr<Event> prpEvent) |
| 32 { |
| 33 if (!m_document.domWindow() || m_document.activeDOMObjectsAreSuspended() ||
m_document.activeDOMObjectsAreStopped()) |
| 34 return; |
| 35 |
| 36 RefPtrWillBeRawPtr<Event> event = prpEvent; |
| 37 m_document.domWindow()->dispatchEvent(event); |
| 38 |
| 39 if (m_needsCheckingNullEvents) { |
| 40 if (isNullEvent(event.get())) |
| 41 stopUpdating(); |
| 42 else |
| 43 m_needsCheckingNullEvents = false; |
| 44 } |
| 45 } |
| 46 |
| 47 void DeviceSingleWindowEventController::didAddEventListener(DOMWindow* window, c
onst AtomicString& eventType) |
| 48 { |
| 49 if (eventType != eventTypeName()) |
| 50 return; |
| 51 |
| 52 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
| 53 startUpdating(); |
| 54 |
| 55 m_hasEventListener = true; |
| 56 } |
| 57 |
| 58 void DeviceSingleWindowEventController::didRemoveEventListener(DOMWindow* window
, const AtomicString& eventType) |
| 59 { |
| 60 if (eventType != eventTypeName() || window->hasEventListeners(eventTypeName(
))) |
| 61 return; |
| 62 |
| 63 stopUpdating(); |
| 64 m_hasEventListener = false; |
| 65 } |
| 66 |
| 67 void DeviceSingleWindowEventController::didRemoveAllEventListeners(DOMWindow*) |
| 68 { |
| 69 stopUpdating(); |
| 70 m_hasEventListener = false; |
| 71 } |
| 72 |
| 73 } // namespace WebCore |
OLD | NEW |