2 * This file is part of the html renderer for KDE.
4 * Copyright (C) 2003, 2006 Apple Computer, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "InlineFlowBox.h"
24 #include "CachedImage.h"
26 #include "EllipsisBox.h"
27 #include "GraphicsContext.h"
28 #include "InlineTextBox.h"
29 #include "RootInlineBox.h"
30 #include "RenderBlock.h"
31 #include "RenderFlow.h"
32 #include "render_list.h"
33 #include "RenderTableCell.h"
39 RenderFlow* InlineFlowBox::flowObject()
41 return static_cast<RenderFlow*>(m_object);
44 int InlineFlowBox::marginLeft()
46 if (!includeLeftEdge())
49 Length margin = object()->style()->marginLeft();
53 return margin.value();
54 return object()->marginLeft();
57 int InlineFlowBox::marginRight()
59 if (!includeRightEdge())
62 Length margin = object()->style()->marginRight();
66 return margin.value();
67 return object()->marginRight();
70 int InlineFlowBox::marginBorderPaddingLeft()
72 return marginLeft() + borderLeft() + paddingLeft();
75 int InlineFlowBox::marginBorderPaddingRight()
77 return marginRight() + borderRight() + paddingRight();
80 int InlineFlowBox::getFlowSpacingWidth()
82 int totWidth = marginBorderPaddingLeft() + marginBorderPaddingRight();
83 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
84 if (curr->isInlineFlowBox())
85 totWidth += static_cast<InlineFlowBox*>(curr)->getFlowSpacingWidth();
90 void InlineFlowBox::addToLine(InlineBox* child) {
92 m_firstChild = m_lastChild = child;
94 m_lastChild->m_next = child;
95 child->m_prev = m_lastChild;
98 child->setFirstLineStyleBit(m_firstLine);
99 child->setParent(this);
101 m_hasTextChildren = true;
102 if (child->object()->selectionState() != RenderObject::SelectionNone)
103 root()->setHasSelectedChildren(true);
106 void InlineFlowBox::removeChild(InlineBox* child)
111 root()->childRemoved(child);
113 if (child == m_firstChild)
114 m_firstChild = child->nextOnLine();
115 if (child == m_lastChild)
116 m_lastChild = child->prevOnLine();
117 if (child->nextOnLine())
118 child->nextOnLine()->setPrevOnLine(child->prevOnLine());
119 if (child->prevOnLine())
120 child->prevOnLine()->setNextOnLine(child->nextOnLine());
125 void InlineFlowBox::deleteLine(RenderArena* arena)
127 InlineBox* child = m_firstChild;
130 next = child->nextOnLine();
131 child->deleteLine(arena);
135 static_cast<RenderFlow*>(m_object)->removeLineBox(this);
139 void InlineFlowBox::extractLine()
142 static_cast<RenderFlow*>(m_object)->extractLineBox(this);
143 for (InlineBox* child = m_firstChild; child; child = child->nextOnLine())
144 child->extractLine();
147 void InlineFlowBox::attachLine()
150 static_cast<RenderFlow*>(m_object)->attachLineBox(this);
151 for (InlineBox* child = m_firstChild; child; child = child->nextOnLine())
155 void InlineFlowBox::adjustPosition(int dx, int dy)
157 InlineRunBox::adjustPosition(dx, dy);
158 for (InlineBox* child = m_firstChild; child; child = child->nextOnLine())
159 child->adjustPosition(dx, dy);
162 bool InlineFlowBox::onEndChain(RenderObject* endObject)
167 if (endObject == object())
170 RenderObject* curr = endObject;
171 RenderObject* parent = curr->parent();
172 while (parent && !parent->isRenderBlock()) {
173 if (parent->lastChild() != curr || parent == object())
177 parent = curr->parent();
183 void InlineFlowBox::determineSpacingForFlowBoxes(bool lastLine, RenderObject* endObject)
185 // All boxes start off open. They will not apply any margins/border/padding on
187 bool includeLeftEdge = false;
188 bool includeRightEdge = false;
190 RenderFlow* flow = static_cast<RenderFlow*>(object());
192 if (!flow->firstChild())
193 includeLeftEdge = includeRightEdge = true; // Empty inlines never split across lines.
194 else if (parent()) { // The root inline box never has borders/margins/padding.
195 bool ltr = flow->style()->direction() == LTR;
197 // Check to see if all initial lines are unconstructed. If so, then
198 // we know the inline began on this line.
199 if (!flow->firstLineBox()->isConstructed()) {
200 if (ltr && flow->firstLineBox() == this)
201 includeLeftEdge = true;
202 else if (!ltr && flow->lastLineBox() == this)
203 includeRightEdge = true;
206 // In order to determine if the inline ends on this line, we check three things:
207 // (1) If we are the last line and we don't have a continuation(), then we can
209 // (2) If the last line box for the flow has an object following it on the line (ltr,
210 // reverse for rtl), then the inline has closed.
211 // (3) The line may end on the inline. If we are the last child (climbing up
212 // the end object's chain), then we just closed as well.
213 if (!flow->lastLineBox()->isConstructed()) {
215 if (!nextLineBox() &&
216 ((lastLine && !object()->continuation()) || nextOnLineExists() || onEndChain(endObject)))
217 includeRightEdge = true;
219 if ((!prevLineBox() || prevLineBox()->isConstructed()) &&
220 ((lastLine && !object()->continuation()) || prevOnLineExists() || onEndChain(endObject)))
221 includeLeftEdge = true;
226 setEdges(includeLeftEdge, includeRightEdge);
228 // Recur into our children.
229 for (InlineBox* currChild = firstChild(); currChild; currChild = currChild->nextOnLine()) {
230 if (currChild->isInlineFlowBox()) {
231 InlineFlowBox* currFlow = static_cast<InlineFlowBox*>(currChild);
232 currFlow->determineSpacingForFlowBoxes(lastLine, endObject);
237 int InlineFlowBox::placeBoxesHorizontally(int x, int& leftPosition, int& rightPosition, bool& needsWordSpacing)
239 // Set our x position.
241 leftPosition = min(x, leftPosition);
244 x += borderLeft() + paddingLeft();
246 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
247 if (curr->object()->isText()) {
248 InlineTextBox* text = static_cast<InlineTextBox*>(curr);
249 RenderText* rt = static_cast<RenderText*>(text->object());
251 if (needsWordSpacing && QChar(rt->text()[text->start()]).isSpace())
252 x += rt->font(m_firstLine)->wordSpacing();
253 needsWordSpacing = !QChar(rt->text()[text->end()]).isSpace();
258 for (ShadowData* shadow = rt->style()->textShadow(); shadow; shadow = shadow->next) {
259 shadowLeft = min(shadowLeft, shadow->x - shadow->blur);
260 shadowRight = max(shadowRight, shadow->x + shadow->blur);
262 leftPosition = min(x + shadowLeft, leftPosition);
263 rightPosition = max(x + text->width() + shadowRight, rightPosition);
264 m_maxHorizontalShadow = max(max(shadowRight, -shadowLeft), m_maxHorizontalShadow);
267 if (curr->object()->isPositioned()) {
268 if (curr->object()->parent()->style()->direction() == LTR)
271 // Our offset that we cache needs to be from the edge of the right border box and
272 // not the left border box. We have to subtract |x| from the width of the block
273 // (which can be obtained from the root line box).
274 curr->setXPos(root()->object()->width()-x);
275 continue; // The positioned object has no effect on the width.
277 if (curr->object()->isInlineFlow()) {
278 InlineFlowBox* flow = static_cast<InlineFlowBox*>(curr);
279 if (curr->object()->isCompact()) {
281 flow->placeBoxesHorizontally(ignoredX, leftPosition, rightPosition, needsWordSpacing);
283 x += flow->marginLeft();
284 x = flow->placeBoxesHorizontally(x, leftPosition, rightPosition, needsWordSpacing);
285 x += flow->marginRight();
287 } else if (!curr->object()->isCompact() && (!curr->object()->isListMarker() || static_cast<RenderListMarker*>(curr->object())->isInside())) {
288 x += curr->object()->marginLeft();
290 leftPosition = min(x, leftPosition);
291 rightPosition = max(x + curr->width(), rightPosition);
292 x += curr->width() + curr->object()->marginRight();
297 x += borderRight() + paddingRight();
299 rightPosition = max(xPos() + width(), rightPosition);
304 void InlineFlowBox::verticallyAlignBoxes(int& heightOfBlock)
306 int maxPositionTop = 0;
307 int maxPositionBottom = 0;
311 // Figure out if we're in strict mode. Note that we can't simply use !style()->htmlHacks(),
312 // because that would match almost strict mode as well.
313 RenderObject* curr = object();
314 while (curr && !curr->element())
315 curr = curr->container();
316 bool strictMode = (curr && curr->document()->inStrictMode());
318 computeLogicalBoxHeights(maxPositionTop, maxPositionBottom, maxAscent, maxDescent, strictMode);
320 if (maxAscent + maxDescent < max(maxPositionTop, maxPositionBottom))
321 adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPositionBottom);
323 int maxHeight = maxAscent + maxDescent;
324 int topPosition = heightOfBlock;
325 int bottomPosition = heightOfBlock;
326 int selectionTop = heightOfBlock;
327 int selectionBottom = heightOfBlock;
328 placeBoxesVertically(heightOfBlock, maxHeight, maxAscent, strictMode, topPosition, bottomPosition, selectionTop, selectionBottom);
330 setVerticalOverflowPositions(topPosition, bottomPosition);
331 setVerticalSelectionPositions(selectionTop, selectionBottom);
333 // Shrink boxes with no text children in quirks and almost strict mode.
335 shrinkBoxesWithNoTextChildren(topPosition, bottomPosition);
337 heightOfBlock += maxHeight;
340 void InlineFlowBox::adjustMaxAscentAndDescent(int& maxAscent, int& maxDescent,
341 int maxPositionTop, int maxPositionBottom)
343 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
344 // The computed lineheight needs to be extended for the
345 // positioned elements
346 if (curr->object()->isPositioned())
347 continue; // Positioned placeholders don't affect calculations.
348 if (curr->yPos() == PositionTop || curr->yPos() == PositionBottom) {
349 if (curr->yPos() == PositionTop) {
350 if (maxAscent + maxDescent < curr->height())
351 maxDescent = curr->height() - maxAscent;
354 if (maxAscent + maxDescent < curr->height())
355 maxAscent = curr->height() - maxDescent;
358 if (maxAscent + maxDescent >= max(maxPositionTop, maxPositionBottom))
362 if (curr->isInlineFlowBox())
363 static_cast<InlineFlowBox*>(curr)->adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPositionBottom);
367 void InlineFlowBox::computeLogicalBoxHeights(int& maxPositionTop, int& maxPositionBottom,
368 int& maxAscent, int& maxDescent, bool strictMode)
370 if (isRootInlineBox()) {
371 // Examine our root box.
372 setHeight(object()->lineHeight(m_firstLine, true));
373 bool isTableCell = object()->isTableCell();
375 RenderTableCell* tableCell = static_cast<RenderTableCell*>(object());
376 setBaseline(tableCell->RenderBlock::baselinePosition(m_firstLine, true));
379 setBaseline(object()->baselinePosition(m_firstLine, true));
380 if (hasTextChildren() || strictMode) {
381 int ascent = baseline();
382 int descent = height() - ascent;
383 if (maxAscent < ascent)
385 if (maxDescent < descent)
386 maxDescent = descent;
390 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
391 if (curr->object()->isPositioned())
392 continue; // Positioned placeholders don't affect calculations.
394 curr->setHeight(curr->object()->lineHeight(m_firstLine));
395 curr->setBaseline(curr->object()->baselinePosition(m_firstLine));
396 curr->setYPos(curr->object()->verticalPositionHint(m_firstLine));
397 if (curr->yPos() == PositionTop) {
398 if (maxPositionTop < curr->height())
399 maxPositionTop = curr->height();
401 else if (curr->yPos() == PositionBottom) {
402 if (maxPositionBottom < curr->height())
403 maxPositionBottom = curr->height();
405 else if (curr->hasTextChildren() || strictMode) {
406 int ascent = curr->baseline() - curr->yPos();
407 int descent = curr->height() - ascent;
408 if (maxAscent < ascent)
410 if (maxDescent < descent)
411 maxDescent = descent;
414 if (curr->isInlineFlowBox())
415 static_cast<InlineFlowBox*>(curr)->computeLogicalBoxHeights(maxPositionTop, maxPositionBottom, maxAscent, maxDescent, strictMode);
419 void InlineFlowBox::placeBoxesVertically(int y, int maxHeight, int maxAscent, bool strictMode,
420 int& topPosition, int& bottomPosition, int& selectionTop, int& selectionBottom)
422 if (isRootInlineBox())
423 setYPos(y + maxAscent - baseline());// Place our root box.
425 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
426 if (curr->object()->isPositioned())
427 continue; // Positioned placeholders don't affect calculations.
429 // Adjust boxes to use their real box y/height and not the logical height (as dictated by
431 if (curr->isInlineFlowBox())
432 static_cast<InlineFlowBox*>(curr)->placeBoxesVertically(y, maxHeight, maxAscent, strictMode, topPosition, bottomPosition, selectionTop, selectionBottom);
434 bool childAffectsTopBottomPos = true;
435 if (curr->yPos() == PositionTop)
437 else if (curr->yPos() == PositionBottom)
438 curr->setYPos(y + maxHeight - curr->height());
440 if (!curr->hasTextChildren() && !strictMode)
441 childAffectsTopBottomPos = false;
442 curr->setYPos(curr->yPos() + y + maxAscent - curr->baseline());
445 int newY = curr->yPos();
446 int newHeight = curr->height();
447 int newBaseline = curr->baseline();
449 int overflowBottom = 0;
450 if (curr->isText() || curr->isInlineFlowBox()) {
451 const Font& font = curr->object()->font(m_firstLine);
452 newBaseline = font.ascent();
453 newY += curr->baseline() - newBaseline;
454 newHeight = newBaseline + font.descent();
455 for (ShadowData* shadow = curr->object()->style()->textShadow(); shadow; shadow = shadow->next) {
456 overflowTop = min(overflowTop, shadow->y - shadow->blur);
457 overflowBottom = max(overflowBottom, shadow->y + shadow->blur);
459 if (curr->isInlineFlowBox()) {
460 newHeight += curr->object()->borderTop() + curr->object()->paddingTop() +
461 curr->object()->borderBottom() + curr->object()->paddingBottom();
462 newY -= curr->object()->borderTop() + curr->object()->paddingTop();
463 newBaseline += curr->object()->borderTop() + curr->object()->paddingTop();
466 else if (!curr->object()->isBR()) {
467 newY += curr->object()->marginTop();
468 newHeight = curr->height() - (curr->object()->marginTop() + curr->object()->marginBottom());
469 overflowTop = curr->object()->overflowTop(false);
470 overflowBottom = curr->object()->overflowHeight(false) - newHeight;
474 curr->setHeight(newHeight);
475 curr->setBaseline(newBaseline);
477 if (childAffectsTopBottomPos) {
478 selectionTop = min(selectionTop, newY);
479 selectionBottom = max(selectionBottom, newY + newHeight);
480 topPosition = min(topPosition, newY + overflowTop);
481 bottomPosition = max(bottomPosition, newY + newHeight + overflowBottom);
485 if (isRootInlineBox()) {
486 const Font& font = object()->font(m_firstLine);
487 setHeight(font.ascent() + font.descent());
488 setYPos(yPos() + baseline() - font.ascent());
489 setBaseline(font.ascent());
490 if (hasTextChildren() || strictMode) {
491 selectionTop = min(selectionTop, yPos());
492 selectionBottom = max(selectionBottom, yPos() + height());
497 void InlineFlowBox::shrinkBoxesWithNoTextChildren(int topPos, int bottomPos)
499 // First shrink our kids.
500 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
501 if (curr->object()->isPositioned())
502 continue; // Positioned placeholders don't affect calculations.
504 if (curr->isInlineFlowBox())
505 static_cast<InlineFlowBox*>(curr)->shrinkBoxesWithNoTextChildren(topPos, bottomPos);
508 // See if we have text children. If not, then we need to shrink ourselves to fit on the line.
509 if (!hasTextChildren()) {
512 if (yPos() + height() > bottomPos)
513 setHeight(bottomPos - yPos());
514 if (baseline() > height())
515 setBaseline(height());
519 bool InlineFlowBox::nodeAtPoint(RenderObject::NodeInfo& i, int x, int y, int tx, int ty)
521 // Check children first.
522 for (InlineBox* curr = lastChild(); curr; curr = curr->prevOnLine()) {
523 if (!curr->object()->layer() && curr->nodeAtPoint(i, x, y, tx, ty)) {
524 object()->setInnerNode(i);
529 // Now check ourselves.
530 IntRect rect(tx + m_x, ty + m_y, m_width, m_height);
531 if (object()->style()->visibility() == VISIBLE && rect.contains(x, y)) {
532 object()->setInnerNode(i);
539 void InlineFlowBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
541 int xPos = tx + m_x - object()->maximalOutlineSize(i.phase);
542 int w = width() + 2 * object()->maximalOutlineSize(i.phase);
543 bool intersectsDamageRect = xPos < i.r.right() && xPos + w > i.r.x();
545 if (intersectsDamageRect && i.phase != PaintPhaseChildOutlines) {
546 if (i.phase == PaintPhaseOutline || i.phase == PaintPhaseSelfOutline) {
547 // Add ourselves to the paint info struct's list of inlines that need to paint their
549 if (object()->style()->visibility() == VISIBLE && object()->style()->outlineWidth() > 0 &&
550 !object()->isInlineContinuation() && !isRootInlineBox()) {
551 i.outlineObjects->add(flowObject());
555 // 1. Paint our background and border.
556 paintBackgroundAndBorder(i, tx, ty);
558 // 2. Paint our underline and overline.
559 paintDecorations(i, tx, ty, false);
563 PaintPhase paintPhase = i.phase == PaintPhaseChildOutlines ? PaintPhaseOutline : i.phase;
564 RenderObject::PaintInfo childInfo(i);
565 childInfo.phase = paintPhase;
567 // 3. Paint our children.
568 if (paintPhase != PaintPhaseSelfOutline) {
569 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
570 if (!curr->object()->layer())
571 curr->paint(childInfo, tx, ty);
575 // 4. Paint our strike-through
576 if (intersectsDamageRect && (i.phase == PaintPhaseForeground || i.phase == PaintPhaseSelection))
577 paintDecorations(i, tx, ty, true);
580 void InlineFlowBox::paintBackgrounds(GraphicsContext* p, const Color& c, const BackgroundLayer* bgLayer,
581 int my, int mh, int _tx, int _ty, int w, int h)
585 paintBackgrounds(p, c, bgLayer->next(), my, mh, _tx, _ty, w, h);
586 paintBackground(p, c, bgLayer, my, mh, _tx, _ty, w, h);
589 void InlineFlowBox::paintBackground(GraphicsContext* p, const Color& c, const BackgroundLayer* bgLayer,
590 int my, int mh, int _tx, int _ty, int w, int h)
592 CachedImage* bg = bgLayer->backgroundImage();
593 bool hasBackgroundImage = bg && bg->canRender();
594 if (!hasBackgroundImage || (!prevLineBox() && !nextLineBox()) || !parent())
595 object()->paintBackgroundExtended(p, c, bgLayer, my, mh, _tx, _ty, w, h,
596 borderLeft(), borderRight(), paddingLeft(), paddingRight());
598 // We have a background image that spans multiple lines.
599 // We need to adjust _tx and _ty by the width of all previous lines.
600 // Think of background painting on inlines as though you had one long line, a single continuous
601 // strip. Even though that strip has been broken up across multiple lines, you still paint it
602 // as though you had one single line. This means each line has to pick up the background where
603 // the previous line left off.
604 // FIXME: What the heck do we do with RTL here? The math we're using is obviously not right,
605 // but it isn't even clear how this should work at all.
606 int xOffsetOnLine = 0;
607 for (InlineRunBox* curr = prevLineBox(); curr; curr = curr->prevLineBox())
608 xOffsetOnLine += curr->width();
609 int startX = _tx - xOffsetOnLine;
610 int totalWidth = xOffsetOnLine;
611 for (InlineRunBox* curr = this; curr; curr = curr->nextLineBox())
612 totalWidth += curr->width();
614 p->addClip(IntRect(_tx, _ty, width(), height()));
615 object()->paintBackgroundExtended(p, c, bgLayer, my, mh, startX, _ty,
616 totalWidth, h, borderLeft(), borderRight(), paddingLeft(), paddingRight());
621 void InlineFlowBox::paintBackgroundAndBorder(RenderObject::PaintInfo& i, int _tx, int _ty)
623 if (!object()->shouldPaintWithinRoot(i) || object()->style()->visibility() != VISIBLE ||
624 i.phase != PaintPhaseForeground)
627 // Move x/y to our coordinates.
634 int my = max(_ty, i.r.y());
637 mh = max(0, h - (i.r.y() - _ty));
639 mh = min(i.r.height(), h);
641 GraphicsContext* p = i.p;
643 // You can use p::first-line to specify a background. If so, the root line boxes for
644 // a line may actually have to paint a background.
645 RenderStyle* styleToUse = object()->style(m_firstLine);
646 if ((!parent() && m_firstLine && styleToUse != object()->style()) ||
647 (parent() && object()->shouldPaintBackgroundOrBorder())) {
648 Color c = styleToUse->backgroundColor();
649 paintBackgrounds(p, c, styleToUse->backgroundLayers(), my, mh, _tx, _ty, w, h);
651 // :first-line cannot be used to put borders on a line. Always paint borders with our
652 // non-first-line style.
653 if (parent() && object()->style()->hasBorder()) {
654 CachedImage* borderImage = object()->style()->borderImage().image();
655 bool hasBorderImage = borderImage && borderImage->canRender();
656 if (hasBorderImage && !borderImage->isLoaded())
657 return; // Don't paint anything while we wait for the image to load.
659 // The simple case is where we either have no border image or we are the only box for this object. In those
660 // cases only a single call to draw is required.
661 if (!hasBorderImage || (!prevLineBox() && !nextLineBox()))
662 object()->paintBorder(p, _tx, _ty, w, h, object()->style(), includeLeftEdge(), includeRightEdge());
664 // We have a border image that spans multiple lines.
665 // We need to adjust _tx and _ty by the width of all previous lines.
666 // Think of border image painting on inlines as though you had one long line, a single continuous
667 // strip. Even though that strip has been broken up across multiple lines, you still paint it
668 // as though you had one single line. This means each line has to pick up the image where
669 // the previous line left off.
670 // FIXME: What the heck do we do with RTL here? The math we're using is obviously not right,
671 // but it isn't even clear how this should work at all.
672 int xOffsetOnLine = 0;
673 for (InlineRunBox* curr = prevLineBox(); curr; curr = curr->prevLineBox())
674 xOffsetOnLine += curr->width();
675 int startX = _tx - xOffsetOnLine;
676 int totalWidth = xOffsetOnLine;
677 for (InlineRunBox* curr = this; curr; curr = curr->nextLineBox())
678 totalWidth += curr->width();
680 p->addClip(IntRect(_tx, _ty, width(), height()));
681 object()->paintBorder(p, startX, _ty, totalWidth, h, object()->style());
688 static bool shouldDrawDecoration(RenderObject* obj)
690 for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling()) {
691 if (curr->isInlineFlow())
693 if (curr->isText() && !curr->isBR()) {
694 if (!curr->style()->collapseWhiteSpace())
696 Node* currElement = curr->element();
699 if (!currElement->isTextNode())
701 if (!static_cast<Text*>(currElement)->containsOnlyWhitespace())
708 void InlineFlowBox::paintDecorations(RenderObject::PaintInfo& i, int _tx, int _ty, bool paintedChildren)
710 // Paint text decorations like underlines/overlines. We only do this if we aren't in quirks mode (i.e., in
711 // almost-strict mode or strict mode).
712 if (object()->style()->htmlHacks() || !object()->shouldPaintWithinRoot(i) ||
713 object()->style()->visibility() != VISIBLE)
716 GraphicsContext* p = i.p;
719 RenderStyle* styleToUse = object()->style(m_firstLine);
720 int deco = parent() ? styleToUse->textDecoration() : styleToUse->textDecorationsInEffect();
721 if (deco != TDNONE &&
722 ((!paintedChildren && ((deco & UNDERLINE) || (deco & OVERLINE))) || (paintedChildren && (deco & LINE_THROUGH))) &&
723 shouldDrawDecoration(object())) {
724 int x = m_x + borderLeft() + paddingLeft();
725 int w = m_width - (borderLeft() + paddingLeft() + borderRight() + paddingRight());
726 RootInlineBox* rootLine = root();
727 if (rootLine->ellipsisBox()) {
728 int ellipsisX = rootLine->ellipsisBox()->xPos();
729 int ellipsisWidth = rootLine->ellipsisBox()->width();
731 // FIXME: Will need to work with RTL
732 if (rootLine == this) {
733 if (x + w >= ellipsisX + ellipsisWidth)
734 w -= (x + w - ellipsisX - ellipsisWidth);
739 if (x + w >= ellipsisX)
740 w -= (x + w - ellipsisX);
744 // Set up the appropriate text-shadow effect for the decoration.
745 // FIXME: Support multiple shadow effects. Need more from the CG API before we can do this.
746 bool setShadow = false;
747 if (styleToUse->textShadow()) {
748 p->setShadow(IntSize(styleToUse->textShadow()->x, styleToUse->textShadow()->y),
749 styleToUse->textShadow()->blur, styleToUse->textShadow()->color);
753 // We must have child boxes and have decorations defined.
754 _tx += borderLeft() + paddingLeft();
756 Color underline, overline, linethrough;
757 underline = overline = linethrough = styleToUse->color();
759 object()->getTextDecorationColors(deco, underline, overline, linethrough);
761 if (styleToUse->font() != p->font())
762 p->setFont(styleToUse->font());
764 bool isPrinting = object()->document()->printing();
765 if (deco & UNDERLINE && !paintedChildren) {
766 p->setPen(underline);
767 p->drawLineForText(IntPoint(_tx, _ty), m_baseline, w, isPrinting);
769 if (deco & OVERLINE && !paintedChildren) {
771 p->drawLineForText(IntPoint(_tx, _ty), 0, w, isPrinting);
773 if (deco & LINE_THROUGH && paintedChildren) {
774 p->setPen(linethrough);
775 p->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, w, isPrinting);
783 InlineBox* InlineFlowBox::firstLeafChild()
785 return firstLeafChildAfterBox();
788 InlineBox* InlineFlowBox::lastLeafChild()
790 return lastLeafChildBeforeBox();
793 InlineBox* InlineFlowBox::firstLeafChildAfterBox(InlineBox* start)
796 for (InlineBox* box = start ? start->nextOnLine() : firstChild(); box && !leaf; box = box->nextOnLine())
797 leaf = box->firstLeafChild();
798 if (start && !leaf && parent())
799 return parent()->firstLeafChildAfterBox(this);
803 InlineBox* InlineFlowBox::lastLeafChildBeforeBox(InlineBox* start)
806 for (InlineBox* box = start ? start->prevOnLine() : lastChild(); box && !leaf; box = box->prevOnLine())
807 leaf = box->lastLeafChild();
808 if (start && !leaf && parent())
809 return parent()->lastLeafChildBeforeBox(this);
813 RenderObject::SelectionState InlineFlowBox::selectionState()
815 return RenderObject::SelectionNone;
818 bool InlineFlowBox::canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth)
820 for (InlineBox *box = firstChild(); box; box = box->nextOnLine()) {
821 if (!box->canAccommodateEllipsis(ltr, blockEdge, ellipsisWidth))
827 int InlineFlowBox::placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool& foundBox)
830 for (InlineBox *box = firstChild(); box; box = box->nextOnLine()) {
831 int currResult = box->placeEllipsisBox(ltr, blockEdge, ellipsisWidth, foundBox);
832 if (currResult != -1 && result == -1)
838 void InlineFlowBox::clearTruncation()
840 for (InlineBox *box = firstChild(); box; box = box->nextOnLine())
841 box->clearTruncation();