diff options
author | Sebastian Geerken <devnull@localhost> | 2014-07-18 23:25:17 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-07-18 23:25:17 +0200 |
commit | 738c0a53692efc77a6888a2f683c2481ca844628 (patch) | |
tree | 8faef1cb0e1d1d9589c35cb1ac71cbea2da4ac9a | |
parent | 9d9b0c76a3b04a8ea5971e9d9cc8c9cd790b8b49 (diff) |
New dillorc option 'adjust_min_width'. Also fixed bug in textblock extremes calculation.
-rw-r--r-- | dillorc | 3 | ||||
-rw-r--r-- | doc/dw-grows.doc | 8 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 5 | ||||
-rw-r--r-- | dw/widget.cc | 91 | ||||
-rw-r--r-- | dw/widget.hh | 8 | ||||
-rw-r--r-- | src/dillo.cc | 2 | ||||
-rw-r--r-- | src/prefs.c | 1 | ||||
-rw-r--r-- | src/prefs.h | 1 | ||||
-rw-r--r-- | src/prefsparser.cc | 1 |
9 files changed, 94 insertions, 26 deletions
@@ -79,6 +79,9 @@ # Set this to YES to limit the word wrap width to the viewport width #limit_text_width=NO +# If this is set to YES, all CSS size specifications are adjusted so that +# all contents can be displayed. +#adjust_min_width=NO #------------------------------------------------------------------------- # PENALTIES diff --git a/doc/dw-grows.doc b/doc/dw-grows.doc index ddaa926b..79262fab 100644 --- a/doc/dw-grows.doc +++ b/doc/dw-grows.doc @@ -107,6 +107,14 @@ dw::core::Widget::correctExtremes, respectively, is called). *Not* honouring the CSS size specification in all cases could improve readability in some cases, so this could depend on a user preference. +**Update:** There is now a dillorc option <tt>adjust_min_width</tt>, +which is implemented for widths, but not heights (since it is based on +width extremes, but there are currently no height extremes). + +Another problem is that in most cases, there is no clippping, so that +contents may exceed the allocation of the widget, but redrawing is not +necessarily triggered. + **Percentage values for margins and paddings, as well as negative margins** are interesting applications, but have not been considered yet. For negative margins, a new attribute diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 0e492df9..792f7d8a 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -1154,7 +1154,7 @@ void Textblock::handleWordExtremes (int wordIndex) core::Extremes wordExtremes; getWordExtremes (word, &wordExtremes); - DBG_OBJ_MSGF ("construct.paragraph", 1, "extremes: %d (%d) / %d (%d", + DBG_OBJ_MSGF ("construct.paragraph", 1, "extremes: %d (%d) / %d (%d)", wordExtremes.minWidth, wordExtremes.minWidthIntrinsic, wordExtremes.maxWidth, wordExtremes.maxWidthIntrinsic); @@ -1262,7 +1262,8 @@ void Textblock::correctLastWordExtremes () Word *word = words->getLastRef (); if (word->badnessAndPenalty.lineCanBeBroken (1) && (word->flags & Word::UNBREAKABLE_FOR_MIN_WIDTH) == 0) { - paragraphs->getLastRef()->parMin = 0; + paragraphs->getLastRef()->parMin = + paragraphs->getLastRef()->parMinIntrinsic = 0; PRINTF (" => corrected; parMin = %d\n", paragraphs->getLastRef()->parMin); } diff --git a/dw/widget.cc b/dw/widget.cc index 44c02436..628aa2b4 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -62,6 +62,7 @@ void Widget::WidgetImgRenderer::draw (int x, int y, int width, int height) // ---------------------------------------------------------------------- +bool Widget::adjustMinWidth = false; int Widget::CLASS_ID = -1; Widget::Widget () @@ -511,13 +512,38 @@ void Widget::sizeRequest (Requisition *requisition) } /** + * \brief Used to evaluate Widget::adjustMinWidth. + * + * If extremes == NULL, getExtremes is called. + */ +int Widget::getMinWidth (Extremes *extremes) +{ + DBG_OBJ_ENTER0 ("resize", 0, "getMinWidth"); + int minWidth; + + if (adjustMinWidth) { + Extremes extremes2; + if (extremes == NULL) { + getExtremes (&extremes2); + extremes = &extremes2; + } + + minWidth = extremes->minWidthIntrinsic; + } else + minWidth = 0; + + DBG_OBJ_MSGF ("resize", 1, "=> %d", minWidth); + DBG_OBJ_LEAVE (); + + return minWidth; +} + +/** * Return available width including margin/border/padding * (extraSpace?), not only the content width. */ int Widget::getAvailWidth (bool forceValue) { - // TODO Correct by extremes? - DBG_OBJ_ENTER ("resize", 0, "getAvailWidth", "%s", forceValue ? "true" : "false"); @@ -545,7 +571,6 @@ int Widget::getAvailWidth (bool forceValue) DBG_OBJ_MSG ("resize", 1, "no specification"); width = viewportWidth; } - } DBG_OBJ_MSG_END (); } else if (parent) { @@ -560,6 +585,9 @@ int Widget::getAvailWidth (bool forceValue) DBG_OBJ_MSG_END (); } + if (width != -1) + width = misc::max (width, getMinWidth (NULL)); + DBG_OBJ_MSGF ("resize", 1, "=> %d", width); DBG_OBJ_LEAVE (); @@ -625,7 +653,7 @@ int Widget::getAvailHeight (bool forceValue) void Widget::correctRequisition (Requisition *requisition, void (*splitHeightFun) (int, int *, int *)) { - // TODO Correct by extremes? + // TODO Correct height by ... not extremes, but ...? (Height extremes?) DBG_OBJ_ENTER ("resize", 0, "correctRequisition", "%d * (%d + %d), ...", requisition->width, requisition->ascent, @@ -636,7 +664,9 @@ void Widget::correctRequisition (Requisition *requisition, DBG_OBJ_MSGF ("resize", 1, "absolute width: %dpx", style::absLengthVal (getStyle()->width)); requisition->width = - style::absLengthVal (getStyle()->width) + boxDiffWidth (); + misc::max (style::absLengthVal (getStyle()->width) + + boxDiffWidth (), + getMinWidth (NULL)); } else if (style::isPerLength (getStyle()->width)) { DBG_OBJ_MSGF ("resize", 1, "percentage width: %g%%", 100 * style::perLengthVal_useThisOnlyForDebugging @@ -644,9 +674,11 @@ void Widget::correctRequisition (Requisition *requisition, int viewportWidth = layout->viewportWidth - (layout->canvasHeightGreater ? layout->vScrollbarThickness : 0); - requisition->width = applyPerWidth (viewportWidth, getStyle()->width); + requisition->width = + misc::max (applyPerWidth (viewportWidth, getStyle()->width), + getMinWidth (NULL)); } - + // TODO Perhaps split first, then add box ascent and descent. if (style::isAbsLength (getStyle()->height)) { DBG_OBJ_MSGF ("resize", 1, "absolute height: %dpx", @@ -683,8 +715,6 @@ void Widget::correctRequisition (Requisition *requisition, void Widget::correctExtremes (Extremes *extremes) { - // TODO Extremes only corrected? - DBG_OBJ_ENTER ("resize", 0, "correctExtremes", "%d (%d) / %d (%d)", extremes->minWidth, extremes->minWidthIntrinsic, extremes->maxWidth, extremes->maxWidthIntrinsic); @@ -692,13 +722,16 @@ void Widget::correctExtremes (Extremes *extremes) if (container == NULL && quasiParent == NULL) { if (style::isAbsLength (getStyle()->width)) extremes->minWidth = extremes->maxWidth = - style::absLengthVal (getStyle()->width) + boxDiffWidth (); + misc::max (style::absLengthVal (getStyle()->width) + + boxDiffWidth (), + getMinWidth (extremes)); else if (style::isPerLength (getStyle()->width)) { int viewportWidth = layout->viewportWidth - (layout->canvasHeightGreater ? layout->vScrollbarThickness : 0); extremes->minWidth = extremes->maxWidth = - applyPerWidth (viewportWidth, getStyle()->width); + misc::max (applyPerWidth (viewportWidth, getStyle()->width), + getMinWidth (extremes)); } } else if (container) container->correctExtremesOfChild (this, extremes); @@ -1285,6 +1318,9 @@ int Widget::getAvailWidthOfChild (Widget *child, bool forceValue) } } + if (width != -1) + width = misc::max (width, child->getMinWidth (NULL)); + DBG_OBJ_MSGF ("resize", 1, "=> %d", width); DBG_OBJ_LEAVE (); @@ -1358,8 +1394,6 @@ void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition, { // Again, a suitable implementation for all widgets (perhaps). - // TODO Correct by extremes? - DBG_OBJ_ENTER ("resize", 0, "correctRequisitionOfChild", "%p, %d * (%d + %d), ...", child, requisition->width, requisition->ascent, requisition->descent); @@ -1380,14 +1414,18 @@ void Widget::correctReqWidthOfChild (Widget *child, Requisition *requisition) requisition->descent); if (style::isAbsLength (child->getStyle()->width)) - requisition->width = style::absLengthVal (child->getStyle()->width) - + child->boxDiffWidth (); + requisition->width = + misc::max (style::absLengthVal (child->getStyle()->width) + + child->boxDiffWidth (), + child->getMinWidth (NULL)); else if (style::isPerLength (child->getStyle()->width)) { int availWidth = getAvailWidth (false); if (availWidth != -1) { int containerWidth = availWidth - boxDiffWidth (); - requisition->width = child->applyPerWidth (containerWidth, - child->getStyle()->width); + requisition->width = + misc::max (child->applyPerWidth (containerWidth, + child->getStyle()->width), + child->getMinWidth (NULL)); } } @@ -1400,6 +1438,8 @@ void Widget::correctReqWidthOfChild (Widget *child, Requisition *requisition) void Widget::correctReqHeightOfChild (Widget *child, Requisition *requisition, void (*splitHeightFun) (int, int*, int*)) { + // TODO Correct height by extremes? (Height extemes?) + DBG_OBJ_ENTER ("resize", 0, "correctReqHeightOfChild", "%p, %d * (%d + %d), ...", child, requisition->width, requisition->ascent, requisition->descent); @@ -1434,17 +1474,18 @@ void Widget::correctExtremesOfChild (Widget *child, Extremes *extremes) { // See comment in correctRequisitionOfChild. - // TODO Extremes only corrected? - - DBG_OBJ_ENTER ("resize", 0, "correctExtremesOfChild", "%p, %d / %d", - child, extremes->minWidth, extremes->maxWidth); + DBG_OBJ_ENTER ("resize", 0, "correctExtremesOfChild", + "%p, %d (%d) / %d (%d)", + child, extremes->minWidth, extremes->minWidthIntrinsic, + extremes->maxWidth, extremes->maxWidthIntrinsic); if (style::isAbsLength (child->getStyle()->width)) { DBG_OBJ_MSGF ("resize", 1, "absolute width: %dpx", style::absLengthVal (child->getStyle()->width)); extremes->minWidth = extremes->maxWidth = - style::absLengthVal (child->getStyle()->width) - + child->boxDiffWidth (); + misc::max (style::absLengthVal (child->getStyle()->width) + + child->boxDiffWidth (), + child->getMinWidth (extremes)); } else if (style::isPerLength (child->getStyle()->width)) { DBG_OBJ_MSGF ("resize", 1, "percentage width: %g%%", 100 * style::perLengthVal_useThisOnlyForDebugging @@ -1455,7 +1496,9 @@ void Widget::correctExtremesOfChild (Widget *child, Extremes *extremes) DBG_OBJ_MSGF ("resize", 1, "containerWidth = %d - %d = %d", availWidth, boxDiffWidth (), containerWidth); extremes->minWidth = extremes->maxWidth = - child->applyPerWidth (containerWidth, child->getStyle()->width); + misc::max (child->applyPerWidth (containerWidth, + child->getStyle()->width), + child->getMinWidth (extremes)); } } else DBG_OBJ_MSG ("resize", 1, "no specification"); diff --git a/dw/widget.hh b/dw/widget.hh index bfbf1e91..23d91a55 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -99,6 +99,8 @@ protected: WidgetImgRenderer *widgetImgRenderer; private: + static bool adjustMinWidth; + /** * \brief The parent widget, NULL for top-level widgets. */ @@ -290,6 +292,8 @@ protected: */ virtual void markExtremesChange (int ref); + int getMinWidth (Extremes *extremes); + virtual int getAvailWidthOfChild (Widget *child, bool forceValue); virtual int getAvailHeightOfChild (Widget *child, bool forceValue); virtual void correctRequisitionOfChild (Widget *child, @@ -383,6 +387,10 @@ private: public: static int CLASS_ID; + inline static void setAdjustMinWidth (bool adjustMinWidth) + { Widget::adjustMinWidth = adjustMinWidth; } + inline static bool getAdjustMinWidth () { return Widget::adjustMinWidth; } + Widget (); ~Widget (); diff --git a/src/dillo.cc b/src/dillo.cc index 4d96988f..d67ba3af 100644 --- a/src/dillo.cc +++ b/src/dillo.cc @@ -56,6 +56,7 @@ #include "lout/debug.hh" #include "dw/fltkcore.hh" +#include "dw/widget.hh" #include "dw/textblock.hh" /* @@ -483,6 +484,7 @@ int main(int argc, char **argv) a_UIcmd_init(); StyleEngine::init(); + dw::core::Widget::setAdjustMinWidth (prefs.adjust_min_width); dw::Textblock::setPenaltyHyphen (prefs.penalty_hyphen); dw::Textblock::setPenaltyHyphen2 (prefs.penalty_hyphen_2); dw::Textblock::setPenaltyEmDashLeft (prefs.penalty_em_dash_left); diff --git a/src/prefs.c b/src/prefs.c index 56e02006..b0213fcc 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -68,6 +68,7 @@ void a_Prefs_init(void) prefs.http_referer = dStrdup(PREFS_HTTP_REFERER); prefs.http_user_agent = dStrdup(PREFS_HTTP_USER_AGENT); prefs.limit_text_width = FALSE; + prefs.adjust_min_width = FALSE; prefs.load_images=TRUE; prefs.load_background_images=FALSE; prefs.load_stylesheets=TRUE; diff --git a/src/prefs.h b/src/prefs.h index 0e54e0fc..b742e6e7 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -66,6 +66,7 @@ typedef struct { int panel_size; bool_t small_icons; bool_t limit_text_width; + bool_t adjust_min_width; bool_t w3c_plus_heuristics; bool_t focus_new_tab; double font_factor; diff --git a/src/prefsparser.cc b/src/prefsparser.cc index ce420eac..33f6cf51 100644 --- a/src/prefsparser.cc +++ b/src/prefsparser.cc @@ -79,6 +79,7 @@ int PrefsParser::parseOption(char *name, char *value) { "http_referer", &prefs.http_referer, PREFS_STRING }, { "http_user_agent", &prefs.http_user_agent, PREFS_STRING }, { "limit_text_width", &prefs.limit_text_width, PREFS_BOOL }, + { "adjust_min_width", &prefs.adjust_min_width, PREFS_BOOL }, { "load_images", &prefs.load_images, PREFS_BOOL }, { "load_background_images", &prefs.load_background_images, PREFS_BOOL }, { "load_stylesheets", &prefs.load_stylesheets, PREFS_BOOL }, |