📄 khtmlview.cpp.orig
字号:
const QPoint &p, QRect &r, QString &s){ HTMLMapElementImpl* map; if (img && img->getDocument()->isHTMLDocument() && (map = static_cast<HTMLDocumentImpl*>(img->getDocument())->getMap(img->imageMap()))) { RenderObject::NodeInfo info(true, false); RenderObject *rend = img->renderer(); int ax, ay; if (!rend || !rend->absolutePosition(ax, ay)) return false; // we're a client side image map bool inside = map->mapMouseEvent(p.x() - ax + scrollOfs.x(), p.y() - ay + scrollOfs.y(), rend->contentWidth(), rend->contentHeight(), info); if (inside && info.URLElement()) { HTMLAreaElementImpl *area = static_cast<HTMLAreaElementImpl *>(info.URLElement()); Q_ASSERT(area->id() == ID_AREA); s = area->getAttribute(ATTR_TITLE).string(); QRegion reg = area->cachedRegion(); if (!s.isEmpty() && !reg.isEmpty()) { r = reg.boundingRect(); r.moveBy(ax, ay); return true; } } } return false;}void KHTMLToolTip::maybeTip(const QPoint& p){ DOM::NodeImpl *node = m_viewprivate->underMouseNonShared; QRect region; while ( node ) { if ( node->isElementNode() ) { DOM::ElementImpl *e = static_cast<DOM::ElementImpl*>( node ); QRect r; QString s; bool found = false; // for images, check if it is part of a client-side image map, // and query the <area>s' title attributes, too if (e->id() == ID_IMG && !e->getAttribute( ATTR_USEMAP ).isEmpty()) { found = findImageMapRect(static_cast<HTMLImageElementImpl *>(e), m_view->viewportToContents(QPoint(0, 0)), p, r, s); } if (!found) { s = e->getAttribute( ATTR_TITLE ).string(); r = node->getRect(); } region |= QRect( m_view->contentsToViewport( r.topLeft() ), r.size() ); if ( !s.isEmpty() ) { tip( region, QStyleSheet::convertFromPlainText( s, QStyleSheetItem::WhiteSpaceNormal ) ); break; } } node = node->parentNode(); }}#endifKHTMLView::KHTMLView( KHTMLPart *part, QWidget *parent, const char *name) : QScrollView( parent, name, WResizeNoErase | WRepaintNoErase ){ m_medium = "screen"; m_part = part; d = new KHTMLViewPrivate; QScrollView::setVScrollBarMode(d->vmode); QScrollView::setHScrollBarMode(d->hmode); connect(kapp, SIGNAL(kdisplayPaletteChanged()), this, SLOT(slotPaletteChanged())); connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(slotScrollBarMoved())); // initialize QScrollView enableClipper(true); // hack to get unclipped painting on the viewport. static_cast<KHTMLView *>(static_cast<QWidget *>(viewport()))->setWFlags(WPaintUnclipped); setResizePolicy(Manual); viewport()->setMouseTracking(true); viewport()->setBackgroundMode(NoBackground); KImageIO::registerFormats();#ifndef QT_NO_TOOLTIP d->tooltip = new KHTMLToolTip( this, d );#endif#ifndef KHTML_NO_TYPE_AHEAD_FIND connect(&d->timer, SIGNAL(timeout()), this, SLOT(findTimeout()));#endif // KHTML_NO_TYPE_AHEAD_FIND init(); viewport()->show();}KHTMLView::~KHTMLView(){ closeChildDialogs(); if (m_part) { //WABA: Is this Ok? Do I need to deref it as well? //Does this need to be done somewhere else? DOM::DocumentImpl *doc = m_part->xmlDocImpl(); if (doc) doc->detach(); } delete d; d = 0;}void KHTMLView::init(){ if(!d->paintBuffer) d->paintBuffer = new QPixmap(PAINT_BUFFER_HEIGHT, PAINT_BUFFER_HEIGHT); if(!d->vertPaintBuffer) d->vertPaintBuffer = new QPixmap(10, PAINT_BUFFER_HEIGHT); if(!d->tp) d->tp = new QPainter(); setFocusPolicy(QWidget::StrongFocus); viewport()->setFocusProxy(this); _marginWidth = -1; // undefined _marginHeight = -1; _width = 0; _height = 0; installEventFilter(this); setAcceptDrops(true); QSize s = viewportSize(4095, 4095); resizeContents(s.width(), s.height());}void KHTMLView::clear(){ // work around QScrollview's unbelievable bugginess setStaticBackground(true);#ifndef KHTML_NO_CARET if (!m_part->isCaretMode() && !m_part->isEditable()) caretOff();#endif#ifndef KHTML_NO_TYPE_AHEAD_FIND if( d->typeAheadActivated ) findTimeout();#endif if (d->accessKeysEnabled && d->accessKeysActivated) accessKeysTimeout(); viewport()->unsetCursor(); if ( d->cursor_icon_widget ) d->cursor_icon_widget->hide(); d->reset(); killTimers(); emit cleared(); QScrollView::setHScrollBarMode(d->hmode); QScrollView::setVScrollBarMode(d->vmode); verticalScrollBar()->setEnabled( false ); horizontalScrollBar()->setEnabled( false );}void KHTMLView::hideEvent(QHideEvent* e){ QScrollView::hideEvent(e);}void KHTMLView::showEvent(QShowEvent* e){ QScrollView::showEvent(e);}void KHTMLView::resizeEvent (QResizeEvent* e){ int dw = e->oldSize().width() - e->size().width(); int dh = e->oldSize().height() - e->size().height(); // if we are shrinking the view, don't allow the content to overflow // before the layout occurs - we don't know if we need scrollbars yet dw = dw>0 ? kMax(0, contentsWidth()-dw) : contentsWidth(); dh = dh>0 ? kMax(0, contentsHeight()-dh) : contentsHeight(); resizeContents(dw, dh); QScrollView::resizeEvent(e); if ( m_part && m_part->xmlDocImpl() ) m_part->xmlDocImpl()->dispatchWindowEvent( EventImpl::RESIZE_EVENT, false, false );}void KHTMLView::viewportResizeEvent (QResizeEvent* e){ QScrollView::viewportResizeEvent(e); //int w = visibleWidth(); //int h = visibleHeight(); if (d->layoutSchedulingEnabled) layout();#ifndef KHTML_NO_CARET else { hideCaret(); recalcAndStoreCaretPos(); showCaret(); }/*end if*/#endif KApplication::sendPostedEvents(viewport(), QEvent::Paint);}// this is to get rid of a compiler virtual overload mismatch warning. do not removevoid KHTMLView::drawContents( QPainter*){}void KHTMLView::drawContents( QPainter *p, int ex, int ey, int ew, int eh ){#ifdef DEBUG_PIXEL if ( d->timer.elapsed() > 5000 ) { qDebug( "drawed %d pixels in %d repaints the last %d milliseconds", d->pixelbooth, d->repaintbooth, d->timer.elapsed() ); d->timer.restart(); d->pixelbooth = 0; d->repaintbooth = 0; } d->pixelbooth += ew*eh; d->repaintbooth++;#endif //kdDebug( 6000 ) << "drawContents this="<< this <<" x=" << ex << ",y=" << ey << ",w=" << ew << ",h=" << eh << endl; if(!m_part || !m_part->xmlDocImpl() || !m_part->xmlDocImpl()->renderer()) { p->fillRect(ex, ey, ew, eh, palette().active().brush(QColorGroup::Base)); return; } else if ( d->complete && static_cast<RenderCanvas*>(m_part->xmlDocImpl()->renderer())->needsLayout() ) { // an external update request happens while we have a layout scheduled unscheduleRelayout(); layout(); } if (d->painting) { kdDebug( 6000 ) << "WARNING: drawContents reentered! " << endl; return; } d->painting = true; QPoint pt = contentsToViewport(QPoint(ex, ey)); QRegion cr = QRect(pt.x(), pt.y(), ew, eh); //kdDebug(6000) << "clip rect: " << QRect(pt.x(), pt.y(), ew, eh) << endl; for (QPtrDictIterator<QWidget> it(d->visibleWidgets); it.current(); ++it) { QWidget *w = it.current(); RenderWidget* rw = static_cast<RenderWidget*>( it.currentKey() ); if (strcmp(w->name(), "__khtml")) { int x, y; rw->absolutePosition(x, y); contentsToViewport(x, y, x, y); cr -= QRect(x, y, rw->width(), rw->height()); } }#if 0 // this is commonly the case with framesets. we still do // want to paint them, otherwise the widgets don't get placed. if (cr.isEmpty()) { d->painting = false; return; }#endif#ifndef DEBUG_NO_PAINT_BUFFER p->setClipRegion(cr); if (eh > PAINT_BUFFER_HEIGHT && ew <= 10) { if ( d->vertPaintBuffer->height() < visibleHeight() ) d->vertPaintBuffer->resize(10, visibleHeight()); d->tp->begin(d->vertPaintBuffer); d->tp->translate(-ex, -ey); d->tp->fillRect(ex, ey, ew, eh, palette().active().brush(QColorGroup::Base)); m_part->xmlDocImpl()->renderer()->layer()->paint(d->tp, QRect(ex, ey, ew, eh)); d->tp->end(); p->drawPixmap(ex, ey, *d->vertPaintBuffer, 0, 0, ew, eh); } else { if ( d->paintBuffer->width() < visibleWidth() ) d->paintBuffer->resize(visibleWidth(),PAINT_BUFFER_HEIGHT); int py=0; while (py < eh) { int ph = eh-py < PAINT_BUFFER_HEIGHT ? eh-py : PAINT_BUFFER_HEIGHT; d->tp->begin(d->paintBuffer); d->tp->translate(-ex, -ey-py); d->tp->fillRect(ex, ey+py, ew, ph, palette().active().brush(QColorGroup::Base)); m_part->xmlDocImpl()->renderer()->layer()->paint(d->tp, QRect(ex, ey+py, ew, ph)); d->tp->end(); p->drawPixmap(ex, ey+py, *d->paintBuffer, 0, 0, ew, ph); py += PAINT_BUFFER_HEIGHT; } }#else // !DEBUG_NO_PAINT_BUFFERstatic int cnt=0; ex = contentsX(); ey = contentsY(); ew = visibleWidth(); eh = visibleHeight(); QRect pr(ex,ey,ew,eh); kdDebug() << "[" << ++cnt << "]" << " clip region: " << pr << endl;// p->setClipRegion(QRect(0,0,ew,eh));// p->translate(-ex, -ey); p->fillRect(ex, ey, ew, eh, palette().active().brush(QColorGroup::Base)); m_part->xmlDocImpl()->renderer()->layer()->paint(p, pr);#endif // DEBUG_NO_PAINT_BUFFER#ifndef KHTML_NO_CARET if (d->m_caretViewContext && d->m_caretViewContext->visible) { QRect pos(d->m_caretViewContext->x, d->m_caretViewContext->y, d->m_caretViewContext->width, d->m_caretViewContext->height); if (pos.intersects(QRect(ex, ey, ew, eh))) { p->setRasterOp(XorROP); p->setPen(white); if (pos.width() == 1) p->drawLine(pos.topLeft(), pos.bottomRight()); else { p->fillRect(pos, white); }/*end if*/ }/*end if*/ }/*end if*/#endif // KHTML_NO_CARET// p->setPen(QPen(magenta,0,DashDotDotLine));// p->drawRect(dbg_paint_rect); khtml::DrawContentsEvent event( p, ex, ey, ew, eh ); QApplication::sendEvent( m_part, &event ); d->painting = false;}void KHTMLView::setMarginWidth(int w){ // make it update the rendering area when set _marginWidth = w;}void KHTMLView::setMarginHeight(int h){ // make it update the rendering area when set _marginHeight = h;}void KHTMLView::layout(){ if( m_part && m_part->xmlDocImpl() ) { DOM::DocumentImpl *document = m_part->xmlDocImpl(); khtml::RenderCanvas* root = static_cast<khtml::RenderCanvas *>(document->renderer()); if ( !root ) return; d->layoutSchedulingEnabled=false; if (document->isHTMLDocument()) { NodeImpl *body = static_cast<HTMLDocumentImpl*>(document)->body(); if(body && body->renderer() && body->id() == ID_FRAMESET) { QScrollView::setVScrollBarMode(AlwaysOff); QScrollView::setHScrollBarMode(AlwaysOff); body->renderer()->setNeedsLayout(true);// if (d->tooltip) {// delete d->tooltip;// d->tooltip = 0;// } } else if (!d->tooltip) d->tooltip = new KHTMLToolTip( this, d ); } d->needsFullRepaint = d->firstRelayout; if (_height != visibleHeight() || _width != visibleWidth()) {; d->needsFullRepaint = true; _height = visibleHeight(); _width = visibleWidth(); } //QTime qt; //qt.start(); root->layout(); emit finishedLayout(); if (d->firstRelayout) { // make sure firstRelayout is set to false now in case this layout // wasn't scheduled d->firstRelayout = false; verticalScrollBar()->setEnabled( true ); horizontalScrollBar()->setEnabled( true ); }#if 0 ElementImpl *listitem = m_part->xmlDocImpl()->getElementById("__test_element__"); if (listitem) kdDebug(6000) << "after layout, before repaint" << endl; if (listitem) dumpLineBoxes(static_cast<RenderFlow *>(listitem->renderer()));#endif#ifndef KHTML_NO_CARET hideCaret(); if ((m_part->isCaretMode() || m_part->isEditable()) && !d->complete && d->m_caretViewContext && !d->m_caretViewContext->caretMoved) { initCaret(); } else { recalcAndStoreCaretPos(); showCaret(); }/*end if*/#endif if (d->accessKeysEnabled && d->accessKeysActivated) { emit hideAccessKeys(); displayAccessKeys(); } //kdDebug( 6000 ) << "TIME: layout() dt=" << qt.elapsed() << endl; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -