summaryrefslogtreecommitdiff
path: root/gfx/2d/BaseMargin.h
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/2d/BaseMargin.h')
-rw-r--r--gfx/2d/BaseMargin.h73
1 files changed, 70 insertions, 3 deletions
diff --git a/gfx/2d/BaseMargin.h b/gfx/2d/BaseMargin.h
index e7203b0af..33afd4658 100644
--- a/gfx/2d/BaseMargin.h
+++ b/gfx/2d/BaseMargin.h
@@ -9,6 +9,57 @@
#include "Types.h"
namespace mozilla {
+
+/**
+ * Sides represents a set of physical sides.
+ */
+struct Sides final {
+ Sides() : mBits(0) {}
+ explicit Sides(SideBits aSideBits)
+ {
+ MOZ_ASSERT((aSideBits & ~eSideBitsAll) == 0, "illegal side bits");
+ mBits = aSideBits;
+ }
+ bool IsEmpty() const { return mBits == 0; }
+ bool Top() const { return mBits & eSideBitsTop; }
+ bool Right() const { return mBits & eSideBitsRight; }
+ bool Bottom() const { return mBits & eSideBitsBottom; }
+ bool Left() const { return mBits & eSideBitsLeft; }
+ bool Contains(SideBits aSideBits) const
+ {
+ MOZ_ASSERT((aSideBits & ~eSideBitsAll) == 0, "illegal side bits");
+ return (mBits & aSideBits) == aSideBits;
+ }
+ Sides operator|(Sides aOther) const
+ {
+ return Sides(SideBits(mBits | aOther.mBits));
+ }
+ Sides operator|(SideBits aSideBits) const
+ {
+ return *this | Sides(aSideBits);
+ }
+ Sides& operator|=(Sides aOther)
+ {
+ mBits |= aOther.mBits;
+ return *this;
+ }
+ Sides& operator|=(SideBits aSideBits)
+ {
+ return *this |= Sides(aSideBits);
+ }
+ bool operator==(Sides aOther) const
+ {
+ return mBits == aOther.mBits;
+ }
+ bool operator!=(Sides aOther) const
+ {
+ return !(*this == aOther);
+ }
+
+private:
+ uint8_t mBits;
+};
+
namespace gfx {
/**
@@ -17,7 +68,7 @@ namespace gfx {
*/
template <class T, class Sub>
struct BaseMargin {
- typedef mozilla::css::Side SideT;
+ typedef mozilla::Side SideT; // because we have a method named Side
// Do not change the layout of these members; the Side() methods below
// depend on this order.
@@ -38,11 +89,27 @@ struct BaseMargin {
T& Side(SideT aSide) {
// This is ugly!
- return *(&top + aSide);
+ return *(&top + T(aSide));
}
T Side(SideT aSide) const {
// This is ugly!
- return *(&top + aSide);
+ return *(&top + T(aSide));
+ }
+
+ void ApplySkipSides(Sides aSkipSides)
+ {
+ if (aSkipSides.Top()) {
+ top = 0;
+ }
+ if (aSkipSides.Right()) {
+ right = 0;
+ }
+ if (aSkipSides.Bottom()) {
+ bottom = 0;
+ }
+ if (aSkipSides.Left()) {
+ left = 0;
+ }
}
// Overloaded operators. Note that '=' isn't defined so we'll get the