diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-03-09 23:50:20 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-03-09 23:50:20 +0100 |
commit | c74425a513d3cf98186298cda94528424aabfdbc (patch) | |
tree | 254cfc8e3cf9462500fe86ebd1aabf989b4ca34d | |
parent | 0a2453a1e1e89e8821e4e8a230f0f56e2f7dd20c (diff) |
support display:inline-block
-rw-r--r-- | dw/Makefile.am | 2 | ||||
-rw-r--r-- | dw/inlineblock.cc | 66 | ||||
-rw-r--r-- | dw/inlineblock.hh | 22 | ||||
-rw-r--r-- | src/html.cc | 12 |
4 files changed, 101 insertions, 1 deletions
diff --git a/dw/Makefile.am b/dw/Makefile.am index 3014b35d..e65d978a 100644 --- a/dw/Makefile.am +++ b/dw/Makefile.am @@ -61,6 +61,8 @@ libDw_widgets_a_SOURCES = \ image.hh \ listitem.cc \ listitem.hh \ + inlineblock.cc \ + inlineblock.hh \ ruler.cc \ ruler.hh \ table.cc \ diff --git a/dw/inlineblock.cc b/dw/inlineblock.cc new file mode 100644 index 00000000..9aa19b5d --- /dev/null +++ b/dw/inlineblock.cc @@ -0,0 +1,66 @@ +/* + * Dillo Widget + * + * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + + +#include "../lout/misc.hh" +#include "inlineblock.hh" +#include <stdio.h> + +namespace dw { + +int InlineBlock::CLASS_ID = -1; + +InlineBlock::InlineBlock (bool limitTextWidth): + Textblock (limitTextWidth) +{ + registerName ("dw::InlineBlock", &CLASS_ID); + unsetFlags (BLOCK_LEVEL); +} + +InlineBlock::~InlineBlock() +{ +} + +void InlineBlock::sizeRequestImpl (core::Requisition *requisition) +{ + rewrap (); + if (lines->size () > 0) { + Line *lastLine = lines->getRef (lines->size () - 1); + requisition->width = + lout::misc::max (lastLine->maxLineWidth, lastLineWidth); + /* Note: the breakSpace of the last line is ignored, so breaks + at the end of a textblock are not visible. */ + requisition->ascent = lines->getRef(0)->boxAscent; + requisition->descent = lastLine->top + + lastLine->boxAscent + lastLine->boxDescent - + lines->getRef(0)->boxAscent; + } else { + requisition->width = lastLineWidth; + requisition->ascent = 0; + requisition->descent = 0; + } + + requisition->width += innerPadding + getStyle()->boxDiffWidth (); + requisition->ascent += getStyle()->boxOffsetY (); + requisition->descent += getStyle()->boxRestHeight (); +} + + +} // namespace dw diff --git a/dw/inlineblock.hh b/dw/inlineblock.hh new file mode 100644 index 00000000..0da8241f --- /dev/null +++ b/dw/inlineblock.hh @@ -0,0 +1,22 @@ +#ifndef __DW_INLINEBLOCK_HH__ +#define __DW_INLINEBLOCK_HH__ + +#include "core.hh" +#include "textblock.hh" + +namespace dw { + +class InlineBlock: public Textblock +{ +public: + static int CLASS_ID; + + InlineBlock(bool limitTextWidth); + ~InlineBlock(); + + void sizeRequestImpl (core::Requisition *requisition); +}; + +} // namespace dw + +#endif // __DW_INLINEBLOCK_HH__ diff --git a/src/html.cc b/src/html.cc index 0cee0a8f..c7e02abf 100644 --- a/src/html.cc +++ b/src/html.cc @@ -42,6 +42,7 @@ #include "dw/textblock.hh" #include "dw/bullet.hh" #include "dw/listitem.hh" +#include "dw/inlineblock.hh" #include "dw/image.hh" #include "dw/ruler.hh" @@ -3448,6 +3449,13 @@ static void Html_display_block(DilloHtml *html) Html_add_textblock(html, 0); } +static void Html_display_inline_block(DilloHtml *html) +{ + Textblock *textblock = new InlineBlock (prefs.limit_text_width); + HT2TB(html)->addWidget (textblock, html->styleEngine->style ()); + S_TOP(html)->textblock = html->dw = textblock; +} + static void Html_display_listitem(DilloHtml *html) { Style *style = html->styleEngine->style (); @@ -3543,6 +3551,9 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize) case DISPLAY_BLOCK: Html_display_block(html); break; + case DISPLAY_INLINE_BLOCK: + Html_display_inline_block(html); + break; case DISPLAY_LIST_ITEM: Html_display_listitem(html); break; @@ -3550,7 +3561,6 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize) S_TOP(html)->display_none = true; break; case DISPLAY_INLINE: - case DISPLAY_INLINE_BLOCK: // TODO: implement inline-block default: break; } |