Bug 734855 - Rename DeviceMotion to DeviceSensors. Review comments address r=mwu
authorDoug Turner <dougt@dougt.org>
Sat, 24 Mar 2012 17:30:03 -0700
changeset 93583 b3b3928b2c0faf3c5d24a56a4812aa86e9ccd0a3
parent 93582 df108e67c87ac98ea770de65ac97dfb4f587f70a
child 93584 3e4735893504f2fc57f68f9596e5fa5a53717d38
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs734855
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 734855 - Rename DeviceMotion to DeviceSensors. Review comments address r=mwu
content/events/src/nsEventListenerManager.cpp
dom/base/nsGlobalWindow.h
dom/system/nsDeviceSensors.cpp
dom/system/nsDeviceSensors.h
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -32,16 +32,20 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/Hal.h"
 #include "mozilla/HalSensor.h"
+
+// Microsoft's API Name hackery sucks
+#undef CreateEvent
+
 #include "nsISupports.h"
 #include "nsGUIEvent.h"
 #include "nsDOMEvent.h"
 #include "nsEventListenerManager.h"
 #include "nsCaret.h"
 #include "nsIDOMNSEvent.h"
 #include "nsIDOMEventListener.h"
 #include "nsITextControlFrame.h"
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -514,17 +514,16 @@ public:
   virtual bool TakeFocus(bool aFocus, PRUint32 aFocusMethod);
   virtual void SetReadyForFocus();
   virtual void PageHidden();
   virtual nsresult DispatchAsyncHashchange(nsIURI *aOldURI, nsIURI *aNewURI);
   virtual nsresult DispatchSyncPopState();
 
   virtual void EnableDeviceSensor(PRUint32 aType);
   virtual void DisableDeviceSensor(PRUint32 aType);
-  nsTArray<PRUint32> mEnabledSensors;
 
   virtual nsresult SetArguments(nsIArray *aArguments, nsIPrincipal *aOrigin);
 
   static bool DOMWindowDumpEnabled();
 
   void MaybeForgiveSpamCount();
   bool IsClosedOrClosing() {
     return (mIsClosed ||
@@ -985,16 +984,18 @@ protected:
   // will be stored in mDialogDisabled variable.
   TimeStamp                     mLastDialogQuitTime;
   bool                          mDialogDisabled;
 
   nsRefPtr<nsDOMMozURLProperty> mURLProperty;
 
   nsTHashtable<nsPtrHashKey<nsDOMEventTargetHelper> > mEventTargetObjects;
 
+  nsTArray<PRUint32> mEnabledSensors;
+
   friend class nsDOMScriptableHelper;
   friend class nsDOMWindowUtils;
   friend class PostMessageEvent;
 
   static WindowByIdTable* sWindowsById;
   static bool sWarnedAboutWindowInternal;
 };
 
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -168,24 +168,27 @@ NS_IMETHODIMP nsDeviceSensors::AddWindow
 }
 
 NS_IMETHODIMP nsDeviceSensors::RemoveWindowListener(PRUint32 aType, nsIDOMWindow *aWindow)
 {
   if (mWindowListeners[aType]->IndexOf(aWindow) == NoIndex)
     return NS_OK;
 
   mWindowListeners[aType]->RemoveElement(aWindow);
+
+  if (mWindowListeners[aType]->Length() == 0)
+    UnregisterSensorObserver((SensorType)aType, this);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDeviceSensors::RemoveWindowAsListener(nsIDOMWindow *aWindow)
 {
   for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
-    if (IsSensorEnabled(i))
-        RemoveWindowListener((SensorType)i, aWindow);
+    RemoveWindowListener((SensorType)i, aWindow);
   }
   return NS_OK;
 }
 
 void 
 nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData)
 {
   if (!mEnabled)
--- a/dom/system/nsDeviceSensors.h
+++ b/dom/system/nsDeviceSensors.h
@@ -69,19 +69,16 @@ public:
   virtual ~nsDeviceSensors();
 
   void Notify(const mozilla::hal::SensorData& aSensorData);
 
 private:
   // sensor -> window listener
   nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
   
-  // window -> sensortype enabled
-  nsDataHashtable<nsUint32HashKey, nsTArray<PRUint32 > > mSensorsEnabled;
-
   void FireDOMOrientationEvent(class nsIDOMDocument *domDoc, 
                                class nsIDOMEventTarget *target,
                                double alpha,
                                double beta,
                                double gamma);
 
   void FireDOMMotionEvent(class nsIDOMDocument *domDoc, 
                           class nsIDOMEventTarget *target,