Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/DOMRect.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/DOMRect.h"
8
9
#include "nsPresContext.h"
10
#include "mozilla/dom/DOMRectListBinding.h"
11
#include "mozilla/dom/DOMRectBinding.h"
12
13
using namespace mozilla;
14
using namespace mozilla::dom;
15
16
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMRectReadOnly, mParent)
17
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectReadOnly)
18
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectReadOnly)
19
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRectReadOnly)
20
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
22
0
NS_INTERFACE_MAP_END
23
24
JSObject*
25
DOMRectReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
26
0
{
27
0
  MOZ_ASSERT(mParent);
28
0
  return DOMRectReadOnly_Binding::Wrap(aCx, this, aGivenProto);
29
0
}
30
31
already_AddRefed<DOMRectReadOnly>
32
DOMRectReadOnly::Constructor(const GlobalObject& aGlobal, double aX, double aY,
33
                             double aWidth, double aHeight, ErrorResult& aRv)
34
0
{
35
0
  RefPtr<DOMRectReadOnly> obj =
36
0
    new DOMRectReadOnly(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
37
0
  return obj.forget();
38
0
}
39
40
// -----------------------------------------------------------------------------
41
42
JSObject*
43
DOMRect::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
44
0
{
45
0
  MOZ_ASSERT(mParent);
46
0
  return DOMRect_Binding::Wrap(aCx, this, aGivenProto);
47
0
}
48
49
already_AddRefed<DOMRect>
50
DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY,
51
                     double aWidth, double aHeight, ErrorResult& aRv)
52
0
{
53
0
  RefPtr<DOMRect> obj =
54
0
    new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
55
0
  return obj.forget();
56
0
}
57
58
// -----------------------------------------------------------------------------
59
60
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMRectList, mParent, mArray)
61
62
0
NS_INTERFACE_TABLE_HEAD(DOMRectList)
63
0
  NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
64
0
  NS_INTERFACE_TABLE0(DOMRectList)
65
0
  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(DOMRectList)
66
0
NS_INTERFACE_MAP_END
67
68
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList)
69
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList)
70
71
JSObject*
72
DOMRectList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
73
0
{
74
0
  return mozilla::dom::DOMRectList_Binding::Wrap(cx, this, aGivenProto);
75
0
}
76
77
static double
78
RoundFloat(double aValue)
79
0
{
80
0
  return floor(aValue + 0.5);
81
0
}
82
83
void
84
DOMRect::SetLayoutRect(const nsRect& aLayoutRect)
85
0
{
86
0
  double scale = 65536.0;
87
0
  // Round to the nearest 1/scale units. We choose scale so it can be represented
88
0
  // exactly by machine floating point.
89
0
  double scaleInv = 1/scale;
90
0
  double t2pScaled = scale/AppUnitsPerCSSPixel();
91
0
  double x = RoundFloat(aLayoutRect.x*t2pScaled)*scaleInv;
92
0
  double y = RoundFloat(aLayoutRect.y*t2pScaled)*scaleInv;
93
0
  SetRect(x, y, RoundFloat(aLayoutRect.XMost()*t2pScaled)*scaleInv - x,
94
0
          RoundFloat(aLayoutRect.YMost()*t2pScaled)*scaleInv - y);
95
0
}