Title: [207442] trunk
Revision
207442
Author
d...@apple.com
Date
2016-10-17 17:12:00 -0700 (Mon, 17 Oct 2016)

Log Message

Allow creation of ExtendedColors and make Color immutable
https://bugs.webkit.org/show_bug.cgi?id=163557
<rdar://problem/28805360>

Reviewed by Darin Adler and Dave Hyatt.

Source/WebCore:

1. Support the creation of ExtendedColor objects via the
Color class.

2. Fix the remaining few places where a Color object is
modified after creation, instead creating a new Color.
Move all the mutation methods into the private section,
making Color now immutable.

Changes to Color are covered by existing tests. Changes
to ExtendedColor are covered by the ExtendedColor API test.

* css/parser/CSSParser.cpp:
(WebCore::CSSParser::fastParseColor): Return a new named Color.

* dom/Document.cpp:
(WebCore::Document::resetActiveLinkColor): Set to be the named "red" color.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::addHTMLColorToStyle): Use the string-based constructor
where possible.

* page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): No need to
use the string "black" here - we have a constant value.

* platform/graphics/cairo/GraphicsContextCairo.cpp: Don't use setRGB.

* platform/graphics/Color.cpp:
(WebCore::findNamedColor): Move this up in the file.
(WebCore::Color::Color): Copy in the code from setNamedColor. Also
add a constructor for ExtendedColor.
(WebCore::Color::serialized): Call ExtendedColor's serializer if necessary.
(WebCore::Color::cssText): Ditto.
(WebCore::Color::setNamedColor): Deleted.
(WebCore::Color::tagAsExtended): Deleted.

* platform/graphics/Color.h: Add a new constructor.
(WebCore::Color::setRGB): Move to private.

* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::cssText): Implement serializer.
* platform/graphics/ExtendedColor.h:

* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::colorIncludingFallback): Construct a new Color rather than changing an existing object.

Tools:

API tests for ExtendedColor.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp: Added.
(TestWebKitAPI::TEST):
(TestWebKitAPI::makeColor):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (207441 => 207442)


--- trunk/Source/WebCore/ChangeLog	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/ChangeLog	2016-10-18 00:12:00 UTC (rev 207442)
@@ -1,3 +1,57 @@
+2016-10-17  Dean Jackson  <d...@apple.com>
+
+        Allow creation of ExtendedColors and make Color immutable
+        https://bugs.webkit.org/show_bug.cgi?id=163557
+        <rdar://problem/28805360>
+
+        Reviewed by Darin Adler and Dave Hyatt.
+
+        1. Support the creation of ExtendedColor objects via the
+        Color class.
+
+        2. Fix the remaining few places where a Color object is
+        modified after creation, instead creating a new Color.
+        Move all the mutation methods into the private section,
+        making Color now immutable.
+
+        Changes to Color are covered by existing tests. Changes
+        to ExtendedColor are covered by the ExtendedColor API test.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::fastParseColor): Return a new named Color.
+
+        * dom/Document.cpp:
+        (WebCore::Document::resetActiveLinkColor): Set to be the named "red" color.
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::addHTMLColorToStyle): Use the string-based constructor
+        where possible.
+
+        * page/CaptionUserPreferencesMediaAF.cpp:
+        (WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): No need to
+        use the string "black" here - we have a constant value.
+
+        * platform/graphics/cairo/GraphicsContextCairo.cpp: Don't use setRGB.
+
+        * platform/graphics/Color.cpp:
+        (WebCore::findNamedColor): Move this up in the file.
+        (WebCore::Color::Color): Copy in the code from setNamedColor. Also
+        add a constructor for ExtendedColor.
+        (WebCore::Color::serialized): Call ExtendedColor's serializer if necessary.
+        (WebCore::Color::cssText): Ditto.
+        (WebCore::Color::setNamedColor): Deleted.
+        (WebCore::Color::tagAsExtended): Deleted.
+
+        * platform/graphics/Color.h: Add a new constructor.
+        (WebCore::Color::setRGB): Move to private.
+
+        * platform/graphics/ExtendedColor.cpp:
+        (WebCore::ExtendedColor::cssText): Implement serializer.
+        * platform/graphics/ExtendedColor.h:
+
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::colorIncludingFallback): Construct a new Color rather than changing an existing object.
+
 2016-10-17  Simon Fraser  <simon.fra...@apple.com>
 
         Implement DOMRect/DOMRectReadOnly

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (207441 => 207442)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -7550,8 +7550,7 @@
         return color;
 
     // Try named colors.
-    color.setNamedColor(name);
-    return color;
+    return Color { name };
 }
     
 inline double CSSParser::parsedDouble(ValueWithCalculation& valueWithCalculation)

Modified: trunk/Source/WebCore/dom/Document.cpp (207441 => 207442)


--- trunk/Source/WebCore/dom/Document.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -820,7 +820,7 @@
 
 void Document::resetActiveLinkColor()
 {
-    m_activeLinkColor.setNamedColor("red");
+    m_activeLinkColor = Color(255, 0, 0);
 }
 
 DOMImplementation& Document::implementation()

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (207441 => 207442)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -1037,18 +1037,13 @@
     if (equalLettersIgnoringASCIICase(colorString, "transparent"))
         return;
 
-    // If the string is a named CSS color or a 3/6-digit hex color, use that.
-    // We can't use the default Color constructor because it accepts
+    Color color;
+    // We can't always use the default Color constructor because it accepts
     // 4/8-digit hex, which conflict with some legacy HTML content using attributes.
-
-    Color color;
-
-    if ((colorString.length() == 4 || colorString.length() == 7) && colorString[0] == '#')
+    if ((colorString.length() != 5 && colorString.length() != 9) || colorString[0] != '#')
         color = Color(colorString);
     if (!color.isValid())
-        color.setNamedColor(colorString);
-    if (!color.isValid())
-        color.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
+        color = Color(parseColorStringWithCrazyLegacyRules(colorString));
 
     style.setProperty(propertyID, CSSValuePool::singleton().createColorValue(color.rgb()));
 }

Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (207441 => 207442)


--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -396,7 +396,7 @@
     bool unused;
     Color color = captionsTextColor(unused);
     if (!color.isValid())
-        color.setNamedColor("black");
+        color = Color { Color::black };
     color = captionsEdgeColorForTextColor(color);
 
     MACaptionAppearanceBehavior behavior;

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (207441 => 207442)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -222,6 +222,22 @@
     return dR * dR + dG * dG + dB * dB;
 }
 
+static inline const NamedColor* findNamedColor(const String& name)
+{
+    char buffer[64]; // easily big enough for the longest color name
+    unsigned length = name.length();
+    if (length > sizeof(buffer) - 1)
+        return nullptr;
+    for (unsigned i = 0; i < length; ++i) {
+        UChar c = name[i];
+        if (!c || !WTF::isASCII(c))
+            return nullptr;
+        buffer[i] = toASCIILower(static_cast<char>(c));
+    }
+    buffer[length] = '\0';
+    return findColor(buffer, length);
+}
+
 Color::Color(const String& name)
 {
     if (name[0] == '#') {
@@ -235,8 +251,12 @@
 
         if (valid)
             setRGB(color);
-    } else
-        setNamedColor(name);
+    } else {
+        if (auto* foundColor = findNamedColor(name))
+            setRGB(foundColor->ARGBValue);
+        else
+            m_colorData.rgbaAndFlags = invalidRGBAColor;
+    }
 }
 
 Color::Color(const char* name)
@@ -267,6 +287,13 @@
     *this = WTFMove(other);
 }
 
