Changeset 135268 in webkit


Ignore:
Timestamp:
Nov 20, 2012 3:09:25 AM (11 years ago)
Author:
kihong.kwon@samsung.com
Message:

Apply DeviceController as parent class of DeviceMotionController.
https://bugs.webkit.org/show_bug.cgi?id=102578

Reviewed by Hajime Morita.

DeviceController needs to be applied as parent class of DeviceMotionController
because DeviceController which is extracted as parent class of
DeviceMotionController and DeviceOrientationController is already added.
Therefore duplicated implementation can be removed.

Covered by existing tests.

  • dom/DeviceMotionClient.h:
  • dom/DeviceMotionController.cpp:

(WebCore::DeviceMotionController::DeviceMotionController):
(WebCore::DeviceMotionController::didChangeDeviceMotion):
(WebCore::DeviceMotionController::deviceMotionClient):
(WebCore::DeviceMotionController::hasLastData):
(WebCore::DeviceMotionController::getLastEvent):
(WebCore::DeviceMotionController::from):
(WebCore):

  • dom/DeviceMotionController.h:

(WebCore):
(WebCore::DeviceMotionController::~DeviceMotionController):
(DeviceMotionController):

  • dom/Document.cpp:

Remove all implementations which are related DeviceOrientationEvnet and DeviceMotionEvent.
Because DeviceController checks suspend and stop status of active dom object before dispatchEvent.
(WebCore::Document::suspendActiveDOMObjects):
(WebCore::Document::resumeActiveDOMObjects):

  • loader/EmptyClients.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::addEventListener):
