diff options
-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; } |