Nothing Special   »   [go: up one dir, main page]

Attachment #8389631: Implement DOMRect (v2) for bug #917755

View | Details | Raw Unified | Return to bug 917755
Collapse All | Expand All

(-)a/content/base/src/DOMRect.cpp (-8 / +35 lines)
Line     Link Here 
 Lines 1-36    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
5
6
#include "DOMRect.h"
6
#include "mozilla/dom/DOMRect.h"
7
7
8
#include "nsPresContext.h"
8
#include "nsPresContext.h"
9
#include "mozilla/dom/DOMRectListBinding.h"
9
#include "mozilla/dom/DOMRectListBinding.h"
10
#include "mozilla/dom/DOMRectBinding.h"
10
#include "mozilla/dom/DOMRectBinding.h"
11
11
12
using namespace mozilla;
12
using namespace mozilla;
13
using namespace mozilla::dom;
13
using namespace mozilla::dom;
14
14
15
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMRect, mParent)
15
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMRectReadOnly, mParent)
16
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRect)
16
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectReadOnly)
17
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRect)
17
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectReadOnly)
18
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRect)
18
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRectReadOnly)
19
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
19
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20
  NS_INTERFACE_MAP_ENTRY(nsIDOMClientRect)
21
  NS_INTERFACE_MAP_ENTRY(nsISupports)
20
  NS_INTERFACE_MAP_ENTRY(nsISupports)
22
NS_INTERFACE_MAP_END
21
NS_INTERFACE_MAP_END
23
22
23
JSObject*
24
DOMRectReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
25
{
26
  MOZ_ASSERT(mParent);
27
  return DOMRectReadOnlyBinding::Wrap(aCx, aScope, this);
28
}
29
30
// -----------------------------------------------------------------------------
31
32
NS_IMPL_ISUPPORTS_INHERITED1(DOMRect, DOMRectReadOnly, nsIDOMClientRect)
33
24
#define FORWARD_GETTER(_name)                                                   \
34
#define FORWARD_GETTER(_name)                                                   \
25
  NS_IMETHODIMP                                                                 \
35
  NS_IMETHODIMP                                                                 \
26
  DOMRect::Get ## _name(float* aResult)                                         \
36
  DOMRect::Get ## _name(float* aResult)                                         \
27
  {                                                                             \
37
  {                                                                             \
28
    *aResult = _name();                                                         \
38
    *aResult = float(_name());                                                  \
29
    return NS_OK;                                                               \
39
    return NS_OK;                                                               \
30
  }
40
  }
31
41
32
FORWARD_GETTER(Left)
42
FORWARD_GETTER(Left)
33
FORWARD_GETTER(Top)
43
FORWARD_GETTER(Top)
34
FORWARD_GETTER(Right)
44
FORWARD_GETTER(Right)
35
FORWARD_GETTER(Bottom)
45
FORWARD_GETTER(Bottom)
36
FORWARD_GETTER(Width)
46
FORWARD_GETTER(Width)
 Lines 38-68   FORWARD_GETTER(Height) Link Here 
38
48
39
JSObject*
49
JSObject*
40
DOMRect::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
50
DOMRect::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
41
{
51
{
42
  MOZ_ASSERT(mParent);
52
  MOZ_ASSERT(mParent);
43
  return DOMRectBinding::Wrap(aCx, aScope, this);
53
  return DOMRectBinding::Wrap(aCx, aScope, this);
44
}
54
}
45
55
56
already_AddRefed<DOMRect>
57
DOMRect::Constructor(const GlobalObject& aGlobal, ErrorResult& aRV)
58
{
59
  nsRefPtr<DOMRect> obj =
60
    new DOMRect(aGlobal.GetAsSupports(), 0.0, 0.0, 0.0, 0.0);
61
  return obj.forget();
62
}
63
64
already_AddRefed<DOMRect>
65
DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY,
66
                     double aWidth, double aHeight, ErrorResult& aRV)
67
{
68
  nsRefPtr<DOMRect> obj =
69
    new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
70
  return obj.forget();
71
}
72
46
// -----------------------------------------------------------------------------
73
// -----------------------------------------------------------------------------
47
74
48
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(DOMRectList, mParent, mArray)
75
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(DOMRectList, mParent, mArray)
49
76
50
NS_INTERFACE_TABLE_HEAD(DOMRectList)
77
NS_INTERFACE_TABLE_HEAD(DOMRectList)
51
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
78
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
52
  NS_INTERFACE_TABLE1(DOMRectList, nsIDOMClientRectList)
