From 40736c5763bf61337c8c14e16d8587db021a87d4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 6 Jan 2012 14:44:00 +0100 Subject: Imported WebKit commit 2ea9d364d0f6efa8fa64acf19f451504c59be0e4 (http://svn.webkit.org/repository/webkit/trunk@104285) --- Source/JavaScriptCore/wtf/qt/MainThreadQt.cpp | 78 ++++++++++++++++++++++ Source/JavaScriptCore/wtf/qt/StringQt.cpp | 73 ++++++++++++++++++++ Source/JavaScriptCore/wtf/qt/UtilsQt.h | 37 ++++++++++ .../JavaScriptCore/wtf/qt/compat/QGuiApplication | 1 + .../JavaScriptCore/wtf/qt/compat/qguiapplication.h | 35 ++++++++++ 5 files changed, 224 insertions(+) create mode 100644 Source/JavaScriptCore/wtf/qt/MainThreadQt.cpp create mode 100644 Source/JavaScriptCore/wtf/qt/StringQt.cpp create mode 100644 Source/JavaScriptCore/wtf/qt/UtilsQt.h create mode 100644 Source/JavaScriptCore/wtf/qt/compat/QGuiApplication create mode 100644 Source/JavaScriptCore/wtf/qt/compat/qguiapplication.h (limited to 'Source/JavaScriptCore/wtf/qt') diff --git a/Source/JavaScriptCore/wtf/qt/MainThreadQt.cpp b/Source/JavaScriptCore/wtf/qt/MainThreadQt.cpp new file mode 100644 index 000000000..606a7190e --- /dev/null +++ b/Source/JavaScriptCore/wtf/qt/MainThreadQt.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007 Staikos Computing Services Inc. + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * 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 "config.h" +#include "MainThread.h" + +#include +#include +#include +#include + +namespace WTF { + +static int s_mainThreadInvokerEventType; + +class MainThreadInvoker : public QObject { + Q_OBJECT +public: + MainThreadInvoker(); + virtual bool event(QEvent*); +}; + +MainThreadInvoker::MainThreadInvoker() +{ + s_mainThreadInvokerEventType = QEvent::registerEventType(); +} + +bool MainThreadInvoker::event(QEvent* e) +{ + if (e->type() != s_mainThreadInvokerEventType) + return QObject::event(e); + + dispatchFunctionsFromMainThread(); + return true; +} + +Q_GLOBAL_STATIC(MainThreadInvoker, webkit_main_thread_invoker) + +void initializeMainThreadPlatform() +{ + webkit_main_thread_invoker(); +} + +void scheduleDispatchFunctionsOnMainThread() +{ + QCoreApplication::postEvent(webkit_main_thread_invoker(), new QEvent(static_cast(s_mainThreadInvokerEventType))); +} + +} // namespace WTF + +#include "MainThreadQt.moc" diff --git a/Source/JavaScriptCore/wtf/qt/StringQt.cpp b/Source/JavaScriptCore/wtf/qt/StringQt.cpp new file mode 100644 index 000000000..16dd439e3 --- /dev/null +++ b/Source/JavaScriptCore/wtf/qt/StringQt.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR + * 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 "config.h" + +#include +#include + +#include + +namespace WTF { + +// String conversions +String::String(const QString& qstr) +{ + if (qstr.isNull()) + return; + m_impl = StringImpl::create(reinterpret_cast_ptr(qstr.constData()), qstr.length()); +} + +String::String(const QStringRef& ref) +{ + if (!ref.string()) + return; + m_impl = StringImpl::create(reinterpret_cast_ptr(ref.unicode()), ref.length()); +} + +String::operator QString() const +{ + return QString(reinterpret_cast(characters()), length()); +} + +QDataStream& operator<<(QDataStream& stream, const String& str) +{ + // could be faster + stream << QString(str); + return stream; +} + +QDataStream& operator>>(QDataStream& stream, String& str) +{ + // mabe not the fastest way, but really easy + QString tmp; + stream >> tmp; + str = tmp; + return stream; +} + +} + +// vim: ts=4 sw=4 et diff --git a/Source/JavaScriptCore/wtf/qt/UtilsQt.h b/Source/JavaScriptCore/wtf/qt/UtilsQt.h new file mode 100644 index 000000000..74067a8ee --- /dev/null +++ b/Source/JavaScriptCore/wtf/qt/UtilsQt.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + + 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. +*/ + +#ifndef WTF_UtilsQt_h +#define WTF_UtilsQt_h + +#include +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#include +#endif + +inline QString escapeHtml(const QString& string) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + return string.toHtmlEscaped(); +#else + return Qt::escape(string); +#endif +} + +#endif // WTF_UtilsQt_h diff --git a/Source/JavaScriptCore/wtf/qt/compat/QGuiApplication b/Source/JavaScriptCore/wtf/qt/compat/QGuiApplication new file mode 100644 index 000000000..0337e2526 --- /dev/null +++ b/Source/JavaScriptCore/wtf/qt/compat/QGuiApplication @@ -0,0 +1 @@ +#include "qguiapplication.h" diff --git a/Source/JavaScriptCore/wtf/qt/compat/qguiapplication.h b/Source/JavaScriptCore/wtf/qt/compat/qguiapplication.h new file mode 100644 index 000000000..2a2fc23cb --- /dev/null +++ b/Source/JavaScriptCore/wtf/qt/compat/qguiapplication.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + + 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. +*/ + +#ifndef qguiapplication_h +#define qguiapplication_h + +#include + +struct QGuiApplication : public QApplication +{ + // Style hints in Qt 5 contain stuff that just used to be in QApplication in Qt 4, hence + // this hack. + static QApplication* styleHints() + { + return qApp; + } +}; + +#endif -- cgit v1.2.1