diff options
-rw-r--r-- | src/core/color_chooser_controller.cpp | 99 | ||||
-rw-r--r-- | src/core/color_chooser_controller.h | 72 | ||||
-rw-r--r-- | src/core/color_chooser_controller_p.h | 70 | ||||
-rw-r--r-- | src/core/color_chooser_qt.cpp | 57 | ||||
-rw-r--r-- | src/core/color_chooser_qt.h | 71 | ||||
-rw-r--r-- | src/core/core_gyp_generator.pro | 5 | ||||
-rw-r--r-- | src/core/web_contents_adapter_client.h | 2 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 10 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 5 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 5 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 1 | ||||
-rw-r--r-- | src/webengine/ui/ColorDialog.qml | 47 | ||||
-rw-r--r-- | src/webengine/ui/ui.pro | 1 | ||||
-rw-r--r-- | src/webengine/ui_delegates_manager.cpp | 38 | ||||
-rw-r--r-- | src/webengine/ui_delegates_manager.h | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 16 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage_p.h | 1 |
17 files changed, 502 insertions, 0 deletions
diff --git a/src/core/color_chooser_controller.cpp b/src/core/color_chooser_controller.cpp new file mode 100644 index 000000000..da856d90e --- /dev/null +++ b/src/core/color_chooser_controller.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "content/browser/web_contents/web_contents_impl.h" + +#include "color_chooser_controller.h" +#include "color_chooser_controller_p.h" +#include "type_conversion.h" + +namespace QtWebEngineCore { + +ColorChooserControllerPrivate::ColorChooserControllerPrivate(content::WebContents *content, const QColor &color) + : m_content(content) + , m_initialColor(color) +{ +} + +ColorChooserController::~ColorChooserController() +{ +} + +ColorChooserController::ColorChooserController(ColorChooserControllerPrivate *dd) +{ + Q_ASSERT(dd); + d.reset(dd); +} + +QColor ColorChooserController::initialColor() const +{ + return d->m_initialColor; +} + +void ColorChooserController::didEndColorDialog() +{ + d->m_content->DidEndColorChooser(); +} + +void ColorChooserController::didChooseColorInColorDialog(const QColor &color) +{ + d->m_content->DidChooseColorInColorChooser(toSk(color)); +} + +void ColorChooserController::accept(const QColor &color) +{ + didChooseColorInColorDialog(color); + didEndColorDialog(); +} + +void ColorChooserController::accept(const QVariant &color) +{ + QColor selectedColor; + if (color.canConvert<QColor>()) { + selectedColor = color.value<QColor>(); + didChooseColorInColorDialog(selectedColor); + } + + didEndColorDialog(); +} + +void ColorChooserController::reject() +{ + didEndColorDialog(); +} + + +} // namespace diff --git a/src/core/color_chooser_controller.h b/src/core/color_chooser_controller.h new file mode 100644 index 000000000..609366967 --- /dev/null +++ b/src/core/color_chooser_controller.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLOR_CHOOSER_CONTROLLER_H +#define COLOR_CHOOSER_CONTROLLER_H + +#include "qtwebenginecoreglobal.h" + +#include <QObject> + +namespace QtWebEngineCore { + +class ColorChooserControllerPrivate; + +class QWEBENGINE_EXPORT ColorChooserController : public QObject { + Q_OBJECT +public: + ~ColorChooserController(); + + QColor initialColor() const; + + void didEndColorDialog(); + void didChooseColorInColorDialog(const QColor &); + +public Q_SLOTS: + void accept(const QColor &); + void accept(const QVariant &); + void reject(); + +private: + ColorChooserController(ColorChooserControllerPrivate *); + QScopedPointer<ColorChooserControllerPrivate> d; + + friend class ColorChooserQt; +}; + +} // namespace + +#endif // COLOR_CHOOSER_CONTROLLER_H diff --git a/src/core/color_chooser_controller_p.h b/src/core/color_chooser_controller_p.h new file mode 100644 index 000000000..a78e735a6 --- /dev/null +++ b/src/core/color_chooser_controller_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLOR_CHOOSER_CONTROLLER_P_H +#define COLOR_CHOOSER_CONTROLLER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QColor> + +namespace content { + class WebContents; +} + +namespace QtWebEngineCore { + +class ColorChooserControllerPrivate { + +public: + ColorChooserControllerPrivate(content::WebContents *, const QColor &); + content::WebContents *m_content; + QColor m_initialColor; +}; + +} // namespace + +#endif // COLOR_CHOOSER_CONTROLLER_P_H + diff --git a/src/core/color_chooser_qt.cpp b/src/core/color_chooser_qt.cpp new file mode 100644 index 000000000..a8f03be10 --- /dev/null +++ b/src/core/color_chooser_qt.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "color_chooser_qt.h" +#include "color_chooser_controller.h" +#include "color_chooser_controller_p.h" + +namespace content { + class WebContents; +} + +namespace QtWebEngineCore { + +ColorChooserQt::ColorChooserQt(content::WebContents *content, const QColor &color) +{ + m_controller.reset(new ColorChooserController(new ColorChooserControllerPrivate(content, color))); +} + +QSharedPointer<ColorChooserController> ColorChooserQt::controller() +{ + return m_controller; +} + +} // namespace diff --git a/src/core/color_chooser_qt.h b/src/core/color_chooser_qt.h new file mode 100644 index 000000000..b1e76b14c --- /dev/null +++ b/src/core/color_chooser_qt.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLOR_CHOOSER_QT_H +#define COLOR_CHOOSER_QT_H + +#include "content/public/browser/color_chooser.h" +#include "type_conversion.h" + +#include <QColor> +#include <QSharedPointer> + +namespace content { + class WebContents; +} + +namespace QtWebEngineCore { + +class ColorChooserController; + +class ColorChooserQt : public content::ColorChooser +{ +public: + ColorChooserQt(content::WebContents *, const QColor &); + + virtual void SetSelectedColor(SkColor color) Q_DECL_OVERRIDE { } + virtual void End() Q_DECL_OVERRIDE {} + + QSharedPointer<ColorChooserController> controller(); + +private: + QSharedPointer<ColorChooserController> m_controller; +}; + + +} // namespace + +#endif // COLOR_CHOOSER_QT_H diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index 14b8d78e2..29798f3fe 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -38,6 +38,8 @@ SOURCES = \ chromium_gpu_helper.cpp \ chromium_overrides.cpp \ clipboard_qt.cpp \ + color_chooser_qt.cpp \ + color_chooser_controller.cpp \ common/qt_messages.cpp \ common/user_script_data.cpp \ content_client_qt.cpp \ @@ -109,6 +111,9 @@ HEADERS = \ certificate_error_controller.h \ chromium_overrides.h \ clipboard_qt.h \ + color_chooser_qt.h \ + color_chooser_controller_p.h \ + color_chooser_controller.h \ common/qt_messages.h \ common/user_script_data.h \ content_client_qt.h \ diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index d9a2876f9..cbe5a687a 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -54,6 +54,7 @@ namespace QtWebEngineCore { class AuthenticationDialogController; class BrowserContextAdapter; +class ColorChooserController; class FilePickerController; class JavaScriptDialogController; class RenderWidgetHostViewQt; @@ -215,6 +216,7 @@ public: virtual bool isFullScreenMode() const = 0; virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) = 0; virtual void runFileChooser(FilePickerController *controller) = 0; + virtual void showColorDialog(QSharedPointer<ColorChooserController>) = 0; virtual void didRunJavaScript(quint64 requestId, const QVariant& result) = 0; virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) = 0; virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 1897664e3..2d707149d 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -41,6 +41,8 @@ #include "web_contents_delegate_qt.h" #include "browser_context_adapter.h" +#include "color_chooser_qt.h" +#include "color_chooser_controller.h" #include "file_picker_controller.h" #include "media_capture_devices_dispatcher.h" #include "network_delegate_qt.h" @@ -240,6 +242,14 @@ void WebContentsDelegateQt::DidUpdateFaviconURL(const std::vector<content::Favic } } +content::ColorChooser *WebContentsDelegateQt::OpenColorChooser(content::WebContents *source, SkColor color, const std::vector<content::ColorSuggestion> &suggestion) +{ + Q_UNUSED(suggestion); + ColorChooserQt *colorChooser = new ColorChooserQt(source, toQt(color)); + m_viewClient->showColorDialog(colorChooser->controller()); + + return colorChooser; +} content::JavaScriptDialogManager *WebContentsDelegateQt::GetJavaScriptDialogManager(content::WebContents *) { return JavaScriptDialogManagerQt::GetInstance(); diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index d3075cfbf..51b290d5a 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -40,9 +40,11 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/permission_status.mojom.h" +#include "third_party/skia/include/core/SkColor.h" #include "base/callback.h" +#include "color_chooser_controller.h" #include "javascript_dialog_manager_qt.h" #include <QtCore/qvector.h> #include <QtCore/qcompilerdetection.h> @@ -51,11 +53,13 @@ QT_FORWARD_DECLARE_CLASS(CertificateErrorController) namespace content { class BrowserContext; + class ColorChooser; class SiteInstance; class RenderViewHost; class JavaScriptDialogManager; class WebContents; struct WebPreferences; + struct ColorSuggestion; } namespace QtWebEngineCore { @@ -79,6 +83,7 @@ public: virtual void CloseContents(content::WebContents *source) Q_DECL_OVERRIDE; virtual void LoadProgressChanged(content::WebContents* source, double progress) Q_DECL_OVERRIDE; virtual void HandleKeyboardEvent(content::WebContents *source, const content::NativeWebKeyboardEvent &event) Q_DECL_OVERRIDE; + virtual content::ColorChooser *OpenColorChooser(content::WebContents *source, SkColor color, const std::vector<content::ColorSuggestion> &suggestion) Q_DECL_OVERRIDE; virtual content::JavaScriptDialogManager *GetJavaScriptDialogManager(content::WebContents *source) Q_DECL_OVERRIDE; virtual void EnterFullscreenModeForTab(content::WebContents* web_contents, const GURL& origin) Q_DECL_OVERRIDE; virtual void ExitFullscreenModeForTab(content::WebContents*) Q_DECL_OVERRIDE; diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index f266fdce6..19ef590b8 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -331,6 +331,11 @@ void QQuickWebEngineViewPrivate::runGeolocationPermissionRequest(const QUrl &url Q_EMIT q->featurePermissionRequested(url, QQuickWebEngineView::Geolocation); } +void QQuickWebEngineViewPrivate::showColorDialog(QSharedPointer<ColorChooserController> controller) +{ + ui()->showColorDialog(controller); +} + void QQuickWebEngineViewPrivate::runFileChooser(FilePickerController* controller) { ui()->showFilePicker(controller); diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 748944a69..7fca79b7a 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -150,6 +150,7 @@ public: virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) Q_DECL_OVERRIDE; virtual void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) Q_DECL_OVERRIDE; virtual void runFileChooser(QtWebEngineCore::FilePickerController *controller) Q_DECL_OVERRIDE; + virtual void showColorDialog(QSharedPointer<QtWebEngineCore::ColorChooserController>) Q_DECL_OVERRIDE; virtual void didRunJavaScript(quint64, const QVariant&) Q_DECL_OVERRIDE; virtual void didFetchDocumentMarkup(quint64, const QString&) Q_DECL_OVERRIDE { } virtual void didFetchDocumentInnerText(quint64, const QString&) Q_DECL_OVERRIDE { } diff --git a/src/webengine/ui/ColorDialog.qml b/src/webengine/ui/ColorDialog.qml new file mode 100644 index 000000000..27245d7f7 --- /dev/null +++ b/src/webengine/ui/ColorDialog.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick.Dialogs 1.2 + +ColorDialog { + id: colorDialog + + signal selectedColor(var color) + + onAccepted: { + selectedColor(colorDialog.currentColor) + } +} diff --git a/src/webengine/ui/ui.pro b/src/webengine/ui/ui.pro index 28ea691b2..249d7dcfd 100644 --- a/src/webengine/ui/ui.pro +++ b/src/webengine/ui/ui.pro @@ -5,6 +5,7 @@ QML_FILES += \ AuthenticationDialog.qml \ # JS Dialogs AlertDialog.qml \ + ColorDialog.qml \ ConfirmDialog.qml \ FilePicker.qml \ PromptDialog.qml \ diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp index 2e686b1b1..2714af9ab 100644 --- a/src/webengine/ui_delegates_manager.cpp +++ b/src/webengine/ui_delegates_manager.cpp @@ -38,6 +38,7 @@ #include "api/qquickwebengineview_p.h" #include <authentication_dialog_controller.h> +#include <color_chooser_controller.h> #include <file_picker_controller.h> #include <javascript_dialog_controller.h> #include <web_contents_adapter_client.h> @@ -318,6 +319,43 @@ void UIDelegatesManager::showDialog(QSharedPointer<JavaScriptDialogController> d QMetaObject::invokeMethod(dialog, "open"); } +void UIDelegatesManager::showColorDialog(QSharedPointer<ColorChooserController> controller) +{ + if (!ensureComponentLoaded(ColorDialog)) { + // Let the controller know it couldn't be loaded + qWarning("Failed to load dialog, rejecting."); + controller->reject(); + return; + } + + QQmlContext *context = qmlContext(m_view); + QObject *colorDialog = colorDialogComponent->beginCreate(context); + if (QQuickItem* item = qobject_cast<QQuickItem*>(colorDialog)) + item->setParentItem(m_view); + colorDialog->setParent(m_view); + + if (controller->initialColor().isValid()) + colorDialog->setProperty("color", controller->initialColor()); + + QQmlProperty selectedColorSignal(colorDialog, QStringLiteral("onSelectedColor")); + CHECK_QML_SIGNAL_PROPERTY(selectedColorSignal, colorDialogComponent->url()); + QQmlProperty rejectedSignal(colorDialog, QStringLiteral("onRejected")); + CHECK_QML_SIGNAL_PROPERTY(rejectedSignal, colorDialogComponent->url()); + + static int acceptIndex = controller->metaObject()->indexOfSlot("accept(QVariant)"); + QObject::connect(colorDialog, selectedColorSignal.method(), controller.data(), controller->metaObject()->method(acceptIndex)); + static int rejectIndex = controller->metaObject()->indexOfSlot("reject()"); + QObject::connect(colorDialog, rejectedSignal.method(), controller.data(), controller->metaObject()->method(rejectIndex)); + + // delete later + static int deleteLaterIndex = colorDialog->metaObject()->indexOfSlot("deleteLater()"); + QObject::connect(colorDialog, selectedColorSignal.method(), colorDialog, colorDialog->metaObject()->method(deleteLaterIndex)); + QObject::connect(colorDialog, rejectedSignal.method(), colorDialog, colorDialog->metaObject()->method(deleteLaterIndex)); + + colorDialogComponent->completeCreate(); + QMetaObject::invokeMethod(colorDialog, "open"); +} + void UIDelegatesManager::showDialog(QSharedPointer<AuthenticationDialogController> dialogController) { Q_ASSERT(!dialogController.isNull()); diff --git a/src/webengine/ui_delegates_manager.h b/src/webengine/ui_delegates_manager.h index 7a87c1eee..71d2e2fb0 100644 --- a/src/webengine/ui_delegates_manager.h +++ b/src/webengine/ui_delegates_manager.h @@ -51,6 +51,7 @@ F(MenuItem, menuItem) SEPARATOR \ F(MenuSeparator, menuSeparator) SEPARATOR \ F(AlertDialog, alertDialog) SEPARATOR \ + F(ColorDialog, colorDialog) SEPARATOR \ F(ConfirmDialog, confirmDialog) SEPARATOR \ F(PromptDialog, promptDialog) SEPARATOR \ F(FilePicker, filePicker) SEPARATOR \ @@ -103,6 +104,7 @@ public: void addMenuSeparator(QObject *menu); QObject *addMenu(QObject *parentMenu, const QString &title, const QPoint &pos = QPoint()); QQmlContext *creationContextForComponent(QQmlComponent *); + void showColorDialog(QSharedPointer<ColorChooserController>); void showDialog(QSharedPointer<JavaScriptDialogController>); void showDialog(QSharedPointer<AuthenticationDialogController>); void showFilePicker(FilePickerController *controller); diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index de0af4747..7d7ffdcf0 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -26,6 +26,7 @@ #include "authentication_dialog_controller.h" #include "browser_context_adapter.h" #include "certificate_error_controller.h" +#include "color_chooser_controller.h" #include "file_picker_controller.h" #include "javascript_dialog_controller.h" #include "qwebenginefullscreenrequest.h" @@ -49,6 +50,7 @@ #include <QApplication> #include <QAuthenticator> #include <QClipboard> +#include <QColorDialog> #include <QContextMenuEvent> #include <QFileDialog> #include <QKeyEvent> @@ -277,6 +279,20 @@ void QWebEnginePagePrivate::authenticationRequired(QSharedPointer<Authentication controller->accept(networkAuth.user(), networkAuth.password()); } +void QWebEnginePagePrivate::showColorDialog(QSharedPointer<ColorChooserController> controller) +{ + QColorDialog *dialog = new QColorDialog(controller.data()->initialColor(), view); + + QColorDialog::connect(dialog, SIGNAL(colorSelected(QColor)), controller.data(), SLOT(accept(QColor))); + QColorDialog::connect(dialog, SIGNAL(rejected()), controller.data(), SLOT(reject())); + + // Delete when done + QColorDialog::connect(dialog, SIGNAL(colorSelected(QColor)), dialog, SLOT(deleteLater())); + QColorDialog::connect(dialog, SIGNAL(rejected()), dialog, SLOT(deleteLater())); + + dialog->open(); +} + void QWebEnginePagePrivate::runMediaAccessPermissionRequest(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags requestFlags) { Q_Q(QWebEnginePage); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index dd43b08c8..6f1341054 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -102,6 +102,7 @@ public: virtual bool isFullScreenMode() const Q_DECL_OVERRIDE; virtual void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) Q_DECL_OVERRIDE; virtual void runFileChooser(QtWebEngineCore::FilePickerController *controller) Q_DECL_OVERRIDE; + virtual void showColorDialog(QSharedPointer<QtWebEngineCore::ColorChooserController>); virtual void didRunJavaScript(quint64 requestId, const QVariant& result) Q_DECL_OVERRIDE; virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) Q_DECL_OVERRIDE; virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) Q_DECL_OVERRIDE; |