+Color::Color(float r, float g, float b, float a, ColorSpace colorSpace)
+{
+    auto extendedColorRef = ExtendedColor::create(r, g, b, a, colorSpace);
+    m_colorData.extendedColor = &extendedColorRef.leakRef();
+    ASSERT(isExtended());
+}
+
 Color::~Color()
 {
     if (isExtended())
@@ -301,6 +328,9 @@
 
 String Color::serialized() const
 {
+    if (isExtended())
+        return asExtended().cssText();
+
     if (!hasAlpha()) {
         StringBuilder builder;
         builder.reserveCapacity(7);
@@ -316,6 +346,9 @@
 
 String Color::cssText() const
 {
+    if (isExtended())
+        return asExtended().cssText();
+
     StringBuilder builder;
     builder.reserveCapacity(28);
     bool colorHasAlpha = hasAlpha();
@@ -352,31 +385,6 @@
     return String::format("#%02X%02X%02X", red(), green(), blue());
 }
 
-static inline const NamedColor* findNamedColor(const String& name)
-{
-    char buffer[64]; // easily big enough for the longest color name
-    unsigned length = name.length();
-    if (length > sizeof(buffer) - 1)
-        return 0;
-    for (unsigned i = 0; i < length; ++i) {
-        UChar c = name[i];
-        if (!c || c > 0x7F)
-            return 0;
-        buffer[i] = toASCIILower(static_cast<char>(c));
-    }
-    buffer[length] = '\0';
-    return findColor(buffer, length);
-}
-
-void Color::setNamedColor(const String& name)
-{
-    const NamedColor* foundColor = findNamedColor(name);
-    if (foundColor)
-        setRGB(foundColor->ARGBValue);
-    else
-        m_colorData.rgbaAndFlags = invalidRGBAColor;
-}
-
 Color Color::light() const
 {
     // Hardcode this common case for speed.
@@ -624,25 +632,15 @@
     m_colorData.rgbaAndFlags |= validRGBAColor;
 }
 
-void Color::tagAsExtended()
-{
-    // FIXME: Is this method necessary? Will colors ever change from RGBA32 to Extended?
-    // Valid colors should not change type.
-    ASSERT(!isValid());
-    m_colorData.rgbaAndFlags &= ~(invalidRGBAColor);
-}
-
 bool Color::isExtended() const
 {
     return !(m_colorData.rgbaAndFlags & invalidRGBAColor);
 }
 
-ExtendedColor* Color::asExtended() const
+ExtendedColor& Color::asExtended() const
 {
     ASSERT(isExtended());
-    if (!isExtended())
-        return nullptr;
-    return m_colorData.extendedColor;
+    return *m_colorData.extendedColor;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/Color.h (207441 => 207442)


--- trunk/Source/WebCore/platform/graphics/Color.h	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2016-10-18 00:12:00 UTC (rev 207442)
@@ -158,7 +158,10 @@
         ASSERT(!isExtended());
     }
 
-    // FIXME: Add constructor for ExtendedColor type.
+    // This creates an ExtendedColor.
+    // FIXME: If the colorSpace is sRGB and the values can all be
+    // converted exactly to integers, we should make a normal Color.
+    WEBCORE_EXPORT Color(float r, float g, float b, float a, ColorSpace colorSpace);
 
     Color(RGBA, ColorSpace);
     WEBCORE_EXPORT Color(const Color&);
@@ -181,14 +184,12 @@
     // <https://html.spec.whatwg.org/multipage/scripting.html#fill-and-stroke-styles> (10 September 2015)
     WEBCORE_EXPORT String serialized() const;
 
-    String cssText() const;
+    WEBCORE_EXPORT String cssText() const;
 
     // Returns the color serialized as either #RRGGBB or #RRGGBBAA
     // The latter format is not a valid CSS color, and should only be seen in DRT dumps.
     String nameForRenderTreeAsText() const;
 
-    void setNamedColor(const String&);
-
     bool isValid() const { return m_colorData.rgbaAndFlags & validRGBAColorBit; }
 
     bool hasAlpha() const { return alpha() < 255; }
@@ -199,8 +200,6 @@
     int alpha() const { return alphaChannel(rgb()); }
     
     RGBA32 rgb() const { ASSERT(!isExtended()); return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32); }
-    void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
-    void setRGB(RGBA32);
     uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }
 
     WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
@@ -256,7 +255,7 @@
 #endif
 
     WEBCORE_EXPORT bool isExtended() const;
-    WEBCORE_EXPORT ExtendedColor* asExtended() const;
+    WEBCORE_EXPORT ExtendedColor& asExtended() const;
 
     WEBCORE_EXPORT Color& operator=(const Color&);
     WEBCORE_EXPORT Color& operator=(Color&&);
@@ -264,6 +263,8 @@
     friend bool operator==(const Color& a, const Color& b);
 
 private:
+    void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
+    void setRGB(RGBA32);
 
     // 0x_______00 is an ExtendedColor pointer.
     // 0x_______01 is an invalid RGBA32.
@@ -274,7 +275,6 @@
     static const uint64_t validRGBAColor = 0x3;
 
     WEBCORE_EXPORT void tagAsValid();
-    void tagAsExtended();
 
     union {
         uint64_t rgbaAndFlags { invalidRGBAColor };

Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp (207441 => 207442)


--- trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -27,6 +27,9 @@
 #include "ExtendedColor.h"
 
 #include "ColorSpace.h"
+#include <wtf/MathExtras.h>
+#include <wtf/dtoa.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -35,4 +38,40 @@
     return adoptRef(*new ExtendedColor(r, g, b, a, colorSpace));
 }
 
+String ExtendedColor::cssText() const
+{
+    StringBuilder builder;
+    builder.reserveCapacity(40);
+    builder.appendLiteral("color(");
+
+    switch (m_colorSpace) {
+    case ColorSpaceSRGB:
+        builder.appendLiteral("srgb ");
+        break;
+    case ColorSpaceDisplayP3:
+        builder.appendLiteral("display-p3 ");
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        return WTF::emptyString();
+    }
+
+    NumberToStringBuffer buffer;
+    bool shouldTruncateTrailingZeros = true;
+
+    builder.append(numberToFixedPrecisionString(red(), 6, buffer, shouldTruncateTrailingZeros));
+    builder.append(' ');
+
+    builder.append(numberToFixedPrecisionString(green(), 6, buffer, shouldTruncateTrailingZeros));
+    builder.append(' ');
+
+    builder.append(numberToFixedPrecisionString(blue(), 6, buffer, shouldTruncateTrailingZeros));
+    builder.appendLiteral(" / ");
+
+    builder.append(numberToFixedPrecisionString(alpha(), 6, buffer, shouldTruncateTrailingZeros));
+    builder.append(')');
+
+    return builder.toString();
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.h (207441 => 207442)


--- trunk/Source/WebCore/platform/graphics/ExtendedColor.h	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.h	2016-10-18 00:12:00 UTC (rev 207442)
@@ -29,6 +29,7 @@
 
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -43,6 +44,8 @@
 
     ColorSpace colorSpace() const { return m_colorSpace; }
 
+    WEBCORE_EXPORT String cssText() const;
+
 private:
     ExtendedColor(float r, float g, float b, float a, ColorSpace colorSpace)
         : m_red(r)

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (207441 => 207442)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -540,7 +540,7 @@
 {
 #if !PLATFORM(GTK)
     // Force the alpha to 50%.  This matches what the Mac does with outline rings.
-    color.setRGB(makeRGBA(color.red(), color.green(), color.blue(), 127));
+    color = Color(makeRGBA(color.red(), color.green(), color.blue(), 127));
 #else
     UNUSED_PARAM(color);
 #endif

Modified: trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp (207441 => 207442)


--- trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -199,6 +199,7 @@
     static const RGBA32 blue = 0xff0000ff;
     static const RGBA32 red = 0xffff0000;
     static const RGBA32 green = 0xff008000;
+    static const RGBA32 cyan = 0xFF00FFFF;
 
     IntSize size = this->size();
     float boxSize = size.width() * .035;
@@ -248,7 +249,7 @@
 
     boxTop += boxSize + 2;
     boxLeft = boxSize;
-    Color boxColors[] = { Color::white, yellow, Color::cyan, green, magenta, red, blue };
+    Color boxColors[] = { Color::white, yellow, cyan, green, magenta, red, blue };
     for (unsigned i = 0; i < sizeof(boxColors) / sizeof(boxColors[0]); i++) {
         context.fillRect(FloatRect(boxLeft, boxTop, boxSize + 1, boxSize + 1), boxColors[i]);
         boxLeft += boxSize + 1;

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (207441 => 207442)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -1683,7 +1683,7 @@
 
     if (!result.isValid()) {
         if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
-            result.setRGB(238, 238, 238);
+            result = Color(238, 238, 238);
         else
             result = visitedLink ? visitedLinkColor() : color();
     }

Modified: trunk/Tools/ChangeLog (207441 => 207442)


--- trunk/Tools/ChangeLog	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Tools/ChangeLog	2016-10-18 00:12:00 UTC (rev 207442)
@@ -1,3 +1,18 @@
+2016-10-17  Dean Jackson  <d...@apple.com>
+
+        Allow creation of ExtendedColors and make Color immutable
+        https://bugs.webkit.org/show_bug.cgi?id=163557
+        <rdar://problem/28805360>
+
+        Reviewed by Darin Adler and Dave Hyatt.
+
+        API tests for ExtendedColor.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp: Added.
+        (TestWebKitAPI::TEST):
+        (TestWebKitAPI::makeColor):
+
 2016-10-17  JF Bastien  <jfbast...@apple.com>
 
         WebAssembly JS API: implement basic stub

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (207441 => 207442)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-10-17 23:27:36 UTC (rev 207441)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-10-18 00:12:00 UTC (rev 207442)
@@ -85,6 +85,7 @@
 		2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */; };
 		2EFF06D41D8AEDBB0004BB30 /* TestWKWebViewMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D31D8AEDBB0004BB30 /* TestWKWebViewMac.mm */; };
 		2EFF06D71D8AF34A0004BB30 /* WKWebViewCandidateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */; };
+		315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; };
 		33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; };
 		33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; };
 		33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */; };
