📄 render_line.cpp
字号:
{
for (InlineBox *box = firstChild(); box; box = box->nextOnLine()) {
if (!box->canAccommodateEllipsis(ltr, blockEdge, ellipsisWidth))
return false;
}
return true;
}
int InlineFlowBox::placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool& foundBox)
{
int result = -1;
for (InlineBox *box = firstChild(); box; box = box->nextOnLine()) {
int currResult = box->placeEllipsisBox(ltr, blockEdge, ellipsisWidth, foundBox);
if (currResult != -1 && result == -1)
result = currResult;
}
return result;
}
void InlineFlowBox::clearTruncation()
{
for (InlineBox *box = firstChild(); box; box = box->nextOnLine())
box->clearTruncation();
}
void EllipsisBox::paint(RenderObject::PaintInfo& i, int _tx, int _ty)
{
QPainter* p = i.p;
RenderStyle* _style = m_firstLine ? m_object->style(true) : m_object->style();
if (_style->font() != p->font())
p->setFont(_style->font());
const Font* font = &_style->htmlFont();
QColor textColor = _style->color();
if (textColor != p->pen().color())
p->setPen(textColor);
bool setShadow = false;
if (_style->textShadow()) {
p->setShadow(_style->textShadow()->x, _style->textShadow()->y,
_style->textShadow()->blur, _style->textShadow()->color);
setShadow = true;
}
const DOMString& str = m_str.string();
font->drawText(p, m_x + _tx,
m_y + _ty + m_baseline,
(str.implementation())->s,
str.length(), 0, str.length(),
0,
QPainter::LTR, _style->visuallyOrdered());
if (setShadow)
p->clearShadow();
if (m_markupBox) {
// Paint the markup box
_tx += m_x + m_width - m_markupBox->xPos();
_ty += m_y + m_baseline - (m_markupBox->yPos() + m_markupBox->baseline());
m_markupBox->paint(i, _tx, _ty);
}
}
bool EllipsisBox::nodeAtPoint(RenderObject::NodeInfo& info, int _x, int _y, int _tx, int _ty)
{
// Hit test the markup box.
if (m_markupBox) {
_tx += m_x + m_width - m_markupBox->xPos();
_ty += m_y + m_baseline - (m_markupBox->yPos() + m_markupBox->baseline());
if (m_markupBox->nodeAtPoint(info, _x, _y, _tx, _ty)) {
object()->setInnerNode(info);
return true;
}
}
QRect rect(_tx + m_x, _ty + m_y, m_width, m_height);
if (object()->style()->visibility() == VISIBLE && rect.contains(_x, _y)) {
object()->setInnerNode(info);
return true;
}
return false;
}
void RootInlineBox::detach(RenderArena* arena)
{
detachEllipsisBox(arena);
InlineFlowBox::detach(arena);
}
void RootInlineBox::detachEllipsisBox(RenderArena* arena)
{
if (m_ellipsisBox) {
m_ellipsisBox->detach(arena);
m_ellipsisBox = 0;
}
}
void RootInlineBox::clearTruncation()
{
if (m_ellipsisBox) {
detachEllipsisBox(m_object->renderArena());
InlineFlowBox::clearTruncation();
}
}
bool RootInlineBox::canAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth)
{
// First sanity-check the unoverflowed width of the whole line to see if there is sufficient room.
int delta = ltr ? lineBoxEdge - blockEdge : blockEdge - lineBoxEdge;
if (width() - delta < ellipsisWidth)
return false;
// Next iterate over all the line boxes on the line. If we find a replaced element that intersects
// then we refuse to accommodate the ellipsis. Otherwise we're ok.
return InlineFlowBox::canAccommodateEllipsis(ltr, blockEdge, ellipsisWidth);
}
void RootInlineBox::placeEllipsis(const AtomicString& ellipsisStr, bool ltr, int blockEdge, int ellipsisWidth,
InlineBox* markupBox)
{
// Create an ellipsis box.
m_ellipsisBox = new (m_object->renderArena()) EllipsisBox(m_object, ellipsisStr, this,
ellipsisWidth - (markupBox ? markupBox->width() : 0),
yPos(), height(), baseline(), !prevRootBox(),
markupBox);
if (ltr && (xPos() + width() + ellipsisWidth) <= blockEdge) {
m_ellipsisBox->m_x = xPos() + width();
return;
}
// Now attempt to find the nearest glyph horizontally and place just to the right (or left in RTL)
// of that glyph. Mark all of the objects that intersect the ellipsis box as not painting (as being
// truncated).
bool foundBox = false;
m_ellipsisBox->m_x = placeEllipsisBox(ltr, blockEdge, ellipsisWidth, foundBox);
}
int RootInlineBox::placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool& foundBox)
{
int result = InlineFlowBox::placeEllipsisBox(ltr, blockEdge, ellipsisWidth, foundBox);
if (result == -1)
result = ltr ? blockEdge - ellipsisWidth : blockEdge;
return result;
}
void RootInlineBox::paintEllipsisBox(RenderObject::PaintInfo& i, int _tx, int _ty) const
{
if (m_ellipsisBox && object()->shouldPaintWithinRoot(i) && object()->style()->visibility() == VISIBLE &&
i.phase == PaintActionForeground)
m_ellipsisBox->paint(i, _tx, _ty);
}
void RootInlineBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
{
InlineFlowBox::paint(i, tx, ty);
paintEllipsisBox(i, tx, ty);
}
bool RootInlineBox::nodeAtPoint(RenderObject::NodeInfo& i, int x, int y, int tx, int ty)
{
if (m_ellipsisBox && object()->style()->visibility() == VISIBLE) {
if (m_ellipsisBox->nodeAtPoint(i, x, y, tx, ty)) {
object()->setInnerNode(i);
return true;
}
}
return InlineFlowBox::nodeAtPoint(i, x, y, tx, ty);
}
void RootInlineBox::adjustPosition(int dx, int dy)
{
InlineFlowBox::adjustPosition(dx, dy);
m_topOverflow += dy;
m_bottomOverflow += dy;
m_blockHeight += dy;
}
void RootInlineBox::childRemoved(InlineBox* box)
{
if (box->object() == m_lineBreakObj)
setLineBreakInfo(0,0);
RootInlineBox* prev = prevRootBox();
if (prev && prev->lineBreakObj() == box->object()) {
prev->setLineBreakInfo(0,0);
prev->markDirty();
}
}
GapRects RootInlineBox::fillLineSelectionGap(int selTop, int selHeight, RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty,
const RenderObject::PaintInfo* i)
{
GapRects result;
RenderObject::SelectionState lineState = selectionState();
bool leftGap, rightGap;
block()->getHorizontalSelectionGapInfo(lineState, leftGap, rightGap);
InlineBox* firstBox = firstSelectedBox();
InlineBox* lastBox = lastSelectedBox();
if (leftGap)
result.uniteLeft(block()->fillLeftSelectionGap(firstBox->parent()->object(),
firstBox->xPos(), selTop, selHeight,
rootBlock, blockX, blockY, tx, ty, i));
if (rightGap)
result.uniteRight(block()->fillRightSelectionGap(lastBox->parent()->object(),
lastBox->xPos() + lastBox->width(), selTop, selHeight,
rootBlock, blockX, blockY, tx, ty, i));
if (firstBox && firstBox != lastBox) {
// Now fill in any gaps on the line that occurred between two selected elements.
int lastX = firstBox->xPos() + firstBox->width();
for (InlineBox* box = firstBox->nextLeafChild(); box; box = box->nextLeafChild()) {
if (box->selectionState() != RenderObject::SelectionNone) {
result.uniteCenter(block()->fillHorizontalSelectionGap(box->parent()->object(),
lastX + tx, selTop + ty,
box->xPos() - lastX, selHeight, i));
lastX = box->xPos() + box->width();
}
if (box == lastBox)
break;
}
}
return result;
}
void RootInlineBox::setHasSelectedChildren(bool b)
{
if (m_hasSelectedChildren == b)
return;
m_hasSelectedChildren = b;
}
RenderObject::SelectionState RootInlineBox::selectionState()
{
// Walk over all of the selected boxes.
RenderObject::SelectionState state = RenderObject::SelectionNone;
for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
RenderObject::SelectionState boxState = box->selectionState();
if ((boxState == RenderObject::SelectionStart && state == RenderObject::SelectionEnd) ||
(boxState == RenderObject::SelectionEnd && state == RenderObject::SelectionStart))
state = RenderObject::SelectionBoth;
else if (state == RenderObject::SelectionNone ||
((boxState == RenderObject::SelectionStart || boxState == RenderObject::SelectionEnd) &&
(state == RenderObject::SelectionNone || state == RenderObject::SelectionInside)))
state = boxState;
if (state == RenderObject::SelectionBoth)
break;
}
return state;
}
InlineBox* RootInlineBox::firstSelectedBox()
{
for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild())
if (box->selectionState() != RenderObject::SelectionNone)
return box;
return 0;
}
InlineBox* RootInlineBox::lastSelectedBox()
{
for (InlineBox* box = lastLeafChild(); box; box = box->prevLeafChild())
if (box->selectionState() != RenderObject::SelectionNone)
return box;
return 0;
}
int RootInlineBox::selectionTop()
{
if (!prevRootBox())
return topOverflow();
int prevBottom = prevRootBox()->bottomOverflow();
if (prevBottom < m_topOverflow && 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 overflow if the offsets are greater on both sides.
int prevLeft = block()->leftOffset(prevBottom);
int prevRight = block()->rightOffset(prevBottom);
int newLeft = block()->leftOffset(m_topOverflow);
int newRight = block()->rightOffset(m_topOverflow);
if (prevLeft > newLeft || prevRight < newRight)
return m_topOverflow;
}
return prevBottom;
}
RenderBlock* RootInlineBox::block() const
{
return static_cast<RenderBlock*>(m_object);
}
InlineBox* RootInlineBox::closestLeafChildForXPos(int _x, int _tx)
{
InlineBox *firstLeaf = firstLeafChildAfterBox();
InlineBox *lastLeaf = lastLeafChildBeforeBox();
if (firstLeaf == lastLeaf)
return firstLeaf;
// Avoid returning a list marker when possible.
if (_x <= _tx + firstLeaf->m_x && !firstLeaf->object()->isListMarker())
// The x coordinate is less or equal to left edge of the firstLeaf.
// Return it.
return firstLeaf;
if (_x >= _tx + lastLeaf->m_x + lastLeaf->m_width && !lastLeaf->object()->isListMarker())
// The x coordinate is greater or equal to right edge of the lastLeaf.
// Return it.
return lastLeaf;
for (InlineBox *leaf = firstLeaf; leaf && leaf != lastLeaf; leaf = leaf->nextLeafChild()) {
if (!leaf->object()->isListMarker()) {
int leafX = _tx + leaf->m_x;
if (_x < leafX + leaf->m_width)
// The x coordinate is less than the right edge of the box.
// Return it.
return leaf;
}
}
return lastLeaf;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -