Title: [120915] trunk/Source
Revision
120915
Author
[email protected]
Date
2012-06-21 03:58:53 -0700 (Thu, 21 Jun 2012)

Log Message

[WK2][Qt] Color chooser API missing
https://bugs.webkit.org/show_bug.cgi?id=87749

Patch by Thiago Marcos P. Santos <[email protected]> on 2012-06-21
Reviewed by Kenneth Rohde Christiansen.

Source/WebKit/qt:

Added ColorChooser API stub to WebKit. Otherwise
it will break the build for Qt WebKit2 (that now has
complete support for color chooser) when INPUT_TYPE_COLOR is set.

* WebCoreSupport/ChromeClientQt.cpp:
(WebCore):
(WebCore::ChromeClientQt::createColorChooser):
* WebCoreSupport/ChromeClientQt.h:
(ChromeClientQt):

Source/WebKit2:

Added public experimental API for ColorChooser. This will
allow the browser to define a custom dialog for selecting
color when a input field of type "color" get focus.

The current implementation gives a model to the QML Component
that has methods for canceling a request, selecting a color
and fetching what is the current value of the HTML input.

* Target.pri:
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::QQuickWebViewPrivate):
(QQuickWebViewExperimental::colorChooser):
(QQuickWebViewExperimental::setColorChooser):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):
* UIProcess/qt/QtPageClient.cpp:
(WebKit::QtPageClient::createColorChooserProxy):
* UIProcess/qt/WebColorChooserProxyQt.cpp: Added.
(WebKit):
(ColorChooserContextObject):
(WebKit::ColorChooserContextObject::ColorChooserContextObject):
(WebKit::ColorChooserContextObject::currentColor):
(WebKit::ColorChooserContextObject::accept):
(WebKit::ColorChooserContextObject::reject):
(WebKit::WebColorChooserProxyQt::WebColorChooserProxyQt):
(WebKit::WebColorChooserProxyQt::~WebColorChooserProxyQt):
(WebKit::WebColorChooserProxyQt::createItem):
(WebKit::WebColorChooserProxyQt::createContext):
(WebKit::WebColorChooserProxyQt::setSelectedColor):
(WebKit::WebColorChooserProxyQt::notifyColorSelected):
(WebKit::WebColorChooserProxyQt::endChooser):
* UIProcess/qt/WebColorChooserProxyQt.h: Added.
(WebCore):
(WebKit):
(WebColorChooserProxyQt):
(WebKit::WebColorChooserProxyQt::create):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/qt/ChangeLog (120914 => 120915)


--- trunk/Source/WebKit/qt/ChangeLog	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit/qt/ChangeLog	2012-06-21 10:58:53 UTC (rev 120915)
@@ -1,3 +1,20 @@
+2012-06-21  Thiago Marcos P. Santos  <[email protected]>
+
+        [WK2][Qt] Color chooser API missing
+        https://bugs.webkit.org/show_bug.cgi?id=87749
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Added ColorChooser API stub to WebKit. Otherwise
+        it will break the build for Qt WebKit2 (that now has
+        complete support for color chooser) when INPUT_TYPE_COLOR is set.
+
+        * WebCoreSupport/ChromeClientQt.cpp:
+        (WebCore):
+        (WebCore::ChromeClientQt::createColorChooser):
+        * WebCoreSupport/ChromeClientQt.h:
+        (ChromeClientQt):
+
 2012-06-20  Simon Hausmann  <[email protected]>
 
         [Qt] Unreviewed build fix

Modified: trunk/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp (120914 => 120915)


--- trunk/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp	2012-06-21 10:58:53 UTC (rev 120915)
@@ -31,6 +31,7 @@
 #include "ChromeClientQt.h"
 
 #include "ApplicationCacheStorage.h"
+#include "ColorChooser.h"
 #include "DatabaseTracker.h"
 #include "Document.h"
 #include "FileChooser.h"
@@ -557,6 +558,14 @@
     emit m_webPage->applicationCacheQuotaExceeded(securityOrigin, defaultOriginQuota, static_cast<quint64>(totalSpaceNeeded));
 }
 
+#if ENABLE(INPUT_TYPE_COLOR)
+PassOwnPtr<ColorChooser> ChromeClientQt::createColorChooser(ColorChooserClient*, const Color&)
+{
+    notImplemented();
+    return nullptr;
+}
+#endif
+
 void ChromeClientQt::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
 {
     RefPtr<FileChooser> fileChooser = prpFileChooser;

Modified: trunk/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.h (120914 => 120915)


--- trunk/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.h	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.h	2012-06-21 10:58:53 UTC (rev 120915)
@@ -163,6 +163,11 @@
     virtual bool requiresFullscreenForVideoPlayback();
     FullScreenVideoQt* fullScreenVideo();
 #endif
+
+#if ENABLE(INPUT_TYPE_COLOR)
+    virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&);
+#endif
+
      virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
      virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*);
 

