1 /* -*- Mode: C++; 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
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/
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
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
45 nscoord top
, right
, bottom
, left
;
49 nsMargin(const nsMargin
& aMargin
) {*this = aMargin
;}
50 nsMargin(nscoord aLeft
, nscoord aTop
,
51 nscoord aRight
, nscoord aBottom
) {left
= aLeft
; top
= aTop
;
52 right
= aRight
; bottom
= aBottom
;}
54 void SizeTo(nscoord aLeft
, nscoord aTop
,
55 nscoord aRight
, nscoord aBottom
) {left
= aLeft
; top
= aTop
;
56 right
= aRight
; bottom
= aBottom
;}
57 void SizeBy(nscoord aLeft
, nscoord aTop
,
58 nscoord aRight
, nscoord aBottom
) {left
+= aLeft
; top
+= aTop
;
59 right
+= aRight
; bottom
+= aBottom
;}
61 nscoord
LeftRight() const { return left
+ right
; }
62 nscoord
TopBottom() const { return top
+ bottom
; }
64 #if (NS_SIDE_TOP == 0) && (NS_SIDE_RIGHT == 1) && (NS_SIDE_BOTTOM == 2) && (NS_SIDE_LEFT == 3)
65 nscoord
& side(PRUint8 aSide
) {
66 NS_PRECONDITION(aSide
<= NS_SIDE_LEFT
, "Out of range side");
67 return *(&top
+ aSide
);
70 nscoord
side(PRUint8 aSide
) const {
71 NS_PRECONDITION(aSide
<= NS_SIDE_LEFT
, "Out of range side");
72 return *(&top
+ aSide
);
75 #error "Somebody changed the side constants."
78 // Overloaded operators. Note that '=' isn't defined so we'll get the
79 // compiler generated default assignment operator
80 PRBool
operator==(const nsMargin
& aMargin
) const {
81 return (PRBool
) ((left
== aMargin
.left
) && (top
== aMargin
.top
) &&
82 (right
== aMargin
.right
) && (bottom
== aMargin
.bottom
));
84 PRBool
operator!=(const nsMargin
& aMargin
) const {
85 return (PRBool
) ((left
!= aMargin
.left
) || (top
!= aMargin
.top
) ||
86 (right
!= aMargin
.right
) || (bottom
!= aMargin
.bottom
));
88 nsMargin
operator+(const nsMargin
& aMargin
) const {
89 return nsMargin(left
+ aMargin
.left
, top
+ aMargin
.top
,
90 right
+ aMargin
.right
, bottom
+ aMargin
.bottom
);
92 nsMargin
operator-(const nsMargin
& aMargin
) const {
93 return nsMargin(left
- aMargin
.left
, top
- aMargin
.top
,
94 right
- aMargin
.right
, bottom
- aMargin
.bottom
);
96 nsMargin
& operator+=(const nsMargin
& aMargin
) {left
+= aMargin
.left
;
98 right
+= aMargin
.right
;
99 bottom
+= aMargin
.bottom
;
101 nsMargin
& operator-=(const nsMargin
& aMargin
) {left
-= aMargin
.left
;
103 right
-= aMargin
.right
;
104 bottom
-= aMargin
.bottom
;
108 #ifdef NS_COORD_IS_FLOAT
110 PRInt32 top
, right
, bottom
, left
;
114 nsIntMargin(const nsIntMargin
& aMargin
) {*this = aMargin
;}
115 nsIntMargin(PRInt32 aLeft
, PRInt32 aTop
,
116 PRInt32 aRight
, PRInt32 aBottom
) {left
= aLeft
; top
= aTop
;
117 right
= aRight
; bottom
= aBottom
;}
120 typedef nsMargin nsIntMargin
;
123 #endif /* NSMARGIN_H */