summaryrefslogtreecommitdiff
path: root/dom/camera/DOMCameraDetectedFace.cpp
blob: 72efa1744f6c65a15037db0afbcd4cb2db17c00c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "DOMCameraDetectedFace.h"
#include "Navigator.h"

using namespace mozilla;
using namespace mozilla::dom;

NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMCameraDetectedFace, mParent,
                                      mBounds, mLeftEye, mRightEye, mMouth)

NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMCameraDetectedFace)
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMCameraDetectedFace)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMCameraDetectedFace)
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

/* static */
bool
DOMCameraDetectedFace::HasSupport(JSContext* aCx, JSObject* aGlobal)
{
  return Navigator::HasCameraSupport(aCx, aGlobal);
}

JSObject*
DOMCameraDetectedFace::WrapObject(JSContext* aCx)
{
  return CameraDetectedFaceBinding::Wrap(aCx, this);
}

DOMCameraDetectedFace::DOMCameraDetectedFace(nsISupports* aParent,
                                             const ICameraControl::Face& aFace)
  : mParent(aParent)
  , mId(aFace.id)
  , mScore(aFace.score)
  , mBounds(new DOMRect(this))
{
  mBounds->SetRect(aFace.bound.left,
                   aFace.bound.top,
                   aFace.bound.right - aFace.bound.left,
                   aFace.bound.bottom - aFace.bound.top);

  if (aFace.hasLeftEye) {
    mLeftEye = new DOMPoint(this, aFace.leftEye.x, aFace.leftEye.y);
  }
  if (aFace.hasRightEye) {
    mRightEye = new DOMPoint(this, aFace.rightEye.x, aFace.rightEye.y);
  }
  if (aFace.hasMouth) {
    mMouth = new DOMPoint(this, aFace.mouth.x, aFace.mouth.y);
  }
}