Changeset 63312 in webkit


Ignore:
Timestamp:
Jul 14, 2010 5:54:49 AM (14 years ago)
Author:
steveblock@google.com
Message:

2010-07-14 Steve Block <steveblock@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):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63311 r63312  
     12010-07-14  Steve Block  <steveblock@google.com>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        Provide implementation of DeviceOrientationController and hook into DOMWindow
     6        https://bugs.webkit.org/show_bug.cgi?id=39588
     7
     8        Added DeviceOrientationController::addListener() and removeListener()
     9        to start and stop the client and added calls from DomWindow. Implemented
     10        DeviceOrientationController::onDeviceOrientationChange() to fire a
     11        DeviceOrientationEvent on the window object.
     12
     13        No new tests yet, pending LayoutTestController methods for mock DeviceOrientation.
     14
     15        * dom/DeviceOrientationClient.h:
     16        * dom/DeviceOrientationController.cpp:
     17        (WebCore::DeviceOrientation::addListener):
     18        (WebCore::DeviceOrientation::removeListener):
     19        (WebCore::DeviceOrientation::removeAllListeners):
     20        (WebCore::DeviceOrientationController::onDeviceOrientationChange):
     21        * dom/DeviceOrientationController.h:
     22        * page/DOMWindow.cpp:
     23        (WebCore::DOMWindow::addEventListener):
     24        (WebCore::DOMWindow::removeEventListener):
     25        (WebCore::DOMWindow::removeAllEventListeners):
     26
    1272010-07-14  Yury Semikhatsky  <yurys@chromium.org>
    228
  • trunk/WebCore/dom/DeviceOrientationClient.h

    r59935 r63312  
    2929namespace WebCore {
    3030
     31class DeviceOrientation;
     32
    3133class DeviceOrientationClient {
    3234public:
    3335    virtual void startUpdating() = 0;
    3436    virtual void stopUpdating() = 0;
     37    virtual DeviceOrientation* lastOrientation() const = 0;
    3538
    3639protected:
  • trunk/WebCore/dom/DeviceOrientationController.cpp

    r62646 r63312  
    2929#if ENABLE(DEVICE_ORIENTATION)
    3030
     31#include "DeviceOrientation.h"
    3132#include "DeviceOrientationClient.h"
    3233#include "DeviceOrientationEvent.h"
    33 #include <wtf/UnusedParam.h>
    3434
    3535namespace WebCore {
     
    4141}
    4242
    43 void DeviceOrientationController::onDeviceOrientationChange(double alpha, double beta, double gamma)
     43void DeviceOrientationController::addListener(DOMWindow* window)
    4444{
    45     // FIXME: Fire DeviceOrientationEvents on the window object of all frames
    46     // that are listening to orientation.
    47     UNUSED_PARAM(alpha);
    48     UNUSED_PARAM(beta);
    49     UNUSED_PARAM(gamma);
     45    // If no client is present, signal that no orientation data is available.
     46    // If the client already has an orientation, call back to this new listener
     47    // immediately.
     48    if (!m_client) {
     49        RefPtr<DeviceOrientation> emptyOrientation = DeviceOrientation::create();
     50        window->dispatchEvent(DeviceOrientationEvent::create(eventNames().deviceorientationEvent, emptyOrientation.get()));
     51    } else if (m_client && m_client->lastOrientation())
     52        window->dispatchEvent(DeviceOrientationEvent::create(eventNames().deviceorientationEvent, m_client->lastOrientation()));
     53
     54    // The client may call back synchronously.
     55    bool wasEmpty = m_listeners.isEmpty();
     56    m_listeners.add(window);
     57    if (wasEmpty && m_client)
     58        m_client->startUpdating();
     59}
     60
     61void DeviceOrientationController::removeListener(DOMWindow* window)
     62{
     63    m_listeners.remove(window);
     64    if (m_listeners.isEmpty() && m_client)
     65        m_client->stopUpdating();
     66}
     67
     68void DeviceOrientationController::removeAllListeners(DOMWindow* window)
     69{
     70    // May be called with a DOMWindow that's not a listener.
     71    if (!m_listeners.contains(window))
     72        return;
     73
     74    m_listeners.removeAll(window);
     75    if (m_listeners.isEmpty() && m_client)
     76        m_client->stopUpdating();
     77}
     78
     79void DeviceOrientationController::onDeviceOrientationChange(DeviceOrientation* orientation)
     80{
     81    RefPtr<DeviceOrientationEvent> event = DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation);
     82    Vector<DOMWindow*> listenersVector;
     83    copyToVector(m_listeners, listenersVector);
     84    for (size_t i = 0; i < listenersVector.size(); ++i)
     85        listenersVector[i]->dispatchEvent(event);
    5086}
    5187
  • trunk/WebCore/dom/DeviceOrientationController.h

    r62646 r63312  
    2727#define DeviceOrientationController_h
    2828
     29#include "DOMWindow.h"
     30#include <wtf/HashCountedSet.h>
     31
    2932namespace WebCore {
    3033
     34class DeviceOrientation;
    3135class DeviceOrientationClient;
    3236class Page;
     
    3640    DeviceOrientationController(Page*, DeviceOrientationClient*);
    3741
    38     // FIXME: Add methods to start and stop the service.
     42    void addListener(DOMWindow*);
     43    void removeListener(DOMWindow*);
     44    void removeAllListeners(DOMWindow*);
    3945
    40     void onDeviceOrientationChange(double alpha, double beta, double gamma);
     46    void onDeviceOrientationChange(DeviceOrientation*);
    4147
    4248private:
    4349    Page* m_page;
    4450    DeviceOrientationClient* m_client;
     51    typedef HashCountedSet<DOMWindow*> ListenersSet;
     52    ListenersSet m_listeners;
    4553};
    4654
  • trunk/WebCore/page/DOMWindow.cpp

    r62984 r63312  
    3636#include "Chrome.h"
    3737#include "Console.h"
    38 #include "Database.h"
    39 #include "DatabaseCallback.h"
    4038#include "DOMApplicationCache.h"
    4139#include "DOMSelection.h"
    4240#include "DOMTimer.h"
     41#include "Database.h"
     42#include "DatabaseCallback.h"
     43#include "DeviceOrientationController.h"
    4344#include "PageTransitionEvent.h"
    4445#include "Document.h"
     
    14111412    else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
    14121413        addBeforeUnloadEventListener(this);
     1414#if ENABLE(DEVICE_ORIENTATION)
     1415    else if (eventType == eventNames().deviceorientationEvent && frame() && frame()->page())
     1416        frame()->page()->deviceOrientation()->addListener(this);
     1417#endif
    14131418
    14141419    return true;
     
    14241429    else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
    14251430        removeBeforeUnloadEventListener(this);
     1431#if ENABLE(DEVICE_ORIENTATION)
     1432    else if (eventType == eventNames().deviceorientationEvent && frame() && frame()->page())
     1433        frame()->page()->deviceOrientation()->removeListener(this);
     1434#endif
    14261435
    14271436    return true;
     
    14981507    EventTarget::removeAllEventListeners();
    14991508
     1509#if ENABLE(DEVICE_ORIENTATION)
     1510    if (frame() && frame()->page())
     1511        frame()->page()->deviceOrientation()->removeAllListeners(this);
     1512#endif
     1513
    15001514    removeAllUnloadEventListeners(this);
    15011515    removeAllBeforeUnloadEventListeners(this);
Note: See TracChangeset for help on using the changeset viewer.