Modified: trunk/Source/WebKit2/ChangeLog (120914 => 120915)


--- trunk/Source/WebKit2/ChangeLog	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit2/ChangeLog	2012-06-21 10:58:53 UTC (rev 120915)
@@ -1,3 +1,48 @@
+2012-06-21  Thiago Marcos P. Santos  <[email protected]>
+
+        [WK2][Qt] Color chooser API missing
+        https://bugs.webkit.org/show_bug.cgi?id=87749
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Added public experimental API for ColorChooser. This will
+        allow the browser to define a custom dialog for selecting
+        color when a input field of type "color" get focus.
+
+        The current implementation gives a model to the QML Component
+        that has methods for canceling a request, selecting a color
+        and fetching what is the current value of the HTML input.
+
+        * Target.pri:
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::QQuickWebViewPrivate):
+        (QQuickWebViewExperimental::colorChooser):
+        (QQuickWebViewExperimental::setColorChooser):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+        * UIProcess/qt/QtPageClient.cpp:
+        (WebKit::QtPageClient::createColorChooserProxy):
+        * UIProcess/qt/WebColorChooserProxyQt.cpp: Added.
+        (WebKit):
+        (ColorChooserContextObject):
+        (WebKit::ColorChooserContextObject::ColorChooserContextObject):
+        (WebKit::ColorChooserContextObject::currentColor):
+        (WebKit::ColorChooserContextObject::accept):
+        (WebKit::ColorChooserContextObject::reject):
+        (WebKit::WebColorChooserProxyQt::WebColorChooserProxyQt):
+        (WebKit::WebColorChooserProxyQt::~WebColorChooserProxyQt):
+        (WebKit::WebColorChooserProxyQt::createItem):
+        (WebKit::WebColorChooserProxyQt::createContext):
+        (WebKit::WebColorChooserProxyQt::setSelectedColor):
+        (WebKit::WebColorChooserProxyQt::notifyColorSelected):
+        (WebKit::WebColorChooserProxyQt::endChooser):
+        * UIProcess/qt/WebColorChooserProxyQt.h: Added.
+        (WebCore):
+        (WebKit):
+        (WebColorChooserProxyQt):
+        (WebKit::WebColorChooserProxyQt::create):
+
 2012-06-21  Mario Sanchez Prada  <[email protected]>
 
         [GTK] Add support for window.showModalDialog in WebKit2GTK+

Modified: trunk/Source/WebKit2/Target.pri (120914 => 120915)


--- trunk/Source/WebKit2/Target.pri	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit2/Target.pri	2012-06-21 10:58:53 UTC (rev 120915)
@@ -809,6 +809,13 @@
         Shared/qt/NativeWebTouchEventQt.cpp
 }
 
+contains(DEFINES, ENABLE_INPUT_TYPE_COLOR=1) {
+    HEADERS += \
+        UIProcess/qt/WebColorChooserProxyQt.h
+    SOURCES += \
+        UIProcess/qt/WebColorChooserProxyQt.cpp
+}
+
 contains(DEFINES, ENABLE_GEOLOCATION=1): QT += location
 
 plugin_backend_xlib {

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp (120914 => 120915)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-06-21 10:58:53 UTC (rev 120915)
@@ -266,6 +266,7 @@
     , proxyAuthenticationDialog(0)
     , filePicker(0)
     , databaseQuotaDialog(0)
+    , colorChooser(0)
     , m_useDefaultContentItemSize(true)
     , m_navigatorQtObjectEnabled(false)
     , m_renderToOffscreenBuffer(false)
@@ -1146,6 +1147,22 @@
     emit databaseQuotaDialogChanged();
 }
 