(WebCore::DOMWindow::removeEventListener):
(WebCore::DOMWindow::removeAllEventListeners):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r135266 r135268  
     12012-11-20  Kihong Kwon  <kihong.kwon@samsung.com>
     2
     3        Apply DeviceController as parent class of DeviceMotionController.
     4        https://bugs.webkit.org/show_bug.cgi?id=102578
     5
     6        Reviewed by Hajime Morita.
     7
     8        DeviceController needs to be applied as parent class of DeviceMotionController
     9        because DeviceController which is extracted as parent class of
     10        DeviceMotionController and DeviceOrientationController is already added.
     11        Therefore duplicated implementation can be removed.
     12
     13        Covered by existing tests.
     14
     15        * dom/DeviceMotionClient.h:
     16        * dom/DeviceMotionController.cpp:
     17        (WebCore::DeviceMotionController::DeviceMotionController):
     18        (WebCore::DeviceMotionController::didChangeDeviceMotion):
     19        (WebCore::DeviceMotionController::deviceMotionClient):
     20        (WebCore::DeviceMotionController::hasLastData):
     21        (WebCore::DeviceMotionController::getLastEvent):
     22        (WebCore::DeviceMotionController::from):
     23        (WebCore):
     24        * dom/DeviceMotionController.h:
     25        (WebCore):
     26        (WebCore::DeviceMotionController::~DeviceMotionController):
     27        (DeviceMotionController):
     28        * dom/Document.cpp:
     29        Remove all implementations which are related DeviceOrientationEvnet and DeviceMotionEvent.
     30        Because DeviceController checks suspend and stop status of active dom object before dispatchEvent.
     31        (WebCore::Document::suspendActiveDOMObjects):
     32        (WebCore::Document::resumeActiveDOMObjects):
     33        * loader/EmptyClients.h:
     34        * page/DOMWindow.cpp:
     35        (WebCore::DOMWindow::addEventListener):
     36        (WebCore::DOMWindow::removeEventListener):
     37        (WebCore::DOMWindow::removeAllEventListeners):
     38
    1392012-11-20  Kentaro Hara  <haraken@chromium.org>
    240
  • trunk/Source/WebCore/dom/DeviceMotionClient.h

    r120224 r135268  
    11/*
    22 * Copyright 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#define DeviceMotionClient_h
    2829
     30#include "DeviceClient.h"
     31
    2932namespace WebCore {
    3033
     
    3336class Page;
    3437
    35 class DeviceMotionClient {
     38class DeviceMotionClient : public DeviceClient {
    3639public:
    3740    virtual ~DeviceMotionClient() {}
    3841    virtual void setController(DeviceMotionController*) = 0;
    39     virtual void startUpdating() = 0;
    40     virtual void stopUpdating() = 0;
    4142    virtual DeviceMotionData* lastMotion() const = 0;
    4243    virtual void deviceMotionControllerDestroyed() = 0;
  • trunk/Source/WebCore/dom/DeviceMotionController.cpp

    r133976 r135268  
    11/*
    22 * Copyright 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3031#include "DeviceMotionData.h"
    3132#include "DeviceMotionEvent.h"
     33#include "Page.h"
    3234
    3335namespace WebCore {
    3436
    3537DeviceMotionController::DeviceMotionController(DeviceMotionClient* client)
    36     : m_client(client)
    37     , m_timer(this, &DeviceMotionController::timerFired)
     38    : DeviceController(client)
    3839{
    3940    ASSERT(m_client);
    40     m_client->setController(this);
    41 }
    42 
    43 DeviceMotionController::~DeviceMotionController()
    44 {
    45     m_client->deviceMotionControllerDestroyed();
     41    deviceMotionClient()->setController(this);
    4642}
    4743
     
    5147}
    5248
    53 void DeviceMotionController::timerFired(Timer<DeviceMotionController>* timer)
     49void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData)
    5450{
    55     ASSERT_UNUSED(timer, timer == &m_timer);
    56     ASSERT(m_client->lastMotion());
    57     m_timer.stop();
    58    
    59     RefPtr<DeviceMotionData> deviceMotionData = m_client->lastMotion();
    60     RefPtr<DeviceMotionEvent> event = DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionData.get());
    61  
    62     Vector<RefPtr<DOMWindow> > listenersVector;
    63     copyToVector(m_newListeners, listenersVector);
    64     m_newListeners.clear();
    65     for (size_t i = 0; i < listenersVector.size(); ++i)
    66         listenersVector[i]->dispatchEvent(event);
    67 }
    68    
    69 void DeviceMotionController::addListener(DOMWindow* window)
    70 {
    71     // If the client already has motion data,
    72     // immediately trigger an asynchronous response.
    73     if (m_client->lastMotion()) {
    74         m_newListeners.add(window);
    75         if (!m_timer.isActive())
    76             m_timer.startOneShot(0);
    77     }
    78    
    79     bool wasEmpty = m_listeners.isEmpty();
    80     m_listeners.add(window);
    81     if (wasEmpty)
    82         m_client->startUpdating();
     51    dispatchDeviceEvent(DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionData));
    8352}
    8453
    85 void DeviceMotionController::removeListener(DOMWindow* window)
     54DeviceMotionClient* DeviceMotionController::deviceMotionClient()
    8655{
    87     m_listeners.remove(window);
    88     m_suspendedListeners.remove(window);
    89     m_newListeners.remove(window);
    90     if (m_listeners.isEmpty())
    91         m_client->stopUpdating();
     56    return static_cast<DeviceMotionClient*>(m_client);
    9257}
    9358
    94 void DeviceMotionController::removeAllListeners(DOMWindow* window)
     59bool DeviceMotionController::hasLastData()
    9560{
    96     // May be called with a DOMWindow that's not a listener.
    97     if (!m_listeners.contains(window))
    98         return;
    99 
    100     m_listeners.removeAll(window);
    101     m_suspendedListeners.removeAll(window);
    102     m_newListeners.remove(window);
    103     if (m_listeners.isEmpty())
    104         m_client->stopUpdating();
     61    return deviceMotionClient()->lastMotion();
    10562}
    10663
    107 void DeviceMotionController::suspendEventsForAllListeners(DOMWindow* window)
     64PassRefPtr<Event> DeviceMotionController::getLastEvent()
    10865{
    109     if (!m_listeners.contains(window))
    110         return;
    111 
    112     int count = m_listeners.count(window);
    113     removeAllListeners(window);
    114     while (count--)
    115         m_suspendedListeners.add(window);
    116 }
    117 
    118 void DeviceMotionController::resumeEventsForAllListeners(DOMWindow* window)
    119 {
    120     if (!m_suspendedListeners.contains(window))
    121         return;
    122 
    123     int count = m_suspendedListeners.count(window);
    124     m_suspendedListeners.removeAll(window);
    125     while (count--)
    126         addListener(window);
    127 }
    128 
    129 void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData)
    130 {
    131     RefPtr<DeviceMotionEvent> event = DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionData);
    132     Vector<RefPtr<DOMWindow> > listenersVector;
    133     copyToVector(m_listeners, listenersVector);
    134     for (size_t i = 0; i < listenersVector.size(); ++i)
    135         listenersVector[i]->dispatchEvent(event);
     66    return DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionClient()->lastMotion());
    13667}
    13768
     
    14071    DEFINE_STATIC_LOCAL(AtomicString, name, ("DeviceMotionController", AtomicString::ConstructFromLiteral));
    14172    return name;
     73}
     74
     75DeviceMotionController* DeviceMotionController::from(Page* page)
     76{
     77    return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, supplementName()));
    14278}
    14379
  • trunk/Source/WebCore/dom/DeviceMotionController.h

    r123451 r135268  
    11/*
    22 * Copyright 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#define DeviceMotionController_h
    2829
    29 #include "DOMWindow.h"
    30 #include "Page.h"
    31 #include "Timer.h"
    32 #include <wtf/HashCountedSet.h>
     30#include "DeviceController.h"
    3331
    3432namespace WebCore {
    3533
     34class DeviceMotionClient;
    3635class DeviceMotionData;
    37 class DeviceMotionClient;
    3836
    39 class DeviceMotionController : public Supplement<Page> {
     37class DeviceMotionController : public DeviceController {
    4038public:
    41     ~DeviceMotionController();
     39    ~DeviceMotionController() { };
    4240
    4341    static PassOwnPtr<DeviceMotionController> create(DeviceMotionClient*);
    4442
    45     void addListener(DOMWindow*);
    46     void removeListener(DOMWindow*);
    47     void removeAllListeners(DOMWindow*);
     43    void didChangeDeviceMotion(DeviceMotionData*);
     44    DeviceMotionClient* deviceMotionClient();
    4845
    49     void suspendEventsForAllListeners(DOMWindow*);
    50     void resumeEventsForAllListeners(DOMWindow*);
    51 
    52     void didChangeDeviceMotion(DeviceMotionData*);
    53 
    54     bool isActive() { return !m_listeners.isEmpty(); }
     46    virtual bool hasLastData() OVERRIDE;
     47    virtual PassRefPtr<Event> getLastEvent() OVERRIDE;
    5548
    5649    static const AtomicString& supplementName();
    57     static DeviceMotionController* from(Page* page) { return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, supplementName())); }
     50    static DeviceMotionController* from(Page*);
    5851    static bool isActiveAt(Page*);
    5952
    6053private:
    6154    explicit DeviceMotionController(DeviceMotionClient*);
    62 
    63     void timerFired(Timer<DeviceMotionController>*);
    64    
    65     DeviceMotionClient* m_client;
    66     typedef HashCountedSet<RefPtr<DOMWindow> > ListenersCountedSet;
    67     ListenersCountedSet m_listeners;
    68     ListenersCountedSet m_suspendedListeners;
    69     typedef HashSet<RefPtr<DOMWindow> > ListenersSet;
    70     ListenersSet m_newListeners;
    71     Timer<DeviceMotionController> m_timer;
    7255};
    7356
  • trunk/Source/WebCore/dom/Document.cpp

    r135242 r135268  
    5252#include "DOMWindow.h"
    5353#include "DateComponents.h"
    54 #include "DeviceMotionController.h"
    55 #include "DeviceOrientationController.h"
    5654#include "DocumentEventQueue.h"
    5755#include "DocumentFragment.h"
     
    21692167{
    21702168    ScriptExecutionContext::suspendActiveDOMObjects(why);
    2171 
    2172 #if ENABLE(DEVICE_ORIENTATION)
    2173     if (!page())
    2174         return;
    2175 
    2176     if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    2177         controller->suspendEventsForAllListeners(domWindow());
    2178 #endif
    21792169}
    21802170
     
    21822172{
    21832173    ScriptExecutionContext::resumeActiveDOMObjects();
    2184 
    2185 #if ENABLE(DEVICE_ORIENTATION)
    2186     if (!page())
    2187         return;
    2188 
    2189     if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    2190         controller->resumeEventsForAllListeners(domWindow());
    2191 #endif
    21922174}
    21932175
  • trunk/Source/WebCore/loader/EmptyClients.h

    r134918 r135268  
    587587public:
    588588    virtual void setController(DeviceMotionController*) { }
    589     virtual void startUpdating() { }
    590     virtual void stopUpdating() { }
    591589    virtual DeviceMotionData* lastMotion() const { return 0; }
    592590    virtual void deviceMotionControllerDestroyed() { }
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r134918 r135268  
    15971597    else if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::deviceMotionEnabled()) {
    15981598        if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    1599             controller->addListener(this);
     1599            controller->addDeviceEventListener(this);
    16001600    } else if (eventType == eventNames().deviceorientationEvent && RuntimeEnabledFeatures::deviceOrientationEnabled()) {
    16011601        if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
     
    16261626    else if (eventType == eventNames().devicemotionEvent) {
    16271627        if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    1628             controller->removeListener(this);
     1628            controller->removeDeviceEventListener(this);
    16291629    } else if (eventType == eventNames().deviceorientationEvent) {
    16301630        if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
     
    16841684#if ENABLE(DEVICE_ORIENTATION)
    16851685    if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    1686         controller->removeAllListeners(this);
     1686        controller->removeAllDeviceEventListeners(this);
    16871687    if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
    16881688        controller->removeAllDeviceEventListeners(this);
Note: See TracChangeset for help on using the changeset viewer.