Share common code between calendar picker and color suggestion picker
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Aug 2012 03:34:14 +0000 (03:34 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Aug 2012 03:34:14 +0000 (03:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93802

Reviewed by Kent Tamura.

.:

* ManualTests/forms/calendar-picker.html:
* ManualTests/forms/color-suggestion-picker.html:

Source/WebCore:

We want to share common code like utility functions between picker page popups.

No new tests because no behavior change. Covered by existing tests, color-suggestion-picker-appearance.html and calendar-picker-apeparance.html.

* Resources/pagepopups/calendarPicker.js:
(YearMonthController.prototype.attachTo):
(YearMonthController.prototype._showPopup):
* Resources/pagepopups/colorSuggestionPicker.js:
(handleMessage):
(handleArgumentsTimeout):
* Resources/pagepopups/pickerCommon.css: Added.
(body):
* Resources/pagepopups/pickerCommon.js: Added.
(createElement):
(resizeWindow):
(getScrollbarWidth):
* WebCore.gyp/WebCore.gyp: Add actions for pickerCommon.{css,js}
* html/shadow/CalendarPickerElement.cpp:
(WebCore::CalendarPickerElement::writeDocument):

Source/WebKit/chromium:

* src/ColorChooserUIController.cpp:
(WebKit::ColorChooserUIController::writeDocument):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125641 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
ChangeLog
ManualTests/forms/calendar-picker.html
ManualTests/forms/color-suggestion-picker.html
Source/WebCore/ChangeLog
Source/WebCore/Resources/pagepopups/calendarPicker.js
Source/WebCore/Resources/pagepopups/colorSuggestionPicker.js
Source/WebCore/Resources/pagepopups/pickerCommon.css [new file with mode: 0644]
Source/WebCore/Resources/pagepopups/pickerCommon.js [new file with mode: 0644]
Source/WebCore/WebCore.gyp/WebCore.gyp
Source/WebCore/html/shadow/CalendarPickerElement.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/ColorChooserUIController.cpp

index a28c6a8..c19362d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-08-14  Keishi Hattori  <keishi@webkit.org>
+
+        Share common code between calendar picker and color suggestion picker
+        https://bugs.webkit.org/show_bug.cgi?id=93802
+
+        Reviewed by Kent Tamura.
+
+        * ManualTests/forms/calendar-picker.html:
+        * ManualTests/forms/color-suggestion-picker.html:
+
 2012-08-14  Milian Wolff  <milian.wolff@kdab.com>
 
         [Qt] QtWebKit linking fails for QNX cross build
index 369f981..d212a78 100644 (file)
@@ -73,10 +73,17 @@ function openCalendar(args) {
     var frame = document.getElementsByTagName('iframe')[0];
     var doc = frame.contentDocument;
     doc.documentElement.innerHTML = '<head></head><body><div id=main>Loading...</div></body>';
+    var commonCssLink = doc.createElement('link');
+    commonCssLink.rel = 'stylesheet';
+    commonCssLink.href = '../../Source/WebCore/Resources/pagepopups/pickerCommon.css?' + (new Date()).getTime();
+    doc.head.appendChild(commonCssLink);
     var link = doc.createElement('link');
     link.rel = 'stylesheet';
     link.href = '../../Source/WebCore/Resources/pagepopups/calendarPicker.css?' + (new Date()).getTime();
     doc.head.appendChild(link);
+    var commonJsScript = doc.createElement('script');
+    commonJsScript.src = '../../Source/WebCore/Resources/pagepopups/pickerCommon.js?' + (new Date()).getTime();
+    doc.body.appendChild(commonJsScript);
     var script = doc.createElement('script');
     script.src = '../../Source/WebCore/Resources/pagepopups/calendarPicker.js?' + (new Date()).getTime();
     doc.body.appendChild(script);
index 8f460f3..ded4e7c 100644 (file)
@@ -36,10 +36,17 @@ function openColorPicker(args) {
     var frame = document.getElementsByTagName('iframe')[0];
     var doc = frame.contentDocument;
     doc.documentElement.innerHTML = '<head></head><body><div id=main>Loading...</div></body>';
+    var commonCssLink = doc.createElement('link');
+    commonCssLink.rel = 'stylesheet';
+    commonCssLink.href = '../../Source/WebCore/Resources/pagepopups/pickerCommon.css?' + (new Date()).getTime();
+    doc.head.appendChild(commonCssLink);
     var link = doc.createElement('link');
     link.rel = 'stylesheet';
     link.href = '../../Source/WebCore/Resources/pagepopups/colorSuggestionPicker.css?' + (new Date()).getTime();
     doc.head.appendChild(link);
+    var commonJsScript = doc.createElement('script');
+    commonJsScript.src = '../../Source/WebCore/Resources/pagepopups/pickerCommon.js?' + (new Date()).getTime();
+    doc.body.appendChild(commonJsScript);
     var script = doc.createElement('script');
     script.src = '../../Source/WebCore/Resources/pagepopups/colorSuggestionPicker.js?' + (new Date()).getTime();
     doc.body.appendChild(script);
index 3c01e26..2e31087 100644 (file)
@@ -1,3 +1,30 @@
+2012-08-14  Keishi Hattori  <keishi@webkit.org>
+
+        Share common code between calendar picker and color suggestion picker
+        https://bugs.webkit.org/show_bug.cgi?id=93802
+
+        Reviewed by Kent Tamura.
+
+        We want to share common code like utility functions between picker page popups.
+
+        No new tests because no behavior change. Covered by existing tests, color-suggestion-picker-appearance.html and calendar-picker-apeparance.html.
+
+        * Resources/pagepopups/calendarPicker.js:
+        (YearMonthController.prototype.attachTo):
+        (YearMonthController.prototype._showPopup):
+        * Resources/pagepopups/colorSuggestionPicker.js:
+        (handleMessage):
+        (handleArgumentsTimeout):
+        * Resources/pagepopups/pickerCommon.css: Added.
+        (body):
+        * Resources/pagepopups/pickerCommon.js: Added.
+        (createElement):
+        (resizeWindow):
+        (getScrollbarWidth):
+        * WebCore.gyp/WebCore.gyp: Add actions for pickerCommon.{css,js}
+        * html/shadow/CalendarPickerElement.cpp:
+        (WebCore::CalendarPickerElement::writeDocument):
+
 2012-08-14  Ojan Vafai  <ojan@chromium.org>
 
         Fix access to m_markupBox in WebCore::EllipsisBox::paint
index 93ed721..ccc4b8d 100644 (file)
@@ -51,7 +51,6 @@ var ClassNames = {
     MonthSelectorPopup: "month-selector-popup",
     MonthSelectorPopupContents: "month-selector-popup-contents",
     MonthSelectorPopupEntry: "month-selector-popup-entry",
-    MonthSelectorPopupSizer: "month-selector-popup-sizer",
     MonthSelectorWall: "month-selector-wall",
     NoFocusRing: "no-focus-ring",
     NotThisMonth: "not-this-month",
@@ -81,34 +80,6 @@ var global = {
 // Utility functions
 
 /**
- * @param {!string} id
- */
-function $(id) {
-    return document.getElementById(id);
-}
-
-function bind(func, context) {
-    return function() {
-        return func.apply(context, arguments);
-    };
-}
-
-/**
- * @param {!string} tagName
- * @param {string=} opt_class
- * @param {string=} opt_text
- * @return {!Element}
- */
-function createElement(tagName, opt_class, opt_text) {
-    var element = document.createElement(tagName);
-    if (opt_class)
-        element.setAttribute("class", opt_class);
-    if (opt_text)
-        element.appendChild(document.createTextNode(opt_text));
-    return element;
-}
-
-/**
  * @return {!string} lowercase locale name. e.g. "en-us"
  */
 function getLocale() {
@@ -224,19 +195,6 @@ function serializeDate(year, month, day) {
     return yearString + "-" + ("0" + (month + 1)).substr(-2, 2) + "-" + ("0" + day).substr(-2, 2);
 }
 
-/**
- * @param {!number} width
- * @param {!number} height
- */
-function resizeWindow(width, height) {
-    if (window.frameElement) {
-        window.frameElement.style.width = width + "px";
-        window.frameElement.style.height = height + "px";
-    } else {
-        window.resizeTo(width, height);
-    }
-}
-
 // ----------------------------------------------------------------
 // Initialization
 
@@ -451,9 +409,6 @@ YearMonthController.prototype.attachTo = function(main) {
     this._monthPopup.tabIndex = 0;
     this._monthPopupContents = createElement("div", ClassNames.MonthSelectorPopupContents);
     this._monthPopup.appendChild(this._monthPopupContents);
-    // Sizer used to determine the width of the viewport in the popup menu.
-    var sizer = createElement("div", ClassNames.MonthSelectorPopupSizer);
-    this._monthPopup.appendChild(sizer);
     box.appendChild(this._monthPopup);
     this._month = createElement("div", ClassNames.MonthSelector);
     this._month.addEventListener("click", bind(this._showPopup, this), false);
@@ -609,10 +564,7 @@ YearMonthController.prototype._showPopup = function() {
            if (bottom > popupHeight)
                this._monthPopup.scrollTop = bottom - popupHeight;
         }
-        var sizer = document.querySelector("." + ClassNames.MonthSelectorPopupSizer);
-        var scrollWidth = this._monthPopupContents.clientWidth - sizer.clientWidth;
-        if (scrollWidth > 0)
-            this._monthPopup.style.webkitPaddingEnd = scrollWidth + 'px';
+        this._monthPopup.style.webkitPaddingEnd = getScrollbarWidth() + 'px';
     }
     this._monthPopup.focus();
 };
index a827e96..d48cb96 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-var global = {
-    argumentsReceived: false,
-    scrollbarWidth: null
-};
-
-/**
- * @param {!string} id
- */
-function $(id) {
-    return document.getElementById(id);
-}
-
-function bind(func, context) {
-    return function() {
-        return func.apply(context, arguments);
-    };
-}
-
-function getScrollbarWidth() {
-    if (global.scrollbarWidth === null) {
-        var scrollDiv = document.createElement("div");
-        scrollDiv.style.opacity = "0";
-        scrollDiv.style.overflow = "scroll";
-        scrollDiv.style.width = "50px";
-        scrollDiv.style.height = "50px";
-        document.body.appendChild(scrollDiv);
-        global.scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
-        scrollDiv.parentNode.removeChild(scrollDiv);
-    }
-    return global.scrollbarWidth;
-}
-
-/**
- * @param {!string} tagName
- * @param {string=} opt_class
- * @param {string=} opt_text
- * @return {!Element}
- */
-function createElement(tagName, opt_class, opt_text) {
-    var element = document.createElement(tagName);
-    if (opt_class)
-        element.setAttribute("class", opt_class);
-    if (opt_text)
-        element.appendChild(document.createTextNode(opt_text));
-    return element;
-}
-
-/**
- * @param {!number} width
- * @param {!number} height
- */
-function resizeWindow(width, height) {
-    if (window.frameElement) {
-        window.frameElement.style.width = width + "px";
-        window.frameElement.style.height = height + "px";
-    } else {
-        window.resizeTo(width, height);
-    }
-}
+window.argumentsReceived = false;
 
 /**
  * @param {Event} event
  */
 function handleMessage(event) {
     initialize(JSON.parse(event.data));
-    global.argumentsReceived = true;
+    window.argumentsReceived = true;
 }
 
 /**
@@ -111,7 +53,7 @@ var DefaultColorPalette = ["#000000", "#404040", "#808080", "#c0c0c0",
     "#4a86e8", "#0000ff", "#9900ff", "#ff00ff"];
 
 function handleArgumentsTimeout() {
-    if (global.argumentsReceived)
+    if (window.argumentsReceived)
         return;
     var args = {
         values : DefaultColorPalette,
diff --git a/Source/WebCore/Resources/pagepopups/pickerCommon.css b/Source/WebCore/Resources/pagepopups/pickerCommon.css
new file mode 100644 (file)
index 0000000..71c5ea4
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 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.
+ */
+
+body {
+    -webkit-user-select: none;
+    background-color: white;
+    font: -webkit-small-control;
+    margin: 0;
+    overflow: hidden;
+}
diff --git a/Source/WebCore/Resources/pagepopups/pickerCommon.js b/Source/WebCore/Resources/pagepopups/pickerCommon.js
new file mode 100644 (file)
index 0000000..dfb2918
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 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.
+ */
+
+/**
+ * @param {!string} id
+ */
+function $(id) {
+    return document.getElementById(id);
+}
+
+function bind(func, context) {
+    return function() {
+        return func.apply(context, arguments);
+    };
+}
+
+/**
+ * @param {!string} tagName
+ * @param {string=} opt_class
+ * @param {string=} opt_text
+ * @return {!Element}
+ */
+function createElement(tagName, opt_class, opt_text) {
+    var element = document.createElement(tagName);
+    if (opt_class)
+        element.setAttribute("class", opt_class);
+    if (opt_text)
+        element.appendChild(document.createTextNode(opt_text));
+    return element;
+}
+
+/**
+ * @param {!number} width
+ * @param {!number} height
+ */
+function resizeWindow(width, height) {
+    if (window.frameElement) {
+        window.frameElement.style.width = width + "px";
+        window.frameElement.style.height = height + "px";
+    } else {
+        window.resizeTo(width, height);
+    }
+}
+
+function getScrollbarWidth() {
+    if (typeof window.scrollbarWidth === "undefined") {
+        var scrollDiv = document.createElement("div");
+        scrollDiv.style.opacity = "0";
+        scrollDiv.style.overflow = "scroll";
+        scrollDiv.style.width = "50px";
+        scrollDiv.style.height = "50px";
+        document.body.appendChild(scrollDiv);
+        window.scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
+        scrollDiv.parentNode.removeChild(scrollDiv);
+    }
+    return window.scrollbarWidth;
+}
index f812f78..1577a9e 100644 (file)
           ],
         },
         {
+          'action_name': 'PickerCommon',
+          'inputs': [
+            '../Resources/pagepopups/pickerCommon.css',
+            '../Resources/pagepopups/pickerCommon.js',
+          ],
+          'outputs': [
+            '<(SHARED_INTERMEDIATE_DIR)/webkit/PickerCommon.h',
+            '<(SHARED_INTERMEDIATE_DIR)/webkit/PickerCommon.cpp',
+          ],
+          'action': [
+            'python',
+            '../make-file-arrays.py',
+            '--condition=ENABLE(CALENDAR_PICKER)',
+            '--out-h=<(SHARED_INTERMEDIATE_DIR)/webkit/PickerCommon.h',
+            '--out-cpp=<(SHARED_INTERMEDIATE_DIR)/webkit/PickerCommon.cpp',
+            '<@(_inputs)',
+          ],
+        },
+        {
           'action_name': 'CalendarPicker',
           'inputs': [
             '../Resources/pagepopups/calendarPicker.css',
         '<(SHARED_INTERMEDIATE_DIR)/webkit/EventTargetHeaders.h',
         '<(SHARED_INTERMEDIATE_DIR)/webkit/EventTargetInterfaces.h',
         '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionCodeDescription.cpp',
+        '<(SHARED_INTERMEDIATE_DIR)/webkit/PickerCommon.cpp',
         '<(SHARED_INTERMEDIATE_DIR)/webkit/UserAgentStyleSheetsData.cpp',
         '<(SHARED_INTERMEDIATE_DIR)/webkit/V8HTMLElementWrapperFactory.cpp',
         '<(SHARED_INTERMEDIATE_DIR)/webkit/XLinkNames.cpp',
index e70151d..f3244de 100644 (file)
@@ -45,6 +45,7 @@
 #include "LocalizedDate.h"
 #include "LocalizedStrings.h"
 #include "Page.h"
+#include "PickerCommon.h"
 #include "RenderDetailsMarker.h"
 #include "RenderTheme.h"
 #include <wtf/text/StringBuilder.h>
@@ -165,6 +166,7 @@ void CalendarPickerElement::writeDocument(DocumentWriter& writer)
         stepString = "1";
 
     addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
+    writer.addData(pickerCommonCss, sizeof(pickerCommonCss));
     writer.addData(calendarPickerCss, sizeof(calendarPickerCss));
     if (document()->page()) {
         CString extraStyle = document()->page()->theme()->extraCalendarPickerStyleSheet();
@@ -188,6 +190,7 @@ void CalendarPickerElement::writeDocument(DocumentWriter& writer)
     addProperty("isRTL", dir == RightToLeft || dir == RightToLeftArabic, writer);
     addString("}\n", writer);
 
+    writer.addData(pickerCommonJs, sizeof(pickerCommonJs));
     writer.addData(calendarPickerJs, sizeof(calendarPickerJs));
     addString("</script></body>\n", writer);
 }
index 2678bb1..7f78dde 100644 (file)
@@ -1,3 +1,13 @@
+2012-08-14  Keishi Hattori  <keishi@webkit.org>
+
+        Share common code between calendar picker and color suggestion picker
+        https://bugs.webkit.org/show_bug.cgi?id=93802
+
+        Reviewed by Kent Tamura.
+
+        * src/ColorChooserUIController.cpp:
+        (WebKit::ColorChooserUIController::writeDocument):
+
 2012-08-14  Scott Graham  <scottmg@chromium.org>
 
         [Chromium] Fix warnings on Windows build
index 28cdc38..c77634c 100644 (file)
@@ -34,6 +34,7 @@
 #include "ColorSuggestionPicker.h"
 #include "IntRect.h"
 #include "LocalizedStrings.h"
+#include "PickerCommon.h"
 #include "WebColorChooser.h"
 #include "platform/WebColor.h"
 #include "platform/WebKitPlatformSupport.h"
@@ -103,12 +104,14 @@ void ColorChooserUIController::writeDocument(WebCore::DocumentWriter& writer)
         suggestionValues.append(suggestions[i].serialized());
     
     WebCore::PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
+    writer.addData(WebCore::pickerCommonCss, sizeof(WebCore::pickerCommonCss));
     writer.addData(WebCore::colorSuggestionPickerCss, sizeof(WebCore::colorSuggestionPickerCss));
     WebCore::PagePopupClient::addString("</style></head><body><div id=main>Loading...</div><script>\n"
                                       "window.dialogArguments = {\n", writer);
     WebCore::PagePopupClient::addProperty("values", suggestionValues, writer);       
     WebCore::PagePopupClient::addProperty("otherColorLabel", Platform::current()->queryLocalizedString(WebLocalizedString::OtherColorLabel), writer);
     WebCore::PagePopupClient::addString("};\n", writer);
+    writer.addData(WebCore::pickerCommonJs, sizeof(WebCore::pickerCommonJs));
     writer.addData(WebCore::colorSuggestionPickerJs, sizeof(WebCore::colorSuggestionPickerJs));
     WebCore::PagePopupClient::addString("</script></body>\n", writer);
 }