Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / DeviceSingleWindowEventController.cpp
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/events/Event.h"
10 #include "core/frame/LocalDOMWindow.h"
11 #include "core/page/Page.h"
12
13 namespace blink {
14
15 DeviceSingleWindowEventController::DeviceSingleWindowEventController(Document& document)
16     : PlatformEventController(document.page())
17     , DOMWindowLifecycleObserver(document.domWindow())
18     , m_needsCheckingNullEvents(true)
19     , m_document(document)
20 {
21 }
22
23 DeviceSingleWindowEventController::~DeviceSingleWindowEventController()
24 {
25 }
26
27 void DeviceSingleWindowEventController::didUpdateData()
28 {
29     dispatchDeviceEvent(lastEvent());
30 }
31
32 void DeviceSingleWindowEventController::dispatchDeviceEvent(PassRefPtrWillBeRawPtr<Event> prpEvent)
33 {
34     if (!document().domWindow() || document().activeDOMObjectsAreSuspended() || document().activeDOMObjectsAreStopped())
35         return;
36
37     RefPtrWillBeRawPtr<Event> event = prpEvent;
38     document().domWindow()->dispatchEvent(event);
39
40     if (m_needsCheckingNullEvents) {
41         if (isNullEvent(event.get()))
42             stopUpdating();
43         else
44             m_needsCheckingNullEvents = false;
45     }
46 }
47
48 void DeviceSingleWindowEventController::didAddEventListener(LocalDOMWindow* window, const AtomicString& eventType)
49 {
50     if (eventType != eventTypeName())
51         return;
52
53     if (page() && page()->visibilityState() == PageVisibilityStateVisible)
54         startUpdating();
55
56     m_hasEventListener = true;
57 }
58
59 void DeviceSingleWindowEventController::didRemoveEventListener(LocalDOMWindow* window, const AtomicString& eventType)
60 {
61     if (eventType != eventTypeName() || window->hasEventListeners(eventTypeName()))
62         return;
63
64     stopUpdating();
65     m_hasEventListener = false;
66 }
67
68 void DeviceSingleWindowEventController::didRemoveAllEventListeners(LocalDOMWindow*)
69 {
70     stopUpdating();
71     m_hasEventListener = false;
72 }
73
74 void DeviceSingleWindowEventController::trace(Visitor* visitor)
75 {
76     visitor->trace(m_document);
77     PlatformEventController::trace(visitor);
78 }
79
80 } // namespace blink