Split Color serialization out of Color classes
https://bugs.webkit.org/show_bug.cgi?id=213820

Reviewed by Darin Adler.

Source/WebCore:

Move all color serialization related functions out of the Color family
of classes, and into a standalone ColorSerialization.h

Now all color serialization calls one of the following three functions, depending on need:

    - serializationForCSS(...)
    - serializationForHTML(...)
    - serializationForRenderTreeAsText(...)

These are overload for all three Color classes (Color, SimpleColor and ExtendedColor) to
allow easy use without necessarily needing to construct another type.

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
Add new files.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText const):
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::inverseTransformColorIfNeeded):
(WebCore::StyleChange::extractTextStyles):
* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::detectContentInRange):
* html/ColorInputType.cpp:
(WebCore::ColorInputType::didChooseColor):
* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::shadowColor const):
* html/canvas/CanvasStyle.h:
(WebCore::CanvasStyle::color const):
* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
(WebCore::TextTrackCueGeneric::toJSON const):
* inspector/InspectorCanvas.cpp:
(WebCore::InspectorCanvas::buildArrayForCanvasGradient):
* page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::CaptionUserPreferencesMediaAF::colorPropertyCSS const):
* page/DragController.cpp:
(WebCore::DragController::concludeEditDrag):
(WebCore::DragController::insertDroppedImagePlaceholdersAtCaret):
* platform/graphics/Color.cpp:
(WebCore::operator<<):
(WebCore::Color::serialized const): Deleted.
(WebCore::Color::cssText const): Deleted.
(WebCore::Color::nameForRenderTreeAsText const): Deleted.
* platform/graphics/Color.h:
* platform/graphics/ColorSerialization.cpp: Added.
(WebCore::decimalDigit):
(WebCore::fractionDigitsForFractionalAlphaValue):
(WebCore::serializationForCSS):
(WebCore::serializationForHTML):
(WebCore::serializationForRenderTreeAsText):
(WebCore::serialization):
* platform/graphics/ColorSerialization.h: Added.
* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::cssText const): Deleted.
* platform/graphics/ExtendedColor.h:
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::dumpProperties const):
* platform/graphics/InbandGenericCue.cpp:
(WebCore::InbandGenericCue::toJSONString const):
* platform/graphics/SimpleColor.cpp:
(WebCore::SimpleColor::serializationForHTML const): Deleted.
(WebCore::decimalDigit): Deleted.
(WebCore::fractionDigitsForFractionalAlphaValue): Deleted.
(WebCore::SimpleColor::serializationForCSS const): Deleted.
(WebCore::SimpleColor::serializationForRenderTreeAsText const): Deleted.
* platform/graphics/SimpleColor.h:
* platform/graphics/filters/FEDropShadow.cpp:
(WebCore::FEDropShadow::externalRepresentation const):
* platform/graphics/filters/FEFlood.cpp:
(WebCore::FEFlood::externalRepresentation const):
* rendering/RenderTreeAsText.cpp:
(WebCore::RenderTreeAsText::writeRenderObject):
* rendering/svg/SVGRenderTreeAsText.cpp:
(WebCore::writeRenderSVGTextBox):
* svg/properties/SVGPropertyTraits.h:
(WebCore::SVGPropertyTraits<Color>::toString):
* testing/Internals.cpp:
(WebCore::Internals::viewBaseBackgroundColor):
(WebCore::Internals::highlightPseudoElementColor):
(WebCore::Internals::systemColorForCSSValue):
(WebCore::Internals::focusRingColor):
Adopt new serialization functions.

Source/WebKit:

Adopt ColorSerialization.h serialization functions.

* UIProcess/API/Cocoa/WKWebView.mm:
(dictionaryRepresentationForEditorState):
* UIProcess/Cocoa/WebViewImpl.mm:
(-[WKTextTouchBarItemController _wkChangeColor:]):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _setTextColorForWebView:sender:]):
* UIProcess/ios/forms/WKFormColorPicker.mm:
(-[WKColorPicker setControlValueFromUIColor:]):
* WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
(WebKit::PDFPluginChoiceAnnotation::createAnnotationElement):
* WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
(WebKit::PDFPluginTextAnnotation::createAnnotationElement):

Source/WebKitLegacy/mac:

Adopt ColorSerialization.h serialization functions.

* WebView/WebView.mm:
(-[WebTextTouchBarItemController _webChangeColor:]):

Tools:

* TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp:
(TestWebKitAPI::TEST):
Update tests to use ColorSerialization.h


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@263788 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index a616e65..842269b 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,95 @@
+2020-06-30  Sam Weinig  <weinig@apple.com>
+
+        Split Color serialization out of Color classes
+        https://bugs.webkit.org/show_bug.cgi?id=213820
+
+        Reviewed by Darin Adler.
+
+        Move all color serialization related functions out of the Color family
+        of classes, and into a standalone ColorSerialization.h
+        
+        Now all color serialization calls one of the following three functions, depending on need:
+
+            - serializationForCSS(...)
+            - serializationForHTML(...)
+            - serializationForRenderTreeAsText(...)
+
+        These are overload for all three Color classes (Color, SimpleColor and ExtendedColor) to
+        allow easy use without necessarily needing to construct another type.
+
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        Add new files.
+    
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText const):
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::inverseTransformColorIfNeeded):
+        (WebCore::StyleChange::extractTextStyles):
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::DataDetection::detectContentInRange):
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::didChooseColor):
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::shadowColor const):
+        * html/canvas/CanvasStyle.h:
+        (WebCore::CanvasStyle::color const):
+        * html/track/TextTrackCueGeneric.cpp:
+        (WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
+        (WebCore::TextTrackCueGeneric::toJSON const):
+        * inspector/InspectorCanvas.cpp:
+        (WebCore::InspectorCanvas::buildArrayForCanvasGradient):
+        * page/CaptionUserPreferencesMediaAF.cpp:
+        (WebCore::CaptionUserPreferencesMediaAF::colorPropertyCSS const):
+        * page/DragController.cpp:
+        (WebCore::DragController::concludeEditDrag):
+        (WebCore::DragController::insertDroppedImagePlaceholdersAtCaret):
+        * platform/graphics/Color.cpp:
+        (WebCore::operator<<):
+        (WebCore::Color::serialized const): Deleted.
+        (WebCore::Color::cssText const): Deleted.
+        (WebCore::Color::nameForRenderTreeAsText const): Deleted.
+        * platform/graphics/Color.h:
+        * platform/graphics/ColorSerialization.cpp: Added.
+        (WebCore::decimalDigit):
+        (WebCore::fractionDigitsForFractionalAlphaValue):
+        (WebCore::serializationForCSS):
+        (WebCore::serializationForHTML):
+        (WebCore::serializationForRenderTreeAsText):
+        (WebCore::serialization):
+        * platform/graphics/ColorSerialization.h: Added.
+        * platform/graphics/ExtendedColor.cpp:
+        (WebCore::ExtendedColor::cssText const): Deleted.
+        * platform/graphics/ExtendedColor.h:
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::dumpProperties const):
+        * platform/graphics/InbandGenericCue.cpp:
+        (WebCore::InbandGenericCue::toJSONString const):
+        * platform/graphics/SimpleColor.cpp:
+        (WebCore::SimpleColor::serializationForHTML const): Deleted.
+        (WebCore::decimalDigit): Deleted.
+        (WebCore::fractionDigitsForFractionalAlphaValue): Deleted.
+        (WebCore::SimpleColor::serializationForCSS const): Deleted.
+        (WebCore::SimpleColor::serializationForRenderTreeAsText const): Deleted.
+        * platform/graphics/SimpleColor.h:
+        * platform/graphics/filters/FEDropShadow.cpp:
+        (WebCore::FEDropShadow::externalRepresentation const):
+        * platform/graphics/filters/FEFlood.cpp:
+        (WebCore::FEFlood::externalRepresentation const):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::RenderTreeAsText::writeRenderObject):
+        * rendering/svg/SVGRenderTreeAsText.cpp:
+        (WebCore::writeRenderSVGTextBox):
+        * svg/properties/SVGPropertyTraits.h:
+        (WebCore::SVGPropertyTraits<Color>::toString):
+        * testing/Internals.cpp:
+        (WebCore::Internals::viewBaseBackgroundColor):
+        (WebCore::Internals::highlightPseudoElementColor):
+        (WebCore::Internals::systemColorForCSSValue):
+        (WebCore::Internals::focusRingColor):
+        Adopt new serialization functions.
+
 2020-06-30  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [WinCairo] Unreviewed build fix after r263776