79
  NS_INTERFACE_TABLE1(DOMRectList, nsIDOMClientRectList)
53
  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(DOMRectList)
80
  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(DOMRectList)
54
NS_INTERFACE_MAP_END
81
NS_INTERFACE_MAP_END
55
82
56
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList)
83
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList)
57
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList)
84
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList)
58
85
59
86
60
NS_IMETHODIMP    
87
NS_IMETHODIMP
61
DOMRectList::GetLength(uint32_t* aLength)
88
DOMRectList::GetLength(uint32_t* aLength)
62
{
89
{
63
  *aLength = Length();
90
  *aLength = Length();
64
  return NS_OK;
91
  return NS_OK;
65
}
92
}
66
93
67
NS_IMETHODIMP    
94
NS_IMETHODIMP    
68
DOMRectList::Item(uint32_t aIndex, nsIDOMClientRect** aReturn)
95
DOMRectList::Item(uint32_t aIndex, nsIDOMClientRect** aReturn)
(-)a/content/base/src/DOMRect.h (-38 / +95 lines)
Line     Link Here 
 Lines 9-94    Link Here 
9
#include "nsIDOMClientRect.h"
9
#include "nsIDOMClientRect.h"
10
#include "nsIDOMClientRectList.h"
10
#include "nsIDOMClientRectList.h"
11
#include "nsTArray.h"
11
#include "nsTArray.h"
12
#include "nsCOMPtr.h"
12
#include "nsCOMPtr.h"
13
#include "nsAutoPtr.h"
13
#include "nsAutoPtr.h"
14
#include "nsWrapperCache.h"
14
#include "nsWrapperCache.h"
15
#include "nsCycleCollectionParticipant.h"
15
#include "nsCycleCollectionParticipant.h"
16
#include "mozilla/Attributes.h"
16
#include "mozilla/Attributes.h"
17
#include "mozilla/dom/BindingDeclarations.h"
18
#include "mozilla/ErrorResult.h"
19
#include <algorithm>
17
20
18
struct nsRect;
21
struct nsRect;
19
22
20
namespace mozilla {
23
namespace mozilla {
21
namespace dom {
24
namespace dom {
22
25
23
class DOMRect MOZ_FINAL : public nsIDOMClientRect
26
class DOMRectReadOnly : public nsISupports
24
                        , public nsWrapperCache
27
                      , public nsWrapperCache
25
{
28
{
26
public:
29
public:
27
  DOMRect(nsISupports* aParent)
30
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28
    : mParent(aParent), mX(0.0), mY(0.0), mWidth(0.0), mHeight(0.0)
31
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectReadOnly)
32
33
  virtual ~DOMRectReadOnly() {}
34
35
  DOMRectReadOnly(nsISupports* aParent)
36
    : mParent(aParent)
29
  {
37
  {
30
    SetIsDOMBinding();
38
    SetIsDOMBinding();
31
  }
39
  }
32
  virtual ~DOMRect() {}
33
  
34
  void SetRect(float aX, float aY, float aWidth, float aHeight) {
35
    mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight;
36
  }
37
  void SetLayoutRect(const nsRect& aLayoutRect);
38
39
40
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
41
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRect)
42
  NS_DECL_NSIDOMCLIENTRECT
43
44
40
45
  nsISupports* GetParentObject() const
41
  nsISupports* GetParentObject() const
46
  {
42
  {
47
    MOZ_ASSERT(mParent);
43
    MOZ_ASSERT(mParent);
48
    return mParent;
44
    return mParent;
49
  }
45
  }
50
  virtual JSObject* WrapObject(JSContext* aCx,
46
  virtual JSObject* WrapObject(JSContext* aCx,
51
                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
47
                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
52
48
49
  virtual double X() const = 0;
50
  virtual double Y() const = 0;
51
  virtual double Width() const = 0;
52
  virtual double Height() const = 0;
53
53
54
  float Left() const
54
  double Left() const
55
  {
56
    double x = X(), w = Width();
57
    return std::min(x, x + w);
58
  }
59
  double Top() const
60
  {
61
    double y = Y(), h = Height();
62
    return std::min(y, y + h);
63
  }
64
  double Right() const
65
  {
66
    double x = X(), w = Width();
67
    return std::max(x, x + w);
68
  }
69
  double Bottom() const
70
  {
71
    double y = Y(), h = Height();
72
    return std::max(y, y + h);
73
  }
74
75
protected:
76
  nsCOMPtr<nsISupports> mParent;
77
};
78
79
class DOMRect MOZ_FINAL : public DOMRectReadOnly
80
                        , public nsIDOMClientRect
81
{
82
public:
83
  DOMRect(nsISupports* aParent, double aX = 0, double aY = 0,
84
          double aWidth = 0, double aHeight = 0)
85
    : DOMRectReadOnly(aParent)
86
    , mX(aX)
87
    , mY(aY)
88
    , mWidth(aWidth)
89
    , mHeight(aHeight)
90
  {
91
  }
92
  
93
  NS_DECL_ISUPPORTS_INHERITED
94
  NS_DECL_NSIDOMCLIENTRECT
95
96
  static already_AddRefed<DOMRect>
97
  Constructor(const GlobalObject& aGlobal, ErrorResult& aRV);
98
  static already_AddRefed<DOMRect>
99
  Constructor(const GlobalObject& aGlobal, double aX, double aY,
100
              double aWidth, double aHeight, ErrorResult& aRV);
101
102
  virtual JSObject* WrapObject(JSContext* aCx,
103
                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
104
105
  void SetRect(float aX, float aY, float aWidth, float aHeight) {
106
    mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight;
107
  }
108
  void SetLayoutRect(const nsRect& aLayoutRect);
109
110
  virtual double X() const MOZ_OVERRIDE
55
  {
111
  {
56
    return mX;
112
    return mX;
57
  }
113
  }
58
114
  virtual double Y() const MOZ_OVERRIDE
59
  float Top() const
60
  {
115
  {
61
    return mY;
116
    return mY;
62
  }
117
  }
63
118
  virtual double Width() const MOZ_OVERRIDE
64
  float Right() const
65
  {
66
    return mX + mWidth;
67
  }
68
69
  float Bottom() const
70
  {
71
    return mY + mHeight;
72
  }
73
74
  float Width() const
75
  {
119
  {
76
    return mWidth;
120
    return mWidth;
77
  }
121
  }
78
122
  virtual double Height() const MOZ_OVERRIDE
79
  float Height() const
80
  {
123
  {
81
    return mHeight;
124
    return mHeight;
82
  }
125
  }
83
126
127
  void SetX(double aX)
128
  {
129
    mX = aX;
130
  }
131
  void SetY(double aY)
132
  {
133
    mY = aY;
134
  }
135
  void SetWidth(double aWidth)
136
  {
137
    mWidth = aWidth;
138
  }
139
  void SetHeight(double aHeight)
140
  {
141
    mHeight = aHeight;
142
  }
143
84
protected:
144
protected:
85
  nsCOMPtr<nsISupports> mParent;
145
  double mX, mY, mWidth, mHeight;
86
  float mX, mY, mWidth, mHeight;
87
};
146
};
88
147
89
class DOMRectList MOZ_FINAL : public nsIDOMClientRectList,
148
class DOMRectList MOZ_FINAL : public nsIDOMClientRectList,
90
                              public nsWrapperCache
149
                              public nsWrapperCache
91
{
150
{
92
public:
151
public:
93
  DOMRectList(nsISupports *aParent) : mParent(aParent)
152
  DOMRectList(nsISupports *aParent) : mParent(aParent)
94
  {
153
  {
 Lines 140-157   public: Link Here 
140
    aFound = aIndex < mArray.Length();
199
    aFound = aIndex < mArray.Length();
141
    if (!aFound) {
200
    if (!aFound) {
142
      return nullptr;
201
      return nullptr;
143
    }
202
    }
144
    return mArray[aIndex];
203
    return mArray[aIndex];
145
  }
204
  }
146
205
147
protected:
206
protected:
148
  virtual ~DOMRectList() {}
207
  nsTArray<nsRefPtr<DOMRect> > mArray;
149
150
  nsTArray< nsRefPtr<DOMRect> > mArray;
151
  nsCOMPtr<nsISupports> mParent;
208
  nsCOMPtr<nsISupports> mParent;
152
};
209
};
153
210
154
}
211
}
155
}
212
}
156
213
157
#endif /*MOZILLA_DOMRECT_H_*/
214
#endif /*MOZILLA_DOMRECT_H_*/
(-)a/dom/bindings/Bindings.conf (-10 / +14 lines)
Line     Link Here 
 Lines 215-240   DOMInterfaces = { Link Here 
215
    'register': False,
215
    'register': False,
216
},
216
},
217
217
218
'ChromeWorker': {
218
'ChromeWorker': {
219
    'headerFile': 'mozilla/dom/WorkerPrivate.h',
219
    'headerFile': 'mozilla/dom/WorkerPrivate.h',
220
    'nativeType': 'mozilla::dom::workers::ChromeWorkerPrivate',
220
    'nativeType': 'mozilla::dom::workers::ChromeWorkerPrivate',
221
},
221
},
222
222
223
'DOMRectList': {
224
    'headerFile': 'mozilla/dom/DOMRect.h',
225
    'resultNotAddRefed': [ 'item' ]
226
},
227
228
'DOMPointReadOnly': {
229
    'headerFile': 'mozilla/dom/DOMPoint.h',
230
    'concrete': False,
231
},
232
233
'Console': {
223
'Console': {
234
    'implicitJSContext': [ 'trace', 'time', 'timeEnd' ],
224
    'implicitJSContext': [ 'trace', 'time', 'timeEnd' ],
235
},
225
},
236
226
237
'ConvolverNode': {
227
'ConvolverNode': {
238
    'implicitJSContext': [ 'buffer' ],
228
    'implicitJSContext': [ 'buffer' ],
239
    'resultNotAddRefed': [ 'buffer' ],
229
    'resultNotAddRefed': [ 'buffer' ],
240
},
230
},
 Lines 333-348   DOMInterfaces = { Link Here 
333
},
323
},
334
324
335
'DOMException': {
325
'DOMException': {
336
    'binaryNames': {
326
    'binaryNames': {
337
        'message': 'messageMoz',
327
        'message': 'messageMoz',
338
    },
328
    },
339
},
329
},
340
330
331
'DOMPointReadOnly': {
332
    'headerFile': 'mozilla/dom/DOMPoint.h',
333
    'concrete': False,
334
},
335
336
'DOMRectList': {
337
    'headerFile': 'mozilla/dom/DOMRect.h',
338
    'resultNotAddRefed': [ 'item' ]
339
},
340
341
'DOMRectReadOnly': {
342
    'headerFile': 'mozilla/dom/DOMRect.h',
343
},
344
341
'DOMSettableTokenList': {
345
'DOMSettableTokenList': {
342
    'nativeType': 'nsDOMSettableTokenList',
346
    'nativeType': 'nsDOMSettableTokenList',
343
},
347
},
344
348
345
'DOMStringMap': {
349
'DOMStringMap': {
346
    'nativeType': 'nsDOMStringMap'
350
    'nativeType': 'nsDOMStringMap'
347
},
351
},
348
352
(-)a/dom/tests/mochitest/general/test_interfaces.html (+2 lines)
Line     Link Here 
 Lines 311-326   var interfaceNamesInGlobalScope = Link Here 
