[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
steveblock at google.com
steveblock at google.com
Wed Dec 22 11:10:33 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 02b970eaaa35ad82cf9176d6d09284c30558cc17
Author: steveblock at google.com <steveblock at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Jul 14 12:54:49 2010 +0000
2010-07-14 Steve Block <steveblock at google.com>
Reviewed by Jeremy Orlow.
Provide implementation of DeviceOrientationController and hook into DOMWindow
https://bugs.webkit.org/show_bug.cgi?id=39588
Added DeviceOrientationController::addListener() and removeListener()
to start and stop the client and added calls from DomWindow. Implemented
DeviceOrientationController::onDeviceOrientationChange() to fire a
DeviceOrientationEvent on the window object.
No new tests yet, pending LayoutTestController methods for mock DeviceOrientation.
* dom/DeviceOrientationClient.h:
* dom/DeviceOrientationController.cpp:
(WebCore::DeviceOrientation::addListener):
(WebCore::DeviceOrientation::removeListener):
(WebCore::DeviceOrientation::removeAllListeners):
(WebCore::DeviceOrientationController::onDeviceOrientationChange):
* dom/DeviceOrientationController.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::addEventListener):
(WebCore::DOMWindow::removeEventListener):
(WebCore::DOMWindow::removeAllEventListeners):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63312 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index de9ac35..d38392a 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,29 @@
+2010-07-14 Steve Block <steveblock at google.com>
+
+ Reviewed by Jeremy Orlow.
+
+ Provide implementation of DeviceOrientationController and hook into DOMWindow
+ https://bugs.webkit.org/show_bug.cgi?id=39588
+
+ Added DeviceOrientationController::addListener() and removeListener()
+ to start and stop the client and added calls from DomWindow. Implemented
+ DeviceOrientationController::onDeviceOrientationChange() to fire a
+ DeviceOrientationEvent on the window object.
+
+ No new tests yet, pending LayoutTestController methods for mock DeviceOrientation.
+
+ * dom/DeviceOrientationClient.h:
+ * dom/DeviceOrientationController.cpp:
+ (WebCore::DeviceOrientation::addListener):
+ (WebCore::DeviceOrientation::removeListener):
+ (WebCore::DeviceOrientation::removeAllListeners):
+ (WebCore::DeviceOrientationController::onDeviceOrientationChange):
+ * dom/DeviceOrientationController.h:
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::addEventListener):
+ (WebCore::DOMWindow::removeEventListener):
+ (WebCore::DOMWindow::removeAllEventListeners):
+
2010-07-14 Yury Semikhatsky <yurys at chromium.org>
Reviewed by Pavel Feldman.
diff --git a/WebCore/dom/DeviceOrientationClient.h b/WebCore/dom/DeviceOrientationClient.h
index e0f14eb..427412f 100644
--- a/WebCore/dom/DeviceOrientationClient.h
+++ b/WebCore/dom/DeviceOrientationClient.h
@@ -28,10 +28,13 @@
namespace WebCore {
+class DeviceOrientation;
+
class DeviceOrientationClient {
public:
virtual void startUpdating() = 0;
virtual void stopUpdating() = 0;
+ virtual DeviceOrientation* lastOrientation() const = 0;
protected:
virtual ~DeviceOrientationClient() {}
diff --git a/WebCore/dom/DeviceOrientationController.cpp b/WebCore/dom/DeviceOrientationController.cpp
index 97ddcd8..204c796 100644
--- a/WebCore/dom/DeviceOrientationController.cpp
+++ b/WebCore/dom/DeviceOrientationController.cpp
@@ -28,9 +28,9 @@
#if ENABLE(DEVICE_ORIENTATION)
+#include "DeviceOrientation.h"
#include "DeviceOrientationClient.h"
#include "DeviceOrientationEvent.h"
-#include <wtf/UnusedParam.h>
namespace WebCore {
@@ -40,13 +40,49 @@ DeviceOrientationController::DeviceOrientationController(Page* page, DeviceOrien
{
}
-void DeviceOrientationController::onDeviceOrientationChange(double alpha, double beta, double gamma)
+void DeviceOrientationController::addListener(DOMWindow* window)
{
- // FIXME: Fire DeviceOrientationEvents on the window object of all frames
- // that are listening to orientation.
- UNUSED_PARAM(alpha);
- UNUSED_PARAM(beta);
- UNUSED_PARAM(gamma);
+ // If no client is present, signal that no orientation data is available.
+ // If the client already has an orientation, call back to this new listener
+ // immediately.
+ if (!m_client) {
+ RefPtr<DeviceOrientation> emptyOrientation = DeviceOrientation::create();
+ window->dispatchEvent(DeviceOrientationEvent::create(eventNames().deviceorientationEvent, emptyOrientation.get()));
+ } else if (m_client && m_client->lastOrientation())
+ window->dispatchEvent(DeviceOrientationEvent::create(eventNames().deviceorientationEvent, m_client->lastOrientation()));
+
+ // The client may call back synchronously.
+ bool wasEmpty = m_listeners.isEmpty();
+ m_listeners.add(window);
+ if (wasEmpty && m_client)
+ m_client->startUpdating();
+}
+
+void DeviceOrientationController::removeListener(DOMWindow* window)
+{
+ m_listeners.remove(window);
+ if (m_listeners.isEmpty() && m_client)
+ m_client->stopUpdating();
+}
+
+void DeviceOrientationController::removeAllListeners(DOMWindow* window)
+{
+ // May be called with a DOMWindow that's not a listener.
+ if (!m_listeners.contains(window))
+ return;
+
+ m_listeners.removeAll(window);
+ if (m_listeners.isEmpty() && m_client)
+ m_client->stopUpdating();
+}
+
+void DeviceOrientationController::onDeviceOrientationChange(DeviceOrientation* orientation)
+{
+ RefPtr<DeviceOrientationEvent> event = DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation);
+ Vector<DOMWindow*> listenersVector;
+ copyToVector(m_listeners, listenersVector);
+ for (size_t i = 0; i < listenersVector.size(); ++i)
+ listenersVector[i]->dispatchEvent(event);
}
} // namespace WebCore
diff --git a/WebCore/dom/DeviceOrientationController.h b/WebCore/dom/DeviceOrientationController.h
index 5f8f49a..f8ad8b4 100644
--- a/WebCore/dom/DeviceOrientationController.h
+++ b/WebCore/dom/DeviceOrientationController.h
@@ -26,8 +26,12 @@
#ifndef DeviceOrientationController_h
#define DeviceOrientationController_h
+#include "DOMWindow.h"
+#include <wtf/HashCountedSet.h>
+
namespace WebCore {
+class DeviceOrientation;
class DeviceOrientationClient;
class Page;
@@ -35,13 +39,17 @@ class DeviceOrientationController {
public:
DeviceOrientationController(Page*, DeviceOrientationClient*);
- // FIXME: Add methods to start and stop the service.
+ void addListener(DOMWindow*);
+ void removeListener(DOMWindow*);
+ void removeAllListeners(DOMWindow*);
- void onDeviceOrientationChange(double alpha, double beta, double gamma);
+ void onDeviceOrientationChange(DeviceOrientation*);
private:
Page* m_page;
DeviceOrientationClient* m_client;
+ typedef HashCountedSet<DOMWindow*> ListenersSet;
+ ListenersSet m_listeners;
};
} // namespace WebCore
diff --git a/WebCore/page/DOMWindow.cpp b/WebCore/page/DOMWindow.cpp
index d469049..5ebe659 100644
--- a/WebCore/page/DOMWindow.cpp
+++ b/WebCore/page/DOMWindow.cpp
@@ -35,11 +35,12 @@
#include "CSSStyleSelector.h"
#include "Chrome.h"
#include "Console.h"
-#include "Database.h"
-#include "DatabaseCallback.h"
#include "DOMApplicationCache.h"
#include "DOMSelection.h"
#include "DOMTimer.h"
+#include "Database.h"
+#include "DatabaseCallback.h"
+#include "DeviceOrientationController.h"
#include "PageTransitionEvent.h"
#include "Document.h"
#include "Element.h"
@@ -1410,6 +1411,10 @@ bool DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<Event
addUnloadEventListener(this);
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
addBeforeUnloadEventListener(this);
+#if ENABLE(DEVICE_ORIENTATION)
+ else if (eventType == eventNames().deviceorientationEvent && frame() && frame()->page())
+ frame()->page()->deviceOrientation()->addListener(this);
+#endif
return true;
}
@@ -1423,6 +1428,10 @@ bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener
removeUnloadEventListener(this);
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
removeBeforeUnloadEventListener(this);
+#if ENABLE(DEVICE_ORIENTATION)
+ else if (eventType == eventNames().deviceorientationEvent && frame() && frame()->page())
+ frame()->page()->deviceOrientation()->removeListener(this);
+#endif
return true;
}
@@ -1497,6 +1506,11 @@ void DOMWindow::removeAllEventListeners()
{
EventTarget::removeAllEventListeners();
+#if ENABLE(DEVICE_ORIENTATION)
+ if (frame() && frame()->page())
+ frame()->page()->deviceOrientation()->removeAllListeners(this);
+#endif
+
removeAllUnloadEventListeners(this);
removeAllBeforeUnloadEventListeners(this);
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list