diff --git a/Source/WebCore/Headers.cmake b/Source/WebCore/Headers.cmake
index 0826870..9e826c4 100644
--- a/Source/WebCore/Headers.cmake
+++ b/Source/WebCore/Headers.cmake
@@ -1085,6 +1085,7 @@
     platform/graphics/ColorComponents.h
     platform/graphics/ColorHash.h
     platform/graphics/ColorMatrix.h
+    platform/graphics/ColorSerialization.h
     platform/graphics/ColorSpace.h
     platform/graphics/ColorTypes.h
     platform/graphics/ColorUtilities.h
diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt
index ca7ce41..4c69cef 100644
--- a/Source/WebCore/Sources.txt
+++ b/Source/WebCore/Sources.txt
@@ -1908,6 +1908,7 @@
 platform/graphics/BitmapImage.cpp
 platform/graphics/Color.cpp
 platform/graphics/ColorBlending.cpp
+platform/graphics/ColorSerialization.cpp
 platform/graphics/ColorUtilities.cpp
 platform/graphics/ComplexTextController.cpp
 platform/graphics/CrossfadeGeneratedImage.cpp
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index 75a5120..3df841e 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -2344,6 +2344,7 @@
 		7CCEBFC01DD8F6AB002C40B8 /* SVGLengthValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE58D531DD7B09300128552 /* SVGLengthValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7CD0E2B81F80A4820016A4CE /* AbortController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD0E2B51F80A4820016A4CE /* AbortController.h */; };
 		7CD0E2BF1F80A56E0016A4CE /* AbortSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD0E2BC1F80A56E0016A4CE /* AbortSignal.h */; };
+		7CD1E69324ABF6240089C419 /* ColorSerialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD1E69124ABF6240089C419 /* ColorSerialization.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7CD494CD1A86EB1D000A87EC /* RenderAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD494CB1A86EB1D000A87EC /* RenderAttachment.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7CD58DFB1F9565A500112791 /* Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CEB57E91F95651500097AEC /* Settings.h */; };
 		7CD58DFD1F9565A800112791 /* Settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CEB57EA1F95651500097AEC /* Settings.cpp */; };
@@ -10193,6 +10194,8 @@
 		7CD0E2BC1F80A56E0016A4CE /* AbortSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AbortSignal.h; sourceTree = "<group>"; };
 		7CD0E2BD1F80A56E0016A4CE /* AbortSignal.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AbortSignal.cpp; sourceTree = "<group>"; };
 		7CD0E2BE1F80A56E0016A4CE /* AbortSignal.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AbortSignal.idl; sourceTree = "<group>"; };
+		7CD1E69124ABF6240089C419 /* ColorSerialization.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorSerialization.h; sourceTree = "<group>"; };
+		7CD1E69224ABF6240089C419 /* ColorSerialization.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ColorSerialization.cpp; sourceTree = "<group>"; };
 		7CD3440D1F310836000DCD49 /* MutationCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MutationCallback.idl; sourceTree = "<group>"; };
 		7CD344111F3108DD000DCD49 /* JSMutationCallback.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSMutationCallback.h; sourceTree = "<group>"; };
 		7CD344121F3108E2000DCD49 /* JSMutationCallback.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSMutationCallback.cpp; sourceTree = "<group>"; };
@@ -25500,6 +25503,8 @@
 				7CAC6AEC247F1C5100E61D59 /* ColorComponents.h */,
 				3103B7DE1DB01556008BB890 /* ColorHash.h */,
 				7CAC6AE8247F082000E61D59 /* ColorMatrix.h */,
+				7CD1E69224ABF6240089C419 /* ColorSerialization.cpp */,
+				7CD1E69124ABF6240089C419 /* ColorSerialization.h */,
 				9382DF5710A8D5C900925652 /* ColorSpace.h */,
 				7C029C6D2493C8F800268204 /* ColorTypes.h */,
 				0FE6C76B1FBFB7A60025C053 /* ColorUtilities.cpp */,
@@ -30079,6 +30084,7 @@
 				CE5169E721F1B84700EA4F78 /* ColorIOS.h in Headers */,
 				EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,
 				7CAC6AE9247F082F00E61D59 /* ColorMatrix.h in Headers */,
+				7CD1E69324ABF6240089C419 /* ColorSerialization.h in Headers */,
 				9382DF5810A8D5C900925652 /* ColorSpace.h in Headers */,
 				7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */,
 				0FEAF66B23BFC39E004030DA /* ColorUtilities.h in Headers */,
diff --git a/Source/WebCore/css/CSSPrimitiveValue.cpp b/Source/WebCore/css/CSSPrimitiveValue.cpp
index e76305c..3c7f14a 100644
--- a/Source/WebCore/css/CSSPrimitiveValue.cpp
+++ b/Source/WebCore/css/CSSPrimitiveValue.cpp
@@ -32,6 +32,7 @@
 #include "CSSValueKeywords.h"
 #include "CalculationValue.h"
 #include "Color.h"
+#include "ColorSerialization.h"
 #include "Counter.h"
 #include "DeprecatedCSSOMPrimitiveValue.h"
 #include "FontCascade.h"
@@ -1086,7 +1087,7 @@
     case CSSUnitType::CSS_QUAD:
         return quadValue()->cssText();
     case CSSUnitType::CSS_RGBCOLOR:
-        return color().cssText();
+        return serializationForCSS(color());
     case CSSUnitType::CSS_PAIR:
         return pairValue()->cssText();
     case CSSUnitType::CSS_CALC:
diff --git a/Source/WebCore/editing/EditingStyle.cpp b/Source/WebCore/editing/EditingStyle.cpp
index 030015b..f22cfae 100644
--- a/Source/WebCore/editing/EditingStyle.cpp
+++ b/Source/WebCore/editing/EditingStyle.cpp
@@ -36,6 +36,7 @@
 #include "CSSStyleRule.h"
 #include "CSSValueList.h"
 #include "CSSValuePool.h"
+#include "ColorSerialization.h"
 #include "Editing.h"
 #include "Editor.h"
 #include "FontCache.h"
@@ -1631,7 +1632,7 @@
     auto invertedColor = [&](CSSPropertyID propertyID) {
         Color newColor = cssValueToColor(extractPropertyValue(*m_mutableStyle, propertyID).get());
         colorFilter.inverseTransformColor(newColor);
-        styleWithInvertedColors->m_mutableStyle->setProperty(propertyID, newColor.cssText());
+        styleWithInvertedColors->m_mutableStyle->setProperty(propertyID, serializationForCSS(newColor));
     };
 
     if (color)
@@ -1807,7 +1808,7 @@
     if (style.getPropertyCSSValue(CSSPropertyColor)) {
         auto color = textColorFromStyle(style);
         if (color.isOpaque()) {
-            m_applyFontColor = color.serialized();
+            m_applyFontColor = serializationForHTML(color);
             style.removeProperty(CSSPropertyColor);
         }
     }
diff --git a/Source/WebCore/editing/cocoa/DataDetection.mm b/Source/WebCore/editing/cocoa/DataDetection.mm
index aafdee0..87a3d18 100644
--- a/Source/WebCore/editing/cocoa/DataDetection.mm
+++ b/Source/WebCore/editing/cocoa/DataDetection.mm
@@ -30,6 +30,7 @@
 
 #import "Attr.h"
 #import "CSSStyleDeclaration.h"
+#import "ColorSerialization.h"
 #import "Editing.h"
 #import "ElementAncestorIterator.h"
 #import "ElementTraversal.h"
@@ -628,7 +629,7 @@
                         auto underlineColor = makeSimpleColor(toSRGBA(hsla));
 
                         anchorElement->setInlineStyleProperty(CSSPropertyColor, CSSValueCurrentcolor);
-                        anchorElement->setInlineStyleProperty(CSSPropertyTextDecorationColor, underlineColor.serializationForCSS());
+                        anchorElement->setInlineStyleProperty(CSSPropertyTextDecorationColor, serializationForCSS(underlineColor));
                     }
                 }
             }
diff --git a/Source/WebCore/html/ColorInputType.cpp b/Source/WebCore/html/ColorInputType.cpp
index e2430e7..14e3f4f 100644
--- a/Source/WebCore/html/ColorInputType.cpp
+++ b/Source/WebCore/html/ColorInputType.cpp
@@ -38,6 +38,7 @@
 #include "CSSPropertyNames.h"
 #include "Chrome.h"
 #include "Color.h"
+#include "ColorSerialization.h"
 #include "Event.h"
 #include "HTMLDataListElement.h"
 #include "HTMLDivElement.h"
@@ -219,7 +220,7 @@
     if (element()->isDisabledFormControl() || color == valueAsColor())
         return;
     EventQueueScope scope;
-    element()->setValueFromRenderer(color.serialized());
+    element()->setValueFromRenderer(serializationForHTML(color));
     updateColorSwatch();
     element()->dispatchFormControlChangeEvent();
 }
diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp b/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
index 7577d94..1a1bbc4 100644
--- a/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
+++ b/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
@@ -40,6 +40,7 @@
 #include "CachedImage.h"
 #include "CanvasGradient.h"
 #include "CanvasPattern.h"
+#include "ColorSerialization.h"
 #include "DOMMatrix.h"
 #include "DOMMatrix2DInit.h"
 #include "DisplayListDrawingContext.h"
@@ -626,7 +627,7 @@
 
 String CanvasRenderingContext2DBase::shadowColor() const
 {
-    return state().shadowColor.serialized();
+    return serializationForHTML(state().shadowColor);
 }
 
 void CanvasRenderingContext2DBase::setShadowColor(const String& colorString)
diff --git a/Source/WebCore/html/canvas/CanvasStyle.h b/Source/WebCore/html/canvas/CanvasStyle.h
index 685fc72..d852280 100644
--- a/Source/WebCore/html/canvas/CanvasStyle.h
+++ b/Source/WebCore/html/canvas/CanvasStyle.h
@@ -29,6 +29,7 @@
 #include "CanvasGradient.h"
 #include "CanvasPattern.h"
 #include "Color.h"
+#include "ColorSerialization.h"
 #include <wtf/Variant.h>
 
 namespace WebCore {
@@ -108,8 +109,7 @@
 
 inline String CanvasStyle::color() const
 {
-    auto& color = WTF::holds_alternative<Color>(m_style) ? WTF::get<Color>(m_style) : WTF::get<CMYKAColor>(m_style).colorConvertedToSRGBA;
-    return color.serialized();
+    return serializationForHTML(WTF::holds_alternative<Color>(m_style) ? WTF::get<Color>(m_style) : WTF::get<CMYKAColor>(m_style).colorConvertedToSRGBA);
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/html/track/TextTrackCueGeneric.cpp b/Source/WebCore/html/track/TextTrackCueGeneric.cpp
index 109a49b..36aa223 100644
--- a/Source/WebCore/html/track/TextTrackCueGeneric.cpp
+++ b/Source/WebCore/html/track/TextTrackCueGeneric.cpp
@@ -32,6 +32,7 @@
 #include "CSSPropertyNames.h"
 #include "CSSStyleDeclaration.h"
 #include "CSSValueKeywords.h"
+#include "ColorSerialization.h"
 #include "HTMLSpanElement.h"
 #include "InbandTextTrackPrivateClient.h"
 #include "Logging.h"
@@ -125,9 +126,9 @@
     }
 
     if (cue->foregroundColor().isValid())
-        cueElement->setInlineStyleProperty(CSSPropertyColor, cue->foregroundColor().serialized());
+        cueElement->setInlineStyleProperty(CSSPropertyColor, serializationForHTML(cue->foregroundColor()));
     if (cue->highlightColor().isValid())
-        cueElement->setInlineStyleProperty(CSSPropertyBackgroundColor, cue->highlightColor().serialized());
+        cueElement->setInlineStyleProperty(CSSPropertyBackgroundColor, serializationForHTML(cue->highlightColor()));
 
     if (cue->getWritingDirection() == VTTCue::Horizontal)
         setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
@@ -145,7 +146,7 @@
         setInlineStyleProperty(CSSPropertyTextAlign, CSSValueStart);
 
     if (cue->backgroundColor().isValid())
-        setInlineStyleProperty(CSSPropertyBackgroundColor, cue->backgroundColor().serialized());
+        setInlineStyleProperty(CSSPropertyBackgroundColor, serializationForHTML(cue->backgroundColor()));
     setInlineStyleProperty(CSSPropertyWritingMode, cue->getCSSWritingMode(), false);
     setInlineStyleProperty(CSSPropertyWhiteSpace, CSSValuePreWrap);
 
@@ -245,11 +246,11 @@
 void TextTrackCueGeneric::toJSON(JSON::Object& object) const
 {
     if (m_foregroundColor.isValid())
-        object.setString("foregroundColor"_s, m_foregroundColor.serialized());
+        object.setString("foregroundColor"_s, serializationForHTML(m_foregroundColor));
     if (m_backgroundColor.isValid())
-        object.setString("backgroundColor"_s, m_backgroundColor.serialized());
+        object.setString("backgroundColor"_s, serializationForHTML(m_backgroundColor));
     if (m_highlightColor.isValid())
-        object.setString("highlightColor"_s, m_highlightColor.serialized());
+        object.setString("highlightColor"_s, serializationForHTML(m_highlightColor));
     if (m_baseFontSizeRelativeToVideoHeight)
         object.setDouble("relativeFontSize"_s, m_baseFontSizeRelativeToVideoHeight);
     if (m_fontSizeMultiplier)
diff --git a/Source/WebCore/inspector/InspectorCanvas.cpp b/Source/WebCore/inspector/InspectorCanvas.cpp
index d47a223..c103dea 100644
--- a/Source/WebCore/inspector/InspectorCanvas.cpp
+++ b/Source/WebCore/inspector/InspectorCanvas.cpp
@@ -32,6 +32,7 @@
 #include "CanvasPattern.h"
 #include "CanvasRenderingContext.h"
 #include "CanvasRenderingContext2D.h"
+#include "ColorSerialization.h"
 #include "Document.h"
 #include "Element.h"
 #include "FloatPoint.h"
@@ -1188,7 +1189,7 @@
     for (auto& colorStop : gradient.stops()) {
         auto stop = JSON::ArrayOf<JSON::Value>::create();
         stop->addItem(colorStop.offset);
-        stop->addItem(indexForData(colorStop.color.cssText()));
+        stop->addItem(indexForData(serializationForCSS(colorStop.color)));
         stops->addItem(WTFMove(stop));
     }
 
diff --git a/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp b/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
index 7fa636e..3a7b0c0 100644
--- a/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
+++ b/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
@@ -32,6 +32,7 @@
 #include "CaptionUserPreferencesMediaAF.h"
 
 #include "AudioTrackList.h"
+#include "ColorSerialization.h"
 #include "FloatConversion.h"
 #include "HTMLMediaElement.h"
 #include "LocalizedStrings.h"
@@ -356,7 +357,8 @@
 String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const
 {
     StringBuilder builder;
-    appendCSS(builder, id, color.serialized(), important);
+    // FIXME: Seems like this should be using serializationForCSS instead?
+    appendCSS(builder, id, serializationForHTML(color), important);
     return builder.toString();
 }
 
diff --git a/Source/WebCore/page/DragController.cpp b/Source/WebCore/page/DragController.cpp
index 2385701..7317bfd 100644
--- a/Source/WebCore/page/DragController.cpp
+++ b/Source/WebCore/page/DragController.cpp
@@ -32,6 +32,7 @@
 #if ENABLE(DRAG_SUPPORT)
 #include "CachedImage.h"
 #include "CachedResourceLoader.h"
+#include "ColorSerialization.h"
 #include "DataTransfer.h"
 #include "Document.h"
 #include "DocumentFragment.h"
@@ -558,7 +559,7 @@
 #if ENABLE(INPUT_TYPE_COLOR)
         if (isEnabledColorInput(*element)) {
             auto& input = downcast<HTMLInputElement>(*element);
-            input.setValue(color.serialized(), DispatchInputAndChangeEvent);
+            input.setValue(serializationForHTML(color), DispatchInputAndChangeEvent);
             return true;
         }
 #endif
@@ -566,7 +567,7 @@
         if (!innerRange)
             return false;
         auto style = MutableStyleProperties::create();
-        style->setProperty(CSSPropertyColor, color.serialized(), false);
+        style->setProperty(CSSPropertyColor, serializationForHTML(color), false);
         if (!innerFrame->editor().shouldApplyStyle(style.ptr(), createLiveRange(innerRange).get()))
             return false;
         client().willPerformDragDestinationAction(DragDestinationAction::Edit, dragData);
@@ -1444,7 +1445,7 @@
         image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomString::number(size.width()));
         image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomString::number(size.height()));
         image->setInlineStyleProperty(CSSPropertyMaxWidth, 100, CSSUnitType::CSS_PERCENTAGE);
