📄 render_canvas.cpp
字号:
result = QRect(m_view->contentsX(), m_view->contentsY(),
m_view->visibleWidth(), m_view->visibleHeight());
return result;
}
void RenderCanvas::computeAbsoluteRepaintRect(QRect& r, bool f)
{
if (m_printingMode) return;
if (f && m_view) {
r.setX(r.x() + m_view->contentsX());
r.setY(r.y() + m_view->contentsY());
}
}
void RenderCanvas::absoluteRects(QValueList<QRect>& rects, int _tx, int _ty)
{
rects.append(QRect(_tx, _ty, m_layer->width(), m_layer->height()));
}
QRect RenderCanvas::selectionRect() const
{
QPtrDict<SelectionInfo> selectedObjects;
selectedObjects.setAutoDelete(true);
RenderObject* os = m_selectionStart;
while (os) {
RenderObject* no = 0;
if (os != m_selectionEnd) {
if (!(no = os->firstChild())) {
if (!(no = os->nextSibling())) {
no = os->parent();
while (no && no != m_selectionEnd && !no->nextSibling())
no = no->parent();
if (no && no != m_selectionEnd)
no = no->nextSibling();
}
}
}
if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) {
// Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
selectedObjects.insert(os, new SelectionInfo(os));
RenderBlock* cb = os->containingBlock();
while (cb && !cb->isCanvas()) {
SelectionInfo* blockInfo = selectedObjects.find(cb);
if (blockInfo) break;
selectedObjects.insert(cb, new SelectionInfo(cb));
cb = cb->containingBlock();
}
}
os = no;
}
// Now create a single bounding box rect that encloses the whole selection.
QRect selRect;
QPtrDictIterator<SelectionInfo> objects(selectedObjects);
for (objects.toFirst(); objects.current(); ++objects)
selRect = selRect.unite(objects.current()->rect());
return selRect;
}
void RenderCanvas::setSelection(RenderObject *s, int sp, RenderObject *e, int ep)
{
// Make sure both our start and end objects are defined.
// Check www.msnbc.com and try clicking around to find the case where this happened.
if ((s && !e) || (e && !s))
return;
// Just return if the selection hasn't changed.
if (m_selectionStart == s && m_selectionStartPos == sp &&
m_selectionEnd == e && m_selectionEndPos == ep)
return;
// Record the old selected objects. These will be used later
// when we compare against the new selected objects.
int oldStartPos = m_selectionStartPos;
int oldEndPos = m_selectionEndPos;
// Objects each have a single selection rect to examine.
QPtrDict<SelectionInfo> oldSelectedObjects;
QPtrDict<SelectionInfo> newSelectedObjects;
oldSelectedObjects.setAutoDelete(true);
newSelectedObjects.setAutoDelete(true);
// Blocks contain selected objects and fill gaps between them, either on the left, right, or in between lines and blocks.
// In order to get the repaint rect right, we have to examine left, middle, and right rects individually, since otherwise
// the union of those rects might remain the same even when changes have occurred.
QPtrDict<BlockSelectionInfo> oldSelectedBlocks;
QPtrDict<BlockSelectionInfo> newSelectedBlocks;
oldSelectedBlocks.setAutoDelete(true);
newSelectedBlocks.setAutoDelete(true);
RenderObject* os = m_selectionStart;
while (os) {
RenderObject* no = 0;
if (os != m_selectionEnd) {
if (!(no = os->firstChild())) {
if (!(no = os->nextSibling())) {
no = os->parent();
while (no && no != m_selectionEnd && !no->nextSibling())
no = no->parent();
if (no && no != m_selectionEnd)
no = no->nextSibling();
}
}
}
if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) {
// Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
oldSelectedObjects.insert(os, new SelectionInfo(os));
RenderBlock* cb = os->containingBlock();
while (cb && !cb->isCanvas()) {
BlockSelectionInfo* blockInfo = oldSelectedBlocks.find(cb);
if (blockInfo) break;
oldSelectedBlocks.insert(cb, new BlockSelectionInfo(cb));
cb = cb->containingBlock();
}
}
os = no;
}
// Now clear the selection.
QPtrDictIterator<SelectionInfo> oldLeaves(oldSelectedObjects);
for (oldLeaves.toFirst(); oldLeaves.current(); ++oldLeaves) {
RenderObject* obj = static_cast<RenderObject*>(oldLeaves.currentKey());
obj->setSelectionState(SelectionNone);
}
// set selection start and end
m_selectionStart = s;
m_selectionStartPos = sp;
m_selectionEnd = e;
m_selectionEndPos = ep;
// Update the selection status of all objects between m_selectionStart and m_selectionEnd
if (s && s == e)
s->setSelectionState(SelectionBoth);
else {
if (s)
s->setSelectionState(SelectionStart);
if (e)
e->setSelectionState(SelectionEnd);
}
RenderObject* o = s;
while (o) {
RenderObject* no = 0;
if (o != s && o != e && o->canBeSelectionLeaf())
o->setSelectionState(SelectionInside);
if (o != e) {
if (!(no = o->firstChild())) {
if ( !(no = o->nextSibling())) {
no = o->parent();
while (no && no != e && !no->nextSibling())
no = no->parent();
if (no && no != e)
no = no->nextSibling();
}
}
}
o=no;
}
// Now that the selection state has been updated for the new objects, walk them again and
// put them in the new objects list.
o = s;
while (o) {
RenderObject* no = 0;
if (o != e) {
if (!(no = o->firstChild())) {
if ( !(no = o->nextSibling())) {
no = o->parent();
while (no && no != e && !no->nextSibling())
no = no->parent();
if (no && no != e)
no = no->nextSibling();
}
}
}
if ((o->canBeSelectionLeaf() || o == s || o == e) && o->selectionState() != SelectionNone) {
newSelectedObjects.insert(o, new SelectionInfo(o));
RenderBlock* cb = o->containingBlock();
while (cb && !cb->isCanvas()) {
BlockSelectionInfo* blockInfo = newSelectedBlocks.find(cb);
if (blockInfo) break;
newSelectedBlocks.insert(cb, new BlockSelectionInfo(cb));
cb = cb->containingBlock();
}
}
o=no;
}
if (!m_view)
return;
// Have any of the old selected objects changed compared to the new selection?
for (oldLeaves.toFirst(); oldLeaves.current(); ++oldLeaves) {
SelectionInfo* newInfo = newSelectedObjects.find(oldLeaves.currentKey());
SelectionInfo* oldInfo = oldLeaves.current();
if (!newInfo || oldInfo->rect() != newInfo->rect() || oldInfo->state() != newInfo->state() ||
(m_selectionStart == oldLeaves.currentKey() && oldStartPos != m_selectionStartPos) ||
(m_selectionEnd == oldLeaves.currentKey() && oldEndPos != m_selectionEndPos)) {
m_view->updateContents(oldInfo->rect());
if (newInfo) {
m_view->updateContents(newInfo->rect());
newSelectedObjects.remove(oldLeaves.currentKey());
}
}
}
// Any new objects that remain were not found in the old objects dict, and so they need to be updated.
QPtrDictIterator<SelectionInfo> newLeaves(newSelectedObjects);
for (newLeaves.toFirst(); newLeaves.current(); ++newLeaves) {
SelectionInfo* newInfo = newLeaves.current();
m_view->updateContents(newInfo->rect());
}
// Have any of the old blocks changed?
QPtrDictIterator<BlockSelectionInfo> oldBlocks(oldSelectedBlocks);
for (oldBlocks.toFirst(); oldBlocks.current(); ++oldBlocks) {
BlockSelectionInfo* newInfo = newSelectedBlocks.find(oldBlocks.currentKey());
BlockSelectionInfo* oldInfo = oldBlocks.current();
if (!newInfo || oldInfo->rects() != newInfo->rects() || oldInfo->state() != newInfo->state()) {
m_view->updateContents(oldInfo->rects());
if (newInfo) {
m_view->updateContents(newInfo->rects());
newSelectedBlocks.remove(oldBlocks.currentKey());
}
}
}
// Any new blocks that remain were not found in the old blocks dict, and so they need to be updated.
QPtrDictIterator<BlockSelectionInfo> newBlocks(newSelectedBlocks);
for (newBlocks.toFirst(); newBlocks.current(); ++newBlocks) {
BlockSelectionInfo* newInfo = newBlocks.current();
m_view->updateContents(newInfo->rects());
}
}
void RenderCanvas::clearSelection()
{
setSelection(0, -1, 0, -1);
}
void RenderCanvas::selectionStartEnd(int& spos, int& epos)
{
spos = m_selectionStartPos;
epos = m_selectionEndPos;
}
QRect RenderCanvas::viewRect() const
{
if (m_printingMode)
return QRect(0,0, m_width, m_height);
else if (m_view)
return QRect(m_view->contentsX(),
m_view->contentsY(),
m_view->visibleWidth(),
m_view->visibleHeight());
else return QRect(0,0,m_rootWidth,m_rootHeight);
}
int RenderCanvas::docHeight() const
{
int h;
if (m_printingMode || !m_view)
h = m_height;
else
h = m_view->visibleHeight();
int lowestPos = lowestPosition();
if( lowestPos > h )
h = lowestPos;
// FIXME: This doesn't do any margin collapsing.
// Instead of this dh computation we should keep the result
// when we call RenderBlock::layout.
int dh = 0;
for (RenderObject *c = firstChild(); c; c = c->nextSibling()) {
dh += c->height() + c->marginTop() + c->marginBottom();
}
if( dh > h )
h = dh;
return h;
}
int RenderCanvas::docWidth() const
{
int w;
if (m_printingMode || !m_view)
w = m_width;
else
w = m_view->visibleWidth();
int rightmostPos = rightmostPosition();
if( rightmostPos > w )
w = rightmostPos;
for (RenderObject *c = firstChild(); c; c = c->nextSibling()) {
int dw = c->width() + c->marginLeft() + c->marginRight();
if( dw > w )
w = dw;
}
return w;
}
#if APPLE_CHANGES
// The idea here is to take into account what object is moving the pagination point, and
// thus choose the best place to chop it.
void RenderCanvas::setBestTruncatedAt(int y, RenderObject *forRenderer, bool forcedBreak)
{
// Nobody else can set a page break once we have a forced break.
if (m_forcedPageBreak) return;
// Forced breaks always win over unforced breaks.
if (forcedBreak) {
m_forcedPageBreak = true;
m_bestTruncatedAt = y;
return;
}
// prefer the widest object who tries to move the pagination point
int width = forRenderer->width();
if (width > m_truncatorWidth) {
m_truncatorWidth = width;
m_bestTruncatedAt = y;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -