using enum classes for enumerated CSS property values in nsStyleConsts.h
"L. David Baron" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.layout |
|---|---|
| Message-ID | <[email protected]> |
Jesse suggested using enum classes for the values of enumerated CSS
properties, and I tend to agree that this is a good idea. It gives
both stricter typechecking than the current uint8_t (etc.) values,
and better warnings for switch() statements omitting values.
I decided to try this out for box-sizing to see what it would look
like. Patches are linked from:
https://bugzilla.mozilla.org/show_bug.cgi?id=1223653#c1
Interestingly, the typechecking actually caught a real bug, where we
were passing an nscoord (size inside the box-sizing) to a function
that expected a uint8_t (enumerated value of box-sizing property),
because we actually intended to call a different function.
But I'm mainly interested in feedback on:
1. Naming
=========
Do the names I chose seem reasonable? I replaced:
-#define NS_STYLE_BOX_SIZING_CONTENT 0
-#define NS_STYLE_BOX_SIZING_PADDING 1
-#define NS_STYLE_BOX_SIZING_BORDER 2
with:
+namespace mozilla {
+
+enum class StyleBoxSizing : uint8_t {
+ Content,
+ Padding,
+ Border
+};
+
+} // namespace mozilla
so that most caller changes look like:
- case NS_STYLE_BOX_SIZING_BORDER:
+ case StyleBoxSizing::Border:
or like:
if (parent &&
- parent->StylePosition()->mBoxSizing != NS_STYLE_BOX_SIZING_BORDER) {
+ parent->StylePosition()->mBoxSizing != StyleBoxSizing::Border) {
2. Casts
========
Does anybody see a good way to eliminate the casts I needed to use
in the main patch (described in the patch header)?
3. General
==========
Do others agree this is a good idea? And are people ok with it
being done gradually?
-David
--
𝄞 L. David Baron http://dbaron.org/ 𝄂
𝄢 Mozilla https://www.mozilla.org/ 𝄂
Before I built a wall I'd ask to know
What I was walling in or walling out,
And to whom I was like to give offense.
- Robert Frost, Mending Wall (1914)
_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout
signature.asc
(application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJWQtsjAAoJEO/hYSUPhPwhtC0P/06pnp7JledSF/y3xsEj3ZBZ n/5k7YGqt7ad+GDNqcupw1tOuhpPcwMHyY+sfqL8H2iC5bB5jEgQytx5GqQJXP8q G3coRcbj9EbALn6pj5nprnuu823MOr3ZxYenEEQRDpk+NBT20jOQP/Hbt3cq8P7M VaDqOlZprJbTfFajwxP3ydR21Fj/ZbZ0/xS2hWmBpPtKGjskk5aVNAfNthHrhKiU qo2IdvnUM/X3/16U+tLNyzIOLpJ7nFmUf0kFKzW5z+Ewf5s99O/CikAV4ncqzZFO iLHDeF+5HZ1aj4a340CV+eobLRN4yIK+rcs4Xlpmph+2tL3iqGFDZp54fVcZFwfR 1Es8fS9PXi2wDL7mFR1QtgkKsCb4o8WZx7td8RKQ8oemdJGIEQfOiey0X2oWj9Kv ePR09p8JPQBB4TpMwLFoCX1JUvVD9yWuaWI9pM+14GAGnaFWXAinK8pfZxIt7epY knHYy+GBouf2ImhmIrSGpf41AlrfhoSSWBcDdYy3n3IcYO+T6WNaxV30mkjLuOHq Mi5+R62tDsGfxFE47BsXnZty/iXU7sYXeyGe+lm2wHJicVnUn5i+7mwurEB/MrM8 fWwodv/pC9ldv4cNoduS6xrDV7GZ4uSqcstz5XycuJb/6ots9HkHu835348ZblKu aeNOI8rZESmRIIsWBcka =N9Rf -----END PGP SIGNATURE-----