-        image->setInlineStyleProperty(CSSPropertyBackgroundColor, Color(Color::black).colorWithAlpha(0.05).cssText());
+        image->setInlineStyleProperty(CSSPropertyBackgroundColor, serializationForCSS(Color::black.colorWithAlpha(13)));
         image->setIsDroppedImagePlaceholder();
         fragment->appendChild(WTFMove(image));
     }
diff --git a/Source/WebCore/platform/graphics/Color.cpp b/Source/WebCore/platform/graphics/Color.cpp
index ceec0f6..b64e829 100644
--- a/Source/WebCore/platform/graphics/Color.cpp
+++ b/Source/WebCore/platform/graphics/Color.cpp
@@ -27,6 +27,7 @@
 #include "Color.h"
 
 #include "AnimationUtilities.h"
+#include "ColorSerialization.h"
 #include "ColorUtilities.h"
 #include <wtf/Assertions.h>
 #include <wtf/MathExtras.h>
@@ -79,27 +80,6 @@
     return *this;
 }
 
-String Color::serialized() const
-{
-    if (isExtended())
-        return asExtended().cssText();
-    return asSimple().serializationForHTML();
-}
-
-String Color::cssText() const
-{
-    if (isExtended())
-        return asExtended().cssText();
-    return asSimple().serializationForCSS();
-}
-
-String Color::nameForRenderTreeAsText() const
-{
-    if (isExtended())
-        return asExtended().cssText();
-    return asSimple().serializationForRenderTreeAsText();
-}
-
 Color Color::lightened() const
 {
     // Hardcode this common case for speed.
@@ -195,7 +175,7 @@
 
 TextStream& operator<<(TextStream& ts, const Color& color)
 {
-    return ts << color.nameForRenderTreeAsText();
+    return ts << serializationForRenderTreeAsText(color);
 }
 
 TextStream& operator<<(TextStream& ts, ColorSpace colorSpace)
diff --git a/Source/WebCore/platform/graphics/Color.h b/Source/WebCore/platform/graphics/Color.h
index 61c998f..ce7c423a 100644
--- a/Source/WebCore/platform/graphics/Color.h
+++ b/Source/WebCore/platform/graphics/Color.h
@@ -108,15 +108,6 @@
             m_colorData.extendedColor->deref();
     }
 
-    // Returns the color serialized according to HTML5
-    // <https://html.spec.whatwg.org/multipage/scripting.html#fill-and-stroke-styles> (10 September 2015)
-    WEBCORE_EXPORT String serialized() const;
-
-    WEBCORE_EXPORT String cssText() const;
-
-    // Returns the color serialized as either #RRGGBB or #RRGGBBAA
-    String nameForRenderTreeAsText() const;
-
     bool isValid() const { return isExtended() || (m_colorData.simpleColorAndFlags & validSimpleColorBit); }
 
     bool isOpaque() const { return isExtended() ? asExtended().alpha() == 1.0 : asSimple().isOpaque(); }
