1 : /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Novell code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Novell Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2006
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Robert O'Callahan <robert@ocallahan.org>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsClientRect.h"
40 : #include "nsContentUtils.h"
41 : #include "nsDOMClassInfoID.h"
42 :
43 : #include "nsPresContext.h"
44 : #include "dombindings.h"
45 :
46 : DOMCI_DATA(ClientRect, nsClientRect)
47 :
48 0 : NS_INTERFACE_TABLE_HEAD(nsClientRect)
49 0 : NS_INTERFACE_TABLE1(nsClientRect, nsIDOMClientRect)
50 0 : NS_INTERFACE_TABLE_TO_MAP_SEGUE
51 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ClientRect)
52 0 : NS_INTERFACE_MAP_END
53 :
54 0 : NS_IMPL_ADDREF(nsClientRect)
55 0 : NS_IMPL_RELEASE(nsClientRect)
56 :
57 0 : nsClientRect::nsClientRect()
58 0 : : mX(0.0), mY(0.0), mWidth(0.0), mHeight(0.0)
59 : {
60 0 : }
61 :
62 : NS_IMETHODIMP
63 0 : nsClientRect::GetLeft(float* aResult)
64 : {
65 0 : *aResult = mX;
66 0 : return NS_OK;
67 : }
68 :
69 : NS_IMETHODIMP
70 0 : nsClientRect::GetTop(float* aResult)
71 : {
72 0 : *aResult = mY;
73 0 : return NS_OK;
74 : }
75 :
76 : NS_IMETHODIMP
77 0 : nsClientRect::GetRight(float* aResult)
78 : {
79 0 : *aResult = mX + mWidth;
80 0 : return NS_OK;
81 : }
82 :
83 : NS_IMETHODIMP
84 0 : nsClientRect::GetBottom(float* aResult)
85 : {
86 0 : *aResult = mY + mHeight;
87 0 : return NS_OK;
88 : }
89 :
90 : NS_IMETHODIMP
91 0 : nsClientRect::GetWidth(float* aResult)
92 : {
93 0 : *aResult = mWidth;
94 0 : return NS_OK;
95 : }
96 :
97 : NS_IMETHODIMP
98 0 : nsClientRect::GetHeight(float* aResult)
99 : {
100 0 : *aResult = mHeight;
101 0 : return NS_OK;
102 : }
103 :
104 : DOMCI_DATA(ClientRectList, nsClientRectList)
105 :
106 1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(nsClientRectList)
107 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsClientRectList)
108 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParent)
109 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
110 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
111 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsClientRectList)
112 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mParent)
113 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
114 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
115 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsClientRectList)
116 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
117 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_END
118 :
119 0 : NS_INTERFACE_TABLE_HEAD(nsClientRectList)
120 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
121 0 : NS_INTERFACE_TABLE1(nsClientRectList, nsIDOMClientRectList)
122 0 : NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsClientRectList)
123 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ClientRectList)
124 0 : NS_INTERFACE_MAP_END
125 :
126 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsClientRectList)
127 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsClientRectList)
128 :
129 :
130 : NS_IMETHODIMP
131 0 : nsClientRectList::GetLength(PRUint32* aLength)
132 : {
133 0 : *aLength = mArray.Count();
134 0 : return NS_OK;
135 : }
136 :
137 : NS_IMETHODIMP
138 0 : nsClientRectList::Item(PRUint32 aIndex, nsIDOMClientRect** aReturn)
139 : {
140 0 : NS_IF_ADDREF(*aReturn = nsClientRectList::GetItemAt(aIndex));
141 0 : return NS_OK;
142 : }
143 :
144 : nsIDOMClientRect*
145 0 : nsClientRectList::GetItemAt(PRUint32 aIndex)
146 : {
147 0 : return mArray.SafeObjectAt(aIndex);
148 : }
149 :
150 : JSObject*
151 0 : nsClientRectList::WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
152 : bool *triedToWrap)
153 : {
154 : return mozilla::dom::binding::ClientRectList::create(cx, scope, this,
155 0 : triedToWrap);
156 : }
157 :
158 : static double
159 0 : RoundFloat(double aValue)
160 : {
161 0 : return floor(aValue + 0.5);
162 : }
163 :
164 : void
165 0 : nsClientRect::SetLayoutRect(const nsRect& aLayoutRect)
166 : {
167 0 : double scale = 65536.0;
168 : // Round to the nearest 1/scale units. We choose scale so it can be represented
169 : // exactly by machine floating point.
170 0 : double scaleInv = 1/scale;
171 0 : double t2pScaled = scale/nsPresContext::AppUnitsPerCSSPixel();
172 0 : double x = RoundFloat(aLayoutRect.x*t2pScaled)*scaleInv;
173 0 : double y = RoundFloat(aLayoutRect.y*t2pScaled)*scaleInv;
174 0 : SetRect(x, y, RoundFloat(aLayoutRect.XMost()*t2pScaled)*scaleInv - x,
175 0 : RoundFloat(aLayoutRect.YMost()*t2pScaled)*scaleInv - y);
176 4392 : }
|