Title: [127817] trunk/Source/WebKit
Revision
127817
Author
[email protected]
Date
2012-09-06 21:18:53 -0700 (Thu, 06 Sep 2012)

Log Message

[BlackBerry]  Implement a color picker
https://bugs.webkit.org/show_bug.cgi?id=96001

Patch by Crystal Zhang <[email protected]> on 2012-09-06
Reviewed by Rob Buis.

Source/WebKit:

Add color picker files into building system.

* PlatformBlackBerry.cmake:

Source/WebKit/blackberry:

Add files for color picker, replace old hook to AIR color picker.

* WebCoreSupport/ColorPickerClient.cpp: Added.
(WebCore):
(WebCore::ColorPickerClient::ColorPickerClient):
(WebCore::ColorPickerClient::~ColorPickerClient):
(WebCore::ColorPickerClient::generateHTML):
(WebCore::ColorPickerClient::closePopup):
(WebCore::ColorPickerClient::contentSize):
(WebCore::ColorPickerClient::htmlSource):
(WebCore::ColorPickerClient::setValueAndClosePopup):
(WebCore::ColorPickerClient::didClosePopup):
(WebCore::ColorPickerClient::writeDocument):
* WebCoreSupport/ColorPickerClient.h: Added.
(WebKit):
(WebCore):
(ColorPickerClient):
* WebKitSupport/InputHandler.cpp:
(BlackBerry::WebKit::InputHandler::openColorPopup):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (127816 => 127817)


--- trunk/Source/WebKit/ChangeLog	2012-09-07 04:14:57 UTC (rev 127816)
+++ trunk/Source/WebKit/ChangeLog	2012-09-07 04:18:53 UTC (rev 127817)
@@ -1,3 +1,14 @@
+2012-09-06  Crystal Zhang  <[email protected]>
+
+        [BlackBerry]  Implement a color picker
+        https://bugs.webkit.org/show_bug.cgi?id=96001
+
+        Reviewed by Rob Buis.
+
+        Add color picker files into building system.
+
+        * PlatformBlackBerry.cmake:
+
 2012-09-06  Simon Hausmann  <[email protected]>
 
         [Qt] Fix build with ANGLE on platforms that provide EGL/GLESv2

Modified: trunk/Source/WebKit/PlatformBlackBerry.cmake (127816 => 127817)


--- trunk/Source/WebKit/PlatformBlackBerry.cmake	2012-09-07 04:14:57 UTC (rev 127816)
+++ trunk/Source/WebKit/PlatformBlackBerry.cmake	2012-09-07 04:18:53 UTC (rev 127817)
@@ -92,6 +92,7 @@
     blackberry/WebCoreSupport/PagePopupBlackBerry.cpp
     blackberry/WebCoreSupport/SelectPopupClient.cpp
     blackberry/WebCoreSupport/DatePickerClient.cpp
+    blackberry/WebCoreSupport/ColorPickerClient.cpp
     blackberry/WebKitSupport/AboutData.cpp
     blackberry/WebKitSupport/BackingStoreCompositingSurface.cpp
     blackberry/WebKitSupport/BackingStoreTile.cpp

