Add DeviceController base-class to remove duplication of DeviceXXXControler

https://bugs.webkit.org/show_bug.cgi?id=96894

Reviewed by Hajime Morita.

Source/WebCore:

Add DeviceController which is extracted from DeviceOrientationController to remove duplication.
And soon-to-be-added DeviceMotionController and ProximityController.

Covered by existing tests.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/DeviceOrientationClient.h:
* dom/DeviceOrientationController.cpp:
Remove member functions to move to DeviceController.
- addListener(), removeListener(), removeAllListeners(), isActive()
(WebCore::DeviceOrientationController::DeviceOrientationController):
(WebCore::DeviceOrientationController::didChangeDeviceOrientation):
(WebCore::DeviceOrientationController::client):
(WebCore::DeviceOrientationController::hasLastData):
(WebCore::DeviceOrientationController::getLastEvent):
(WebCore::DeviceOrientationController::from):
(WebCore):
* dom/DeviceOrientationController.h:
(WebCore):
(WebCore::DeviceOrientationController::~DeviceOrientationController):
(DeviceOrientationController):
* dom/Document.cpp:
Remove suspendEventsForAllListeners() and resumeEventsForAllListeners() function calls.
These calls can be made by checking activeDOMObjectsAreSuspended() and activeDOMObjectsAreStopped() before dispatchEvent.
(WebCore::Document::suspendActiveDOMObjects):
(WebCore::Document::resumeActiveDOMObjects):
* loader/EmptyClients.h:
(EmptyDeviceClient):
(WebCore::EmptyDeviceClient::startUpdating):
(WebCore::EmptyDeviceClient::stopUpdating):
(WebCore):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::addEventListener):
(WebCore::DOMWindow::removeEventListener):
(WebCore::DOMWindow::removeAllEventListeners):
* page/DeviceClient.h: Added.
(WebCore):
(DeviceClient):
(WebCore::DeviceClient::~DeviceClient):
* page/DeviceController.cpp: Added.
DeviceController has extracted functions from DeviceOrientationController and DeviceMotionController.
- addDeviceEventListener(), removeDeviceEventlistener(), removeAllDeviceEventListeners(), dispatchDeviceEvent()
All kind of device event controller which has DeviceClient can be inherited from DeviceController.
(WebCore):
(WebCore::DeviceController::DeviceController):
(WebCore::DeviceController::addDeviceEventListener):
(WebCore::DeviceController::removeDeviceEventListener):
(WebCore::DeviceController::removeAllDeviceEventListeners):
(WebCore::DeviceController::dispatchDeviceEvent):
(WebCore::DeviceController::fireDeviceEvent):
* page/DeviceController.h: Added.
(WebCore):
(DeviceController):
(WebCore::DeviceController::~DeviceController):
(WebCore::DeviceController::isActive):
(WebCore::DeviceController::client):
(WebCore::DeviceController::hasLastData):
(WebCore::DeviceController::getLastEvent):

Source/WebKit/qt:

Change client() to deviceOrientationClient() to get DeviceOrientationClient*.