+QQmlComponent* QQuickWebViewExperimental::colorChooser() const
+{
+    Q_D(const QQuickWebView);
+    return d->colorChooser;
+}
+
+void QQuickWebViewExperimental::setColorChooser(QQmlComponent* colorChooser)
+{
+    Q_D(QQuickWebView);
+    if (d->colorChooser == colorChooser)
+        return;
+
+    d->colorChooser = colorChooser;
+    emit colorChooserChanged();
+}
+
 QString QQuickWebViewExperimental::userAgent() const
 {
     Q_D(const QQuickWebView);

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h (120914 => 120915)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2012-06-21 10:58:53 UTC (rev 120915)
@@ -265,6 +265,7 @@
     Q_PROPERTY(QQmlComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged)
     Q_PROPERTY(QQmlComponent* filePicker READ filePicker WRITE setFilePicker NOTIFY filePickerChanged)
     Q_PROPERTY(QQmlComponent* databaseQuotaDialog READ databaseQuotaDialog WRITE setDatabaseQuotaDialog NOTIFY databaseQuotaDialogChanged)
+    Q_PROPERTY(QQmlComponent* colorChooser READ colorChooser WRITE setColorChooser NOTIFY colorChooserChanged)
 
     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
     Q_PROPERTY(QWebKitTest* test READ test CONSTANT FINAL)
@@ -300,6 +301,8 @@
     void setFilePicker(QQmlComponent*);
     QQmlComponent* databaseQuotaDialog() const;
     void setDatabaseQuotaDialog(QQmlComponent*);
+    QQmlComponent* colorChooser() const;
+    void setColorChooser(QQmlComponent*);
     QString userAgent() const;
     void setUserAgent(const QString& userAgent);
     int deviceWidth() const;
@@ -356,6 +359,7 @@
     void itemSelectorChanged();
     void filePickerChanged();
     void databaseQuotaDialogChanged();
+    void colorChooserChanged();
     void downloadRequested(QWebDownloadItem* downloadItem);
     void permissionRequested(QWebPermissionRequest* permission);
     void messageReceived(const QVariantMap& message);

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h (120914 => 120915)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2012-06-21 10:58:53 UTC (rev 120915)
@@ -185,6 +185,7 @@
     QQmlComponent* proxyAuthenticationDialog;
     QQmlComponent* filePicker;
     QQmlComponent* databaseQuotaDialog;
+    QQmlComponent* colorChooser;
 
     QList<QUrl> userScripts;
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPageClient.cpp (120914 => 120915)


--- trunk/Source/WebKit2/UIProcess/qt/QtPageClient.cpp	2012-06-21 10:24:32 UTC (rev 120914)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPageClient.cpp	2012-06-21 10:58:53 UTC (rev 120915)
@@ -26,6 +26,9 @@
 #include "QtWebPageEventHandler.h"
 #include "QtWebUndoController.h"
 #include "ShareableBitmap.h"
+#if ENABLE(INPUT_TYPE_COLOR)
+#include "WebColorChooserProxyQt.h"
+#endif
 #include "WebContextMenuProxyQt.h"
 #include "WebEditCommandProxy.h"
 #include "WebPopupMenuProxyQt.h"
@@ -206,10 +209,9 @@
 }
 
 #if ENABLE(INPUT_TYPE_COLOR)
-PassRefPtr<WebColorChooserProxy> QtPageClient::createColorChooserProxy(WebPageProxy*, const WebCore::Color&)
+PassRefPtr<WebColorChooserProxy> QtPageClient::createColorChooserProxy(WebPageProxy* webPageProxy, const WebCore::Color& initialColor)
 {
-    notImplemented();
-    return 0;
+    return WebColorChooserProxyQt::create(webPageProxy, m_webView, initialColor);
 }
 #endif
 

Added: trunk/Source/WebKit2/UIProcess/qt/WebColorChooserProxyQt.cpp (0 => 120915)


