📄 jsobjects.cpp
字号:
/* * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include <jsobjects.h>#include <qwebpage.h>#include <qwebhistory.h>#include <qwebframe.h>#include <qevent.h>#include <qapplication.h>#include <qevent.h>#include <qtimer.h>#include "DumpRenderTree.h"#include "WorkQueueItem.h"#include "WorkQueue.h"extern void qt_dump_editing_callbacks(bool b);extern void qt_dump_resource_load_callbacks(bool b);extern void qt_drt_setJavaScriptProfilingEnabled(QWebFrame*, bool enabled);extern bool qt_drt_pauseAnimation(QWebFrame*, const QString &name, double time, const QString &elementId);extern bool qt_drt_pauseTransitionOfProperty(QWebFrame*, const QString &name, double time, const QString &elementId);extern int qt_drt_numberOfActiveAnimations(QWebFrame*);QWebFrame *findFrameNamed(const QString &frameName, QWebFrame *frame){ if (frame->frameName() == frameName) return frame; foreach (QWebFrame *childFrame, frame->childFrames()) if (QWebFrame *f = findFrameNamed(frameName, childFrame)) return f; return 0;}void LoadItem::invoke() const{ //qDebug() << ">>>LoadItem::invoke"; Q_ASSERT(m_webPage); QWebFrame *frame = 0; const QString t = target(); if (t.isEmpty()) frame = m_webPage->mainFrame(); else frame = findFrameNamed(t, m_webPage->mainFrame()); if (!frame) return; frame->load(url());}void ReloadItem::invoke() const{ //qDebug() << ">>>ReloadItem::invoke"; Q_ASSERT(m_webPage); m_webPage->triggerAction(QWebPage::Reload);}void ScriptItem::invoke() const{ //qDebug() << ">>>ScriptItem::invoke"; Q_ASSERT(m_webPage); m_webPage->mainFrame()->evaluateJavaScript(script());}void BackForwardItem::invoke() const{ //qDebug() << ">>>BackForwardItem::invoke"; Q_ASSERT(m_webPage); if (m_howFar > 0) { for (int i = 0; i != m_howFar; ++i) m_webPage->triggerAction(QWebPage::Forward); } else { for (int i = 0; i != m_howFar; --i) m_webPage->triggerAction(QWebPage::Back); }}LayoutTestController::LayoutTestController(WebCore::DumpRenderTree *drt) : QObject() , m_drt(drt){ m_timeoutTimer = 0; reset();}void LayoutTestController::reset(){ m_isLoading = true; m_textDump = false; m_dumpBackForwardList = false; m_dumpChildrenAsText = false; m_canOpenWindows = false; m_waitForDone = false; m_dumpTitleChanges = false; if (m_timeoutTimer) { killTimer(m_timeoutTimer); m_timeoutTimer = 0; } m_topLoadingFrame = 0; qt_dump_editing_callbacks(false); qt_dump_resource_load_callbacks(false);}void LayoutTestController::processWork(){ qDebug() << ">>>processWork"; // quit doing work once a load is in progress while (WorkQueue::shared()->count() > 0 && !m_topLoadingFrame) { WorkQueueItem* item = WorkQueue::shared()->dequeue(); Q_ASSERT(item); item->invoke(); delete item; } // if we didn't start a new load, then we finished all the commands, so we're ready to dump state if (!m_topLoadingFrame && !shouldWaitUntilDone()) { emit done(); m_isLoading = false; }}void LayoutTestController::maybeDump(bool){ m_topLoadingFrame = 0; WorkQueue::shared()->setFrozen(true); // first complete load freezes the queue for the rest of this test if (!shouldWaitUntilDone()) { if (WorkQueue::shared()->count()) QTimer::singleShot(0, this, SLOT(processWork())); else { emit done(); m_isLoading = false; } }}void LayoutTestController::waitUntilDone(){ //qDebug() << ">>>>waitForDone"; m_waitForDone = true; m_timeoutTimer = startTimer(11000);}void LayoutTestController::notifyDone(){ //qDebug() << ">>>>notifyDone"; if (!m_timeoutTimer) return; killTimer(m_timeoutTimer); m_timeoutTimer = 0; emit done(); m_isLoading = false;}int LayoutTestController::windowCount(){ return m_drt->windowCount();}void LayoutTestController::clearBackForwardList(){ m_drt->webPage()->history()->clear();}void LayoutTestController::dumpEditingCallbacks(){ qDebug() << ">>>dumpEditingCallbacks"; qt_dump_editing_callbacks(true);}void LayoutTestController::dumpResourceLoadCallbacks(){ qt_dump_resource_load_callbacks(true);}void LayoutTestController::queueBackNavigation(int howFarBackward){ //qDebug() << ">>>queueBackNavigation" << howFarBackward; WorkQueue::shared()->queue(new BackItem(howFarBackward, m_drt->webPage()));}void LayoutTestController::queueForwardNavigation(int howFarForward){ //qDebug() << ">>>queueForwardNavigation" << howFarForward; WorkQueue::shared()->queue(new ForwardItem(howFarForward, m_drt->webPage()));}void LayoutTestController::queueLoad(const QString &url, const QString &target){ //qDebug() << ">>>queueLoad" << url << target; QUrl mainResourceUrl = m_drt->webPage()->mainFrame()->url(); QString absoluteUrl = mainResourceUrl.resolved(QUrl(url)).toEncoded(); WorkQueue::shared()->queue(new LoadItem(absoluteUrl, target, m_drt->webPage()));}void LayoutTestController::queueReload(){ //qDebug() << ">>>queueReload"; WorkQueue::shared()->queue(new ReloadItem(m_drt->webPage()));}void LayoutTestController::queueScript(const QString &url){ //qDebug() << ">>>queueScript" << url; WorkQueue::shared()->queue(new ScriptItem(url, m_drt->webPage()));}void LayoutTestController::provisionalLoad(){ QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); if (!m_topLoadingFrame && m_isLoading) m_topLoadingFrame = frame;}void LayoutTestController::timerEvent(QTimerEvent *){ qDebug() << ">>>>>>>>>>>>> timeout"; notifyDone();}QString LayoutTestController::encodeHostName(const QString &host){ QString encoded = QString::fromLatin1(QUrl::toAce(host + QLatin1String(".no"))); encoded.truncate(encoded.length() - 3); // strip .no return encoded;}QString LayoutTestController::decodeHostName(const QString &host){ QString decoded = QUrl::fromAce(host.toLatin1() + QByteArray(".no")); decoded.truncate(decoded.length() - 3); return decoded;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -