2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "InlineFlowBox.h"
23 #include "CSSPropertyNames.h"
25 #include "EllipsisBox.h"
27 #include "GraphicsContext.h"
28 #include "InlineTextBox.h"
29 #include "HitTestResult.h"
30 #include "RenderBlock.h"
31 #include "RenderInline.h"
32 #include "RenderLayer.h"
33 #include "RenderListMarker.h"
34 #include "RenderRubyBase.h"
35 #include "RenderRubyRun.h"
36 #include "RenderRubyText.h"
37 #include "RenderTableCell.h"
38 #include "RenderView.h"
39 #include "RootInlineBox.h"
48 struct SameSizeAsInlineFlowBox : public InlineBox {
50 uint32_t bitfields : 23;
53 COMPILE_ASSERT(sizeof(InlineFlowBox) == sizeof(SameSizeAsInlineFlowBox), InlineFlowBox_should_stay_small);
57 InlineFlowBox::~InlineFlowBox()
59 if (!m_hasBadChildList)
60 for (InlineBox* child = firstChild(); child; child = child->nextOnLine())
61 child->setHasBadParent();
66 LayoutUnit InlineFlowBox::getFlowSpacingLogicalWidth()
68 LayoutUnit totWidth = marginBorderPaddingLogicalLeft() + marginBorderPaddingLogicalRight();
69 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
70 if (curr->isInlineFlowBox())
71 totWidth += toInlineFlowBox(curr)->getFlowSpacingLogicalWidth();
76 IntRect InlineFlowBox::roundedFrameRect() const
78 // Begin by snapping the x and y coordinates to the nearest pixel.
79 int snappedX = lroundf(x());
80 int snappedY = lroundf(y());
82 int snappedMaxX = lroundf(x() + width());
83 int snappedMaxY = lroundf(y() + height());
85 return IntRect(snappedX, snappedY, snappedMaxX - snappedX, snappedMaxY - snappedY);
88 static void setHasTextDescendantsOnAncestors(InlineFlowBox* box)
90 while (box && !box->hasTextDescendants()) {
91 box->setHasTextDescendants();
96 void InlineFlowBox::addToLine(InlineBox* child)
98 ASSERT(!child->parent());
99 ASSERT(!child->nextOnLine());
100 ASSERT(!child->prevOnLine());
103 child->setParent(this);
105 m_firstChild = child;
108 m_lastChild->setNextOnLine(child);
109 child->setPrevOnLine(m_lastChild);
112 child->setFirstLineStyleBit(isFirstLineStyle());
113 child->setIsHorizontal(isHorizontal());
114 if (child->behavesLikeText()) {
115 if (child->renderer().parent() == &renderer())
116 m_hasTextChildren = true;
117 setHasTextDescendantsOnAncestors(this);
118 } else if (child->isInlineFlowBox()) {
119 if (toInlineFlowBox(child)->hasTextDescendants())
120 setHasTextDescendantsOnAncestors(this);
123 if (descendantsHaveSameLineHeightAndBaseline() && !child->renderer().isOutOfFlowPositioned()) {
124 RenderStyle* parentStyle = renderer().style(isFirstLineStyle());
125 RenderStyle* childStyle = child->renderer().style(isFirstLineStyle());
126 bool shouldClearDescendantsHaveSameLineHeightAndBaseline = false;
127 if (child->renderer().isReplaced())
128 shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
129 else if (child->behavesLikeText()) {
130 if (child->renderer().isLineBreak() || child->renderer().parent() != &renderer()) {
131 if (!parentStyle->font().fontMetrics().hasIdenticalAscentDescentAndLineGap(childStyle->font().fontMetrics())
132 || parentStyle->lineHeight() != childStyle->lineHeight()
133 || (parentStyle->verticalAlign() != BASELINE && !isRootInlineBox()) || childStyle->verticalAlign() != BASELINE)
134 shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
136 if (childStyle->hasTextCombine() || childStyle->textEmphasisMark() != TextEmphasisMarkNone)
137 shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
139 if (child->renderer().isLineBreak()) {
140 // FIXME: This is dumb. We only turn off because current layout test results expect the <br> to be 0-height on the baseline.
141 // Other than making a zillion tests have to regenerate results, there's no reason to ditch the optimization here.
142 shouldClearDescendantsHaveSameLineHeightAndBaseline = child->renderer().isBR();
144 ASSERT(isInlineFlowBox());
145 InlineFlowBox* childFlowBox = toInlineFlowBox(child);
146 // Check the child's bit, and then also check for differences in font, line-height, vertical-align
147 if (!childFlowBox->descendantsHaveSameLineHeightAndBaseline()
148 || !parentStyle->font().fontMetrics().hasIdenticalAscentDescentAndLineGap(childStyle->font().fontMetrics())
149 || parentStyle->lineHeight() != childStyle->lineHeight()
150 || (parentStyle->verticalAlign() != BASELINE && !isRootInlineBox()) || childStyle->verticalAlign() != BASELINE
151 || childStyle->hasBorder() || childStyle->hasPadding() || childStyle->hasTextCombine())
152 shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
156 if (shouldClearDescendantsHaveSameLineHeightAndBaseline)
157 clearDescendantsHaveSameLineHeightAndBaseline();
160 if (!child->renderer().isOutOfFlowPositioned()) {
161 if (child->behavesLikeText()) {
162 RenderStyle* childStyle = child->renderer().style(isFirstLineStyle());
163 if (childStyle->letterSpacing() < 0 || childStyle->textShadow() || childStyle->textEmphasisMark() != TextEmphasisMarkNone || childStyle->textStrokeWidth())
164 child->clearKnownToHaveNoOverflow();
165 } else if (child->renderer().isReplaced()) {
166 const RenderBox& box = toRenderBox(child->renderer());
167 if (box.hasRenderOverflow() || box.hasSelfPaintingLayer())
168 child->clearKnownToHaveNoOverflow();
169 } else if (!child->renderer().isLineBreak() && (child->renderer().style(isFirstLineStyle())->boxShadow() || child->boxModelObject()->hasSelfPaintingLayer()
170 || (child->renderer().isListMarker() && !toRenderListMarker(child->renderer()).isInside())
171 || child->renderer().style(isFirstLineStyle())->hasBorderImageOutsets()))
172 child->clearKnownToHaveNoOverflow();
174 if (knownToHaveNoOverflow() && child->isInlineFlowBox() && !toInlineFlowBox(child)->knownToHaveNoOverflow())
175 clearKnownToHaveNoOverflow();
181 void InlineFlowBox::removeChild(InlineBox* child)
188 root().childRemoved(child);
190 if (child == m_firstChild)
191 m_firstChild = child->nextOnLine();
192 if (child == m_lastChild)
193 m_lastChild = child->prevOnLine();
194 if (child->nextOnLine())
195 child->nextOnLine()->setPrevOnLine(child->prevOnLine());
196 if (child->prevOnLine())
197 child->prevOnLine()->setNextOnLine(child->nextOnLine());
204 void InlineFlowBox::deleteLine(RenderArena& arena)
206 InlineBox* child = firstChild();
209 ASSERT(this == child->parent());
210 next = child->nextOnLine();
214 child->deleteLine(arena);
222 removeLineBoxFromRenderObject();
226 void InlineFlowBox::removeLineBoxFromRenderObject()
228 toRenderInline(renderer()).lineBoxes().removeLineBox(this);
231 void InlineFlowBox::extractLine()
234 extractLineBoxFromRenderObject();
235 for (InlineBox* child = firstChild(); child; child = child->nextOnLine())
236 child->extractLine();
239 void InlineFlowBox::extractLineBoxFromRenderObject()
241 toRenderInline(renderer()).lineBoxes().extractLineBox(this);
244 void InlineFlowBox::attachLine()
247 attachLineBoxToRenderObject();
248 for (InlineBox* child = firstChild(); child; child = child->nextOnLine())
252 void InlineFlowBox::attachLineBoxToRenderObject()
254 toRenderInline(renderer()).lineBoxes().attachLineBox(this);
257 void InlineFlowBox::adjustPosition(float dx, float dy)
259 InlineBox::adjustPosition(dx, dy);
260 for (InlineBox* child = firstChild(); child; child = child->nextOnLine())
261 child->adjustPosition(dx, dy);
263 m_overflow->move(dx, dy); // FIXME: Rounding error here since overflow was pixel snapped, but nobody other than list markers passes non-integral values here.
266 RenderLineBoxList& InlineFlowBox::rendererLineBoxes() const
268 return toRenderInline(renderer()).lineBoxes();
271 static inline bool isLastChildForRenderer(RenderElement* ancestor, RenderObject* child)
276 if (child == ancestor)
279 RenderObject* curr = child;
280 RenderElement* parent = curr->parent();
281 while (parent && (!parent->isRenderBlock() || parent->isInline())) {
282 if (parent->lastChild() != curr)
284 if (parent == ancestor)
288 parent = curr->parent();
294 static bool isAncestorAndWithinBlock(RenderObject& ancestor, RenderObject* child)
296 RenderObject* object = child;
297 while (object && (!object->isRenderBlock() || object->isInline())) {
298 if (object == &ancestor)
300 object = object->parent();
305 void InlineFlowBox::determineSpacingForFlowBoxes(bool lastLine, bool isLogicallyLastRunWrapped, RenderObject* logicallyLastRunRenderer)
307 // All boxes start off open. They will not apply any margins/border/padding on
309 bool includeLeftEdge = false;
310 bool includeRightEdge = false;
312 // The root inline box never has borders/margins/padding.
314 bool ltr = renderer().style()->isLeftToRightDirection();
316 // Check to see if all initial lines are unconstructed. If so, then
317 // we know the inline began on this line (unless we are a continuation).
318 RenderLineBoxList& lineBoxList = rendererLineBoxes();
319 if (!lineBoxList.firstLineBox()->isConstructed() && !renderer().isInlineElementContinuation()) {
320 #if ENABLE(CSS_BOX_DECORATION_BREAK)
321 if (renderer().style()->boxDecorationBreak() == DCLONE)
322 includeLeftEdge = includeRightEdge = true;
325 if (ltr && lineBoxList.firstLineBox() == this)
326 includeLeftEdge = true;
327 else if (!ltr && lineBoxList.lastLineBox() == this)
328 includeRightEdge = true;
331 if (!lineBoxList.lastLineBox()->isConstructed()) {
332 RenderInline& inlineFlow = toRenderInline(renderer());
333 bool isLastObjectOnLine = !isAncestorAndWithinBlock(renderer(), logicallyLastRunRenderer) || (isLastChildForRenderer(&renderer(), logicallyLastRunRenderer) && !isLogicallyLastRunWrapped);
335 // We include the border under these conditions:
336 // (1) The next line was not created, or it is constructed. We check the previous line for rtl.
337 // (2) The logicallyLastRun is not a descendant of this renderer.
338 // (3) The logicallyLastRun is a descendant of this renderer, but it is the last child of this renderer and it does not wrap to the next line.
339 #if ENABLE(CSS_BOX_DECORATION_BREAK)
340 // (4) The decoration break is set to clone therefore there will be borders on every sides.
341 if (renderer().style()->boxDecorationBreak() == DCLONE)
342 includeLeftEdge = includeRightEdge = true;
347 && ((lastLine || isLastObjectOnLine) && !inlineFlow.continuation()))
348 includeRightEdge = true;
350 if ((!prevLineBox() || prevLineBox()->isConstructed())
351 && ((lastLine || isLastObjectOnLine) && !inlineFlow.continuation()))
352 includeLeftEdge = true;
357 setEdges(includeLeftEdge, includeRightEdge);
359 // Recur into our children.
360 for (InlineBox* currChild = firstChild(); currChild; currChild = currChild->nextOnLine()) {
361 if (currChild->isInlineFlowBox()) {
362 InlineFlowBox* currFlow = toInlineFlowBox(currChild);
363 currFlow->determineSpacingForFlowBoxes(lastLine, isLogicallyLastRunWrapped, logicallyLastRunRenderer);
368 float InlineFlowBox::placeBoxesInInlineDirection(float logicalLeft, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
370 // Set our x position.
371 beginPlacingBoxRangesInInlineDirection(logicalLeft);
373 float startLogicalLeft = logicalLeft;
374 logicalLeft += borderLogicalLeft() + paddingLogicalLeft();
376 float minLogicalLeft = startLogicalLeft;
377 float maxLogicalRight = logicalLeft;
379 placeBoxRangeInInlineDirection(firstChild(), 0, logicalLeft, minLogicalLeft, maxLogicalRight, needsWordSpacing, textBoxDataMap);
381 logicalLeft += borderLogicalRight() + paddingLogicalRight();
382 endPlacingBoxRangesInInlineDirection(startLogicalLeft, logicalLeft, minLogicalLeft, maxLogicalRight);
386 float InlineFlowBox::placeBoxRangeInInlineDirection(InlineBox* firstChild, InlineBox* lastChild, float& logicalLeft, float& minLogicalLeft, float& maxLogicalRight, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
388 for (InlineBox* curr = firstChild; curr && curr != lastChild; curr = curr->nextOnLine()) {
389 if (curr->renderer().isText()) {
390 InlineTextBox* text = toInlineTextBox(curr);
391 RenderText& rt = text->renderer();
392 if (rt.textLength()) {
393 if (needsWordSpacing && isSpaceOrNewline(rt.characterAt(text->start())))
394 logicalLeft += rt.style(isFirstLineStyle())->font().wordSpacing();
395 needsWordSpacing = !isSpaceOrNewline(rt.characterAt(text->end()));
397 text->setLogicalLeft(logicalLeft);
398 if (knownToHaveNoOverflow())
399 minLogicalLeft = min(logicalLeft, minLogicalLeft);
400 logicalLeft += text->logicalWidth();
401 if (knownToHaveNoOverflow())
402 maxLogicalRight = max(logicalLeft, maxLogicalRight);
404 if (curr->renderer().isOutOfFlowPositioned()) {
405 if (curr->renderer().parent()->style()->isLeftToRightDirection())
406 curr->setLogicalLeft(logicalLeft);
408 // Our offset that we cache needs to be from the edge of the right border box and
409 // not the left border box. We have to subtract |x| from the width of the block
410 // (which can be obtained from the root line box).
411 curr->setLogicalLeft(root().block().logicalWidth() - logicalLeft);
412 continue; // The positioned object has no effect on the width.
414 if (curr->renderer().isRenderInline()) {
415 InlineFlowBox* flow = toInlineFlowBox(curr);
416 logicalLeft += flow->marginLogicalLeft();
417 if (knownToHaveNoOverflow())
418 minLogicalLeft = min(logicalLeft, minLogicalLeft);
419 logicalLeft = flow->placeBoxesInInlineDirection(logicalLeft, needsWordSpacing, textBoxDataMap);
420 if (knownToHaveNoOverflow())
421 maxLogicalRight = max(logicalLeft, maxLogicalRight);
422 logicalLeft += flow->marginLogicalRight();
423 } else if (!curr->renderer().isListMarker() || toRenderListMarker(curr->renderer()).isInside()) {
424 // The box can have a different writing-mode than the overall line, so this is a bit complicated.
425 // Just get all the physical margin and overflow values by hand based off |isVertical|.
426 LayoutUnit logicalLeftMargin = isHorizontal() ? curr->boxModelObject()->marginLeft() : curr->boxModelObject()->marginTop();
427 LayoutUnit logicalRightMargin = isHorizontal() ? curr->boxModelObject()->marginRight() : curr->boxModelObject()->marginBottom();
429 logicalLeft += logicalLeftMargin;
430 curr->setLogicalLeft(logicalLeft);
431 if (knownToHaveNoOverflow())
432 minLogicalLeft = min(logicalLeft, minLogicalLeft);
433 logicalLeft += curr->logicalWidth();
434 if (knownToHaveNoOverflow())
435 maxLogicalRight = max(logicalLeft, maxLogicalRight);
436 logicalLeft += logicalRightMargin;
437 // If we encounter any space after this inline block then ensure it is treated as the space between two words.
438 needsWordSpacing = true;
445 bool InlineFlowBox::requiresIdeographicBaseline(const GlyphOverflowAndFallbackFontsMap& textBoxDataMap) const
450 if (renderer().style(isFirstLineStyle())->fontDescription().nonCJKGlyphOrientation() == NonCJKGlyphOrientationUpright
451 || renderer().style(isFirstLineStyle())->font().primaryFont()->hasVerticalGlyphs())
454 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
455 if (curr->renderer().isOutOfFlowPositioned())
456 continue; // Positioned placeholders don't affect calculations.
458 if (curr->isInlineFlowBox()) {
459 if (toInlineFlowBox(curr)->requiresIdeographicBaseline(textBoxDataMap))
462 if (curr->renderer().style(isFirstLineStyle())->font().primaryFont()->hasVerticalGlyphs())
465 const Vector<const SimpleFontData*>* usedFonts = 0;
466 if (curr->isInlineTextBox()) {
467 GlyphOverflowAndFallbackFontsMap::const_iterator it = textBoxDataMap.find(toInlineTextBox(curr));
468 usedFonts = it == textBoxDataMap.end() ? 0 : &it->value.first;
472 for (size_t i = 0; i < usedFonts->size(); ++i) {
473 if (usedFonts->at(i)->hasVerticalGlyphs())
483 static bool verticalAlignApplies(const RenderObject& renderer)
485 // http://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align - vertical-align
486 // only applies to inline level and table-cell elements
487 return !renderer.isText() || renderer.parent()->isInline() || renderer.parent()->isTableCell();
490 void InlineFlowBox::adjustMaxAscentAndDescent(int& maxAscent, int& maxDescent, int maxPositionTop, int maxPositionBottom)
492 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
493 // The computed lineheight needs to be extended for the
494 // positioned elements
495 if (curr->renderer().isOutOfFlowPositioned())
496 continue; // Positioned placeholders don't affect calculations.
498 if ((curr->verticalAlign() == TOP || curr->verticalAlign() == BOTTOM) && verticalAlignApplies(curr->renderer())) {
499 int lineHeight = curr->lineHeight();
500 if (curr->verticalAlign() == TOP) {
501 if (maxAscent + maxDescent < lineHeight)
502 maxDescent = lineHeight - maxAscent;
505 if (maxAscent + maxDescent < lineHeight)
506 maxAscent = lineHeight - maxDescent;
509 if (maxAscent + maxDescent >= max(maxPositionTop, maxPositionBottom))
513 if (curr->isInlineFlowBox())
514 toInlineFlowBox(curr)->adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPositionBottom);
518 void InlineFlowBox::computeLogicalBoxHeights(RootInlineBox* rootBox, LayoutUnit& maxPositionTop, LayoutUnit& maxPositionBottom,
519 int& maxAscent, int& maxDescent, bool& setMaxAscent, bool& setMaxDescent,
520 bool strictMode, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
521 FontBaseline baselineType, VerticalPositionCache& verticalPositionCache)
523 // The primary purpose of this function is to compute the maximal ascent and descent values for
524 // a line. These values are computed based off the block's line-box-contain property, which indicates
525 // what parts of descendant boxes have to fit within the line.
527 // The maxAscent value represents the distance of the highest point of any box (typically including line-height) from
528 // the root box's baseline. The maxDescent value represents the distance of the lowest point of any box
529 // (also typically including line-height) from the root box baseline. These values can be negative.
531 // A secondary purpose of this function is to store the offset of every box's baseline from the root box's
532 // baseline. This information is cached in the logicalTop() of every box. We're effectively just using
533 // the logicalTop() as scratch space.
535 // Because a box can be positioned such that it ends up fully above or fully below the
536 // root line box, we only consider it to affect the maxAscent and maxDescent values if some
537 // part of the box (EXCLUDING leading) is above (for ascent) or below (for descent) the root box's baseline.
538 bool affectsAscent = false;
539 bool affectsDescent = false;
540 bool checkChildren = !descendantsHaveSameLineHeightAndBaseline();
542 if (isRootInlineBox()) {
543 // Examine our root box.
546 rootBox->ascentAndDescentForBox(rootBox, textBoxDataMap, ascent, descent, affectsAscent, affectsDescent);
547 if (strictMode || hasTextChildren() || (!checkChildren && hasTextDescendants())) {
548 if (maxAscent < ascent || !setMaxAscent) {
552 if (maxDescent < descent || !setMaxDescent) {
553 maxDescent = descent;
554 setMaxDescent = true;
562 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
563 if (curr->renderer().isOutOfFlowPositioned())
564 continue; // Positioned placeholders don't affect calculations.
566 InlineFlowBox* inlineFlowBox = curr->isInlineFlowBox() ? toInlineFlowBox(curr) : 0;
568 bool affectsAscent = false;
569 bool affectsDescent = false;
571 // The verticalPositionForBox function returns the distance between the child box's baseline
572 // and the root box's baseline. The value is negative if the child box's baseline is above the
573 // root box's baseline, and it is positive if the child box's baseline is below the root box's baseline.
574 curr->setLogicalTop(rootBox->verticalPositionForBox(curr, verticalPositionCache));
578 rootBox->ascentAndDescentForBox(curr, textBoxDataMap, ascent, descent, affectsAscent, affectsDescent);
580 LayoutUnit boxHeight = ascent + descent;
581 if (curr->verticalAlign() == TOP && verticalAlignApplies(curr->renderer())) {
582 if (maxPositionTop < boxHeight)
583 maxPositionTop = boxHeight;
584 } else if (curr->verticalAlign() == BOTTOM && verticalAlignApplies(curr->renderer())) {
585 if (maxPositionBottom < boxHeight)
586 maxPositionBottom = boxHeight;
587 } else if (!inlineFlowBox || strictMode || inlineFlowBox->hasTextChildren() || (inlineFlowBox->descendantsHaveSameLineHeightAndBaseline() && inlineFlowBox->hasTextDescendants())
588 || inlineFlowBox->boxModelObject()->hasInlineDirectionBordersOrPadding()) {
589 // Note that these values can be negative. Even though we only affect the maxAscent and maxDescent values
590 // if our box (excluding line-height) was above (for ascent) or below (for descent) the root baseline, once you factor in line-height
591 // the final box can end up being fully above or fully below the root box's baseline! This is ok, but what it
592 // means is that ascent and descent (including leading), can end up being negative. The setMaxAscent and
593 // setMaxDescent booleans are used to ensure that we're willing to initially set maxAscent/Descent to negative
595 ascent -= curr->logicalTop();
596 descent += curr->logicalTop();
597 if (affectsAscent && (maxAscent < ascent || !setMaxAscent)) {
602 if (affectsDescent && (maxDescent < descent || !setMaxDescent)) {
603 maxDescent = descent;
604 setMaxDescent = true;
609 inlineFlowBox->computeLogicalBoxHeights(rootBox, maxPositionTop, maxPositionBottom, maxAscent, maxDescent,
610 setMaxAscent, setMaxDescent, strictMode, textBoxDataMap,
611 baselineType, verticalPositionCache);
615 void InlineFlowBox::placeBoxesInBlockDirection(LayoutUnit top, LayoutUnit maxHeight, int maxAscent, bool strictMode, LayoutUnit& lineTop, LayoutUnit& lineBottom, bool& setLineTop,
616 LayoutUnit& lineTopIncludingMargins, LayoutUnit& lineBottomIncludingMargins, bool& hasAnnotationsBefore, bool& hasAnnotationsAfter, FontBaseline baselineType)
618 bool isRootBox = isRootInlineBox();
620 const FontMetrics& fontMetrics = renderer().style(isFirstLineStyle())->fontMetrics();
621 // RootInlineBoxes are always placed on at pixel boundaries in their logical y direction. Not doing
622 // so results in incorrect rendering of text decorations, most notably underlines.
623 setLogicalTop(roundToInt(top + maxAscent - fontMetrics.ascent(baselineType)));
626 LayoutUnit adjustmentForChildrenWithSameLineHeightAndBaseline = 0;
627 if (descendantsHaveSameLineHeightAndBaseline()) {
628 adjustmentForChildrenWithSameLineHeightAndBaseline = logicalTop();
630 adjustmentForChildrenWithSameLineHeightAndBaseline += (boxModelObject()->borderAndPaddingBefore());
633 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
634 if (curr->renderer().isOutOfFlowPositioned())
635 continue; // Positioned placeholders don't affect calculations.
637 if (descendantsHaveSameLineHeightAndBaseline()) {
638 curr->adjustBlockDirectionPosition(adjustmentForChildrenWithSameLineHeightAndBaseline);
642 InlineFlowBox* inlineFlowBox = curr->isInlineFlowBox() ? toInlineFlowBox(curr) : 0;
643 bool childAffectsTopBottomPos = true;
645 if (curr->verticalAlign() == TOP && verticalAlignApplies(curr->renderer()))
646 curr->setLogicalTop(top);
647 else if (curr->verticalAlign() == BOTTOM && verticalAlignApplies(curr->renderer()))
648 curr->setLogicalTop(top + maxHeight - curr->lineHeight());
650 if (!strictMode && inlineFlowBox && !inlineFlowBox->hasTextChildren() && !curr->boxModelObject()->hasInlineDirectionBordersOrPadding()
651 && !(inlineFlowBox->descendantsHaveSameLineHeightAndBaseline() && inlineFlowBox->hasTextDescendants()))
652 childAffectsTopBottomPos = false;
653 LayoutUnit posAdjust = maxAscent - curr->baselinePosition(baselineType);
654 curr->setLogicalTop(curr->logicalTop() + top + posAdjust);
657 LayoutUnit newLogicalTop = curr->logicalTop();
658 LayoutUnit newLogicalTopIncludingMargins = newLogicalTop;
659 LayoutUnit boxHeight = curr->logicalHeight();
660 LayoutUnit boxHeightIncludingMargins = boxHeight;
662 if (curr->behavesLikeText() || curr->isInlineFlowBox()) {
663 const FontMetrics& fontMetrics = curr->renderer().style(isFirstLineStyle())->fontMetrics();
664 newLogicalTop += curr->baselinePosition(baselineType) - fontMetrics.ascent(baselineType);
665 if (curr->isInlineFlowBox()) {
666 RenderBoxModelObject& boxObject = toRenderBoxModelObject(curr->renderer());
667 newLogicalTop -= boxObject.style(isFirstLineStyle())->isHorizontalWritingMode()
668 ? boxObject.borderTop() + boxObject.paddingTop()
669 : boxObject.borderRight() + boxObject.paddingRight();
671 newLogicalTopIncludingMargins = newLogicalTop;
672 } else if (!curr->renderer().isBR()) {
673 const RenderBox& box = toRenderBox(curr->renderer());
674 newLogicalTopIncludingMargins = newLogicalTop;
675 LayoutUnit overSideMargin = curr->isHorizontal() ? box.marginTop() : box.marginRight();
676 LayoutUnit underSideMargin = curr->isHorizontal() ? box.marginBottom() : box.marginLeft();
677 newLogicalTop += overSideMargin;
678 boxHeightIncludingMargins += overSideMargin + underSideMargin;
681 curr->setLogicalTop(newLogicalTop);
683 if (childAffectsTopBottomPos) {
684 if (curr->renderer().isRubyRun()) {
685 // Treat the leading on the first and last lines of ruby runs as not being part of the overall lineTop/lineBottom.
686 // Really this is a workaround hack for the fact that ruby should have been done as line layout and not done using
688 if (renderer().style()->isFlippedLinesWritingMode() == (curr->renderer().style()->rubyPosition() == RubyPositionAfter))
689 hasAnnotationsBefore = true;
691 hasAnnotationsAfter = true;
693 RenderRubyRun& rubyRun = toRenderRubyRun(curr->renderer());
694 if (RenderRubyBase* rubyBase = rubyRun.rubyBase()) {
695 LayoutUnit bottomRubyBaseLeading = (curr->logicalHeight() - rubyBase->logicalBottom()) + rubyBase->logicalHeight() - (rubyBase->lastRootBox() ? rubyBase->lastRootBox()->lineBottom() : LayoutUnit());
696 LayoutUnit topRubyBaseLeading = rubyBase->logicalTop() + (rubyBase->firstRootBox() ? rubyBase->firstRootBox()->lineTop() : LayoutUnit());
697 newLogicalTop += !renderer().style()->isFlippedLinesWritingMode() ? topRubyBaseLeading : bottomRubyBaseLeading;
698 boxHeight -= (topRubyBaseLeading + bottomRubyBaseLeading);
701 if (curr->isInlineTextBox()) {
702 TextEmphasisPosition emphasisMarkPosition;
703 if (toInlineTextBox(curr)->getEmphasisMarkPosition(curr->renderer().style(isFirstLineStyle()), emphasisMarkPosition)) {
704 bool emphasisMarkIsOver = emphasisMarkPosition == TextEmphasisPositionOver;
705 if (emphasisMarkIsOver != curr->renderer().style(isFirstLineStyle())->isFlippedLinesWritingMode())
706 hasAnnotationsBefore = true;
708 hasAnnotationsAfter = true;
714 lineTop = newLogicalTop;
715 lineTopIncludingMargins = min(lineTop, newLogicalTopIncludingMargins);
717 lineTop = min(lineTop, newLogicalTop);
718 lineTopIncludingMargins = min(lineTop, min(lineTopIncludingMargins, newLogicalTopIncludingMargins));
720 lineBottom = max(lineBottom, newLogicalTop + boxHeight);
721 lineBottomIncludingMargins = max(lineBottom, max(lineBottomIncludingMargins, newLogicalTopIncludingMargins + boxHeightIncludingMargins));
724 // Adjust boxes to use their real box y/height and not the logical height (as dictated by
727 inlineFlowBox->placeBoxesInBlockDirection(top, maxHeight, maxAscent, strictMode, lineTop, lineBottom, setLineTop,
728 lineTopIncludingMargins, lineBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType);
732 if (strictMode || hasTextChildren() || (descendantsHaveSameLineHeightAndBaseline() && hasTextDescendants())) {
735 lineTop = pixelSnappedLogicalTop();
736 lineTopIncludingMargins = lineTop;
738 lineTop = min<LayoutUnit>(lineTop, pixelSnappedLogicalTop());
739 lineTopIncludingMargins = min(lineTop, lineTopIncludingMargins);
741 lineBottom = max<LayoutUnit>(lineBottom, pixelSnappedLogicalBottom());
742 lineBottomIncludingMargins = max(lineBottom, lineBottomIncludingMargins);
745 if (renderer().style()->isFlippedLinesWritingMode())
746 flipLinesInBlockDirection(lineTopIncludingMargins, lineBottomIncludingMargins);
750 #if ENABLE(CSS3_TEXT)
751 void InlineFlowBox::computeMaxLogicalTop(float& maxLogicalTop) const
753 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
754 if (curr->renderer().isOutOfFlowPositioned())
755 continue; // Positioned placeholders don't affect calculations.
757 if (descendantsHaveSameLineHeightAndBaseline())
760 maxLogicalTop = max<float>(maxLogicalTop, curr->y());
761 float localMaxLogicalTop = 0;
762 if (curr->isInlineFlowBox())
763 toInlineFlowBox(curr)->computeMaxLogicalTop(localMaxLogicalTop);
764 maxLogicalTop = max<float>(maxLogicalTop, localMaxLogicalTop);
769 void InlineFlowBox::flipLinesInBlockDirection(LayoutUnit lineTop, LayoutUnit lineBottom)
771 // Flip the box on the line such that the top is now relative to the lineBottom instead of the lineTop.
772 setLogicalTop(lineBottom - (logicalTop() - lineTop) - logicalHeight());
774 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
775 if (curr->renderer().isOutOfFlowPositioned())
776 continue; // Positioned placeholders aren't affected here.
778 if (curr->isInlineFlowBox())
779 toInlineFlowBox(curr)->flipLinesInBlockDirection(lineTop, lineBottom);
781 curr->setLogicalTop(lineBottom - (curr->logicalTop() - lineTop) - curr->logicalHeight());
785 inline void InlineFlowBox::addBoxShadowVisualOverflow(LayoutRect& logicalVisualOverflow)
787 // box-shadow on root line boxes is applying to the block and not to the lines.
791 RenderStyle* style = renderer().style(isFirstLineStyle());
792 if (!style->boxShadow())
795 LayoutUnit boxShadowLogicalTop;
796 LayoutUnit boxShadowLogicalBottom;
797 style->getBoxShadowBlockDirectionExtent(boxShadowLogicalTop, boxShadowLogicalBottom);
799 // Similar to how glyph overflow works, if our lines are flipped, then it's actually the opposite shadow that applies, since
800 // the line is "upside down" in terms of block coordinates.
801 LayoutUnit shadowLogicalTop = style->isFlippedLinesWritingMode() ? -boxShadowLogicalBottom : boxShadowLogicalTop;
802 LayoutUnit shadowLogicalBottom = style->isFlippedLinesWritingMode() ? -boxShadowLogicalTop : boxShadowLogicalBottom;
804 LayoutUnit logicalTopVisualOverflow = min(pixelSnappedLogicalTop() + shadowLogicalTop, logicalVisualOverflow.y());
805 LayoutUnit logicalBottomVisualOverflow = max(pixelSnappedLogicalBottom() + shadowLogicalBottom, logicalVisualOverflow.maxY());
807 LayoutUnit boxShadowLogicalLeft;
808 LayoutUnit boxShadowLogicalRight;
809 style->getBoxShadowInlineDirectionExtent(boxShadowLogicalLeft, boxShadowLogicalRight);
811 LayoutUnit logicalLeftVisualOverflow = min(pixelSnappedLogicalLeft() + boxShadowLogicalLeft, logicalVisualOverflow.x());
812 LayoutUnit logicalRightVisualOverflow = max(pixelSnappedLogicalRight() + boxShadowLogicalRight, logicalVisualOverflow.maxX());
814 logicalVisualOverflow = LayoutRect(logicalLeftVisualOverflow, logicalTopVisualOverflow,
815 logicalRightVisualOverflow - logicalLeftVisualOverflow, logicalBottomVisualOverflow - logicalTopVisualOverflow);
818 inline void InlineFlowBox::addBorderOutsetVisualOverflow(LayoutRect& logicalVisualOverflow)
820 // border-image-outset on root line boxes is applying to the block and not to the lines.
824 RenderStyle* style = renderer().style(isFirstLineStyle());
825 if (!style->hasBorderImageOutsets())
828 LayoutBoxExtent borderOutsets = style->borderImageOutsets();
830 LayoutUnit borderOutsetLogicalTop = borderOutsets.logicalTop(style->writingMode());
831 LayoutUnit borderOutsetLogicalBottom = borderOutsets.logicalBottom(style->writingMode());
832 LayoutUnit borderOutsetLogicalLeft = borderOutsets.logicalLeft(style->writingMode());
833 LayoutUnit borderOutsetLogicalRight = borderOutsets.logicalRight(style->writingMode());
835 // Similar to how glyph overflow works, if our lines are flipped, then it's actually the opposite border that applies, since
836 // the line is "upside down" in terms of block coordinates. vertical-rl and horizontal-bt are the flipped line modes.
837 LayoutUnit outsetLogicalTop = style->isFlippedLinesWritingMode() ? borderOutsetLogicalBottom : borderOutsetLogicalTop;
838 LayoutUnit outsetLogicalBottom = style->isFlippedLinesWritingMode() ? borderOutsetLogicalTop : borderOutsetLogicalBottom;
840 LayoutUnit logicalTopVisualOverflow = min(pixelSnappedLogicalTop() - outsetLogicalTop, logicalVisualOverflow.y());
841 LayoutUnit logicalBottomVisualOverflow = max(pixelSnappedLogicalBottom() + outsetLogicalBottom, logicalVisualOverflow.maxY());
843 LayoutUnit outsetLogicalLeft = includeLogicalLeftEdge() ? borderOutsetLogicalLeft : LayoutUnit();
844 LayoutUnit outsetLogicalRight = includeLogicalRightEdge() ? borderOutsetLogicalRight : LayoutUnit();
846 LayoutUnit logicalLeftVisualOverflow = min(pixelSnappedLogicalLeft() - outsetLogicalLeft, logicalVisualOverflow.x());
847 LayoutUnit logicalRightVisualOverflow = max(pixelSnappedLogicalRight() + outsetLogicalRight, logicalVisualOverflow.maxX());
849 logicalVisualOverflow = LayoutRect(logicalLeftVisualOverflow, logicalTopVisualOverflow,
850 logicalRightVisualOverflow - logicalLeftVisualOverflow, logicalBottomVisualOverflow - logicalTopVisualOverflow);
853 inline void InlineFlowBox::addTextBoxVisualOverflow(InlineTextBox* textBox, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, LayoutRect& logicalVisualOverflow)
855 if (textBox->knownToHaveNoOverflow())
858 RenderStyle* style = textBox->renderer().style(isFirstLineStyle());
860 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.find(textBox);
861 GlyphOverflow* glyphOverflow = it == textBoxDataMap.end() ? 0 : &it->value.second;
862 bool isFlippedLine = style->isFlippedLinesWritingMode();
864 int topGlyphEdge = glyphOverflow ? (isFlippedLine ? glyphOverflow->bottom : glyphOverflow->top) : 0;
865 int bottomGlyphEdge = glyphOverflow ? (isFlippedLine ? glyphOverflow->top : glyphOverflow->bottom) : 0;
866 int leftGlyphEdge = glyphOverflow ? glyphOverflow->left : 0;
867 int rightGlyphEdge = glyphOverflow ? glyphOverflow->right : 0;
869 int strokeOverflow = static_cast<int>(ceilf(style->textStrokeWidth() / 2.0f));
870 int topGlyphOverflow = -strokeOverflow - topGlyphEdge;
871 int bottomGlyphOverflow = strokeOverflow + bottomGlyphEdge;
872 int leftGlyphOverflow = -strokeOverflow - leftGlyphEdge;
873 int rightGlyphOverflow = strokeOverflow + rightGlyphEdge;
875 TextEmphasisPosition emphasisMarkPosition;
876 if (style->textEmphasisMark() != TextEmphasisMarkNone && textBox->getEmphasisMarkPosition(style, emphasisMarkPosition)) {
877 int emphasisMarkHeight = style->font().emphasisMarkHeight(style->textEmphasisMarkString());
878 if ((emphasisMarkPosition == TextEmphasisPositionOver) == (!style->isFlippedLinesWritingMode()))
879 topGlyphOverflow = min(topGlyphOverflow, -emphasisMarkHeight);
881 bottomGlyphOverflow = max(bottomGlyphOverflow, emphasisMarkHeight);
884 // If letter-spacing is negative, we should factor that into right layout overflow. (Even in RTL, letter-spacing is
885 // applied to the right, so this is not an issue with left overflow.
886 rightGlyphOverflow -= min(0, (int)style->font().letterSpacing());
888 LayoutUnit textShadowLogicalTop;
889 LayoutUnit textShadowLogicalBottom;
890 style->getTextShadowBlockDirectionExtent(textShadowLogicalTop, textShadowLogicalBottom);
892 LayoutUnit childOverflowLogicalTop = min<LayoutUnit>(textShadowLogicalTop + topGlyphOverflow, topGlyphOverflow);
893 LayoutUnit childOverflowLogicalBottom = max<LayoutUnit>(textShadowLogicalBottom + bottomGlyphOverflow, bottomGlyphOverflow);
895 LayoutUnit textShadowLogicalLeft;
896 LayoutUnit textShadowLogicalRight;
897 style->getTextShadowInlineDirectionExtent(textShadowLogicalLeft, textShadowLogicalRight);
899 LayoutUnit childOverflowLogicalLeft = min<LayoutUnit>(textShadowLogicalLeft + leftGlyphOverflow, leftGlyphOverflow);
900 LayoutUnit childOverflowLogicalRight = max<LayoutUnit>(textShadowLogicalRight + rightGlyphOverflow, rightGlyphOverflow);
902 LayoutUnit logicalTopVisualOverflow = min(textBox->pixelSnappedLogicalTop() + childOverflowLogicalTop, logicalVisualOverflow.y());
903 LayoutUnit logicalBottomVisualOverflow = max(textBox->pixelSnappedLogicalBottom() + childOverflowLogicalBottom, logicalVisualOverflow.maxY());
904 LayoutUnit logicalLeftVisualOverflow = min(textBox->pixelSnappedLogicalLeft() + childOverflowLogicalLeft, logicalVisualOverflow.x());
905 LayoutUnit logicalRightVisualOverflow = max(textBox->pixelSnappedLogicalRight() + childOverflowLogicalRight, logicalVisualOverflow.maxX());
907 logicalVisualOverflow = LayoutRect(logicalLeftVisualOverflow, logicalTopVisualOverflow,
908 logicalRightVisualOverflow - logicalLeftVisualOverflow, logicalBottomVisualOverflow - logicalTopVisualOverflow);
910 textBox->setLogicalOverflowRect(logicalVisualOverflow);
913 inline void InlineFlowBox::addReplacedChildOverflow(const InlineBox* inlineBox, LayoutRect& logicalLayoutOverflow, LayoutRect& logicalVisualOverflow)
915 const RenderBox& box = toRenderBox(inlineBox->renderer());
917 // Visual overflow only propagates if the box doesn't have a self-painting layer. This rectangle does not include
918 // transforms or relative positioning (since those objects always have self-painting layers), but it does need to be adjusted
919 // for writing-mode differences.
920 if (!box.hasSelfPaintingLayer()) {
921 LayoutRect childLogicalVisualOverflow = box.logicalVisualOverflowRectForPropagation(renderer().style());
922 childLogicalVisualOverflow.move(inlineBox->logicalLeft(), inlineBox->logicalTop());
923 logicalVisualOverflow.unite(childLogicalVisualOverflow);
926 // Layout overflow internal to the child box only propagates if the child box doesn't have overflow clip set.
927 // Otherwise the child border box propagates as layout overflow. This rectangle must include transforms and relative positioning
928 // and be adjusted for writing-mode differences.
929 LayoutRect childLogicalLayoutOverflow = box.logicalLayoutOverflowRectForPropagation(renderer().style());
930 childLogicalLayoutOverflow.move(inlineBox->logicalLeft(), inlineBox->logicalTop());
931 logicalLayoutOverflow.unite(childLogicalLayoutOverflow);
934 void InlineFlowBox::computeOverflow(LayoutUnit lineTop, LayoutUnit lineBottom, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
936 // If we know we have no overflow, we can just bail.
937 if (knownToHaveNoOverflow())
940 // Visual overflow just includes overflow for stuff we need to repaint ourselves. Self-painting layers are ignored.
941 // Layout overflow is used to determine scrolling extent, so it still includes child layers and also factors in
942 // transforms, relative positioning, etc.
943 LayoutRect logicalLayoutOverflow(enclosingLayoutRect(logicalFrameRectIncludingLineHeight(lineTop, lineBottom)));
944 LayoutRect logicalVisualOverflow(logicalLayoutOverflow);
946 addBoxShadowVisualOverflow(logicalVisualOverflow);
947 addBorderOutsetVisualOverflow(logicalVisualOverflow);
949 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
950 if (curr->renderer().isOutOfFlowPositioned())
951 continue; // Positioned placeholders don't affect calculations.
953 if (curr->renderer().isLineBreak())
955 if (curr->renderer().isText()) {
956 InlineTextBox* text = toInlineTextBox(curr);
957 LayoutRect textBoxOverflow(enclosingLayoutRect(text->logicalFrameRect()));
958 addTextBoxVisualOverflow(text, textBoxDataMap, textBoxOverflow);
959 logicalVisualOverflow.unite(textBoxOverflow);
960 } else if (curr->renderer().isRenderInline()) {
961 InlineFlowBox* flow = toInlineFlowBox(curr);
962 flow->computeOverflow(lineTop, lineBottom, textBoxDataMap);
963 if (!flow->boxModelObject()->hasSelfPaintingLayer())
964 logicalVisualOverflow.unite(flow->logicalVisualOverflowRect(lineTop, lineBottom));
965 LayoutRect childLayoutOverflow = flow->logicalLayoutOverflowRect(lineTop, lineBottom);
966 childLayoutOverflow.move(flow->boxModelObject()->relativePositionLogicalOffset());
967 logicalLayoutOverflow.unite(childLayoutOverflow);
969 addReplacedChildOverflow(curr, logicalLayoutOverflow, logicalVisualOverflow);
972 setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, lineTop, lineBottom);
975 void InlineFlowBox::setLayoutOverflow(const LayoutRect& rect, LayoutUnit lineTop, LayoutUnit lineBottom)
977 LayoutRect frameBox = enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
978 if (frameBox.contains(rect) || rect.isEmpty())
982 m_overflow = adoptPtr(new RenderOverflow(frameBox, frameBox));
984 m_overflow->setLayoutOverflow(rect);
987 void InlineFlowBox::setVisualOverflow(const LayoutRect& rect, LayoutUnit lineTop, LayoutUnit lineBottom)
989 LayoutRect frameBox = enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
990 if (frameBox.contains(rect) || rect.isEmpty())
994 m_overflow = adoptPtr(new RenderOverflow(frameBox, frameBox));
996 m_overflow->setVisualOverflow(rect);
999 void InlineFlowBox::setOverflowFromLogicalRects(const LayoutRect& logicalLayoutOverflow, const LayoutRect& logicalVisualOverflow, LayoutUnit lineTop, LayoutUnit lineBottom)
1001 LayoutRect layoutOverflow(isHorizontal() ? logicalLayoutOverflow : logicalLayoutOverflow.transposedRect());
1002 setLayoutOverflow(layoutOverflow, lineTop, lineBottom);
1004 LayoutRect visualOverflow(isHorizontal() ? logicalVisualOverflow : logicalVisualOverflow.transposedRect());
1005 setVisualOverflow(visualOverflow, lineTop, lineBottom);
1008 bool InlineFlowBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
1010 LayoutRect overflowRect(visualOverflowRect(lineTop, lineBottom));
1011 flipForWritingMode(overflowRect);
1012 overflowRect.moveBy(accumulatedOffset);
1013 if (!locationInContainer.intersects(overflowRect))
1016 // Check children first.
1017 // We need to account for culled inline parents of the hit-tested nodes, so that they may also get included in area-based hit-tests.
1018 RenderObject* culledParent = 0;
1019 for (InlineBox* curr = lastChild(); curr; curr = curr->prevOnLine()) {
1020 if (curr->renderer().isText() || !curr->boxModelObject()->hasSelfPaintingLayer()) {
1021 RenderObject* newParent = 0;
1022 // Culled parents are only relevant for area-based hit-tests, so ignore it in point-based ones.
1023 if (locationInContainer.isRectBasedTest()) {
1024 newParent = curr->renderer().parent();
1025 if (newParent == &renderer())
1028 // Check the culled parent after all its children have been checked, to do this we wait until
1029 // we are about to test an element with a different parent.
1030 if (newParent != culledParent) {
1031 if (!newParent || !newParent->isDescendantOf(culledParent)) {
1032 while (culledParent && culledParent != &renderer() && culledParent != newParent) {
1033 if (culledParent->isRenderInline() && toRenderInline(culledParent)->hitTestCulledInline(request, result, locationInContainer, accumulatedOffset))
1035 culledParent = culledParent->parent();
1038 culledParent = newParent;
1040 if (curr->nodeAtPoint(request, result, locationInContainer, accumulatedOffset, lineTop, lineBottom)) {
1041 renderer().updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
1046 // Check any culled ancestor of the final children tested.
1047 while (culledParent && culledParent != &renderer()) {
1048 if (culledParent->isRenderInline() && toRenderInline(culledParent)->hitTestCulledInline(request, result, locationInContainer, accumulatedOffset))
1050 culledParent = culledParent->parent();
1053 // Now check ourselves. Pixel snap hit testing.
1054 if (!visibleToHitTesting())
1057 // Do not hittest content beyond the ellipsis box.
1058 if (isRootInlineBox() && hasEllipsisBox()) {
1059 const EllipsisBox* ellipsisBox = root().ellipsisBox();
1060 LayoutRect boundsRect(roundedFrameRect());
1063 renderer().style()->isLeftToRightDirection() ? boundsRect.shiftXEdgeTo(ellipsisBox->right()) : boundsRect.setWidth(ellipsisBox->left() - left());
1065 boundsRect.shiftYEdgeTo(ellipsisBox->right());
1067 flipForWritingMode(boundsRect);
1068 boundsRect.moveBy(accumulatedOffset);
1069 // We are beyond the ellipsis box.
1070 if (locationInContainer.intersects(boundsRect))
1074 LayoutRect frameRect = roundedFrameRect();
1075 LayoutUnit minX = frameRect.x();
1076 LayoutUnit minY = frameRect.y();
1077 LayoutUnit width = frameRect.width();
1078 LayoutUnit height = frameRect.height();
1080 // Constrain our hit testing to the line top and bottom if necessary.
1081 bool noQuirksMode = renderer().document().inNoQuirksMode();
1082 if (!noQuirksMode && !hasTextChildren() && !(descendantsHaveSameLineHeightAndBaseline() && hasTextDescendants())) {
1083 RootInlineBox& rootBox = root();
1084 LayoutUnit& top = isHorizontal() ? minY : minX;
1085 LayoutUnit& logicalHeight = isHorizontal() ? height : width;
1086 LayoutUnit bottom = min(rootBox.lineBottom(), top + logicalHeight);
1087 top = max(rootBox.lineTop(), top);
1088 logicalHeight = bottom - top;
1091 // Move x/y to our coordinates.
1092 LayoutRect rect(minX, minY, width, height);
1093 flipForWritingMode(rect);
1094 rect.moveBy(accumulatedOffset);
1096 if (locationInContainer.intersects(rect)) {
1097 renderer().updateHitTestResult(result, flipForWritingMode(locationInContainer.point() - toLayoutSize(accumulatedOffset))); // Don't add in m_x or m_y here, we want coords in the containing block's space.
1098 if (!result.addNodeToRectBasedTestResult(renderer().element(), request, locationInContainer, rect))
1105 void InlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
1107 LayoutRect overflowRect(visualOverflowRect(lineTop, lineBottom));
1108 overflowRect.inflate(renderer().maximalOutlineSize(paintInfo.phase));
1109 flipForWritingMode(overflowRect);
1110 overflowRect.moveBy(paintOffset);
1112 if (!paintInfo.rect.intersects(pixelSnappedIntRect(overflowRect)))
1115 if (paintInfo.phase != PaintPhaseChildOutlines) {
1116 if (paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) {
1117 // Add ourselves to the paint info struct's list of inlines that need to paint their
1119 if (renderer().style()->visibility() == VISIBLE && renderer().hasOutline() && !isRootInlineBox()) {
1120 RenderInline& inlineFlow = toRenderInline(renderer());
1122 RenderBlock* cb = 0;
1123 bool containingBlockPaintsContinuationOutline = inlineFlow.continuation() || inlineFlow.isInlineElementContinuation();
1124 if (containingBlockPaintsContinuationOutline) {
1125 // FIXME: See https://bugs.webkit.org/show_bug.cgi?id=54690. We currently don't reconnect inline continuations
1126 // after a child removal. As a result, those merged inlines do not get seperated and hence not get enclosed by
1127 // anonymous blocks. In this case, it is better to bail out and paint it ourself.
1128 RenderBlock* enclosingAnonymousBlock = renderer().containingBlock();
1129 if (!enclosingAnonymousBlock->isAnonymousBlock())
1130 containingBlockPaintsContinuationOutline = false;
1132 cb = enclosingAnonymousBlock->containingBlock();
1133 for (RenderBoxModelObject* box = boxModelObject(); box != cb; box = box->parent()->enclosingBoxModelObject()) {
1134 if (box->hasSelfPaintingLayer()) {
1135 containingBlockPaintsContinuationOutline = false;
1142 if (containingBlockPaintsContinuationOutline) {
1143 // Add ourselves to the containing block of the entire continuation so that it can
1144 // paint us atomically.
1145 cb->addContinuationWithOutline(toRenderInline(renderer().element()->renderer()));
1146 } else if (!inlineFlow.isInlineElementContinuation())
1147 paintInfo.outlineObjects->add(&inlineFlow);
1149 } else if (paintInfo.phase == PaintPhaseMask) {
1150 paintMask(paintInfo, paintOffset);
1153 // Paint our background, border and box-shadow.
1154 paintBoxDecorations(paintInfo, paintOffset);
1158 if (paintInfo.phase == PaintPhaseMask)
1161 PaintPhase paintPhase = paintInfo.phase == PaintPhaseChildOutlines ? PaintPhaseOutline : paintInfo.phase;
1162 PaintInfo childInfo(paintInfo);
1163 childInfo.phase = paintPhase;
1164 childInfo.updateSubtreePaintRootForChildren(&renderer());
1166 // Paint our children.
1167 if (paintPhase != PaintPhaseSelfOutline) {
1168 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
1169 if (curr->renderer().isText() || !curr->boxModelObject()->hasSelfPaintingLayer())
1170 curr->paint(childInfo, paintOffset, lineTop, lineBottom);
1175 void InlineFlowBox::paintFillLayers(const PaintInfo& paintInfo, const Color& c, const FillLayer* fillLayer, const LayoutRect& rect, CompositeOperator op)
1179 paintFillLayers(paintInfo, c, fillLayer->next(), rect, op);
1180 paintFillLayer(paintInfo, c, fillLayer, rect, op);
1183 bool InlineFlowBox::boxShadowCanBeAppliedToBackground(const FillLayer& lastBackgroundLayer) const
1185 // The checks here match how paintFillLayer() decides whether to clip (if it does, the shadow
1186 // would be clipped out, so it has to be drawn separately).
1187 StyleImage* image = lastBackgroundLayer.image();
1188 bool hasFillImage = image && image->canRender(&renderer(), renderer().style()->effectiveZoom());
1189 return (!hasFillImage && !renderer().style()->hasBorderRadius()) || (!prevLineBox() && !nextLineBox()) || !parent();
1192 void InlineFlowBox::paintFillLayer(const PaintInfo& paintInfo, const Color& c, const FillLayer* fillLayer, const LayoutRect& rect, CompositeOperator op)
1194 StyleImage* img = fillLayer->image();
1195 bool hasFillImage = img && img->canRender(&renderer(), renderer().style()->effectiveZoom());
1196 if ((!hasFillImage && !renderer().style()->hasBorderRadius()) || (!prevLineBox() && !nextLineBox()) || !parent())
1197 boxModelObject()->paintFillLayerExtended(paintInfo, c, fillLayer, rect, BackgroundBleedNone, this, rect.size(), op);
1198 #if ENABLE(CSS_BOX_DECORATION_BREAK)
1199 else if (renderer().style()->boxDecorationBreak() == DCLONE) {
1200 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1201 paintInfo.context->clip(LayoutRect(rect.x(), rect.y(), width(), height()));
1202 boxModelObject()->paintFillLayerExtended(paintInfo, c, fillLayer, rect, BackgroundBleedNone, this, rect.size(), op);
1206 // We have a fill image that spans multiple lines.
1207 // We need to adjust tx and ty by the width of all previous lines.
1208 // Think of background painting on inlines as though you had one long line, a single continuous
1209 // strip. Even though that strip has been broken up across multiple lines, you still paint it
1210 // as though you had one single line. This means each line has to pick up the background where
1211 // the previous line left off.
1212 LayoutUnit logicalOffsetOnLine = 0;
1213 LayoutUnit totalLogicalWidth;
1214 if (renderer().style()->direction() == LTR) {
1215 for (InlineFlowBox* curr = prevLineBox(); curr; curr = curr->prevLineBox())
1216 logicalOffsetOnLine += curr->logicalWidth();
1217 totalLogicalWidth = logicalOffsetOnLine;
1218 for (InlineFlowBox* curr = this; curr; curr = curr->nextLineBox())
1219 totalLogicalWidth += curr->logicalWidth();
1221 for (InlineFlowBox* curr = nextLineBox(); curr; curr = curr->nextLineBox())
1222 logicalOffsetOnLine += curr->logicalWidth();
1223 totalLogicalWidth = logicalOffsetOnLine;
1224 for (InlineFlowBox* curr = this; curr; curr = curr->prevLineBox())
1225 totalLogicalWidth += curr->logicalWidth();
1227 LayoutUnit stripX = rect.x() - (isHorizontal() ? logicalOffsetOnLine : LayoutUnit());
1228 LayoutUnit stripY = rect.y() - (isHorizontal() ? LayoutUnit() : logicalOffsetOnLine);
1229 LayoutUnit stripWidth = isHorizontal() ? totalLogicalWidth : static_cast<LayoutUnit>(width());
1230 LayoutUnit stripHeight = isHorizontal() ? static_cast<LayoutUnit>(height()) : totalLogicalWidth;
1232 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1233 paintInfo.context->clip(LayoutRect(rect.x(), rect.y(), width(), height()));
1234 boxModelObject()->paintFillLayerExtended(paintInfo, c, fillLayer, LayoutRect(stripX, stripY, stripWidth, stripHeight), BackgroundBleedNone, this, rect.size(), op);
1238 void InlineFlowBox::paintBoxShadow(const PaintInfo& info, RenderStyle* s, ShadowStyle shadowStyle, const LayoutRect& paintRect)
1240 if ((!prevLineBox() && !nextLineBox()) || !parent())
1241 boxModelObject()->paintBoxShadow(info, paintRect, s, shadowStyle);
1243 // FIXME: We can do better here in the multi-line case. We want to push a clip so that the shadow doesn't
1244 // protrude incorrectly at the edges, and we want to possibly include shadows cast from the previous/following lines
1245 boxModelObject()->paintBoxShadow(info, paintRect, s, shadowStyle, includeLogicalLeftEdge(), includeLogicalRightEdge());
1249 void InlineFlowBox::constrainToLineTopAndBottomIfNeeded(LayoutRect& rect) const
1251 bool noQuirksMode = renderer().document().inNoQuirksMode();
1252 if (!noQuirksMode && !hasTextChildren() && !(descendantsHaveSameLineHeightAndBaseline() && hasTextDescendants())) {
1253 const RootInlineBox& rootBox = root();
1254 LayoutUnit logicalTop = isHorizontal() ? rect.y() : rect.x();
1255 LayoutUnit logicalHeight = isHorizontal() ? rect.height() : rect.width();
1256 LayoutUnit bottom = min(rootBox.lineBottom(), logicalTop + logicalHeight);
1257 logicalTop = max(rootBox.lineTop(), logicalTop);
1258 logicalHeight = bottom - logicalTop;
1259 if (isHorizontal()) {
1260 rect.setY(logicalTop);
1261 rect.setHeight(logicalHeight);
1263 rect.setX(logicalTop);
1264 rect.setWidth(logicalHeight);
1269 static LayoutRect clipRectForNinePieceImageStrip(InlineFlowBox* box, const NinePieceImage& image, const LayoutRect& paintRect)
1271 LayoutRect clipRect(paintRect);
1272 RenderStyle* style = box->renderer().style();
1273 LayoutBoxExtent outsets = style->imageOutsets(image);
1274 if (box->isHorizontal()) {
1275 clipRect.setY(paintRect.y() - outsets.top());
1276 clipRect.setHeight(paintRect.height() + outsets.top() + outsets.bottom());
1277 if (box->includeLogicalLeftEdge()) {
1278 clipRect.setX(paintRect.x() - outsets.left());
1279 clipRect.setWidth(paintRect.width() + outsets.left());
1281 if (box->includeLogicalRightEdge())
1282 clipRect.setWidth(clipRect.width() + outsets.right());
1284 clipRect.setX(paintRect.x() - outsets.left());
1285 clipRect.setWidth(paintRect.width() + outsets.left() + outsets.right());
1286 if (box->includeLogicalLeftEdge()) {
1287 clipRect.setY(paintRect.y() - outsets.top());
1288 clipRect.setHeight(paintRect.height() + outsets.top());
1290 if (box->includeLogicalRightEdge())
1291 clipRect.setHeight(clipRect.height() + outsets.bottom());
1296 void InlineFlowBox::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
1298 if (!paintInfo.shouldPaintWithinRoot(&renderer()) || renderer().style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseForeground)
1301 // Pixel snap background/border painting.
1302 LayoutRect frameRect = roundedFrameRect();
1304 constrainToLineTopAndBottomIfNeeded(frameRect);
1306 // Move x/y to our coordinates.
1307 LayoutRect localRect(frameRect);
1308 flipForWritingMode(localRect);
1309 LayoutPoint adjustedPaintoffset = paintOffset + localRect.location();
1311 GraphicsContext* context = paintInfo.context;
1313 // You can use p::first-line to specify a background. If so, the root line boxes for
1314 // a line may actually have to paint a background.
1315 RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
1316 if ((!parent() && isFirstLineStyle() && styleToUse != renderer().style()) || (parent() && renderer().hasBoxDecorations())) {
1317 LayoutRect paintRect = LayoutRect(adjustedPaintoffset, frameRect.size());
1318 // Shadow comes first and is behind the background and border.
1319 if (!boxModelObject()->boxShadowShouldBeAppliedToBackground(BackgroundBleedNone, this))
1320 paintBoxShadow(paintInfo, styleToUse, Normal, paintRect);
1322 Color c = styleToUse->visitedDependentColor(CSSPropertyBackgroundColor);
1323 paintFillLayers(paintInfo, c, styleToUse->backgroundLayers(), paintRect);
1324 paintBoxShadow(paintInfo, styleToUse, Inset, paintRect);
1326 // :first-line cannot be used to put borders on a line. Always paint borders with our
1327 // non-first-line style.
1328 if (parent() && renderer().style()->hasBorder()) {
1329 const NinePieceImage& borderImage = renderer().style()->borderImage();
1330 StyleImage* borderImageSource = borderImage.image();
1331 bool hasBorderImage = borderImageSource && borderImageSource->canRender(&renderer(), styleToUse->effectiveZoom());
1332 if (hasBorderImage && !borderImageSource->isLoaded())
1333 return; // Don't paint anything while we wait for the image to load.
1335 // The simple case is where we either have no border image or we are the only box for this object. In those
1336 // cases only a single call to draw is required.
1337 if (!hasBorderImage || (!prevLineBox() && !nextLineBox()))
1338 boxModelObject()->paintBorder(paintInfo, paintRect, renderer().style(isFirstLineStyle()), BackgroundBleedNone, includeLogicalLeftEdge(), includeLogicalRightEdge());
1340 // We have a border image that spans multiple lines.
1341 // We need to adjust tx and ty by the width of all previous lines.
1342 // Think of border image painting on inlines as though you had one long line, a single continuous
1343 // strip. Even though that strip has been broken up across multiple lines, you still paint it
1344 // as though you had one single line. This means each line has to pick up the image where
1345 // the previous line left off.
1346 // FIXME: What the heck do we do with RTL here? The math we're using is obviously not right,
1347 // but it isn't even clear how this should work at all.
1348 LayoutUnit logicalOffsetOnLine = 0;
1349 for (InlineFlowBox* curr = prevLineBox(); curr; curr = curr->prevLineBox())
1350 logicalOffsetOnLine += curr->logicalWidth();
1351 LayoutUnit totalLogicalWidth = logicalOffsetOnLine;
1352 for (InlineFlowBox* curr = this; curr; curr = curr->nextLineBox())
1353 totalLogicalWidth += curr->logicalWidth();
1354 LayoutUnit stripX = adjustedPaintoffset.x() - (isHorizontal() ? logicalOffsetOnLine : LayoutUnit());
1355 LayoutUnit stripY = adjustedPaintoffset.y() - (isHorizontal() ? LayoutUnit() : logicalOffsetOnLine);
1356 LayoutUnit stripWidth = isHorizontal() ? totalLogicalWidth : frameRect.width();
1357 LayoutUnit stripHeight = isHorizontal() ? frameRect.height() : totalLogicalWidth;
1359 LayoutRect clipRect = clipRectForNinePieceImageStrip(this, borderImage, paintRect);
1360 GraphicsContextStateSaver stateSaver(*context);
1361 context->clip(clipRect);
1362 boxModelObject()->paintBorder(paintInfo, LayoutRect(stripX, stripY, stripWidth, stripHeight), renderer().style(isFirstLineStyle()));
1368 void InlineFlowBox::paintMask(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
1370 if (!paintInfo.shouldPaintWithinRoot(&renderer()) || renderer().style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask)
1373 // Pixel snap mask painting.
1374 LayoutRect frameRect = roundedFrameRect();
1376 constrainToLineTopAndBottomIfNeeded(frameRect);
1378 // Move x/y to our coordinates.
1379 LayoutRect localRect(frameRect);
1380 flipForWritingMode(localRect);
1381 LayoutPoint adjustedPaintOffset = paintOffset + localRect.location();
1383 const NinePieceImage& maskNinePieceImage = renderer().style()->maskBoxImage();
1384 StyleImage* maskBoxImage = renderer().style()->maskBoxImage().image();
1386 // Figure out if we need to push a transparency layer to render our mask.
1387 bool pushTransparencyLayer = false;
1388 bool compositedMask = renderer().hasLayer() && boxModelObject()->layer()->hasCompositedMask();
1389 bool flattenCompositingLayers = renderer().view().frameView().paintBehavior() & PaintBehaviorFlattenCompositingLayers;
1390 CompositeOperator compositeOp = CompositeSourceOver;
1391 if (!compositedMask || flattenCompositingLayers) {
1392 if ((maskBoxImage && renderer().style()->maskLayers()->hasImage()) || renderer().style()->maskLayers()->next())
1393 pushTransparencyLayer = true;
1395 compositeOp = CompositeDestinationIn;
1396 if (pushTransparencyLayer) {
1397 paintInfo.context->setCompositeOperation(CompositeDestinationIn);
1398 paintInfo.context->beginTransparencyLayer(1.0f);
1399 compositeOp = CompositeSourceOver;
1403 LayoutRect paintRect = LayoutRect(adjustedPaintOffset, frameRect.size());
1404 paintFillLayers(paintInfo, Color(), renderer().style()->maskLayers(), paintRect, compositeOp);
1406 bool hasBoxImage = maskBoxImage && maskBoxImage->canRender(&renderer(), renderer().style()->effectiveZoom());
1407 if (!hasBoxImage || !maskBoxImage->isLoaded()) {
1408 if (pushTransparencyLayer)
1409 paintInfo.context->endTransparencyLayer();
1410 return; // Don't paint anything while we wait for the image to load.
1413 // The simple case is where we are the only box for this object. In those
1414 // cases only a single call to draw is required.
1415 if (!prevLineBox() && !nextLineBox()) {
1416 boxModelObject()->paintNinePieceImage(paintInfo.context, LayoutRect(adjustedPaintOffset, frameRect.size()), renderer().style(), maskNinePieceImage, compositeOp);
1418 // We have a mask image that spans multiple lines.
1419 // We need to adjust _tx and _ty by the width of all previous lines.
1420 LayoutUnit logicalOffsetOnLine = 0;
1421 for (InlineFlowBox* curr = prevLineBox(); curr; curr = curr->prevLineBox())
1422 logicalOffsetOnLine += curr->logicalWidth();
1423 LayoutUnit totalLogicalWidth = logicalOffsetOnLine;
1424 for (InlineFlowBox* curr = this; curr; curr = curr->nextLineBox())
1425 totalLogicalWidth += curr->logicalWidth();
1426 LayoutUnit stripX = adjustedPaintOffset.x() - (isHorizontal() ? logicalOffsetOnLine : LayoutUnit());
1427 LayoutUnit stripY = adjustedPaintOffset.y() - (isHorizontal() ? LayoutUnit() : logicalOffsetOnLine);
1428 LayoutUnit stripWidth = isHorizontal() ? totalLogicalWidth : frameRect.width();
1429 LayoutUnit stripHeight = isHorizontal() ? frameRect.height() : totalLogicalWidth;
1431 LayoutRect clipRect = clipRectForNinePieceImageStrip(this, maskNinePieceImage, paintRect);
1432 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1433 paintInfo.context->clip(clipRect);
1434 boxModelObject()->paintNinePieceImage(paintInfo.context, LayoutRect(stripX, stripY, stripWidth, stripHeight), renderer().style(), maskNinePieceImage, compositeOp);
1437 if (pushTransparencyLayer)
1438 paintInfo.context->endTransparencyLayer();
1441 InlineBox* InlineFlowBox::firstLeafChild() const
1443 InlineBox* leaf = 0;
1444 for (InlineBox* child = firstChild(); child && !leaf; child = child->nextOnLine())
1445 leaf = child->isLeaf() ? child : toInlineFlowBox(child)->firstLeafChild();
1449 InlineBox* InlineFlowBox::lastLeafChild() const
1451 InlineBox* leaf = 0;
1452 for (InlineBox* child = lastChild(); child && !leaf; child = child->prevOnLine())
1453 leaf = child->isLeaf() ? child : toInlineFlowBox(child)->lastLeafChild();
1457 RenderObject::SelectionState InlineFlowBox::selectionState()
1459 return RenderObject::SelectionNone;
1462 bool InlineFlowBox::canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth) const
1464 for (InlineBox *box = firstChild(); box; box = box->nextOnLine()) {
1465 if (!box->canAccommodateEllipsis(ltr, blockEdge, ellipsisWidth))
1471 float InlineFlowBox::placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, float &truncatedWidth, bool& foundBox)
1474 // We iterate over all children, the foundBox variable tells us when we've found the
1475 // box containing the ellipsis. All boxes after that one in the flow are hidden.
1476 // If our flow is ltr then iterate over the boxes from left to right, otherwise iterate
1477 // from right to left. Varying the order allows us to correctly hide the boxes following the ellipsis.
1478 InlineBox* box = ltr ? firstChild() : lastChild();
1480 // NOTE: these will cross after foundBox = true.
1481 int visibleLeftEdge = blockLeftEdge;
1482 int visibleRightEdge = blockRightEdge;
1485 int currResult = box->placeEllipsisBox(ltr, visibleLeftEdge, visibleRightEdge, ellipsisWidth, truncatedWidth, foundBox);
1486 if (currResult != -1 && result == -1)
1487 result = currResult;
1490 visibleLeftEdge += box->logicalWidth();
1491 box = box->nextOnLine();
1494 visibleRightEdge -= box->logicalWidth();
1495 box = box->prevOnLine();
1501 void InlineFlowBox::clearTruncation()
1503 for (InlineBox *box = firstChild(); box; box = box->nextOnLine())
1504 box->clearTruncation();
1507 LayoutUnit InlineFlowBox::computeOverAnnotationAdjustment(LayoutUnit allowedPosition) const
1509 LayoutUnit result = 0;
1510 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
1511 if (curr->renderer().isOutOfFlowPositioned())
1512 continue; // Positioned placeholders don't affect calculations.
1514 if (curr->isInlineFlowBox())
1515 result = max(result, toInlineFlowBox(curr)->computeOverAnnotationAdjustment(allowedPosition));
1517 if (curr->renderer().isReplaced() && curr->renderer().isRubyRun() && curr->renderer().style()->rubyPosition() == RubyPositionBefore) {
1518 RenderRubyRun& rubyRun = toRenderRubyRun(curr->renderer());
1519 RenderRubyText* rubyText = rubyRun.rubyText();
1523 if (!rubyRun.style()->isFlippedLinesWritingMode()) {
1524 LayoutUnit topOfFirstRubyTextLine = rubyText->logicalTop() + (rubyText->firstRootBox() ? rubyText->firstRootBox()->lineTop() : LayoutUnit());
1525 if (topOfFirstRubyTextLine >= 0)
1527 topOfFirstRubyTextLine += curr->logicalTop();
1528 result = max(result, allowedPosition - topOfFirstRubyTextLine);
1530 LayoutUnit bottomOfLastRubyTextLine = rubyText->logicalTop() + (rubyText->lastRootBox() ? rubyText->lastRootBox()->lineBottom() : rubyText->logicalHeight());
1531 if (bottomOfLastRubyTextLine <= curr->logicalHeight())
1533 bottomOfLastRubyTextLine += curr->logicalTop();
1534 result = max(result, bottomOfLastRubyTextLine - allowedPosition);
1538 if (curr->isInlineTextBox()) {
1539 RenderStyle* style = curr->renderer().style(isFirstLineStyle());
1540 TextEmphasisPosition emphasisMarkPosition;
1541 if (style->textEmphasisMark() != TextEmphasisMarkNone && toInlineTextBox(curr)->getEmphasisMarkPosition(style, emphasisMarkPosition) && emphasisMarkPosition == TextEmphasisPositionOver) {
1542 if (!style->isFlippedLinesWritingMode()) {
1543 int topOfEmphasisMark = curr->logicalTop() - style->font().emphasisMarkHeight(style->textEmphasisMarkString());
1544 result = max(result, allowedPosition - topOfEmphasisMark);
1546 int bottomOfEmphasisMark = curr->logicalBottom() + style->font().emphasisMarkHeight(style->textEmphasisMarkString());
1547 result = max(result, bottomOfEmphasisMark - allowedPosition);
1555 LayoutUnit InlineFlowBox::computeUnderAnnotationAdjustment(LayoutUnit allowedPosition) const
1557 LayoutUnit result = 0;
1558 for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
1559 if (curr->renderer().isOutOfFlowPositioned())
1560 continue; // Positioned placeholders don't affect calculations.
1562 if (curr->isInlineFlowBox())
1563 result = max(result, toInlineFlowBox(curr)->computeUnderAnnotationAdjustment(allowedPosition));
1565 if (curr->renderer().isReplaced() && curr->renderer().isRubyRun() && curr->renderer().style()->rubyPosition() == RubyPositionAfter) {
1566 RenderRubyRun& rubyRun = toRenderRubyRun(curr->renderer());
1567 RenderRubyText* rubyText = rubyRun.rubyText();
1571 if (rubyRun.style()->isFlippedLinesWritingMode()) {
1572 LayoutUnit topOfFirstRubyTextLine = rubyText->logicalTop() + (rubyText->firstRootBox() ? rubyText->firstRootBox()->lineTop() : LayoutUnit());
1573 if (topOfFirstRubyTextLine >= 0)
1575 topOfFirstRubyTextLine += curr->logicalTop();
1576 result = max(result, allowedPosition - topOfFirstRubyTextLine);
1578 LayoutUnit bottomOfLastRubyTextLine = rubyText->logicalTop() + (rubyText->lastRootBox() ? rubyText->lastRootBox()->lineBottom() : rubyText->logicalHeight());
1579 if (bottomOfLastRubyTextLine <= curr->logicalHeight())
1581 bottomOfLastRubyTextLine += curr->logicalTop();
1582 result = max(result, bottomOfLastRubyTextLine - allowedPosition);
1586 if (curr->isInlineTextBox()) {
1587 RenderStyle* style = curr->renderer().style(isFirstLineStyle());
1588 if (style->textEmphasisMark() != TextEmphasisMarkNone && style->textEmphasisPosition() == TextEmphasisPositionUnder) {
1589 if (!style->isFlippedLinesWritingMode()) {
1590 LayoutUnit bottomOfEmphasisMark = curr->logicalBottom() + style->font().emphasisMarkHeight(style->textEmphasisMarkString());
1591 result = max(result, bottomOfEmphasisMark - allowedPosition);
1593 LayoutUnit topOfEmphasisMark = curr->logicalTop() - style->font().emphasisMarkHeight(style->textEmphasisMarkString());
1594 result = max(result, allowedPosition - topOfEmphasisMark);
1602 void InlineFlowBox::collectLeafBoxesInLogicalOrder(Vector<InlineBox*>& leafBoxesInLogicalOrder, CustomInlineBoxRangeReverse customReverseImplementation, void* userData) const
1604 InlineBox* leaf = firstLeafChild();
1606 // FIXME: The reordering code is a copy of parts from BidiResolver::createBidiRunsForLine, operating directly on InlineBoxes, instead of BidiRuns.
1607 // Investigate on how this code could possibly be shared.
1608 unsigned char minLevel = 128;
1609 unsigned char maxLevel = 0;
1611 // First find highest and lowest levels, and initialize leafBoxesInLogicalOrder with the leaf boxes in visual order.
1612 for (; leaf; leaf = leaf->nextLeafChild()) {
1613 minLevel = min(minLevel, leaf->bidiLevel());
1614 maxLevel = max(maxLevel, leaf->bidiLevel());
1615 leafBoxesInLogicalOrder.append(leaf);
1618 if (renderer().style()->rtlOrdering() == VisualOrder)
1621 // Reverse of reordering of the line (L2 according to Bidi spec):
1622 // L2. From the highest level found in the text to the lowest odd level on each line,
1623 // reverse any contiguous sequence of characters that are at that level or higher.
1625 // Reversing the reordering of the line is only done up to the lowest odd level.
1626 if (!(minLevel % 2))
1629 Vector<InlineBox*>::iterator end = leafBoxesInLogicalOrder.end();
1630 while (minLevel <= maxLevel) {
1631 Vector<InlineBox*>::iterator it = leafBoxesInLogicalOrder.begin();
1634 if ((*it)->bidiLevel() >= minLevel)
1638 Vector<InlineBox*>::iterator first = it;
1640 if ((*it)->bidiLevel() < minLevel)
1644 Vector<InlineBox*>::iterator last = it;
1645 if (customReverseImplementation) {
1647 (*customReverseImplementation)(userData, first, last);
1649 std::reverse(first, last);
1657 const char* InlineFlowBox::boxName() const
1659 return "InlineFlowBox";
1662 void InlineFlowBox::showLineTreeAndMark(const InlineBox* markedBox1, const char* markedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const RenderObject* obj, int depth) const
1664 InlineBox::showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLabel2, obj, depth);
1665 for (const InlineBox* box = firstChild(); box; box = box->nextOnLine())
1666 box->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLabel2, obj, depth + 1);
1669 void InlineFlowBox::checkConsistency() const
1671 #ifdef CHECK_CONSISTENCY
1672 ASSERT(!m_hasBadChildList);
1673 const InlineBox* prev = 0;
1674 for (const InlineBox* child = m_firstChild; child; child = child->nextOnLine()) {
1675 ASSERT(child->parent() == this);
1676 ASSERT(child->prevOnLine() == prev);
1679 ASSERT(prev == m_lastChild);
1685 } // namespace WebCore