diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/qt')
-rw-r--r-- | Source/WebKit2/UIProcess/qt/ColorChooserContextObject.h | 57 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/DialogContextObjects.h | 287 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.cpp | 181 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.h | 119 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp | 262 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/QtPageClient.cpp | 3 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/WebColorPickerQt.cpp | 29 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp | 227 |
8 files changed, 650 insertions, 515 deletions
diff --git a/Source/WebKit2/UIProcess/qt/ColorChooserContextObject.h b/Source/WebKit2/UIProcess/qt/ColorChooserContextObject.h new file mode 100644 index 000000000..0af685b61 --- /dev/null +++ b/Source/WebKit2/UIProcess/qt/ColorChooserContextObject.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * Copyright (C) 2012 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. + * + */ + +#pragma once + +#include <QColor> +#include <QObject> +#include <QRectF> + +namespace WebKit { + +class ColorChooserContextObject : public QObject { + Q_OBJECT + Q_PROPERTY(QColor currentColor READ currentColor CONSTANT FINAL) + Q_PROPERTY(QRectF elementRect READ elementRect CONSTANT FINAL) + +public: + ColorChooserContextObject(const QColor& color, const QRectF& rect) + : m_currentColor(color) + , m_rect(rect) + { + } + + QColor currentColor() const { return m_currentColor; } + QRectF elementRect() const { return m_rect; } + + Q_INVOKABLE void accept(const QColor& color) { emit accepted(color); } + Q_INVOKABLE void reject() { emit rejected(); } + +Q_SIGNALS: + void accepted(const QColor&); + void rejected(); + +private: + QColor m_currentColor; + QRectF m_rect; +}; + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/qt/DialogContextObjects.h b/Source/WebKit2/UIProcess/qt/DialogContextObjects.h new file mode 100644 index 000000000..c6257125e --- /dev/null +++ b/Source/WebKit2/UIProcess/qt/DialogContextObjects.h @@ -0,0 +1,287 @@ +/* + * 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 program 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 program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#pragma once + +#include "QtDialogRunner.h" +#include "WKRetainPtr.h" +#include "WKStringQt.h" +#include "qtwebsecurityorigin_p.h" + +namespace WebKit { + +// All dialogs need a way to support the state of the +// dialog being done/finished/dismissed. This is handled +// in the dialog base context. +class DialogContextBase : public QObject { + Q_OBJECT + +public: + DialogContextBase() + : QObject() + , m_dismissed(false) + { + } + +public Q_SLOTS: + // Allows clients to call dismiss() directly, while also + // being able to hook up signals to automatically also + // dismiss the dialog since it's a slot. + + void dismiss() + { + m_dismissed = true; + emit dismissed(); + } + +Q_SIGNALS: + void dismissed(); + +private: + // We store the dismissed state so that run() can check to see if a + // dialog has already been dismissed before spinning an event loop. + bool m_dismissed; + friend void QtDialogRunner::run(); +}; + +class DialogContextObject : public DialogContextBase { + Q_OBJECT + Q_PROPERTY(QString message READ message CONSTANT) + Q_PROPERTY(QString defaultValue READ defaultValue CONSTANT) + +public: + DialogContextObject(const QString& message, const QString& defaultValue = QString()) + : DialogContextBase() + , m_message(message) + , m_defaultValue(defaultValue) + { + connect(this, SIGNAL(accepted(QString)), SLOT(dismiss())); + connect(this, SIGNAL(rejected()), SLOT(dismiss())); + } + QString message() const { return m_message; } + QString defaultValue() const { return m_defaultValue; } + +public Q_SLOTS: + void accept(const QString& result = QString()) { emit accepted(result); } + void reject() { emit rejected(); } + +Q_SIGNALS: + void accepted(const QString& result); + void rejected(); + +private: + QString m_message; + QString m_defaultValue; +}; + +class BaseAuthenticationContextObject : public DialogContextBase { + Q_OBJECT + Q_PROPERTY(QString hostname READ hostname CONSTANT) + Q_PROPERTY(QString prefilledUsername READ prefilledUsername CONSTANT) + +public: + BaseAuthenticationContextObject(const QString& hostname, const QString& prefilledUsername) + : DialogContextBase() + , m_hostname(hostname) + , m_prefilledUsername(prefilledUsername) + { + connect(this, SIGNAL(accepted(QString, QString)), SLOT(dismiss())); + connect(this, SIGNAL(rejected()), SLOT(dismiss())); + } + + QString hostname() const { return m_hostname; } + QString prefilledUsername() const { return m_prefilledUsername; } + +public Q_SLOTS: + void accept(const QString& username, const QString& password) { emit accepted(username, password); } + void reject() { emit rejected(); } + +Q_SIGNALS: + void accepted(const QString& username, const QString& password); + void rejected(); + +private: + QString m_hostname; + QString m_prefilledUsername; +}; + +class HttpAuthenticationDialogContextObject : public BaseAuthenticationContextObject { + Q_OBJECT + Q_PROPERTY(QString realm READ realm CONSTANT) + +public: + HttpAuthenticationDialogContextObject(const QString& hostname, const QString& realm, const QString& prefilledUsername) + : BaseAuthenticationContextObject(hostname, prefilledUsername) + , m_realm(realm) + { + } + + QString realm() const { return m_realm; } + +private: + QString m_realm; +}; + +class ProxyAuthenticationDialogContextObject : public BaseAuthenticationContextObject { + Q_OBJECT + Q_PROPERTY(quint16 port READ port CONSTANT) + +public: + ProxyAuthenticationDialogContextObject(const QString& hostname, quint16 port, const QString& prefilledUsername) + : BaseAuthenticationContextObject(hostname, prefilledUsername) + , m_port(port) + { + } + + quint16 port() const { return m_port; } + +private: + quint16 m_port; +}; + +class CertificateVerificationDialogContextObject : public DialogContextBase { + Q_OBJECT + Q_PROPERTY(QString hostname READ hostname CONSTANT) + +public: + CertificateVerificationDialogContextObject(const QString& hostname) + : DialogContextBase() + , m_hostname(hostname) + { + connect(this, SIGNAL(accepted()), SLOT(dismiss())); + connect(this, SIGNAL(rejected()), SLOT(dismiss())); + } + + QString hostname() const { return m_hostname; } + +public Q_SLOTS: + void accept() { emit accepted(); } + void reject() { emit rejected(); } + +Q_SIGNALS: + void accepted(); + void rejected(); + +private: + QString m_hostname; +}; + +class FilePickerContextObject : public DialogContextBase { + Q_OBJECT + Q_PROPERTY(QStringList fileList READ fileList CONSTANT) + Q_PROPERTY(bool allowMultipleFiles READ allowMultipleFiles CONSTANT) + +public: + FilePickerContextObject(const QStringList& selectedFiles, bool allowMultiple) + : DialogContextBase() + , m_allowMultiple(allowMultiple) + , m_fileList(selectedFiles) + { + connect(this, SIGNAL(fileSelected(QStringList)), SLOT(dismiss())); + connect(this, SIGNAL(rejected()), SLOT(dismiss())); + } + + QStringList fileList() const { return m_fileList; } + bool allowMultipleFiles() const { return m_allowMultiple;} + +public Q_SLOTS: + void reject() { emit rejected();} + void accept(const QVariant& path) + { + QStringList filesPath = path.toStringList(); + + if (filesPath.isEmpty()) { + emit rejected(); + return; + } + + // For single file upload, send only the first element if there are more than one file paths + if (!m_allowMultiple && filesPath.count() > 1) + filesPath = QStringList(filesPath.at(0)); + emit fileSelected(filesPath); + } + +Q_SIGNALS: + void rejected(); + void fileSelected(const QStringList&); + +private: + bool m_allowMultiple; + QStringList m_fileList; +}; + +class DatabaseQuotaDialogContextObject : public DialogContextBase { + Q_OBJECT + Q_PROPERTY(QString databaseName READ databaseName CONSTANT) + Q_PROPERTY(QString displayName READ displayName CONSTANT) + Q_PROPERTY(quint64 currentQuota READ currentQuota CONSTANT) + Q_PROPERTY(quint64 currentOriginUsage READ currentOriginUsage CONSTANT) + Q_PROPERTY(quint64 currentDatabaseUsage READ currentDatabaseUsage CONSTANT) + Q_PROPERTY(quint64 expectedUsage READ expectedUsage CONSTANT) + Q_PROPERTY(QtWebSecurityOrigin* origin READ securityOrigin CONSTANT) + +public: + DatabaseQuotaDialogContextObject(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage) + : DialogContextBase() + , m_databaseName(databaseName) + , m_displayName(displayName) + , m_currentQuota(currentQuota) + , m_currentOriginUsage(currentOriginUsage) + , m_currentDatabaseUsage(currentDatabaseUsage) + , m_expectedUsage(expectedUsage) + { + WKRetainPtr<WKStringRef> scheme = adoptWK(WKSecurityOriginCopyProtocol(securityOrigin)); + WKRetainPtr<WKStringRef> host = adoptWK(WKSecurityOriginCopyHost(securityOrigin)); + + m_securityOrigin.setScheme(WKStringCopyQString(scheme.get())); + m_securityOrigin.setHost(WKStringCopyQString(host.get())); + m_securityOrigin.setPort(static_cast<int>(WKSecurityOriginGetPort(securityOrigin))); + + connect(this, SIGNAL(accepted(quint64)), SLOT(dismiss())); + connect(this, SIGNAL(rejected()), SLOT(dismiss())); + } + + QString databaseName() const { return m_databaseName; } + QString displayName() const { return m_displayName; } + quint64 currentQuota() const { return m_currentQuota; } + quint64 currentOriginUsage() const { return m_currentOriginUsage; } + quint64 currentDatabaseUsage() const { return m_currentDatabaseUsage; } + quint64 expectedUsage() const { return m_expectedUsage; } + QtWebSecurityOrigin* securityOrigin() { return &m_securityOrigin; } + +public Q_SLOTS: + void accept(quint64 size) { emit accepted(size); } + void reject() { emit rejected(); } + +Q_SIGNALS: + void accepted(quint64 size); + void rejected(); + +private: + QString m_databaseName; + QString m_displayName; + quint64 m_currentQuota; + quint64 m_currentOriginUsage; + quint64 m_currentDatabaseUsage; + quint64 m_expectedUsage; + QtWebSecurityOrigin m_securityOrigin; +}; + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.cpp b/Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.cpp new file mode 100644 index 000000000..a78fe4964 --- /dev/null +++ b/Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * 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 INC. 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 INC. 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 "ItemSelectorContextObject.h" + +#include "PlatformPopupMenuData.h" +#include "WebPopupItem.h" +#include "WebPopupMenuProxyQt.h" +#include "qquickwebview_p.h" +#include "qquickwebview_p_p.h" +#include <QtCore/QAbstractListModel> +#include <QtQml/QQmlContext> +#include <QtQml/QQmlEngine> + +using namespace WebCore; + +namespace WebKit { + +ItemSelectorContextObject::ItemSelectorContextObject(const QRectF& elementRect, const Vector<WebPopupItem>& webPopupItems, bool multiple) + : m_elementRect(elementRect) + , m_items(webPopupItems, multiple) +{ + connect(&m_items, SIGNAL(indexUpdated()), SLOT(onIndexUpdate())); +} + +void ItemSelectorContextObject::onIndexUpdate() +{ + // Send the update for multi-select list. + if (m_items.multiple()) + emit acceptedWithOriginalIndex(m_items.selectedOriginalIndex()); +} + + +void ItemSelectorContextObject::accept(int index) +{ + // If the index is not valid for multi-select lists, just hide the pop up as the selected indices have + // already been sent. + if ((index == -1) && m_items.multiple()) + emit done(); + else { + if (index != -1) + m_items.toggleItem(index); + emit acceptedWithOriginalIndex(m_items.selectedOriginalIndex()); + } +} + +static QHash<int, QByteArray> createRoleNamesHash() +{ + QHash<int, QByteArray> roles; + roles[Qt::DisplayRole] = "text"; + roles[Qt::ToolTipRole] = "tooltip"; + roles[PopupMenuItemModel::GroupRole] = "group"; + roles[PopupMenuItemModel::EnabledRole] = "enabled"; + roles[PopupMenuItemModel::SelectedRole] = "selected"; + roles[PopupMenuItemModel::IsSeparatorRole] = "isSeparator"; + return roles; +} + +PopupMenuItemModel::PopupMenuItemModel(const Vector<WebPopupItem>& webPopupItems, bool multiple) + : m_selectedModelIndex(-1) + , m_allowMultiples(multiple) +{ + buildItems(webPopupItems); +} + +QHash<int, QByteArray> PopupMenuItemModel::roleNames() const +{ + static QHash<int, QByteArray> roles = createRoleNamesHash(); + return roles; +} + +QVariant PopupMenuItemModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size()) + return QVariant(); + + const Item& item = m_items[index.row()]; + if (item.isSeparator) { + if (role == IsSeparatorRole) + return true; + return QVariant(); + } + + switch (role) { + case Qt::DisplayRole: + return item.text; + case Qt::ToolTipRole: + return item.toolTip; + case GroupRole: + return item.group; + case EnabledRole: + return item.enabled; + case SelectedRole: + return item.selected; + case IsSeparatorRole: + return false; + } + + return QVariant(); +} + +void PopupMenuItemModel::select(int index) +{ + toggleItem(index); + emit indexUpdated(); +} + +void PopupMenuItemModel::toggleItem(int index) +{ + int oldIndex = m_selectedModelIndex; + if (index < 0 || index >= m_items.size()) + return; + Item& item = m_items[index]; + if (!item.enabled) + return; + + m_selectedModelIndex = index; + if (m_allowMultiples) + item.selected = !item.selected; + else { + if (index == oldIndex) + return; + item.selected = true; + if (oldIndex != -1) { + Item& oldItem = m_items[oldIndex]; + oldItem.selected = false; + emit dataChanged(this->index(oldIndex), this->index(oldIndex)); + } + } + + emit dataChanged(this->index(index), this->index(index)); +} + +int PopupMenuItemModel::selectedOriginalIndex() const +{ + if (m_selectedModelIndex == -1) + return -1; + return m_items[m_selectedModelIndex].originalIndex; +} + +void PopupMenuItemModel::buildItems(const Vector<WebPopupItem>& webPopupItems) +{ + QString currentGroup; + m_items.reserveInitialCapacity(webPopupItems.size()); + for (int i = 0; i < webPopupItems.size(); i++) { + const WebPopupItem& webPopupItem = webPopupItems[i]; + if (webPopupItem.m_isLabel) { + currentGroup = webPopupItem.m_text; + continue; + } + if (webPopupItem.m_isSelected && !m_allowMultiples) + m_selectedModelIndex = m_items.size(); + m_items.append(Item(webPopupItem, currentGroup, i)); + } +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.h b/Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.h new file mode 100644 index 000000000..ad63893d6 --- /dev/null +++ b/Source/WebKit2/UIProcess/qt/ItemSelectorContextObject.h @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * 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 INC. 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 INC. 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. + */ + +#pragma once + +#include "WebPopupItem.h" +#include <QtCore/QAbstractListModel> +#include <QtCore/QRectF> +#include <wtf/Vector.h> + +namespace WebKit { + +class PopupMenuItemModel final : public QAbstractListModel { + Q_OBJECT + +public: + enum Roles { + GroupRole = Qt::UserRole, + EnabledRole = Qt::UserRole + 1, + SelectedRole = Qt::UserRole + 2, + IsSeparatorRole = Qt::UserRole + 3 + }; + + PopupMenuItemModel(const Vector<WebPopupItem>&, bool multiple); + int rowCount(const QModelIndex& parent = QModelIndex()) const final { return m_items.size(); } + QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const final; + QHash<int, QByteArray> roleNames() const final; + + Q_INVOKABLE void select(int); + + int selectedOriginalIndex() const; + bool multiple() const { return m_allowMultiples; } + void toggleItem(int); + +Q_SIGNALS: + void indexUpdated(); + +private: + struct Item { + Item(const WebPopupItem& webPopupItem, const QString& group, int originalIndex) + : text(webPopupItem.m_text) + , toolTip(webPopupItem.m_toolTip) + , group(group) + , originalIndex(originalIndex) + , enabled(webPopupItem.m_isEnabled) + , selected(webPopupItem.m_isSelected) + , isSeparator(webPopupItem.m_type == WebPopupItem::Separator) + { } + + QString text; + QString toolTip; + QString group; + // Keep track of originalIndex because we don't add the label (group) items to our vector. + int originalIndex; + bool enabled; + bool selected; + bool isSeparator; + }; + + void buildItems(const Vector<WebPopupItem>& webPopupItems); + + Vector<Item> m_items; + int m_selectedModelIndex; + bool m_allowMultiples; +}; + +class ItemSelectorContextObject : public QObject { + Q_OBJECT + Q_PROPERTY(QRectF elementRect READ elementRect CONSTANT FINAL) + Q_PROPERTY(QObject* items READ items CONSTANT FINAL) + Q_PROPERTY(bool allowMultiSelect READ allowMultiSelect CONSTANT FINAL) + +public: + ItemSelectorContextObject(const QRectF& elementRect, const Vector<WebPopupItem>&, bool multiple); + + QRectF elementRect() const { return m_elementRect; } + PopupMenuItemModel* items() { return &m_items; } + bool allowMultiSelect() { return m_items.multiple(); } + + Q_INVOKABLE void accept(int index = -1); + Q_INVOKABLE void reject() { emit done(); } + Q_INVOKABLE void dismiss() { emit done(); } + +Q_SIGNALS: + void acceptedWithOriginalIndex(int); + void done(); + +private Q_SLOTS: + void onIndexUpdate(); + +private: + QRectF m_elementRect; + PopupMenuItemModel m_items; +}; + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp b/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp index 5043a170f..2cd5828a8 100644 --- a/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp +++ b/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp @@ -21,8 +21,7 @@ #include "config.h" #include "QtDialogRunner.h" -#include "WKRetainPtr.h" -#include "WKStringQt.h" +#include "DialogContextObjects.h" #include "qquickwebview_p_p.h" #include "qwebpermissionrequest_p.h" #include <QtQml/QQmlComponent> @@ -43,263 +42,6 @@ QtDialogRunner::~QtDialogRunner() { } -// All dialogs need a way to support the state of the -// dialog being done/finished/dismissed. This is handled -// in the dialog base context. -class DialogContextBase : public QObject { - Q_OBJECT - -public: - DialogContextBase() - : QObject() - , m_dismissed(false) - { - } - -public Q_SLOTS: - // Allows clients to call dismiss() directly, while also - // being able to hook up signals to automatically also - // dismiss the dialog since it's a slot. - - void dismiss() - { - m_dismissed = true; - emit dismissed(); - } - -Q_SIGNALS: - void dismissed(); - -private: - // We store the dismissed state so that run() can check to see if a - // dialog has already been dismissed before spinning an event loop. - bool m_dismissed; - friend void QtDialogRunner::run(); -}; - -class DialogContextObject : public DialogContextBase { - Q_OBJECT - Q_PROPERTY(QString message READ message CONSTANT) - Q_PROPERTY(QString defaultValue READ defaultValue CONSTANT) - -public: - DialogContextObject(const QString& message, const QString& defaultValue = QString()) - : DialogContextBase() - , m_message(message) - , m_defaultValue(defaultValue) - { - connect(this, SIGNAL(accepted(QString)), SLOT(dismiss())); - connect(this, SIGNAL(rejected()), SLOT(dismiss())); - } - QString message() const { return m_message; } - QString defaultValue() const { return m_defaultValue; } - -public Q_SLOTS: - void accept(const QString& result = QString()) { emit accepted(result); } - void reject() { emit rejected(); } - -Q_SIGNALS: - void accepted(const QString& result); - void rejected(); - -private: - QString m_message; - QString m_defaultValue; -}; - -class BaseAuthenticationContextObject : public DialogContextBase { - Q_OBJECT - Q_PROPERTY(QString hostname READ hostname CONSTANT) - Q_PROPERTY(QString prefilledUsername READ prefilledUsername CONSTANT) - -public: - BaseAuthenticationContextObject(const QString& hostname, const QString& prefilledUsername) - : DialogContextBase() - , m_hostname(hostname) - , m_prefilledUsername(prefilledUsername) - { - connect(this, SIGNAL(accepted(QString, QString)), SLOT(dismiss())); - connect(this, SIGNAL(rejected()), SLOT(dismiss())); - } - - QString hostname() const { return m_hostname; } - QString prefilledUsername() const { return m_prefilledUsername; } - -public Q_SLOTS: - void accept(const QString& username, const QString& password) { emit accepted(username, password); } - void reject() { emit rejected(); } - -Q_SIGNALS: - void accepted(const QString& username, const QString& password); - void rejected(); - -private: - QString m_hostname; - QString m_prefilledUsername; -}; - -class HttpAuthenticationDialogContextObject : public BaseAuthenticationContextObject { - Q_OBJECT - Q_PROPERTY(QString realm READ realm CONSTANT) - -public: - HttpAuthenticationDialogContextObject(const QString& hostname, const QString& realm, const QString& prefilledUsername) - : BaseAuthenticationContextObject(hostname, prefilledUsername) - , m_realm(realm) - { - } - - QString realm() const { return m_realm; } - -private: - QString m_realm; -}; - -class ProxyAuthenticationDialogContextObject : public BaseAuthenticationContextObject { - Q_OBJECT - Q_PROPERTY(quint16 port READ port CONSTANT) - -public: - ProxyAuthenticationDialogContextObject(const QString& hostname, quint16 port, const QString& prefilledUsername) - : BaseAuthenticationContextObject(hostname, prefilledUsername) - , m_port(port) - { - } - - quint16 port() const { return m_port; } - -private: - quint16 m_port; -}; - -class CertificateVerificationDialogContextObject : public DialogContextBase { - Q_OBJECT - Q_PROPERTY(QString hostname READ hostname CONSTANT) - -public: - CertificateVerificationDialogContextObject(const QString& hostname) - : DialogContextBase() - , m_hostname(hostname) - { - connect(this, SIGNAL(accepted()), SLOT(dismiss())); - connect(this, SIGNAL(rejected()), SLOT(dismiss())); - } - - QString hostname() const { return m_hostname; } - -public Q_SLOTS: - void accept() { emit accepted(); } - void reject() { emit rejected(); } - -Q_SIGNALS: - void accepted(); - void rejected(); - -private: - QString m_hostname; -}; - -class FilePickerContextObject : public DialogContextBase { - Q_OBJECT - Q_PROPERTY(QStringList fileList READ fileList CONSTANT) - Q_PROPERTY(bool allowMultipleFiles READ allowMultipleFiles CONSTANT) - -public: - FilePickerContextObject(const QStringList& selectedFiles, bool allowMultiple) - : DialogContextBase() - , m_allowMultiple(allowMultiple) - , m_fileList(selectedFiles) - { - connect(this, SIGNAL(fileSelected(QStringList)), SLOT(dismiss())); - connect(this, SIGNAL(rejected()), SLOT(dismiss())); - } - - QStringList fileList() const { return m_fileList; } - bool allowMultipleFiles() const { return m_allowMultiple;} - -public Q_SLOTS: - void reject() { emit rejected();} - void accept(const QVariant& path) - { - QStringList filesPath = path.toStringList(); - - if (filesPath.isEmpty()) { - emit rejected(); - return; - } - - // For single file upload, send only the first element if there are more than one file paths - if (!m_allowMultiple && filesPath.count() > 1) - filesPath = QStringList(filesPath.at(0)); - emit fileSelected(filesPath); - } - -Q_SIGNALS: - void rejected(); - void fileSelected(const QStringList&); - -private: - bool m_allowMultiple; - QStringList m_fileList; -}; - -class DatabaseQuotaDialogContextObject : public DialogContextBase { - Q_OBJECT - Q_PROPERTY(QString databaseName READ databaseName CONSTANT) - Q_PROPERTY(QString displayName READ displayName CONSTANT) - Q_PROPERTY(quint64 currentQuota READ currentQuota CONSTANT) - Q_PROPERTY(quint64 currentOriginUsage READ currentOriginUsage CONSTANT) - Q_PROPERTY(quint64 currentDatabaseUsage READ currentDatabaseUsage CONSTANT) - Q_PROPERTY(quint64 expectedUsage READ expectedUsage CONSTANT) - Q_PROPERTY(QtWebSecurityOrigin* origin READ securityOrigin CONSTANT) - -public: - DatabaseQuotaDialogContextObject(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage) - : DialogContextBase() - , m_databaseName(databaseName) - , m_displayName(displayName) - , m_currentQuota(currentQuota) - , m_currentOriginUsage(currentOriginUsage) - , m_currentDatabaseUsage(currentDatabaseUsage) - , m_expectedUsage(expectedUsage) - { - WKRetainPtr<WKStringRef> scheme = adoptWK(WKSecurityOriginCopyProtocol(securityOrigin)); - WKRetainPtr<WKStringRef> host = adoptWK(WKSecurityOriginCopyHost(securityOrigin)); - - m_securityOrigin.setScheme(WKStringCopyQString(scheme.get())); - m_securityOrigin.setHost(WKStringCopyQString(host.get())); - m_securityOrigin.setPort(static_cast<int>(WKSecurityOriginGetPort(securityOrigin))); - - connect(this, SIGNAL(accepted(quint64)), SLOT(dismiss())); - connect(this, SIGNAL(rejected()), SLOT(dismiss())); - } - - QString databaseName() const { return m_databaseName; } - QString displayName() const { return m_displayName; } - quint64 currentQuota() const { return m_currentQuota; } - quint64 currentOriginUsage() const { return m_currentOriginUsage; } - quint64 currentDatabaseUsage() const { return m_currentDatabaseUsage; } - quint64 expectedUsage() const { return m_expectedUsage; } - QtWebSecurityOrigin* securityOrigin() { return &m_securityOrigin; } - -public Q_SLOTS: - void accept(quint64 size) { emit accepted(size); } - void reject() { emit rejected(); } - -Q_SIGNALS: - void accepted(quint64 size); - void rejected(); - -private: - QString m_databaseName; - QString m_displayName; - quint64 m_currentQuota; - quint64 m_currentOriginUsage; - quint64 m_currentDatabaseUsage; - quint64 m_expectedUsage; - QtWebSecurityOrigin m_securityOrigin; -}; - void QtDialogRunner::run() { DialogContextBase* context = static_cast<DialogContextBase*>(m_dialogContext->contextObject()); @@ -476,5 +218,5 @@ void QtDialogRunner::onDatabaseQuotaAccepted(quint64 quota) } // namespace WebKit -#include "QtDialogRunner.moc" +#include "moc_DialogContextObjects.cpp" #include "moc_QtDialogRunner.cpp" diff --git a/Source/WebKit2/UIProcess/qt/QtPageClient.cpp b/Source/WebKit2/UIProcess/qt/QtPageClient.cpp index 53faa7647..fd410ffdd 100644 --- a/Source/WebKit2/UIProcess/qt/QtPageClient.cpp +++ b/Source/WebKit2/UIProcess/qt/QtPageClient.cpp @@ -90,7 +90,8 @@ void QtPageClient::pageDidRequestScroll(const IntPoint& pos) void QtPageClient::processDidExit() { - QQuickWebViewPrivate::get(m_webView)->processDidCrash(); + // TODO: Do we need this signal? + // QQuickWebViewPrivate::get(m_webView)->processDidExit(); } void QtPageClient::didRelaunchProcess() diff --git a/Source/WebKit2/UIProcess/qt/WebColorPickerQt.cpp b/Source/WebKit2/UIProcess/qt/WebColorPickerQt.cpp index 031c32d9e..c37099654 100644 --- a/Source/WebKit2/UIProcess/qt/WebColorPickerQt.cpp +++ b/Source/WebKit2/UIProcess/qt/WebColorPickerQt.cpp @@ -22,6 +22,7 @@ #include "config.h" #include "WebColorPickerQt.h" +#include "ColorChooserContextObject.h" #include "qquickwebview_p.h" #include "qquickwebview_p_p.h" #include <QtQml/QQmlContext> @@ -31,33 +32,6 @@ using namespace WebCore; namespace WebKit { -class ColorChooserContextObject : public QObject { - Q_OBJECT - Q_PROPERTY(QColor currentColor READ currentColor CONSTANT FINAL) - Q_PROPERTY(QRectF elementRect READ elementRect CONSTANT FINAL) - -public: - ColorChooserContextObject(const QColor& color, const QRectF& rect) - : m_currentColor(color) - , m_rect(rect) - { - } - - QColor currentColor() const { return m_currentColor; } - QRectF elementRect() const { return m_rect; } - - Q_INVOKABLE void accept(const QColor& color) { emit accepted(color); } - Q_INVOKABLE void reject() { emit rejected(); } - -Q_SIGNALS: - void accepted(const QColor&); - void rejected(); - -private: - QColor m_currentColor; - QRectF m_rect; -}; - WebColorPickerQt::WebColorPickerQt(WebColorPicker::Client* client, QQuickWebView* webView, const Color& initialColor, const IntRect& elementRect) : WebColorPicker(client) , m_webView(webView) @@ -149,5 +123,4 @@ void WebColorPickerQt::endPicker() } // namespace WebKit -#include "WebColorPickerQt.moc" #include "moc_WebColorPickerQt.cpp" diff --git a/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp b/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp index 249de62ec..066e273a9 100644 --- a/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp +++ b/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp @@ -27,6 +27,7 @@ #include "config.h" #include "WebPopupMenuProxyQt.h" +#include "ItemSelectorContextObject.h" #include "PlatformPopupMenuData.h" #include "WebPopupItem.h" #include "qquickwebview_p.h" @@ -39,229 +40,6 @@ using namespace WebCore; namespace WebKit { -static QHash<int, QByteArray> createRoleNamesHash(); - -class PopupMenuItemModel final : public QAbstractListModel { - Q_OBJECT - -public: - enum Roles { - GroupRole = Qt::UserRole, - EnabledRole = Qt::UserRole + 1, - SelectedRole = Qt::UserRole + 2, - IsSeparatorRole = Qt::UserRole + 3 - }; - - PopupMenuItemModel(const Vector<WebPopupItem>&, bool multiple); - int rowCount(const QModelIndex& parent = QModelIndex()) const final { return m_items.size(); } - QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const final; - QHash<int, QByteArray> roleNames() const final; - - Q_INVOKABLE void select(int); - - int selectedOriginalIndex() const; - bool multiple() const { return m_allowMultiples; } - void toggleItem(int); - -Q_SIGNALS: - void indexUpdated(); - -private: - struct Item { - Item(const WebPopupItem& webPopupItem, const QString& group, int originalIndex) - : text(webPopupItem.m_text) - , toolTip(webPopupItem.m_toolTip) - , group(group) - , originalIndex(originalIndex) - , enabled(webPopupItem.m_isEnabled) - , selected(webPopupItem.m_isSelected) - , isSeparator(webPopupItem.m_type == WebPopupItem::Separator) - { } - - QString text; - QString toolTip; - QString group; - // Keep track of originalIndex because we don't add the label (group) items to our vector. - int originalIndex; - bool enabled; - bool selected; - bool isSeparator; - }; - - void buildItems(const Vector<WebPopupItem>& webPopupItems); - - Vector<Item> m_items; - int m_selectedModelIndex; - bool m_allowMultiples; -}; - -class ItemSelectorContextObject : public QObject { - Q_OBJECT - Q_PROPERTY(QRectF elementRect READ elementRect CONSTANT FINAL) - Q_PROPERTY(QObject* items READ items CONSTANT FINAL) - Q_PROPERTY(bool allowMultiSelect READ allowMultiSelect CONSTANT FINAL) - -public: - ItemSelectorContextObject(const QRectF& elementRect, const Vector<WebPopupItem>&, bool multiple); - - QRectF elementRect() const { return m_elementRect; } - PopupMenuItemModel* items() { return &m_items; } - bool allowMultiSelect() { return m_items.multiple(); } - - Q_INVOKABLE void accept(int index = -1); - Q_INVOKABLE void reject() { emit done(); } - Q_INVOKABLE void dismiss() { emit done(); } - -Q_SIGNALS: - void acceptedWithOriginalIndex(int); - void done(); - -private Q_SLOTS: - void onIndexUpdate(); - -private: - QRectF m_elementRect; - PopupMenuItemModel m_items; -}; - -ItemSelectorContextObject::ItemSelectorContextObject(const QRectF& elementRect, const Vector<WebPopupItem>& webPopupItems, bool multiple) - : m_elementRect(elementRect) - , m_items(webPopupItems, multiple) -{ - connect(&m_items, SIGNAL(indexUpdated()), SLOT(onIndexUpdate())); -} - -void ItemSelectorContextObject::onIndexUpdate() -{ - // Send the update for multi-select list. - if (m_items.multiple()) - emit acceptedWithOriginalIndex(m_items.selectedOriginalIndex()); -} - - -void ItemSelectorContextObject::accept(int index) -{ - // If the index is not valid for multi-select lists, just hide the pop up as the selected indices have - // already been sent. - if ((index == -1) && m_items.multiple()) - emit done(); - else { - if (index != -1) - m_items.toggleItem(index); - emit acceptedWithOriginalIndex(m_items.selectedOriginalIndex()); - } -} - -static QHash<int, QByteArray> createRoleNamesHash() -{ - QHash<int, QByteArray> roles; - roles[Qt::DisplayRole] = "text"; - roles[Qt::ToolTipRole] = "tooltip"; - roles[PopupMenuItemModel::GroupRole] = "group"; - roles[PopupMenuItemModel::EnabledRole] = "enabled"; - roles[PopupMenuItemModel::SelectedRole] = "selected"; - roles[PopupMenuItemModel::IsSeparatorRole] = "isSeparator"; - return roles; -} - -PopupMenuItemModel::PopupMenuItemModel(const Vector<WebPopupItem>& webPopupItems, bool multiple) - : m_selectedModelIndex(-1) - , m_allowMultiples(multiple) -{ - buildItems(webPopupItems); -} - -QHash<int, QByteArray> PopupMenuItemModel::roleNames() const -{ - static QHash<int, QByteArray> roles = createRoleNamesHash(); - return roles; -} - -QVariant PopupMenuItemModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size()) - return QVariant(); - - const Item& item = m_items[index.row()]; - if (item.isSeparator) { - if (role == IsSeparatorRole) - return true; - return QVariant(); - } - - switch (role) { - case Qt::DisplayRole: - return item.text; - case Qt::ToolTipRole: - return item.toolTip; - case GroupRole: - return item.group; - case EnabledRole: - return item.enabled; - case SelectedRole: - return item.selected; - case IsSeparatorRole: - return false; - } - - return QVariant(); -} - -void PopupMenuItemModel::select(int index) -{ - toggleItem(index); - emit indexUpdated(); -} - -void PopupMenuItemModel::toggleItem(int index) -{ - int oldIndex = m_selectedModelIndex; - if (index < 0 || index >= m_items.size()) - return; - Item& item = m_items[index]; - if (!item.enabled) - return; - - m_selectedModelIndex = index; - if (m_allowMultiples) - item.selected = !item.selected; - else { - if (index == oldIndex) - return; - item.selected = true; - if (oldIndex != -1) { - Item& oldItem = m_items[oldIndex]; - oldItem.selected = false; - emit dataChanged(this->index(oldIndex), this->index(oldIndex)); - } - } - - emit dataChanged(this->index(index), this->index(index)); -} - -int PopupMenuItemModel::selectedOriginalIndex() const -{ - if (m_selectedModelIndex == -1) - return -1; - return m_items[m_selectedModelIndex].originalIndex; -} - -void PopupMenuItemModel::buildItems(const Vector<WebPopupItem>& webPopupItems) -{ - QString currentGroup; - m_items.reserveInitialCapacity(webPopupItems.size()); - for (int i = 0; i < webPopupItems.size(); i++) { - const WebPopupItem& webPopupItem = webPopupItems[i]; - if (webPopupItem.m_isLabel) { - currentGroup = webPopupItem.m_text; - continue; - } - if (webPopupItem.m_isSelected && !m_allowMultiples) - m_selectedModelIndex = m_items.size(); - m_items.append(Item(webPopupItem, currentGroup, i)); - } -} - WebPopupMenuProxyQt::WebPopupMenuProxyQt(WebPopupMenuProxy::Client& client, QQuickWebView* webView) : WebPopupMenuProxy(client) , m_webView(webView) @@ -348,8 +126,5 @@ void WebPopupMenuProxyQt::createContext(QQmlComponent* component, QObject* conte } // namespace WebKit -// Since we define QObjects in WebPopupMenuProxyQt.cpp, this will trigger moc to run on .cpp. -#include "WebPopupMenuProxyQt.moc" - // And we can't compile the moc for WebPopupMenuProxyQt.h by itself, since it doesn't include "config.h" #include "moc_WebPopupMenuProxyQt.cpp" |