Modified: trunk/Source/WebKit/blackberry/ChangeLog (127816 => 127817)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-09-07 04:14:57 UTC (rev 127816)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-09-07 04:18:53 UTC (rev 127817)
@@ -1,3 +1,30 @@
+2012-09-06  Crystal Zhang  <[email protected]>
+
+        [BlackBerry]  Implement a color picker
+        https://bugs.webkit.org/show_bug.cgi?id=96001
+
+        Reviewed by Rob Buis.
+
+        Add files for color picker, replace old hook to AIR color picker.
+
+        * WebCoreSupport/ColorPickerClient.cpp: Added.
+        (WebCore):
+        (WebCore::ColorPickerClient::ColorPickerClient):
+        (WebCore::ColorPickerClient::~ColorPickerClient):
+        (WebCore::ColorPickerClient::generateHTML):
+        (WebCore::ColorPickerClient::closePopup):
+        (WebCore::ColorPickerClient::contentSize):
+        (WebCore::ColorPickerClient::htmlSource):
+        (WebCore::ColorPickerClient::setValueAndClosePopup):
+        (WebCore::ColorPickerClient::didClosePopup):
+        (WebCore::ColorPickerClient::writeDocument):
+        * WebCoreSupport/ColorPickerClient.h: Added.
+        (WebKit):
+        (WebCore):
+        (ColorPickerClient):
+        * WebKitSupport/InputHandler.cpp:
+        (BlackBerry::WebKit::InputHandler::openColorPopup):
+
 2012-09-06  Genevieve Mak  <[email protected]>
 
         Add data-blackberry-webworks-context attribute and set the custom context when

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/ColorPickerClient.cpp (0 => 127817)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ColorPickerClient.cpp	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ColorPickerClient.cpp	2012-09-07 04:18:53 UTC (rev 127817)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "ColorPickerClient.h"
+
+#include "Chrome.h"
+#include "ChromeClient.h"
+#include "Document.h"
+#include "DocumentWriter.h"
+#include "HTMLInputElement.h"
+#include "Page.h"
+#include "PagePopup.h"
+#include "PopupPicker.h"
+#include "RenderObject.h"
+#include "WebPage_p.h"
+#include "WebString.h"
+
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+ColorPickerClient::ColorPickerClient(const BlackBerry::WebKit::WebString& value, BlackBerry::WebKit::WebPagePrivate* webPage, HTMLInputElement* element)
+    : m_webPage(webPage)
+    , m_element(element)
+{
+    generateHTML(value);
+}
+
+void ColorPickerClient::generateHTML(const BlackBerry::WebKit::WebString& value)
+{
+    StringBuilder source;
+    source.append("<style>\n");
+    // Include CSS file.
+    source.append(popupControlBlackBerryCss,
+            sizeof(popupControlBlackBerryCss));
+    source.append("</style>\n<style>");
+    source.append(colorControlBlackBerryCss,
+            sizeof(colorControlBlackBerryCss));
+    source.append("</style></head><body>\n");
+    source.append("<script>\n");
+    source.append("window.addEventListener('load', function () {");
+    source.append("window.popupcontrol.show(");
+    if (!value.isEmpty())
+        source.append("\"" + String(value.impl()) + "\"); \n }); \n");
+    else
+        source.append("); \n }); \n");
+    source.append(colorControlBlackBerryJs, sizeof(colorControlBlackBerryJs));
+    source.append("</script>\n");
+    source.append("</body> </html>\n");
+    m_source = source.toString();
+}
+
+void ColorPickerClient::closePopup()
+{
+    ASSERT(m_webPage);
+    m_webPage->m_page->chrome()->client()->closePagePopup(0);
+}
+
+IntSize ColorPickerClient::contentSize()
+{
+    // FIXME: will generate content size dynamically
+    return IntSize(320, 256);
+}
+
+String ColorPickerClient::htmlSource() const
+{
+    return m_source;
+}
+
+void ColorPickerClient::setValueAndClosePopup(int, const String& value)
+{
+    ASSERT(m_element);
+
+    static const char* cancelValue = "-1";
+    if (value != cancelValue)
+        m_element->setValue(value);
+    closePopup();
+}
+
+void ColorPickerClient::didClosePopup()
+{
+    m_webPage = 0;
+    m_element = 0;
+}
+
+void ColorPickerClient::writeDocument(DocumentWriter& writer)
+{
+    CString sourceString = m_source.utf8();
+    writer.addData(sourceString.data(), sourceString.length());
+}
+}

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/ColorPickerClient.h (0 => 127817)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ColorPickerClient.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ColorPickerClient.h	2012-09-07 04:18:53 UTC (rev 127817)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef ColorPickerClient_h
+#define ColorPickerClient_h
+
+#include "PagePopupClient.h"
+#include <BlackBerryPlatformInputEvents.h>
+
+namespace BlackBerry {
+namespace WebKit {
+class WebPagePrivate;
+class WebString;
+}
+}
+
+namespace WebCore {
+class DocumentWriter;
+class HTMLInputElement;
+
+class ColorPickerClient : public PagePopupClient {
+public:
+    ColorPickerClient(const BlackBerry::WebKit::WebString& value, BlackBerry::WebKit::WebPagePrivate*, HTMLInputElement*);
+
+    void generateHTML(const BlackBerry::WebKit::WebString& value);
+    void writeDocument(DocumentWriter&);
+    IntSize contentSize();
+    String htmlSource() const;
+    void setValueAndClosePopup(int, const String&);
+    void didClosePopup();
+
+private:
+    void closePopup();
+
+    String m_source;
+    BlackBerry::WebKit::WebPagePrivate* m_webPage;
+    HTMLInputElement* m_element;
+};
+} // namespace WebCore
+#endif

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp (127816 => 127817)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-09-07 04:14:57 UTC (rev 127816)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-09-07 04:18:53 UTC (rev 127817)
@@ -23,6 +23,7 @@
 #include "BackingStoreClient.h"
 #include "CSSStyleDeclaration.h"
 #include "Chrome.h"
+#include "ColorPickerClient.h"
 #include "DOMSupport.h"
 #include "DatePickerClient.h"
 #include "Document.h"
@@ -977,8 +978,11 @@
     m_currentFocusElement = element;
     m_currentFocusElementType = TextPopup;
 
-    // FIXME: Need to add pagePopup support and the colour dialog.
-    // PR 180778
+    // Check if popup already exists, close it if does.
+    m_webPage->m_page->chrome()->client()->closePagePopup(0);
+    ColorPickerClient* client = new ColorPickerClient(element->value(), m_webPage, element);
+    m_webPage->m_page->chrome()->client()->openPagePopup(client,  WebCore::IntRect());
+    return true;
 }
 
 void InputHandler::setInputValue(const WTF::String& value)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to