Bug 1733673 [wpt PR 31066] - Annotate CSS Transforms WPT reftests as fuzzy where...
[gecko.git] / dom / midi / MIDIInput.cpp
blob5947f08f41e16258a7c986fc0d1aec06ad5ea508
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/MIDIInput.h"
8 #include "mozilla/dom/Document.h"
9 #include "mozilla/dom/MIDIPortChild.h"
10 #include "mozilla/dom/MIDIInputBinding.h"
11 #include "mozilla/dom/MIDIMessageEvent.h"
12 #include "mozilla/dom/MIDIMessageEventBinding.h"
13 #include "nsDOMNavigationTiming.h"
15 namespace mozilla::dom {
17 MIDIInput::MIDIInput(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent)
18 : MIDIPort(aWindow, aMIDIAccessParent) {}
20 // static
21 MIDIInput* MIDIInput::Create(nsPIDOMWindowInner* aWindow,
22 MIDIAccess* aMIDIAccessParent,
23 const MIDIPortInfo& aPortInfo,
24 const bool aSysexEnabled) {
25 MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) ==
26 MIDIPortType::Input);
27 auto port = new MIDIInput(aWindow, aMIDIAccessParent);
28 if (!port->Initialize(aPortInfo, aSysexEnabled)) {
29 return nullptr;
31 return port;
34 JSObject* MIDIInput::WrapObject(JSContext* aCx,
35 JS::Handle<JSObject*> aGivenProto) {
36 return MIDIInput_Binding::Wrap(aCx, this, aGivenProto);
39 void MIDIInput::Receive(const nsTArray<MIDIMessage>& aMsgs) {
40 nsCOMPtr<Document> doc = GetOwner() ? GetOwner()->GetDoc() : nullptr;
41 if (!doc) {
42 NS_WARNING("No document available to send MIDIMessageEvent to!");
43 return;
45 for (auto& msg : aMsgs) {
46 RefPtr<MIDIMessageEvent> event(
47 MIDIMessageEvent::Constructor(this, msg.timestamp(), msg.data()));
48 DispatchTrustedEvent(event);
52 EventHandlerNonNull* MIDIInput::GetOnmidimessage() {
53 return GetEventHandler(nsGkAtoms::onmidimessage);
56 void MIDIInput::SetOnmidimessage(EventHandlerNonNull* aCallback) {
57 SetEventHandler(nsGkAtoms::onmidimessage, aCallback);
58 if (mPort->ConnectionState() != MIDIPortConnectionState::Open) {
59 mPort->SendOpen();
63 } // namespace mozilla::dom