@@ -822,6 +823,7 @@
 		2EFF06D21D8AEDBB0004BB30 /* TestWKWebViewMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestWKWebViewMac.h; sourceTree = "<group>"; };
 		2EFF06D31D8AEDBB0004BB30 /* TestWKWebViewMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestWKWebViewMac.mm; sourceTree = "<group>"; };
 		2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCandidateTests.mm; sourceTree = "<group>"; };
+		3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; };
 		333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
 		33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
 		33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = "<group>"; };
@@ -1456,6 +1458,7 @@
 				260BA5781B1D2E7B004FA07C /* DFACombiner.cpp */,
 				260BA57A1B1D2EE2004FA07C /* DFAHelpers.h */,
 				26F6E1EF1ADC749B00DE696B /* DFAMinimizer.cpp */,
+				3151180F1DB1ADD500176304 /* ExtendedColor.cpp */,
 				41973B5A1AF2286A006C7B36 /* FileSystem.cpp */,
 				83B88A331C80056D00BB2418 /* HTMLParserIdioms.cpp */,
 				14464012167A8305000BD218 /* LayoutUnit.cpp */,
@@ -2431,6 +2434,7 @@
 				7CCE7EC51A411A7E00447C4C /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */,
 				7CCE7EC61A411A7E00447C4C /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */,
 				7C83E0B71D0A64B800FEBCF3 /* MenuTypesForMouseEvents.cpp in Sources */,
