diff options
-rw-r--r-- | dw/oofawarewidget.cc | 89 | ||||
-rw-r--r-- | dw/oofawarewidget.hh | 27 | ||||
-rw-r--r-- | dw/textblock.cc | 84 | ||||
-rw-r--r-- | dw/textblock.hh | 17 |
4 files changed, 112 insertions, 105 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) { diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh index 890d8a14..a7b3de2b 100644 --- a/dw/oofawarewidget.hh +++ b/dw/oofawarewidget.hh @@ -24,16 +24,35 @@ protected: public: OOFAwareWidget *oofContainer[NUM_OOFM]; - oof::OutOfFlowMgr *outOfFlowMgr[NUM_OOFM]; + OutOfFlowMgr *outOfFlowMgr[NUM_OOFM]; protected: + inline OutOfFlowMgr *searchOutOfFlowMgr (int oofmIndex) + { return oofContainer[oofmIndex] ? + oofContainer[oofmIndex]->outOfFlowMgr[oofmIndex] : NULL; } + + static inline bool testWidgetFloat (Widget *widget) + { return widget->getStyle()->vloat != core::style::FLOAT_NONE; } + static inline bool testWidgetAbsolutelyPositioned (Widget *widget) + { return widget->getStyle()->position == core::style::POSITION_ABSOLUTE; } + static inline bool testWidgetFixedlyPositioned (Widget *widget) + { return widget->getStyle()->position == core::style::POSITION_FIXED; } + static inline bool testWidgetOutOfFlow (Widget *widget) + { return testWidgetFloat (widget) || testWidgetAbsolutelyPositioned (widget) + || testWidgetFixedlyPositioned (widget); } + + static inline bool testWidgetRelativelyPositioned (Widget *widget) + { return widget->getStyle()->position == core::style::POSITION_RELATIVE; } + void initOutOfFlowMgrs (); void sizeAllocateStart (core::Allocation *allocation); void sizeAllocateEnd (); - inline OutOfFlowMgr *searchOutOfFlowMgr (int oofmIndex) - { return oofContainer[oofmIndex] ? - oofContainer[oofmIndex]->outOfFlowMgr[oofmIndex] : NULL; } + void notifySetAsTopLevel(); + void notifySetParent(); + + static bool isContainingBlock (Widget *widget, int oofmIndex); + public: OOFAwareWidget (); ~OOFAwareWidget (); diff --git a/dw/textblock.cc b/dw/textblock.cc index 062b727b..5d79f2a5 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -883,90 +883,6 @@ void Textblock::markExtremesChange (int ref) DBG_OBJ_LEAVE (); } -void Textblock::notifySetAsTopLevel() -{ - oofContainer[OOFM_FLOATS] = oofContainer[OOFM_ABSOLUTE] - = oofContainer[OOFM_FIXED] = this; -} - -bool Textblock::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 Textblock::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); - } -} - bool Textblock::isBlockLevel () { return true; diff --git a/dw/textblock.hh b/dw/textblock.hh index 4cadeffd..4c1810e6 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -279,19 +279,6 @@ protected: inline oof::OutOfFlowMgr *getWidgetOutOfFlowMgr (Widget *widget) { return getParentRefOutOfFlowMgr (widget->parentRef); } - static inline bool testWidgetFloat (Widget *widget) - { return widget->getStyle()->vloat != core::style::FLOAT_NONE; } - static inline bool testWidgetAbsolutelyPositioned (Widget *widget) - { return widget->getStyle()->position == core::style::POSITION_ABSOLUTE; } - static inline bool testWidgetFixedlyPositioned (Widget *widget) - { return widget->getStyle()->position == core::style::POSITION_FIXED; } - static inline bool testWidgetOutOfFlow (Widget *widget) - { return testWidgetFloat (widget) || testWidgetAbsolutelyPositioned (widget) - || testWidgetFixedlyPositioned (widget); } - - static inline bool testWidgetRelativelyPositioned (Widget *widget) - { return widget->getStyle()->position == core::style::POSITION_RELATIVE; } - /** * \brief Implementation used for words. */ @@ -816,9 +803,6 @@ protected: void markSizeChange (int ref); void markExtremesChange (int ref); - void notifySetAsTopLevel(); - void notifySetParent(); - bool isBlockLevel (); void draw (core::View *view, core::Rectangle *area); @@ -837,7 +821,6 @@ protected: core::style::Style *style, int numBreaks, int *breakPos, core::Requisition *wordSize); - static bool isContainingBlock (Widget *widget, int oofmIndex); inline bool mustBeWidenedToAvailWidth () { DBG_OBJ_ENTER0 ("resize", 0, "mustBeWidenedToAvailWidth"); |