#include "core/rendering/RootInlineBox.h"
#include "core/dom/Document.h"
+#include "core/dom/StyleEngine.h"
+#include "core/paint/RootInlineBoxPainter.h"
#include "core/rendering/EllipsisBox.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/InlineTextBox.h"
#include "core/rendering/PaintInfo.h"
-#include "core/rendering/RenderBlock.h"
+#include "core/rendering/RenderBlockFlow.h"
#include "core/rendering/RenderFlowThread.h"
+#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/VerticalPositionCache.h"
#include "platform/text/BidiResolver.h"
#include "wtf/unicode/Unicode.h"
-using namespace std;
-
-namespace WebCore {
+namespace blink {
struct SameSizeAsRootInlineBox : public InlineFlowBox {
- unsigned variables[5];
+ unsigned unsignedVariable;
void* pointers[4];
+ LayoutUnit layoutVariables[5];
};
COMPILE_ASSERT(sizeof(RootInlineBox) == sizeof(SameSizeAsRootInlineBox), RootInlineBox_should_stay_small);
typedef WTF::HashMap<const RootInlineBox*, EllipsisBox*> EllipsisBoxMap;
static EllipsisBoxMap* gEllipsisBoxMap = 0;
-RootInlineBox::RootInlineBox(RenderBlock* block)
+RootInlineBox::RootInlineBox(RenderBlockFlow& block)
: InlineFlowBox(block)
, m_lineBreakPos(0)
, m_lineBreakObj(0)
, m_lineBottom(0)
, m_lineTopWithLeading(0)
, m_lineBottomWithLeading(0)
+ , m_selectionBottom(0)
{
- setIsHorizontal(block->isHorizontalWritingMode());
+ setIsHorizontal(block.isHorizontalWritingMode());
}
RenderLineBoxList* RootInlineBox::rendererLineBoxes() const
{
- return block()->lineBoxes();
+ return block().lineBoxes();
}
void RootInlineBox::clearTruncation()
}
}
-bool RootInlineBox::isHyphenated() const
-{
- for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
- if (box->isInlineTextBox()) {
- if (toInlineTextBox(box)->hasHyphen())
- return true;
- }
- }
-
- return false;
-}
-
int RootInlineBox::baselinePosition(FontBaseline baselineType) const
{
return boxModelObject()->baselinePosition(baselineType, isFirstLineStyle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
// Create an ellipsis box.
EllipsisBox* ellipsisBox = new EllipsisBox(renderer(), ellipsisStr, this,
ellipsisWidth - (markupBox ? markupBox->logicalWidth() : 0), logicalHeight(),
- y(), !prevRootBox(), isHorizontal(), markupBox);
+ x(), y(), !prevRootBox(), isHorizontal(), markupBox);
if (!gEllipsisBoxMap)
gEllipsisBoxMap = new EllipsisBoxMap();
setHasEllipsisBox(true);
// FIXME: Do we need an RTL version of this?
- if (ltr && (x() + logicalWidth() + ellipsisWidth) <= blockRightEdge) {
- ellipsisBox->setX(x() + logicalWidth());
+ if (ltr && (logicalLeft() + logicalWidth() + ellipsisWidth) <= blockRightEdge) {
+ ellipsisBox->setLogicalLeft(logicalLeft() + logicalWidth());
return logicalWidth() + ellipsisWidth;
}
bool foundBox = false;
float truncatedWidth = 0;
float position = placeEllipsisBox(ltr, blockLeftEdge, blockRightEdge, ellipsisWidth, truncatedWidth, foundBox);
- ellipsisBox->setX(position);
+ ellipsisBox->setLogicalLeft(position);
return truncatedWidth;
}
return result;
}
-void RootInlineBox::paintEllipsisBox(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom) const
-{
- if (hasEllipsisBox() && paintInfo.shouldPaintWithinRoot(renderer()) && renderer()->style()->visibility() == VISIBLE
- && paintInfo.phase == PaintPhaseForeground)
- ellipsisBox()->paint(paintInfo, paintOffset, lineTop, lineBottom);
-}
-
void RootInlineBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
{
- InlineFlowBox::paint(paintInfo, paintOffset, lineTop, lineBottom);
- paintEllipsisBox(paintInfo, paintOffset, lineTop, lineBottom);
+ RootInlineBoxPainter(*this).paint(paintInfo, paintOffset, lineTop, lineBottom);
}
bool RootInlineBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
{
if (hasEllipsisBox() && visibleToHitTestRequest(request)) {
if (ellipsisBox()->nodeAtPoint(request, result, locationInContainer, accumulatedOffset, lineTop, lineBottom)) {
- renderer()->updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
+ renderer().updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
return true;
}
}
m_lineBottom += blockDirectionDelta;
m_lineTopWithLeading += blockDirectionDelta;
m_lineBottomWithLeading += blockDirectionDelta;
+ m_selectionBottom += blockDirectionDelta;
if (hasEllipsisBox())
ellipsisBox()->adjustPosition(dx, dy);
}
void RootInlineBox::childRemoved(InlineBox* box)
{
- if (box->renderer() == m_lineBreakObj)
+ if (&box->renderer() == m_lineBreakObj)
setLineBreakInfo(0, 0, BidiStatus());
- for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == box->renderer(); prev = prev->prevRootBox()) {
+ for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == &box->renderer(); prev = prev->prevRootBox()) {
prev->setLineBreakInfo(0, 0, BidiStatus());
prev->markDirty();
}
}
-RenderRegion* RootInlineBox::containingRegion() const
-{
- RenderRegion* region = m_fragmentationData ? m_fragmentationData->m_containingRegion : 0;
-
-#ifndef NDEBUG
- if (region) {
- RenderFlowThread* flowThread = block()->flowThreadContainingBlock();
- const RenderRegionList& regionList = flowThread->renderRegionList();
- ASSERT(regionList.contains(region));
- }
-#endif
-
- return region;
-}
-
-void RootInlineBox::setContainingRegion(RenderRegion* region)
-{
- ASSERT(!isDirty());
- ASSERT(block()->flowThreadContainingBlock());
- LineFragmentationData* fragmentationData = ensureLineFragmentationData();
- fragmentationData->m_containingRegion = region;
-}
-
LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache)
{
// SVG will handle vertical alignment on its own.
bool setMaxDescent = false;
// Figure out if we're in no-quirks mode.
- bool noQuirksMode = renderer()->document().inNoQuirksMode();
+ bool noQuirksMode = renderer().document().inNoQuirksMode();
m_baselineType = requiresIdeographicBaseline(textBoxDataMap) ? IdeographicBaseline : AlphabeticBaseline;
computeLogicalBoxHeights(this, maxPositionTop, maxPositionBottom, maxAscent, maxDescent, setMaxAscent, setMaxDescent, noQuirksMode,
textBoxDataMap, baselineType(), verticalPositionCache);
- if (maxAscent + maxDescent < max(maxPositionTop, maxPositionBottom))
+ if (maxAscent + maxDescent < std::max(maxPositionTop, maxPositionBottom))
adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPositionBottom);
LayoutUnit maxHeight = maxAscent + maxDescent;
LayoutUnit lineBottom = heightOfBlock;
LayoutUnit lineTopIncludingMargins = heightOfBlock;
LayoutUnit lineBottomIncludingMargins = heightOfBlock;
+ LayoutUnit selectionBottom = heightOfBlock;
bool setLineTop = false;
bool hasAnnotationsBefore = false;
bool hasAnnotationsAfter = false;
- placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode, lineTop, lineBottom, setLineTop,
+ placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode, lineTop, lineBottom, selectionBottom, setLineTop,
lineTopIncludingMargins, lineBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType());
m_hasAnnotationsBefore = hasAnnotationsBefore;
m_hasAnnotationsAfter = hasAnnotationsAfter;
- maxHeight = max<LayoutUnit>(0, maxHeight); // FIXME: Is this really necessary?
+ maxHeight = std::max<LayoutUnit>(0, maxHeight); // FIXME: Is this really necessary?
- setLineTopBottomPositions(lineTop, lineBottom, heightOfBlock, heightOfBlock + maxHeight);
- setPaginatedLineWidth(block()->availableLogicalWidthForContent(heightOfBlock));
+ setLineTopBottomPositions(lineTop, lineBottom, heightOfBlock, heightOfBlock + maxHeight, selectionBottom);
+ if (block().view()->layoutState()->isPaginated())
+ setPaginatedLineWidth(block().availableLogicalWidthForContent());
LayoutUnit annotationsAdjustment = beforeAnnotationsAdjustment();
if (annotationsAdjustment) {
// FIXME: Need to handle pagination here. We might have to move to the next page/column as a result of the
// ruby expansion.
- adjustBlockDirectionPosition(annotationsAdjustment);
+ adjustBlockDirectionPosition(annotationsAdjustment.toFloat());
heightOfBlock += annotationsAdjustment;
}
- LayoutUnit gridSnapAdjustment = lineSnapAdjustment();
- if (gridSnapAdjustment) {
- adjustBlockDirectionPosition(gridSnapAdjustment);
- heightOfBlock += gridSnapAdjustment;
- }
-
return heightOfBlock + maxHeight;
}
{
LayoutUnit result = 0;
- if (!renderer()->style()->isFlippedLinesWritingMode()) {
+ if (!renderer().style()->isFlippedLinesWritingMode()) {
// Annotations under the previous line may push us down.
if (prevRootBox() && prevRootBox()->hasAnnotationsAfter())
result = prevRootBox()->computeUnderAnnotationAdjustment(lineTop());
return result;
// Annotations over this line may push us further down.
- LayoutUnit highestAllowedPosition = prevRootBox() ? min(prevRootBox()->lineBottom(), lineTop()) + result : static_cast<LayoutUnit>(block()->borderBefore());
+ LayoutUnit highestAllowedPosition = prevRootBox() ? std::min(prevRootBox()->lineBottom(), lineTop()) + result : static_cast<LayoutUnit>(block().borderBefore());
result = computeOverAnnotationAdjustment(highestAllowedPosition);
} else {
// Annotations under this line may push us up.
if (hasAnnotationsBefore())
- result = computeUnderAnnotationAdjustment(prevRootBox() ? prevRootBox()->lineBottom() : static_cast<LayoutUnit>(block()->borderBefore()));
+ result = computeUnderAnnotationAdjustment(prevRootBox() ? prevRootBox()->lineBottom() : static_cast<LayoutUnit>(block().borderBefore()));
if (!prevRootBox() || !prevRootBox()->hasAnnotationsAfter())
return result;
// We have to compute the expansion for annotations over the previous line to see how much we should move.
- LayoutUnit lowestAllowedPosition = max(prevRootBox()->lineBottom(), lineTop()) - result;
+ LayoutUnit lowestAllowedPosition = std::max(prevRootBox()->lineBottom(), lineTop()) - result;
result = prevRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
}
return result;
}
-LayoutUnit RootInlineBox::lineSnapAdjustment(LayoutUnit delta) const
-{
- // If our block doesn't have snapping turned on, do nothing.
- // FIXME: Implement bounds snapping.
- if (block()->style()->lineSnap() == LineSnapNone)
- return 0;
-
- // Get the current line grid and offset.
- LayoutState* layoutState = block()->view()->layoutState();
- RenderBlock* lineGrid = layoutState->lineGrid();
- LayoutSize lineGridOffset = layoutState->lineGridOffset();
- if (!lineGrid || lineGrid->style()->writingMode() != block()->style()->writingMode())
- return 0;
-
- // Get the hypothetical line box used to establish the grid.
- RootInlineBox* lineGridBox = lineGrid->lineGridBox();
- if (!lineGridBox)
- return 0;
-
- LayoutUnit lineGridBlockOffset = lineGrid->isHorizontalWritingMode() ? lineGridOffset.height() : lineGridOffset.width();
- LayoutUnit blockOffset = block()->isHorizontalWritingMode() ? layoutState->layoutOffset().height() : layoutState->layoutOffset().width();
-
- // Now determine our position on the grid. Our baseline needs to be adjusted to the nearest baseline multiple
- // as established by the line box.
- // FIXME: Need to handle crazy line-box-contain values that cause the root line box to not be considered. I assume
- // the grid should honor line-box-contain.
- LayoutUnit gridLineHeight = lineGridBox->lineBottomWithLeading() - lineGridBox->lineTopWithLeading();
- if (!gridLineHeight)
- return 0;
-
- LayoutUnit lineGridFontAscent = lineGrid->style()->fontMetrics().ascent(baselineType());
- LayoutUnit lineGridFontHeight = lineGridBox->logicalHeight();
- LayoutUnit firstTextTop = lineGridBlockOffset + lineGridBox->logicalTop();
- LayoutUnit firstLineTopWithLeading = lineGridBlockOffset + lineGridBox->lineTopWithLeading();
- LayoutUnit firstBaselinePosition = firstTextTop + lineGridFontAscent;
-
- LayoutUnit currentTextTop = blockOffset + logicalTop() + delta;
- LayoutUnit currentFontAscent = block()->style()->fontMetrics().ascent(baselineType());
- LayoutUnit currentBaselinePosition = currentTextTop + currentFontAscent;
-
- LayoutUnit lineGridPaginationOrigin = isHorizontal() ? layoutState->lineGridPaginationOrigin().height() : layoutState->lineGridPaginationOrigin().width();
-
- // If we're paginated, see if we're on a page after the first one. If so, the grid resets on subsequent pages.
- // FIXME: If the grid is an ancestor of the pagination establisher, then this is incorrect.
- LayoutUnit pageLogicalTop = 0;
- if (layoutState->isPaginated() && layoutState->pageLogicalHeight()) {
- pageLogicalTop = block()->pageLogicalTopForOffset(lineTopWithLeading() + delta);
- if (pageLogicalTop > firstLineTopWithLeading)
- firstTextTop = pageLogicalTop + lineGridBox->logicalTop() - lineGrid->borderBefore() - lineGrid->paddingBefore() + lineGridPaginationOrigin;
- }
-
- if (block()->style()->lineSnap() == LineSnapContain) {
- // Compute the desired offset from the text-top of a grid line.
- // Look at our height (logicalHeight()).
- // Look at the total available height. It's going to be (textBottom - textTop) + (n-1)*(multiple with leading)
- // where n is number of grid lines required to enclose us.
- if (logicalHeight() <= lineGridFontHeight)
- firstTextTop += (lineGridFontHeight - logicalHeight()) / 2;
- else {
- LayoutUnit numberOfLinesWithLeading = ceilf(static_cast<float>(logicalHeight() - lineGridFontHeight) / gridLineHeight);
- LayoutUnit totalHeight = lineGridFontHeight + numberOfLinesWithLeading * gridLineHeight;
- firstTextTop += (totalHeight - logicalHeight()) / 2;
- }
- firstBaselinePosition = firstTextTop + currentFontAscent;
- } else
- firstBaselinePosition = firstTextTop + lineGridFontAscent;
-
- // If we're above the first line, just push to the first line.
- if (currentBaselinePosition < firstBaselinePosition)
- return delta + firstBaselinePosition - currentBaselinePosition;
-
- // Otherwise we're in the middle of the grid somewhere. Just push to the next line.
- LayoutUnit baselineOffset = currentBaselinePosition - firstBaselinePosition;
- LayoutUnit remainder = roundToInt(baselineOffset) % roundToInt(gridLineHeight);
- LayoutUnit result = delta;
- if (remainder)
- result += gridLineHeight - remainder;
-
- // If we aren't paginated we can return the result.
- if (!layoutState->isPaginated() || !layoutState->pageLogicalHeight() || result == delta)
- return result;
-
- // We may end up shifted to a new page. We need to do a re-snap when that happens.
- LayoutUnit newPageLogicalTop = block()->pageLogicalTopForOffset(lineBottomWithLeading() + result);
- if (newPageLogicalTop == pageLogicalTop)
- return result;
-
- // Put ourselves at the top of the next page to force a snap onto the new grid established by that page.
- return lineSnapAdjustment(newPageLogicalTop - (blockOffset + lineTopWithLeading()));
-}
-
-GapRects RootInlineBox::lineSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
- LayoutUnit selTop, LayoutUnit selHeight, const PaintInfo* paintInfo)
+GapRects RootInlineBox::lineSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
+ LayoutUnit selTop, LayoutUnit selHeight, const PaintInfo* paintInfo) const
{
RenderObject::SelectionState lineState = selectionState();
bool leftGap, rightGap;
- block()->getSelectionGapInfo(lineState, leftGap, rightGap);
+ block().getSelectionGapInfo(lineState, leftGap, rightGap);
GapRects result;
InlineBox* firstBox = firstSelectedBox();
InlineBox* lastBox = lastSelectedBox();
- if (leftGap)
- result.uniteLeft(block()->logicalLeftSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
- firstBox->parent()->renderer(), firstBox->logicalLeft(), selTop, selHeight, paintInfo));
- if (rightGap)
- result.uniteRight(block()->logicalRightSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
- lastBox->parent()->renderer(), lastBox->logicalRight(), selTop, selHeight, paintInfo));
+ if (leftGap) {
+ result.uniteLeft(block().logicalLeftSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
+ &firstBox->parent()->renderer(), firstBox->logicalLeft(), selTop, selHeight, paintInfo));
+ }
+ if (rightGap) {
+ result.uniteRight(block().logicalRightSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
+ &lastBox->parent()->renderer(), lastBox->logicalRight(), selTop, selHeight, paintInfo));
+ }
// When dealing with bidi text, a non-contiguous selection region is possible.
// e.g. The logical text aaaAAAbbb (capitals denote RTL text and non-capitals LTR) is layed out
for (InlineBox* box = firstBox->nextLeafChild(); box; box = box->nextLeafChild()) {
if (box->selectionState() != RenderObject::SelectionNone) {
LayoutRect logicalRect(lastLogicalLeft, selTop, box->logicalLeft() - lastLogicalLeft, selHeight);
- logicalRect.move(renderer()->isHorizontalWritingMode() ? offsetFromRootBlock : LayoutSize(offsetFromRootBlock.height(), offsetFromRootBlock.width()));
+ logicalRect.move(renderer().isHorizontalWritingMode() ? offsetFromRootBlock : LayoutSize(offsetFromRootBlock.height(), offsetFromRootBlock.width()));
LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect);
if (isPreviousBoxSelected && gapRect.width() > 0 && gapRect.height() > 0) {
- if (paintInfo && box->parent()->renderer()->style()->visibility() == VISIBLE)
- paintInfo->context->fillRect(gapRect, box->parent()->renderer()->selectionBackgroundColor());
+ if (paintInfo && box->parent()->renderer().style()->visibility() == VISIBLE)
+ paintInfo->context->fillRect(gapRect, box->parent()->renderer().selectionBackgroundColor());
// VisibleSelection may be non-contiguous, see comment above.
result.uniteCenter(gapRect);
}
return result;
}
-RenderObject::SelectionState RootInlineBox::selectionState()
+RenderObject::SelectionState RootInlineBox::selectionState() const
{
// Walk over all of the selected boxes.
RenderObject::SelectionState state = RenderObject::SelectionNone;
return state;
}
-InlineBox* RootInlineBox::firstSelectedBox()
+InlineBox* RootInlineBox::firstSelectedBox() const
{
for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
if (box->selectionState() != RenderObject::SelectionNone)
return 0;
}
-InlineBox* RootInlineBox::lastSelectedBox()
+InlineBox* RootInlineBox::lastSelectedBox() const
{
for (InlineBox* box = lastLeafChild(); box; box = box->prevLeafChild()) {
if (box->selectionState() != RenderObject::SelectionNone)
LayoutUnit selectionTop = m_lineTop;
if (m_hasAnnotationsBefore)
- selectionTop -= !renderer()->style()->isFlippedLinesWritingMode() ? computeOverAnnotationAdjustment(m_lineTop) : computeUnderAnnotationAdjustment(m_lineTop);
+ selectionTop -= !renderer().style()->isFlippedLinesWritingMode() ? computeOverAnnotationAdjustment(m_lineTop) : computeUnderAnnotationAdjustment(m_lineTop);
- if (renderer()->style()->isFlippedLinesWritingMode())
+ if (renderer().style()->isFlippedLinesWritingMode() || !prevRootBox())
return selectionTop;
- LayoutUnit prevBottom = prevRootBox() ? prevRootBox()->selectionBottom() : block()->borderBefore() + block()->paddingBefore();
- if (prevBottom < selectionTop && block()->containsFloats()) {
+ LayoutUnit prevBottom = prevRootBox()->selectionBottom();
+ if (prevBottom < selectionTop && block().containsFloats()) {
// This line has actually been moved further down, probably from a large line-height, but possibly because the
// line was forced to clear floats. If so, let's check the offsets, and only be willing to use the previous
// line's bottom if the offsets are greater on both sides.
- LayoutUnit prevLeft = block()->logicalLeftOffsetForLine(prevBottom, false);
- LayoutUnit prevRight = block()->logicalRightOffsetForLine(prevBottom, false);
- LayoutUnit newLeft = block()->logicalLeftOffsetForLine(selectionTop, false);
- LayoutUnit newRight = block()->logicalRightOffsetForLine(selectionTop, false);
+ LayoutUnit prevLeft = block().logicalLeftOffsetForLine(prevBottom, false);
+ LayoutUnit prevRight = block().logicalRightOffsetForLine(prevBottom, false);
+ LayoutUnit newLeft = block().logicalLeftOffsetForLine(selectionTop, false);
+ LayoutUnit newRight = block().logicalRightOffsetForLine(selectionTop, false);
if (prevLeft > newLeft || prevRight < newRight)
return selectionTop;
}
{
LayoutUnit top = selectionTop();
- RenderObject::SelectionState blockSelectionState = root()->block()->selectionState();
+ RenderObject::SelectionState blockSelectionState = root().block().selectionState();
if (blockSelectionState != RenderObject::SelectionInside && blockSelectionState != RenderObject::SelectionEnd)
return top;
LayoutSize offsetToBlockBefore;
- if (RenderBlock* block = root()->block()->blockBeforeWithinSelectionRoot(offsetToBlockBefore)) {
- if (RootInlineBox* lastLine = block->lastRootBox()) {
- RenderObject::SelectionState lastLineSelectionState = lastLine->selectionState();
- if (lastLineSelectionState != RenderObject::SelectionInside && lastLineSelectionState != RenderObject::SelectionStart)
- return top;
-
- LayoutUnit lastLineSelectionBottom = lastLine->selectionBottom() + offsetToBlockBefore.height();
- top = max(top, lastLineSelectionBottom);
+ if (RenderBlock* block = root().block().blockBeforeWithinSelectionRoot(offsetToBlockBefore)) {
+ if (block->isRenderBlockFlow()) {
+ if (RootInlineBox* lastLine = toRenderBlockFlow(block)->lastRootBox()) {
+ RenderObject::SelectionState lastLineSelectionState = lastLine->selectionState();
+ if (lastLineSelectionState != RenderObject::SelectionInside && lastLineSelectionState != RenderObject::SelectionStart)
+ return top;
+
+ LayoutUnit lastLineSelectionBottom = lastLine->selectionBottom() + offsetToBlockBefore.height();
+ top = std::max(top, lastLineSelectionBottom);
+ }
}
}
LayoutUnit RootInlineBox::selectionBottom() const
{
- LayoutUnit selectionBottom = m_lineBottom;
+ LayoutUnit selectionBottom = m_selectionBottom;
if (m_hasAnnotationsAfter)
- selectionBottom += !renderer()->style()->isFlippedLinesWritingMode() ? computeUnderAnnotationAdjustment(m_lineBottom) : computeOverAnnotationAdjustment(m_lineBottom);
+ selectionBottom += !renderer().style()->isFlippedLinesWritingMode() ? computeUnderAnnotationAdjustment(m_lineBottom) : computeOverAnnotationAdjustment(m_lineBottom);
- if (!renderer()->style()->isFlippedLinesWritingMode() || !nextRootBox())
+ if (!renderer().style()->isFlippedLinesWritingMode() || !nextRootBox())
return selectionBottom;
LayoutUnit nextTop = nextRootBox()->selectionTop();
- if (nextTop > selectionBottom && block()->containsFloats()) {
+ if (nextTop > selectionBottom && block().containsFloats()) {
// The next line has actually been moved further over, probably from a large line-height, but possibly because the
// line was forced to clear floats. If so, let's check the offsets, and only be willing to use the next
// line's top if the offsets are greater on both sides.
- LayoutUnit nextLeft = block()->logicalLeftOffsetForLine(nextTop, false);
- LayoutUnit nextRight = block()->logicalRightOffsetForLine(nextTop, false);
- LayoutUnit newLeft = block()->logicalLeftOffsetForLine(selectionBottom, false);
- LayoutUnit newRight = block()->logicalRightOffsetForLine(selectionBottom, false);
+ LayoutUnit nextLeft = block().logicalLeftOffsetForLine(nextTop, false);
+ LayoutUnit nextRight = block().logicalRightOffsetForLine(nextTop, false);
+ LayoutUnit newLeft = block().logicalLeftOffsetForLine(selectionBottom, false);
+ LayoutUnit newRight = block().logicalRightOffsetForLine(selectionBottom, false);
if (nextLeft > newLeft || nextRight < newRight)
return selectionBottom;
}
int RootInlineBox::blockDirectionPointInLine() const
{
- return !block()->style()->isFlippedBlocksWritingMode() ? max(lineTop(), selectionTop()) : min(lineBottom(), selectionBottom());
+ return !block().style()->slowIsFlippedBlocksWritingMode() ? std::max(lineTop(), selectionTop()) : std::min(lineBottom(), selectionBottom());
}
-RenderBlock* RootInlineBox::block() const
+RenderBlockFlow& RootInlineBox::block() const
{
- return toRenderBlock(renderer());
+ return toRenderBlockFlow(renderer());
}
static bool isEditableLeaf(InlineBox* leaf)
{
- return leaf && leaf->renderer() && leaf->renderer()->node() && leaf->renderer()->node()->rendererIsEditable();
+ return leaf && leaf->renderer().node() && leaf->renderer().node()->hasEditableStyle();
}
InlineBox* RootInlineBox::closestLeafChildForPoint(const IntPoint& pointInContents, bool onlyEditableLeaves)
{
- return closestLeafChildForLogicalLeftPosition(block()->isHorizontalWritingMode() ? pointInContents.x() : pointInContents.y(), onlyEditableLeaves);
+ return closestLeafChildForLogicalLeftPosition(block().isHorizontalWritingMode() ? pointInContents.x() : pointInContents.y(), onlyEditableLeaves);
}
InlineBox* RootInlineBox::closestLeafChildForLogicalLeftPosition(int leftPosition, bool onlyEditableLeaves)
return firstLeaf;
// Avoid returning a list marker when possible.
- if (leftPosition <= firstLeaf->logicalLeft() && !firstLeaf->renderer()->isListMarker() && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
+ if (leftPosition <= firstLeaf->logicalLeft() && !firstLeaf->renderer().isListMarker() && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
// The leftPosition coordinate is less or equal to left edge of the firstLeaf.
// Return it.
return firstLeaf;
- if (leftPosition >= lastLeaf->logicalRight() && !lastLeaf->renderer()->isListMarker() && (!onlyEditableLeaves || isEditableLeaf(lastLeaf)))
+ if (leftPosition >= lastLeaf->logicalRight() && !lastLeaf->renderer().isListMarker() && (!onlyEditableLeaves || isEditableLeaf(lastLeaf)))
// The leftPosition coordinate is greater or equal to right edge of the lastLeaf.
// Return it.
return lastLeaf;
InlineBox* closestLeaf = 0;
for (InlineBox* leaf = firstLeaf; leaf; leaf = leaf->nextLeafChildIgnoringLineBreak()) {
- if (!leaf->renderer()->isListMarker() && (!onlyEditableLeaves || isEditableLeaf(leaf))) {
+ if (!leaf->renderer().isListMarker() && (!onlyEditableLeaves || isEditableLeaf(leaf))) {
closestLeaf = leaf;
if (leftPosition < leaf->logicalRight())
// The x coordinate is less than the right edge of the box.
void RootInlineBox::setLineBreakInfo(RenderObject* obj, unsigned breakPos, const BidiStatus& status)
{
+ // When setting lineBreakObj, the RenderObject must not be a RenderInline
+ // with no line boxes, otherwise all sorts of invariants are broken later.
+ // This has security implications because if the RenderObject does not
+ // point to at least one line box, then that RenderInline can be deleted
+ // later without resetting the lineBreakObj, leading to use-after-free.
+ ASSERT_WITH_SECURITY_IMPLICATION(!obj || obj->isText() || !(obj->isRenderInline() && obj->isBox() && !toRenderBox(obj)->inlineBoxWrapper()));
+
m_lineBreakObj = obj;
m_lineBreakPos = breakPos;
m_lineBreakBidiStatusEor = status.eor;
void RootInlineBox::removeLineBoxFromRenderObject()
{
- block()->lineBoxes()->removeLineBox(this);
+ block().lineBoxes()->removeLineBox(this);
}
void RootInlineBox::extractLineBoxFromRenderObject()
{
- block()->lineBoxes()->extractLineBox(this);
+ block().lineBoxes()->extractLineBox(this);
}
void RootInlineBox::attachLineBoxToRenderObject()
{
- block()->lineBoxes()->attachLineBox(this);
+ block().lineBoxes()->attachLineBox(this);
}
LayoutRect RootInlineBox::paddedLayoutOverflowRect(LayoutUnit endPadding) const
if (!endPadding)
return lineLayoutOverflow;
- // FIXME: Audit whether to use pixel snapped values when not using integers for layout: https://bugs.webkit.org/show_bug.cgi?id=63656
if (isHorizontal()) {
if (isLeftToRightDirection())
- lineLayoutOverflow.shiftMaxXEdgeTo(max<LayoutUnit>(lineLayoutOverflow.maxX(), pixelSnappedLogicalRight() + endPadding));
+ lineLayoutOverflow.shiftMaxXEdgeTo(std::max<LayoutUnit>(lineLayoutOverflow.maxX(), logicalRight() + endPadding));
else
- lineLayoutOverflow.shiftXEdgeTo(min<LayoutUnit>(lineLayoutOverflow.x(), pixelSnappedLogicalLeft() - endPadding));
+ lineLayoutOverflow.shiftXEdgeTo(std::min<LayoutUnit>(lineLayoutOverflow.x(), logicalLeft() - endPadding));
} else {
if (isLeftToRightDirection())
- lineLayoutOverflow.shiftMaxYEdgeTo(max<LayoutUnit>(lineLayoutOverflow.maxY(), pixelSnappedLogicalRight() + endPadding));
+ lineLayoutOverflow.shiftMaxYEdgeTo(std::max<LayoutUnit>(lineLayoutOverflow.maxY(), logicalRight() + endPadding));
else
- lineLayoutOverflow.shiftYEdgeTo(min<LayoutUnit>(lineLayoutOverflow.y(), pixelSnappedLogicalLeft() - endPadding));
+ lineLayoutOverflow.shiftYEdgeTo(std::min<LayoutUnit>(lineLayoutOverflow.y(), logicalLeft() - endPadding));
}
return lineLayoutOverflow;
ascent = newAscent;
descent = newDescent;
} else {
- ascent = max(ascent, newAscent);
- descent = max(descent, newDescent);
+ ascent = std::max(ascent, newAscent);
+ descent = std::max(descent, newDescent);
}
}
// Replaced boxes will return 0 for the line-height if line-box-contain says they are
// not to be included.
- if (box->renderer()->isReplaced()) {
- if (renderer()->style(isFirstLineStyle())->lineBoxContain() & LineBoxContainReplaced) {
+ if (box->renderer().isReplaced()) {
+ if (renderer().style(isFirstLineStyle())->lineBoxContain() & LineBoxContainReplaced) {
ascent = box->baselinePosition(baselineType());
descent = box->lineHeight() - ascent;
bool setUsedFont = false;
bool setUsedFontWithLeading = false;
- if (usedFonts && !usedFonts->isEmpty() && (includeFont || (box->renderer()->style(isFirstLineStyle())->lineHeight().isNegative() && includeLeading))) {
- usedFonts->append(box->renderer()->style(isFirstLineStyle())->font().primaryFont());
+ if (usedFonts && !usedFonts->isEmpty() && (includeFont || (box->renderer().style(isFirstLineStyle())->lineHeight().isNegative() && includeLeading))) {
+ usedFonts->append(box->renderer().style(isFirstLineStyle())->font().primaryFont());
for (size_t i = 0; i < usedFonts->size(); ++i) {
const FontMetrics& fontMetrics = usedFonts->at(i)->fontMetrics();
int usedFontAscent = fontMetrics.ascent(baselineType());
}
if (includeFontForBox(box) && !setUsedFont) {
- int fontAscent = box->renderer()->style(isFirstLineStyle())->fontMetrics().ascent(baselineType());
- int fontDescent = box->renderer()->style(isFirstLineStyle())->fontMetrics().descent(baselineType());
+ int fontAscent = box->renderer().style(isFirstLineStyle())->fontMetrics().ascent(baselineType());
+ int fontDescent = box->renderer().style(isFirstLineStyle())->fontMetrics().descent(baselineType());
setAscentAndDescent(ascent, descent, fontAscent, fontDescent, ascentDescentSet);
affectsAscent = fontAscent - box->logicalTop() > 0;
affectsDescent = fontDescent + box->logicalTop() > 0;
setAscentAndDescent(ascent, descent, glyphOverflow->top, glyphOverflow->bottom, ascentDescentSet);
affectsAscent = glyphOverflow->top - box->logicalTop() > 0;
affectsDescent = glyphOverflow->bottom + box->logicalTop() > 0;
- glyphOverflow->top = min(glyphOverflow->top, max(0, glyphOverflow->top - box->renderer()->style(isFirstLineStyle())->fontMetrics().ascent(baselineType())));
- glyphOverflow->bottom = min(glyphOverflow->bottom, max(0, glyphOverflow->bottom - box->renderer()->style(isFirstLineStyle())->fontMetrics().descent(baselineType())));
+ glyphOverflow->top = std::min(glyphOverflow->top, std::max(0, glyphOverflow->top - box->renderer().style(isFirstLineStyle())->fontMetrics().ascent(baselineType())));
+ glyphOverflow->bottom = std::min(glyphOverflow->bottom, std::max(0, glyphOverflow->bottom - box->renderer().style(isFirstLineStyle())->fontMetrics().descent(baselineType())));
}
if (includeMarginForBox(box)) {
- LayoutUnit ascentWithMargin = box->renderer()->style(isFirstLineStyle())->fontMetrics().ascent(baselineType());
- LayoutUnit descentWithMargin = box->renderer()->style(isFirstLineStyle())->fontMetrics().descent(baselineType());
- if (box->parent() && !box->renderer()->isText()) {
+ LayoutUnit ascentWithMargin = box->renderer().style(isFirstLineStyle())->fontMetrics().ascent(baselineType());
+ LayoutUnit descentWithMargin = box->renderer().style(isFirstLineStyle())->fontMetrics().descent(baselineType());
+ if (box->parent() && !box->renderer().isText()) {
ascentWithMargin += box->boxModelObject()->borderBefore() + box->boxModelObject()->paddingBefore() + box->boxModelObject()->marginBefore();
descentWithMargin += box->boxModelObject()->borderAfter() + box->boxModelObject()->paddingAfter() + box->boxModelObject()->marginAfter();
}
LayoutUnit RootInlineBox::verticalPositionForBox(InlineBox* box, VerticalPositionCache& verticalPositionCache)
{
- if (box->renderer()->isText())
+ if (box->renderer().isText())
return box->parent()->logicalTop();
RenderBoxModelObject* renderer = box->boxModelObject();
if (verticalAlign != BASELINE) {
const Font& font = parent->style(firstLine)->font();
const FontMetrics& fontMetrics = font.fontMetrics();
- int fontSize = font.pixelSize();
+ int fontSize = font.fontDescription().computedPixelSize();
LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? HorizontalLine : VerticalLine;
lineHeight = renderer->style()->computedLineHeight();
else
lineHeight = renderer->lineHeight(firstLine, lineDirection);
- verticalPosition -= valueForLength(renderer->style()->verticalAlignLength(), lineHeight, renderer->view());
+ verticalPosition -= valueForLength(renderer->style()->verticalAlignLength(), lineHeight);
}
}
bool RootInlineBox::includeLeadingForBox(InlineBox* box) const
{
- if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
+ if (box->renderer().isReplaced() || (box->renderer().isText() && !box->isText()))
return false;
- LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
+ LineBoxContain lineBoxContain = renderer().style()->lineBoxContain();
return (lineBoxContain & LineBoxContainInline) || (box == this && (lineBoxContain & LineBoxContainBlock));
}
bool RootInlineBox::includeFontForBox(InlineBox* box) const
{
- if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
+ if (box->renderer().isReplaced() || (box->renderer().isText() && !box->isText()))
return false;
if (!box->isText() && box->isInlineFlowBox() && !toInlineFlowBox(box)->hasTextChildren())
return false;
// For now map "glyphs" to "font" in vertical text mode until the bounds returned by glyphs aren't garbage.
- LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
+ LineBoxContain lineBoxContain = renderer().style()->lineBoxContain();
return (lineBoxContain & LineBoxContainFont) || (!isHorizontal() && (lineBoxContain & LineBoxContainGlyphs));
}
bool RootInlineBox::includeGlyphsForBox(InlineBox* box) const
{
- if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
+ if (box->renderer().isReplaced() || (box->renderer().isText() && !box->isText()))
return false;
if (!box->isText() && box->isInlineFlowBox() && !toInlineFlowBox(box)->hasTextChildren())
return false;
// FIXME: We can't fit to glyphs yet for vertical text, since the bounds returned are garbage.
- LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
+ LineBoxContain lineBoxContain = renderer().style()->lineBoxContain();
return isHorizontal() && (lineBoxContain & LineBoxContainGlyphs);
}
bool RootInlineBox::includeMarginForBox(InlineBox* box) const
{
- if (box->renderer()->isReplaced() || (box->renderer()->isText() && !box->isText()))
+ if (box->renderer().isReplaced() || (box->renderer().isText() && !box->isText()))
return false;
- LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
+ LineBoxContain lineBoxContain = renderer().style()->lineBoxContain();
return lineBoxContain & LineBoxContainInlineBox;
}
bool RootInlineBox::fitsToGlyphs() const
{
// FIXME: We can't fit to glyphs yet for vertical text, since the bounds returned are garbage.
- LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
+ LineBoxContain lineBoxContain = renderer().style()->lineBoxContain();
return isHorizontal() && (lineBoxContain & LineBoxContainGlyphs);
}
bool RootInlineBox::includesRootLineBoxFontOrLeading() const
{
- LineBoxContain lineBoxContain = renderer()->style()->lineBoxContain();
+ LineBoxContain lineBoxContain = renderer().style()->lineBoxContain();
return (lineBoxContain & LineBoxContainBlock) || (lineBoxContain & LineBoxContainInline) || (lineBoxContain & LineBoxContainFont);
}
Vector<InlineBox*> leafBoxesInLogicalOrder;
collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder);
for (size_t i = 0; i < leafBoxesInLogicalOrder.size(); ++i) {
- if (leafBoxesInLogicalOrder[i]->renderer()->node()) {
+ if (leafBoxesInLogicalOrder[i]->renderer().nonPseudoNode()) {
startBox = leafBoxesInLogicalOrder[i];
- return startBox->renderer()->node();
+ return startBox->renderer().nonPseudoNode();
}
}
startBox = 0;
Vector<InlineBox*> leafBoxesInLogicalOrder;
collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder);
for (size_t i = leafBoxesInLogicalOrder.size(); i > 0; --i) {
- if (leafBoxesInLogicalOrder[i - 1]->renderer()->node()) {
+ if (leafBoxesInLogicalOrder[i - 1]->renderer().nonPseudoNode()) {
endBox = leafBoxesInLogicalOrder[i - 1];
- return endBox->renderer()->node();
+ return endBox->renderer().nonPseudoNode();
}
}
endBox = 0;
}
#endif
-} // namespace WebCore
+} // namespace blink