Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved.
      3  *
      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.
      8  *
      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.
     13  *
     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.
     18  */
     19 
     20 #include "config.h"
     21 #include "core/rendering/RootInlineBox.h"
     22 
     23 #include "core/dom/Document.h"
     24 #include "core/page/Chrome.h"
     25 #include "core/page/ChromeClient.h"
     26 #include "core/page/Frame.h"
     27 #include "core/page/Page.h"
     28 #include "core/platform/graphics/GraphicsContext.h"
     29 #include "core/platform/text/BidiResolver.h"
     30 #include "core/rendering/EllipsisBox.h"
     31 #include "core/rendering/HitTestResult.h"
     32 #include "core/rendering/InlineTextBox.h"
     33 #include "core/rendering/PaintInfo.h"
     34 #include "core/rendering/RenderBlock.h"
     35 #include "core/rendering/RenderFlowThread.h"
     36 #include "core/rendering/RenderView.h"
     37 #include "core/rendering/VerticalPositionCache.h"
     38 #include "wtf/unicode/Unicode.h"
     39 
     40 using namespace std;
     41 
     42 namespace WebCore {
     43 
     44 struct SameSizeAsRootInlineBox : public InlineFlowBox {
     45     unsigned variables[5];
     46     void* pointers[4];
     47 };
     48 
     49 COMPILE_ASSERT(sizeof(RootInlineBox) == sizeof(SameSizeAsRootInlineBox), RootInlineBox_should_stay_small);
     50 
     51 typedef WTF::HashMap<const RootInlineBox*, EllipsisBox*> EllipsisBoxMap;
     52 static EllipsisBoxMap* gEllipsisBoxMap = 0;
     53 
     54 RootInlineBox::RootInlineBox(RenderBlock* block)
     55     : InlineFlowBox(block)
     56     , m_lineBreakPos(0)
     57     , m_lineBreakObj(0)
     58     , m_lineTop(0)
     59     , m_lineBottom(0)
     60     , m_lineTopWithLeading(0)
     61     , m_lineBottomWithLeading(0)
     62 {
     63     setIsHorizontal(block->isHorizontalWritingMode());
     64 }
     65 
     66 
     67 void RootInlineBox::destroy()
     68 {
     69     detachEllipsisBox();
     70     InlineFlowBox::destroy();
     71 }
     72 
     73 void RootInlineBox::detachEllipsisBox()
     74 {
     75     if (hasEllipsisBox()) {
     76         EllipsisBox* box = gEllipsisBoxMap->take(this);
     77         box->setParent(0);
     78         box->destroy();
     79         setHasEllipsisBox(false);
     80     }
     81 }
     82 
     83 RenderLineBoxList* RootInlineBox::rendererLineBoxes() const
     84 {
     85     return block()->lineBoxes();
     86 }
     87 
     88 void RootInlineBox::clearTruncation()
     89 {
     90     if (hasEllipsisBox()) {
     91         detachEllipsisBox();
     92         InlineFlowBox::clearTruncation();
     93     }
     94 }
     95 
     96 bool RootInlineBox::isHyphenated() const
     97 {
     98     for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
     99         if (box->isInlineTextBox()) {
    100             if (toInlineTextBox(box)->hasHyphen())
    101                 return true;
    102         }
    103     }
    104 
    105     return false;
    106 }
    107 
    108 int RootInlineBox::baselinePosition(FontBaseline baselineType) const
    109 {
    110     return boxModelObject()->baselinePosition(baselineType, isFirstLineStyle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
    111 }
    112 
    113 LayoutUnit RootInlineBox::lineHeight() const
    114 {
    115     return boxModelObject()->lineHeight(isFirstLineStyle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
    116 }
    117 
    118 bool RootInlineBox::lineCanAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth)
    119 {
    120     // First sanity-check the unoverflowed width of the whole line to see if there is sufficient room.
    121     int delta = ltr ? lineBoxEdge - blockEdge : blockEdge - lineBoxEdge;
    122     if (logicalWidth() - delta < ellipsisWidth)
    123         return false;
    124 
    125     // Next iterate over all the line boxes on the line.  If we find a replaced element that intersects
    126     // then we refuse to accommodate the ellipsis.  Otherwise we're ok.
    127     return InlineFlowBox::canAccommodateEllipsis(ltr, blockEdge, ellipsisWidth);
    128 }
    129 
    130 float RootInlineBox::placeEllipsis(const AtomicString& ellipsisStr,  bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth,
    131                                   InlineBox* markupBox)
    132 {
    133     // Create an ellipsis box.
    134     EllipsisBox* ellipsisBox = new EllipsisBox(renderer(), ellipsisStr, this,
    135         ellipsisWidth - (markupBox ? markupBox->logicalWidth() : 0), logicalHeight(),
    136         y(), !prevRootBox(), isHorizontal(), markupBox);
    137 
    138     if (!gEllipsisBoxMap)
    139         gEllipsisBoxMap = new EllipsisBoxMap();
    140     gEllipsisBoxMap->add(this, ellipsisBox);
    141     setHasEllipsisBox(true);
    142 
    143     // FIXME: Do we need an RTL version of this?
    144     if (ltr && (x() + logicalWidth() + ellipsisWidth) <= blockRightEdge) {
    145         ellipsisBox->setX(x() + logicalWidth());
    146         return logicalWidth() + ellipsisWidth;
    147     }
    148 
    149     // Now attempt to find the nearest glyph horizontally and place just to the right (or left in RTL)
    150     // of that glyph.  Mark all of the objects that intersect the ellipsis box as not painting (as being
    151     // truncated).
    152     bool foundBox = false;
    153     float truncatedWidth = 0;
    154     float position = placeEllipsisBox(ltr, blockLeftEdge, blockRightEdge, ellipsisWidth, truncatedWidth, foundBox);
    155     ellipsisBox->setX(position);
    156     return truncatedWidth;
    157 }
    158 
    159 float RootInlineBox::placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, float &truncatedWidth, bool& foundBox)
    160 {
    161     float result = InlineFlowBox::placeEllipsisBox(ltr, blockLeftEdge, blockRightEdge, ellipsisWidth, truncatedWidth, foundBox);
    162     if (result == -1) {
    163         result = ltr ? blockRightEdge - ellipsisWidth : blockLeftEdge;
    164         truncatedWidth = blockRightEdge - blockLeftEdge;
    165     }
    166     return result;
    167 }
    168 
    169 void RootInlineBox::paintEllipsisBox(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom) const
    170 {
    171     if (hasEllipsisBox() && paintInfo.shouldPaintWithinRoot(renderer()) && renderer()->style()->visibility() == VISIBLE
    172             && paintInfo.phase == PaintPhaseForeground)
    173         ellipsisBox()->paint(paintInfo, paintOffset, lineTop, lineBottom);
    174 }
    175 
    176 void RootInlineBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
    177 {
    178     InlineFlowBox::paint(paintInfo, paintOffset, lineTop, lineBottom);
    179     paintEllipsisBox(paintInfo, paintOffset, lineTop, lineBottom);
    180 }
    181 
    182 bool RootInlineBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
    183 {
    184     if (hasEllipsisBox() && visibleToHitTestRequest(request)) {
    185         if (ellipsisBox()->nodeAtPoint(request, result, locationInContainer, accumulatedOffset, lineTop, lineBottom)) {
    186             renderer()->updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
    187             return true;
    188         }
    189     }
    190     return InlineFlowBox::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, lineTop, lineBottom);
    191 }
    192 
    193 void RootInlineBox::adjustPosition(float dx, float dy)
    194 {
    195     InlineFlowBox::adjustPosition(dx, dy);
    196     LayoutUnit blockDirectionDelta = isHorizontal() ? dy : dx; // The block direction delta is a LayoutUnit.
    197     m_lineTop += blockDirectionDelta;
    198     m_lineBottom += blockDirectionDelta;
    199     m_lineTopWithLeading += blockDirectionDelta;
    200     m_lineBottomWithLeading += blockDirectionDelta;
    201     if (hasEllipsisBox())
    202         ellipsisBox()->adjustPosition(dx, dy);
    203 }
    204 
    205 void RootInlineBox::childRemoved(InlineBox* box)
    206 {
    207     if (box->renderer() == m_lineBreakObj)
    208         setLineBreakInfo(0, 0, BidiStatus());
    209 
    210     for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == box->renderer(); prev = prev->prevRootBox()) {
    211         prev->setLineBreakInfo(0, 0, BidiStatus());
    212         prev->markDirty();
    213     }
    214 }
    215 
    216 RenderRegion* RootInlineBox::containingRegion() const
    217 {
    218     RenderRegion* region = m_fragmentationData ? m_fragmentationData->m_containingRegion : 0;
    219 
    220 #ifndef NDEBUG
    221     if (region) {
    222         RenderFlowThread* flowThread = block()->flowThreadContainingBlock();
    223         const RenderRegionList& regionList = flowThread->renderRegionList();
    224         ASSERT(regionList.contains(region));
    225     }
    226 #endif
    227 
    228     return region;
    229 }
    230 
    231 void RootInlineBox::setContainingRegion(RenderRegion* region)
    232 {
    233     ASSERT(!isDirty());
    234     ASSERT(block()->flowThreadContainingBlock());
    235     LineFragmentationData* fragmentationData  = ensureLineFragmentationData();
    236     fragmentationData->m_containingRegion = region;
    237 }
    238 
    239 LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache)
    240 {
    241     // SVG will handle vertical alignment on its own.
    242     if (isSVGRootInlineBox())
    243         return 0;
    244 
    245     LayoutUnit maxPositionTop = 0;
    246     LayoutUnit maxPositionBottom = 0;
    247     int maxAscent = 0;
    248     int maxDescent = 0;
    249     bool setMaxAscent = false;
    250     bool setMaxDescent = false;
    251 
    252     // Figure out if we're in no-quirks mode.
    253     bool noQuirksMode = renderer()->document()->inNoQuirksMode();
    254 
    255     m_baselineType = requiresIdeographicBaseline(textBoxDataMap) ? IdeographicBaseline : AlphabeticBaseline;
    256 
    257     computeLogicalBoxHeights(this, maxPositionTop, maxPositionBottom, maxAscent, maxDescent, setMaxAscent, setMaxDescent, noQuirksMode,
    258                              textBoxDataMap, baselineType(), verticalPositionCache);
    259 
    260     if (maxAscent + maxDescent < max(maxPositionTop, maxPositionBottom))
    261         adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPositionBottom);
    262 
    263     LayoutUnit maxHeight = maxAscent + maxDescent;
    264     LayoutUnit lineTop = heightOfBlock;
    265     LayoutUnit lineBottom = heightOfBlock;
    266     LayoutUnit lineTopIncludingMargins = heightOfBlock;
    267     LayoutUnit lineBottomIncludingMargins = heightOfBlock;
    268     bool setLineTop = false;
    269     bool hasAnnotationsBefore = false;
    270     bool hasAnnotationsAfter = false;
    271     placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode, lineTop, lineBottom, setLineTop,
    272                                lineTopIncludingMargins, lineBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType());
    273     m_hasAnnotationsBefore = hasAnnotationsBefore;
    274     m_hasAnnotationsAfter = hasAnnotationsAfter;
    275 
    276     maxHeight = max<LayoutUnit>(0, maxHeight); // FIXME: Is this really necessary?
    277 
    278     setLineTopBottomPositions(lineTop, lineBottom, heightOfBlock, heightOfBlock + maxHeight);
    279     setPaginatedLineWidth(block()->availableLogicalWidthForContent(heightOfBlock));
    280 
    281     LayoutUnit annotationsAdjustment = beforeAnnotationsAdjustment();
    282     if (annotationsAdjustment) {
    283         // FIXME: Need to handle pagination here. We might have to move to the next page/column as a result of the
    284         // ruby expansion.
    285         adjustBlockDirectionPosition(annotationsAdjustment);
    286         heightOfBlock += annotationsAdjustment;
    287     }
    288 
    289     LayoutUnit gridSnapAdjustment = lineSnapAdjustment();
    290     if (gridSnapAdjustment) {
    291         adjustBlockDirectionPosition(gridSnapAdjustment);
    292         heightOfBlock += gridSnapAdjustment;
    293     }
    294 
    295     return heightOfBlock + maxHeight;
    296 }
    297 
    298 #if ENABLE(CSS3_TEXT)
    299 float RootInlineBox::maxLogicalTop() const
    300 {
    301     float maxLogicalTop = 0;
    302     computeMaxLogicalTop(maxLogicalTop);
    303     return maxLogicalTop;
    304 }
    305 #endif // CSS3_TEXT
    306 
    307 LayoutUnit RootInlineBox::beforeAnnotationsAdjustment() const
    308 {
    309     LayoutUnit result = 0;
    310 
    311     if (!renderer()->style()->isFlippedLinesWritingMode()) {
    312         // Annotations under the previous line may push us down.
    313         if (prevRootBox() && prevRootBox()->hasAnnotationsAfter())
    314             result = prevRootBox()->computeUnderAnnotationAdjustment(lineTop());
    315 
    316         if (!hasAnnotationsBefore())
    317             return result;
    318 
    319         // Annotations over this line may push us further down.
    320         LayoutUnit highestAllowedPosition = prevRootBox() ? min(prevRootBox()->lineBottom(), lineTop()) + result : static_cast<LayoutUnit>(block()->borderBefore());
    321         result = computeOverAnnotationAdjustment(highestAllowedPosition);
    322     } else {
    323         // Annotations under this line may push us up.
    324         if (hasAnnotationsBefore())
    325             result = computeUnderAnnotationAdjustment(prevRootBox() ? prevRootBox()->lineBottom() : static_cast<LayoutUnit>(block()->borderBefore()));
    326 
    327         if (!prevRootBox() || !prevRootBox()->hasAnnotationsAfter())
    328             return result;
    329 
    330         // We have to compute the expansion for annotations over the previous line to see how much we should move.
    331         LayoutUnit lowestAllowedPosition = max(prevRootBox()->lineBottom(), lineTop()) - result;
    332         result = prevRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
    333     }
    334 
    335     return result;
    336 }
    337 
    338 LayoutUnit RootInlineBox::lineSnapAdjustment(LayoutUnit delta) const
    339 {
    340     // If our block doesn't have snapping turned on, do nothing.
    341     // FIXME: Implement bounds snapping.
    342     if (block()->style()->lineSnap() == LineSnapNone)
    343         return 0;
    344 
    345     // Get the current line grid and offset.
    346     LayoutState* layoutState = block()->view()->layoutState();
    347     RenderBlock* lineGrid = layoutState->lineGrid();
    348     LayoutSize lineGridOffset = layoutState->lineGridOffset();
    349     if (!lineGrid || lineGrid->style()->writingMode() != block()->style()->writingMode())
    350         return 0;
    351 
    352     // Get the hypothetical line box used to establish the grid.
    353     RootInlineBox* lineGridBox = lineGrid->lineGridBox();
    354     if (!lineGridBox)
    355         return 0;
    356 
    357     LayoutUnit lineGridBlockOffset = lineGrid->isHorizontalWritingMode() ? lineGridOffset.height() : lineGridOffset.width();
    358     LayoutUnit blockOffset = block()->isHorizontalWritingMode() ? layoutState->layoutOffset().height() : layoutState->layoutOffset().width();
    359 
    360     // Now determine our position on the grid. Our baseline needs to be adjusted to the nearest baseline multiple
    361     // as established by the line box.
    362     // FIXME: Need to handle crazy line-box-contain values that cause the root line box to not be considered. I assume
    363     // the grid should honor line-box-contain.
    364     LayoutUnit gridLineHeight = lineGridBox->lineBottomWithLeading() - lineGridBox->lineTopWithLeading();
    365     if (!gridLineHeight)
    366         return 0;
    367 
    368     LayoutUnit lineGridFontAscent = lineGrid->style()->fontMetrics().ascent(baselineType());
    369     LayoutUnit lineGridFontHeight = lineGridBox->logicalHeight();
    370     LayoutUnit firstTextTop = lineGridBlockOffset + lineGridBox->logicalTop();
    371     LayoutUnit firstLineTopWithLeading = lineGridBlockOffset + lineGridBox->lineTopWithLeading();
    372     LayoutUnit firstBaselinePosition = firstTextTop + lineGridFontAscent;
    373 
    374     LayoutUnit currentTextTop = blockOffset + logicalTop() + delta;
    375     LayoutUnit currentFontAscent = block()->style()->fontMetrics().ascent(baselineType());
    376     LayoutUnit currentBaselinePosition = currentTextTop + currentFontAscent;
    377 
    378     LayoutUnit lineGridPaginationOrigin = isHorizontal() ? layoutState->lineGridPaginationOrigin().height() : layoutState->lineGridPaginationOrigin().width();
    379 
    380     // If we're paginated, see if we're on a page after the first one. If so, the grid resets on subsequent pages.
    381     // FIXME: If the grid is an ancestor of the pagination establisher, then this is incorrect.
    382     LayoutUnit pageLogicalTop = 0;
    383     if (layoutState->isPaginated() && layoutState->pageLogicalHeight()) {
    384         pageLogicalTop = block()->pageLogicalTopForOffset(lineTopWithLeading() + delta);
    385         if (pageLogicalTop > firstLineTopWithLeading)
    386             firstTextTop = pageLogicalTop + lineGridBox->logicalTop() - lineGrid->borderBefore() - lineGrid->paddingBefore() + lineGridPaginationOrigin;
    387     }
    388 
    389     if (block()->style()->lineSnap() == LineSnapContain) {
    390         // Compute the desired offset from the text-top of a grid line.
    391         // Look at our height (logicalHeight()).
    392         // Look at the total available height. It's going to be (textBottom - textTop) + (n-1)*(multiple with leading)
    393         // where n is number of grid lines required to enclose us.
    394         if (logicalHeight() <= lineGridFontHeight)
    395             firstTextTop += (lineGridFontHeight - logicalHeight()) / 2;
    396         else {
    397             LayoutUnit numberOfLinesWithLeading = ceilf(static_cast<float>(logicalHeight() - lineGridFontHeight) / gridLineHeight);
    398             LayoutUnit totalHeight = lineGridFontHeight + numberOfLinesWithLeading * gridLineHeight;
    399             firstTextTop += (totalHeight - logicalHeight()) / 2;
    400         }
    401         firstBaselinePosition = firstTextTop + currentFontAscent;
    402     } else
    403         firstBaselinePosition = firstTextTop + lineGridFontAscent;
    404 
    405     // If we're above the first line, just push to the first line.
    406     if (currentBaselinePosition < firstBaselinePosition)
    407         return delta + firstBaselinePosition - currentBaselinePosition;
    408 
    409     // Otherwise we're in the middle of the grid somewhere. Just push to the next line.
    410     LayoutUnit baselineOffset = currentBaselinePosition - firstBaselinePosition;
    411     LayoutUnit remainder = roundToInt(baselineOffset) % roundToInt(gridLineHeight);
    412     LayoutUnit result = delta;
    413     if (remainder)
    414         result += gridLineHeight - remainder;
    415 
    416     // If we aren't paginated we can return the result.
    417     if (!layoutState->isPaginated() || !layoutState->pageLogicalHeight() || result == delta)
    418         return result;
    419 
    420     // We may end up shifted to a new page. We need to do a re-snap when that happens.
    421     LayoutUnit newPageLogicalTop = block()->pageLogicalTopForOffset(lineBottomWithLeading() + result);
    422     if (newPageLogicalTop == pageLogicalTop)
    423         return result;
    424 
    425     // Put ourselves at the top of the next page to force a snap onto the new grid established by that page.
    426     return lineSnapAdjustment(newPageLogicalTop - (blockOffset + lineTopWithLeading()));
    427 }
    428 
    429 GapRects RootInlineBox::lineSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
    430                                          LayoutUnit selTop, LayoutUnit selHeight, const PaintInfo* paintInfo)
    431 {
    432     RenderObject::SelectionState lineState = selectionState();
    433 
    434     bool leftGap, rightGap;
    435     block()->getSelectionGapInfo(lineState, leftGap, rightGap);
    436 
    437     GapRects result;
    438 
    439     InlineBox* firstBox = firstSelectedBox();
    440     InlineBox* lastBox = lastSelectedBox();
    441     if (leftGap)
    442         result.uniteLeft(block()->logicalLeftSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
    443                                                           firstBox->parent()->renderer(), firstBox->logicalLeft(), selTop, selHeight, paintInfo));
    444     if (rightGap)
    445         result.uniteRight(block()->logicalRightSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
    446                                                             lastBox->parent()->renderer(), lastBox->logicalRight(), selTop, selHeight, paintInfo));
    447 
    448     // When dealing with bidi text, a non-contiguous selection region is possible.
    449     // e.g. The logical text aaaAAAbbb (capitals denote RTL text and non-capitals LTR) is layed out
    450     // visually as 3 text runs |aaa|bbb|AAA| if we select 4 characters from the start of the text the
    451     // selection will look like (underline denotes selection):
    452     // |aaa|bbb|AAA|
    453     //  ___       _
    454     // We can see that the |bbb| run is not part of the selection while the runs around it are.
    455     if (firstBox && firstBox != lastBox) {
    456         // Now fill in any gaps on the line that occurred between two selected elements.
    457         LayoutUnit lastLogicalLeft = firstBox->logicalRight();
    458         bool isPreviousBoxSelected = firstBox->selectionState() != RenderObject::SelectionNone;
    459         for (InlineBox* box = firstBox->nextLeafChild(); box; box = box->nextLeafChild()) {
    460             if (box->selectionState() != RenderObject::SelectionNone) {
    461                 LayoutRect logicalRect(lastLogicalLeft, selTop, box->logicalLeft() - lastLogicalLeft, selHeight);
    462                 logicalRect.move(renderer()->isHorizontalWritingMode() ? offsetFromRootBlock : LayoutSize(offsetFromRootBlock.height(), offsetFromRootBlock.width()));
    463                 LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect);
    464                 if (isPreviousBoxSelected && gapRect.width() > 0 && gapRect.height() > 0) {
    465                     if (paintInfo && box->parent()->renderer()->style()->visibility() == VISIBLE)
    466                         paintInfo->context->fillRect(gapRect, box->parent()->renderer()->selectionBackgroundColor());
    467                     // VisibleSelection may be non-contiguous, see comment above.
    468                     result.uniteCenter(gapRect);
    469                 }
    470                 lastLogicalLeft = box->logicalRight();
    471             }
    472             if (box == lastBox)
    473                 break;
    474             isPreviousBoxSelected = box->selectionState() != RenderObject::SelectionNone;
    475         }
    476     }
    477 
    478     return result;
    479 }
    480 
    481 RenderObject::SelectionState RootInlineBox::selectionState()
    482 {
    483     // Walk over all of the selected boxes.
    484     RenderObject::SelectionState state = RenderObject::SelectionNone;
    485     for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
    486         RenderObject::SelectionState boxState = box->selectionState();
    487         if ((boxState == RenderObject::SelectionStart && state == RenderObject::SelectionEnd) ||
    488             (boxState == RenderObject::SelectionEnd && state == RenderObject::SelectionStart))
    489             state = RenderObject::SelectionBoth;
    490         else if (state == RenderObject::SelectionNone ||
    491                  ((boxState == RenderObject::SelectionStart || boxState == RenderObject::SelectionEnd) &&
    492                   (state == RenderObject::SelectionNone || state == RenderObject::SelectionInside)))
    493             state = boxState;
    494         else if (boxState == RenderObject::SelectionNone && state == RenderObject::SelectionStart) {
    495             // We are past the end of the selection.
    496             state = RenderObject::SelectionBoth;
    497         }
    498         if (state == RenderObject::SelectionBoth)
    499             break;
    500     }
    501 
    502     return state;
    503 }
    504 
    505 InlineBox* RootInlineBox::firstSelectedBox()
    506 {
    507     for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
    508         if (box->selectionState() != RenderObject::SelectionNone)
    509             return box;
    510     }
    511 
    512     return 0;
    513 }
    514 
    515 InlineBox* RootInlineBox::lastSelectedBox()
    516 {
    517     for (InlineBox* box = lastLeafChild(); box; box = box->prevLeafChild()) {
    518         if (box->selectionState() != RenderObject::SelectionNone)
    519             return box;
    520     }
    521 
    522     return 0;
    523 }
    524 
    525 LayoutUnit RootInlineBox::selectionTop() const
    526 {
    527     LayoutUnit selectionTop = m_lineTop;
    528 
    529     if (m_hasAnnotationsBefore)
    530         selectionTop -= !renderer()->style()->isFlippedLinesWritingMode() ? computeOverAnnotationAdjustment(m_lineTop) : computeUnderAnnotationAdjustment(m_lineTop);
    531 
    532     if (renderer()->style()->isFlippedLinesWritingMode())
    533         return selectionTop;
    534 
    535     LayoutUnit prevBottom = prevRootBox() ? prevRootBox()->selectionBottom() : block()->borderBefore() + block()->paddingBefore();
    536     if (prevBottom < selectionTop && block()->containsFloats()) {
    537         // This line has actually been moved further down, probably from a large line-height, but possibly because the
    538         // line was forced to clear floats.  If so, let's check the offsets, and only be willing to use the previous
    539         // line's bottom if the offsets are greater on both sides.
    540         LayoutUnit prevLeft = block()->logicalLeftOffsetForLine(prevBottom, false);
    541         LayoutUnit prevRight = block()->logicalRightOffsetForLine(prevBottom, false);
    542         LayoutUnit newLeft = block()->logicalLeftOffsetForLine(selectionTop, false);
    543         LayoutUnit newRight = block()->logicalRightOffsetForLine(selectionTop, false);
    544         if (prevLeft > newLeft || prevRight < newRight)
    545             return selectionTop;
    546     }
    547 
    548     return prevBottom;
    549 }
    550 
    551 LayoutUnit RootInlineBox::selectionTopAdjustedForPrecedingBlock() const
    552 {
    553     LayoutUnit top = selectionTop();
    554 
    555     RenderObject::SelectionState blockSelectionState = root()->block()->selectionState();
    556     if (blockSelectionState != RenderObject::SelectionInside && blockSelectionState != RenderObject::SelectionEnd)
    557         return top;
    558 
    559     LayoutSize offsetToBlockBefore;
    560     if (RenderBlock* block = root()->block()->blockBeforeWithinSelectionRoot(offsetToBlockBefore)) {
    561         if (RootInlineBox* lastLine = block->lastRootBox()) {
    562             RenderObject::SelectionState lastLineSelectionState = lastLine->selectionState();
    563             if (lastLineSelectionState != RenderObject::SelectionInside && lastLineSelectionState != RenderObject::SelectionStart)
    564                 return top;
    565 
    566             LayoutUnit lastLineSelectionBottom = lastLine->selectionBottom() + offsetToBlockBefore.height();
    567             top = max(top, lastLineSelectionBottom);
    568         }
    569     }
    570 
    571     return top;
    572 }
    573 
    574 LayoutUnit RootInlineBox::selectionBottom() const
    575 {
    576     LayoutUnit selectionBottom = m_lineBottom;
    577 
    578     if (m_hasAnnotationsAfter)
    579         selectionBottom += !renderer()->style()->isFlippedLinesWritingMode() ? computeUnderAnnotationAdjustment(m_lineBottom) : computeOverAnnotationAdjustment(m_lineBottom);
    580 
    581     if (!renderer()->style()->isFlippedLinesWritingMode() || !nextRootBox())
    582         return selectionBottom;
    583 
    584     LayoutUnit nextTop = nextRootBox()->selectionTop();
    585     if (nextTop > selectionBottom && block()->containsFloats()) {
    586         // The next line has actually been moved further over, probably from a large line-height, but possibly because the
    587         // line was forced to clear floats.  If so, let's check the offsets, and only be willing to use the next
    588         // line's top if the offsets are greater on both sides.
    589         LayoutUnit nextLeft = block()->logicalLeftOffsetForLine(nextTop, false);
    590         LayoutUnit nextRight = block()->logicalRightOffsetForLine(nextTop, false);
    591         LayoutUnit newLeft = block()->logicalLeftOffsetForLine(selectionBottom, false);
    592         LayoutUnit newRight = block()->logicalRightOffsetForLine(selectionBottom, false);
    593         if (nextLeft > newLeft || nextRight < newRight)
    594             return selectionBottom;
    595     }
    596 
    597     return nextTop;
    598 }
    599 
    600 int RootInlineBox::blockDirectionPointInLine() const
    601 {
    602     return !block()->style()->isFlippedBlocksWritingMode() ? max(lineTop(), selectionTop()) : min(lineBottom(), selectionBottom());
    603 }
    604 
    605 RenderBlock* RootInlineBox::block() const
    606 {
    607     return toRenderBlock(renderer());
    608 }
    609 
    610 static bool isEditableLeaf(InlineBox* leaf)
    611 {
    612     return leaf && leaf->renderer() && leaf->renderer()->node() && leaf->renderer()->node()->rendererIsEditable();
    613 }
    614 
    615 InlineBox* RootInlineBox::closestLeafChildForPoint(const IntPoint& pointInContents, bool onlyEditableLeaves)
    616 {
    617     return closestLeafChildForLogicalLeftPosition(block()->isHorizontalWritingMode() ? pointInContents.x() : pointInContents.y(), onlyEditableLeaves);
    618 }
    619 
    620 InlineBox* RootInlineBox::closestLeafChildForLogicalLeftPosition(int leftPosition, bool onlyEditableLeaves)
    621 {
    622     InlineBox* firstLeaf = firstLeafChild();
    623     InlineBox* lastLeaf = lastLeafChild();
    624 
    625     if (firstLeaf != lastLeaf) {
    626         if (firstLeaf->isLineBreak())
    627             firstLeaf = firstLeaf->nextLeafChildIgnoringLineBreak();
    628         else if (lastLeaf->isLineBreak())
    629             lastLeaf = lastLeaf->prevLeafChildIgnoringLineBreak();
    630     }
    631 
    632     if (firstLeaf == lastLeaf && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
    633         return firstLeaf;
    634 
    635     // Avoid returning a list marker when possible.
    636     if (leftPosition <= firstLeaf->logicalLeft() && !firstLeaf->renderer()->isListMarker() && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
    637         // The leftPosition coordinate is less or equal to left edge of the firstLeaf.
    638         // Return it.
    639         return firstLeaf;
    640 
    641     if (leftPosition >= lastLeaf->logicalRight() && !lastLeaf->renderer()->isListMarker() && (!onlyEditableLeaves || isEditableLeaf(lastLeaf)))
    642         // The leftPosition coordinate is greater or equal to right edge of the lastLeaf.
    643         // Return it.
    644         return lastLeaf;
    645 
    646     InlineBox* closestLeaf = 0;
    647     for (InlineBox* leaf = firstLeaf; leaf; leaf = leaf->nextLeafChildIgnoringLineBreak()) {
    648         if (!leaf->renderer()->isListMarker() && (!onlyEditableLeaves || isEditableLeaf(leaf))) {
    649             closestLeaf = leaf;
    650             if (leftPosition < leaf->logicalRight())
    651                 // The x coordinate is less than the right edge of the box.
    652                 // Return it.
    653                 return leaf;
    654         }
    655     }
    656 
    657     return closestLeaf ? closestLeaf : lastLeaf;
    658 }
    659 
    660 BidiStatus RootInlineBox::lineBreakBidiStatus() const
    661 {
    662     return BidiStatus(static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusEor), static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusLastStrong), static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusLast), m_lineBreakContext);
    663 }
    664 
    665 void RootInlineBox::setLineBreakInfo(RenderObject* obj, unsigned breakPos, const BidiStatus& status)
    666 {
    667     m_lineBreakObj = obj;
    668     m_lineBreakPos = breakPos;
    669     m_lineBreakBidiStatusEor = status.eor;
    670     m_lineBreakBidiStatusLastStrong = status.lastStrong;
    671     m_lineBreakBidiStatusLast = status.last;
    672     m_lineBreakContext = status.context;
    673 }
    674 
    675 EllipsisBox* RootInlineBox::ellipsisBox() const
    676 {
    677     if (!hasEllipsisBox())
    678         return 0;
    679     return gEllipsisBoxMap->get(this);
    680 }
    681 
    682 void RootInlineBox::removeLineBoxFromRenderObject()
    683 {
    684     block()->lineBoxes()->removeLineBox(this);
    685 }
    686 
    687 void RootInlineBox::extractLineBoxFromRenderObject()
    688 {
    689     block()->lineBoxes()->extractLineBox(this);
    690 }
    691 
    692 void RootInlineBox::attachLineBoxToRenderObject()
    693 {
    694     block()->lineBoxes()->attachLineBox(this);
    695 }
    696 
    697 LayoutRect RootInlineBox::paddedLayoutOverflowRect(LayoutUnit endPadding) const
    698 {
    699     LayoutRect lineLayoutOverflow = layoutOverflowRect(lineTop(), lineBottom());
    700     if (!endPadding)
    701         return lineLayoutOverflow;
    702 
    703     // FIXME: Audit whether to use pixel snapped values when not using integers for layout: https://bugs.webkit.org/show_bug.cgi?id=63656
    704     if (isHorizontal()) {
    705         if (isLeftToRightDirection())
    706             lineLayoutOverflow.shiftMaxXEdgeTo(max<LayoutUnit>(lineLayoutOverflow.maxX(), pixelSnappedLogicalRight() + endPadding));
    707         else
    708             lineLayoutOverflow.shiftXEdgeTo(min<LayoutUnit>(lineLayoutOverflow.x(), pixelSnappedLogicalLeft() - endPadding));
    709     } else {
    710         if (isLeftToRightDirection())
    711             lineLayoutOverflow.shiftMaxYEdgeTo(max<LayoutUnit>(lineLayoutOverflow.maxY(), pixelSnappedLogicalRight() + endPadding));
    712         else
    713             lineLayoutOverflow.shiftYEdgeTo(min<LayoutUnit>(lineLayoutOverflow.y(), pixelSnappedLogicalLeft() - endPadding));
    714     }
    715 
    716     return lineLayoutOverflow;
    717 }
    718 
    719 static void setAscentAndDescent(int& ascent, int& descent, int newAscent, int newDescent, bool& ascentDescentSet)
    720 {
    721     if (!ascentDescentSet) {
    722         ascentDescentSet = true;
    723         ascent = newAscent;
    724         descent = newDescent;
    725     } else {
    726         ascent = max(ascent, newAscent);
    727         descent = max(descent, newDescent);
    728     }
    729 }
    730 
    731 void RootInlineBox::ascentAndDescentForBox(InlineBox* box, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, int& ascent, int& descent,
    732                                            bool& affectsAscent, bool& affectsDescent) const
    733 {
    734     bool ascentDescentSet = false;
    735 
    736     // Replaced boxes will return 0 for the line-height if line-box-contain says they are
    737     // not to be included.
    738     if (box->renderer()->isReplaced()) {
    739         if (renderer()->style(isFirstLineStyle())->lineBoxContain() & LineBoxContainReplaced) {
    740             ascent = box->baselinePosition(baselineType());
    741             descent = box->lineHeight() - ascent;
    742 
    743             // Replaced elements always affect both the ascent and descent.
    744             affectsAscent = true;
    745             affectsDescent = true;
    746         }
    747         return;
    748     }
    749 
    750     Vector<const SimpleFontData*>* usedFonts = 0;
    751     GlyphOverflow* glyphOverflow = 0;
    752     if (box->isText()) {
    753         GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.find(toInlineTextBox(box));
    754         usedFonts = it == textBoxDataMap.end() ? 0 : &it->value.first;
    755         glyphOverflow = it == textBoxDataMap.end() ? 0 : &it->value.second;
    756     }
    757 
    758     bool includeLeading = includeLeadingForBox(box);
    759     bool includeFont = includeFontForBox(box);
    760 
    761     bool setUsedFont = false;
    762     bool setUsedFontWithLeading = false;
    763 
    764     if (usedFonts && !usedFonts->isEmpty() && (includeFont || (box->renderer()->style(isFirstLineStyle())->lineHeight().isNegative() && includeLeading))) {
    765         usedFonts->append(box->renderer()->style(isFirstLineStyle())->font().primaryFont());
    766         for (size_t i = 0; i < usedFonts->size(); ++i) {
    767             const FontMetrics& fontMetrics = usedFonts->at(i)->fontMetrics();
    768             int usedFontAscent = fontMetrics.ascent(baselineType());
    769             int usedFontDescent = fontMetrics.descent(baselineType());
    770             int halfLeading = (fontMetrics.lineSpacing() - fontMetrics.height()) / 2;
    771             int usedFontAscentAndLeading = usedFontAscent + halfLeading;
    772             int usedFontDescentAndLeading = fontMetrics.lineSpacing() - usedFontAscentAndLeading;
    773             if (includeFont) {
    774                 setAscentAndDescent(ascent, descent, usedFontAscent, usedFontDescent, ascentDescentSet);
    775                 setUsedFont = true;
    776             }
    777             if (includeLeading) {
    778                 setAscentAndDescent(ascent, descent, usedFontAscentAndLeading, usedFontDescentAndLeading, ascentDescentSet);
    779                 setUsedFontWithLeading = true;
    780             }
    781             if (!affectsAscent)
    782                 affectsAscent = usedFontAscent - box->logicalTop() > 0;
    783             if (!affectsDescent)
    784                 affectsDescent = usedFontDescent + box->logicalTop() > 0;
    785         }
    786     }
    787 
    788     // If leading is included for the box, then we compute that box.
    789     if (includeLeading && !setUsedFontWithLeading) {
    790         int ascentWithLeading = box->baselinePosition(baselineType());
    791         int descentWithLeading = box->lineHeight() - ascentWithLeading;
    792         setAscentAndDescent(ascent, descent, ascentWithLeading, descentWithLeading, ascentDescentSet);
    793 
    794         // Examine the font box for inline flows and text boxes to see if any part of it is above the baseline.
    795         // If the top of our font box relative to the root box baseline is above the root box baseline, then
    796         // we are contributing to the maxAscent value. Descent is similar. If any part of our font box is below
    797         // the root box's baseline, then we contribute to the maxDescent value.
    798         affectsAscent = ascentWithLeading - box->logicalTop() > 0;
    799         affectsDescent = descentWithLeading + box->logicalTop() > 0;
    800     }
    801 
    802     if (includeFontForBox(box) && !setUsedFont) {
    803         int fontAscent = box->renderer()->style(isFirstLineStyle())->fontMetrics().ascent(baselineType());
    804         int fontDescent = box->renderer()->style(isFirstLineStyle())->fontMetrics().descent(baselineType());
    805         setAscentAndDescent(ascent, descent, fontAscent, fontDescent, ascentDescentSet);
    806         affectsAscent = fontAscent - box->logicalTop() > 0;
    807         affectsDescent = fontDescent + box->logicalTop() > 0;
    808     }
    809 
    810     if (includeGlyphsForBox(box) && glyphOverflow && glyphOverflow->computeBounds) {
    811         setAscentAndDescent(ascent, descent, glyphOverflow->top, glyphOverflow->bottom, ascentDescentSet);
    812         affectsAscent = glyphOverflow->top - box->logicalTop() > 0;
    813         affectsDescent = glyphOverflow->bottom + box->logicalTop() > 0;
    814         glyphOverflow->top = min(glyphOverflow->top, max(0, glyphOverflow->top - box->renderer()->style(isFirstLineStyle())->fontMetrics().ascent(baselineType())));
    815         glyphOverflow->bottom = min(glyphOverflow->bottom, max(0, glyphOverflow->bottom - box->renderer()->style(isFirstLineStyle())->fontMetrics().descent(baselineType())));
    816     }
    817 
    818     if (includeMarginForBox(box)) {
    819         LayoutUnit ascentWithMargin = box->renderer()->style(isFirstLineStyle())->fontMetrics().ascent(baselineType());
    820         LayoutUnit descentWithMargin = box->renderer()->style(isFirstLineStyle())->fontMetrics().descent(baselineType());
    821         if (box->parent() && !box->renderer()->isText()) {
    822             ascentWithMargin += box->boxModelObject()->borderBefore() + box->boxModelObject()->paddingBefore() + box->boxModelObject()->marginBefore();
    823             descentWithMargin += box->boxModelObject()->borderAfter() + box->boxModelObject()->paddingAfter() + box->boxModelObject()->marginAfter();
    824         }
    825         setAscentAndDescent(ascent, descent, ascentWithMargin, descentWithMargin, ascentDescentSet);
    826 
    827         // Treat like a replaced element, since we're using the margin box.
    828         affectsAscent = true;
    829         affectsDescent = true;
    830     }
    831 }
    832 
    833 LayoutUnit RootInlineBox::verticalPositionForBox(InlineBox* box, VerticalPositionCache& verticalPositionCache)
    834 {
    835     if (box->renderer()->isText())
    836         return box->parent()->logicalTop();
    837 
    838     RenderBoxModelObject* renderer = box->boxModelObject();
    839     ASSERT(renderer->isInline());
    840     if (!renderer->isInline())
    841         return 0;
    842 
    843     // This method determines the vertical position for inline elements.
    844     bool firstLine = isFirstLineStyle();
    845     if (firstLine && !renderer->document()->styleSheetCollection()->usesFirstLineRules())
    846         firstLine = false;
    847 
    848     // Check the cache.
    849     bool isRenderInline = renderer->isRenderInline();
    850     if (isRenderInline && !firstLine) {
    851         LayoutUnit verticalPosition = verticalPositionCache.get(renderer, baselineType());
    852         if (verticalPosition != PositionUndefined)
    853             return verticalPosition;
    854     }
    855 
    856     LayoutUnit verticalPosition = 0;
    857     EVerticalAlign verticalAlign = renderer->style()->verticalAlign();
    858     if (verticalAlign == TOP || verticalAlign == BOTTOM)
    859         return 0;
    860 
    861     RenderObject* parent = renderer->parent();
    862     if (parent->isRenderInline() && parent->style()->verticalAlign() != TOP && parent->style()->verticalAlign() != BOTTOM)
    863         verticalPosition = box->parent()->logicalTop();
    864 
    865     if (verticalAlign != BASELINE) {
    866         const Font& font = parent->style(firstLine)->font();
    867         const FontMetrics& fontMetrics = font.fontMetrics();
    868         int fontSize = font.pixelSize();
    869 
    870         LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? HorizontalLine : VerticalLine;
    871 
    872         if (verticalAlign == SUB)
    873             verticalPosition += fontSize / 5 + 1;
    874         else if (verticalAlign == SUPER)
    875             verticalPosition -= fontSize / 3 + 1;
    876         else if (verticalAlign == TEXT_TOP)
    877             verticalPosition += renderer->baselinePosition(baselineType(), firstLine, lineDirection) - fontMetrics.ascent(baselineType());
    878         else if (verticalAlign == MIDDLE)
    879             verticalPosition = (verticalPosition - static_cast<LayoutUnit>(fontMetrics.xHeight() / 2) - renderer->lineHeight(firstLine, lineDirection) / 2 + renderer->baselinePosition(baselineType(), firstLine, lineDirection)).round();
    880         else if (verticalAlign == TEXT_BOTTOM) {
    881             verticalPosition += fontMetrics.descent(baselineType());
    882             // lineHeight - baselinePosition is always 0 for replaced elements (except inline blocks), so don't bother wasting time in that case.
    883             if (!renderer->isReplaced() || renderer->isInlineBlockOrInlineTable())
    884                 verticalPosition -= (renderer->lineHeight(firstLine, lineDirection) - renderer->baselinePosition(baselineType(), firstLine, lineDirection));
    885         } else if (verticalAlign == BASELINE_MIDDLE)
    886             verticalPosition += -renderer->lineHeight(firstLine, lineDirection) / 2 + renderer->baselinePosition(baselineType(), firstLine, lineDirection);
    887         else if (verticalAlign == LENGTH) {
    888             LayoutUnit lineHeight;
    889             //Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-align: 'Percentages: refer to the 'line-height' of the element itself'.
    890             if (renderer->style()->verticalAlignLength().isPercent())
    891                 lineHeight = renderer->style()->computedLineHeight();
    892             else
    893                 lineHeight = renderer->lineHeight(firstLine, lineDirection);
    894             verticalPosition -= valueForLength(renderer->style()->verticalAlignLength(), lineHeight, renderer->view());
    895         }
    896     }
    897 
    898     // Store the cached value.
    899     if (isRenderInline && !firstLine)
    900         verticalPositionCache.set(renderer, baselineType(), verticalPosition);
    901 
    902     return verticalPosition;
    903 }
    904 
    905 bool RootInlineBox::includeLeadingForBox(InlineBox* box) const
    906 {
    907     if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
    908         return false;
    909 
    910     LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
    911     return (lineBoxContain & LineBoxContainInline) || (box == this && (lineBoxContain & LineBoxContainBlock));
    912 }
    913 
    914 bool RootInlineBox::includeFontForBox(InlineBox* box) const
    915 {
    916     if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
    917         return false;
    918 
    919     if (!box->isText() && box->isInlineFlowBox() && !toInlineFlowBox(box)->hasTextChildren())
    920         return false;
    921 
    922     // For now map "glyphs" to "font" in vertical text mode until the bounds returned by glyphs aren't garbage.
    923     LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
    924     return (lineBoxContain & LineBoxContainFont) || (!isHorizontal() && (lineBoxContain & LineBoxContainGlyphs));
    925 }
    926 
    927 bool RootInlineBox::includeGlyphsForBox(InlineBox* box) const
    928 {
    929     if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
    930         return false;
    931 
    932     if (!box->isText() && box->isInlineFlowBox() && !toInlineFlowBox(box)->hasTextChildren())
    933         return false;
    934 
    935     // FIXME: We can't fit to glyphs yet for vertical text, since the bounds returned are garbage.
    936     LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
    937     return isHorizontal() && (lineBoxContain & LineBoxContainGlyphs);
    938 }
    939 
    940 bool RootInlineBox::includeMarginForBox(InlineBox* box) const
    941 {
    942     if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
    943         return false;
    944 
    945     LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
    946     return lineBoxContain & LineBoxContainInlineBox;
    947 }
    948 
    949 
    950 bool RootInlineBox::fitsToGlyphs() const
    951 {
    952     // FIXME: We can't fit to glyphs yet for vertical text, since the bounds returned are garbage.
    953     LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
    954     return isHorizontal() && (lineBoxContain & LineBoxContainGlyphs);
    955 }
    956 
    957 bool RootInlineBox::includesRootLineBoxFontOrLeading() const
    958 {
    959     LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
    960     return (lineBoxContain & LineBoxContainBlock) || (lineBoxContain & LineBoxContainInline) || (lineBoxContain & LineBoxContainFont);
    961 }
    962 
    963 Node* RootInlineBox::getLogicalStartBoxWithNode(InlineBox*& startBox) const
    964 {
    965     Vector<InlineBox*> leafBoxesInLogicalOrder;
    966     collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder);
    967     for (size_t i = 0; i < leafBoxesInLogicalOrder.size(); ++i) {
    968         if (leafBoxesInLogicalOrder[i]->renderer()->node()) {
    969             startBox = leafBoxesInLogicalOrder[i];
    970             return startBox->renderer()->node();
    971         }
    972     }
    973     startBox = 0;
    974     return 0;
    975 }
    976 
    977 Node* RootInlineBox::getLogicalEndBoxWithNode(InlineBox*& endBox) const
    978 {
    979     Vector<InlineBox*> leafBoxesInLogicalOrder;
    980     collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder);
    981     for (size_t i = leafBoxesInLogicalOrder.size(); i > 0; --i) {
    982         if (leafBoxesInLogicalOrder[i - 1]->renderer()->node()) {
    983             endBox = leafBoxesInLogicalOrder[i - 1];
    984             return endBox->renderer()->node();
    985         }
    986     }
    987     endBox = 0;
    988     return 0;
    989 }
    990 
    991 #ifndef NDEBUG
    992 const char* RootInlineBox::boxName() const
    993 {
    994     return "RootInlineBox";
    995 }
    996 #endif
    997 
    998 } // namespace WebCore
    999