summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2016-06-26 01:44:33 +0200
committerSebastian Geerken <devnull@localhost>2016-06-26 01:44:33 +0200
commit69a3cd0edb23470da3fd1079196936a02591f35f (patch)
tree0a570069278b6521792b5006b598193246fa5b3a
parent29f65909079b027a1e8f81ed6a8c7b46a97e5ef1 (diff)
Simplify again the signature of OOFAwareWidget:getGeneratorWidth(), with a slightly more complex (but more correct) implementatin for Textblock.
-rw-r--r--devdoc/dw-miscellaneous.doc10
-rw-r--r--dw/oofawarewidget.cc2
-rw-r--r--dw/oofawarewidget.hh7
-rw-r--r--dw/ooffloatsmgr.cc8
-rw-r--r--dw/textblock.cc64
-rw-r--r--dw/textblock.hh2
6 files changed, 61 insertions, 32 deletions
diff --git a/devdoc/dw-miscellaneous.doc b/devdoc/dw-miscellaneous.doc
index faaf2fa8..f7e44e73 100644
--- a/devdoc/dw-miscellaneous.doc
+++ b/devdoc/dw-miscellaneous.doc
@@ -46,6 +46,16 @@ Should dw::core::Widget::calcExtraSpace be called from
dw::core::Widget::getExtremes?
+Widgets out of flow
+===================
+
+dw::Textblock::getGeneratorWidth
+--------------------------------
+Re-evaluate dw::Textblock::getGeneratorWidth (especially the limitation on
+instances of dw::Textblock) for positioned elements. Is this method really only
+called for floats?
+
+
Widget sizes
============
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);