📄 render_flow.cpp
字号:
// dirty the adjacent lines that might be affected
// NOTE: we dirty the previous line because RootInlineBox objects cache
// the address of the first object on the next line after a BR, which we may be
// invalidating here. For more info, see how RenderBlock::layoutInlineChildren
// calls setLineBreakInfo with the result of findNextLineBreak. findNextLineBreak,
// despite the name, actually returns the first RenderObject after the BR.
// <rdar://problem/3849947> "Typing after pasting line does not appear until after window resize."
adjacentBox = box->prevRootBox();
if (adjacentBox)
adjacentBox->markDirty();
if (child->isBR() || (curr && curr->isBR())) {
adjacentBox = box->nextRootBox();
if (adjacentBox)
adjacentBox->markDirty();
}
}
}
short RenderFlow::lineHeight(bool firstLine, bool isRootLineBox) const
{
if (firstLine) {
RenderStyle* s = style(firstLine);
Length lh = s->lineHeight();
#ifdef NOKIA_CHANGES
lh.value = lh.value * 100 / canvas()->view()->scalingFactor();
#endif
if (lh.value < 0) {
if (s == style()) {
if (m_lineHeight == -1)
m_lineHeight = RenderObject::lineHeight(false);
return m_lineHeight;
}
return s->fontMetrics().lineSpacing();
}
if (lh.isPercent())
return lh.minWidth(s->font().pixelSize());
return lh.value;
}
if (m_lineHeight == -1)
m_lineHeight = RenderObject::lineHeight(false);
return m_lineHeight;
}
void RenderFlow::dirtyLineBoxes(bool fullLayout, bool isRootLineBox)
{
if (!isRootLineBox && isReplaced())
return RenderContainer::dirtyLineBoxes(fullLayout, isRootLineBox);
if (fullLayout)
deleteLineBoxes();
else {
for (InlineRunBox* curr = firstLineBox(); curr; curr = curr->nextLineBox())
curr->dirtyLineBoxes();
}
}
InlineBox* RenderFlow::createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun)
{
if (!isRootLineBox &&
(isReplaced() || makePlaceHolderBox)) // Inline tables and inline blocks
return RenderContainer::createInlineBox(false, isRootLineBox); // (or positioned element placeholders).
InlineFlowBox* flowBox = 0;
if (isInlineFlow())
flowBox = new (renderArena()) InlineFlowBox(this);
else
flowBox = new (renderArena()) RootInlineBox(this);
if (!m_firstLineBox)
m_firstLineBox = m_lastLineBox = flowBox;
else {
m_lastLineBox->setNextLineBox(flowBox);
flowBox->setPreviousLineBox(m_lastLineBox);
m_lastLineBox = flowBox;
}
return flowBox;
}
void RenderFlow::paintLines(PaintInfo& i, int _tx, int _ty)
{
// Only paint during the foreground/selection phases.
if (i.phase != PaintActionForeground && i.phase != PaintActionSelection && i.phase != PaintActionOutline)
return;
bool inlineFlow = isInlineFlow();
if (inlineFlow)
KHTMLAssert(m_layer); // The only way a compact/run-in/inline could paint like this is if it has a layer.
// If we have no lines then we have no work to do.
if (!firstLineBox())
return;
// We can check the first box and last box and avoid painting if we don't
// intersect. This is a quick short-circuit that we can take to avoid walking any lines.
// FIXME: This check is flawed in two extremely obscure ways.
// (1) If some line in the middle has a huge overflow, it might actually extend below the last line.
// (2) The overflow from an inline block on a line is not reported to the line.
int yPos = firstLineBox()->root()->selectionTop() - maximalOutlineSize(i.phase);
int h = maximalOutlineSize(i.phase) + lastLineBox()->root()->selectionTop() + lastLineBox()->root()->selectionHeight() - yPos;
yPos += _ty;
if ((yPos >= i.r.y() + i.r.height()) || (yPos + h <= i.r.y()))
return;
// See if our root lines intersect with the dirty rect. If so, then we paint
// them. Note that boxes can easily overlap, so we can't make any assumptions
// based off positions of our first line box or our last line box.
bool isPrinting = (i.p->device()->devType() == QInternal::Printer);
for (InlineFlowBox* curr = firstLineBox(); curr; curr = curr->nextFlowBox()) {
if (isPrinting) {
// FIXME: This is a feeble effort to avoid splitting a line across two pages.
// It is utterly inadequate, and this should not be done at paint time at all.
// The whole way objects break across pages needs to be redone.
RenderCanvas* c = canvas();
// Try to avoid splitting a line vertically, but only if it's less than the height
// of the entire page.
if (curr->root()->bottomOverflow() - curr->root()->topOverflow() <= c->printRect().height()) {
if (_ty + curr->root()->bottomOverflow() > c->printRect().y() + c->printRect().height()) {
if (_ty + curr->root()->topOverflow() < c->truncatedAt())
c->setBestTruncatedAt(_ty + curr->root()->topOverflow(), this);
// If we were able to truncate, don't paint.
if (_ty + curr->root()->topOverflow() >= c->truncatedAt())
break;
}
}
}
int top = kMin(curr->root()->topOverflow(), curr->root()->selectionTop()) - maximalOutlineSize(i.phase);
int bottom = kMax(curr->root()->selectionTop() + curr->root()->selectionHeight(), curr->root()->bottomOverflow()) + maximalOutlineSize(i.phase);
h = bottom - top;
yPos = _ty + top;
if ((yPos < i.r.y() + i.r.height()) && (yPos + h > i.r.y()))
curr->paint(i, _tx, _ty);
}
if (i.phase == PaintActionOutline && i.outlineObjects) {
// FIXME: Will the order in which we added objects to the dictionary be preserved? Probably not.
// This means the paint order of outlines will be wrong, although this is a minor issue.
QPtrDictIterator<RenderFlow> objects(*i.outlineObjects);
for (objects.toFirst(); objects.current(); ++objects) {
#ifdef APPLE_CHANGES
if (objects.current()->style()->outlineStyleIsAuto())
objects.current()->paintFocusRing(i.p, _tx, _ty);
else
#endif
objects.current()->paintOutlines(i.p, _tx, _ty);
}
i.outlineObjects->clear();
}
}
bool RenderFlow::hitTestLines(NodeInfo& i, int x, int y, int tx, int ty, HitTestAction hitTestAction)
{
if (hitTestAction != HitTestForeground)
return false;
bool inlineFlow = isInlineFlow();
if (inlineFlow)
KHTMLAssert(m_layer); // The only way a compact/run-in/inline could paint like this is if it has a layer.
// If we have no lines then we have no work to do.
if (!firstLineBox())
return false;
// We can check the first box and last box and avoid hit testing if we don't
// contain the point. This is a quick short-circuit that we can take to avoid walking any lines.
// FIXME: This check is flawed in two extremely obscure ways.
// (1) If some line in the middle has a huge overflow, it might actually extend below the last line.
// (2) The overflow from an inline block on a line is not reported to the line.
if ((y >= ty + lastLineBox()->root()->bottomOverflow()) || (y < ty + firstLineBox()->root()->topOverflow()))
return false;
// See if our root lines contain the point. If so, then we hit test
// them further. Note that boxes can easily overlap, so we can't make any assumptions
// based off positions of our first line box or our last line box.
for (InlineFlowBox* curr = lastLineBox(); curr; curr = curr->prevFlowBox()) {
if (y >= ty + curr->root()->topOverflow() && y < ty + curr->root()->bottomOverflow()) {
bool inside = curr->nodeAtPoint(i, x, y, tx, ty);
if (inside) {
setInnerNode(i);
return true;
}
}
}
return false;
}
QRect RenderFlow::getAbsoluteRepaintRect()
{
if (isInlineFlow()) {
// Find our leftmost position.
int left = 0;
int top = firstLineBox() ? firstLineBox()->yPos() : 0;
for (InlineRunBox* curr = firstLineBox(); curr; curr = curr->nextLineBox())
if (curr == firstLineBox() || curr->xPos() < left)
left = curr->xPos();
// Now invalidate a rectangle.
int ow = style() ? style()->outlineSize() : 0;
if (isCompact())
left -= m_x;
// We need to add in the relative position offsets of any inlines (including us) up to our
// containing block.
RenderBlock* cb = containingBlock();
for (RenderObject* inlineFlow = this; inlineFlow && inlineFlow->isInlineFlow() && inlineFlow != cb;
inlineFlow = inlineFlow->parent()) {
if (inlineFlow->style()->position() == RELATIVE && inlineFlow->layer())
inlineFlow->layer()->relativePositionOffset(left, top);
}
QRect r(-ow+left, -ow+top, width()+ow*2, height()+ow*2);
if (cb->hasOverflowClip()) {
// cb->height() is inaccurate if we're in the middle of a layout of |cb|, so use the
// layer's size instead. Even if the layer's size is wrong, the layer itself will repaint
// anyway if its size does change.
int x = r.left();
int y = r.top();
QRect boxRect(0, 0, cb->layer()->width(), cb->layer()->height());
cb->layer()->subtractScrollOffset(x,y); // For overflow:auto/scroll/hidden.
QRect repaintRect(x, y, r.width(), r.height());
r = repaintRect.intersect(boxRect);
}
cb->computeAbsoluteRepaintRect(r);
if (ow) {
for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
if (!curr->isText()) {
QRect childRect = curr->getAbsoluteRepaintRectWithOutline(ow);
r = r.unite(childRect);
}
}
if (continuation() && !continuation()->isInline()) {
QRect contRect = continuation()->getAbsoluteRepaintRectWithOutline(ow);
r = r.unite(contRect);
}
}
return r;
}
else {
if (firstLineBox() && firstLineBox()->topOverflow() < 0) {
int ow = style() ? style()->outlineSize() : 0;
QRect r(-ow, -ow+firstLineBox()->topOverflow(),
overflowWidth(false)+ow*2,
overflowHeight(false)+ow*2-firstLineBox()->topOverflow());
computeAbsoluteRepaintRect(r);
return r;
}
}
return RenderContainer::getAbsoluteRepaintRect();
}
int
RenderFlow::lowestPosition(bool includeOverflowInterior, bool includeSelf) const
{
int bottom = RenderContainer::lowestPosition(includeOverflowInterior, includeSelf);
if (!includeOverflowInterior && hasOverflowClip())
return bottom;
// FIXME: Come up with a way to use the layer tree to avoid visiting all the kids.
// For now, we have to descend into all the children, since we may have a huge abs div inside
// a tiny rel div buried somewhere deep in our child tree. In this case we have to get to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -