diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-10-02 19:32:44 +0200 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-10-05 09:47:01 +0200 |
commit | 08371f8d8532fd82cb59d9eae85cb2e5a835376f (patch) | |
tree | 1586944bfee51ee68cb47e64d630c46f25b44abe /src/styleengine.cc | |
parent | ac56aa678cfe1666b60821f342ccb7b3d3fa7a0d (diff) |
Add support for more CSS units
Implements support for ch, rem, vw, vh, vmin and vmax units of CSS
lengths. For now the units relative to the viewport are only computed
once, and they won't change when the window is resized, but only when
the page is reloaded.
See: https://www.toomanyatoms.com/software/mobilized_dillo.html
Authored-By: dogma
Diffstat (limited to 'src/styleengine.cc')
-rw-r--r-- | src/styleengine.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/styleengine.cc b/src/styleengine.cc index ea818f85..14411da8 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -804,6 +804,32 @@ bool StyleEngine::computeValue (int *dest, CssLength value, Font *font) { /* Doesn't need zoom as it is already applied to font->xHeight */ *dest = roundInt (CSS_LENGTH_VALUE(value) * font->xHeight); return true; + case CSS_LENGTH_TYPE_CH: + *dest = roundInt (CSS_LENGTH_VALUE(value) * font->zeroWidth); + return true; + case CSS_LENGTH_TYPE_REM: + if (stack->size() < 2) { + *dest = 0; + } else { + dw::core::style::Style *root_style = stack->getRef (1)->style; + if (root_style) + *dest = roundInt (CSS_LENGTH_VALUE(value) * root_style->font->size); + else + *dest = 0; + } + return true; + case CSS_LENGTH_TYPE_VW: + *dest = roundInt (CSS_LENGTH_VALUE(value) * layout->getWidthViewport() / 100); + return true; + case CSS_LENGTH_TYPE_VH: + *dest = roundInt (CSS_LENGTH_VALUE(value) * layout->getHeightViewport() / 100); + return true; + case CSS_LENGTH_TYPE_VMIN: + *dest = roundInt (CSS_LENGTH_VALUE(value) * MIN(layout->getWidthViewport(), layout->getHeightViewport()) / 100); + return true; + case CSS_LENGTH_TYPE_VMAX: + *dest = roundInt (CSS_LENGTH_VALUE(value) * MAX(layout->getWidthViewport(), layout->getHeightViewport()) / 100); + return true; case CSS_LENGTH_TYPE_NONE: // length values other than 0 without unit are only allowed // in special cases (line-height) and have to be handled |