Some thoughts on the usage of the constants in LayoutConstants.h
Categories
(Core :: Layout, defect, P5)
Tracking
()
Tracking | Status | |
---|---|---|
firefox69 | --- | fixed |
People
(Reporter: TYLin, Assigned: TYLin)
Details
Attachments
(2 files)
Inspired by dholbert's comment in https://phabricator.services.mozilla.com/D29616?id=98435#inline-172862,
nscoord_MAX is semantically "giant number", whereas NS_INTRINSICSIZE is semantically "sentinel value, whose underlying representation you should not depend on"
So here's my thoughts on the constants define in LayoutConstants.h:
- We should add document to
NS_UNCONSTRAINEDSIZE
to warn people not to rely on its value, and point tonscoord_MAX
if a giant number is needed. - We should just replace
NS_MAXSIZE
withnscoord_MAX
because it doens't have many usage per https://searchfox.org/mozilla-central/search?q=symbol:M_1833fe56%2CM_a4599bec68c82a18&redirect=false - Do we really need
NS_INTRINSICSIZE
,NS_AUTOHEIGHT
,NS_AUTOOFFSET
? Since they're all equal toNS_UNCONSTRAINEDSIZE
, can we just remove them? Without proper documentation, it's difficult (at least to me) to choose when to use which constant. Mnemonics are good unless we have a proper way to enforce them, but they are allnscoord
...
Any other thoughts?
Comment 1•6 years ago
|
||
(In reply to Ting-Yu Lin [:TYLin] (UTC-7) from comment #0)
- We should add document to
NS_UNCONSTRAINEDSIZE
to warn people not to rely on its value, and point tonscoord_MAX
if a giant number is needed.
Documenting it and advising people to not depend on its numeric value is good,
however I don't think we should use nscoord_MAX
directly in layout (in general).
If a new symbolic value is needed for some purpose then it's better to add it
to this header with documentation on what it represents symbolically.
- We should just replace
NS_MAXSIZE
withnscoord_MAX
because it doens't have many usage per https://searchfox.org/mozilla-central/search?q=symbol:M_1833fe56%2CM_a4599bec68c82a18&redirect=false
I don't think replacing it with nscoord_MAX
is an improvement, since neither
convey any semantics or intention. We should probably replace NS_MAXSIZE
with some of the other symbolic values instead, or introduce new ones that
represent the specific use cases, if needed. (Like ASK_FOR_BASELINE
.)
- Do we really need
NS_INTRINSICSIZE
,NS_AUTOHEIGHT
,NS_AUTOOFFSET
? Since they're all equal toNS_UNCONSTRAINEDSIZE
, can we just remove them? Without proper documentation, it's difficult (at least to me) to choose when to use which constant. Mnemonics are good unless we have a proper way to enforce them, but they are allnscoord
...
NS_AUTOHEIGHT
and NS_INTRINSICSIZE
can probably be replaced by
NS_UNCONSTRAINEDSIZE
, since they have (roughly) the same meaning.
NS_AUTOOFFSET
is a specific use case though, that we might want to
keep as a distinct constant.
Assignee | ||
Comment 2•5 years ago
|
||
This patch is generated by the following steps.
-
Manually delete NS_INTRINSICSIZE and NS_AUTOHEIGHT in LayoutConstants.
-
Run the following script.
#!/bin/bash
function rename() {
find .
-type f
! -path "./obj*"
! -path "./.git"
! -path "./.hg"
( -name ".cpp" -or
-name ".h" )
-exec sed -i -e "s/$1/$2/g" "{}" ;
}
rename NS_INTRINSICSIZE NS_UNCONSTRAINEDSIZE
rename NS_AUTOHEIGHT NS_UNCONSTRAINEDSIZE
- ./mach clang-format
Assignee | ||
Comment 3•5 years ago
|
||
Depends on D31696
Assignee | ||
Updated•5 years ago
|
Comment 5•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/23bbfebbe583
https://hg.mozilla.org/mozilla-central/rev/778464d9aac8
Description
•