nsRectAbsolute.h (1699B)
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 #ifndef NSRECTABSOLUTE_H 8 #define NSRECTABSOLUTE_H 9 10 #include "mozilla/gfx/RectAbsolute.h" 11 #include "nsCoord.h" 12 #include "nsMargin.h" 13 #include "nsRect.h" 14 15 struct nsRectAbsolute 16 : public mozilla::gfx::BaseRectAbsolute<nscoord, nsRectAbsolute, nsPoint, 17 nsRect> { 18 typedef mozilla::gfx::BaseRectAbsolute<nscoord, nsRectAbsolute, nsPoint, 19 nsRect> 20 Super; 21 22 nsRectAbsolute() {} 23 nsRectAbsolute(nscoord aX1, nscoord aY1, nscoord aX2, nscoord aY2) 24 : Super(aX1, aY1, aX2, aY2) {} 25 26 MOZ_ALWAYS_INLINE nscoord SafeWidth() const { 27 int64_t width = right; 28 width -= left; 29 return nscoord( 30 std::min<int64_t>(std::numeric_limits<nscoord>::max(), width)); 31 } 32 MOZ_ALWAYS_INLINE nscoord SafeHeight() const { 33 int64_t height = bottom; 34 height -= top; 35 return nscoord( 36 std::min<int64_t>(std::numeric_limits<nscoord>::max(), height)); 37 } 38 39 nsRect ToNSRect() const { 40 return nsRect(left, top, nscoord(SafeWidth()), nscoord(SafeHeight())); 41 } 42 43 [[nodiscard]] nsRectAbsolute UnsafeUnion(const nsRectAbsolute& aRect) const { 44 return Super::Union(aRect); 45 } 46 47 void Inflate(const nsMargin& aMargin) { 48 left -= aMargin.left; 49 top -= aMargin.top; 50 right += aMargin.right; 51 bottom += aMargin.bottom; 52 } 53 }; 54 55 #endif /* NSRECTABSOLUTE_H */