311
    "DOMPoint",
311
    "DOMPoint",
312
// IMPORTANT: Do not change this list without review from a DOM peer!
312
// IMPORTANT: Do not change this list without review from a DOM peer!
313
    "DOMPointReadOnly",
313
    "DOMPointReadOnly",
314
// IMPORTANT: Do not change this list without review from a DOM peer!
314
// IMPORTANT: Do not change this list without review from a DOM peer!
315
    "DOMRect",
315
    "DOMRect",
316
// IMPORTANT: Do not change this list without review from a DOM peer!
316
// IMPORTANT: Do not change this list without review from a DOM peer!
317
    "DOMRectList",
317
    "DOMRectList",
318
// IMPORTANT: Do not change this list without review from a DOM peer!
318
// IMPORTANT: Do not change this list without review from a DOM peer!
319
    "DOMRectReadOnly",
320
// IMPORTANT: Do not change this list without review from a DOM peer!
319
    "DOMRequest",
321
    "DOMRequest",
320
// IMPORTANT: Do not change this list without review from a DOM peer!
322
// IMPORTANT: Do not change this list without review from a DOM peer!
321
    "DOMSettableTokenList",
323
    "DOMSettableTokenList",
322
// IMPORTANT: Do not change this list without review from a DOM peer!
324
// IMPORTANT: Do not change this list without review from a DOM peer!
323
    "DOMStringList",
