diff options
author | Sebastian Geerken <devnull@localhost> | 2014-09-12 13:11:32 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-09-12 13:11:32 +0200 |
commit | 350fa597967a501d5f5c6988ff35a262e50a2a68 (patch) | |
tree | 102ccb0775eef7e4d4b8b7cfd40b7f11459b1ee2 /dw/oofawarewidget.cc | |
parent | 36fcd74196a898403ef1e66884dc52d296c42665 (diff) |
OOFAwareWidget: moving even more stuff from Textblock to OOFAwareWidget.
Diffstat (limited to 'dw/oofawarewidget.cc')
-rw-r--r-- | dw/oofawarewidget.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/dw/oofawarewidget.cc b/dw/oofawarewidget.cc index 673d4596..f1c91d11 100644 --- a/dw/oofawarewidget.cc +++ b/dw/oofawarewidget.cc @@ -23,6 +23,11 @@ #include "oofposfixedmgr.hh" #include "textblock.hh" +// TODO: Avoid reference to Textblock by replacing +// "instanceOf (Textblock::CLASS_ID)" by some new methods. + +using namespace dw; +using namespace dw::core; using namespace lout::misc; namespace dw { @@ -41,6 +46,90 @@ OOFAwareWidget::~OOFAwareWidget () { } +void OOFAwareWidget::notifySetAsTopLevel() +{ + oofContainer[OOFM_FLOATS] = oofContainer[OOFM_ABSOLUTE] + = oofContainer[OOFM_FIXED] = this; +} + +bool OOFAwareWidget::isContainingBlock (Widget *widget, int oofmIndex) +{ + switch (oofmIndex) { + case OOFM_FLOATS: + return + // For floats, only textblocks are considered as containing + // blocks. + widget->instanceOf (Textblock::CLASS_ID) && + // The second condition: that this block is "out of flow", in a + // wider sense. + (// The toplevel widget is "out of flow", since there is no + // parent, and so no context. + widget->getParent() == NULL || + // A similar reasoning applies to a widget with another parent + // than a textblock (typical example: a table cell (this is + // also a text block) within a table widget). + !widget->getParent()->instanceOf (Textblock::CLASS_ID) || + // Inline blocks are containing blocks, too. + widget->getStyle()->display == core::style::DISPLAY_INLINE_BLOCK || + // Finally, "out of flow" in a narrower sense: floats; absolutely + // and fixedly positioned elements. + testWidgetOutOfFlow (widget)); + + case OOFM_ABSOLUTE: + // Only the toplevel widget (as for all) as well as absolutely, + // relatively, and fixedly positioned elements constitute the + // containing block for absolutely positioned elements, but + // neither floats nor other elements like table cells. + // + // (Notice that relative positions are not yet supported, but + // only tested to get the correct containing block. Furthermore, + // it seems that this test would be incorrect for floats.) + // + // We also test whether this widget is a textblock: is this + // necessary? (What about other absolutely widgets containing + // children, like tables? TODO: Check CSS spec.) + + return widget->instanceOf (Textblock::CLASS_ID) && + (widget->getParent() == NULL || + testWidgetAbsolutelyPositioned (widget) || + testWidgetRelativelyPositioned (widget) || + testWidgetFixedlyPositioned (widget)); + + case OOFM_FIXED: + // The single container for fixedly positioned elements is the + // toplevel (canvas; actually the viewport). (The toplevel + // widget should always be a textblock; at least this is the + // case in dillo.) + return widget->getParent() == NULL; + + default: + // compiler happiness + lout::misc::assertNotReached (); + return false; + } +} + +void OOFAwareWidget::notifySetParent () +{ + // Search for containing blocks. + for (int oofmIndex = 0; oofmIndex < NUM_OOFM; oofmIndex++) { + oofContainer[oofmIndex] = NULL; + + for (Widget *widget = this; + widget != NULL && oofContainer[oofmIndex] == NULL; + widget = widget->getParent ()) + if (isContainingBlock (widget, oofmIndex)) { + assert (widget->instanceOf (Textblock::CLASS_ID)); + oofContainer[oofmIndex] = (Textblock*)widget; + } + + DBG_OBJ_ARRSET_PTR ("containingBlock", oofmIndex, + containingBlock[oofmIndex]); + + assert (oofContainer[oofmIndex] != NULL); + } +} + void OOFAwareWidget::initOutOfFlowMgrs () { if (oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS] == NULL) { |