Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/gfx/BaseMargin.h
Line
Count
Source (jump to first uncovered line)
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 MOZILLA_GFX_BASEMARGIN_H_
8
#define MOZILLA_GFX_BASEMARGIN_H_
9
10
#include <ostream>
11
12
#include "Types.h"
13
14
namespace mozilla {
15
16
/**
17
 * Sides represents a set of physical sides.
18
 */
19
struct Sides final {
20
0
  Sides() : mBits(0) {}
21
  explicit Sides(SideBits aSideBits)
22
0
  {
23
0
    MOZ_ASSERT((aSideBits & ~eSideBitsAll) == 0, "illegal side bits");
24
0
    mBits = aSideBits;
25
0
  }
26
0
  bool IsEmpty() const { return mBits == 0; }
27
0
  bool Top()     const { return (mBits & eSideBitsTop) != 0; }
28
0
  bool Right()   const { return (mBits & eSideBitsRight) != 0; }
29
0
  bool Bottom()  const { return (mBits & eSideBitsBottom) != 0; }
30
0
  bool Left()    const { return (mBits & eSideBitsLeft) != 0; }
31
  bool Contains(SideBits aSideBits) const
32
0
  {
33
0
    MOZ_ASSERT((aSideBits & ~eSideBitsAll) == 0, "illegal side bits");
34
0
    return (mBits & aSideBits) == aSideBits;
35
0
  }
36
  Sides operator|(Sides aOther) const
37
0
  {
38
0
    return Sides(SideBits(mBits | aOther.mBits));
39
0
  }
40
  Sides operator|(SideBits aSideBits) const
41
0
  {
42
0
    return *this | Sides(aSideBits);
43
0
  }
44
  Sides& operator|=(Sides aOther)
45
0
  {
46
0
    mBits |= aOther.mBits;
47
0
    return *this;
48
0
  }
49
  Sides& operator|=(SideBits aSideBits)
50
0
  {
51
0
    return *this |= Sides(aSideBits);
52
0
  }
53
  bool operator==(Sides aOther) const
54
0
  {
55
0
    return mBits == aOther.mBits;
56
0
  }
57
  bool operator!=(Sides aOther) const
58
0
  {
59
0
    return !(*this == aOther);
60
0
  }
61
62
private:
63
  uint8_t mBits;
64
};
65
66
namespace gfx {
67
68
/**
69
 * Do not use this class directly. Subclass it, pass that subclass as the
70
 * Sub parameter, and only use that subclass.
71
 */
72
template <class T, class Sub>
73
struct BaseMargin {
74
  typedef mozilla::Side SideT; // because we have a method named Side
75
76
  // Do not change the layout of these members; the Side() methods below
77
  // depend on this order.
78
  T top, right, bottom, left;
79
80
  // Constructors
81
0
  BaseMargin() : top(0), right(0), bottom(0), left(0) {}
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> >::BaseMargin()
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::BaseMargin()
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::CSSPixel, float> >::BaseMargin()
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::gfx::UnknownUnits, float> >::BaseMargin()
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::BaseMargin()
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel> >::BaseMargin()
82
  BaseMargin(T aTop, T aRight, T aBottom, T aLeft) :
83
0
      top(aTop), right(aRight), bottom(aBottom), left(aLeft) {}
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::BaseMargin(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::gfx::UnknownUnits, float> >::BaseMargin(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::BaseMargin(int, int, int, int)
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> >::BaseMargin(int, int, int, int)
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::CSSPixel, float> >::BaseMargin(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ParentLayerPixel, float> >::BaseMargin(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel> >::BaseMargin(int, int, int, int)
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::LayoutDevicePixel, float> >::BaseMargin(float, float, float, float)
84
85
  void SizeTo(T aTop, T aRight, T aBottom, T aLeft)
86
0
  {
87
0
    top = aTop; right = aRight; bottom = aBottom; left = aLeft;
88
0
  }
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::SizeTo(int, int, int, int)
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::gfx::UnknownUnits, float> >::SizeTo(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> >::SizeTo(int, int, int, int)
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel> >::SizeTo(int, int, int, int)
89
90
0
  T LeftRight() const { return left + right; }
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::LeftRight() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> >::LeftRight() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::CSSPixel, float> >::LeftRight() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::LeftRight() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ParentLayerPixel, float> >::LeftRight() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::LayoutDevicePixel, float> >::LeftRight() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel> >::LeftRight() const
91
0
  T TopBottom() const { return top + bottom; }
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::TopBottom() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> >::TopBottom() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::CSSPixel, float> >::TopBottom() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::TopBottom() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ParentLayerPixel, float> >::TopBottom() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::LayoutDevicePixel, float> >::TopBottom() const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel> >::TopBottom() const
92
93
0
  T& Side(SideT aSide) {
94
0
    // This is ugly!
95
0
    return *(&top + int(aSide));
96
0
  }
97
0
  T Side(SideT aSide) const {
98
0
    // This is ugly!
99
0
    return *(&top + int(aSide));
100
0
  }
101
102
  void ApplySkipSides(Sides aSkipSides)
103
0
  {
104
0
    if (aSkipSides.Top()) {
105
0
      top = 0;
106
0
    }
107
0
    if (aSkipSides.Right()) {
108
0
      right = 0;
109
0
    }
110
0
    if (aSkipSides.Bottom()) {
111
0
      bottom = 0;
112
0
    }
113
0
    if (aSkipSides.Left()) {
114
0
      left = 0;
115
0
    }
116
0
  }
117
118
  // Overloaded operators. Note that '=' isn't defined so we'll get the
119
  // compiler generated default assignment operator
120
0
  bool operator==(const Sub& aMargin) const {
121
0
    return top == aMargin.top && right == aMargin.right &&
122
0
           bottom == aMargin.bottom && left == aMargin.left;
123
0
  }
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::operator==(mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> const&) const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::operator==(nsMargin const&) const
124
0
  bool operator!=(const Sub& aMargin) const {
125
0
    return !(*this == aMargin);
126
0
  }
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::operator!=(nsMargin const&) const
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::operator!=(mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> const&) const
127
0
  Sub operator+(const Sub& aMargin) const {
128
0
    return Sub(top + aMargin.top, right + aMargin.right,
129
0
               bottom + aMargin.bottom, left + aMargin.left);
130
0
  }
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::operator+(nsMargin const&) const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> >::operator+(mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits> const&) const
131
0
  Sub operator-(const Sub& aMargin) const {
132
0
    return Sub(top - aMargin.top, right - aMargin.right,
133
0
               bottom - aMargin.bottom, left - aMargin.left);
134
0
  }
Unexecuted instantiation: mozilla::gfx::BaseMargin<float, mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> >::operator-(mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float> const&) const
Unexecuted instantiation: mozilla::gfx::BaseMargin<int, nsMargin>::operator-(nsMargin const&) const
135
0
  Sub& operator+=(const Sub& aMargin) {
136
0
    top += aMargin.top;
137
0
    right += aMargin.right;
138
0
    bottom += aMargin.bottom;
139
0
    left += aMargin.left;
140
0
    return *static_cast<Sub*>(this);
141
0
  }
142
143
  friend std::ostream& operator<<(std::ostream& aStream,
144
      const BaseMargin& aMargin) {
145
    return aStream << '(' << aMargin.top << ',' << aMargin.right << ','
146
                  << aMargin.bottom << ',' << aMargin.left << ')';
147
  }
148
};
149
150
} // namespace gfx
151
} // namespace mozilla
152
153
#endif /* MOZILLA_GFX_BASEMARGIN_H_ */