Changeset 135268 in webkit
- Timestamp:
- Nov 20, 2012 3:09:25 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r135266 r135268 1 2012-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 1 39 2012-11-20 Kentaro Hara <haraken@chromium.org> 2 40 -
trunk/Source/WebCore/dom/DeviceMotionClient.h
r120224 r135268 1 1 /* 2 2 * Copyright 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 27 28 #define DeviceMotionClient_h 28 29 30 #include "DeviceClient.h" 31 29 32 namespace WebCore { 30 33 … … 33 36 class Page; 34 37 35 class DeviceMotionClient {38 class DeviceMotionClient : public DeviceClient { 36 39 public: 37 40 virtual ~DeviceMotionClient() {} 38 41 virtual void setController(DeviceMotionController*) = 0; 39 virtual void startUpdating() = 0;40 virtual void stopUpdating() = 0;41 42 virtual DeviceMotionData* lastMotion() const = 0; 42 43 virtual void deviceMotionControllerDestroyed() = 0; -
trunk/Source/WebCore/dom/DeviceMotionController.cpp
r133976 r135268 1 1 /* 2 2 * Copyright 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 30 31 #include "DeviceMotionData.h" 31 32 #include "DeviceMotionEvent.h" 33 #include "Page.h" 32 34 33 35 namespace WebCore { 34 36 35 37 DeviceMotionController::DeviceMotionController(DeviceMotionClient* client) 36 : m_client(client) 37 , m_timer(this, &DeviceMotionController::timerFired) 38 : DeviceController(client) 38 39 { 39 40 ASSERT(m_client); 40 m_client->setController(this); 41 } 42 43 DeviceMotionController::~DeviceMotionController() 44 { 45 m_client->deviceMotionControllerDestroyed(); 41 deviceMotionClient()->setController(this); 46 42 } 47 43 … … 51 47 } 52 48 53 void DeviceMotionController:: timerFired(Timer<DeviceMotionController>* timer)49 void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData) 54 50 { 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)); 83 52 } 84 53 85 void DeviceMotionController::removeListener(DOMWindow* window)54 DeviceMotionClient* DeviceMotionController::deviceMotionClient() 86 55 { 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); 92 57 } 93 58 94 void DeviceMotionController::removeAllListeners(DOMWindow* window)59 bool DeviceMotionController::hasLastData() 95 60 { 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(); 105 62 } 106 63 107 void DeviceMotionController::suspendEventsForAllListeners(DOMWindow* window)64 PassRefPtr<Event> DeviceMotionController::getLastEvent() 108 65 { 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()); 136 67 } 137 68 … … 140 71 DEFINE_STATIC_LOCAL(AtomicString, name, ("DeviceMotionController", AtomicString::ConstructFromLiteral)); 141 72 return name; 73 } 74 75 DeviceMotionController* DeviceMotionController::from(Page* page) 76 { 77 return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, supplementName())); 142 78 } 143 79 -
trunk/Source/WebCore/dom/DeviceMotionController.h
r123451 r135268 1 1 /* 2 2 * Copyright 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 27 28 #define DeviceMotionController_h 28 29 29 #include "DOMWindow.h" 30 #include "Page.h" 31 #include "Timer.h" 32 #include <wtf/HashCountedSet.h> 30 #include "DeviceController.h" 33 31 34 32 namespace WebCore { 35 33 34 class DeviceMotionClient; 36 35 class DeviceMotionData; 37 class DeviceMotionClient;38 36 39 class DeviceMotionController : public Supplement<Page>{37 class DeviceMotionController : public DeviceController { 40 38 public: 41 ~DeviceMotionController() ;39 ~DeviceMotionController() { }; 42 40 43 41 static PassOwnPtr<DeviceMotionController> create(DeviceMotionClient*); 44 42 45 void addListener(DOMWindow*); 46 void removeListener(DOMWindow*); 47 void removeAllListeners(DOMWindow*); 43 void didChangeDeviceMotion(DeviceMotionData*); 44 DeviceMotionClient* deviceMotionClient(); 48 45 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; 55 48 56 49 static const AtomicString& supplementName(); 57 static DeviceMotionController* from(Page* page) { return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, supplementName())); }50 static DeviceMotionController* from(Page*); 58 51 static bool isActiveAt(Page*); 59 52 60 53 private: 61 54 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;72 55 }; 73 56 -
trunk/Source/WebCore/dom/Document.cpp
r135242 r135268 52 52 #include "DOMWindow.h" 53 53 #include "DateComponents.h" 54 #include "DeviceMotionController.h"55 #include "DeviceOrientationController.h"56 54 #include "DocumentEventQueue.h" 57 55 #include "DocumentFragment.h" … … 2169 2167 { 2170 2168 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 #endif2179 2169 } 2180 2170 … … 2182 2172 { 2183 2173 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 #endif2192 2174 } 2193 2175 -
trunk/Source/WebCore/loader/EmptyClients.h
r134918 r135268 587 587 public: 588 588 virtual void setController(DeviceMotionController*) { } 589 virtual void startUpdating() { }590 virtual void stopUpdating() { }591 589 virtual DeviceMotionData* lastMotion() const { return 0; } 592 590 virtual void deviceMotionControllerDestroyed() { } -
trunk/Source/WebCore/page/DOMWindow.cpp
r134918 r135268 1597 1597 else if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::deviceMotionEnabled()) { 1598 1598 if (DeviceMotionController* controller = DeviceMotionController::from(page())) 1599 controller->add Listener(this);1599 controller->addDeviceEventListener(this); 1600 1600 } else if (eventType == eventNames().deviceorientationEvent && RuntimeEnabledFeatures::deviceOrientationEnabled()) { 1601 1601 if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) … … 1626 1626 else if (eventType == eventNames().devicemotionEvent) { 1627 1627 if (DeviceMotionController* controller = DeviceMotionController::from(page())) 1628 controller->remove Listener(this);1628 controller->removeDeviceEventListener(this); 1629 1629 } else if (eventType == eventNames().deviceorientationEvent) { 1630 1630 if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) … … 1684 1684 #if ENABLE(DEVICE_ORIENTATION) 1685 1685 if (DeviceMotionController* controller = DeviceMotionController::from(page())) 1686 controller->removeAll Listeners(this);1686 controller->removeAllDeviceEventListeners(this); 1687 1687 if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) 1688 1688 controller->removeAllDeviceEventListeners(this);
Note: See TracChangeset
for help on using the changeset viewer.