Changeset 63312 in webkit
- Timestamp:
- Jul 14, 2010 5:54:49 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r63311 r63312 1 2010-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 1 27 2010-07-14 Yury Semikhatsky <yurys@chromium.org> 2 28 -
trunk/WebCore/dom/DeviceOrientationClient.h
r59935 r63312 29 29 namespace WebCore { 30 30 31 class DeviceOrientation; 32 31 33 class DeviceOrientationClient { 32 34 public: 33 35 virtual void startUpdating() = 0; 34 36 virtual void stopUpdating() = 0; 37 virtual DeviceOrientation* lastOrientation() const = 0; 35 38 36 39 protected: -
trunk/WebCore/dom/DeviceOrientationController.cpp
r62646 r63312 29 29 #if ENABLE(DEVICE_ORIENTATION) 30 30 31 #include "DeviceOrientation.h" 31 32 #include "DeviceOrientationClient.h" 32 33 #include "DeviceOrientationEvent.h" 33 #include <wtf/UnusedParam.h>34 34 35 35 namespace WebCore { … … 41 41 } 42 42 43 void DeviceOrientationController:: onDeviceOrientationChange(double alpha, double beta, double gamma)43 void DeviceOrientationController::addListener(DOMWindow* window) 44 44 { 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 61 void DeviceOrientationController::removeListener(DOMWindow* window) 62 { 63 m_listeners.remove(window); 64 if (m_listeners.isEmpty() && m_client) 65 m_client->stopUpdating(); 66 } 67 68 void 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 79 void 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); 50 86 } 51 87 -
trunk/WebCore/dom/DeviceOrientationController.h
r62646 r63312 27 27 #define DeviceOrientationController_h 28 28 29 #include "DOMWindow.h" 30 #include <wtf/HashCountedSet.h> 31 29 32 namespace WebCore { 30 33 34 class DeviceOrientation; 31 35 class DeviceOrientationClient; 32 36 class Page; … … 36 40 DeviceOrientationController(Page*, DeviceOrientationClient*); 37 41 38 // FIXME: Add methods to start and stop the service. 42 void addListener(DOMWindow*); 43 void removeListener(DOMWindow*); 44 void removeAllListeners(DOMWindow*); 39 45 40 void onDeviceOrientationChange( double alpha, double beta, double gamma);46 void onDeviceOrientationChange(DeviceOrientation*); 41 47 42 48 private: 43 49 Page* m_page; 44 50 DeviceOrientationClient* m_client; 51 typedef HashCountedSet<DOMWindow*> ListenersSet; 52 ListenersSet m_listeners; 45 53 }; 46 54 -
trunk/WebCore/page/DOMWindow.cpp
r62984 r63312 36 36 #include "Chrome.h" 37 37 #include "Console.h" 38 #include "Database.h"39 #include "DatabaseCallback.h"40 38 #include "DOMApplicationCache.h" 41 39 #include "DOMSelection.h" 42 40 #include "DOMTimer.h" 41 #include "Database.h" 42 #include "DatabaseCallback.h" 43 #include "DeviceOrientationController.h" 43 44 #include "PageTransitionEvent.h" 44 45 #include "Document.h" … … 1411 1412 else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this)) 1412 1413 addBeforeUnloadEventListener(this); 1414 #if ENABLE(DEVICE_ORIENTATION) 1415 else if (eventType == eventNames().deviceorientationEvent && frame() && frame()->page()) 1416 frame()->page()->deviceOrientation()->addListener(this); 1417 #endif 1413 1418 1414 1419 return true; … … 1424 1429 else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this)) 1425 1430 removeBeforeUnloadEventListener(this); 1431 #if ENABLE(DEVICE_ORIENTATION) 1432 else if (eventType == eventNames().deviceorientationEvent && frame() && frame()->page()) 1433 frame()->page()->deviceOrientation()->removeListener(this); 1434 #endif 1426 1435 1427 1436 return true; … … 1498 1507 EventTarget::removeAllEventListeners(); 1499 1508 1509 #if ENABLE(DEVICE_ORIENTATION) 1510 if (frame() && frame()->page()) 1511 frame()->page()->deviceOrientation()->removeAllListeners(this); 1512 #endif 1513 1500 1514 removeAllUnloadEventListeners(this); 1501 1515 removeAllBeforeUnloadEventListeners(this);
Note: See TracChangeset
for help on using the changeset viewer.