Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/DOMQuad.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/DOMQuad.h"
8
9
#include "mozilla/dom/DOMQuadBinding.h"
10
#include "mozilla/dom/DOMPoint.h"
11
#include "mozilla/dom/DOMRect.h"
12
#include <algorithm>
13
14
using namespace mozilla;
15
using namespace mozilla::dom;
16
using namespace mozilla::gfx;
17
18
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMQuad, mParent, mBounds, mPoints[0],
19
                                      mPoints[1], mPoints[2], mPoints[3])
20
21
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMQuad, AddRef)
22
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMQuad, Release)
23
24
DOMQuad::DOMQuad(nsISupports* aParent, CSSPoint aPoints[4])
25
  : mParent(aParent)
26
0
{
27
0
  for (uint32_t i = 0; i < 4; ++i) {
28
0
    mPoints[i] = new DOMPoint(aParent, aPoints[i].x, aPoints[i].y);
29
0
  }
30
0
}
31
32
DOMQuad::DOMQuad(nsISupports* aParent)
33
  : mParent(aParent)
34
0
{
35
0
}
36
37
DOMQuad::~DOMQuad()
38
0
{
39
0
}
40
41
JSObject*
42
DOMQuad::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
43
0
{
44
0
  return DOMQuad_Binding::Wrap(aCx, this, aGivenProto);
45
0
}
46
47
already_AddRefed<DOMQuad>
48
DOMQuad::Constructor(const GlobalObject& aGlobal,
49
                     const DOMPointInit& aP1,
50
                     const DOMPointInit& aP2,
51
                     const DOMPointInit& aP3,
52
                     const DOMPointInit& aP4,
53
                     ErrorResult& aRV)
54
0
{
55
0
  RefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports());
56
0
  obj->mPoints[0] = DOMPoint::FromPoint(aGlobal, aP1);
57
0
  obj->mPoints[1] = DOMPoint::FromPoint(aGlobal, aP2);
58
0
  obj->mPoints[2] = DOMPoint::FromPoint(aGlobal, aP3);
59
0
  obj->mPoints[3] = DOMPoint::FromPoint(aGlobal, aP4);
60
0
  return obj.forget();
61
0
}
62
63
already_AddRefed<DOMQuad>
64
DOMQuad::Constructor(const GlobalObject& aGlobal, const DOMRectReadOnly& aRect,
65
                     ErrorResult& aRV)
66
0
{
67
0
  CSSPoint points[4];
68
0
  Float x = aRect.X(), y = aRect.Y(), w = aRect.Width(), h = aRect.Height();
69
0
  points[0] = CSSPoint(x, y);
70
0
  points[1] = CSSPoint(x + w, y);
71
0
  points[2] = CSSPoint(x + w, y + h);
72
0
  points[3] = CSSPoint(x, y + h);
73
0
  RefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports(), points);
74
0
  return obj.forget();
75
0
}
76
77
void
78
DOMQuad::GetHorizontalMinMax(double* aX1, double* aX2) const
79
0
{
80
0
  double x1, x2;
81
0
  x1 = x2 = Point(0)->X();
82
0
  for (uint32_t i = 1; i < 4; ++i) {
83
0
    double x = Point(i)->X();
84
0
    x1 = std::min(x1, x);
85
0
    x2 = std::max(x2, x);
86
0
  }
87
0
  *aX1 = x1;
88
0
  *aX2 = x2;
89
0
}
90
91
void
92
DOMQuad::GetVerticalMinMax(double* aY1, double* aY2) const
93
0
{
94
0
  double y1, y2;
95
0
  y1 = y2 = Point(0)->Y();
96
0
  for (uint32_t i = 1; i < 4; ++i) {
97
0
    double y = Point(i)->Y();
98
0
    y1 = std::min(y1, y);
99
0
    y2 = std::max(y2, y);
100
0
  }
101
0
  *aY1 = y1;
102
0
  *aY2 = y2;
103
0
}
104
105
DOMRectReadOnly*
106
DOMQuad::Bounds()
107
0
{
108
0
  if (!mBounds) {
109
0
    mBounds = GetBounds();
110
0
  }
111
0
  return mBounds;
112
0
}
113
114
already_AddRefed<DOMRectReadOnly>
115
DOMQuad::GetBounds() const
116
0
{
117
0
  double x1, x2;
118
0
  double y1, y2;
119
0
120
0
  GetHorizontalMinMax(&x1, &x2);
121
0
  GetVerticalMinMax(&y1, &y2);
122
0
123
0
  RefPtr<DOMRectReadOnly> rval = new DOMRectReadOnly(GetParentObject(),
124
0
                                                     x1, y1, x2 - x1, y2 - y1);
125
0
  return rval.forget();
126
0
}
127
128
void
129
DOMQuad::ToJSON(DOMQuadJSON& aInit)
130
0
{
131
0
  aInit.mP1.Construct(RefPtr<DOMPoint>(P1()).forget());
132
0
  aInit.mP2.Construct(RefPtr<DOMPoint>(P2()).forget());
133
0
  aInit.mP3.Construct(RefPtr<DOMPoint>(P3()).forget());
134
0
  aInit.mP4.Construct(RefPtr<DOMPoint>(P4()).forget());
135
0
}