diff --git a/Source/WebCore/platform/graphics/ColorSerialization.cpp b/Source/WebCore/platform/graphics/ColorSerialization.cpp
new file mode 100644
index 0000000..c768ea2
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ColorSerialization.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2020 Apple 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.
+ */
+
+#include "config.h"
+#include "ColorSerialization.h"
+
+#include <wtf/Assertions.h>
+#include <wtf/HexNumber.h>
+#include <wtf/MathExtras.h>
+#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringConcatenateNumbers.h>
+
+namespace WebCore {
+
+// SimpleColor overloads
+
+static char decimalDigit(unsigned number)
+{
+    ASSERT(number < 10);
+    return '0' + number;
+}
+
+static std::array<char, 4> fractionDigitsForFractionalAlphaValue(uint8_t alpha)
+{
+    ASSERT(alpha > 0);
+    ASSERT(alpha < 0xFF);
+    if (((alpha * 100 + 0x7F) / 0xFF * 0xFF + 50) / 100 != alpha)
+        return { { decimalDigit(alpha * 10 / 0xFF % 10), decimalDigit(alpha * 100 / 0xFF % 10), decimalDigit((alpha * 1000 + 0x7F) / 0xFF % 10), '\0' } };
+    if (int thirdDigit = (alpha * 100 + 0x7F) / 0xFF % 10)
+        return { { decimalDigit(alpha * 10 / 0xFF), decimalDigit(thirdDigit), '\0', '\0' } };
+    return { { decimalDigit((alpha * 10 + 0x7F) / 0xFF), '\0', '\0', '\0' } };
+}
+
+String serializationForCSS(SimpleColor color)
+{
+    auto [red, green, blue, alpha] = color;
+    switch (alpha) {
+    case 0:
+        return makeString("rgba(", red, ", ", green, ", ", blue, ", 0)");
+    case 0xFF:
+        return makeString("rgb(", red, ", ", green, ", ", blue, ')');
+    default:
+        return makeString("rgba(", red, ", ", green, ", ", blue, ", 0.", fractionDigitsForFractionalAlphaValue(alpha).data(), ')');
+    }
+}
+
+String serializationForHTML(SimpleColor color)
+{
+    auto [red, green, blue, alpha] = color;
+    if (color.isOpaque())
+        return makeString('#', hex(red, 2, Lowercase), hex(green, 2, Lowercase), hex(blue, 2, Lowercase));
+    return serializationForCSS(color);
+}
+
+String serializationForRenderTreeAsText(SimpleColor color)
+{
+    auto [red, green, blue, alpha] = color;
+    if (alpha < 0xFF)
+        return makeString('#', hex(red, 2), hex(green, 2), hex(blue, 2), hex(alpha, 2));
+    return makeString('#', hex(red, 2), hex(green, 2), hex(blue, 2));
+}
+
+
+// ExtendedColor overloads
+
+static ASCIILiteral serialization(ColorSpace colorSpace)
+{
+    switch (colorSpace) {
+    case ColorSpace::SRGB:
+        return "srgb"_s;
+    case ColorSpace::LinearRGB:
+        return "linear-srgb"_s;
+    case ColorSpace::DisplayP3:
+        return "display-p3"_s;
+    }
+
+    ASSERT_NOT_REACHED();
+    return ""_s;
+}
+
+String serializationForCSS(const ExtendedColor& color)
+{
+    auto [c1, c2, c3, alpha] = color.components();
+    if (WTF::areEssentiallyEqual(alpha, 1.0f))
+        return makeString("color(", serialization(color.colorSpace()), ' ', c1, ' ', c2, ' ', c3, ')');
+    return makeString("color(", serialization(color.colorSpace()), ' ', c1, ' ', c2, ' ', c3, " / ", alpha, ')');
+}
+
+String serializationForHTML(const ExtendedColor& color)
+{
+    return serializationForCSS(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedColor& color)
+{
+    return serializationForCSS(color);
+}
+
+// Color overloads
+
+String serializationForCSS(const Color& color)
+{
+    if (color.isExtended())
+        return serializationForCSS(color.asExtended());
+    return serializationForCSS(color.asSimple());
+}
+
+String serializationForHTML(const Color& color)
+{
+    if (color.isExtended())
+        return serializationForHTML(color.asExtended());
+    return serializationForHTML(color.asSimple());
+}
+
+String serializationForRenderTreeAsText(const Color& color)
+{
+    if (color.isExtended())
+        return serializationForRenderTreeAsText(color.asExtended());
+    return serializationForRenderTreeAsText(color.asSimple());
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/ColorSerialization.h b/Source/WebCore/platform/graphics/ColorSerialization.h
new file mode 100644
index 0000000..9633ecc
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ColorSerialization.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 Apple 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.
+ */
+
+#pragma once
+
+namespace WebCore {
+
+class Color;
+class ExtendedColor;
+class SimpleColor;
+
+// serializationForHTML returns the color serialized according to HTML5 <https://html.spec.whatwg.org/multipage/scripting.html#fill-and-stroke-styles> (10 September 2015)
+// serializationForCSS returns the color serialized according to CSS
+// serializationForRenderTreeAsText returns the color serialized for DumpRenderTree, #RRGGBB, #RRGGBBAA or the CSS serialization
+
+WEBCORE_EXPORT String serializationForCSS(SimpleColor);
+WEBCORE_EXPORT String serializationForHTML(SimpleColor);
+WEBCORE_EXPORT String serializationForRenderTreeAsText(SimpleColor);
+
+WEBCORE_EXPORT String serializationForCSS(const ExtendedColor&);
+WEBCORE_EXPORT String serializationForHTML(const ExtendedColor&);
+WEBCORE_EXPORT String serializationForRenderTreeAsText(const ExtendedColor&);
+
+WEBCORE_EXPORT String serializationForCSS(const Color&);
+WEBCORE_EXPORT String serializationForHTML(const Color&);
+WEBCORE_EXPORT String serializationForRenderTreeAsText(const Color&);
+
+}
diff --git a/Source/WebCore/platform/graphics/ExtendedColor.cpp b/Source/WebCore/platform/graphics/ExtendedColor.cpp
index fd2e3a8..80325e5 100644
--- a/Source/WebCore/platform/graphics/ExtendedColor.cpp
+++ b/Source/WebCore/platform/graphics/ExtendedColor.cpp
@@ -31,7 +31,6 @@
 #include "ColorUtilities.h"
 #include <wtf/Hasher.h>
 #include <wtf/MathExtras.h>
-#include <wtf/text/StringConcatenateNumbers.h>
 
 namespace WebCore {
 
@@ -46,29 +45,6 @@
     return computeHash(c1, c2, c3, alpha, m_colorSpace);
 }
 
-String ExtendedColor::cssText() const
-{
-    const char* colorSpace;
-    switch (m_colorSpace) {
-    case ColorSpace::SRGB:
-        colorSpace = "srgb";
-        break;
-    case ColorSpace::DisplayP3:
-        colorSpace = "display-p3";
-        break;
-    default:
-        ASSERT_NOT_REACHED();
-        return WTF::emptyString();
-    }
-
-    auto [c1, c2, c3, existingAlpha] = components();
-
-    if (WTF::areEssentiallyEqual(alpha(), 1.0f))
-        return makeString("color(", colorSpace, ' ', c1, ' ', c2, ' ', c3, ')');
-
-    return makeString("color(", colorSpace, ' ', c1, ' ', c2, ' ', c3, " / ", existingAlpha, ')');
-}
-
 Ref<ExtendedColor> ExtendedColor::colorWithAlpha(float overrideAlpha) const
 {
     auto [c1, c2, c3, existingAlpha] = components();
diff --git a/Source/WebCore/platform/graphics/ExtendedColor.h b/Source/WebCore/platform/graphics/ExtendedColor.h
index 503e33f..39e84e6 100644
--- a/Source/WebCore/platform/graphics/ExtendedColor.h
+++ b/Source/WebCore/platform/graphics/ExtendedColor.h
@@ -29,7 +29,6 @@
 #include "ColorSpace.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -47,8 +46,6 @@
 
     WEBCORE_EXPORT unsigned hash() const;
 
-    WEBCORE_EXPORT String cssText() const;
-
     Ref<ExtendedColor> colorWithAlpha(float) const;
     Ref<ExtendedColor> invertedColorWithAlpha(float) const;
 
diff --git a/Source/WebCore/platform/graphics/GraphicsLayer.cpp b/Source/WebCore/platform/graphics/GraphicsLayer.cpp
index f6893ab..fe4e4a0 100644
--- a/Source/WebCore/platform/graphics/GraphicsLayer.cpp
+++ b/Source/WebCore/platform/graphics/GraphicsLayer.cpp
@@ -24,9 +24,9 @@
  */
 
 #include "config.h"
-
 #include "GraphicsLayer.h"
 
+#include "ColorSerialization.h"
 #include "FloatPoint.h"
 #include "FloatRect.h"
 #include "GraphicsContext.h"
@@ -931,7 +931,7 @@
         ts << indent << "(primary-layer-id " << primaryLayerID() << ")\n";
 
     if (m_backgroundColor.isValid() && client().shouldDumpPropertyForLayer(this, "backgroundColor", behavior))
-        ts << indent << "(backgroundColor " << m_backgroundColor.nameForRenderTreeAsText() << ")\n";
+        ts << indent << "(backgroundColor " << serializationForRenderTreeAsText(m_backgroundColor) << ")\n";
 
     if (behavior & LayerTreeAsTextIncludeAcceleratesDrawing && m_acceleratesDrawing)
         ts << indent << "(acceleratesDrawing " << m_acceleratesDrawing << ")\n";
diff --git a/Source/WebCore/platform/graphics/InbandGenericCue.cpp b/Source/WebCore/platform/graphics/InbandGenericCue.cpp
index e438add..3ec8005 100644
--- a/Source/WebCore/platform/graphics/InbandGenericCue.cpp
+++ b/Source/WebCore/platform/graphics/InbandGenericCue.cpp
@@ -28,6 +28,8 @@
 
 #if ENABLE(VIDEO)
 
+#include "ColorSerialization.h"
+
 
 namespace WebCore {
 
@@ -94,13 +96,13 @@
     }
 
     if (m_cueData.m_foregroundColor.isValid())
-        object->setString("foregroundColor"_s, m_cueData.m_foregroundColor.serialized());
+        object->setString("foregroundColor"_s, serializationForHTML(m_cueData.m_foregroundColor));
 
     if (m_cueData.m_backgroundColor.isValid())
-        object->setString("backgroundColor"_s, m_cueData.m_backgroundColor.serialized());
+        object->setString("backgroundColor"_s, serializationForHTML(m_cueData.m_backgroundColor));
 
     if (m_cueData.m_highlightColor.isValid())
-        object->setString("highlightColor"_s, m_cueData.m_highlightColor.serialized());
+        object->setString("highlightColor"_s, serializationForHTML(m_cueData.m_highlightColor));
 
     if (m_cueData.m_baseFontSize)
         object->setDouble("baseFontSize"_s, m_cueData.m_baseFontSize);
diff --git a/Source/WebCore/platform/graphics/SimpleColor.cpp b/Source/WebCore/platform/graphics/SimpleColor.cpp
index 5c2b254..e09500b 100644
--- a/Source/WebCore/platform/graphics/SimpleColor.cpp
+++ b/Source/WebCore/platform/graphics/SimpleColor.cpp
@@ -26,11 +26,6 @@
 #include "config.h"
 #include "SimpleColor.h"
 
-#include <wtf/Assertions.h>
-#include <wtf/HexNumber.h>
-#include <wtf/MathExtras.h>
-#include <wtf/text/StringBuilder.h>
-
 namespace WebCore {
 
 SimpleColor premultiplyFlooring(SimpleColor color)
@@ -62,47 +57,5 @@
     return makeSimpleColor(unpremultiplyChannel(r, a), unpremultiplyChannel(g, a), unpremultiplyChannel(b, a), a);
 }
 
-String SimpleColor::serializationForHTML() const
-{
-    if (isOpaque())
-        return makeString('#', hex(redComponent(), 2, Lowercase), hex(greenComponent(), 2, Lowercase), hex(blueComponent(), 2, Lowercase));
-    return serializationForCSS();
-}
-
-static char decimalDigit(unsigned number)
-{
-    ASSERT(number < 10);
-    return '0' + number;
-}
-
-static std::array<char, 4> fractionDigitsForFractionalAlphaValue(uint8_t alpha)
-{
-    ASSERT(alpha > 0);
-    ASSERT(alpha < 0xFF);
-    if (((alpha * 100 + 0x7F) / 0xFF * 0xFF + 50) / 100 != alpha)
-        return { { decimalDigit(alpha * 10 / 0xFF % 10), decimalDigit(alpha * 100 / 0xFF % 10), decimalDigit((alpha * 1000 + 0x7F) / 0xFF % 10), '\0' } };
-    if (int thirdDigit = (alpha * 100 + 0x7F) / 0xFF % 10)
-        return { { decimalDigit(alpha * 10 / 0xFF), decimalDigit(thirdDigit), '\0', '\0' } };
-    return { { decimalDigit((alpha * 10 + 0x7F) / 0xFF), '\0', '\0', '\0' } };
-}
-
-String SimpleColor::serializationForCSS() const
-{
-    switch (alphaComponent()) {
-    case 0:
-        return makeString("rgba(", redComponent(), ", ", greenComponent(), ", ", blueComponent(), ", 0)");
-    case 0xFF:
-        return makeString("rgb(", redComponent(), ", ", greenComponent(), ", ", blueComponent(), ')');
-    default:
-        return makeString("rgba(", redComponent(), ", ", greenComponent(), ", ", blueComponent(), ", 0.", fractionDigitsForFractionalAlphaValue(alphaComponent()).data(), ')');
-    }
-}
-
-String SimpleColor::serializationForRenderTreeAsText() const
-{
-    if (alphaComponent() < 0xFF)
-        return makeString('#', hex(redComponent(), 2), hex(greenComponent(), 2), hex(blueComponent(), 2), hex(alphaComponent(), 2));
-    return makeString('#', hex(redComponent(), 2), hex(greenComponent(), 2), hex(blueComponent(), 2));
-}
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/SimpleColor.h b/Source/WebCore/platform/graphics/SimpleColor.h
index c1cf6dc..f27b89d 100644
--- a/Source/WebCore/platform/graphics/SimpleColor.h
+++ b/Source/WebCore/platform/graphics/SimpleColor.h
@@ -52,10 +52,6 @@
     constexpr bool isOpaque() const { return alphaComponent() == 0xFF; }
     constexpr bool isVisible() const { return alphaComponent(); }
 
-    String serializationForHTML() const;
-    String serializationForCSS() const;
-    String serializationForRenderTreeAsText() const;
-
     constexpr SimpleColor colorWithAlpha(uint8_t alpha) const
     {
         return { (m_value & 0x00FFFFFF) | alpha << 24 };
diff --git a/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp b/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp
index 1395a2d..cd514df 100644
--- a/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp
+++ b/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "FEDropShadow.h"
 
+#include "ColorSerialization.h"
 #include "FEGaussianBlur.h"
 #include "Filter.h"
 #include "GraphicsContext.h"
@@ -131,7 +132,7 @@
 {
     ts << indent <<"[feDropShadow";
     FilterEffect::externalRepresentation(ts, representation);
-    ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\" dx=\"" << m_dx << "\" dy=\"" << m_dy << "\" flood-color=\"" << m_shadowColor.nameForRenderTreeAsText() <<"\" flood-opacity=\"" << m_shadowOpacity << "]\n";
+    ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\" dx=\"" << m_dx << "\" dy=\"" << m_dy << "\" flood-color=\"" << serializationForRenderTreeAsText(m_shadowColor) <<"\" flood-opacity=\"" << m_shadowOpacity << "]\n";
 
     TextStream::IndentScope indentScope(ts);
     inputEffect(0)->externalRepresentation(ts, representation);
diff --git a/Source/WebCore/platform/graphics/filters/FEFlood.cpp b/Source/WebCore/platform/graphics/filters/FEFlood.cpp
index f33e8a3..bc54483 100644
--- a/Source/WebCore/platform/graphics/filters/FEFlood.cpp
+++ b/Source/WebCore/platform/graphics/filters/FEFlood.cpp
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "FEFlood.h"
 
+#include "ColorSerialization.h"
 #include "Filter.h"
 #include "GraphicsContext.h"
 #include <wtf/text/TextStream.h>
@@ -71,7 +72,7 @@
 {
     ts << indent << "[feFlood";
     FilterEffect::externalRepresentation(ts, representation);
-    ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
+    ts << " flood-color=\"" << serializationForRenderTreeAsText(floodColor()) << "\" "
        << "flood-opacity=\"" << floodOpacity() << "\"]\n";
     return ts;
 }
diff --git a/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp b/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp
index 8318323..c148c85 100644
--- a/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp
+++ b/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp
@@ -48,6 +48,11 @@
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 
+#if PLATFORM(MAC)
+#include "ScreenDisplayCapturerMac.h"
+#include "WindowDisplayCapturerMac.h"
+#endif
+
 #include "CoreVideoSoftLink.h"
 
 namespace WebCore {
diff --git a/Source/WebCore/rendering/RenderTreeAsText.cpp b/Source/WebCore/rendering/RenderTreeAsText.cpp
index 5787584..6e2d4b8 100644
--- a/Source/WebCore/rendering/RenderTreeAsText.cpp
+++ b/Source/WebCore/rendering/RenderTreeAsText.cpp
@@ -27,6 +27,7 @@
 #include "RenderTreeAsText.h"
 
 #include "ClipRect.h"
+#include "ColorSerialization.h"
 #include "Document.h"
 #include "Frame.h"
 #include "FrameSelection.h"
@@ -239,23 +240,23 @@
         if (o.parent()) {
             Color color = o.style().visitedDependentColor(CSSPropertyColor);
             if (!equalIgnoringSemanticColor(o.parent()->style().visitedDependentColor(CSSPropertyColor), color))
-                ts << " [color=" << color.nameForRenderTreeAsText() << "]";
+                ts << " [color=" << serializationForRenderTreeAsText(color) << "]";
 
             // Do not dump invalid or transparent backgrounds, since that is the default.
             Color backgroundColor = o.style().visitedDependentColor(CSSPropertyBackgroundColor);
             if (!equalIgnoringSemanticColor(o.parent()->style().visitedDependentColor(CSSPropertyBackgroundColor), backgroundColor)
                 && backgroundColor != Color::transparent)
-                ts << " [bgcolor=" << backgroundColor.nameForRenderTreeAsText() << "]";
+                ts << " [bgcolor=" << serializationForRenderTreeAsText(backgroundColor) << "]";
             
             Color textFillColor = o.style().visitedDependentColor(CSSPropertyWebkitTextFillColor);
             if (!equalIgnoringSemanticColor(o.parent()->style().visitedDependentColor(CSSPropertyWebkitTextFillColor), textFillColor)
                 && textFillColor != color && textFillColor != Color::transparent)
-                ts << " [textFillColor=" << textFillColor.nameForRenderTreeAsText() << "]";
+                ts << " [textFillColor=" << serializationForRenderTreeAsText(textFillColor) << "]";
 
             Color textStrokeColor = o.style().visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
             if (!equalIgnoringSemanticColor(o.parent()->style().visitedDependentColor(CSSPropertyWebkitTextStrokeColor), textStrokeColor)
                 && textStrokeColor != color && textStrokeColor != Color::transparent)
-                ts << " [textStrokeColor=" << textStrokeColor.nameForRenderTreeAsText() << "]";
+                ts << " [textStrokeColor=" << serializationForRenderTreeAsText(textStrokeColor) << "]";
 
             if (o.parent()->style().textStrokeWidth() != o.style().textStrokeWidth() && o.style().textStrokeWidth() > 0)
                 ts << " [textStrokeWidth=" << o.style().textStrokeWidth() << "]";
@@ -290,10 +291,10 @@
             else {
                 ts << " (" << borderTop << "px ";
                 printBorderStyle(ts, o.style().borderTopStyle());
-                Color col = o.style().borderTopColor();
-                if (!col.isValid())
-                    col = o.style().color();
-                ts << col.nameForRenderTreeAsText() << ")";
+                auto color = o.style().borderTopColor();
+                if (!color.isValid())
+                    color = o.style().color();
+                ts << serializationForRenderTreeAsText(color) << ")";
             }
 
             if (o.style().borderRight() != prevBorder) {
@@ -303,10 +304,10 @@
                 else {
                     ts << " (" << borderRight << "px ";
                     printBorderStyle(ts, o.style().borderRightStyle());
-                    Color col = o.style().borderRightColor();
-                    if (!col.isValid())
-                        col = o.style().color();
-                    ts << col.nameForRenderTreeAsText() << ")";
+                    auto color = o.style().borderRightColor();
+                    if (!color.isValid())
+                        color = o.style().color();
+                    ts << serializationForRenderTreeAsText(color) << ")";
                 }
             }
 
@@ -317,10 +318,10 @@
                 else {
                     ts << " (" << borderBottom << "px ";
                     printBorderStyle(ts, o.style().borderBottomStyle());
-                    Color col = o.style().borderBottomColor();
-                    if (!col.isValid())
-                        col = o.style().color();
-                    ts << col.nameForRenderTreeAsText() << ")";
+                    auto color = o.style().borderBottomColor();
+                    if (!color.isValid())
+                        color = o.style().color();
+                    ts << serializationForRenderTreeAsText(color) << ")";
                 }
             }
 
@@ -331,10 +332,10 @@
                 else {
                     ts << " (" << borderLeft << "px ";
                     printBorderStyle(ts, o.style().borderLeftStyle());
-                    Color col = o.style().borderLeftColor();
-                    if (!col.isValid())
-                        col = o.style().color();
-                    ts << col.nameForRenderTreeAsText() << ")";
+                    auto color = o.style().borderLeftColor();
+                    if (!color.isValid())
+                        color = o.style().color();
+                    ts << serializationForRenderTreeAsText(color) << ")";
                 }
             }
 
diff --git a/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp b/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp
index 3b4934b..f949ed5 100644
--- a/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp
+++ b/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp
@@ -29,6 +29,7 @@
 #include "config.h"
 #include "SVGRenderTreeAsText.h"
 
+#include "ColorSerialization.h"
 #include "GraphicsTypes.h"
 #include "NodeRenderStyle.h"
 #include "RenderImage.h"
@@ -300,7 +301,7 @@
     ts << " contains 1 chunk(s)";
 
     if (text.parent() && (text.parent()->style().visitedDependentColor(CSSPropertyColor) != text.style().visitedDependentColor(CSSPropertyColor)))
-        writeNameValuePair(ts, "color", text.style().visitedDependentColor(CSSPropertyColor).nameForRenderTreeAsText());
+        writeNameValuePair(ts, "color", serializationForRenderTreeAsText(text.style().visitedDependentColor(CSSPropertyColor)));
 }
 
 static inline void writeSVGInlineTextBox(TextStream& ts, SVGInlineTextBox* textBox)
diff --git a/Source/WebCore/svg/properties/SVGPropertyTraits.h b/Source/WebCore/svg/properties/SVGPropertyTraits.h
index b77ce58..7d04fbc 100644
--- a/Source/WebCore/svg/properties/SVGPropertyTraits.h
+++ b/Source/WebCore/svg/properties/SVGPropertyTraits.h
@@ -23,6 +23,7 @@
 
 #include "CSSParser.h"
 #include "Color.h"
+#include "ColorSerialization.h"
 #include "FloatPoint.h"
 #include "FloatRect.h"
 #include "QualifiedName.h"
@@ -52,7 +53,7 @@
             return WTF::nullopt;
         return color;
     }
-    static String toString(const Color& type) { return type.serialized(); }
+    static String toString(const Color& type) { return serializationForHTML(type); }
 };
 
 template<>
diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp
index 6bbd6cc..758a3be 100644
--- a/Source/WebCore/testing/Internals.cpp
+++ b/Source/WebCore/testing/Internals.cpp
@@ -51,6 +51,7 @@
 #include "Chrome.h"
 #include "ChromeClient.h"
 #include "ClientOrigin.h"
+#include "ColorSerialization.h"
 #include "ComposedTreeIterator.h"
 #include "CookieJar.h"
 #include "Cursor.h"
@@ -1955,7 +1956,7 @@
     Document* document = contextDocument();
     if (!document || !document->view())
         return Exception { InvalidAccessError };
-    return document->view()->baseBackgroundColor().cssText();
+    return serializationForCSS(document->view()->baseBackgroundColor());
 }
 
 ExceptionOr<void> Internals::setViewBaseBackgroundColor(const String& colorValue)
@@ -5660,7 +5661,7 @@
     if (!style)
         return { };
 
-    return style->color().cssText();
+    return serializationForCSS(style->color());
 }
     
 Internals::TextIndicatorInfo::TextIndicatorInfo()
@@ -5772,7 +5773,7 @@
     if (useElevatedUserInterfaceLevel)
         options.add(StyleColor::Options::UseElevatedUserInterfaceLevel);
     
-    return RenderTheme::singleton().systemColor(id, options).cssText();
+    return serializationForCSS(RenderTheme::singleton().systemColor(id, options));
 }
 
 bool Internals::systemHasBattery() const