325
    "DOMStringList",
324
// IMPORTANT: Do not change this list without review from a DOM peer!
326
// IMPORTANT: Do not change this list without review from a DOM peer!
325
    "DOMStringMap",
327
    "DOMStringMap",
326
// IMPORTANT: Do not change this list without review from a DOM peer!
328
// IMPORTANT: Do not change this list without review from a DOM peer!
(-)a/dom/webidl/DOMRect.webidl (-9 / +27 lines)
Line     Link Here 
 Lines 1-14    Link Here 
1
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
 *
6
 * The origin of this IDL file is
7
 * http://dev.w3.org/fxtf/geometry/
8
 *
9
 * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
10
 * liability, trademark and document use rules apply.
11
 */
5
12
6
interface DOMRect
13
[Constructor,
7
{
14
 Constructor(unrestricted double x, unrestricted double y,
8
  readonly attribute float left;
15
             unrestricted double width, unrestricted double height)]
9
  readonly attribute float top;
16
interface DOMRect : DOMRectReadOnly {
10
  readonly attribute float right;
17
    inherit attribute unrestricted double x;
11
  readonly attribute float bottom;
18
    inherit attribute unrestricted double y;
12
  readonly attribute float width;
19
    inherit attribute unrestricted double width;
13
  readonly attribute float height;
20
    inherit attribute unrestricted double height;
14
};
21
};
22
23
interface DOMRectReadOnly {
24
    readonly attribute unrestricted double x;
25
    readonly attribute unrestricted double y;
26
    readonly attribute unrestricted double width;
27
    readonly attribute unrestricted double height;
28
    readonly attribute unrestricted double top;
29
    readonly attribute unrestricted double right;
30
    readonly attribute unrestricted double bottom;
31
    readonly attribute unrestricted double left;
32
};
(-)a/dom/webidl/LegacyQueryInterface.webidl (-2 lines)
Line     Link Here 
 Lines 19-36   BarProp implements LegacyQueryInterface; Link Here 
19
CaretPosition implements LegacyQueryInterface;
19
CaretPosition implements LegacyQueryInterface;
20
Comment implements LegacyQueryInterface;
20
Comment implements LegacyQueryInterface;
21
Crypto implements LegacyQueryInterface;
21
Crypto implements LegacyQueryInterface;
22
CSSPrimitiveValue implements LegacyQueryInterface;
22
CSSPrimitiveValue implements LegacyQueryInterface;
23
CSSStyleDeclaration implements LegacyQueryInterface;
23
CSSStyleDeclaration implements LegacyQueryInterface;
24
CSSValueList implements LegacyQueryInterface;
24
CSSValueList implements LegacyQueryInterface;
25
DOMImplementation implements LegacyQueryInterface;
25
DOMImplementation implements LegacyQueryInterface;
26
DOMParser implements LegacyQueryInterface;
26
DOMParser implements LegacyQueryInterface;
27
DOMRect implements LegacyQueryInterface;
28
DOMRectList implements LegacyQueryInterface;
29
DOMStringMap implements LegacyQueryInterface;
27
DOMStringMap implements LegacyQueryInterface;
30
DOMTokenList implements LegacyQueryInterface;
28
DOMTokenList implements LegacyQueryInterface;
31
Document implements LegacyQueryInterface;
29
Document implements LegacyQueryInterface;
32
DocumentFragment implements LegacyQueryInterface;
30
DocumentFragment implements LegacyQueryInterface;
33
DocumentType implements LegacyQueryInterface;
31
DocumentType implements LegacyQueryInterface;
34
Element implements LegacyQueryInterface;
32
Element implements LegacyQueryInterface;
35
Event implements LegacyQueryInterface;
33
Event implements LegacyQueryInterface;
36
EventSource implements LegacyQueryInterface;
34
EventSource implements LegacyQueryInterface;

Return to bug 917755