Bug 734325 - implement compassneedscalibration event. r=jdm

This commit is contained in:
Doug Turner 2012-03-13 16:57:09 -07:00
parent 0648b34ca3
commit cb5e3dd11b
12 changed files with 106 additions and 8 deletions

View File

@ -753,6 +753,16 @@ ContentChild::RecvDeviceMotionChanged(const long int& type,
return true;
}
bool
ContentChild::RecvNeedsCalibration()
{
nsCOMPtr<nsIDeviceMotionUpdate> dmu =
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
if (dmu)
dmu->NeedsCalibration();
return true;
}
bool
ContentChild::RecvScreenSizeChanged(const gfxIntSize& size)
{

View File

@ -162,6 +162,8 @@ public:
const double& x, const double& y,
const double& z);
virtual bool RecvNeedsCalibration();
virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
virtual bool RecvFlushMemory(const nsString& reason);

View File

@ -1291,6 +1291,12 @@ ContentParent::OnMotionChange(nsIDeviceMotionData *aDeviceData) {
return NS_OK;
}
NS_IMETHODIMP
ContentParent::NeedsCalibration() {
unused << SendNeedsCalibration();
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -134,6 +134,7 @@ child:
AddPermission(Permission permission);
DeviceMotionChanged(long type, double x, double y, double z);
NeedsCalibration();
ScreenSizeChanged(gfxIntSize size);

View File

@ -261,6 +261,64 @@ nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
return NS_OK;
}
NS_IMETHODIMP
nsDeviceMotion::NeedsCalibration()
{
if (!mEnabled)
return NS_ERROR_NOT_INITIALIZED;
nsCOMArray<nsIDeviceMotionListener> listeners = mListeners;
for (PRUint32 i = listeners.Count(); i > 0 ; ) {
--i;
listeners[i]->NeedsCalibration();
}
nsCOMArray<nsIDOMWindow> windowListeners;
for (PRUint32 i = 0; i < mWindowListeners.Length(); i++) {
windowListeners.AppendObject(mWindowListeners[i]);
}
for (PRUint32 i = windowListeners.Count(); i > 0 ; ) {
--i;
// check to see if this window is in the background. if
// it is, don't send any device motion to it.
nsCOMPtr<nsPIDOMWindow> pwindow = do_QueryInterface(windowListeners[i]);
if (!pwindow ||
!pwindow->GetOuterWindow() ||
pwindow->GetOuterWindow()->IsBackground())
continue;
nsCOMPtr<nsIDOMDocument> domdoc;
windowListeners[i]->GetDocument(getter_AddRefs(domdoc));
if (domdoc) {
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(windowListeners[i]);
FireNeedsCalibration(domdoc, target);
}
}
return NS_OK;
}
void
nsDeviceMotion::FireNeedsCalibration(nsIDOMDocument *domdoc,
nsIDOMEventTarget *target)
{
nsCOMPtr<nsIDOMEvent> event;
domdoc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
if (!event)
return;
event->InitEvent(NS_LITERAL_STRING("compassneedscalibration"), true, false);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
if (privateEvent)
privateEvent->SetTrusted(true);
bool defaultActionEnabled = true;
target->DispatchEvent(event, &defaultActionEnabled);
}
void
nsDeviceMotion::FireDOMOrientationEvent(nsIDOMDocument *domdoc,
nsIDOMEventTarget *target,

View File

@ -76,6 +76,9 @@ private:
protected:
void FireNeedsCalibration(nsIDOMDocument *domdoc,
nsIDOMEventTarget *target);
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
class nsIDOMEventTarget *target,
double alpha,

View File

@ -2608,6 +2608,8 @@ abstract public class GeckoApp
// accelerometer
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
Log.w(LOGTAG, "onAccuracyChanged "+accuracy);
GeckoAppShell.sendEventToGecko(GeckoEvent.createSensorAccuracyEvent(accuracy));
}
public void onSensorChanged(SensorEvent event)

View File

@ -89,6 +89,7 @@ public class GeckoEvent {
private static final int PROXIMITY_EVENT = 23;
private static final int ACTIVITY_RESUMING = 24;
private static final int SCREENSHOT = 25;
private static final int SENSOR_ACCURACY = 26;
public static final int IME_COMPOSITION_END = 0;
public static final int IME_COMPOSITION_BEGIN = 1;
@ -292,9 +293,9 @@ public class GeckoEvent {
case Sensor.TYPE_ORIENTATION:
event = new GeckoEvent(ORIENTATION_EVENT);
event.mAlpha = -s.values[0];
event.mBeta = -s.values[1];
event.mGamma = -s.values[2];
event.mAlpha = s.values[0];
event.mBeta = s.values[1];
event.mGamma = s.values[2];
break;
case Sensor.TYPE_PROXIMITY:
@ -408,4 +409,10 @@ public class GeckoEvent {
event.mMetaState = tabId;
return event;
}
public static GeckoEvent createSensorAccuracyEvent(int accuracy) {
GeckoEvent event = new GeckoEvent(SENSOR_ACCURACY);
event.mFlags = accuracy;
return event;
}
}

View File

@ -473,6 +473,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
break;
}
case SENSOR_ACCURACY:
case ACTIVITY_STOPPING:
case ACTIVITY_START:
case ACTIVITY_PAUSING:

View File

@ -549,6 +549,7 @@ public:
PROXIMITY_EVENT = 23,
ACTIVITY_RESUMING = 24,
SCREENSHOT = 25,
SENSOR_ACCURACY = 26,
dummy_java_enum_list_end
};

View File

@ -331,6 +331,11 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
NativeEventCallback();
break;
case AndroidGeckoEvent::SENSOR_ACCURACY:
if (curEvent->Flags() == 0)
gDeviceMotionSystem->NeedsCalibration();
break;
case AndroidGeckoEvent::ACCELERATION_EVENT:
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
-curEvent->X(),
@ -340,9 +345,9 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
case AndroidGeckoEvent::ORIENTATION_EVENT:
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
-curEvent->Alpha(),
curEvent->Beta(),
curEvent->Gamma());
curEvent->Alpha(),
-curEvent->Beta(),
-curEvent->Gamma());
mPendingOrientationEvents = false;
break;

View File

@ -51,10 +51,11 @@ interface nsIDeviceMotionData : nsISupports
readonly attribute double z;
};
[scriptable, uuid(f01774a2-3b7e-4630-954b-196dc178221f)]
[scriptable, uuid(D29EA788-CCB6-4875-88E0-32A34BB71CBB)]
interface nsIDeviceMotionListener : nsISupports
{
void onMotionChange(in nsIDeviceMotionData aMotionData);
void needsCalibration();
};
[scriptable, uuid(B6E5C463-AAA6-44E2-BD07-7A7DC6192E68)]
@ -73,9 +74,10 @@ interface nsIDeviceMotion : nsISupports
/* for use by IPC system to notify non-chrome processes of
* device motion events
*/
[uuid(d3a56f08-b7b1-46bb-9dc1-fc3665a3631a)]
[uuid(C12C0157-DCFF-41B5-83F3-89179BF6CA4E)]
interface nsIDeviceMotionUpdate : nsIDeviceMotion
{
/* must be called on the main thread or else */
void deviceMotionChanged(in unsigned long type, in double x, in double y, in double z);
void needsCalibration();
};