RESOLVED FIXED 220214
[LFC Display] Introduce type-safe rect types for the display tree
https://bugs.webkit.org/show_bug.cgi?id=220214
Summary [LFC Display] Introduce type-safe rect types for the display tree
Simon Fraser (smfr)
Reported 2020-12-31 13:08:49 PST
[LFC Display] Introduce typesafe rect types for the display tree
Attachments
Patch (15.48 KB, patch)
2020-12-31 13:10 PST, Simon Fraser (smfr)
no flags
Patch (34.45 KB, patch)
2021-08-14 20:00 PDT, Simon Fraser (smfr)
no flags
Simon Fraser (smfr)
Comment 1 2020-12-31 13:10:58 PST
Simon Fraser (smfr)
Comment 2 2020-12-31 13:11:23 PST
Feedback welcome on this approach.
Sam Weinig
Comment 3 2021-01-03 11:40:22 PST
Comment on attachment 416870 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=416870&action=review > Source/WebCore/display/DisplayGeometryTypes.h:43 > +template<typename T> class TypedFloatRect : public FloatRect { > +}; > + > +enum AbsoluteCoordinates { }; > +using AbsoluteFloatRect = TypedFloatRect<AbsoluteCoordinates>; > + > + > +enum ViewCoordinates { }; > +using ViewFloatRect = TypedFloatRect<ViewCoordinates>; I'm not sure having the template adds much here. Maybe instead just have `class AbsoluteFloatRect : public FloatRect { };` etc. For the intersection() and unionRect() functions below, then you could just have: template<typename T> inline auto intersection(T& a, const T& b) -> typename std::enable_if_t<std::is_base_of_v<FloatRect, T>, T> { T c = a; c.intersect(b); return c; } (you might just be able to replace the definition in FloatRect with this generic one actually, since std::is_base_of_v<FloatRect, FloatRect> == true).
Simon Fraser (smfr)
Comment 4 2021-01-03 11:41:56 PST
The templates were intended to prevent implicit conversion, but maybe I can achieve the same with explicit constructors etc?
Sam Weinig
Comment 5 2021-01-04 08:46:33 PST
(In reply to Simon Fraser (smfr) from comment #4) > The templates were intended to prevent implicit conversion, but maybe I can > achieve the same with explicit constructors etc? Implicit conversion in which direction? Just by having the subclass you will avoid implicit conversion of FloatRect to AbsoluteFloatRect. As an example void foo(const AbsoluteFloatRect& rect) { } FloatRect rect; foo(rect); This would fail to compile. However, this would still work: void bar(const FloatRect& rect) { } AbsoluteFloatRect rect; bar(rect);
Radar WebKit Bug Importer
Comment 6 2021-01-07 13:09:24 PST
Simon Fraser (smfr)
Comment 7 2021-08-14 20:00:46 PDT
EWS
Comment 8 2021-08-15 08:44:35 PDT
Committed r281061 (240523@main): <https://commits.webkit.org/240523@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 435555 [details].
Note You need to log in before you can comment on or make changes to this bug.