--- trunk/Source/WebKit2/UIProcess/qt/WebColorChooserProxyQt.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/WebColorChooserProxyQt.cpp	2012-06-21 10:58:53 UTC (rev 120915)
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ *
+ */
+
+#include "config.h"
+#include "WebColorChooserProxyQt.h"
+
+#include "qquickwebview_p.h"
+#include "qquickwebview_p_p.h"
+#include <QtQml/QQmlContext>
+#include <QtQml/QQmlEngine>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class ColorChooserContextObject : public QObject {
+    Q_OBJECT
+    Q_PROPERTY(QColor currentColor READ currentColor CONSTANT FINAL)
+
+public:
+    ColorChooserContextObject(const QColor& color)
+        : m_currentColor(color)
+    {
+    }
+
+    QColor currentColor() const { return m_currentColor; }
+
+    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;
+};
+
+WebColorChooserProxyQt::WebColorChooserProxyQt(WebColorChooserProxy::Client* client, QQuickWebView* webView, const Color& initialColor)
+    : WebColorChooserProxy(client)
+    , m_webView(webView)
+{
+    ColorChooserContextObject* contextObject = new ColorChooserContextObject(initialColor);
+    createItem(contextObject);
+}
+
+WebColorChooserProxyQt::~WebColorChooserProxyQt()
+{
+}
+
+void WebColorChooserProxyQt::createItem(QObject* contextObject)
+{
+    QQmlComponent* component = m_webView->experimental()->colorChooser();
+    if (!component) {
+        delete contextObject;
+        return;
+    }
+
+    createContext(component, contextObject);
+    QObject* object = component->beginCreate(m_context.get());
+    if (!object) {
+        m_context.clear();
+        return;
+    }
+
+    m_colorChooser = adoptPtr(qobject_cast<QQuickItem*>(object));
+    if (!m_colorChooser) {
+        m_context.clear();
+        return;
+    }
+
+    // Needs to be enqueue because it might trigger deletion.
+    connect(contextObject, SIGNAL(accepted(QColor)), SLOT(notifyColorSelected(QColor)), Qt::QueuedConnection);
+    connect(contextObject, SIGNAL(rejected()), SLOT(endChooser()), Qt::QueuedConnection);
+
+    QQuickWebViewPrivate::get(m_webView)->addAttachedPropertyTo(m_colorChooser.get());
+    m_colorChooser->setParentItem(m_webView);
+
+    component->completeCreate();
+    QQuickWebViewPrivate::get(m_webView)->setDialogActive(true);
+}
+
+void WebColorChooserProxyQt::createContext(QQmlComponent* component, QObject* contextObject)
+{
+    QQmlContext* baseContext = component->creationContext();
+    if (!baseContext)
+        baseContext = QQmlEngine::contextForObject(m_webView);
+    m_context = adoptPtr(new QQmlContext(baseContext));
+
+    contextObject->setParent(m_context.get());
+    m_context->setContextProperty(QLatin1String("model"), contextObject);
+    m_context->setContextObject(contextObject);
+}
+
+void WebColorChooserProxyQt::setSelectedColor(const Color&)
+{
+    // This is suppose to be used to react to DOM changes. When
+    // a user script changes the input value, the method gives the
+    // option to update the color chooser UI if we were showing the
+    // current value. Since we don't, it is irrelevant right now.
+    // And yes, the name sounds misleading but comes from WebCore.
+}
+
+void WebColorChooserProxyQt::notifyColorSelected(const QColor& color)
+{
+    if (!m_client)
+        return;
+
+    // Alpha is always ignored by the color input
+    Color coreColor = makeRGB(color.red(), color.green(), color.blue());
+    m_client->didChooseColor(coreColor);
+
+    endChooser();
+}
+
+void WebColorChooserProxyQt::endChooser()
+{
+    QQuickWebViewPrivate::get(m_webView)->setDialogActive(false);
+
+    m_colorChooser.clear();
+    m_context.clear();
+
+    if (!m_client)
+        return;
+
+    m_client->didEndColorChooser();
+}
+
+} // namespace WebKit
+
+#include "WebColorChooserProxyQt.moc"
+#include "moc_WebColorChooserProxyQt.cpp"

Added: trunk/Source/WebKit2/UIProcess/qt/WebColorChooserProxyQt.h (0 => 120915)


--- trunk/Source/WebKit2/UIProcess/qt/WebColorChooserProxyQt.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/WebColorChooserProxyQt.h	2012-06-21 10:58:53 UTC (rev 120915)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * 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 WebColorChooserProxyQt_h
+#define WebColorChooserProxyQt_h
+
+#include "WebColorChooserProxy.h"
+#include <QtCore/QObject>
+#include <wtf/OwnPtr.h>
+
+class QQmlComponent;
+class QQmlContext;
+class QQuickItem;
+class QQuickWebView;
+
+namespace WebCore {
+class Color;
+}
+
+namespace WebKit {
+
+class WebColorChooserProxyQt : public QObject, public WebColorChooserProxy {
+    Q_OBJECT
+
+public:
+    static PassRefPtr<WebColorChooserProxy> create(WebColorChooserProxy::Client* client, QQuickWebView* webView, const WebCore::Color& initialColor)
+    {
+        return adoptRef(new WebColorChooserProxyQt(client, webView, initialColor));
+    }
+    ~WebColorChooserProxyQt();
+
+    virtual void setSelectedColor(const WebCore::Color&);
+
+public Q_SLOTS:
+    virtual void endChooser();
+
+private Q_SLOTS:
+    void notifyColorSelected(const QColor&);
+
+private:
+    WebColorChooserProxyQt(WebColorChooserProxy::Client*, QQuickWebView*, const WebCore::Color&);
+
+    void createItem(QObject*);
+    void createContext(QQmlComponent*, QObject*);
+
+    OwnPtr<QQmlContext> m_context;
+    OwnPtr<QQuickItem> m_colorChooser;
+
+    QQuickWebView* m_webView;
+};
+
+} // namespace WebKit
+
+#endif // WebColorChooserProxyQt_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to