@@ -5827,8 +5828,7 @@
 
 String Internals::focusRingColor()
 {
-    OptionSet<StyleColor::Options> options;
-    return RenderTheme::singleton().focusRingColor(options).cssText();
+    return serializationForCSS(RenderTheme::singleton().focusRingColor({ }));
 }
 
 unsigned Internals::createSleepDisabler(const String& reason, bool display)
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 8459589..86f02b5 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,25 @@
+2020-06-30  Sam Weinig  <weinig@apple.com>
+
+        Split Color serialization out of Color classes
+        https://bugs.webkit.org/show_bug.cgi?id=213820
+
+        Reviewed by Darin Adler.
+
+        Adopt ColorSerialization.h serialization functions.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (dictionaryRepresentationForEditorState):
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (-[WKTextTouchBarItemController _wkChangeColor:]):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _setTextColorForWebView:sender:]):
+        * UIProcess/ios/forms/WKFormColorPicker.mm:
+        (-[WKColorPicker setControlValueFromUIColor:]):
+        * WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
+        (WebKit::PDFPluginChoiceAnnotation::createAnnotationElement):
+        * WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
+        (WebKit::PDFPluginTextAnnotation::createAnnotationElement):
+
 2020-06-30  Geoffrey Garen  <ggaren@apple.com>
 
         [Cocoa] [GTK] RunLoop::Timer::isActive() is incorrect for timers while they are firing
diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
index 23b7c19..b585d3e 100644
--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
@@ -116,6 +116,7 @@
 #import "_WKVisitedLinkStoreInternal.h"
 #import "_WKWebsitePoliciesInternal.h"
 #import <WebCore/AttributedString.h>
+#import <WebCore/ColorSerialization.h>
 #import <WebCore/ElementContext.h>
 #import <WebCore/JSDOMBinding.h>
 #import <WebCore/JSDOMExceptionHandling.h>
@@ -1382,7 +1383,7 @@
         @"italic": postLayoutData.typingAttributes & WebKit::AttributeItalics ? @YES : @NO,
         @"underline": postLayoutData.typingAttributes & WebKit::AttributeUnderline ? @YES : @NO,
         @"text-alignment": @(nsTextAlignment(static_cast<WebKit::TextAlignment>(postLayoutData.textAlignment))),
-        @"text-color": (NSString *)postLayoutData.textColor.cssText()
+        @"text-color": (NSString *)serializationForCSS(postLayoutData.textColor)
     };
 }
 
diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
index 1145bd4..14840fdc 100644
--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
@@ -84,6 +84,7 @@
 #import <WebCore/ActivityState.h>
 #import <WebCore/AttributedString.h>
 #import <WebCore/ColorMac.h>
+#import <WebCore/ColorSerialization.h>
 #import <WebCore/CompositionHighlight.h>
 #import <WebCore/DictionaryLookup.h>
 #import <WebCore/DragData.h>
@@ -832,7 +833,7 @@
         return;
 
     _textColor = self.colorPickerItem.color;
-    _webViewImpl->page().executeEditCommand("ForeColor", WebCore::colorFromNSColor(_textColor.get()).serialized());
+    _webViewImpl->page().executeEditCommand("ForeColor", WebCore::serializationForHTML(WebCore::colorFromNSColor(_textColor.get())));
 }
 
 - (NSViewController *)textListViewController
diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
index 45a0758..667401c 100644
--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
@@ -97,6 +97,7 @@
 #import <MobileCoreServices/UTCoreTypes.h>
 #import <WebCore/Color.h>
 #import <WebCore/ColorIOS.h>
+#import <WebCore/ColorSerialization.h>
 #import <WebCore/CompositionHighlight.h>
 #import <WebCore/DOMPasteAccess.h>
 #import <WebCore/DataDetection.h>
@@ -3196,7 +3197,7 @@
 
 - (void)_setTextColorForWebView:(UIColor *)color sender:(id)sender
 {
-    _page->executeEditCommand("ForeColor"_s, WebCore::Color(color.CGColor).serialized());
+    _page->executeEditCommand("ForeColor"_s, WebCore::serializationForHTML(WebCore::Color(color.CGColor)));
 }
 
 - (void)toggleStrikeThroughForWebView:(id)sender
diff --git a/Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm b/Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm
index 6fb8663..d142430 100644
--- a/Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm
+++ b/Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm
@@ -35,6 +35,7 @@
 #import "WebPageProxy.h"
 
 #import <WebCore/Color.h>
+#import <WebCore/ColorSerialization.h>
 #import <wtf/SoftLinking.h>
 
 SOFT_LINK_PRIVATE_FRAMEWORK(PencilKit)
