📄 kwqrendertreedebug.cpp
字号:
result += ' ';
} else {
ushort u = c.unicode();
if (u >= 0x20 && u < 0x7F) {
result += c;
} else {
QString hex;
hex.sprintf("\\x{%X}", u);
result += hex;
}
}
}
result += '"';
return result;
}
static void writeTextRun(QTextStream &ts, const RenderText &o, const InlineTextBox &run)
{
ts << "text run at (" << run.m_x << "," << run.m_y << ") width " << run.m_width << ": "
<< quoteAndEscapeNonPrintables(o.data().string().mid(run.m_start, run.m_len))
<< "\n";
}
static void write(QTextStream &ts, const RenderObject &o, int indent = 0)
{
writeIndent(ts, indent);
ts << o << "\n";
if (o.isText() && !o.isBR()) {
const RenderText &text = static_cast<const RenderText &>(o);
for (InlineTextBox* box = text.firstTextBox(); box; box = box->nextTextBox()) {
writeIndent(ts, indent+1);
writeTextRun(ts, text, *box);
}
}
for (RenderObject *child = o.firstChild(); child; child = child->nextSibling()) {
if (child->layer()) {
continue;
}
write(ts, *child, indent + 1);
}
if (o.isWidget()) {
QWidget *widget = static_cast<const RenderWidget &>(o).widget();
if (widget && widget->inherits("KHTMLView")) {
KHTMLView *view = static_cast<KHTMLView *>(widget);
RenderObject *root = KWQ(view->part())->renderer();
if (root) {
view->layout();
RenderLayer* l = root->layer();
if (l)
writeLayers(ts, l, l, QRect(l->xPos(), l->yPos(), l->width(), l->height()), indent+1);
}
}
}
}
static void write(QTextStream &ts, RenderLayer &l,
const QRect& layerBounds, const QRect& backgroundClipRect, const QRect& clipRect,
int layerType = 0, int indent = 0)
{
writeIndent(ts, indent);
ts << "layer";
ts << " " << layerBounds;
if (layerBounds != layerBounds.intersect(backgroundClipRect))
ts << " backgroundClip " << backgroundClipRect;
if (layerBounds != layerBounds.intersect(clipRect))
ts << " clip " << clipRect;
if (l.renderer()->hasOverflowClip()) {
if (l.scrollXOffset())
ts << " scrollX " << l.scrollXOffset();
if (l.scrollYOffset())
ts << " scrollY " << l.scrollYOffset();
if (l.renderer()->clientWidth() != l.scrollWidth())
ts << " scrollWidth " << l.scrollWidth();
if (l.renderer()->clientHeight() != l.scrollHeight())
ts << " scrollHeight " << l.scrollHeight();
}
if (layerType == -1)
ts << " layerType: background only";
else if (layerType == 1)
ts << " layerType: foreground only";
ts << "\n";
if (layerType != -1)
write(ts, *l.renderer(), indent + 1);
}
static void writeLayers(QTextStream &ts, const RenderLayer* rootLayer, RenderLayer* l,
const QRect& paintDirtyRect, int indent)
{
// Calculate the clip rects we should use.
QRect layerBounds, damageRect, clipRectToApply;
l->calculateRects(rootLayer, paintDirtyRect, layerBounds, damageRect, clipRectToApply);
// Ensure our z-order lists are up-to-date.
l->updateZOrderLists();
bool shouldPaint = l->intersectsDamageRect(layerBounds, damageRect);
QPtrVector<RenderLayer>* negList = l->negZOrderList();
if (shouldPaint && negList && negList->count() > 0)
write(ts, *l, layerBounds, damageRect, clipRectToApply, -1, indent);
if (negList) {
for (unsigned i = 0; i != negList->count(); ++i)
writeLayers(ts, rootLayer, negList->at(i), paintDirtyRect, indent);
}
if (shouldPaint)
write(ts, *l, layerBounds, damageRect, clipRectToApply, negList && negList->count() > 0, indent);
QPtrVector<RenderLayer>* posList = l->posZOrderList();
if (posList) {
for (unsigned i = 0; i != posList->count(); ++i)
writeLayers(ts, rootLayer, posList->at(i), paintDirtyRect, indent);
}
}
static QString nodePositionRelativeToRoot(NodeImpl *node, NodeImpl *root)
{
QString result;
NodeImpl *n = node;
while (1) {
NodeImpl *p = n->parentNode();
if (!p || n == root) {
result += " of root {" + getTagName(n) + "}";
break;
}
if (n != node)
result += " of ";
int count = 1;
for (NodeImpl *search = p->firstChild(); search != n; search = search->nextSibling())
count++;
result += "child " + QString::number(count) + " {" + getTagName(n) + "}";
n = p;
}
return result;
}
static void writeSelection(QTextStream &ts, const RenderObject *o)
{
NodeImpl *n = o->element();
if (!n || !n->isDocumentNode())
return;
DocumentImpl *doc = static_cast<DocumentImpl *>(n);
if (!doc->part())
return;
Selection selection = doc->part()->selection();
if (selection.isNone())
return;
if (!selection.start().node()->isContentEditable() || !selection.end().node()->isContentEditable())
return;
Position startPosition = selection.start();
Position endPosition = selection.end();
QString startNodeTagName(getTagName(startPosition.node()));
QString endNodeTagName(getTagName(endPosition.node()));
NodeImpl *rootNode = doc->getElementById("root");
if (selection.isCaret()) {
Position upstream = startPosition.upstream(DOM::StayInBlock);
Position downstream = startPosition.downstream(DOM::StayInBlock);
QString positionString = nodePositionRelativeToRoot(startPosition.node(), rootNode);
QString upstreamString = nodePositionRelativeToRoot(upstream.node(), rootNode);
QString downstreamString = nodePositionRelativeToRoot(downstream.node(), rootNode);
ts << "selection is CARET:\n" <<
"start: position " << startPosition.offset() << " of " << positionString << "\n"
"upstream: position " << upstream.offset() << " of " << upstreamString << "\n"
"downstream: position " << downstream.offset() << " of " << downstreamString << "\n";
}
else if (selection.isRange()) {
QString startString = nodePositionRelativeToRoot(startPosition.node(), rootNode);
Position upstreamStart = startPosition.upstream(DOM::StayInBlock);
QString upstreamStartString = nodePositionRelativeToRoot(upstreamStart.node(), rootNode);
Position downstreamStart = startPosition.downstream(DOM::StayInBlock);
QString downstreamStartString = nodePositionRelativeToRoot(downstreamStart.node(), rootNode);
QString endString = nodePositionRelativeToRoot(endPosition.node(), rootNode);
Position upstreamEnd = endPosition.upstream(DOM::StayInBlock);
QString upstreamEndString = nodePositionRelativeToRoot(upstreamEnd.node(), rootNode);
Position downstreamEnd = endPosition.downstream(DOM::StayInBlock);
QString downstreamEndString = nodePositionRelativeToRoot(downstreamEnd.node(), rootNode);
ts << "selection is RANGE:\n" <<
"start: position " << startPosition.offset() << " of " << startString << "\n" <<
"upstream: position " << upstreamStart.offset() << " of " << upstreamStartString << "\n"
"downstream: position " << downstreamStart.offset() << " of " << downstreamStartString << "\n"
"end: position " << endPosition.offset() << " of " << endString << "\n"
"upstream: position " << upstreamEnd.offset() << " of " << upstreamEndString << "\n"
"downstream: position " << downstreamEnd.offset() << " of " << downstreamEndString << "\n";
}
}
static bool debuggingRenderTreeFlag = false;
bool debuggingRenderTree()
{
return debuggingRenderTreeFlag;
}
QString externalRepresentation(RenderObject *o)
{
debuggingRenderTreeFlag = true;
JSEditor::setSupportsPasteCommand(true);
QString s;
{
QTextStream ts(&s);
if (o) {
// FIXME: Hiding the vertical scrollbar is a total hack to preserve the
// layout test results until I can figure out what the heck is going on. -dwh
o->canvas()->view()->setVScrollBarMode(QScrollView::AlwaysOff);
o->canvas()->view()->layout();
RenderLayer* l = o->layer();
if (l) {
writeLayers(ts, l, l, QRect(l->xPos(), l->yPos(), l->width(), l->height()));
writeSelection(ts, o);
}
}
}
return s;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -