Bug 1870572 - Use constexpr variables instead of macro to define layout constants. r=layout-reviewers,emilio

Here are some benefits to define those constants in constexpr variables:

1. Better assertion messages. For example, without this patch, the assertion in
   bug 1870103 looks like:

```
Assertion failure: cbSize.BSize(wm) == nscoord((1 << 30) - 1)
```

With this patch, it looks like:

```
Assertion failure: cbSize.BSize(wm) == NS_UNCONSTRAINEDSIZE
```

2. We can use those constants in a debugger.

This patch doesn't change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D196708
This commit is contained in:
Ting-Yu Lin 2023-12-18 18:18:28 +00:00
parent 90733dd7b4
commit db975b21a8
3 changed files with 8 additions and 9 deletions

View file

@ -25,9 +25,9 @@
* 96dpi as possible.
*/
typedef int32_t nscoord;
#define nscoord_MAX nscoord((1 << 30) - 1)
#define nscoord_MIN (-nscoord_MAX)
using nscoord = int32_t;
inline constexpr nscoord nscoord_MAX = (1 << 30) - 1;
inline constexpr nscoord nscoord_MIN = -nscoord_MAX;
namespace mozilla {
struct AppUnit {};

View file

@ -12,7 +12,7 @@
#include "mozilla/gfx/Point.h"
// Maximum allowable size
#define NS_MAXSIZE nscoord_MAX
inline constexpr nscoord NS_MAXSIZE = nscoord_MAX;
typedef mozilla::gfx::IntSize nsIntSize;

View file

@ -10,7 +10,6 @@
#define LayoutConstants_h___
#include "mozilla/EnumSet.h"
#include "nsSize.h" // for NS_MAXSIZE
#include "Units.h"
/**
@ -20,15 +19,15 @@
* values, so user should not depend on the underlying numeric values. If
* new specific use cases arise, define a new constant here.
*/
#define NS_UNCONSTRAINEDSIZE NS_MAXSIZE
inline constexpr nscoord NS_UNCONSTRAINEDSIZE = nscoord_MAX;
// NS_AUTOOFFSET is assumed to have the same value as NS_UNCONSTRAINEDSIZE.
#define NS_AUTOOFFSET NS_UNCONSTRAINEDSIZE
inline constexpr nscoord NS_AUTOOFFSET = NS_UNCONSTRAINEDSIZE;
// +1 is to avoid clamped huge margin values being processed as auto margins
#define NS_AUTOMARGIN (NS_UNCONSTRAINEDSIZE + 1)
inline constexpr nscoord NS_AUTOMARGIN = NS_UNCONSTRAINEDSIZE + 1;
#define NS_INTRINSIC_ISIZE_UNKNOWN nscoord_MIN
inline constexpr nscoord NS_INTRINSIC_ISIZE_UNKNOWN = nscoord_MIN;
namespace mozilla {