Skip to content

Instantly share code, notes, and snippets.

@keishi
Created April 22, 2011 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keishi/936213 to your computer and use it in GitHub Desktop.
Save keishi/936213 to your computer and use it in GitHub Desktop.
Add Color Input Control
diff --git a/LayoutTests/fast/forms/input-widths.html b/LayoutTests/fast/forms/input-widths.html
index f9efbf6..dc9deb1 100644
--- a/LayoutTests/fast/forms/input-widths.html
+++ b/LayoutTests/fast/forms/input-widths.html
@@ -38,7 +38,6 @@ shouldBe('document.getElementById("url").offsetWidth', 'baseWidth');
// type=search is not tested intentionally.
// The folloiwng types should be removed when dedicated UIs are implemented.
-shouldBe('document.getElementById("color").offsetWidth', 'baseWidth');
shouldBe('document.getElementById("date").offsetWidth', 'baseWidth');
shouldBe('document.getElementById("datetime").offsetWidth', 'baseWidth');
shouldBe('document.getElementById("datetimelocal").offsetWidth', 'baseWidth');
diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am
index 2801232..e0ed5a8 100644
--- a/Source/WebCore/GNUmakefile.list.am
+++ b/Source/WebCore/GNUmakefile.list.am
@@ -2306,6 +2306,7 @@ webcore_sources += \
Source/WebCore/platform/AsyncFileSystem.cpp \
Source/WebCore/platform/AsyncFileSystem.h \
Source/WebCore/platform/AutodrainedPool.h \
+ Source/WebCore/platform/ColorChooser.cpp \
Source/WebCore/platform/ContentType.cpp \
Source/WebCore/platform/ContentType.h \
Source/WebCore/platform/ContextMenu.h \
diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in
index d8ee526..981545e 100644
--- a/Source/WebCore/WebCore.exp.in
+++ b/Source/WebCore/WebCore.exp.in
@@ -1305,6 +1305,9 @@ __ZTVN7WebCore17FrameLoaderClientE
__ZTVN7WebCore18PlatformStrategiesE
__ZTVN7WebCore25HistoryPropertyListWriterE
__ZTVN7WebCore28InspectorFrontendClientLocal8SettingsE
+__ZN7WebCore7makeRGBEiii
+__ZN7WebCore12ColorChooser7chooserEv
+__ZN7WebCore12ColorChooser11chooseColorERKNS_5ColorE
_filenameByFixingIllegalCharacters
_hasCaseInsensitiveSubstring
_hasCaseInsensitiveSuffix
diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi
index 3a5cea5..5e46f06 100644
--- a/Source/WebCore/WebCore.gypi
+++ b/Source/WebCore/WebCore.gypi
@@ -731,6 +731,7 @@
'page/mac/WebCoreFrameView.h',
'page/mac/WebCoreViewFactory.h',
'platform/AsyncFileStream.h',
+ 'platform/ColorChooser.h',
'platform/ContextMenu.h',
'platform/ContextMenuItem.h',
'platform/Cookie.h',
diff --git a/Source/WebCore/WebCore.pro b/Source/WebCore/WebCore.pro
index d805809..f9a757c 100644
--- a/Source/WebCore/WebCore.pro
+++ b/Source/WebCore/WebCore.pro
@@ -957,6 +957,7 @@ SOURCES += \
platform/text/BidiContext.cpp \
platform/text/Hyphenation.cpp \
platform/text/LocalizedNumberNone.cpp \
+ platform/ColorChooser.cpp \
platform/ContentType.cpp \
platform/CrossThreadCopier.cpp \
platform/DefaultLocalizationStrategy.cpp \
diff --git a/Source/WebCore/WebCore.vcproj/WebCore.vcproj b/Source/WebCore/WebCore.vcproj/WebCore.vcproj
index 676949c..312f263 100755
--- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/Source/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -25950,6 +25950,14 @@
>
</File>
<File
+ RelativePath="..\platform\ColorChooser.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\platform\ColorChooser.h"
+ >
+ </File>
+ <File
RelativePath="..\platform\ContentType.cpp"
>
</File>
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index 8475a91..3a2950c 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -5370,6 +5370,8 @@
C0DFC8700DB6841A003EAE7C /* JSConsoleCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0DFC86F0DB6841A003EAE7C /* JSConsoleCustom.cpp */; };
C105DA620F3AA68F001DD44F /* TextEncodingDetectorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */; };
C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
+ C3EA60371360019E00E97683 /* ColorChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = C3EA60351360019E00E97683 /* ColorChooser.h */; };
+ C3EA60381360019E00E97683 /* ColorChooser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C3EA60361360019E00E97683 /* ColorChooser.cpp */; };
C50B561612119D23008B46E0 /* GroupSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50B561412119D23008B46E0 /* GroupSettings.cpp */; };
C50B561712119D23008B46E0 /* GroupSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = C50B561512119D23008B46E0 /* GroupSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
C50D0E820FF4272900AC2644 /* StorageNamespace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50D0E800FF4272900AC2644 /* StorageNamespace.cpp */; };
@@ -11882,6 +11884,8 @@
C0DFC86F0DB6841A003EAE7C /* JSConsoleCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSConsoleCustom.cpp; sourceTree = "<group>"; };
C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; };
C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
+ C3EA60351360019E00E97683 /* ColorChooser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorChooser.h; sourceTree = "<group>"; };
+ C3EA60361360019E00E97683 /* ColorChooser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorChooser.cpp; sourceTree = "<group>"; };
C50B561412119D23008B46E0 /* GroupSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GroupSettings.cpp; sourceTree = "<group>"; };
C50B561512119D23008B46E0 /* GroupSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupSettings.h; sourceTree = "<group>"; };
C50D0E800FF4272900AC2644 /* StorageNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageNamespace.cpp; sourceTree = "<group>"; };
@@ -18780,6 +18784,8 @@
9380F47109A11AB4001FDB34 /* Widget.cpp */,
9380F47209A11AB4001FDB34 /* Widget.h */,
E1E1BEFF115FF6FB006F52CA /* WindowsKeyboardCodes.h */,
+ C3EA60351360019E00E97683 /* ColorChooser.h */,
+ C3EA60361360019E00E97683 /* ColorChooser.cpp */,
);
path = platform;
sourceTree = "<group>";
@@ -20078,6 +20084,7 @@
93C441F00F813A1A00C1A634 /* CollectionCache.h in Headers */,
93C442000F813AE100C1A634 /* CollectionType.h in Headers */,
B27535670B053814002CE64F /* Color.h in Headers */,
+ C3EA60371360019E00E97683 /* ColorChooser.h in Headers */,
B22279630D00BF220071B782 /* ColorDistance.h in Headers */,
F55B3DB41251F12D003EF269 /* ColorInputType.h in Headers */,
EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,
@@ -25712,6 +25719,7 @@
93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */,
E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
+ C3EA60381360019E00E97683 /* ColorChooser.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/Source/WebCore/css/CSSPrimitiveValueMappings.h b/Source/WebCore/css/CSSPrimitiveValueMappings.h
index b1f9aec..9731715 100644
--- a/Source/WebCore/css/CSSPrimitiveValueMappings.h
+++ b/Source/WebCore/css/CSSPrimitiveValueMappings.h
@@ -219,6 +219,12 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(ControlPart e)
case ListItemPart:
m_value.ident = CSSValueListitem;
break;
+ case ColorWellPart:
+ m_value.ident = CSSValueColorWell;
+ break;
+ case ColorListPart:
+ m_value.ident = CSSValueColorList;
+ break;
case MediaFullscreenButtonPart:
m_value.ident = CSSValueMediaFullscreenButton;
break;
diff --git a/Source/WebCore/css/CSSValueKeywords.in b/Source/WebCore/css/CSSValueKeywords.in
index 6dac06f..8a7364d 100644
--- a/Source/WebCore/css/CSSValueKeywords.in
+++ b/Source/WebCore/css/CSSValueKeywords.in
@@ -576,6 +576,8 @@ inner-spin-button
list-button
listbox
listitem
+color-well
+color-list
media-fullscreen-button
media-mute-button
media-play-button
diff --git a/Source/WebCore/css/html.css b/Source/WebCore/css/html.css
index ecbaef9..4fbbff3 100644
--- a/Source/WebCore/css/html.css
+++ b/Source/WebCore/css/html.css
@@ -576,6 +576,14 @@ input[type="radio"] {
-webkit-box-sizing: border-box;
}
+input[type="color"] {
+ -webkit-appearance: color-well;
+}
+
+input[type="color"][list] {
+ -webkit-appearance: color-list;
+}
+
select {
-webkit-appearance: menulist;
-webkit-box-sizing: border-box;
diff --git a/Source/WebCore/html/ColorInputType.cpp b/Source/WebCore/html/ColorInputType.cpp
index c55eba2..d5f6095 100644
--- a/Source/WebCore/html/ColorInputType.cpp
+++ b/Source/WebCore/html/ColorInputType.cpp
@@ -31,8 +31,12 @@
#include "config.h"
#include "ColorInputType.h"
+#include "Chrome.h"
#include "Color.h"
#include "HTMLInputElement.h"
+#include "MouseEvent.h"
+#include "Page.h"
+#include "RenderBlock.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/text/WTFString.h>
@@ -84,4 +88,26 @@ bool ColorInputType::supportsRequired() const
return false;
}
+bool ColorInputType::shouldRespectListAttribute()
+{
+ return true;
+}
+
+RenderObject* ColorInputType::createRenderer(RenderArena* arena, RenderStyle*) const
+{
+ return new (arena) RenderBlock(element());
+}
+
+void ColorInputType::handleMouseDownEvent(MouseEvent* event)
+{
+ ColorChooser::chooser()->connectClient(this);
+ element()->document()->page()->chrome()->runColorPanel(Color(element()->value()));
+ event->setDefaultHandled();
+}
+
+void ColorInputType::colorChanged(const Color& color)
+{
+ element()->setValue(color.serialized(), true);
+}
+
} // namespace WebCore
diff --git a/Source/WebCore/html/ColorInputType.h b/Source/WebCore/html/ColorInputType.h
index ea3798b..25b6899 100644
--- a/Source/WebCore/html/ColorInputType.h
+++ b/Source/WebCore/html/ColorInputType.h
@@ -31,20 +31,25 @@
#ifndef ColorInputType_h
#define ColorInputType_h
-#include "TextFieldInputType.h"
+#include "BaseButtonInputType.h"
+#include "ColorChooser.h"
namespace WebCore {
-class ColorInputType : public TextFieldInputType {
+class ColorInputType : public BaseButtonInputType, private ColorChooserClient {
public:
static PassOwnPtr<InputType> create(HTMLInputElement*);
private:
- ColorInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
+ ColorInputType(HTMLInputElement* element) : BaseButtonInputType(element) { }
virtual const AtomicString& formControlType() const;
virtual bool typeMismatchFor(const String&) const;
virtual bool typeMismatch() const;
virtual bool supportsRequired() const;
+ virtual bool shouldRespectListAttribute();
+ virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
+ virtual void handleMouseDownEvent(MouseEvent*);
+ virtual void colorChanged(const Color&);
};
} // namespace WebCore
diff --git a/Source/WebCore/loader/EmptyClients.h b/Source/WebCore/loader/EmptyClients.h
index e9971a4..a079baf 100644
--- a/Source/WebCore/loader/EmptyClients.h
+++ b/Source/WebCore/loader/EmptyClients.h
@@ -196,6 +196,8 @@ public:
virtual void enumerateChosenDirectory(const String&, FileChooser*) { }
#endif
+ virtual void runColorPanel(const Color&) { }
+
virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) { }
virtual void chooseIconForFiles(const Vector<String>&, FileChooser*) { }
diff --git a/Source/WebCore/page/Chrome.cpp b/Source/WebCore/page/Chrome.cpp
index dce7d33..4adf268 100644
--- a/Source/WebCore/page/Chrome.cpp
+++ b/Source/WebCore/page/Chrome.cpp
@@ -444,6 +444,11 @@ void Chrome::cancelGeolocationPermissionRequestForFrame(Frame* frame, Geolocatio
m_client->cancelGeolocationPermissionRequestForFrame(frame, geolocation);
}
+void Chrome::runColorPanel(const Color& color)
+{
+ m_client->runColorPanel(color);
+}
+
#if ENABLE(DIRECTORY_UPLOAD)
void Chrome::enumerateChosenDirectory(const String& path, FileChooser* fileChooser)
{
diff --git a/Source/WebCore/page/Chrome.h b/Source/WebCore/page/Chrome.h
index 9adfec8..a2f62e0 100644
--- a/Source/WebCore/page/Chrome.h
+++ b/Source/WebCore/page/Chrome.h
@@ -21,6 +21,7 @@
#ifndef Chrome_h
#define Chrome_h
+#include "Color.h"
#include "Cursor.h"
#include "FileChooser.h"
#include "FocusDirection.h"
@@ -151,6 +152,8 @@ namespace WebCore {
void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);
+ void runColorPanel(const Color&);
+
void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
void chooseIconForFiles(const Vector<String>&, FileChooser*);
#if ENABLE(DIRECTORY_UPLOAD)
diff --git a/Source/WebCore/page/ChromeClient.h b/Source/WebCore/page/ChromeClient.h
index 5d5b229..43df19a 100644
--- a/Source/WebCore/page/ChromeClient.h
+++ b/Source/WebCore/page/ChromeClient.h
@@ -220,6 +220,8 @@ namespace WebCore {
virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) = 0;
virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
+ virtual void runColorPanel(const Color&) = 0;
+
virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
// Asynchronous request to load an icon for specified filenames.
virtual void chooseIconForFiles(const Vector<String>&, FileChooser*) = 0;
diff --git a/Source/WebCore/platform/ColorChooser.cpp b/Source/WebCore/platform/ColorChooser.cpp
new file mode 100644
index 0000000..85a967f
--- /dev/null
+++ b/Source/WebCore/platform/ColorChooser.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "ColorChooser.h"
+
+namespace WebCore {
+
+ColorChooserClient::~ColorChooserClient()
+{
+ ColorChooser::chooser()->disconnectClient(this);
+}
+
+static ColorChooser* staticChooser = 0;
+
+ColorChooser* ColorChooser::chooser()
+{
+ if (!staticChooser)
+ staticChooser = new ColorChooser();
+
+ return staticChooser;
+}
+
+void ColorChooser::connectClient(ColorChooserClient* client)
+{
+ if (client != m_client)
+ m_client = client;
+}
+
+void ColorChooser::disconnectClient(const ColorChooserClient* client)
+{
+ if (client == m_client)
+ m_client = 0;
+}
+
+void ColorChooser::chooseColor(const Color& color)
+{
+ if (m_client)
+ m_client->colorChanged(color);
+}
+
+}
diff --git a/Source/WebCore/platform/ColorChooser.h b/Source/WebCore/platform/ColorChooser.h
new file mode 100644
index 0000000..a3cbc6a
--- /dev/null
+++ b/Source/WebCore/platform/ColorChooser.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+ *
+ */
+
+#ifndef ColorChooser_h
+#define ColorChooser_h
+
+#include "Color.h"
+
+namespace WebCore {
+
+class ColorChooser;
+
+class ColorChooserClient {
+public:
+ virtual void colorChanged(const Color&) = 0;
+ virtual ~ColorChooserClient();
+};
+
+class ColorChooser {
+public:
+ static ColorChooser* chooser();
+
+ void connectClient(ColorChooserClient*);
+ void disconnectClient(const ColorChooserClient*);
+ bool disconnected() { return !m_client; }
+
+ void chooseColor(const Color&);
+
+private:
+ ColorChooserClient* m_client;
+};
+
+} // namespace WebCore
+
+#endif // ColorChooser_h
diff --git a/Source/WebCore/platform/ThemeTypes.h b/Source/WebCore/platform/ThemeTypes.h
index ec45cb7..c799c5b 100644
--- a/Source/WebCore/platform/ThemeTypes.h
+++ b/Source/WebCore/platform/ThemeTypes.h
@@ -48,7 +48,7 @@ typedef unsigned ControlStates;
enum ControlPart {
NoControlPart, CheckboxPart, RadioPart, PushButtonPart, SquareButtonPart, ButtonPart,
ButtonBevelPart, DefaultButtonPart, InnerSpinButtonPart, InputSpeechButtonPart, ListButtonPart, ListboxPart, ListItemPart,
- MediaFullscreenButtonPart, MediaMuteButtonPart, MediaPlayButtonPart, MediaSeekBackButtonPart,
+ ColorWellPart, ColorListPart, MediaFullscreenButtonPart, MediaMuteButtonPart, MediaPlayButtonPart, MediaSeekBackButtonPart,
MediaSeekForwardButtonPart, MediaRewindButtonPart, MediaReturnToRealtimeButtonPart, MediaToggleClosedCaptionsButtonPart,
MediaSliderPart, MediaSliderThumbPart, MediaVolumeSliderContainerPart, MediaVolumeSliderPart, MediaVolumeSliderThumbPart,
MediaVolumeSliderMuteButtonPart, MediaControlsBackgroundPart, MediaControlsFullscreenBackgroundPart, MediaCurrentTimePart, MediaTimeRemainingPart,
diff --git a/Source/WebCore/rendering/RenderTheme.cpp b/Source/WebCore/rendering/RenderTheme.cpp
index 8de1878..cf14f1a 100644
--- a/Source/WebCore/rendering/RenderTheme.cpp
+++ b/Source/WebCore/rendering/RenderTheme.cpp
@@ -203,6 +203,10 @@ void RenderTheme::adjustStyle(CSSStyleSelector* selector, RenderStyle* style, El
return adjustMenuListStyle(selector, style, e);
case MenulistButtonPart:
return adjustMenuListButtonStyle(selector, style, e);
+ case ColorWellPart:
+ return adjustColorWellStyle(selector, style, e);
+ case ColorListPart:
+ return adjustColorListStyle(selector, style, e);
case MediaSliderPart:
case MediaVolumeSliderPart:
case SliderHorizontalPart:
@@ -316,6 +320,10 @@ bool RenderTheme::paint(RenderObject* o, const PaintInfo& paintInfo, const IntRe
return paintSliderThumb(o, paintInfo, r);
// We don't support drawing a slider thumb without a parent slider
break;
+ case ColorWellPart:
+ return paintColorWell(o, paintInfo, r);
+ case ColorListPart:
+ return paintColorList(o, paintInfo, r);
case MediaFullscreenButtonPart:
return paintMediaFullscreenButton(o, paintInfo, r);
case MediaPlayButtonPart:
@@ -394,6 +402,7 @@ bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, c
return paintTextArea(o, paintInfo, r);
case MenulistButtonPart:
case SearchFieldPart:
+ case ColorWellPart:
return true;
case CheckboxPart:
case RadioPart:
@@ -424,6 +433,7 @@ bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, c
#if ENABLE(INPUT_SPEECH)
case InputSpeechButtonPart:
#endif
+ case ColorListPart:
default:
break;
}
@@ -473,6 +483,8 @@ bool RenderTheme::paintDecorations(RenderObject* o, const PaintInfo& paintInfo,
#if ENABLE(INPUT_SPEECH)
case InputSpeechButtonPart:
#endif
+ case ColorWellPart:
+ case ColorListPart:
default:
break;
}
@@ -1001,6 +1013,14 @@ void RenderTheme::adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderS
{
}
+void RenderTheme::adjustColorWellStyle(CSSStyleSelector*, RenderStyle*, Element*) const
+{
+}
+
+void RenderTheme::adjustColorListStyle(CSSStyleSelector*, RenderStyle*, Element*) const
+{
+}
+
void RenderTheme::platformColorsDidChange()
{
m_activeSelectionForegroundColor = Color();
diff --git a/Source/WebCore/rendering/RenderTheme.h b/Source/WebCore/rendering/RenderTheme.h
index 8384644..f1fa30d 100644
--- a/Source/WebCore/rendering/RenderTheme.h
+++ b/Source/WebCore/rendering/RenderTheme.h
@@ -285,6 +285,12 @@ protected:
virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
+ virtual void adjustColorWellStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
+ virtual bool paintColorWell(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
+
+ virtual void adjustColorListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
+ virtual bool paintColorList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
+
virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
@@ -316,6 +322,9 @@ public:
bool isSpinUpButtonPartHovered(const RenderObject*) const;
bool isReadOnlyControl(const RenderObject*) const;
bool isDefault(const RenderObject*) const;
+
+protected:
+ Theme* theme() { return m_theme; }
private:
mutable Color m_activeSelectionBackgroundColor;
diff --git a/Source/WebCore/rendering/RenderThemeMac.h b/Source/WebCore/rendering/RenderThemeMac.h
index 8a17acf..e5907ff 100644
--- a/Source/WebCore/rendering/RenderThemeMac.h
+++ b/Source/WebCore/rendering/RenderThemeMac.h
@@ -142,6 +142,12 @@ protected:
virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&);
+ virtual void adjustColorWellStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
+ virtual bool paintColorWell(RenderObject*, const PaintInfo&, const IntRect&);
+
+ virtual void adjustColorListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
+ virtual bool paintColorList(RenderObject*, const PaintInfo&, const IntRect&);
+
#if ENABLE(VIDEO)
virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
diff --git a/Source/WebCore/rendering/RenderThemeMac.mm b/Source/WebCore/rendering/RenderThemeMac.mm
index a6f999a..a0c1a07 100644
--- a/Source/WebCore/rendering/RenderThemeMac.mm
+++ b/Source/WebCore/rendering/RenderThemeMac.mm
@@ -1629,6 +1629,80 @@ bool RenderThemeMac::paintSearchFieldResultsButton(RenderObject* o, const PaintI
return false;
}
+void RenderThemeMac::adjustColorWellStyle(CSSStyleSelector*, RenderStyle* style, Element* e) const
+{
+ if (e->style()->getPropertyValue("width").isEmpty()) {
+ style->setWidth(Length(44, Fixed));
+ }
+ if (e->style()->getPropertyValue("height").isEmpty()) {
+ style->setHeight(Length(23, Fixed));
+ }
+
+ const int minWidth = 13;
+ style->setMinWidth(Length(minWidth, Fixed));
+ const int minHeight = 13;
+ style->setMinHeight(Length(minHeight, Fixed));
+}
+
+bool RenderThemeMac::paintColorWell(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
+{
+ theme()->paint(SquareButtonPart, controlStatesForRenderer(o), const_cast<GraphicsContext*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView());
+
+ HTMLInputElement* element = static_cast<HTMLInputElement*>(o->node());
+ IntRect swatchRect(r);
+ swatchRect.inflate(-5);
+ Color color = Color(element->value());
+
+ paintInfo.context->save();
+
+ paintInfo.context->fillRect(swatchRect, color, o->style()->colorSpace());
+ paintInfo.context->setStrokeColor(Color("#777777"), o->style()->colorSpace());
+ FloatRect swatchBorderRect(swatchRect);
+ swatchBorderRect.inflate(-0.5);
+ paintInfo.context->strokeRect(swatchBorderRect, 1.0);
+
+ paintInfo.context->restore();
+
+ return false;
+}
+
+void RenderThemeMac::adjustColorListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
+{
+ adjustMenuListStyle(selector, style, e);
+ if (e->style()->getPropertyValue("width").isEmpty()) {
+ style->setWidth(Length(88, Fixed));
+ }
+
+ const int minWidth = 33;
+ style->setMinWidth(Length(minWidth, Fixed));
+}
+
+bool RenderThemeMac::paintColorList(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
+{
+ paintMenuList(o, paintInfo, r);
+
+ const int* padding = popupButtonPadding(controlSizeForFont(o->style()));
+
+ HTMLInputElement* element = static_cast<HTMLInputElement*>(o->node());
+ IntRect swatchRect(r);
+ swatchRect.shiftXEdgeTo(swatchRect.x() + padding[leftMargin]);
+ swatchRect.setWidth(swatchRect.width() - padding[rightMargin]);
+ swatchRect.inflateY(-5);
+ Color color = Color(element->value());
+
+ paintInfo.context->save();
+
+ paintInfo.context->fillRect(swatchRect, color, o->style()->colorSpace());
+ paintInfo.context->setStrokeColor(Color("#000000"), o->style()->colorSpace());
+ FloatRect swatchBorderRect(swatchRect);
+ swatchBorderRect.inflate(-0.5);
+ paintInfo.context->strokeRect(swatchBorderRect, 1.0);
+
+ paintInfo.context->restore();
+
+ return false;
+}
+
#if ENABLE(VIDEO)
typedef enum {
MediaControllerThemeClassic = 1,
diff --git a/Source/WebKit/mac/WebCoreSupport/WebChromeClient.h b/Source/WebKit/mac/WebCoreSupport/WebChromeClient.h
index 004d49b..0d257a0 100644
--- a/Source/WebKit/mac/WebCoreSupport/WebChromeClient.h
+++ b/Source/WebKit/mac/WebCoreSupport/WebChromeClient.h
@@ -124,6 +124,8 @@ public:
virtual void dashboardRegionsChanged();
#endif
+ virtual void runColorPanel(const WebCore::Color&);
+
virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
virtual void chooseIconForFiles(const Vector<WTF::String>&, WebCore::FileChooser*);
diff --git a/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm b/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm
index 6bf116b..b81cafd 100644
--- a/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm
+++ b/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm
@@ -49,6 +49,7 @@
#import "WebViewInternal.h"
#import <Foundation/Foundation.h>
#import <WebCore/BlockExceptions.h>
+#import <WebCore/ColorChooser.h>
#import <WebCore/Console.h>
#import <WebCore/Cursor.h>
#import <WebCore/ContextMenu.h>
@@ -126,6 +127,10 @@ NSString *WebConsoleMessageDebugMessageLevel = @"DebugMessageLevel";
using namespace WebCore;
+@interface WebColorPanelResultListener : NSObject <WebColorPanelResultListener>
++ (WebColorPanelResultListener *)sharedListener;
+@end
+
@interface WebOpenPanelResultListener : NSObject <WebOpenPanelResultListener>
{
FileChooser* _chooser;
@@ -773,6 +778,25 @@ void WebChromeClient::paintCustomHighlight(Node* node, const AtomicString& type,
END_BLOCK_OBJC_EXCEPTIONS;
}
+void WebChromeClient::runColorPanel(const WebCore::Color& color)
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ NSColor *platformColor = [NSColor colorWithDeviceRed:color.red()/255.0 green:color.green()/255.0 blue:color.blue()/255.0 alpha:0.0];
+
+ id delegate = [m_webView UIDelegate];
+ if ([delegate respondsToSelector:@selector(webView:runColorPanelForColorWellWithResultListener:)]) {
+ CallUIDelegate(m_webView, @selector(webView:runColorPanelForColorWellWithResultListener:initialColor:), [WebColorPanelResultListener sharedListener], platformColor);
+ } else {
+ NSColorPanel* panel = [NSColorPanel sharedColorPanel];
+ [panel setColor:platformColor];
+ [panel setTarget:[WebColorPanelResultListener sharedListener]];
+ [panel setAction:@selector(colorChanged:)];
+ [panel makeKeyAndOrderFront:NULL];
+ }
+ END_BLOCK_OBJC_EXCEPTIONS;
+}
+
void WebChromeClient::runOpenPanel(Frame*, PassRefPtr<FileChooser> chooser)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -1019,6 +1043,26 @@ void WebChromeClient::fullScreenRendererChanged(RenderBox* renderer)
#endif
+@implementation WebColorPanelResultListener
+
+static WebColorPanelResultListener *sharedWebColorPanelResultListener = nil;
+
++ (WebColorPanelResultListener *)sharedListener
+{
+ if (!sharedWebColorPanelResultListener)
+ sharedWebColorPanelResultListener = [[WebColorPanelResultListener alloc] init];
+ return sharedWebColorPanelResultListener;
+}
+
+- (void)colorChanged:(NSColorPanel *)panel
+{
+ NSColor *platformColor = [panel color];
+ WebCore::Color color([platformColor redComponent] * 255, [platformColor greenComponent] * 255, [platformColor blueComponent] * 255);
+ WebCore::ColorChooser::chooser()->chooseColor(color);
+}
+
+@end
+
@implementation WebOpenPanelResultListener
- (id)initWithChooser:(PassRefPtr<FileChooser>)chooser
diff --git a/Source/WebKit/mac/WebView/WebUIDelegate.h b/Source/WebKit/mac/WebView/WebUIDelegate.h
index c3dd9ff..5bd917d 100644
--- a/Source/WebKit/mac/WebView/WebUIDelegate.h
+++ b/Source/WebKit/mac/WebView/WebUIDelegate.h
@@ -115,6 +115,22 @@ typedef enum {
} WebDragSourceAction;
/*!
+ @protocol WebColorPanelResultListener
+ @discussion This protocol is used to call back with the results of
+ the color panel requested by runColorPanelForFileButtonWithResultListener:
+ */
+@protocol WebColorPanelResultListener <NSObject>
+
+/*!
+ @method colorChanged:
+ @abstract Call this method to notify change in the color panel.
+ @param panel
+ */
+- (void)colorChanged:(NSColorPanel *)panel;
+
+@end
+
+/*!
@protocol WebOpenPanelResultListener
@discussion This protocol is used to call back with the results of
the file open panel requested by runOpenPanelForFileButtonWithResultListener:
@@ -401,6 +417,15 @@ typedef enum {
- (BOOL)webView:(WebView *)sender runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
/*!
+ @method webView:runColorPanelForColorWellWithResultListener:initialColor:
+ @abstract Display a color panel for a color well.
+ @param sender The WebView sending the delegate method.
+ @param resultListener The object to call back with the results.
+ @param color Initial color for the color panel.
+ */
+- (void)webView:(WebView *)sender runColorPanelForColorWellWithResultListener:(id<WebColorPanelResultListener>)resultListener initialColor:(NSColor *)color;
+
+/*!
@method webView:runOpenPanelForFileButtonWithResultListener:
@abstract Display a file open panel for a file input control.
@param sender The WebView sending the delegate method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment