Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/midi/MIDIInput.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "mozilla/dom/MIDIInput.h"
8
#include "mozilla/dom/MIDIPortChild.h"
9
#include "mozilla/dom/MIDIInputBinding.h"
10
#include "mozilla/dom/MIDIMessageEvent.h"
11
#include "mozilla/dom/MIDIMessageEventBinding.h"
12
#include "nsDOMNavigationTiming.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
MIDIInput::MIDIInput(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent)
18
  : MIDIPort(aWindow, aMIDIAccessParent)
19
0
{
20
0
}
21
22
//static
23
MIDIInput*
24
MIDIInput::Create(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent,
25
                  const MIDIPortInfo& aPortInfo, const bool aSysexEnabled)
26
0
{
27
0
  MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) == MIDIPortType::Input);
28
0
  auto port = new MIDIInput(aWindow, aMIDIAccessParent);
29
0
  if (!port->Initialize(aPortInfo, aSysexEnabled)) {
30
0
    return nullptr;
31
0
  }
32
0
  return port;
33
0
}
34
35
JSObject*
36
MIDIInput::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
37
0
{
38
0
  return MIDIInput_Binding::Wrap(aCx, this, aGivenProto);
39
0
}
40
41
void
42
MIDIInput::Receive(const nsTArray<MIDIMessage>& aMsgs)
43
0
{
44
0
  nsCOMPtr<nsIDocument> doc = GetOwner() ? GetOwner()->GetDoc() : nullptr;
45
0
  if (!doc) {
46
0
    NS_WARNING("No document available to send MIDIMessageEvent to!");
47
0
    return;
48
0
  }
49
0
  for (auto& msg:aMsgs) {
50
0
    RefPtr<MIDIMessageEvent> event(
51
0
      MIDIMessageEvent::Constructor(this, msg.timestamp(), msg.data()));
52
0
    DispatchTrustedEvent(event);
53
0
  }
54
0
}
55
56
EventHandlerNonNull*
57
MIDIInput::GetOnmidimessage()
58
0
{
59
0
  return GetEventHandler(nsGkAtoms::onmidimessage);
60
0
}
61
62
void
63
MIDIInput::SetOnmidimessage(EventHandlerNonNull* aCallback)
64
0
{
65
0
  SetEventHandler(nsGkAtoms::onmidimessage, aCallback);
66
0
  if (mPort->ConnectionState() != MIDIPortConnectionState::Open) {
67
0
    mPort->SendOpen();
68
0
  }
69
0
}
70
71
72
} // namespace dom
73
} // namespace mozilla