Convert nscoord into a struct / class
Categories
(Core :: Layout, task, P3)
Tracking
()
People
(Reporter: TYLin, Unassigned)
References
Details
(Whiteboard: [layout:backlog:quality])
Attachments
(1 file)
3.21 KB,
patch
|
Details | Diff | Splinter Review |
Comment 1•5 years ago
|
||
(In reply to Ting-Yu Lin [:TYLin] (UTC+8) (Traveling Nov 23 - Dec 15) from comment #0)
nscoord
can be converted into a struct or class for type safety, better saturation operations, etc. If we are worrying about performance, we can use struct or class in debug build only.
I don't think we should do this in debug builds only. It's a recipee to get build errors with the build configuration that you're not using :)
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Reporter | ||
Comment 2•5 years ago
|
||
Reporter | ||
Updated•5 years ago
|
Reporter | ||
Updated•5 years ago
|
Reporter | ||
Comment 3•5 years ago
•
|
||
Reporter | ||
Comment 4•5 years ago
|
||
It would be good to collect more feedbacks before proceeding since it takes a lot of effort to audit all the type incompatibility of nscoord and int32_t all over our codebase.
Emilio, do you have any idea about how to do 3. in Comment 3.
Botond, you invented the type hierarchy layout/base/Units.h
. Is the patch in comment 3 closer to what you'd envisioned if nscoord
were a struct?
Comment 5•5 years ago
•
|
||
I think this is a promising direction, yes. A couple of potential suggestions to consider:
- We could go a step further and derive
nscoord
fromIntCoordTyped<AppUnits>
, whereAppUnits
is a new type similar toCSSPixel
. This would allow some additional strong typing, such as usingScaleFactor
to represent the app units to CSS pixel and app units to device pixel scales (and make them harder to mix up). - We could introduce a
nsCoordTyped
class that behaves as described above, and leavenscoord
alone, and gradually transition usages ofnscoord
tonsCoordTyped
, thereby avoiding a large transition all at once.
Comment 6•5 years ago
|
||
(In reply to Ting-Yu Lin [:TYLin] (UTC-7) from comment #3)
Right now given nscoord is only an int so places that need to interface with it just use Au(..)
or to_i32_au()
. In practice, just using .value
/ .mValue
would work.
A somewhat nicer solution would be to make Au
#[repr(C)]
around here, and then alias them using cbindgen-types
/ export.rename
in ServoBindings.toml
and cbindgen.toml
respectively.
Then code like that would read like Size2D::new(area.width, area.height)
, which would be ideal.
Updated•2 years ago
|
Description
•