+				315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */,
 				51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
 				7C83E0B61D0A64B300FEBCF3 /* ModalAlertsSPI.cpp in Sources */,
 				7CCE7F011A411AE600447C4C /* MouseMoveAfterCrash.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp (0 => 207442)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp	2016-10-18 00:12:00 UTC (rev 207442)
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2016 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 "Test.h"
+#include <WebCore/Color.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+TEST(ExtendedColor, Constructor)
+{
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1.isExtended());
+    EXPECT_FLOAT_EQ(1.0, c1.asExtended().red());
+    EXPECT_FLOAT_EQ(0.5, c1.asExtended().green());
+    EXPECT_FLOAT_EQ(0.25, c1.asExtended().blue());
+    EXPECT_FLOAT_EQ(1.0, c1.asExtended().alpha());
+    EXPECT_EQ(static_cast<unsigned>(1), c1.asExtended().refCount());
+    EXPECT_TRUE(c1.cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+}
+
+TEST(ExtendedColor, CopyConstructor)
+{
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1.isExtended());
+
+    Color c2(c1);
+
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().red());
+    EXPECT_FLOAT_EQ(0.5, c2.asExtended().green());
+    EXPECT_FLOAT_EQ(0.25, c2.asExtended().blue());
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().alpha());
+    EXPECT_EQ(static_cast<unsigned>(2), c1.asExtended().refCount());
+    EXPECT_EQ(static_cast<unsigned>(2), c2.asExtended().refCount());
+    EXPECT_TRUE(c2.cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+}
+
+TEST(ExtendedColor, Assignment)
+{
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1.isExtended());
+
+    Color c2 = c1;
+
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().red());
+    EXPECT_FLOAT_EQ(0.5, c2.asExtended().green());
+    EXPECT_FLOAT_EQ(0.25, c2.asExtended().blue());
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().alpha());
+    EXPECT_EQ(static_cast<unsigned>(2), c1.asExtended().refCount());
+    EXPECT_EQ(static_cast<unsigned>(2), c2.asExtended().refCount());
+    EXPECT_TRUE(c2.cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+}
+
+TEST(ExtendedColor, MoveConstructor)
+{
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1.isExtended());
+
+    Color c2(WTFMove(c1));
+    // We should have moved the extended color pointer into c2,
+    // and set c1 to invalid so that it doesn't cause deletion.
+    EXPECT_FALSE(c1.isExtended());
+    EXPECT_FALSE(c1.isValid());
+
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().red());
+    EXPECT_FLOAT_EQ(0.5, c2.asExtended().green());
+    EXPECT_FLOAT_EQ(0.25, c2.asExtended().blue());
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().alpha());
+    EXPECT_EQ(static_cast<unsigned>(1), c2.asExtended().refCount());
+    EXPECT_TRUE(c2.cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+}
+
+TEST(ExtendedColor, MoveAssignment)
+{
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1.isExtended());
+
+    Color c2 = WTFMove(c1);
+    // We should have moved the extended color pointer into c2,
+    // and set c1 to invalid so that it doesn't cause deletion.
+    EXPECT_FALSE(c1.isExtended());
+    EXPECT_FALSE(c1.isValid());
+
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().red());
+    EXPECT_FLOAT_EQ(0.5, c2.asExtended().green());
+    EXPECT_FLOAT_EQ(0.25, c2.asExtended().blue());
+    EXPECT_FLOAT_EQ(1.0, c2.asExtended().alpha());
+    EXPECT_EQ(static_cast<unsigned>(1), c2.asExtended().refCount());
+    EXPECT_TRUE(c2.cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+}
+
+TEST(ExtendedColor, BasicReferenceCounting)
+{
+    Color* c1 = new Color(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1->isExtended());
+
+    Color* c2 = new Color(*c1);
+    Color* c3 = new Color(*c2);
+
+    EXPECT_FLOAT_EQ(1.0, c2->asExtended().red());
+    EXPECT_FLOAT_EQ(0.5, c2->asExtended().green());
+    EXPECT_FLOAT_EQ(0.25, c2->asExtended().blue());
+    EXPECT_FLOAT_EQ(1.0, c2->asExtended().alpha());
+    EXPECT_EQ(static_cast<unsigned>(3), c2->asExtended().refCount());
+    EXPECT_TRUE(c2->cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+
+    delete c1;
+    EXPECT_EQ(static_cast<unsigned>(2), c2->asExtended().refCount());
+
+    delete c2;
+    EXPECT_EQ(static_cast<unsigned>(1), c3->asExtended().refCount());
+
+    delete c3;
+}
+
+Color makeColor()
+{
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    EXPECT_TRUE(c1.isExtended());
+    EXPECT_EQ(static_cast<unsigned>(1), c1.asExtended().refCount());
+
+    return c1;
+}
+
+TEST(ExtendedColor, ReturnValues)
+{
+    Color c2 = makeColor();
+    EXPECT_TRUE(c2.isExtended());
+
+    EXPECT_EQ(static_cast<unsigned>(1), c2.asExtended().refCount());
+    EXPECT_TRUE(c2.cssText() == "color(display-p3 1 0.5 0.25 / 1)");
+
+}
+
+
+} // namespace TestWebKitAPI
Property changes on: trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Author Id Revision HeadURL \ No newline at end of property
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to