2 Copyright (C) 2008,2009 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2007 Staikos Computing Services Inc.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "qwebframe.h"
26 #include "BridgeJSC.h"
27 #include "CallFrame.h"
29 #include "V8Binding.h"
32 #include "DocumentLoader.h"
35 #include "FocusController.h"
37 #include "FrameLoaderClientQt.h"
38 #include "FrameSelection.h"
39 #include "FrameTree.h"
40 #include "FrameView.h"
42 #include "GCController.h"
44 #include "V8GCController.h"
46 #include "GraphicsContext.h"
47 #include "HTMLMetaElement.h"
48 #include "HitTestResult.h"
49 #include "HTTPParsers.h"
50 #include "IconDatabase.h"
51 #include "InspectorController.h"
53 #include "JavaScript.h"
54 #include "JSDOMBinding.h"
55 #include "JSDOMWindowBase.h"
58 #include "JSRetainPtr.h"
59 #include "OpaqueJSString.h"
61 #include "V8DOMWrapper.h"
62 #include "V8DOMWindowShell.h"
64 #include "NetworkingContext.h"
67 #include "PlatformMouseEvent.h"
68 #include "PlatformWheelEvent.h"
69 #include "PrintContext.h"
71 #include "PutPropertySlot.h"
73 #include "RenderLayer.h"
74 #include "RenderTreeAsText.h"
75 #include "RenderView.h"
76 #include "ResourceRequest.h"
77 #include "ScriptController.h"
78 #include "ScriptSourceCode.h"
79 #include "ScriptValue.h"
80 #include "Scrollbar.h"
82 #include "SubstituteData.h"
83 #include "SVGSMILElement.h"
84 #include "TiledBackingStore.h"
85 #include "htmlediting.h"
88 #include "qt_instance.h"
89 #include "qt_runtime.h"
91 #include "qwebelement.h"
92 #include "qwebframe_p.h"
94 #include "qwebpage_p.h"
95 #include "qwebsecurityorigin.h"
96 #include "qwebsecurityorigin_p.h"
97 #include "qwebscriptworld.h"
98 #include "qwebscriptworld_p.h"
100 #include "runtime_object.h"
101 #include "runtime_root.h"
103 #if USE(TEXTURE_MAPPER)
104 #include "texmap/TextureMapper.h"
105 #include "texmap/TextureMapperNode.h"
107 #include "wtf/HashMap.h"
111 #include <qfileinfo.h>
112 #include <qpainter.h>
113 #include <qprinter.h>
115 #include <qnetworkrequest.h>
117 using namespace WebCore;
119 // from text/qfont.cpp
121 extern Q_GUI_EXPORT int qt_defaultDpi();
124 bool QWEBKIT_EXPORT qtwebkit_webframe_scrollOverflow(QWebFrame* qFrame, int dx, int dy, const QPoint& pos)
126 WebCore::Frame* frame = QWebFramePrivate::core(qFrame);
127 if (!frame || !frame->document() || !frame->view() || !frame->eventHandler())
130 QPoint contentsPos = frame->view()->windowToContents(pos);
131 Node* node = frame->document()->elementFromPoint(contentsPos.x(), contentsPos.y());
135 RenderObject* renderer = node->renderer();
139 if (renderer->isListBox())
142 RenderLayer* renderLayer = renderer->enclosingLayer();
146 bool scrolledHorizontal = false;
147 bool scrolledVertical = false;
151 scrolledHorizontal = renderLayer->scroll(ScrollRight, ScrollByPixel, dx);
153 scrolledHorizontal = renderLayer->scroll(ScrollLeft, ScrollByPixel, qAbs(dx));
156 scrolledVertical = renderLayer->scroll(ScrollDown, ScrollByPixel, dy);
158 scrolledVertical = renderLayer->scroll(ScrollUp, ScrollByPixel, qAbs(dy));
160 if (scrolledHorizontal || scrolledVertical)
163 renderLayer = renderLayer->parent();
164 } while (renderLayer);
172 Scrolls nested frames starting at this frame, \a dx pixels to the right
173 and \a dy pixels downward. Both \a dx and \a dy may be negative. First attempts
174 to scroll elements with CSS overflow at position pos, followed by this frame. If this
175 frame doesn't scroll, attempts to scroll the parent
177 void QWEBKIT_EXPORT qtwebkit_webframe_scrollRecursively(QWebFrame* qFrame, int dx, int dy, const QPoint& pos)
182 if (qtwebkit_webframe_scrollOverflow(qFrame, dx, dy, pos))
185 bool scrollHorizontal = false;
186 bool scrollVertical = false;
189 if (dx > 0) // scroll right
190 scrollHorizontal = qFrame->scrollBarValue(Qt::Horizontal) < qFrame->scrollBarMaximum(Qt::Horizontal);
191 else if (dx < 0) // scroll left
192 scrollHorizontal = qFrame->scrollBarValue(Qt::Horizontal) > qFrame->scrollBarMinimum(Qt::Horizontal);
194 if (dy > 0) // scroll down
195 scrollVertical = qFrame->scrollBarValue(Qt::Vertical) < qFrame->scrollBarMaximum(Qt::Vertical);
196 else if (dy < 0) //scroll up
197 scrollVertical = qFrame->scrollBarValue(Qt::Vertical) > qFrame->scrollBarMinimum(Qt::Vertical);
199 if (scrollHorizontal || scrollVertical) {
200 qFrame->scroll(dx, dy);
204 qFrame = qFrame->parentFrame();
208 static inline ResourceRequestCachePolicy cacheLoadControlToCachePolicy(uint cacheLoadControl)
210 switch (cacheLoadControl) {
211 case QNetworkRequest::AlwaysNetwork:
212 return WebCore::ReloadIgnoringCacheData;
213 case QNetworkRequest::PreferCache:
214 return WebCore::ReturnCacheDataElseLoad;
215 case QNetworkRequest::AlwaysCache:
216 return WebCore::ReturnCacheDataDontLoad;
220 return WebCore::UseProtocolCachePolicy;
223 QWebFrameData::QWebFrameData(WebCore::Page* parentPage, WebCore::Frame* parentFrame,
224 WebCore::HTMLFrameOwnerElement* ownerFrameElement,
225 const WTF::String& frameName)
227 , ownerElement(ownerFrameElement)
229 , allowsScrolling(true)
233 frameLoaderClient = new FrameLoaderClientQt();
234 frame = Frame::create(page, ownerElement, frameLoaderClient);
236 // FIXME: All of the below should probably be moved over into WebCore
237 frame->tree()->setName(name);
239 parentFrame->tree()->appendChild(frame);
242 void QWebFramePrivate::init(QWebFrame *qframe, QWebFrameData *frameData)
246 allowsScrolling = frameData->allowsScrolling;
247 marginWidth = frameData->marginWidth;
248 marginHeight = frameData->marginHeight;
249 frame = frameData->frame.get();
250 frameLoaderClient = frameData->frameLoaderClient;
251 frameLoaderClient->setFrame(qframe, frame);
256 void QWebFramePrivate::setPage(QWebPage* newPage)
261 // The QWebFrame is created as a child of QWebPage or a parent QWebFrame.
262 // That adds it to QObject's internal children list and ensures it will be
263 // deleted when parent QWebPage is deleted. Reparent if needed.
264 if (q->parent() == qobject_cast<QObject*>(page))
265 q->setParent(newPage);
268 emit q->pageChanged();
271 WebCore::Scrollbar* QWebFramePrivate::horizontalScrollBar() const
275 return frame->view()->horizontalScrollbar();
278 WebCore::Scrollbar* QWebFramePrivate::verticalScrollBar() const
282 return frame->view()->verticalScrollbar();
285 #if ENABLE(TILED_BACKING_STORE)
286 void QWebFramePrivate::renderFromTiledBackingStore(GraphicsContext* context, const QRegion& clip)
288 ASSERT(frame->tiledBackingStore());
290 if (!frame->view() || !frame->contentRenderer())
293 QVector<QRect> vector = clip.rects();
294 if (vector.isEmpty())
297 QPainter* painter = context->platformContext();
299 WebCore::FrameView* view = frame->view();
301 int scrollX = view->scrollX();
302 int scrollY = view->scrollY();
303 context->translate(-scrollX, -scrollY);
305 for (int i = 0; i < vector.size(); ++i) {
306 const QRect& clipRect = vector.at(i);
310 QRect rect = clipRect.translated(scrollX, scrollY);
311 painter->setClipRect(rect, Qt::IntersectClip);
313 frame->tiledBackingStore()->paint(context, rect);
318 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
319 renderCompositedLayers(context, IntRect(clip.boundingRect()));
320 renderFrameExtras(context, QFlags<QWebFrame::RenderLayer>(QWebFrame::ScrollBarLayer) | QWebFrame::PanIconLayer, clip);
325 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
326 void QWebFramePrivate::renderCompositedLayers(GraphicsContext* context, const IntRect& clip)
328 if (!rootTextureMapperNode || !textureMapper)
331 textureMapper->setGraphicsContext(context);
332 textureMapper->setImageInterpolationQuality(context->imageInterpolationQuality());
333 textureMapper->setTextDrawingMode(context->textDrawingMode());
334 textureMapper->setViewportSize(frame->view()->frameRect().size());
335 QPainter* painter = context->platformContext();
336 const QTransform transform = painter->worldTransform();
337 const TransformationMatrix matrix(
338 transform.m11(), transform.m12(), 0, transform.m13(),
339 transform.m21(), transform.m22(), 0, transform.m23(),
341 transform.m31(), transform.m32(), 0, transform.m33()
343 rootTextureMapperNode->setTransform(matrix);
344 rootTextureMapperNode->setOpacity(painter->opacity());
345 textureMapper->beginPainting();
346 textureMapper->beginClip(matrix, clip);
347 rootTextureMapperNode->paint();
348 textureMapper->endClip();
349 textureMapper->endPainting();
353 void QWebFramePrivate::renderRelativeCoords(GraphicsContext* context, QFlags<QWebFrame::RenderLayer> layers, const QRegion& clip)
355 if (!frame->view() || !frame->contentRenderer())
358 QVector<QRect> vector = clip.rects();
359 if (vector.isEmpty())
362 QPainter* painter = context->platformContext();
364 WebCore::FrameView* view = frame->view();
365 view->updateLayoutAndStyleIfNeededRecursive();
367 if (layers & QWebFrame::ContentsLayer) {
368 for (int i = 0; i < vector.size(); ++i) {
369 const QRect& clipRect = vector.at(i);
371 QRect rect = clipRect.intersected(view->frameRect());
374 painter->setClipRect(clipRect, Qt::IntersectClip);
379 int scrollX = view->scrollX();
380 int scrollY = view->scrollY();
382 context->translate(x, y);
383 rect.translate(-x, -y);
384 context->translate(-scrollX, -scrollY);
385 rect.translate(scrollX, scrollY);
386 context->clip(view->visibleContentRect());
388 view->paintContents(context, rect);
392 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
393 renderCompositedLayers(context, IntRect(clip.boundingRect()));
396 renderFrameExtras(context, layers, clip);
397 #if ENABLE(INSPECTOR)
398 if (frame->page()->inspectorController()->highlightedNode()) {
400 frame->page()->inspectorController()->drawHighlight(*context);
406 void QWebFramePrivate::renderFrameExtras(GraphicsContext* context, QFlags<QWebFrame::RenderLayer> layers, const QRegion& clip)
408 if (!(layers & (QWebFrame::PanIconLayer | QWebFrame::ScrollBarLayer)))
410 QPainter* painter = context->platformContext();
411 WebCore::FrameView* view = frame->view();
412 QVector<QRect> vector = clip.rects();
413 for (int i = 0; i < vector.size(); ++i) {
414 const QRect& clipRect = vector.at(i);
416 QRect intersectedRect = clipRect.intersected(view->frameRect());
419 painter->setClipRect(clipRect, Qt::IntersectClip);
424 if (layers & QWebFrame::ScrollBarLayer
425 && !view->scrollbarsSuppressed()
426 && (view->horizontalScrollbar() || view->verticalScrollbar())) {
428 QRect rect = intersectedRect;
429 context->translate(x, y);
430 rect.translate(-x, -y);
431 view->paintScrollbars(context, rect);
432 context->translate(-x, -y);
435 #if ENABLE(PAN_SCROLLING)
436 if (layers & QWebFrame::PanIconLayer)
437 view->paintPanScrollIcon(context);
444 void QWebFramePrivate::emitUrlChanged()
446 url = frame->document()->url();
447 emit q->urlChanged(url);
450 void QWebFramePrivate::_q_orientationChanged()
452 #if ENABLE(ORIENTATION_EVENTS)
454 WebCore::Frame* frame = core(q);
456 switch (m_orientation.reading()->orientation()) {
457 case QtMobility::QOrientationReading::TopUp:
460 case QtMobility::QOrientationReading::TopDown:
463 case QtMobility::QOrientationReading::LeftUp:
466 case QtMobility::QOrientationReading::RightUp:
469 case QtMobility::QOrientationReading::FaceUp:
470 case QtMobility::QOrientationReading::FaceDown:
471 // WebCore unable to handle it
475 frame->sendOrientationChangeEvent(orientation);
479 void QWebFramePrivate::didClearWindowObject()
482 if (page->settings()->testAttribute(QWebSettings::JavascriptEnabled))
483 addQtSenderToGlobalObject();
485 emit q->javaScriptWindowObjectCleared();
489 static JSValueRef qtSenderCallback(JSContextRef context, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef*)
491 QObject* sender = JSC::Bindings::QtInstance::qtSenderStack()->top();
493 return JSValueMakeUndefined(context);
495 JSC::ExecState* exec = ::toJS(context);
496 RefPtr<JSC::Bindings::RootObject> rootObject = JSC::Bindings::findRootObject(exec->dynamicGlobalObject());
497 JSC::JSObject* jsSender = JSC::Bindings::QtInstance::getQtInstance(sender, rootObject, QScriptEngine::QtOwnership)->createRuntimeObject(exec);
498 return ::toRef(jsSender);
501 void QWebFramePrivate::addQtSenderToGlobalObject()
503 JSC::JSLock lock(JSC::SilenceAssertionsOnly);
505 JSDOMWindow* window = toJSDOMWindow(frame, mainThreadNormalWorld());
508 JSC::ExecState* exec = window->globalExec();
511 JSContextRef context = ::toRef(exec);
512 JSRetainPtr<JSStringRef> propertyName(Adopt, JSStringCreateWithUTF8CString("__qt_sender__"));
513 JSObjectRef function = JSObjectMakeFunctionWithCallback(context, propertyName.get(), qtSenderCallback);
515 // JSC public API doesn't support setting a Getter for a property of a given object, https://bugs.webkit.org/show_bug.cgi?id=61374.
516 window->defineGetter(exec, propertyName.get()->identifier(&exec->globalData()), ::toJS(function),
517 JSC::ReadOnly | JSC::DontEnum | JSC::DontDelete);
524 \brief The QWebFrame class represents a frame in a web page.
528 QWebFrame represents a frame inside a web page. Each QWebPage
529 object contains at least one frame, the main frame, obtained using
530 QWebPage::mainFrame(). Additional frames will be created for HTML
531 \c{<frame>} or \c{<iframe>} elements.
533 A frame can be loaded using load() or setUrl(). Alternatively, if you have
534 the HTML content readily available, you can use setHtml() instead.
536 The page() function returns a pointer to the web page object. See
537 \l{QWebView}{Elements of QWebView} for an explanation of how web
538 frames are related to a web page and web view.
540 The QWebFrame class also offers methods to retrieve both the URL currently
541 loaded by the frame (see url()) as well as the URL originally requested
542 to be loaded (see requestedUrl()). These methods make possible the retrieval
543 of the URL before and after a DNS resolution or a redirection occurs during
544 the load process. The requestedUrl() also matches to the URL added to the
545 frame history (\l{QWebHistory}) if load is successful.
547 The title of an HTML frame can be accessed with the title() property.
548 Additionally, a frame may also specify an icon, which can be accessed
549 using the icon() property. If the title or the icon changes, the
550 corresponding titleChanged() and iconChanged() signals will be emitted.
551 The zoomFactor() property can be used to change the overall size
552 of the content displayed in the frame.
554 QWebFrame objects are created and controlled by the web page. You
555 can connect to the web page's \l{QWebPage::}{frameCreated()} signal
556 to be notified when a new frame is created.
558 There are multiple ways to programmatically examine the contents of a frame.
559 The hitTestContent() function can be used to find elements by coordinate.
560 For access to the underlying DOM tree, there is documentElement(),
561 findAllElements() and findFirstElement().
563 A QWebFrame can be printed onto a QPrinter using the print() function.
564 This function is marked as a slot and can be conveniently connected to
565 \l{QPrintPreviewDialog}'s \l{QPrintPreviewDialog::}{paintRequested()}
572 \enum QWebFrame::RenderLayer
574 This enum describes the layers available for rendering using \l{QWebFrame::}{render()}.
575 The layers can be OR-ed together from the following list:
577 \value ContentsLayer The web content of the frame
578 \value ScrollBarLayer The scrollbars of the frame
579 \value PanIconLayer The icon used when panning the frame
581 \value AllLayers Includes all the above layers
584 QWebFrame::QWebFrame(QWebPage *parent, QWebFrameData *frameData)
586 , d(new QWebFramePrivate)
589 d->init(this, frameData);
591 if (!frameData->url.isEmpty()) {
592 WebCore::ResourceRequest request(frameData->url, frameData->referrer);
593 d->frame->loader()->load(request, frameData->name, false);
595 #if ENABLE(ORIENTATION_EVENTS)
596 connect(&d->m_orientation, SIGNAL(readingChanged()), this, SLOT(_q_orientationChanged()));
597 d->m_orientation.start();
601 QWebFrame::QWebFrame(QWebFrame *parent, QWebFrameData *frameData)
603 , d(new QWebFramePrivate)
605 d->page = parent->d->page;
606 d->init(this, frameData);
607 #if ENABLE(ORIENTATION_EVENTS)
608 connect(&d->m_orientation, SIGNAL(readingChanged()), this, SLOT(_q_orientationChanged()));
609 d->m_orientation.start();
613 QWebFrame::~QWebFrame()
615 if (d->frame && d->frame->loader() && d->frame->loader()->client())
616 static_cast<FrameLoaderClientQt*>(d->frame->loader()->client())->m_webFrame = 0;
622 Make \a object available under \a name from within the frame's JavaScript
623 context. The \a object will be inserted as a child of the frame's window
626 Qt properties will be exposed as JavaScript properties and slots as
628 The interaction between C++ and JavaScript is explained in the documentation of the \l{The QtWebKit Bridge}{QtWebKit bridge}.
630 If you want to ensure that your QObjects remain accessible after loading a
631 new URL, you should add them in a slot connected to the
632 javaScriptWindowObjectCleared() signal.
634 If Javascript is not enabled for this page, then this method does nothing.
636 The \a object will never be explicitly deleted by QtWebKit.
638 void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object)
640 addToJavaScriptWindowObject(name, object, QScriptEngine::QtOwnership);
644 \fn void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership own)
647 Make \a object available under \a name from within the frame's JavaScript
648 context. The \a object will be inserted as a child of the frame's window
651 Qt properties will be exposed as JavaScript properties and slots as
653 The interaction between C++ and JavaScript is explained in the documentation of the \l{The QtWebKit Bridge}{QtWebKit bridge}.
655 If you want to ensure that your QObjects remain accessible after loading a
656 new URL, you should add them in a slot connected to the
657 javaScriptWindowObjectCleared() signal.
659 If Javascript is not enabled for this page, then this method does nothing.
661 The ownership of \a object is specified using \a own.
663 void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership)
665 if (!page()->settings()->testAttribute(QWebSettings::JavascriptEnabled))
668 JSC::JSLock lock(JSC::SilenceAssertionsOnly);
669 JSDOMWindow* window = toJSDOMWindow(d->frame, mainThreadNormalWorld());
670 JSC::Bindings::RootObject* root;
671 if (ownership == QScriptEngine::QtOwnership)
672 root = d->frame->script()->cacheableBindingRootObject();
674 root = d->frame->script()->bindingRootObject();
677 qDebug() << "Warning: couldn't get window object";
681 qDebug() << "Warning: couldn't get root object";
685 JSC::ExecState* exec = window->globalExec();
687 JSC::JSObject* runtimeObject =
688 JSC::Bindings::QtInstance::getQtInstance(object, root, ownership)->createRuntimeObject(exec);
690 JSC::PutPropertySlot slot;
691 window->put(exec, JSC::Identifier(exec, reinterpret_cast_ptr<const UChar*>(name.constData()), name.length()), runtimeObject, slot);
693 QScriptEngine* engine = d->frame->script()->qtScriptEngine();
696 QScriptValue v = engine->newQObject(object, ownership);
697 engine->globalObject().property(QLatin1String("window")).setProperty(name, v);
702 Returns the frame's content as HTML, enclosed in HTML and BODY tags.
704 \sa setHtml(), toPlainText()
706 QString QWebFrame::toHtml() const
708 if (!d->frame->document())
710 return createMarkup(d->frame->document());
714 Returns the content of this frame converted to plain text, completely
715 stripped of all HTML formatting.
719 QString QWebFrame::toPlainText() const
721 if (d->frame->view() && d->frame->view()->layoutPending())
722 d->frame->view()->layout();
724 Element *documentElement = d->frame->document()->documentElement();
726 return documentElement->innerText();
731 Returns a dump of the rendering tree. This is mainly useful for debugging
734 QString QWebFrame::renderTreeDump() const
736 if (d->frame->view() && d->frame->view()->layoutPending())
737 d->frame->view()->layout();
739 return externalRepresentation(d->frame);
743 \property QWebFrame::title
744 \brief the title of the frame as defined by the HTML <title> element
749 QString QWebFrame::title() const
751 if (d->frame->document())
752 return d->frame->loader()->documentLoader()->title().string();
758 \brief Returns the meta data in this frame as a QMultiMap
760 The meta data consists of the name and content attributes of the
761 of the \c{<meta>} tags in the HTML document.
768 <meta name="description" content="This document is a tutorial about Qt development">
769 <meta name="keywords" content="Qt, WebKit, Programming">
775 Given the above HTML code the metaData() function will return a map with two entries:
779 \row \o "description"
780 \o "This document is a tutorial about Qt development"
782 \o "Qt, WebKit, Programming"
785 This function returns a multi map to support multiple meta tags with the same attribute name.
787 QMultiMap<QString, QString> QWebFrame::metaData() const
789 if (!d->frame->document())
790 return QMap<QString, QString>();
792 QMultiMap<QString, QString> map;
793 Document* doc = d->frame->document();
794 RefPtr<NodeList> list = doc->getElementsByTagName("meta");
795 unsigned len = list->length();
796 for (unsigned i = 0; i < len; i++) {
797 HTMLMetaElement* meta = static_cast<HTMLMetaElement*>(list->item(i));
798 map.insert(meta->name(), meta->content());
803 static inline void clearCoreFrame(WebCore::Frame* frame)
805 WebCore::DocumentLoader* documentLoader = frame->loader()->activeDocumentLoader();
806 Q_ASSERT(documentLoader);
807 documentLoader->writer()->begin();
808 documentLoader->writer()->end();
811 static inline bool isCoreFrameClear(WebCore::Frame* frame)
813 return frame->document()->url().isEmpty();
816 static inline QUrl ensureAbsoluteUrl(const QUrl &url)
818 if (!url.isValid() || !url.isRelative())
821 // This contains the URL with absolute path but without
822 // the query and the fragment part.
823 QUrl baseUrl = QUrl::fromLocalFile(QFileInfo(url.toLocalFile()).absoluteFilePath());
825 // The path is removed so the query and the fragment parts are there.
826 QString pathRemoved = url.toString(QUrl::RemovePath);
827 QUrl toResolve(pathRemoved);
829 return baseUrl.resolved(toResolve);
833 \property QWebFrame::url
834 \brief the url of the frame currently viewed
836 Setting this property clears the view and loads the URL.
838 By default, this property contains an empty, invalid URL.
843 void QWebFrame::setUrl(const QUrl &url)
845 clearCoreFrame(d->frame);
846 const QUrl absolute = ensureAbsoluteUrl(url);
851 QUrl QWebFrame::url() const
858 \property QWebFrame::requestedUrl
860 The URL requested to loaded by the frame currently viewed. The URL may differ from
861 the one returned by url() if a DNS resolution or a redirection occurs.
865 QUrl QWebFrame::requestedUrl() const
867 return d->frameLoaderClient->lastRequestedUrl();
871 \property QWebFrame::baseUrl
872 \brief the base URL of the frame, can be used to resolve relative URLs
876 QUrl QWebFrame::baseUrl() const
878 if (isCoreFrameClear(d->frame))
879 return QUrl(d->url).resolved(QUrl());
880 return d->frame->document()->baseURL();
884 \property QWebFrame::icon
885 \brief the icon associated with this frame
887 \sa iconChanged(), QWebSettings::iconForUrl()
890 QIcon QWebFrame::icon() const
892 return QWebSettings::iconForUrl(d->frame->document()->url());
896 The name of this frame as defined by the parent frame.
898 QString QWebFrame::frameName() const
900 return d->frame->tree()->uniqueName();
904 The web page that contains this frame.
908 QWebPage *QWebFrame::page() const
914 Loads \a url into this frame.
916 \note The view remains the same until enough data has arrived to display the new \a url.
918 \sa setUrl(), setHtml(), setContent()
920 void QWebFrame::load(const QUrl &url)
922 // The load() overload ensures that the url is absolute.
923 load(QNetworkRequest(url));
927 Loads a network request, \a req, into this frame, using the method specified in \a
930 \a body is optional and is only used for POST operations.
932 \note The view remains the same until enough data has arrived to display the new content.
936 void QWebFrame::load(const QNetworkRequest &req,
937 QNetworkAccessManager::Operation operation,
938 const QByteArray &body)
940 if (d->parentFrame())
941 d->page->d->insideOpenCall = true;
943 QUrl url = ensureAbsoluteUrl(req.url());
945 WebCore::ResourceRequest request(url);
948 case QNetworkAccessManager::HeadOperation:
949 request.setHTTPMethod("HEAD");
951 case QNetworkAccessManager::GetOperation:
952 request.setHTTPMethod("GET");
954 case QNetworkAccessManager::PutOperation:
955 request.setHTTPMethod("PUT");
957 case QNetworkAccessManager::PostOperation:
958 request.setHTTPMethod("POST");
960 case QNetworkAccessManager::DeleteOperation:
961 request.setHTTPMethod("DELETE");
963 case QNetworkAccessManager::CustomOperation:
964 request.setHTTPMethod(req.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray().constData());
966 case QNetworkAccessManager::UnknownOperation:
971 QVariant cacheLoad = req.attribute(QNetworkRequest::CacheLoadControlAttribute);
972 if (cacheLoad.isValid()) {
974 uint cacheLoadValue = cacheLoad.toUInt(&ok);
976 request.setCachePolicy(cacheLoadControlToCachePolicy(cacheLoadValue));
979 QList<QByteArray> httpHeaders = req.rawHeaderList();
980 for (int i = 0; i < httpHeaders.size(); ++i) {
981 const QByteArray &headerName = httpHeaders.at(i);
982 request.addHTTPHeaderField(QString::fromLatin1(headerName), QString::fromLatin1(req.rawHeader(headerName)));
986 request.setHTTPBody(WebCore::FormData::create(body.constData(), body.size()));
988 d->frame->loader()->load(request, false);
990 if (d->parentFrame())
991 d->page->d->insideOpenCall = false;
995 Sets the content of this frame to \a html. \a baseUrl is optional and used to resolve relative
996 URLs in the document, such as referenced images or stylesheets.
998 The \a html is loaded immediately; external objects are loaded asynchronously.
1000 If a script in the \a html runs longer than the default script timeout (currently 10 seconds),
1001 for example due to being blocked by a modal JavaScript alert dialog, this method will return
1002 as soon as possible after the timeout and any subsequent \a html will be loaded asynchronously.
1004 When using this method WebKit assumes that external resources such as JavaScript programs or style
1005 sheets are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external
1006 script can be specified through the charset attribute of the HTML script tag. It is also possible
1007 for the encoding to be specified by web server.
1009 This is a convenience function equivalent to setContent(html, "text/html", baseUrl).
1011 \note This method will not affect session or global history for the frame.
1013 \warning This function works only for HTML, for other mime types (i.e. XHTML, SVG)
1014 setContent() should be used instead.
1016 \sa toHtml(), setContent(), load()
1018 void QWebFrame::setHtml(const QString &html, const QUrl &baseUrl)
1021 WebCore::ResourceRequest request(kurl);
1022 const QByteArray utf8 = html.toUtf8();
1023 WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length());
1024 WebCore::SubstituteData substituteData(data, WTF::String("text/html"), WTF::String("utf-8"), KURL());
1025 d->frame->loader()->load(request, substituteData, false);
1029 Sets the content of this frame to the specified content \a data. If the \a mimeType argument
1030 is empty it is currently assumed that the content is HTML but in future versions we may introduce
1033 External objects referenced in the content are located relative to \a baseUrl.
1035 The \a data is loaded immediately; external objects are loaded asynchronously.
1037 \note This method will not affect session or global history for the frame.
1039 \sa toHtml(), setHtml()
1041 void QWebFrame::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
1044 WebCore::ResourceRequest request(kurl);
1045 WTF::RefPtr<WebCore::SharedBuffer> buffer = WebCore::SharedBuffer::create(data.constData(), data.length());
1046 QString actualMimeType;
1047 WTF::String encoding;
1048 if (mimeType.isEmpty())
1049 actualMimeType = QLatin1String("text/html");
1051 actualMimeType = extractMIMETypeFromMediaType(mimeType);
1052 encoding = extractCharsetFromMediaType(mimeType);
1054 WebCore::SubstituteData substituteData(buffer, WTF::String(actualMimeType), encoding, KURL());
1055 d->frame->loader()->load(request, substituteData, false);
1059 Returns the parent frame of this frame, or 0 if the frame is the web pages
1062 This is equivalent to qobject_cast<QWebFrame*>(frame->parent()).
1066 QWebFrame *QWebFrame::parentFrame() const
1068 return d->parentFrame();
1072 Returns a list of all frames that are direct children of this frame.
1076 QList<QWebFrame*> QWebFrame::childFrames() const
1078 QList<QWebFrame*> rc;
1080 FrameTree *tree = d->frame->tree();
1081 for (Frame *child = tree->firstChild(); child; child = child->tree()->nextSibling()) {
1082 FrameLoader *loader = child->loader();
1083 QWebFrame* webFrame = qobject_cast<QWebFrame*>(loader->networkingContext()->originatingObject());
1085 rc.append(webFrame);
1093 Returns the scrollbar policy for the scrollbar defined by \a orientation.
1095 Qt::ScrollBarPolicy QWebFrame::scrollBarPolicy(Qt::Orientation orientation) const
1097 if (orientation == Qt::Horizontal)
1098 return d->horizontalScrollBarPolicy;
1099 return d->verticalScrollBarPolicy;
1103 Sets the scrollbar policy for the scrollbar defined by \a orientation to \a policy.
1105 void QWebFrame::setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
1107 Q_ASSERT((int)ScrollbarAuto == (int)Qt::ScrollBarAsNeeded);
1108 Q_ASSERT((int)ScrollbarAlwaysOff == (int)Qt::ScrollBarAlwaysOff);
1109 Q_ASSERT((int)ScrollbarAlwaysOn == (int)Qt::ScrollBarAlwaysOn);
1111 if (orientation == Qt::Horizontal) {
1112 d->horizontalScrollBarPolicy = policy;
1113 if (d->frame->view()) {
1114 d->frame->view()->setHorizontalScrollbarMode((ScrollbarMode)policy, policy != Qt::ScrollBarAsNeeded /* lock */);
1115 d->frame->view()->updateCanHaveScrollbars();
1118 d->verticalScrollBarPolicy = policy;
1119 if (d->frame->view()) {
1120 d->frame->view()->setVerticalScrollbarMode((ScrollbarMode)policy, policy != Qt::ScrollBarAsNeeded /* lock */);
1121 d->frame->view()->updateCanHaveScrollbars();
1127 Sets the current \a value for the scrollbar with orientation \a orientation.
1129 The scrollbar forces the \a value to be within the legal range: minimum <= value <= maximum.
1131 Changing the value also updates the thumb position.
1133 \sa scrollBarMinimum(), scrollBarMaximum()
1135 void QWebFrame::setScrollBarValue(Qt::Orientation orientation, int value)
1138 sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
1142 else if (value > scrollBarMaximum(orientation))
1143 value = scrollBarMaximum(orientation);
1144 sb->scrollableArea()->scrollToOffsetWithoutAnimation(orientation == Qt::Horizontal ? HorizontalScrollbar : VerticalScrollbar, value);
1149 Returns the current value for the scrollbar with orientation \a orientation, or 0
1150 if no scrollbar is found for \a orientation.
1152 \sa scrollBarMinimum(), scrollBarMaximum()
1154 int QWebFrame::scrollBarValue(Qt::Orientation orientation) const
1157 sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
1164 Returns the maximum value for the scrollbar with orientation \a orientation, or 0
1165 if no scrollbar is found for \a orientation.
1167 \sa scrollBarMinimum()
1169 int QWebFrame::scrollBarMaximum(Qt::Orientation orientation) const
1172 sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
1174 return sb->maximum();
1179 Returns the minimum value for the scrollbar with orientation \a orientation.
1181 The minimum value is always 0.
1183 \sa scrollBarMaximum()
1185 int QWebFrame::scrollBarMinimum(Qt::Orientation orientation) const
1187 Q_UNUSED(orientation)
1193 Returns the geometry for the scrollbar with orientation \a orientation.
1195 If the scrollbar does not exist an empty rect is returned.
1197 QRect QWebFrame::scrollBarGeometry(Qt::Orientation orientation) const
1200 sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
1202 return sb->frameRect();
1208 Scrolls the frame \a dx pixels to the right and \a dy pixels downward. Both
1209 \a dx and \a dy may be negative.
1211 \sa QWebFrame::scrollPosition
1214 void QWebFrame::scroll(int dx, int dy)
1216 if (!d->frame->view())
1219 d->frame->view()->scrollBy(IntSize(dx, dy));
1223 \property QWebFrame::scrollPosition
1225 \brief the position the frame is currently scrolled to.
1228 QPoint QWebFrame::scrollPosition() const
1230 if (!d->frame->view())
1231 return QPoint(0, 0);
1233 IntSize ofs = d->frame->view()->scrollOffset();
1234 return QPoint(ofs.width(), ofs.height());
1237 void QWebFrame::setScrollPosition(const QPoint &pos)
1239 QPoint current = scrollPosition();
1240 int dx = pos.x() - current.x();
1241 int dy = pos.y() - current.y();
1247 Scrolls the frame to the given \a anchor name.
1249 void QWebFrame::scrollToAnchor(const QString& anchor)
1251 FrameView *view = d->frame->view();
1253 view->scrollToAnchor(anchor);
1258 Render the \a layer of the frame using \a painter clipping to \a clip.
1263 void QWebFrame::render(QPainter* painter, RenderLayer layer, const QRegion& clip)
1265 GraphicsContext context(painter);
1266 if (context.paintingDisabled() && !context.updatingControlTints())
1269 if (!clip.isEmpty())
1270 d->renderRelativeCoords(&context, layer, clip);
1271 else if (d->frame->view())
1272 d->renderRelativeCoords(&context, layer, QRegion(d->frame->view()->frameRect()));
1276 Render the frame into \a painter clipping to \a clip.
1278 void QWebFrame::render(QPainter* painter, const QRegion& clip)
1280 GraphicsContext context(painter);
1281 if (context.paintingDisabled() && !context.updatingControlTints())
1284 d->renderRelativeCoords(&context, AllLayers, clip);
1288 Render the frame into \a painter.
1290 void QWebFrame::render(QPainter* painter)
1292 if (!d->frame->view())
1295 GraphicsContext context(painter);
1296 if (context.paintingDisabled() && !context.updatingControlTints())
1299 d->renderRelativeCoords(&context, AllLayers, QRegion(d->frame->view()->frameRect()));
1303 \property QWebFrame::textSizeMultiplier
1304 \brief the scaling factor for all text in the frame
1307 Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in
1310 \note Setting this property also enables the ZoomTextOnly attribute in
1315 Sets the value of the multiplier used to scale the text in a Web frame to
1316 the \a factor specified.
1318 void QWebFrame::setTextSizeMultiplier(qreal factor)
1320 page()->settings()->setAttribute(QWebSettings::ZoomTextOnly, true);
1322 d->frame->setPageAndTextZoomFactors(1, factor);
1326 Returns the value of the multiplier used to scale the text in a Web frame.
1328 qreal QWebFrame::textSizeMultiplier() const
1330 return page()->settings()->testAttribute(QWebSettings::ZoomTextOnly) ? d->frame->textZoomFactor() : d->frame->pageZoomFactor();
1334 \property QWebFrame::zoomFactor
1336 \brief the zoom factor for the frame
1339 void QWebFrame::setZoomFactor(qreal factor)
1341 if (page()->settings()->testAttribute(QWebSettings::ZoomTextOnly))
1342 d->frame->setTextZoomFactor(factor);
1344 d->frame->setPageZoomFactor(factor);
1347 qreal QWebFrame::zoomFactor() const
1349 return page()->settings()->testAttribute(QWebSettings::ZoomTextOnly) ? d->frame->textZoomFactor() : d->frame->pageZoomFactor();
1353 \property QWebFrame::focus
1356 Returns true if this frame has keyboard input focus; otherwise, returns false.
1358 bool QWebFrame::hasFocus() const
1360 WebCore::Frame* ff = d->frame->page()->focusController()->focusedFrame();
1361 return ff && QWebFramePrivate::kit(ff) == this;
1367 Gives keyboard input focus to this frame.
1369 void QWebFrame::setFocus()
1371 QWebFramePrivate::core(this)->page()->focusController()->setFocusedFrame(QWebFramePrivate::core(this));
1375 Returns the position of the frame relative to it's parent frame.
1377 QPoint QWebFrame::pos() const
1379 if (!d->frame->view())
1382 return d->frame->view()->frameRect().location();
1386 Return the geometry of the frame relative to it's parent frame.
1388 QRect QWebFrame::geometry() const
1390 if (!d->frame->view())
1392 return d->frame->view()->frameRect();
1396 \property QWebFrame::contentsSize
1397 \brief the size of the contents in this frame
1399 \sa contentsSizeChanged()
1401 QSize QWebFrame::contentsSize() const
1403 FrameView *view = d->frame->view();
1406 return QSize(view->contentsWidth(), view->contentsHeight());
1412 Returns the document element of this frame.
1414 The document element provides access to the entire structured
1415 content of the frame.
1417 QWebElement QWebFrame::documentElement() const
1419 WebCore::Document *doc = d->frame->document();
1421 return QWebElement();
1422 return QWebElement(doc->documentElement());
1427 Returns a new list of elements matching the given CSS selector \a selectorQuery.
1428 If there are no matching elements, an empty list is returned.
1430 \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is
1433 \sa QWebElement::findAll()
1435 QWebElementCollection QWebFrame::findAllElements(const QString &selectorQuery) const
1437 return documentElement().findAll(selectorQuery);
1442 Returns the first element in the frame's document that matches the
1443 given CSS selector \a selectorQuery. If there is no matching element, a
1444 null element is returned.
1446 \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is
1449 \sa QWebElement::findFirst()
1451 QWebElement QWebFrame::findFirstElement(const QString &selectorQuery) const
1453 return documentElement().findFirst(selectorQuery);
1457 Performs a hit test on the frame contents at the given position \a pos and returns the hit test result.
1459 QWebHitTestResult QWebFrame::hitTestContent(const QPoint &pos) const
1461 if (!d->frame->view() || !d->frame->contentRenderer())
1462 return QWebHitTestResult();
1464 HitTestResult result = d->frame->eventHandler()->hitTestResultAtPoint(d->frame->view()->windowToContents(pos), /*allowShadowContent*/ false, /*ignoreClipping*/ true);
1466 if (result.scrollbar())
1467 return QWebHitTestResult();
1469 return QWebHitTestResult(new QWebHitTestResultPrivate(result));
1474 bool QWebFrame::event(QEvent *e)
1476 return QObject::event(e);
1479 #ifndef QT_NO_PRINTER
1481 Prints the frame to the given \a printer.
1485 void QWebFrame::print(QPrinter *printer) const
1488 if (!painter.begin(printer))
1491 const qreal zoomFactorX = (qreal)printer->logicalDpiX() / qt_defaultDpi();
1492 const qreal zoomFactorY = (qreal)printer->logicalDpiY() / qt_defaultDpi();
1494 PrintContext printContext(d->frame);
1495 float pageHeight = 0;
1497 QRect qprinterRect = printer->pageRect();
1499 IntRect pageRect(0, 0,
1500 int(qprinterRect.width() / zoomFactorX),
1501 int(qprinterRect.height() / zoomFactorY));
1503 printContext.begin(pageRect.width());
1505 printContext.computePageRects(pageRect, /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
1509 if (printer->collateCopies()) {
1511 pageCopies = printer->numCopies();
1513 docCopies = printer->numCopies();
1517 int fromPage = printer->fromPage();
1518 int toPage = printer->toPage();
1519 bool ascending = true;
1521 if (fromPage == 0 && toPage == 0) {
1523 toPage = printContext.pageCount();
1526 fromPage = qMax(1, fromPage);
1527 toPage = qMin(static_cast<int>(printContext.pageCount()), toPage);
1528 if (toPage < fromPage) {
1529 // if the user entered a page range outside the actual number
1530 // of printable pages, just return
1534 if (printer->pageOrder() == QPrinter::LastPageFirst) {
1541 painter.scale(zoomFactorX, zoomFactorY);
1542 GraphicsContext ctx(&painter);
1544 for (int i = 0; i < docCopies; ++i) {
1545 int page = fromPage;
1547 for (int j = 0; j < pageCopies; ++j) {
1548 if (printer->printerState() == QPrinter::Aborted
1549 || printer->printerState() == QPrinter::Error) {
1553 printContext.spoolPage(ctx, page - 1, pageRect.width());
1554 if (j < pageCopies - 1)
1569 if ( i < docCopies - 1)
1575 #endif // QT_NO_PRINTER
1578 Evaluates the JavaScript defined by \a scriptSource using this frame as context
1579 and returns the result of the last executed statement.
1581 \sa addToJavaScriptWindowObject(), javaScriptWindowObjectCleared()
1583 QVariant QWebFrame::evaluateJavaScript(const QString& scriptSource)
1585 ScriptController *proxy = d->frame->script();
1590 JSC::JSValue v = d->frame->script()->executeScript(ScriptSourceCode(scriptSource)).jsValue();
1592 rc = JSC::Bindings::convertValueToQVariant(proxy->globalObject(mainThreadNormalWorld())->globalExec(), v, QMetaType::Void, &distance);
1594 QScriptEngine* engine = d->frame->script()->qtScriptEngine();
1597 rc = engine->evaluate(scriptSource).toVariant();
1606 Returns the frame's security origin.
1608 QWebSecurityOrigin QWebFrame::securityOrigin() const
1610 QWebFrame* that = const_cast<QWebFrame*>(this);
1611 QWebSecurityOriginPrivate* priv = new QWebSecurityOriginPrivate(QWebFramePrivate::core(that)->document()->securityOrigin());
1612 return QWebSecurityOrigin(priv);
1615 WebCore::Frame* QWebFramePrivate::core(const QWebFrame* webFrame)
1617 return webFrame->d->frame;
1620 QWebFrame* QWebFramePrivate::kit(const WebCore::Frame* coreFrame)
1622 return qobject_cast<QWebFrame*>(coreFrame->loader()->networkingContext()->originatingObject());
1627 \fn void QWebFrame::javaScriptWindowObjectCleared()
1629 This signal is emitted whenever the global window object of the JavaScript
1630 environment is cleared, e.g., before starting a new load.
1632 If you intend to add QObjects to a QWebFrame using
1633 addToJavaScriptWindowObject(), you should add them in a slot connected
1634 to this signal. This ensures that your objects remain accessible when
1639 \fn void QWebFrame::provisionalLoad()
1644 \fn void QWebFrame::titleChanged(const QString &title)
1646 This signal is emitted whenever the title of the frame changes.
1647 The \a title string specifies the new title.
1653 \fn void QWebFrame::urlChanged(const QUrl &url)
1655 This signal is emitted with the URL of the frame when the frame's title is
1656 received. The new URL is specified by \a url.
1662 \fn void QWebFrame::initialLayoutCompleted()
1664 This signal is emitted when the frame is laid out the first time.
1665 This is the first time you will see contents displayed on the frame.
1667 \note A frame can be laid out multiple times.
1671 \fn void QWebFrame::iconChanged()
1673 This signal is emitted when the icon ("favicon") associated with the frame
1680 \fn void QWebFrame::contentsSizeChanged(const QSize &size)
1683 This signal is emitted when the frame's contents size changes
1690 \fn void QWebFrame::loadStarted()
1693 This signal is emitted when a new load of this frame is started.
1699 \fn void QWebFrame::loadFinished(bool ok)
1702 This signal is emitted when a load of this frame is finished.
1703 \a ok will indicate whether the load was successful or any error occurred.
1709 \fn void QWebFrame::pageChanged()
1712 This signal is emitted when this frame has been moved to a different QWebPage.
1718 \class QWebHitTestResult
1720 \brief The QWebHitTestResult class provides information about the web
1721 page content after a hit test.
1725 QWebHitTestResult is returned by QWebFrame::hitTestContent() to provide
1726 information about the content of the web page at the specified position.
1732 QWebHitTestResult::QWebHitTestResult(QWebHitTestResultPrivate *priv)
1737 QWebHitTestResultPrivate::QWebHitTestResultPrivate(const WebCore::HitTestResult &hitTest)
1738 : isContentEditable(false)
1739 , isContentSelected(false)
1740 , isScrollBar(false)
1742 if (!hitTest.innerNode())
1744 pos = hitTest.point();
1745 WebCore::TextDirection dir;
1746 title = hitTest.title(dir);
1747 linkText = hitTest.textContent();
1748 linkUrl = hitTest.absoluteLinkURL();
1749 linkTitle = hitTest.titleDisplayString();
1750 alternateText = hitTest.altDisplayString();
1751 imageUrl = hitTest.absoluteImageURL();
1752 innerNode = hitTest.innerNode();
1753 innerNonSharedNode = hitTest.innerNonSharedNode();
1754 boundingRect = innerNonSharedNode ? innerNonSharedNode->renderer()->absoluteBoundingBoxRect(true) : IntRect();
1755 WebCore::Image *img = hitTest.image();
1757 QPixmap *pix = img->nativeImageForCurrentFrame();
1761 WebCore::Frame *wframe = hitTest.targetFrame();
1763 linkTargetFrame = QWebFramePrivate::kit(wframe);
1764 linkElement = QWebElement(hitTest.URLElement());
1766 isContentEditable = hitTest.isContentEditable();
1767 isContentSelected = hitTest.isSelected();
1768 isScrollBar = hitTest.scrollbar();
1770 if (innerNonSharedNode && innerNonSharedNode->document()
1771 && innerNonSharedNode->document()->frame())
1772 frame = QWebFramePrivate::kit(innerNonSharedNode->document()->frame());
1774 enclosingBlock = QWebElement(WebCore::enclosingBlock(innerNode.get()));
1778 Constructs a null hit test result.
1780 QWebHitTestResult::QWebHitTestResult()
1786 Constructs a hit test result from \a other.
1788 QWebHitTestResult::QWebHitTestResult(const QWebHitTestResult &other)
1792 d = new QWebHitTestResultPrivate(*other.d);
1796 Assigns the \a other hit test result to this.
1798 QWebHitTestResult &QWebHitTestResult::operator=(const QWebHitTestResult &other)
1800 if (this != &other) {
1803 d = new QWebHitTestResultPrivate;
1816 QWebHitTestResult::~QWebHitTestResult()
1822 Returns true if the hit test result is null; otherwise returns false.
1824 bool QWebHitTestResult::isNull() const
1830 Returns the position where the hit test occured.
1832 QPoint QWebHitTestResult::pos() const
1841 Returns the bounding rect of the element.
1843 QRect QWebHitTestResult::boundingRect() const
1847 return d->boundingRect;
1852 Returns the block element that encloses the element hit.
1854 A block element is an element that is rendered using the
1855 CSS "block" style. This includes for example text
1858 QWebElement QWebHitTestResult::enclosingBlockElement() const
1861 return QWebElement();
1862 return d->enclosingBlock;
1866 Returns the title of the nearest enclosing HTML element.
1868 QString QWebHitTestResult::title() const
1876 Returns the text of the link.
1878 QString QWebHitTestResult::linkText() const
1886 Returns the url to which the link points to.
1888 QUrl QWebHitTestResult::linkUrl() const
1896 Returns the title of the link.
1898 QUrl QWebHitTestResult::linkTitle() const
1902 return d->linkTitle;
1907 Returns the element that represents the link.
1909 \sa linkTargetFrame()
1911 QWebElement QWebHitTestResult::linkElement() const
1914 return QWebElement();
1915 return d->linkElement;
1919 Returns the frame that will load the link if it is activated.
1923 QWebFrame *QWebHitTestResult::linkTargetFrame() const
1927 return d->linkTargetFrame.data();
1931 Returns the alternate text of the element. This corresponds to the HTML alt attribute.
1933 QString QWebHitTestResult::alternateText() const
1937 return d->alternateText;
1941 Returns the url of the image.
1943 QUrl QWebHitTestResult::imageUrl() const
1951 Returns a QPixmap containing the image. A null pixmap is returned if the
1952 element being tested is not an image.
1954 QPixmap QWebHitTestResult::pixmap() const
1962 Returns true if the content is editable by the user; otherwise returns false.
1964 bool QWebHitTestResult::isContentEditable() const
1968 return d->isContentEditable;
1972 Returns true if the content tested is part of the selection; otherwise returns false.
1974 bool QWebHitTestResult::isContentSelected() const
1978 return d->isContentSelected;
1983 Returns the underlying DOM element as QWebElement.
1985 QWebElement QWebHitTestResult::element() const
1987 if (!d || !d->innerNonSharedNode || !d->innerNonSharedNode->isElementNode())
1988 return QWebElement();
1990 return QWebElement(static_cast<WebCore::Element*>(d->innerNonSharedNode.get()));
1994 Returns the frame the hit test was executed in.
1996 QWebFrame *QWebHitTestResult::frame() const
2000 return d->frame.data();
2003 #include "moc_qwebframe.cpp"