diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2023-12-31 20:15:21 +0100 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2023-12-31 20:15:21 +0100 |
commit | 24bcd67df29a5418d05600b038a9283a00e555d2 (patch) | |
tree | 498c15b76afd8a0732af01d578bf43c3428090fd /dw/widget.cc | |
parent | 6f66fd861ef1d1bd583c31c2ce3d9c4a9896ede1 (diff) |
Constraint width with min-width or max-width
When a widget has a parent, the calcFinalWidth() method was not being
called to compute the limits of min-width or max-width given by CSS
rules. The change makes the call to calcFinalWidth in all cases.
Diffstat (limited to 'dw/widget.cc')
-rw-r--r-- | dw/widget.cc | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/dw/widget.cc b/dw/widget.cc index 941779bb..795b4f46 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -2,6 +2,7 @@ * Dillo Widget * * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> + * Copyright 2023 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 @@ -641,28 +642,24 @@ int Widget::getMinWidth (Extremes *extremes, bool forceValue) /** * Return available width including margin/border/padding * (extraSpace?), not only the content width. + * + * If the widget has a parent or a quasiParent, the width computation is + * delegated to the parent first, or the quasiParent later. */ int Widget::getAvailWidth (bool forceValue) { DBG_OBJ_ENTER ("resize", 0, "getAvailWidth", "%s", forceValue ? "true" : "false"); - int width; + int width = -1; + int scrollbarThickness = + layout->canvasHeightGreater ? layout->vScrollbarThickness : 0; + int viewportWidth = layout->viewportWidth - scrollbarThickness; if (parent == NULL && quasiParent == NULL) { DBG_OBJ_MSG ("resize", 1, "no parent, regarding viewport"); DBG_OBJ_MSG_START (); - // TODO Consider nested layouts (e. g. <button>). - - int viewportWidth = - layout->viewportWidth - (layout->canvasHeightGreater ? - layout->vScrollbarThickness : 0); - width = -1; - calcFinalWidth (getStyle (), viewportWidth, NULL, 0, forceValue, &width); - if (width == -1) - width = viewportWidth; - DBG_OBJ_MSG_END (); } else if (parent) { DBG_OBJ_MSG ("resize", 1, "delegated to parent"); @@ -676,6 +673,15 @@ int Widget::getAvailWidth (bool forceValue) DBG_OBJ_MSG_END (); } + /* The refWidth will be used for relative sizes. If not set, use the + * viewport width */ + int refWidth = width == -1 ? viewportWidth : width; + + /* Constraint the width with min-width and max-width */ + calcFinalWidth (getStyle (), refWidth, NULL, 0, forceValue, &width); + if (width == -1) + width = refWidth; + DBG_OBJ_LEAVE_VAL ("%d", width); return width; } |