* WebCoreSupport/DumpRenderTreeSupportQt.cpp:
(DumpRenderTreeSupportQt::setMockDeviceOrientation):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@133143 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6d2298a4
......@@ -1711,6 +1711,7 @@ SET(WebCore_SOURCES
page/ContentSecurityPolicy.cpp
page/ContextMenuController.cpp
page/Crypto.cpp
page/DeviceController.cpp
page/DiagnosticLoggingKeys.cpp
page/DOMSecurityPolicy.cpp
page/DOMSelection.cpp
......
2012-11-01 Kihong Kwon <kihong.kwon@samsung.com>
Add DeviceController base-class to remove duplication of DeviceXXXControler
https://bugs.webkit.org/show_bug.cgi?id=96894
Reviewed by Hajime Morita.
Add DeviceController which is extracted from DeviceOrientationController to remove duplication.
And soon-to-be-added DeviceMotionController and ProximityController.
Covered by existing tests.
* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/DeviceOrientationClient.h:
* dom/DeviceOrientationController.cpp:
Remove member functions to move to DeviceController.
- addListener(), removeListener(), removeAllListeners(), isActive()
(WebCore::DeviceOrientationController::DeviceOrientationController):
(WebCore::DeviceOrientationController::didChangeDeviceOrientation):
(WebCore::DeviceOrientationController::client):
(WebCore::DeviceOrientationController::hasLastData):
(WebCore::DeviceOrientationController::getLastEvent):
(WebCore::DeviceOrientationController::from):
(WebCore):
* dom/DeviceOrientationController.h:
(WebCore):
(WebCore::DeviceOrientationController::~DeviceOrientationController):
(DeviceOrientationController):
* dom/Document.cpp:
Remove suspendEventsForAllListeners() and resumeEventsForAllListeners() function calls.
These calls can be made by checking activeDOMObjectsAreSuspended() and activeDOMObjectsAreStopped() before dispatchEvent.
(WebCore::Document::suspendActiveDOMObjects):
(WebCore::Document::resumeActiveDOMObjects):
* loader/EmptyClients.h:
(EmptyDeviceClient):
(WebCore::EmptyDeviceClient::startUpdating):
(WebCore::EmptyDeviceClient::stopUpdating):
(WebCore):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::addEventListener):
(WebCore::DOMWindow::removeEventListener):
(WebCore::DOMWindow::removeAllEventListeners):
* page/DeviceClient.h: Added.
(WebCore):
(DeviceClient):
(WebCore::DeviceClient::~DeviceClient):
* page/DeviceController.cpp: Added.
DeviceController has extracted functions from DeviceOrientationController and DeviceMotionController.
- addDeviceEventListener(), removeDeviceEventlistener(), removeAllDeviceEventListeners(), dispatchDeviceEvent()
All kind of device event controller which has DeviceClient can be inherited from DeviceController.
(WebCore):
(WebCore::DeviceController::DeviceController):
(WebCore::DeviceController::addDeviceEventListener):
(WebCore::DeviceController::removeDeviceEventListener):
(WebCore::DeviceController::removeAllDeviceEventListeners):
(WebCore::DeviceController::dispatchDeviceEvent):
(WebCore::DeviceController::fireDeviceEvent):
* page/DeviceController.h: Added.
(WebCore):
(DeviceController):
(WebCore::DeviceController::~DeviceController):
(WebCore::DeviceController::isActive):
(WebCore::DeviceController::client):
(WebCore::DeviceController::hasLastData):
(WebCore::DeviceController::getLastEvent):
2012-11-01 Yury Semikhatsky <yurys@chromium.org>
Memory instrumentation: report memory occupied by ResourceRequest instead of its base ResourceRequestBase
......@@ -4009,6 +4009,9 @@ webcore_sources += \
Source/WebCore/page/Coordinates.h \
Source/WebCore/page/Crypto.cpp \
Source/WebCore/page/Crypto.h \
Source/WebCore/page/DeviceClient.h \
Source/WebCore/page/DeviceController.cpp \
Source/WebCore/page/DeviceController.h \
Source/WebCore/page/DiagnosticLoggingKeys.cpp \
Source/WebCore/page/DiagnosticLoggingKeys.h \
Source/WebCore/page/DOMSecurityPolicy.cpp \
......
......@@ -872,6 +872,7 @@ SOURCES += \
page/ContentSecurityPolicy.cpp \
page/ContextMenuController.cpp \
page/Crypto.cpp \
page/DeviceController.cpp \
page/DiagnosticLoggingKeys.cpp \
page/DOMSelection.cpp \
page/DOMTimer.cpp \
......@@ -1999,6 +2000,8 @@ HEADERS += \
page/ContextMenuController.h \
page/ContextMenuProvider.h \
page/Coordinates.h \
page/DeviceClient.h \
page/DeviceController.h \
page/DiagnosticLoggingKeys.h \
page/DOMSelection.h \
page/DOMTimer.h \
......
......@@ -3115,6 +3115,9 @@
'page/ContextMenuProvider.h',
'page/Crypto.cpp',
'page/Crypto.h',
'page/DeviceClient.h',
'page/DeviceController.cpp',
'page/DeviceController.h',
'page/DiagnosticLoggingKeys.cpp',
'page/DiagnosticLoggingKeys.h',
'page/DOMSecurityPolicy.cpp',
......
......@@ -26962,6 +26962,18 @@
RelativePath="..\page\animation\CSSPropertyAnimation.h"
>
</File>
<File
RelativePath="..\page\DeviceClient.h"
>
</File>
<File
RelativePath="..\page\DeviceController.cpp"
>
</File>
<File
RelativePath="..\page\DeviceController.h"
>
</File>
<File
RelativePath="..\page\DiagnosticLoggingKeys.cpp"
>
......@@ -5893,6 +5893,9 @@
CAE9F90F146441F000C245B0 /* CSSAspectRatioValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CAE9F90D146441F000C245B0 /* CSSAspectRatioValue.cpp */; };
CAE9F910146441F000C245B0 /* CSSAspectRatioValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CAE9F90E146441F000C245B0 /* CSSAspectRatioValue.h */; };
CAE9F910146441F000C245B1 /* CSSVariableValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CAE9F90E146441F000C245B1 /* CSSVariableValue.h */; };
CCC2B51415F613060048CDD6 /* DeviceClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51015F613060048CDD6 /* DeviceClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
CCC2B51515F613060048CDD6 /* DeviceController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCC2B51115F613060048CDD6 /* DeviceController.cpp */; };
CCC2B51615F613060048CDD6 /* DeviceController.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51215F613060048CDD6 /* DeviceController.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD27F6E51457685A0078207D /* JSMediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E2145767580078207D /* JSMediaController.cpp */; };
......@@ -13270,6 +13273,9 @@
CAE9F90D146441F000C245B0 /* CSSAspectRatioValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSAspectRatioValue.cpp; sourceTree = "<group>"; };
CAE9F90E146441F000C245B0 /* CSSAspectRatioValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSAspectRatioValue.h; sourceTree = "<group>"; };
CAE9F90E146441F000C245B1 /* CSSVariableValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSVariableValue.h; sourceTree = "<group>"; };
CCC2B51015F613060048CDD6 /* DeviceClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceClient.h; sourceTree = "<group>"; };
CCC2B51115F613060048CDD6 /* DeviceController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceController.cpp; sourceTree = "<group>"; };
CCC2B51215F613060048CDD6 /* DeviceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceController.h; sourceTree = "<group>"; };
CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFullScreenWindow.h; sourceTree = "<group>"; };
CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenWindow.mm; sourceTree = "<group>"; };
CD27F6E014575C1B0078207D /* MediaController.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MediaController.idl; sourceTree = "<group>"; };
......@@ -15858,6 +15864,9 @@
975CA287130365F800E99AD9 /* Crypto.cpp */,
975CA288130365F800E99AD9 /* Crypto.h */,
975CA289130365F800E99AD9 /* Crypto.idl */,
CCC2B51015F613060048CDD6 /* DeviceClient.h */,
CCC2B51115F613060048CDD6 /* DeviceController.cpp */,
CCC2B51215F613060048CDD6 /* DeviceController.h */,
CD37B37415C1A7E1006DC898 /* DiagnosticLoggingKeys.cpp */,
CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */,
2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */,
......@@ -22783,6 +22792,8 @@
93309DE1099E64920056E581 /* DeleteSelectionCommand.h in Headers */,
FD1660A513787C6D001FFA7B /* DenormalDisabler.h in Headers */,
A7C9ABF91357A3BF00F5503F /* DetailsMarkerControl.h in Headers */,
CCC2B51415F613060048CDD6 /* DeviceClient.h in Headers */,
CCC2B51615F613060048CDD6 /* DeviceController.h in Headers */,
31FB1A57120A5D0600DC02A0 /* DeviceMotionClient.h in Headers */,
31FB1A59120A5D0600DC02A0 /* DeviceMotionController.h in Headers */,
31FB1A5B120A5D0600DC02A0 /* DeviceMotionData.h in Headers */,
......@@ -26342,6 +26353,7 @@
93309DDE099E64920056E581 /* DeleteFromTextNodeCommand.cpp in Sources */,
93309DE0099E64920056E581 /* DeleteSelectionCommand.cpp in Sources */,
A7C9ABF81357A3BF00F5503F /* DetailsMarkerControl.cpp in Sources */,
CCC2B51515F613060048CDD6 /* DeviceController.cpp in Sources */,
31FB1A58120A5D0600DC02A0 /* DeviceMotionController.cpp in Sources */,
31FB1A5A120A5D0600DC02A0 /* DeviceMotionData.cpp in Sources */,
31FB1A5C120A5D0600DC02A0 /* DeviceMotionEvent.cpp in Sources */,
/*
* Copyright 2010, The Android Open Source Project
* Copyright (C) 2012 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,18 +27,18 @@
#ifndef DeviceOrientationClient_h
#define DeviceOrientationClient_h
#include "DeviceClient.h"
namespace WebCore {
class DeviceOrientationController;
class DeviceOrientationData;
class Page;
class DeviceOrientationClient {
class DeviceOrientationClient : public DeviceClient {
public:
virtual ~DeviceOrientationClient() {}
virtual void setController(DeviceOrientationController*) = 0;
virtual void startUpdating() = 0;
virtual void stopUpdating() = 0;
virtual DeviceOrientationData* lastOrientation() const = 0;
virtual void deviceOrientationControllerDestroyed() = 0;
};
......
/*
* Copyright 2010, The Android Open Source Project
* Copyright (C) 2012 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -34,17 +35,11 @@
namespace WebCore {
DeviceOrientationController::DeviceOrientationController(Page* page, DeviceOrientationClient* client)
: m_client(client)
: DeviceController(client)
, m_page(page)
, m_timer(this, &DeviceOrientationController::timerFired)
{
ASSERT(m_client);
m_client->setController(this);
}
DeviceOrientationController::~DeviceOrientationController()
{
m_client->deviceOrientationControllerDestroyed();
deviceOrientationClient()->setController(this);
}
PassOwnPtr<DeviceOrientationController> DeviceOrientationController::create(Page* page, DeviceOrientationClient* client)
......@@ -52,91 +47,25 @@ PassOwnPtr<DeviceOrientationController> DeviceOrientationController::create(Page
return adoptPtr(new DeviceOrientationController(page, client));
}
void DeviceOrientationController::timerFired(Timer<DeviceOrientationController>* timer)
{
ASSERT_UNUSED(timer, timer == &m_timer);
ASSERT(m_client->lastOrientation());
RefPtr<DeviceOrientationData> orientation = m_client->lastOrientation();
RefPtr<DeviceOrientationEvent> event = DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation.get());
Vector<RefPtr<DOMWindow> > listenersVector;
copyToVector(m_newListeners, listenersVector);
m_newListeners.clear();
for (size_t i = 0; i < listenersVector.size(); ++i)
listenersVector[i]->dispatchEvent(event);
}
void DeviceOrientationController::addListener(DOMWindow* window)
{
// If the client already has an orientation, we should fire an event with that
// orientation. The event is fired asynchronously, but without
// waiting for the client to get a new orientation.
if (m_client->lastOrientation()) {
m_newListeners.add(window);
if (!m_timer.isActive())
m_timer.startOneShot(0);
}
// The client must not call back synchronously.
bool wasEmpty = m_listeners.isEmpty();
m_listeners.add(window);
if (wasEmpty)
m_client->startUpdating();
}
void DeviceOrientationController::removeListener(DOMWindow* window)
{
m_listeners.remove(window);
m_suspendedListeners.remove(window);
m_newListeners.remove(window);
if (m_listeners.isEmpty())
m_client->stopUpdating();
}
void DeviceOrientationController::removeAllListeners(DOMWindow* window)
void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationData* orientation)
{
// May be called with a DOMWindow that's not a listener.
if (!m_listeners.contains(window))
return;
m_listeners.removeAll(window);
m_suspendedListeners.removeAll(window);
m_newListeners.remove(window);
if (m_listeners.isEmpty())
m_client->stopUpdating();
orientation = InspectorInstrumentation::overrideDeviceOrientation(m_page, orientation);
dispatchDeviceEvent(DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation));
}
void DeviceOrientationController::suspendEventsForAllListeners(DOMWindow* window)
DeviceOrientationClient* DeviceOrientationController::deviceOrientationClient()
{
if (!m_listeners.contains(window))
return;
int count = m_listeners.count(window);
removeAllListeners(window);
while (count--)
m_suspendedListeners.add(window);
return static_cast<DeviceOrientationClient*>(m_client);
}
void DeviceOrientationController::resumeEventsForAllListeners(DOMWindow* window)
bool DeviceOrientationController::hasLastData()
{
if (!m_suspendedListeners.contains(window))
return;
int count = m_suspendedListeners.count(window);
m_suspendedListeners.removeAll(window);
while (count--)
addListener(window);
return deviceOrientationClient()->lastOrientation();
}
void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationData* orientation)
PassRefPtr<Event> DeviceOrientationController::getLastEvent()
{
orientation = InspectorInstrumentation::overrideDeviceOrientation(m_page, orientation);
RefPtr<DeviceOrientationEvent> event = DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation);
Vector<RefPtr<DOMWindow> > listenersVector;
copyToVector(m_listeners, listenersVector);
for (size_t i = 0; i < listenersVector.size(); ++i)
listenersVector[i]->dispatchEvent(event);
return DeviceOrientationEvent::create(eventNames().deviceorientationEvent, deviceOrientationClient()->lastOrientation());
}
const AtomicString& DeviceOrientationController::supplementName()
......@@ -145,6 +74,11 @@ const AtomicString& DeviceOrientationController::supplementName()
return name;
}
DeviceOrientationController* DeviceOrientationController::from(Page* page)
{
return static_cast<DeviceOrientationController*>(Supplement<Page>::from(page, supplementName()));
}
bool DeviceOrientationController::isActiveAt(Page* page)
{
if (DeviceOrientationController* self = DeviceOrientationController::from(page))
......
/*
* Copyright 2010, The Android Open Source Project
* Copyright (C) 2012 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,53 +27,34 @@
#ifndef DeviceOrientationController_h
#define DeviceOrientationController_h
#include "DOMWindow.h"
#include "Page.h"
#include "Timer.h"
#include "DeviceController.h"
#include <wtf/HashCountedSet.h>
namespace WebCore {
class DeviceOrientationData;
class DeviceOrientationClient;
class DeviceOrientationData;
class DeviceOrientationController : public Supplement<Page> {
class DeviceOrientationController : public DeviceController {
public:
~DeviceOrientationController();
~DeviceOrientationController() { };
static PassOwnPtr<DeviceOrientationController> create(Page*, DeviceOrientationClient*);
void addListener(DOMWindow*);
void removeListener(DOMWindow*);
void removeAllListeners(DOMWindow*);
void suspendEventsForAllListeners(DOMWindow*);
void resumeEventsForAllListeners(DOMWindow*);
void didChangeDeviceOrientation(DeviceOrientationData*);
DeviceOrientationClient* deviceOrientationClient();
bool isActive() { return !m_listeners.isEmpty(); }
DeviceOrientationClient* client() const { return m_client; }
virtual bool hasLastData() OVERRIDE;
virtual PassRefPtr<Event> getLastEvent() OVERRIDE;
static const AtomicString& supplementName();
static DeviceOrientationController* from(Page* page) { return static_cast<DeviceOrientationController*>(Supplement<Page>::from(page, supplementName())); }
static DeviceOrientationController* from(Page*);
static bool isActiveAt(Page*);
private:
explicit DeviceOrientationController(Page*, DeviceOrientationClient*);
void timerFired(Timer<DeviceOrientationController>*);
DeviceOrientationController(Page*, DeviceOrientationClient*);
DeviceOrientationClient* m_client;
Page* m_page;
typedef HashCountedSet<RefPtr<DOMWindow> > ListenersCountedSet;
ListenersCountedSet m_listeners;
ListenersCountedSet m_suspendedListeners;
typedef HashSet<RefPtr<DOMWindow> > ListenersSet;
ListenersSet m_newListeners;
Timer<DeviceOrientationController> m_timer;
};
} // namespace WebCore
......
......@@ -2182,9 +2182,6 @@ void Document::suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension why)
if (DeviceMotionController* controller = DeviceMotionController::from(page()))
controller->suspendEventsForAllListeners(domWindow());
if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
controller->suspendEventsForAllListeners(domWindow());
#endif
}
......@@ -2198,8 +2195,6 @@ void Document::resumeActiveDOMObjects()
if (DeviceMotionController* controller = DeviceMotionController::from(page()))
controller->resumeEventsForAllListeners(domWindow());
if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
controller->resumeEventsForAllListeners(domWindow());
#endif
}
......
......@@ -573,6 +573,12 @@ public:
virtual void hideHighlight() { }
};
class EmptyDeviceClient : public DeviceClient {
public:
virtual void startUpdating() OVERRIDE { }
virtual void stopUpdating() OVERRIDE { }
};
class EmptyDeviceMotionClient : public DeviceMotionClient {
public:
virtual void setController(DeviceMotionController*) { }
......@@ -585,8 +591,6 @@ public:
class EmptyDeviceOrientationClient : public DeviceOrientationClient {
public:
virtual void setController(DeviceOrientationController*) { }
virtual void startUpdating() { }
virtual void stopUpdating() { }
virtual DeviceOrientationData* lastOrientation() const { return 0; }
virtual void deviceOrientationControllerDestroyed() { }
};
......
......@@ -1601,7 +1601,7 @@ bool DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<Event
controller->addListener(this);
} else if (eventType == eventNames().deviceorientationEvent && RuntimeEnabledFeatures::deviceOrientationEnabled()) {
if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
controller->addListener(this);
controller->addDeviceEventListener(this);
}
#endif
......@@ -1630,7 +1630,7 @@ bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener
controller->removeListener(this);
} else if (eventType == eventNames().deviceorientationEvent) {
if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
controller->removeListener(this);
controller->removeDeviceEventListener(this);
}
#endif
......@@ -1687,7 +1687,7 @@ void DOMWindow::removeAllEventListeners()
if (DeviceMotionController* controller = DeviceMotionController::from(page()))
controller->removeAllListeners(this);
if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
controller->removeAllListeners(this);
controller->removeAllDeviceEventListeners(this);
#endif
removeAllUnloadEventListeners(this);
......
/*
* Copyright 2010, The Android Open Source Project
* Copyright (C) 2012 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DeviceClient_h
#define DeviceClient_h
namespace WebCore {
class DeviceClient {
public:
virtual ~DeviceClient() { }
virtual void startUpdating() = 0;
virtual void stopUpdating() = 0;
};
} // namespace WebCore
#endif // DeviceClient_h
/*
* Copyright 2010, The Android Open Source Project
* Copyright (C) 2012 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "DeviceController.h"
#include "DeviceClient.h"
#include "Document.h"
#include "Page.h"
namespace WebCore {
DeviceController::DeviceController(DeviceClient* client)
: m_client(client)
, m_timer(this, &DeviceController::fireDeviceEvent)
{
ASSERT(m_client);
}
void DeviceController::addDeviceEventListener(DOMWindow* window)
{
bool wasEmpty = m_listeners.isEmpty();
m_listeners.add(window);
if (hasLastData()) {
m_lastEventListeners.add(window);
if (!m_timer.isActive())
m_timer.startOneShot(0);
}
if (!wasEmpty)
m_client->startUpdating();
}
void DeviceController::removeDeviceEventListener(DOMWindow* window)
{
m_listeners.remove(window);
m_lastEventListeners.remove(window);
if (m_listeners.isEmpty())
m_client->stopUpdating();
}
void DeviceController::removeAllDeviceEventListeners(DOMWindow* window)
{
m_listeners.removeAll(window);
m_lastEventListeners.removeAll(window);
if (m_listeners.isEmpty())
m_client->stopUpdating();
}
void DeviceController::dispatchDeviceEvent(PassRefPtr<Event> event)
{
Vector<RefPtr<DOMWindow> > listenerVector;
copyToVector(m_listeners, listenerVector);
for (size_t i = 0; i < listenerVector.size(); ++i) {
if (listenerVector[i]->document()
&& !listenerVector[i]->document()->activeDOMObjectsAreSuspended()
&& !listenerVector[i]->document()->activeDOMObjectsAreStopped())
listenerVector[i]->dispatchEvent(event);
}
}
void DeviceController::fireDeviceEvent(Timer<DeviceController>* timer)
{
ASSERT_UNUSED(timer, timer == &m_timer);
ASSERT(hasLastData());
m_timer.stop();
Vector<RefPtr<DOMWindow> > listenerVector;
copyToVector(m_lastEventListeners, listenerVector);
m_lastEventListeners.clear();
for (size_t i = 0; i < listenerVector.size(); ++i) {
if (listenerVector[i]->document()
&& !listenerVector[i]->document()->activeDOMObjectsAreSuspended()
&& !listenerVector[i]->document()->activeDOMObjectsAreStopped())
listenerVector[i]->dispatchEvent(getLastEvent());
}
}
} // namespace WebCore
/*
* Copyright 2010, The Android Open Source Project
* Copyright (C) 2012 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DeviceController_h
#define DeviceController_h
#include "DOMWindow.h"
#include "Event.h"
#include "Supplementable.h"
#include "Timer.h"