/* Copyright (C) 2008,2009 Nokia Corporation and/or its subsidiary(-ies) Copyright (C) 2007 Staikos Computing Services Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" #include "qwebframe.h" #include "CallFrame.h" #include "Document.h" #include "DocumentLoader.h" #include "DragData.h" #include "Element.h" #include "FocusController.h" #include "Frame.h" #include "FrameLoaderClientQt.h" #include "FrameTree.h" #include "FrameView.h" #include "GCController.h" #include "GraphicsContext.h" #include "HTMLMetaElement.h" #include "HitTestResult.h" #include "IconDatabase.h" #include "InspectorController.h" #include "JSDOMBinding.h" #include "JSDOMWindowBase.h" #include "JSLock.h" #include "JSObject.h" #include "NodeList.h" #include "Page.h" #include "PlatformMouseEvent.h" #include "PlatformWheelEvent.h" #include "PrintContext.h" #include "PutPropertySlot.h" #include "RenderTreeAsText.h" #include "RenderView.h" #include "ResourceRequest.h" #include "ScriptController.h" #include "ScriptSourceCode.h" #include "ScriptValue.h" #include "Scrollbar.h" #include "SelectionController.h" #include "SubstituteData.h" #include "htmlediting.h" #include "markup.h" #include "qt_instance.h" #include "qt_runtime.h" #include "qwebelement.h" #include "qwebframe_p.h" #include "qwebpage.h" #include "qwebpage_p.h" #include "qwebsecurityorigin.h" #include "qwebsecurityorigin_p.h" #include "runtime.h" #include "runtime_object.h" #include "runtime_root.h" #include "wtf/HashMap.h" #include #include #include #include #include #include #include #if QT_VERSION < 0x040400 #include "qwebnetworkinterface.h" #endif #if QT_VERSION >= 0x040400 #include #endif using namespace WebCore; // from text/qfont.cpp QT_BEGIN_NAMESPACE extern Q_GUI_EXPORT int qt_defaultDpi(); QT_END_NAMESPACE void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* qframe, bool enabled) { #if ENABLE(JAVASCRIPT_DEBUGGER) Frame* frame = QWebFramePrivate::core(qframe); InspectorController* controller = frame->page()->inspectorController(); if (!controller) return; if (enabled) controller->enableProfiler(); else controller->disableProfiler(); #endif } // Pause a given CSS animation or transition on the target node at a specific time. // If the animation or transition is already paused, it will update its pause time. // This method is only intended to be used for testing the CSS animation and transition system. bool QWEBKIT_EXPORT qt_drt_pauseAnimation(QWebFrame *qframe, const QString &animationName, double time, const QString &elementId) { Frame* frame = QWebFramePrivate::core(qframe); if (!frame) return false; AnimationController* controller = frame->animation(); if (!controller) return false; Document* doc = frame->document(); Q_ASSERT(doc); Node* coreNode = doc->getElementById(elementId); if (!coreNode || !coreNode->renderer()) return false; return controller->pauseAnimationAtTime(coreNode->renderer(), animationName, time); } bool QWEBKIT_EXPORT qt_drt_pauseTransitionOfProperty(QWebFrame *qframe, const QString &propertyName, double time, const QString &elementId) { Frame* frame = QWebFramePrivate::core(qframe); if (!frame) return false; AnimationController* controller = frame->animation(); if (!controller) return false; Document* doc = frame->document(); Q_ASSERT(doc); Node* coreNode = doc->getElementById(elementId); if (!coreNode || !coreNode->renderer()) return false; return controller->pauseTransitionAtTime(coreNode->renderer(), propertyName, time); } // Returns the total number of currently running animations (includes both CSS transitions and CSS animations). int QWEBKIT_EXPORT qt_drt_numberOfActiveAnimations(QWebFrame *qframe) { Frame* frame = QWebFramePrivate::core(qframe); if (!frame) return false; AnimationController* controller = frame->animation(); if (!controller) return false; return controller->numberOfActiveAnimations(); } void QWEBKIT_EXPORT qt_drt_clearFrameName(QWebFrame* qFrame) { Frame* frame = QWebFramePrivate::core(qFrame); frame->tree()->clearName(); } int QWEBKIT_EXPORT qt_drt_javaScriptObjectsCount() { return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount(); } void QWEBKIT_EXPORT qt_drt_garbageCollector_collect() { gcController().garbageCollectNow(); } void QWEBKIT_EXPORT qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone) { gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone); } QWebFrameData::QWebFrameData(WebCore::Page* parentPage, WebCore::Frame* parentFrame, WebCore::HTMLFrameOwnerElement* ownerFrameElement, const WebCore::String& frameName) : name(frameName) , ownerElement(ownerFrameElement) , page(parentPage) , allowsScrolling(true) , marginWidth(0) , marginHeight(0) { frameLoaderClient = new FrameLoaderClientQt(); frame = Frame::create(page, ownerElement, frameLoaderClient); // FIXME: All of the below should probably be moved over into WebCore frame->tree()->setName(name); if (parentFrame) parentFrame->tree()->appendChild(frame); } void QWebFramePrivate::init(QWebFrame *qframe, QWebFrameData *frameData) { q = qframe; allowsScrolling = frameData->allowsScrolling; marginWidth = frameData->marginWidth; marginHeight = frameData->marginHeight; frame = frameData->frame.get(); frameLoaderClient = frameData->frameLoaderClient; frameLoaderClient->setFrame(qframe, frame); frame->init(); } WebCore::Scrollbar* QWebFramePrivate::horizontalScrollBar() const { if (!frame->view()) return 0; return frame->view()->horizontalScrollbar(); } WebCore::Scrollbar* QWebFramePrivate::verticalScrollBar() const { if (!frame->view()) return 0; return frame->view()->verticalScrollbar(); } void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip) { if (!frame->view() || !frame->contentRenderer()) return; QVector vector = clip.rects(); if (vector.isEmpty()) return; WebCore::FrameView* view = frame->view(); view->layoutIfNeededRecursive(); GraphicsContext context(painter); if (clipRenderToViewport) view->paint(&context, vector.first()); else view->paintContents(&context, vector.first()); for (int i = 1; i < vector.size(); ++i) { const QRect& clipRect = vector.at(i); painter->save(); painter->setClipRect(clipRect, Qt::IntersectClip); if (clipRenderToViewport) view->paint(&context, clipRect); else view->paintContents(&context, clipRect); painter->restore(); } } /*! \class QWebFrame \since 4.4 \brief The QWebFrame class represents a frame in a web page. QWebFrame represents a frame inside a web page. Each QWebPage object contains at least one frame, the main frame, obtained using QWebPage::mainFrame(). Additional frames will be created for HTML \c{} or \c{