📄 qwebframe.cpp
字号:
*/QIcon QWebFrame::icon() const{ return QWebSettings::iconForUrl(d->frame->loader()->url());}/*! The name of this frame as defined by the parent frame.*/QString QWebFrame::frameName() const{ return d->frame->tree()->name();}/*! The web page that contains this frame.*/QWebPage *QWebFrame::page() const{ return d->page;}/*! Loads \a url into this frame. \note The view remains the same until enough data has arrived to display the new \a url. \sa setUrl(), setHtml(), setContent()*/void QWebFrame::load(const QUrl &url){#if QT_VERSION < 0x040400 load(QWebNetworkRequest(ensureAbsoluteUrl(url)));#else load(QNetworkRequest(ensureAbsoluteUrl(url)));#endif}#if QT_VERSION < 0x040400/*! Loads a network request, \a req, into this frame. \note The view remains the same until enough data has arrived to display the new url.*/void QWebFrame::load(const QWebNetworkRequest &req){ if (d->parentFrame()) d->page->d->insideOpenCall = true; QUrl url = ensureAbsoluteUrl(req.url()); QHttpRequestHeader httpHeader = req.httpHeader(); QByteArray postData = req.postData(); WebCore::ResourceRequest request(url); QString method = httpHeader.method(); if (!method.isEmpty()) request.setHTTPMethod(method); QList<QPair<QString, QString> > values = httpHeader.values(); for (int i = 0; i < values.size(); ++i) { const QPair<QString, QString> &val = values.at(i); request.addHTTPHeaderField(val.first, val.second); } if (!postData.isEmpty()) request.setHTTPBody(WebCore::FormData::create(postData.constData(), postData.size())); d->frame->loader()->load(request, false); if (d->parentFrame()) d->page->d->insideOpenCall = false;}#else/*! Loads a network request, \a req, into this frame, using the method specified in \a operation. \a body is optional and is only used for POST operations. \note The view remains the same until enough data has arrived to display the new \a url. \sa setUrl()*/void QWebFrame::load(const QNetworkRequest &req, QNetworkAccessManager::Operation operation, const QByteArray &body){ if (d->parentFrame()) d->page->d->insideOpenCall = true; QUrl url = ensureAbsoluteUrl(req.url()); WebCore::ResourceRequest request(url); switch (operation) { case QNetworkAccessManager::HeadOperation: request.setHTTPMethod("HEAD"); break; case QNetworkAccessManager::GetOperation: request.setHTTPMethod("GET"); break; case QNetworkAccessManager::PutOperation: request.setHTTPMethod("PUT"); break; case QNetworkAccessManager::PostOperation: request.setHTTPMethod("POST"); break; case QNetworkAccessManager::UnknownOperation: // eh? break; } QList<QByteArray> httpHeaders = req.rawHeaderList(); for (int i = 0; i < httpHeaders.size(); ++i) { const QByteArray &headerName = httpHeaders.at(i); request.addHTTPHeaderField(QString::fromLatin1(headerName), QString::fromLatin1(req.rawHeader(headerName))); } if (!body.isEmpty()) request.setHTTPBody(WebCore::FormData::create(body.constData(), body.size())); d->frame->loader()->load(request, false); if (d->parentFrame()) d->page->d->insideOpenCall = false;}#endif/*! Sets the content of this frame to \a html. \a baseUrl is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets. When using this method WebKit assumes that external resources such as JavaScript programs or style sheets are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external script can be specified through the charset attribute of the HTML script tag. It is also possible for the encoding to be specified by web server. \sa toHtml()*/void QWebFrame::setHtml(const QString &html, const QUrl &baseUrl){ KURL kurl(baseUrl); WebCore::ResourceRequest request(kurl); const QByteArray utf8 = html.toUtf8(); WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length()); WebCore::SubstituteData substituteData(data, WebCore::String("text/html"), WebCore::String("utf-8"), kurl); d->frame->loader()->load(request, substituteData, false);}/*! Sets the content of this frame to the specified content \a data. If the \a mimeType argument is empty it is currently assumed that the content is HTML but in future versions we may introduce auto-detection. External objects referenced in the content are located relative to \a baseUrl. \sa toHtml()*/void QWebFrame::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl){ KURL kurl(baseUrl); WebCore::ResourceRequest request(kurl); WTF::RefPtr<WebCore::SharedBuffer> buffer = WebCore::SharedBuffer::create(data.constData(), data.length()); QString actualMimeType = mimeType; if (actualMimeType.isEmpty()) actualMimeType = QLatin1String("text/html"); WebCore::SubstituteData substituteData(buffer, WebCore::String(actualMimeType), WebCore::String(), kurl); d->frame->loader()->load(request, substituteData, false);}/*! Returns the parent frame of this frame, or 0 if the frame is the web pages main frame. This is equivalent to qobject_cast<QWebFrame*>(frame->parent()). \sa childFrames()*/QWebFrame *QWebFrame::parentFrame() const{ return d->parentFrame();}/*! Returns a list of all frames that are direct children of this frame. \sa parentFrame()*/QList<QWebFrame*> QWebFrame::childFrames() const{ QList<QWebFrame*> rc; if (d->frame) { FrameTree *tree = d->frame->tree(); for (Frame *child = tree->firstChild(); child; child = child->tree()->nextSibling()) { FrameLoader *loader = child->loader(); FrameLoaderClientQt *client = static_cast<FrameLoaderClientQt*>(loader->client()); if (client) rc.append(client->webFrame()); } } return rc;}/*! Returns the scrollbar policy for the scrollbar defined by \a orientation.*/Qt::ScrollBarPolicy QWebFrame::scrollBarPolicy(Qt::Orientation orientation) const{ if (orientation == Qt::Horizontal) return d->horizontalScrollBarPolicy; return d->verticalScrollBarPolicy;}/*! Sets the scrollbar policy for the scrollbar defined by \a orientation to \a policy.*/void QWebFrame::setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy){ Q_ASSERT((int)ScrollbarAuto == (int)Qt::ScrollBarAsNeeded); Q_ASSERT((int)ScrollbarAlwaysOff == (int)Qt::ScrollBarAlwaysOff); Q_ASSERT((int)ScrollbarAlwaysOn == (int)Qt::ScrollBarAlwaysOn); if (orientation == Qt::Horizontal) { d->horizontalScrollBarPolicy = policy; if (d->frame->view()) { d->frame->view()->setHorizontalScrollbarMode((ScrollbarMode)policy); d->frame->view()->updateDefaultScrollbarState(); } } else { d->verticalScrollBarPolicy = policy; if (d->frame->view()) { d->frame->view()->setVerticalScrollbarMode((ScrollbarMode)policy); d->frame->view()->updateDefaultScrollbarState(); } }}/*! Sets the current \a value for the scrollbar with orientation \a orientation. The scrollbar forces the \a value to be within the legal range: minimum <= value <= maximum. Changing the value also updates the thumb position. \sa scrollBarMinimum(), scrollBarMaximum()*/void QWebFrame::setScrollBarValue(Qt::Orientation orientation, int value){ Scrollbar *sb; sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); if (sb) { if (value < 0) value = 0; else if (value > scrollBarMaximum(orientation)) value = scrollBarMaximum(orientation); sb->setValue(value); }}/*! Returns the current value for the scrollbar with orientation \a orientation, or 0 if no scrollbar is found for \a orientation. \sa scrollBarMinimum(), scrollBarMaximum()*/int QWebFrame::scrollBarValue(Qt::Orientation orientation) const{ Scrollbar *sb; sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); if (sb) { return sb->value(); } return 0;}/*! Returns the maximum value for the scrollbar with orientation \a orientation, or 0 if no scrollbar is found for \a orientation. \sa scrollBarMinimum()*/int QWebFrame::scrollBarMaximum(Qt::Orientation orientation) const{ Scrollbar *sb; sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); if (sb) return sb->maximum(); return 0;}/*! Returns the minimum value for the scrollbar with orientation \a orientation. The minimum value is always 0. \sa scrollBarMaximum()*/int QWebFrame::scrollBarMinimum(Qt::Orientation orientation) const{ return 0;}/*! \since 4.6 Returns the geometry for the scrollbar with orientation \a orientation. If the scrollbar does not exist an empty rect is returned.*/QRect QWebFrame::scrollBarGeometry(Qt::Orientation orientation) const{ Scrollbar *sb; sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); if (sb) return sb->frameRect(); return QRect();}/*! \since 4.5 Scrolls the frame \a dx pixels to the right and \a dy pixels downward. Both \a dx and \a dy may be negative. \sa QWebFrame::scrollPosition*/void QWebFrame::scroll(int dx, int dy){ if (!d->frame->view()) return; d->frame->view()->scrollBy(IntSize(dx, dy));}/*! \property QWebFrame::scrollPosition \since 4.5 \brief the position the frame is currently scrolled to.*/QPoint QWebFrame::scrollPosition() const{ if (!d->frame->view()) return QPoint(0,0); IntSize ofs = d->frame->view()->scrollOffset(); return QPoint(ofs.width(), ofs.height());}void QWebFrame::setScrollPosition(const QPoint &pos){ QPoint current = scrollPosition(); int dx = pos.x() - current.x(); int dy = pos.y() - current.y(); scroll(dx, dy);}/*! Render the frame into \a painter clipping to \a clip. \sa print()*/void QWebFrame::render(QPainter *painter, const QRegion &clip){ d->renderPrivate(painter, clip);}/*! Render the frame into \a painter.*/void QWebFrame::render(QPainter *painter){ if (!d->frame->view()) return; d->renderPrivate(painter, QRegion(d->frame->view()->frameRect()));}/*! \since 4.6 Render the frame's \a contents into \a painter while clipping to \a contents.*/void QWebFrame::renderContents(QPainter *painter, const QRegion &contents){ d->renderPrivate(painter, contents, true);}/*! \property QWebFrame::textSizeMultiplier \brief the scaling factor for all text in the frame \obsolete Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in QWebSettings. \note Setting this property also enables the ZoomTextOnly attribute in QWebSettings.*//*! Sets the value of the multiplier used to scale the text in a Web frame to the \a factor specified.*/void QWebFrame::setTextSizeMultiplier(qreal factor){ d->frame->setZoomFactor(factor, /*isTextOnly*/true);}/*! Returns the value of the multiplier used to scale the text in a Web frame.*/qreal QWebFrame::textSizeMultiplier() const{ return d->frame->zoomFactor();}/*! \property QWebFrame::zoomFactor \since 4.5 \brief the zoom factor for the frame*/void QWebFrame::setZoomFactor(qreal factor){ d->frame->setZoomFactor(factor, d->frame->isZoomFactorTextOnly());}qreal QWebFrame::zoomFactor() const{ return d->frame->zoomFactor();}/*! Returns the position of the frame relative to it's parent frame.*/QPoint QWebFrame::pos() const{ if (!d->frame->view()) return QPoint(); return d->frame->view()->frameRect().topLeft();}/*! Return the geometry of the frame relative to it's parent frame.*/QRect QWebFrame::geometry() const{ if (!d->frame->view()) return QRect(); return d->frame->view()->frameRect();}/*! \property QWebFrame::contentsSize \brief the size of the contents in this frame \sa contentsSizeChanged*/QSize QWebFrame::contentsSize() const{ FrameView *view = d->frame->view(); if (!view) return QSize(); return QSize(view->contentsWidth(), view->contentsHeight());}/*! Performs a hit test on the frame contents at the given position \a pos and returns the hit test result.*/QWebHitTestResult QWebFrame::hitTestContent(const QPoint &pos) const{ if (!d->frame->view() || !d->frame->contentRenderer()) return QWebHitTestResult(); HitTestResult result = d->frame->eventHandler()->hitTestResultAtPoint(d->frame->view()->windowToContents(pos), /*allowShadowContent*/ false, /*ignoreClipping*/ true); return QWebHitTestResult(new QWebHitTestResultPrivate(result));}/*! \reimp*/bool QWebFrame::event(QEvent *e){ return QObject::event(e);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -