diff options
author | Sebastian Geerken <devnull@localhost> | 2014-04-29 22:17:25 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-04-29 22:17:25 +0200 |
commit | 97c77e536cb878ee4752d7017f26af04e8be74a2 (patch) | |
tree | ff02e83013535164b2b8867c3c1ca333e9a6fe50 /dw/outofflowmgr.cc | |
parent | 5e0678ef523f24dd452278427d8e02ba9e7f76e8 (diff) |
Fixed a CPU hogging bug (plus some refactoring).
Diffstat (limited to 'dw/outofflowmgr.cc')
-rw-r--r-- | dw/outofflowmgr.cc | 105 |
1 files changed, 74 insertions, 31 deletions
diff --git a/dw/outofflowmgr.cc b/dw/outofflowmgr.cc index a2f5a722..954da505 100644 --- a/dw/outofflowmgr.cc +++ b/dw/outofflowmgr.cc @@ -1685,43 +1685,17 @@ void OutOfFlowMgr::getFloatsExtremes (Extremes *cbExtr, Side side, for (int i = 0; i < list->size(); i++) { Float *vloat = list->get(i); + int leftDiff, rightDiff; - if (vloat->generatingBlock == containingBlock || - wasAllocated (vloat->generatingBlock)) { + if (getFloatDiffToCB (vloat, &leftDiff, &rightDiff)) { Extremes extr; vloat->getWidget()->getExtremes (&extr); - int leftDiff, rightDiff; DBG_OBJ_MSGF ("resize.oofm", 1, "considering float %p generated by %p: %d / %d", vloat->getWidget (), vloat->generatingBlock, extr.minWidth, extr.maxWidth); - if (vloat->generatingBlock == containingBlock) { - leftDiff = vloat->generatingBlock->getStyle()->boxOffsetX(); - rightDiff = vloat->generatingBlock->getStyle()->boxRestWidth(); - DBG_OBJ_MSGF ("resize.oofm", 1, - "GB == CB => leftDiff = %d, rightDiff = %d", - leftDiff, rightDiff); - } else { - Allocation *gba = getAllocation(vloat->generatingBlock); - leftDiff = gba->x - containingBlockAllocation.x - + vloat->generatingBlock->getStyle()->boxOffsetX(); - rightDiff = - (containingBlockAllocation.x + containingBlockAllocation.width) - - (gba->x + gba->width) - + vloat->generatingBlock->getStyle()->boxRestWidth(); - DBG_OBJ_MSGF ("resize.oofm", 1, - "GB != CB => leftDiff = %d - %d + %d = %d, " - "rightDiff = (%d + %d) - (%d + %d) + %d = %d", - gba->x, containingBlockAllocation.x, - vloat->generatingBlock->getStyle()->boxOffsetX(), - leftDiff, containingBlockAllocation.x, - containingBlockAllocation.width, gba->x, gba->width, - vloat->generatingBlock->getStyle()->boxRestWidth(), - rightDiff); - } - // TODO: Or zero (instead of rightDiff) for right floats? *minWidth = max (*minWidth, @@ -1738,6 +1712,52 @@ void OutOfFlowMgr::getFloatsExtremes (Extremes *cbExtr, Side side, DBG_OBJ_MSG_END (); } +// Returns "false" when borders cannot yet determined; *leftDiff and +// *rightDiff are undefined in this case. +bool OutOfFlowMgr::getFloatDiffToCB (Float *vloat, int *leftDiff, + int *rightDiff) +{ + DBG_OBJ_MSGF ("resize.oofm", 0, + "<b>getDiffToCB</b> (float %p [generated by %p], ...)", + vloat->getWidget (), vloat->generatingBlock); + DBG_OBJ_MSG_START (); + + bool result; + + if (vloat->generatingBlock == containingBlock) { + *leftDiff = vloat->generatingBlock->getStyle()->boxOffsetX(); + *rightDiff = vloat->generatingBlock->getStyle()->boxRestWidth(); + result = true; + DBG_OBJ_MSGF ("resize.oofm", 1, + "GB == CB => leftDiff = %d, rightDiff = %d", + *leftDiff, *rightDiff); + } else if (wasAllocated (vloat->generatingBlock)) { + Allocation *gba = getAllocation(vloat->generatingBlock); + *leftDiff = gba->x - containingBlockAllocation.x + + vloat->generatingBlock->getStyle()->boxOffsetX(); + *rightDiff = + (containingBlockAllocation.x + containingBlockAllocation.width) + - (gba->x + gba->width) + + vloat->generatingBlock->getStyle()->boxRestWidth(); + result = true; + DBG_OBJ_MSGF ("resize.oofm", 1, + "GB != CB => leftDiff = %d - %d + %d = %d, " + "rightDiff = (%d + %d) - (%d + %d) + %d = %d", + gba->x, containingBlockAllocation.x, + vloat->generatingBlock->getStyle()->boxOffsetX(), + *leftDiff, containingBlockAllocation.x, + containingBlockAllocation.width, gba->x, gba->width, + vloat->generatingBlock->getStyle()->boxRestWidth(), + *rightDiff); + } else { + DBG_OBJ_MSG ("resize.oofm", 1, "GB != CB, and float not allocated"); + result = false; + } + + DBG_OBJ_MSG_END (); + return result; +} + OutOfFlowMgr::TBInfo *OutOfFlowMgr::getTextblock (Textblock *textblock) { TypedPointer<Textblock> key (textblock); @@ -1980,12 +2000,35 @@ void OutOfFlowMgr::ensureFloatSize (Float *vloat) width = adjustFloatWidth (width, &extremes); vloat->getWidget()->setWidth (width); } else if (isPerLength (vloat->getWidget()->getStyle()->width)) { + // It is important that the width of the *CB* is not + // larger than its minimal width, when the latter is set + // as size hint; otherwise we have an endless queueResize + // cycle (resulting in CPU hogging) when the CB is part of + // a narrow table column. To prevent this, the width of + // the *float* has to be limited (cf. also getExtremes). + + int availWidth, leftDiff, rightDiff; + if (getFloatDiffToCB (vloat, &leftDiff, &rightDiff)) + availWidth = containingBlock->getAvailWidth() + - (vloat->getWidget()->getStyle()->vloat == FLOAT_LEFT ? + leftDiff : rightDiff); + else + // Not allocated: next allocation will take care. + availWidth = containingBlock->getAvailWidth(); + int width = - multiplyWithPerLength (containingBlock->getAvailWidth(), + multiplyWithPerLength (availWidth, vloat->getWidget()->getStyle()->width); + + // Some more corrections (nonsense percentage values): + if (width < 1) + width = 1; + if (width > availWidth) + width = availWidth; + DBG_OBJ_MSGF ("resize.oofm", 1, - "about to set percentage width: %d * %g = %d", - containingBlock->getAvailWidth(), + "about to set percentage width: %d * %g -> %d", + availWidth, perLengthVal (vloat->getWidget()->getStyle()->width), width); width = adjustFloatWidth (width, &extremes); |