diff options
Diffstat (limited to 'dw')
-rw-r--r-- | dw/oofawarewidget.cc | 2 | ||||
-rw-r--r-- | dw/oofawarewidget.hh | 7 | ||||
-rw-r--r-- | dw/ooffloatsmgr.cc | 8 | ||||
-rw-r--r-- | dw/textblock.cc | 64 | ||||
-rw-r--r-- | dw/textblock.hh | 2 |
5 files changed, 51 insertions, 32 deletions
diff --git a/dw/oofawarewidget.cc b/dw/oofawarewidget.cc index 025111ae..f33df546 100644 --- a/dw/oofawarewidget.cc +++ b/dw/oofawarewidget.cc @@ -585,7 +585,7 @@ int OOFAwareWidget::getGeneratorY (int oofmIndex) return 0; } -int OOFAwareWidget::getGeneratorWidth (int callerX, int callerWidth) +int OOFAwareWidget::getGeneratorWidth () { notImplemented ("OOFAwareWidget::getGeneratorWidth"); return 0; diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh index 8d18675e..baeda592 100644 --- a/dw/oofawarewidget.hh +++ b/dw/oofawarewidget.hh @@ -288,13 +288,8 @@ public: /** * Return width including margin/border/padding Called by OOFFloatsMgr to * position floats. - * - * In somce cases (as in dw::Textblock::getGeneratorRest), the value is not - * up to date; for this, the caller may pass its position relative to this - * widget, as well as its width, which are used for adjustments. (See comment - * in dw::Textblock::getGeneratorRest.) */ - virtual int getGeneratorWidth (int callerX, int callerWidth); + virtual int getGeneratorWidth (); virtual int getMaxGeneratorWidth (); diff --git a/dw/ooffloatsmgr.cc b/dw/ooffloatsmgr.cc index 0d701b0b..9b754fff 100644 --- a/dw/ooffloatsmgr.cc +++ b/dw/ooffloatsmgr.cc @@ -476,7 +476,7 @@ int OOFFloatsMgr::calcFloatX (Float *vloat) // (ii) If there is more than one line, the line break will already be // exceeded, and so be smaller that GB width + float width. effGeneratorWidth = - min (vloat->generator->getGeneratorWidth (0, 0) + vloat->size.width, + min (vloat->generator->getGeneratorWidth () + vloat->size.width, vloat->generator->getMaxGeneratorWidth ()); x = max (generator->getGeneratorX (oofmIndex) + effGeneratorWidth @@ -868,7 +868,7 @@ bool OOFFloatsMgr::collidesH (Float *vloat, Float *other) if (vloat->generator == other->generator) collidesH = vloat->size.width + other->size.width + vloat->generator->boxDiffWidth() - > vloat->generator->getGeneratorWidth (0, 0); + > vloat->generator->getGeneratorWidth (); else { // Again, if the other float is not allocated, there is no // collision. Compare to collidesV. (But vloat->size is used @@ -1039,8 +1039,8 @@ void OOFFloatsMgr::getFloatsExtremes (Extremes *cbExtr, Side side, *maxWidth = max (*maxWidth, extr.maxWidth + vloat->generator->getStyle()->boxDiffWidth(), - + max (container->getGeneratorWidth (0, 0) - - vloat->generator->getGeneratorWidth (0, 0), + + max (container->getGeneratorWidth () + - vloat->generator->getGeneratorWidth (), 0)); DBG_OBJ_MSGF ("resize.oofm", 1, "%d / %d => %d / %d", diff --git a/dw/textblock.cc b/dw/textblock.cc index f0bfb3d8..12868c11 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -3109,17 +3109,9 @@ int Textblock::getGeneratorRest (int oofmIndex) int xRef, rest; OOFAwareWidget *container = oofContainer[oofmIndex]; - if (container != NULL && findSizeRequestReference (container, &xRef, NULL)) { - // This method is typically called within sizeRequest; so, this widget has - // more information to calculate the width than the container, which will - // result in too small values (often negative) of the rest. For this - // reason, we use the possibility to pass values from this widget. - - // (Also notice that the return value may actually be negative.) - - int width = getGeneratorWidth (0, 0); - rest = container->getGeneratorWidth (xRef, width) - (xRef + width); - } else { + if (container != NULL && findSizeRequestReference (container, &xRef, NULL)) + rest = container->getGeneratorWidth () - (xRef + getGeneratorWidth ()); + else { // Only callend for floats, so this should not happen: assertNotReached (); rest = 0; @@ -3129,22 +3121,54 @@ int Textblock::getGeneratorRest (int oofmIndex) return rest; } -int Textblock::getGeneratorWidth (int callerX, int callerWidth) +int Textblock::getGeneratorWidth () { - DBG_OBJ_ENTER ("resize", 0, "Textblock::getGeneratorWidth", "%d, %d", - callerX, callerWidth); + DBG_OBJ_ENTER0 ("resize", 0, "Textblock::getGeneratorWidth"); // Cf. sizeRequestImpl. if (usesMaxGeneratorWidth ()) { DBG_OBJ_LEAVE_VAL ("%d", lineBreakWidth); return lineBreakWidth; } else { - int w0 = max (lines->size () > 0 ? lines->getLastRef()->maxLineWidth : 0, - callerX + callerWidth), - w = min (w0 + leftInnerPadding + boxDiffWidth (), lineBreakWidth); - DBG_OBJ_LEAVE_VAL ("min (%d + %d + %d, %d) = %d", - w0, leftInnerPadding, boxDiffWidth (), lineBreakWidth, - w); + // In some cases (especially when called from sizeRequest for an + // ancestor), the value is not up to date, since content from children is + // not yet added to lines. Moreover, this leads to inconsistencies between + // this widget and ancestors (as in Textblock::getGeneratorRest). For this + // reason, the children are examined recursively. + // + // Test case: + // + // <div style="float:left"> + // <div div style="float:right">float</div> + // <div>abcdefghijkl mnopqrstuvwx</div> + // </div> + + int wChild = 0; + int firstWordAfterLastLine = + lines->size() > 0 ? lines->getLastRef()->lastWord + 1 : 0; + for (int i = firstWordAfterLastLine; i < words->size(); i++) { + Word *word = words->getRef(i); + int xRel; + // We only examine instances of dw::Textblock, since they are relevant + // for floats, for which this method is only called. + if(word->content.type == core::Content::WIDGET_IN_FLOW && + word->content.widget->instanceOf(Textblock::CLASS_ID)) { + Textblock *tbChild = (Textblock*)word->content.widget; + if(tbChild->findSizeRequestReference(this, &xRel, NULL)) + wChild = max(wChild, xRel + tbChild->getGeneratorWidth()); + } + } + + DBG_OBJ_MSGF ("resize", 1, "wChild = %d", wChild); + + int w0 = lines->size () > 0 ? lines->getLastRef()->maxLineWidth : 0; + DBG_OBJ_MSGF ("resize", 1, "w0 = %d", w0); + int wThis = min(w0 + leftInnerPadding + boxDiffWidth (), lineBreakWidth); + DBG_OBJ_MSGF ("resize", 1, "wThis = min(%d + %d + %d, %d) = %d", + w0, leftInnerPadding, boxDiffWidth (), lineBreakWidth, + wThis); + int w = max(wThis, wChild); + DBG_OBJ_LEAVE_VAL ("max(%d, %d) = %d", wThis, wChild, w); return w; } } diff --git a/dw/textblock.hh b/dw/textblock.hh index dc4805e1..d7e1fb4e 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -905,7 +905,7 @@ public: void oofSizeChanged (bool extremesChanged); int getGeneratorX (int oofmIndex); int getGeneratorY (int oofmIndex); - int getGeneratorWidth (int callerX, int callerWidth); + int getGeneratorWidth (); int getMaxGeneratorWidth (); bool usesMaxGeneratorWidth (); bool isPossibleOOFContainer (int oofmIndex); |