New computed value system#188
Conversation
| export struct Viewport { | ||
| // https://drafts.csswg.org/css-values/#small-viewport-size | ||
| RectAu small; | ||
| // https://drafts.csswg.org/css-values/#large-viewport-size | ||
| RectAu large = small; | ||
| // https://drafts.csswg.org/css-values/#dynamic-viewport-size | ||
| RectAu dynamic = small; | ||
| }; |
There was a problem hiding this comment.
This is duplicated from Layout::Viewport
|
|
||
| // FIXME: This should be renamed to changeDisplayArea, and we should make sure that | ||
| // its input is the page box and not the page area. | ||
| void changeViewport(Vec2Au viewport) { | ||
| if (_media.changeViewport(viewport)) | ||
| if (_media.changeDisplayArea(viewport)) | ||
| invalidateRender(); | ||
| } |
There was a problem hiding this comment.
If we renamed it changeDisplayAreana() it should take something like:
using DisplayArea = Union<Viewport, PageArea>
| Driver::RenderResult& ensureRender() { | ||
| if (_render) | ||
| return *_render; | ||
| _render = Driver::render(_document.upgrade(), _media, {.small = _media.viewportSize()}); | ||
| _render = Driver::render(_document.upgrade(), _media, {.small = _media.displayArea()}); | ||
| return *_render; | ||
| } |
There was a problem hiding this comment.
Once we keep the display reana object and the full Viewport, we can pass it here instead of digging in media. Which will be needed for stuff for position: sticky;
| context.media.width / Au{context.media.resolution}, | ||
| context.media.height / Au{context.media.resolution} |
There was a problem hiding this comment.
I don't like that we transformed our resolution object from a nice and rich object to something semantically poor. This looks very confusing if you don't know/remeber that resolution actually means scale.
| struct ComputationContext { | ||
| // FIXME: Fonts are not optional but are wrapped in Opt<> due to the lack of a default constructor. | ||
| // They also require mutability for caching stuff which forces ComputationContext to be passed | ||
| // by mut reference. Ideally they should be replaced by a richer version of | ||
| Opt<Gfx::Font> rootFont = NONE; | ||
| Opt<Gfx::Font> font = NONE; | ||
| WritingMode writingMode = WritingMode::HORIZONTAL_TB; | ||
| Viewport viewport = {.small = {800_au, 600_au}}; /// Viewport of the current box | ||
| Vec2Au displayArea = {800_au, 600_au}; | ||
| }; | ||
|
|
||
| export template <typename T> | ||
| concept Computible = requires(T const& a, ComputationContext& ctx) { | ||
| { toComputed(a, ctx) } -> Meta::Convertible<Computed<T>>; | ||
| }; | ||
|
|
||
| export template <typename T> | ||
| struct IdentityComputed { | ||
| using Type = T; | ||
| }; | ||
|
|
||
| export template <typename T> | ||
| requires Meta::Derive<_Computed<T>, IdentityComputed<T>> | ||
| Computed<T> toComputed(T const& val, ComputationContext&) { | ||
| return val; | ||
| } |
There was a problem hiding this comment.
This needs to be consolidated into a Computable traits or something.
Exemple:
template <>
struct Computable<Foo> {
using Type = FooComputed;
static Type toComputed(Foo const& val, ctx){}
}
And for a simple case, you can just do
template <>
struct Computable<Foo> : IdentityComputable<Foo> {};
| export template <> | ||
| struct _Computed<Ratio> { | ||
| using Type = Number; | ||
| }; | ||
|
|
||
| export Computed<Ratio> toComputed(Ratio const& val, [[maybe_unused]] ComputationContext& ctx) { | ||
| return val.num / val.deno; | ||
| } |
There was a problem hiding this comment.
This should be identity computed since the computed value of a ratio is the pair of numbers
| .orientation = Print::Orientation::LANDSCAPE, | ||
|
|
||
| .resolution = Resolution::fromDpi(96), | ||
| .resolution = Resolution::fromDpi(96).toDppx(), |
There was a problem hiding this comment.
This smell, see comment below and above 😅
| .orientation = Print::Orientation::LANDSCAPE, | ||
|
|
||
| .resolution = Resolution::fromDpi(96), | ||
| .resolution = Resolution::fromDpi(96).toDppx(), |
| .orientation = Print::orientationFromSize(viewport), | ||
|
|
||
| .resolution = Resolution::fromDpi(96), | ||
| .resolution = Resolution::fromDpi(96).toDppx(), |
There was a problem hiding this comment.
Same smell as all the resolution stuff.
| }; | ||
|
|
||
| export template <typename T> | ||
| concept Computible = requires(T const& a, ComputationContext& ctx) { |
No description provided.