diff options
author | Sebastian Geerken <devnull@localhost> | 2014-11-08 14:57:16 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-11-08 14:57:16 +0100 |
commit | aa4f6269918fcfc5ebd11d3b712e88577773ba02 (patch) | |
tree | 9e914def2dc344a71c266f4361123abcbde88cba /dw | |
parent | faa8d1b65d9f724445e068d2766356103204728a (diff) | |
parent | 550d933b21d548411fe862d6a24ce73e4d5621c5 (diff) |
Merge with main repo.
Diffstat (limited to 'dw')
-rw-r--r-- | dw/imgrenderer.cc | 19 | ||||
-rw-r--r-- | dw/style.cc | 26 | ||||
-rw-r--r-- | dw/style.hh | 2 | ||||
-rw-r--r-- | dw/textblock.cc | 3 | ||||
-rw-r--r-- | dw/textblock_iterator.cc | 56 | ||||
-rw-r--r-- | dw/widget.cc | 25 |
6 files changed, 109 insertions, 22 deletions
diff --git a/dw/imgrenderer.cc b/dw/imgrenderer.cc index 285a8dcd..14806ea2 100644 --- a/dw/imgrenderer.cc +++ b/dw/imgrenderer.cc @@ -1,3 +1,22 @@ +/* + * Dillo Widget + * + * Copyright 2013 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 "core.hh" namespace dw { diff --git a/dw/style.cc b/dw/style.cc index 830613fa..32a33a9e 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -1208,18 +1208,26 @@ void drawBorder (View *view, Layout *layout, Rectangle *area, * * Otherwise, the caller should not try to increase the performance by * doing some tests before; this is all done in this method. + * + * "bgColor" is passes implicitly. For non-inversed drawing, + * style->backgroundColor may simply used. However, when drawing is + * inversed, and style->backgroundColor is undefined (NULL), a + * background color defined higher in the hierarchy (which is not + * accessable here) must be used. + * + * (Background *images* are never drawn inverse.) */ void drawBackground (View *view, Layout *layout, Rectangle *area, int x, int y, int width, int height, int xRef, int yRef, int widthRef, int heightRef, - Style *style, bool inverse, bool atTop) + Style *style, Color *bgColor, bool inverse, bool atTop) { - bool bgColor = style->backgroundColor != NULL && + bool hasBgColor = bgColor != NULL && // The test for background colors is rather simple, since only the color // has to be compared, ... - (!atTop || layout->getBgColor () != style->backgroundColor); - bool bgImage = (style->backgroundImage != NULL && - style->backgroundImage->getImgbufSrc() != NULL) && + (!atTop || layout->getBgColor () != bgColor); + bool hasBgImage = (style->backgroundImage != NULL && + style->backgroundImage->getImgbufSrc() != NULL) && // ... but for backgrounds, it would be rather complicated. To handle the // two cases (normal HTML in a viewport, where the layout background // image is set, and contents of <button> within a flat view, where the @@ -1233,7 +1241,7 @@ void drawBackground (View *view, Layout *layout, Rectangle *area, // necessary to draw the background if background color and image // are not set (NULL), i. e. shining through. - if (bgColor || bgImage) { + if (hasBgColor || hasBgImage) { Rectangle bgArea, intersection; bgArea.x = x; bgArea.y = y; @@ -1241,14 +1249,14 @@ void drawBackground (View *view, Layout *layout, Rectangle *area, bgArea.height = height; if (area->intersectsWith (&bgArea, &intersection)) { - if (bgColor) - view->drawRectangle (style->backgroundColor, + if (hasBgColor) + view->drawRectangle (bgColor, inverse ? Color::SHADING_INVERSE : Color::SHADING_NORMAL, true, intersection.x, intersection.y, intersection.width, intersection.height); - if (bgImage) + if (hasBgImage) drawBackgroundImage (view, style->backgroundImage, style->backgroundRepeat, style->backgroundAttachment, diff --git a/dw/style.hh b/dw/style.hh index 43fff0a1..12ca1664 100644 --- a/dw/style.hh +++ b/dw/style.hh @@ -903,7 +903,7 @@ void drawBorder (View *view, Layout *layout, Rectangle *area, void drawBackground (View *view, Layout *layout, Rectangle *area, int x, int y, int width, int height, int xRef, int yRef, int widthRef, int heightRef, - Style *style, bool inverse, bool atTop); + Style *style, Color *bgColor, bool inverse, bool atTop); void drawBackgroundImage (View *view, StyleImage *backgroundImage, BackgroundRepeat backgroundRepeat, BackgroundAttachment backgroundAttachment, diff --git a/dw/textblock.cc b/dw/textblock.cc index 18303951..d88b411f 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -3129,7 +3129,8 @@ Textblock *Textblock::getTextblockForLine (Line *line) Textblock *Textblock::getTextblockForLine (int lineNo) { - int firstWord = lineNo == 0 ? 0 :lines->getRef(lineNo - 1)->lastWord + 1; + // Can also be used for a line not yet existing. + int firstWord = lineNo == 0 ? 0 : lines->getRef(lineNo - 1)->lastWord + 1; int lastWord = lineNo < lines->size() ? lines->getRef(lineNo)->lastWord : words->size() - 1; return getTextblockForLine (firstWord, lastWord); diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc index 8da692d6..95e2ce65 100644 --- a/dw/textblock_iterator.cc +++ b/dw/textblock_iterator.cc @@ -188,15 +188,54 @@ void Textblock::TextblockIterator::getAllocation (int start, int end, { if (inFlow ()) { Textblock *textblock = (Textblock*)getWidget(); - int index = getInFlowIndex (), - lineIndex = textblock->findLineOfWord (index); - Line *line = textblock->lines->getRef (lineIndex); - Word *word = textblock->words->getRef (index); - allocation->x = - textblock->allocation.x + line->textOffset; + int index = getInFlowIndex (); + Word *word = textblock->words->getRef (index); + int firstWordOfLine, textOffset, lineYOffsetCanvas, lineBorderAscent; + + int lineIndex = textblock->findLineOfWord (index); + + // It may be that the line does not exist yet. + if (lineIndex != -1) { + // Line exists: simple. + Line *line = textblock->lines->getRef (lineIndex); + firstWordOfLine = line->firstWord; + textOffset = line->textOffset; + lineYOffsetCanvas = textblock->lineYOffsetCanvas (line); + lineBorderAscent = line->borderAscent; + } else { + // Line does not exist. Calculate the values in a similar way as in + // Textblock::addLine(). + Line *prevLine = textblock->lines->size () > 0 ? + textblock->lines->getLastRef () : NULL; + firstWordOfLine = prevLine ? prevLine->lastWord + 1 : 0; + + // The variable textOffset, defined below, is what Line::leftOffset + // will be for the next line; Line::textOffset itself cannot be + // calculated before the line is complete. + bool regardBorder = + textblock->mustBorderBeRegarded (textblock->lines->size ()); + textOffset = + misc::max (regardBorder ? textblock->newLineLeftBorder : 0, + textblock->boxOffsetX () + textblock->leftInnerPadding + + (textblock->lines->size () == 0 ? + textblock->line1OffsetEff : 0)); + + lineYOffsetCanvas = textblock->yOffsetOfLineToBeCreated (); + + lineBorderAscent = 0; + for (int i = firstWordOfLine; i < textblock->words->size (); i++) { + Word *w = textblock->words->getRef (i); + int borderAscent = + w->content.type == core::Content::WIDGET_IN_FLOW ? + w->size.ascent - w->content.widget->getStyle()->margin.top : + w->size.ascent; + lineBorderAscent = misc::max (lineBorderAscent, borderAscent); + } + } - for (int i = line->firstWord; i < index; i++) { + allocation->x = textblock->allocation.x + textOffset; + for (int i = firstWordOfLine; i < index; i++) { Word *w = textblock->words->getRef(i); allocation->x += w->size.width + w->effSpace; } @@ -208,8 +247,7 @@ void Textblock::TextblockIterator::getAllocation (int start, int end, && word->content.text[start] == 0); } - allocation->y = textblock->lineYOffsetCanvas (line) + line->borderAscent - - word->size.ascent; + allocation->y = lineYOffsetCanvas + lineBorderAscent - word->size.ascent; allocation->width = word->size.width; if (word->content.type == core::Content::TEXT) { diff --git a/dw/widget.cc b/dw/widget.cc index 4c1fb896..9c517f24 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -1422,6 +1422,10 @@ void Widget::drawBox (View *view, style::Style *style, Rectangle *area, // does not define what here is called "reference area". To make it look // smoothly, the widget padding box is used. + // TODO Handle inverse drawing the same way as in drawWidgetBox? + // Maybe this method (drawBox) is anyway obsolete when extraSpace + // is fully supported (as here, in the "dillo_grows" repository). + int xPad, yPad, widthPad, heightPad; getPaddingArea (&xPad, &yPad, &widthPad, &heightPad); style::drawBackground @@ -1432,7 +1436,8 @@ void Widget::drawBox (View *view, style::Style *style, Rectangle *area, - style->margin.right - style->borderWidth.right, height - style->margin.top - style->borderWidth.top - style->margin.bottom - style->borderWidth.bottom, - xPad, yPad, widthPad, heightPad, style, inverse, false); + xPad, yPad, widthPad, heightPad, style, style->backgroundColor, + inverse, false); } /** @@ -1456,10 +1461,26 @@ void Widget::drawWidgetBox (View *view, Rectangle *area, bool inverse) int xPad, yPad, widthPad, heightPad; getPaddingArea (&xPad, &yPad, &widthPad, &heightPad); + + style::Color *bgColor; + if (inverse && style->backgroundColor == NULL) { + // See style::drawBackground: for inverse drawing, we need a + // defined background color. Search through ancestors. + Widget *w = this; + while (w != NULL && w->style->backgroundColor == NULL) + w = w->parent; + + if (w != NULL && w->style->backgroundColor != NULL) + bgColor = w->style->backgroundColor; + else + bgColor = layout->getBgColor (); + } else + bgColor = style->backgroundColor; + style::drawBackground (view, layout, &canvasArea, xPad, yPad, widthPad, heightPad, xPad, yPad, widthPad, heightPad, - style, inverse, parent == NULL); + style, bgColor, inverse, parent == NULL); } /* |