@@ -278,7 +279,7 @@
 - (void)setControlValueFromUIColor:(UIColor *)uiColor
 {
     WebCore::Color color(uiColor.CGColor);
-    [_view page]->setFocusedElementValue(color.serialized());
+    [_view page]->setFocusedElementValue(WebCore::serializationForHTML(color));
 }
 
 #pragma mark WKFormControl
diff --git a/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm b/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm
index e9b76c2..2896f04 100644
--- a/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm
+++ b/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm
@@ -34,6 +34,7 @@
 #import <WebCore/CSSPrimitiveValue.h>
 #import <WebCore/CSSPropertyNames.h>
 #import <WebCore/ColorMac.h>
+#import <WebCore/ColorSerialization.h>
 #import <WebCore/HTMLElement.h>
 #import <WebCore/HTMLNames.h>
 #import <WebCore/HTMLOptionElement.h>
@@ -76,7 +77,7 @@
     auto& styledElement = downcast<StyledElement>(element.get());
 
     // FIXME: Match font weight and style as well?
-    styledElement.setInlineStyleProperty(CSSPropertyColor, colorFromNSColor(choiceAnnotation.fontColor).serialized());
+    styledElement.setInlineStyleProperty(CSSPropertyColor, serializationForHTML(colorFromNSColor(choiceAnnotation.fontColor)));
     styledElement.setInlineStyleProperty(CSSPropertyFontFamily, choiceAnnotation.font.familyName);
 
     NSArray *choices = choiceAnnotation.choices;
diff --git a/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm b/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
index c8aaa91..d58701c 100644
--- a/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
+++ b/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
@@ -36,6 +36,7 @@
 #import <WebCore/CSSPrimitiveValue.h>
 #import <WebCore/CSSPropertyNames.h>
 #import <WebCore/ColorMac.h>
+#import <WebCore/ColorSerialization.h>
 #import <WebCore/Event.h>
 #import <WebCore/EventNames.h>
 #import <WebCore/HTMLElement.h>
@@ -94,7 +95,7 @@
         return element;
 
     // FIXME: Match font weight and style as well?
-    styledElement.setInlineStyleProperty(CSSPropertyColor, colorFromNSColor(textAnnotation.fontColor).serialized());
+    styledElement.setInlineStyleProperty(CSSPropertyColor, serializationForHTML(colorFromNSColor(textAnnotation.fontColor)));
     styledElement.setInlineStyleProperty(CSSPropertyFontFamily, textAnnotation.font.familyName);
     styledElement.setInlineStyleProperty(CSSPropertyTextAlign, cssAlignmentValueForNSTextAlignment(textAnnotation.alignment));
 
diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog
index bd7dfef..ebe325a 100644
--- a/Source/WebKitLegacy/mac/ChangeLog
+++ b/Source/WebKitLegacy/mac/ChangeLog
@@ -1,3 +1,15 @@
+2020-06-30  Sam Weinig  <weinig@apple.com>
+
+        Split Color serialization out of Color classes
+        https://bugs.webkit.org/show_bug.cgi?id=213820
+
+        Reviewed by Darin Adler.
+
+        Adopt ColorSerialization.h serialization functions.
+
+        * WebView/WebView.mm:
+        (-[WebTextTouchBarItemController _webChangeColor:]):
+
 2020-06-30  Kate Cheney  <katherine_cheney@apple.com>
 
         Remove NeedsInAppBrowserPrivacyQuirks flag from WebKitLegacy
diff --git a/Source/WebKitLegacy/mac/WebView/WebView.mm b/Source/WebKitLegacy/mac/WebView/WebView.mm
index 5e4854d..82a0c10 100644
--- a/Source/WebKitLegacy/mac/WebView/WebView.mm
+++ b/Source/WebKitLegacy/mac/WebView/WebView.mm
@@ -136,6 +136,7 @@
 #import <WebCore/CacheStorageProvider.h>
 #import <WebCore/Chrome.h>
 #import <WebCore/ColorMac.h>
+#import <WebCore/ColorSerialization.h>
 #import <WebCore/CookieJar.h>
 #import <WebCore/DatabaseManager.h>
 #import <WebCore/DeprecatedGlobalSettings.h>
@@ -1208,7 +1209,7 @@
 - (void)_webChangeColor:(id)sender
 {
     _textColor = self.colorPickerItem.color;
-    [_webView _executeCoreCommandByName:@"ForeColor" value: WebCore::colorFromNSColor(_textColor.get()).serialized()];
+    [_webView _executeCoreCommandByName:@"ForeColor" value: WebCore::serializationForHTML(WebCore::colorFromNSColor(_textColor.get()))];
 }
 
 - (NSViewController *)textListViewController
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 52b08a8..256c75d 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,14 @@
+2020-06-30  Sam Weinig  <weinig@apple.com>
+
+        Split Color serialization out of Color classes
+        https://bugs.webkit.org/show_bug.cgi?id=213820
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp:
+        (TestWebKitAPI::TEST):
+        Update tests to use ColorSerialization.h
+
 2020-06-30  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Several key event tests in fast/events/ios are failing after <rdar://problem/62197116>
diff --git a/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp b/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp
index 0f5e604..3810149 100644
--- a/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp
+++ b/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp
@@ -28,6 +28,7 @@
 #include "Test.h"
 #include "WTFStringUtilities.h"
 #include <WebCore/Color.h>
+#include <WebCore/ColorSerialization.h>
 #include <wtf/MathExtras.h>
 
 using namespace WebCore;
@@ -46,7 +47,7 @@
     EXPECT_FLOAT_EQ(0.25, b);
     EXPECT_FLOAT_EQ(1.0, alpha);
     EXPECT_EQ(1u, c1.asExtended().refCount());
-    EXPECT_EQ(c1.cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(c1), "color(display-p3 1 0.5 0.25)");
 }
 
 TEST(ExtendedColor, CopyConstructor)
@@ -64,7 +65,7 @@
     EXPECT_FLOAT_EQ(1.0, alpha);
     EXPECT_EQ(2u, c1.asExtended().refCount());
     EXPECT_EQ(2u, c2.asExtended().refCount());
-    EXPECT_EQ(c2.cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(c2), "color(display-p3 1 0.5 0.25)");
 }
 
 TEST(ExtendedColor, Assignment)
@@ -82,7 +83,7 @@
     EXPECT_FLOAT_EQ(1.0, alpha);
     EXPECT_EQ(2u, c1.asExtended().refCount());
     EXPECT_EQ(2u, c2.asExtended().refCount());
-    EXPECT_EQ(c2.cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(c2), "color(display-p3 1 0.5 0.25)");
 }
 
 TEST(ExtendedColor, Equality)
@@ -166,7 +167,7 @@
     EXPECT_FLOAT_EQ(0.25, b);
     EXPECT_FLOAT_EQ(1.0, alpha);
     EXPECT_EQ(1u, c2.asExtended().refCount());
-    EXPECT_EQ(c2.cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(c2), "color(display-p3 1 0.5 0.25)");
 }
 
 TEST(ExtendedColor, MoveAssignment)
@@ -188,7 +189,7 @@
     EXPECT_FLOAT_EQ(0.25, b);
     EXPECT_FLOAT_EQ(1.0, alpha);
     EXPECT_EQ(1u, c2.asExtended().refCount());
-    EXPECT_EQ(c2.cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(c2), "color(display-p3 1 0.5 0.25)");
 }
 
 TEST(ExtendedColor, BasicReferenceCounting)
@@ -206,7 +207,7 @@
     EXPECT_FLOAT_EQ(0.25, b);
     EXPECT_FLOAT_EQ(1.0, alpha);
     EXPECT_EQ(3u, c2->asExtended().refCount());
-    EXPECT_EQ(c2->cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(*c2), "color(display-p3 1 0.5 0.25)");
 
     delete c1;
     EXPECT_EQ(2u, c2->asExtended().refCount());
@@ -232,7 +233,7 @@
     EXPECT_TRUE(c2.isExtended());
 
     EXPECT_EQ(1u, c2.asExtended().refCount());
-    EXPECT_EQ(c2.cssText(), "color(display-p3 1 0.5 0.25)");
+    EXPECT_EQ(serializationForCSS(c2), "color(display-p3 1 0.5 0.25)");
 }
 
 TEST(ExtendedColor, P3ConversionToSRGB)