mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 783934 - Final Version: Add events onconnected and ondisconnected in BluetoothDevice, r=qdot, sr=mrbkap
This commit is contained in:
parent
e992387408
commit
c07731cc1b
@ -30,13 +30,17 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothDevice,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(propertychanged)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(propertychanged)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(connected)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(disconnected)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothDevice,
|
||||
nsDOMEventTargetHelper)
|
||||
tmp->Unroot();
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(propertychanged)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(propertychanged)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(connected)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(disconnected)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothDevice)
|
||||
@ -170,9 +174,29 @@ BluetoothDevice::Notify(const BluetoothSignal& aData)
|
||||
// Get BluetoothNamedValue, make sure array length is 1
|
||||
BluetoothNamedValue v = aData.value().get_ArrayOfBluetoothNamedValue()[0];
|
||||
nsString name = v.name();
|
||||
SetPropertyByValue(v);
|
||||
nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(name);
|
||||
e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged"));
|
||||
|
||||
if (name.EqualsLiteral("Connected")) {
|
||||
bool isConnected = v.value();
|
||||
nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nullptr, nullptr);
|
||||
nsresult rv;
|
||||
if (isConnected) {
|
||||
rv = event->InitEvent(NS_LITERAL_STRING("connected"), false, false);
|
||||
} else {
|
||||
rv = event->InitEvent(NS_LITERAL_STRING("disconnected"), false, false);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to init the connected/disconnected event!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
event->SetTrusted(true);
|
||||
bool dummy;
|
||||
DispatchEvent(event, &dummy);
|
||||
} else {
|
||||
SetPropertyByValue(v);
|
||||
nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(name);
|
||||
e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged"));
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
nsCString warningMsg;
|
||||
@ -231,3 +255,5 @@ BluetoothDevice::GetUuids(JSContext* aCx, jsval* aUuids)
|
||||
}
|
||||
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothDevice, propertychanged)
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothDevice, connected)
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothDevice, disconnected)
|
||||
|
@ -75,6 +75,8 @@ private:
|
||||
nsTArray<nsString> mUuids;
|
||||
|
||||
NS_DECL_EVENT_HANDLER(propertychanged)
|
||||
NS_DECL_EVENT_HANDLER(connected)
|
||||
NS_DECL_EVENT_HANDLER(disconnected)
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "nsIDOMEventTarget.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(24c64513-9587-46c6-b718-bb9b9a754b0d)]
|
||||
[scriptable, builtinclass, uuid(647bb64c-8d45-4642-b86b-b3b80d4c8c25)]
|
||||
interface nsIDOMBluetoothDevice : nsIDOMEventTarget
|
||||
{
|
||||
readonly attribute DOMString address;
|
||||
@ -16,4 +16,6 @@ interface nsIDOMBluetoothDevice : nsIDOMEventTarget
|
||||
readonly attribute bool connected;
|
||||
readonly attribute bool paired;
|
||||
attribute nsIDOMEventListener onpropertychanged;
|
||||
attribute nsIDOMEventListener onconnected;
|
||||
attribute nsIDOMEventListener ondisconnected;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user