[LFC Display] Introduce typesafe rect types for the display tree
Created attachment 416870 [details] Patch
Feedback welcome on this approach.
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).
The templates were intended to prevent implicit conversion, but maybe I can achieve the same with explicit constructors etc?
(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);
<rdar://problem/72902364>
Created attachment 435555 [details] Patch
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].