content/base/src/DOMRect.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/dom/DOMRect.h"
michael@0 7
michael@0 8 #include "nsPresContext.h"
michael@0 9 #include "mozilla/dom/DOMRectListBinding.h"
michael@0 10 #include "mozilla/dom/DOMRectBinding.h"
michael@0 11
michael@0 12 using namespace mozilla;
michael@0 13 using namespace mozilla::dom;
michael@0 14
michael@0 15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMRectReadOnly, mParent)
michael@0 16 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectReadOnly)
michael@0 17 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectReadOnly)
michael@0 18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRectReadOnly)
michael@0 19 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 20 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 21 NS_INTERFACE_MAP_END
michael@0 22
michael@0 23 JSObject*
michael@0 24 DOMRectReadOnly::WrapObject(JSContext* aCx)
michael@0 25 {
michael@0 26 MOZ_ASSERT(mParent);
michael@0 27 return DOMRectReadOnlyBinding::Wrap(aCx, this);
michael@0 28 }
michael@0 29
michael@0 30 // -----------------------------------------------------------------------------
michael@0 31
michael@0 32 NS_IMPL_ISUPPORTS_INHERITED(DOMRect, DOMRectReadOnly, nsIDOMClientRect)
michael@0 33
michael@0 34 #define FORWARD_GETTER(_name) \
michael@0 35 NS_IMETHODIMP \
michael@0 36 DOMRect::Get ## _name(float* aResult) \
michael@0 37 { \
michael@0 38 *aResult = float(_name()); \
michael@0 39 return NS_OK; \
michael@0 40 }
michael@0 41
michael@0 42 FORWARD_GETTER(Left)
michael@0 43 FORWARD_GETTER(Top)
michael@0 44 FORWARD_GETTER(Right)
michael@0 45 FORWARD_GETTER(Bottom)
michael@0 46 FORWARD_GETTER(Width)
michael@0 47 FORWARD_GETTER(Height)
michael@0 48
michael@0 49 JSObject*
michael@0 50 DOMRect::WrapObject(JSContext* aCx)
michael@0 51 {
michael@0 52 MOZ_ASSERT(mParent);
michael@0 53 return DOMRectBinding::Wrap(aCx, this);
michael@0 54 }
michael@0 55
michael@0 56 already_AddRefed<DOMRect>
michael@0 57 DOMRect::Constructor(const GlobalObject& aGlobal, ErrorResult& aRV)
michael@0 58 {
michael@0 59 nsRefPtr<DOMRect> obj =
michael@0 60 new DOMRect(aGlobal.GetAsSupports(), 0.0, 0.0, 0.0, 0.0);
michael@0 61 return obj.forget();
michael@0 62 }
michael@0 63
michael@0 64 already_AddRefed<DOMRect>
michael@0 65 DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY,
michael@0 66 double aWidth, double aHeight, ErrorResult& aRV)
michael@0 67 {
michael@0 68 nsRefPtr<DOMRect> obj =
michael@0 69 new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
michael@0 70 return obj.forget();
michael@0 71 }
michael@0 72
michael@0 73 // -----------------------------------------------------------------------------
michael@0 74
michael@0 75 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(DOMRectList, mParent, mArray)
michael@0 76
michael@0 77 NS_INTERFACE_TABLE_HEAD(DOMRectList)
michael@0 78 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 79 NS_INTERFACE_TABLE(DOMRectList, nsIDOMClientRectList)
michael@0 80 NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(DOMRectList)
michael@0 81 NS_INTERFACE_MAP_END
michael@0 82
michael@0 83 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList)
michael@0 84 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList)
michael@0 85
michael@0 86
michael@0 87 NS_IMETHODIMP
michael@0 88 DOMRectList::GetLength(uint32_t* aLength)
michael@0 89 {
michael@0 90 *aLength = Length();
michael@0 91 return NS_OK;
michael@0 92 }
michael@0 93
michael@0 94 NS_IMETHODIMP
michael@0 95 DOMRectList::Item(uint32_t aIndex, nsIDOMClientRect** aReturn)
michael@0 96 {
michael@0 97 NS_IF_ADDREF(*aReturn = Item(aIndex));
michael@0 98 return NS_OK;
michael@0 99 }
michael@0 100
michael@0 101 JSObject*
michael@0 102 DOMRectList::WrapObject(JSContext *cx)
michael@0 103 {
michael@0 104 return mozilla::dom::DOMRectListBinding::Wrap(cx, this);
michael@0 105 }
michael@0 106
michael@0 107 static double
michael@0 108 RoundFloat(double aValue)
michael@0 109 {
michael@0 110 return floor(aValue + 0.5);
michael@0 111 }
michael@0 112
michael@0 113 void
michael@0 114 DOMRect::SetLayoutRect(const nsRect& aLayoutRect)
michael@0 115 {
michael@0 116 double scale = 65536.0;
michael@0 117 // Round to the nearest 1/scale units. We choose scale so it can be represented
michael@0 118 // exactly by machine floating point.
michael@0 119 double scaleInv = 1/scale;
michael@0 120 double t2pScaled = scale/nsPresContext::AppUnitsPerCSSPixel();
michael@0 121 double x = RoundFloat(aLayoutRect.x*t2pScaled)*scaleInv;
michael@0 122 double y = RoundFloat(aLayoutRect.y*t2pScaled)*scaleInv;
michael@0 123 SetRect(x, y, RoundFloat(aLayoutRect.XMost()*t2pScaled)*scaleInv - x,
michael@0 124 RoundFloat(aLayoutRect.YMost()*t2pScaled)*scaleInv - y);
michael@0 125 }

mercurial