diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-03-17 10:16:29 +0100 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-03-17 20:37:33 +0100 |
commit | b0f6a3f055039c5c9c3ab651029a315a88eb6134 (patch) | |
tree | 5728f114444a85a66112d12b4999d263d2cbe94d /dw | |
parent | 90e0e5b3bb0ff3c4dfbdaa6c6a22f2a6196b4f73 (diff) |
Clamp width to min/max in getAvailWidthOfChild()
When the width is set to auto, a different branch is used to compute the
width via getAvailWidth(true). The returned witdh needs to be clamped to
be in the min/max-width CSS range if given, as otherwise it won't be
corrected.
Fixes: https://github.com/dillo-browser/dillo/issues/89
Diffstat (limited to 'dw')
-rw-r--r-- | dw/textblock.cc | 22 | ||||
-rw-r--r-- | dw/widget.cc | 33 |
2 files changed, 49 insertions, 6 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index 27438b6d..0cef739b 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -2,7 +2,7 @@ * Dillo Widget * * Copyright 2005-2007, 2012-2014 Sebastian Geerken <sgeerken@dillo.org> - * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com> + * Copyright 2023-2024 Rodrigo Arias Mallo <rodarima@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -768,12 +768,28 @@ int Textblock::getAvailWidthOfChild (Widget *child, bool forceValue) // No width specified: similar to standard implementation (see // there), but "leftInnerPadding" has to be considered, too. DBG_OBJ_MSG ("resize", 1, "no specification"); - if (forceValue) + if (forceValue) { width = misc::max (getAvailWidth (true) - boxDiffWidth () - leftInnerPadding, 0); - else + + if (width != -1) { + /* Clamp to min-width and max-width if given, taking into + * account leftInnerPadding. */ + int maxWidth = child->calcWidth (child->getStyle()->maxWidth, + -1, this, -1, false); + if (maxWidth != -1 && width > maxWidth - leftInnerPadding) + width = maxWidth - leftInnerPadding; + + int minWidth = child->calcWidth (child->getStyle()->minWidth, + -1, this, -1, false); + if (minWidth != -1 && width < minWidth - leftInnerPadding) + width = minWidth - leftInnerPadding; + } + + } else { width = -1; + } } else width = Widget::getAvailWidthOfChild (child, forceValue); diff --git a/dw/widget.cc b/dw/widget.cc index b778700b..59cbdd9b 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -2,7 +2,7 @@ * Dillo Widget * * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> - * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com> + * Copyright 2023-2024 Rodrigo Arias Mallo <rodarima@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1668,6 +1668,16 @@ int Widget::applyPerHeight (int containerHeight, style::Length perHeight) + boxDiffHeight (); } +/** + * Computes the content width available of a child widget. + * + * @param child The child widget of which the available width will be + * computed. + * @param forceValue If true, computes the width of the child with value + * "auto". Otherwise, it wont. + * + * @return The available width in pixels or -1. + */ int Widget::getAvailWidthOfChild (Widget *child, bool forceValue) { // This is a halfway suitable implementation for all @@ -1681,10 +1691,27 @@ int Widget::getAvailWidthOfChild (Widget *child, bool forceValue) if (child->getStyle()->width == style::LENGTH_AUTO) { DBG_OBJ_MSG ("resize", 1, "no specification"); - if (forceValue) + + /* We only compute when forceValue is true */ + if (forceValue) { width = misc::max (getAvailWidth (true) - boxDiffWidth (), 0); - else + + if (width != -1) { + /* Clamp to min-width and max-width if given */ + int maxWidth = child->calcWidth (child->getStyle()->maxWidth, + -1, this, -1, false); + if (maxWidth != -1 && width > maxWidth) + width = maxWidth; + + int minWidth = child->calcWidth (child->getStyle()->minWidth, + -1, this, -1, false); + if (minWidth != -1 && width < minWidth) + width = minWidth; + } + + } else { width = -1; + } } else { // In most cases, the toplevel widget should be a container, so // the container is non-NULL when the parent is non-NULL. Just |