This source file includes following definitions.
- appendLineBox
- deleteLineBoxTree
- extractLineBox
- attachLineBox
- removeLineBox
- deleteLineBoxes
- dirtyLineBoxes
- rangeIntersectsRect
- anyLineIntersectsRect
- lineIntersectsDirtyRect
- paint
- hitTest
- dirtyLinesFromChangedChild
- checkConsistency
#include "config.h"
#include "core/rendering/RenderLineBoxList.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/InlineTextBox.h"
#include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/RootInlineBox.h"
using namespace std;
namespace WebCore {
#ifndef NDEBUG
RenderLineBoxList::~RenderLineBoxList()
{
ASSERT(!m_firstLineBox);
ASSERT(!m_lastLineBox);
}
#endif
void RenderLineBoxList::appendLineBox(InlineFlowBox* box)
{
checkConsistency();
if (!m_firstLineBox)
m_firstLineBox = m_lastLineBox = box;
else {
m_lastLineBox->setNextLineBox(box);
box->setPreviousLineBox(m_lastLineBox);
m_lastLineBox = box;
}
checkConsistency();
}
void RenderLineBoxList::deleteLineBoxTree()
{
InlineFlowBox* line = m_firstLineBox;
InlineFlowBox* nextLine;
while (line) {
nextLine = line->nextLineBox();
line->deleteLine();
line = nextLine;
}
m_firstLineBox = m_lastLineBox = 0;
}
void RenderLineBoxList::extractLineBox(InlineFlowBox* box)
{
checkConsistency();
m_lastLineBox = box->prevLineBox();
if (box == m_firstLineBox)
m_firstLineBox = 0;
if (box->prevLineBox())
box->prevLineBox()->setNextLineBox(0);
box->setPreviousLineBox(0);
for (InlineFlowBox* curr = box; curr; curr = curr->nextLineBox())
curr->setExtracted();
checkConsistency();
}
void RenderLineBoxList::attachLineBox(InlineFlowBox* box)
{
checkConsistency();
if (m_lastLineBox) {
m_lastLineBox->setNextLineBox(box);
box->setPreviousLineBox(m_lastLineBox);
} else
m_firstLineBox = box;
InlineFlowBox* last = box;
for (InlineFlowBox* curr = box; curr; curr = curr->nextLineBox()) {
curr->setExtracted(false);
last = curr;
}
m_lastLineBox = last;
checkConsistency();
}
void RenderLineBoxList::removeLineBox(InlineFlowBox* box)
{
checkConsistency();
if (box == m_firstLineBox)
m_firstLineBox = box->nextLineBox();
if (box == m_lastLineBox)
m_lastLineBox = box->prevLineBox();
if (box->nextLineBox())
box->nextLineBox()->setPreviousLineBox(box->prevLineBox());
if (box->prevLineBox())
box->prevLineBox()->setNextLineBox(box->nextLineBox());
checkConsistency();
}
void RenderLineBoxList::deleteLineBoxes()
{
if (m_firstLineBox) {
InlineFlowBox* next;
for (InlineFlowBox* curr = m_firstLineBox; curr; curr = next) {
next = curr->nextLineBox();
curr->destroy();
}
m_firstLineBox = 0;
m_lastLineBox = 0;
}
}
void RenderLineBoxList::dirtyLineBoxes()
{
for (InlineFlowBox* curr = firstLineBox(); curr; curr = curr->nextLineBox())
curr->dirtyLineBoxes();
}
bool RenderLineBoxList::rangeIntersectsRect(RenderBoxModelObject* renderer, LayoutUnit logicalTop, LayoutUnit logicalBottom, const LayoutRect& rect, const LayoutPoint& offset) const
{
RenderBox* block;
if (renderer->isBox())
block = toRenderBox(renderer);
else
block = renderer->containingBlock();
LayoutUnit physicalStart = block->flipForWritingMode(logicalTop);
LayoutUnit physicalEnd = block->flipForWritingMode(logicalBottom);
LayoutUnit physicalExtent = absoluteValue(physicalEnd - physicalStart);
physicalStart = min(physicalStart, physicalEnd);
if (renderer->style()->isHorizontalWritingMode()) {
physicalStart += offset.y();
if (physicalStart >= rect.maxY() || physicalStart + physicalExtent <= rect.y())
return false;
} else {
physicalStart += offset.x();
if (physicalStart >= rect.maxX() || physicalStart + physicalExtent <= rect.x())
return false;
}
return true;
}
bool RenderLineBoxList::anyLineIntersectsRect(RenderBoxModelObject* renderer, const LayoutRect& rect, const LayoutPoint& offset) const
{
RootInlineBox& firstRootBox = firstLineBox()->root();
RootInlineBox& lastRootBox = lastLineBox()->root();
LayoutUnit firstLineTop = firstLineBox()->logicalTopVisualOverflow(firstRootBox.lineTop());
LayoutUnit lastLineBottom = lastLineBox()->logicalBottomVisualOverflow(lastRootBox.lineBottom());
return rangeIntersectsRect(renderer, firstLineTop, lastLineBottom, rect, offset);
}
bool RenderLineBoxList::lineIntersectsDirtyRect(RenderBoxModelObject* renderer, InlineFlowBox* box, const PaintInfo& paintInfo, const LayoutPoint& offset) const
{
RootInlineBox& root = box->root();
LayoutUnit logicalTop = min<LayoutUnit>(box->logicalTopVisualOverflow(root.lineTop()), root.selectionTop());
LayoutUnit logicalBottom = box->logicalBottomVisualOverflow(root.lineBottom());
return rangeIntersectsRect(renderer, logicalTop, logicalBottom, paintInfo.rect, offset);
}
void RenderLineBoxList::paint(RenderBoxModelObject* renderer, PaintInfo& paintInfo, const LayoutPoint& paintOffset) const
{
if (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseOutline
&& paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintPhaseChildOutlines && paintInfo.phase != PaintPhaseTextClip
&& paintInfo.phase != PaintPhaseMask)
return;
ASSERT(renderer->isRenderBlock() || (renderer->isRenderInline() && renderer->hasLayer()));
if (!firstLineBox())
return;
if (!anyLineIntersectsRect(renderer, paintInfo.rect, paintOffset))
return;
PaintInfo info(paintInfo);
ListHashSet<RenderInline*> outlineObjects;
info.setOutlineObjects(&outlineObjects);
for (InlineFlowBox* curr = firstLineBox(); curr; curr = curr->nextLineBox()) {
if (lineIntersectsDirtyRect(renderer, curr, info, paintOffset)) {
RootInlineBox& root = curr->root();
curr->paint(info, paintOffset, root.lineTop(), root.lineBottom());
}
}
if (info.phase == PaintPhaseOutline || info.phase == PaintPhaseSelfOutline || info.phase == PaintPhaseChildOutlines) {
ListHashSet<RenderInline*>::iterator end = info.outlineObjects()->end();
for (ListHashSet<RenderInline*>::iterator it = info.outlineObjects()->begin(); it != end; ++it) {
RenderInline* flow = *it;
flow->paintOutline(info, paintOffset);
}
info.outlineObjects()->clear();
}
}
bool RenderLineBoxList::hitTest(RenderBoxModelObject* renderer, const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction) const
{
if (hitTestAction != HitTestForeground)
return false;
ASSERT(renderer->isRenderBlock() || (renderer->isRenderInline() && renderer->hasLayer()));
if (!firstLineBox())
return false;
LayoutPoint point = locationInContainer.point();
LayoutRect rect = firstLineBox()->isHorizontal() ?
IntRect(point.x(), point.y() - locationInContainer.topPadding(), 1, locationInContainer.topPadding() + locationInContainer.bottomPadding() + 1) :
IntRect(point.x() - locationInContainer.leftPadding(), point.y(), locationInContainer.rightPadding() + locationInContainer.leftPadding() + 1, 1);
if (!anyLineIntersectsRect(renderer, rect, accumulatedOffset))
return false;
for (InlineFlowBox* curr = lastLineBox(); curr; curr = curr->prevLineBox()) {
RootInlineBox& root = curr->root();
if (rangeIntersectsRect(renderer, curr->logicalTopVisualOverflow(root.lineTop()), curr->logicalBottomVisualOverflow(root.lineBottom()), rect, accumulatedOffset)) {
bool inside = curr->nodeAtPoint(request, result, locationInContainer, accumulatedOffset, root.lineTop(), root.lineBottom());
if (inside) {
renderer->updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
return true;
}
}
}
return false;
}
void RenderLineBoxList::dirtyLinesFromChangedChild(RenderObject* container, RenderObject* child)
{
if (!container->parent() || (container->isRenderBlock() && (container->selfNeedsLayout() || !container->isRenderBlockFlow())))
return;
RenderInline* inlineContainer = container->isRenderInline() ? toRenderInline(container) : 0;
InlineBox* firstBox = inlineContainer ? inlineContainer->firstLineBoxIncludingCulling() : firstLineBox();
if (!firstBox) {
if (container->isInline() && !container->ancestorLineBoxDirty()) {
container->parent()->dirtyLinesFromChangedChild(container);
container->setAncestorLineBoxDirty();
}
return;
}
RootInlineBox* box = 0;
RenderObject* curr = 0;
for (curr = child->previousSibling(); curr; curr = curr->previousSibling()) {
if (curr->isFloatingOrOutOfFlowPositioned())
continue;
if (curr->isReplaced()) {
InlineBox* wrapper = toRenderBox(curr)->inlineBoxWrapper();
if (wrapper)
box = &wrapper->root();
} else if (curr->isText()) {
InlineTextBox* textBox = toRenderText(curr)->lastTextBox();
if (textBox)
box = &textBox->root();
} else if (curr->isRenderInline()) {
InlineBox* lastSiblingBox = toRenderInline(curr)->lastLineBoxIncludingCulling();
if (lastSiblingBox)
box = &lastSiblingBox->root();
}
if (box)
break;
}
if (!box) {
if (inlineContainer && !inlineContainer->alwaysCreateLineBoxes()) {
if (!inlineContainer->ancestorLineBoxDirty()) {
inlineContainer->parent()->dirtyLinesFromChangedChild(inlineContainer);
inlineContainer->setAncestorLineBoxDirty();
}
return;
}
box = &firstBox->root();
}
if (box) {
RootInlineBox* adjacentBox;
box->markDirty();
adjacentBox = box->prevRootBox();
if (adjacentBox)
adjacentBox->markDirty();
adjacentBox = box->nextRootBox();
bool insertedAfterLeadingSpace = box->lineBreakObj() == child->previousSibling();
if (adjacentBox && (adjacentBox->lineBreakObj() == child || child->isBR() || (curr && curr->isBR())
|| insertedAfterLeadingSpace || isIsolated(container->style()->unicodeBidi()))) {
adjacentBox->markDirty();
}
}
}
#ifndef NDEBUG
void RenderLineBoxList::checkConsistency() const
{
#ifdef CHECK_CONSISTENCY
const InlineFlowBox* prev = 0;
for (const InlineFlowBox* child = m_firstLineBox; child != 0; child = child->nextLineBox()) {
ASSERT(child->prevLineBox() == prev);
prev = child;
}
ASSERT(prev == m_lastLineBox);
#endif
}
#endif
}