Diff
Modified: trunk/Source/WebCore/ChangeLog (255784 => 255785)
--- trunk/Source/WebCore/ChangeLog 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/ChangeLog 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,3 +1,146 @@
+2020-02-01 Darin Adler <[email protected]>
+
+ Replace RGBA32 typedef with a class to improve type safety
+ https://bugs.webkit.org/show_bug.cgi?id=206862
+
+ Reviewed by Sam Weinig.
+
+ * Headers.cmake: Remove RGBColor.h.
+ * Sources.txt: Remove RBGColor.cpp.
+ * WebCore.xcodeproj/project.pbxproj: Remove RGBColor.h and RGBColor.cpp.
+
+ * css/CSSPrimitiveValue.cpp: Removed include of RGBColor.h.
+ (WebCore::CSSPrimitiveValue::getCounterValue const): Deleted.
+ (WebCore::CSSPrimitiveValue::getRectValue const): Deleted.
+ (WebCore::CSSPrimitiveValue::getRGBColorValue const): Deleted.
+ * css/CSSPrimitiveValue.h: Updated for the above.
+
+ * css/DeprecatedCSSOMPrimitiveValue.cpp:
+ (WebCore::DeprecatedCSSOMPrimitiveValue::getCounterValue const): Use
+ CSSPrimitiveValue::counterValue.
+ (WebCore::DeprecatedCSSOMPrimitiveValue::getRectValue const): Use
+ CSSPrimitiveValue::rectValue.
+ (WebCore::DeprecatedCSSOMPrimitiveValue::getRGBColorValue const): USe
+ CSSPrimitiveValue::isRGBColor and CSSPrimitiveValue::color.
+
+ * css/DeprecatedCSSOMRGBColor.h: Store a Color instead of an RGBA32.
+ Take a Color argument instead of a RGBColor argument. Refactored to
+ use a createWrapper template function member to tighten the code.
+
+ * css/RGBColor.cpp: Removed.
+ * css/RGBColor.h: Removed.
+
+ * css/StyleColor.cpp:
+ (WebCore::StyleColor::colorFromKeyword): Explicitly convert to SimpleColor
+ rather than relying on initializing a Color from an integer ARGB value.
+
+ * editing/cocoa/HTMLConverter.mm: Removed include of RGBColor.h.
+
+ * inspector/InspectorOverlay.cpp:
+ (WebCore::drawOutlinedQuadWithClip): Use the Color constructor instead of
+ Color::createUnchecked.
+
+ * page/cocoa/ResourceUsageOverlayCocoa.mm:
+ (WebCore::HistoricMemoryCategoryInfo::HistoricMemoryCategoryInfo): Use
+ explicit SimpleColor rather than relying on initializing a Color from an
+ integer ARGB value.
+
+ * platform/graphics/Color.cpp: Use constexpr for constant colors.
+ (WebCore::makeRGB): Implement by calling makeRGBA.
+ (WebCore::makeRGBA): Use an explicit argument list to call the
+ SimpleColor constructor.
+ (WebCore::makeRGBA32FromFloats): Implement by calling makeRGBA.
+ (WebCore::colorWithOverrideAlpha): Use an explicit argument list to call
+ the SimpleColor constructor.
+ (WebCore::parseHexColorInternal): Ditto.
+ (WebCore::Color::Color): Removed unneeded code to set the color
+ to invalid, since that's already the default for a new Color object.
+ Also tweak the logic a bit and add explicit argument list for the
+ SimpleColor constructor.
+ (WebCore::SimpleColor::serializationForHTML const): Added. Factored out of
+ the Color::serialized function.
+ (WebCore::Color::serialized const): Changed to call serializationForHTML.
+ (WebCore::fractionDigitsForFractionalAlphaValue): Renamed slightly shorter.
+ (WebCore::SimpleColor::serializationForCSS const): Added. Factored out of
+ the Color::cssText function.
+ (WebCore::Color::cssText const): Changed to call serializationForCSS.
+ (WebCore::RGBA32::serializationForRenderTreeAsText const): Added.
+ Factored out of nameForRenderTreeAsText.
+ (WebCore::Color::nameForRenderTreeAsText const): Changed to call
+ serializationForRenderTreeAsText.
+ (WebCore::colorFromPremultipliedARGB): Updated to use the SimpleColor
+ member functions instead of the red/green/blue/alphaChannel functions.
+ (WebCore::blend): Use Color::transparent for blending where the old
+ code used 0 and relied on how that is converted to a Color.
+
+ * platform/graphics/Color.h: Replaced the RGBA32 typedef and the
+ RGBA class with a new class named SimpleColor. Deleted the four
+ red/green/blue/alphaChannel functions, the Color constructor that
+ takes and RGBA, and the Color::createUnchecked function. Changed
+ the color constants to all be constexpr. Moved the inline function
+ definitions until after everything is delcared.
+
+ * platform/graphics/ImageBackingStore.h:
+ (WebCore::ImageBackingStore::setSize): Use uint32_t instead of RGBA32.
+ (WebCore::ImageBackingStore::clear): Ditto.
+ (WebCore::ImageBackingStore::clearRect): Ditto.
+ (WebCore::ImageBackingStore::fillRect): Ditto.
+ (WebCore::ImageBackingStore::repeatFirstRow): Ditto.
+ (WebCore::ImageBackingStore::pixelAt const): Ditto.
+ (WebCore::ImageBackingStore::setPixel): Ditto.
+ (WebCore::ImageBackingStore::blendPixel): Ditto. Convert to and from
+ SimpleColor so we can use various functions that operate on that type.
+ Use the isVisible and red/green/blue/alphaComponent member functions.
+ (WebCore::ImageBackingStore::ImageBackingStore): Ditto.
+ (WebCore::ImageBackingStore::pixelValue const): Use Color::transparent
+ instead of returning a 0 and relying on how that is converted to a Color.
+
+ * platform/graphics/ImageFrame.h: Removed include of ImageBackingStore.h.
+ * platform/graphics/ImageSource.h: Added forward delaration of SharedBuffer.
+
+ * platform/graphics/cairo/ImageBufferCairo.cpp:
+ (WebCore::ImageBuffer::platformTransformColorSpace): Call value() to
+ convert RGBA32, which is now a class, to an 32-bit ARGB integer.
+
+ * platform/graphics/cg/ColorCG.cpp:
+ (WebCore::cachedCGColor): Use constexpr SimpleColor::value function to
+ switch on a SimpleColor.
+
+ * platform/graphics/mac/ColorMac.mm:
+ (WebCore::oldAquaFocusRingColor): Use an explicit SimpleColor to turn a
+ hex integer into a Color without relying on implicit conversion.
+
+ * platform/graphics/win/ColorDirect2D.cpp:
+ (WebCore::Color::operator D2D1_COLOR_F const): Use value() to get the color
+ integer, just to keep this working. Probably needs a better implementation
+ at some point.
+
+ * platform/image-decoders/png/PNGImageDecoder.cpp:
+ (WebCore::PNGImageDecoder::rowAvailable): Don't use makeRGB any more,
+ write the _expression_ out here instead. More efficient anyway since these
+ are already single bytes.
+
+ * platform/mock/MockRealtimeMediaSourceCenter.cpp:
+ (WebCore::defaultDevices): Use an explicit SimpleColor to turn a
+ hex integer into a Color without relying on implicit conversion.
+ * platform/mock/MockRealtimeVideoSource.cpp:
+ (WebCore::MockRealtimeVideoSource::drawBoxes): Ditto. Also use a modern
+ for loop instead of indexing.
+ * platform/mock/ScrollbarThemeMock.cpp:
+ (WebCore::ScrollbarThemeMock::paintTrackBackground): Ditto.
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::calculateBorderStyleColor): Ditto.
+ * rendering/RenderTheme.cpp:
+ (WebCore::RenderTheme::systemColor const): Ditto. Also used named colors.
+ * rendering/RenderThemeMac.mm:
+ (WebCore::RenderThemeMac::systemColor const): Ditto.
+
+ * rendering/RenderTreeAsText.cpp:
+ (WebCore::RenderTreeAsText::writeRenderObject): Added checks against
+ Color::transparent instead of converting to an integer and checking
+ against 0. Removed unneeded isValid checks, since invalid color's ARGB
+ value is Color::transparent.
+
2020-02-04 Darin Adler <[email protected]>
Remove NSKeyedArchiverSPI.h now that WebKit only uses API
Modified: trunk/Source/WebCore/Headers.cmake (255784 => 255785)
--- trunk/Source/WebCore/Headers.cmake 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/Headers.cmake 2020-02-05 03:47:15 UTC (rev 255785)
@@ -336,7 +336,6 @@
css/MediaQueryEvaluator.h
css/MediaQueryExpression.h
css/MediaQueryParserContext.h
- css/RGBColor.h
css/Rect.h
css/StyleColor.h
css/StyleProperties.h
Modified: trunk/Source/WebCore/Sources.txt (255784 => 255785)
--- trunk/Source/WebCore/Sources.txt 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/Sources.txt 2020-02-05 03:47:15 UTC (rev 255785)
@@ -766,7 +766,6 @@
css/MediaQueryMatcher.cpp
css/MediaQueryParserContext.cpp
css/PropertySetCSSStyleDeclaration.cpp
-css/RGBColor.cpp
css/SVGCSSComputedStyleDeclaration.cpp
css/SelectorChecker.cpp
css/SelectorFilter.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (255784 => 255785)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-02-05 03:47:15 UTC (rev 255785)
@@ -3831,7 +3831,6 @@
BC6932740D7E293900AE44D1 /* JSDOMWindowBase.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6932720D7E293900AE44D1 /* JSDOMWindowBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC6D44ED0C07F2ED0072D2C9 /* JSHTMLEmbedElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6D44EB0C07F2ED0072D2C9 /* JSHTMLEmbedElement.h */; };
BC6D6E2609AF943500F59759 /* ScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6D6E2509AF943500F59759 /* ScrollView.h */; settings = {ATTRIBUTES = (Private, ); }; };
- BC74DA371013F3F7007987AD /* RGBColor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC74DA351013F3F7007987AD /* RGBColor.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC772B3C0C4EA91E0083285F /* CSSHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = BC772B360C4EA91E0083285F /* CSSHelper.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC772C470C4EB2C60083285F /* XMLHttpRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = BC772C450C4EB2C60083285F /* XMLHttpRequest.h */; };
BC772C4F0C4EB3040083285F /* MIMETypeRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -13184,8 +13183,6 @@
BC6D44EA0C07F2ED0072D2C9 /* JSHTMLEmbedElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLEmbedElement.cpp; sourceTree = "<group>"; };
BC6D44EB0C07F2ED0072D2C9 /* JSHTMLEmbedElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLEmbedElement.h; sourceTree = "<group>"; };
BC6D6E2509AF943500F59759 /* ScrollView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ScrollView.h; sourceTree = "<group>"; };
- BC74DA351013F3F7007987AD /* RGBColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RGBColor.h; sourceTree = "<group>"; };
- BC74DA361013F3F7007987AD /* RGBColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RGBColor.cpp; sourceTree = "<group>"; };
BC772B360C4EA91E0083285F /* CSSHelper.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSHelper.h; sourceTree = "<group>"; };
BC772C440C4EB2C60083285F /* XMLHttpRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = XMLHttpRequest.cpp; sourceTree = "<group>"; };
BC772C450C4EB2C60083285F /* XMLHttpRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = XMLHttpRequest.h; sourceTree = "<group>"; };
@@ -27563,8 +27560,6 @@
E4BBED0D14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h */,
93CA4C9F09DF93FA00DF8677 /* quirks.css */,
BC4368E70C226E32005EFB5F /* Rect.h */,
- BC74DA361013F3F7007987AD /* RGBColor.cpp */,
- BC74DA351013F3F7007987AD /* RGBColor.h */,
E44B4BB1141650D7002B1D8B /* SelectorChecker.cpp */,
E44B4BB2141650D7002B1D8B /* SelectorChecker.h */,
432D3FE718A8658400D7DC03 /* SelectorCheckerTestFunctions.h */,
@@ -32090,7 +32085,6 @@
FD3160A912B026F700C1A359 /* ReverbConvolver.h in Headers */,
FD3160AB12B026F700C1A359 /* ReverbConvolverStage.h in Headers */,
FD3160AD12B026F700C1A359 /* ReverbInputBuffer.h in Headers */,
- BC74DA371013F3F7007987AD /* RGBColor.h in Headers */,
A8CFF5E10A155A05000A4234 /* RootInlineBox.h in Headers */,
49E911C90EF86D47009D0CAF /* RotateTransformOperation.h in Headers */,
A73F95FF12C97BFE0031AAF9 /* RoundedRect.h in Headers */,
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (255784 => 255785)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -37,7 +37,6 @@
#include "FontCascade.h"
#include "Node.h"
#include "Pair.h"
-#include "RGBColor.h"
#include "Rect.h"
#include "RenderStyle.h"
#include <wtf/NeverDestroyed.h>
@@ -874,29 +873,6 @@
}
}
-ExceptionOr<Counter&> CSSPrimitiveValue::getCounterValue() const
-{
- if (primitiveUnitType() != CSSUnitType::CSS_COUNTER)
- return Exception { InvalidAccessError };
- return *m_value.counter;
-}
-
-ExceptionOr<Rect&> CSSPrimitiveValue::getRectValue() const
-{
- if (primitiveUnitType() != CSSUnitType::CSS_RECT)
- return Exception { InvalidAccessError };
- return *m_value.rect;
-}
-
-ExceptionOr<Ref<RGBColor>> CSSPrimitiveValue::getRGBColorValue() const
-{
- if (primitiveUnitType() != CSSUnitType::CSS_RGBCOLOR)
- return Exception { InvalidAccessError };
-
- // FIXME: This should not return a new object for each invocation.
- return RGBColor::create(m_value.color->rgb());
-}
-
NEVER_INLINE String CSSPrimitiveValue::formatNumberValue(StringView suffix) const
{
return makeString(m_value.num, suffix);
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (255784 => 255785)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -142,9 +142,6 @@
WEBCORE_EXPORT ExceptionOr<float> getFloatValue(CSSUnitType) const;
WEBCORE_EXPORT ExceptionOr<void> setStringValue(CSSUnitType, const String&);
WEBCORE_EXPORT ExceptionOr<String> getStringValue() const;
- WEBCORE_EXPORT ExceptionOr<Counter&> getCounterValue() const;
- WEBCORE_EXPORT ExceptionOr<Rect&> getRectValue() const;
- WEBCORE_EXPORT ExceptionOr<Ref<RGBColor>> getRGBColorValue() const;
double computeDegrees() const;
Modified: trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp (255784 => 255785)
--- trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-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
@@ -36,7 +36,6 @@
// such as StyleCounterValue, StyleRectValue, and StyleColorValue, these methods will get
// more complicated.
-
unsigned short DeprecatedCSSOMPrimitiveValue::primitiveType() const
{
return static_cast<unsigned short>(m_value->primitiveType());
@@ -64,26 +63,25 @@
ExceptionOr<Ref<DeprecatedCSSOMCounter>> DeprecatedCSSOMPrimitiveValue::getCounterValue() const
{
- ExceptionOr<Counter&> counter = m_value->getCounterValue();
- if (counter.hasException())
+ auto* value = m_value->counterValue();
+ if (!value)
return Exception { InvalidAccessError };
- return DeprecatedCSSOMCounter::create(counter.releaseReturnValue(), m_owner.get());
+ return DeprecatedCSSOMCounter::create(*value, m_owner);
}
ExceptionOr<Ref<DeprecatedCSSOMRect>> DeprecatedCSSOMPrimitiveValue::getRectValue() const
{
- ExceptionOr<Rect&> rect = m_value->getRectValue();
- if (rect.hasException())
+ auto* value = m_value->rectValue();
+ if (!value)
return Exception { InvalidAccessError };
- return DeprecatedCSSOMRect::create(rect.releaseReturnValue(), m_owner.get());
+ return DeprecatedCSSOMRect::create(*value, m_owner);
}
ExceptionOr<Ref<DeprecatedCSSOMRGBColor>> DeprecatedCSSOMPrimitiveValue::getRGBColorValue() const
{
- ExceptionOr<Ref<RGBColor>> color = m_value->getRGBColorValue();
- if (color.hasException())
+ if (!m_value->isRGBColor())
return Exception { InvalidAccessError };
- return DeprecatedCSSOMRGBColor::create(color.releaseReturnValue(), m_owner.get());
+ return DeprecatedCSSOMRGBColor::create(m_owner, m_value->color());
}
}
Modified: trunk/Source/WebCore/css/DeprecatedCSSOMRGBColor.h (255784 => 255785)
--- trunk/Source/WebCore/css/DeprecatedCSSOMRGBColor.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/DeprecatedCSSOMRGBColor.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999-2003 Lars Knoll ([email protected])
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -21,55 +21,44 @@
#pragma once
#include "DeprecatedCSSOMPrimitiveValue.h"
-#include "RGBColor.h"
-#include <wtf/RefPtr.h>
+#include <wtf/Ref.h>
namespace WebCore {
class DeprecatedCSSOMRGBColor final : public RefCounted<DeprecatedCSSOMRGBColor> {
public:
- static Ref<DeprecatedCSSOMRGBColor> create(const RGBColor& color, CSSStyleDeclaration& owner)
+ static Ref<DeprecatedCSSOMRGBColor> create(CSSStyleDeclaration& owner, const Color& color)
{
- return adoptRef(*new DeprecatedCSSOMRGBColor(color, owner));
+ return adoptRef(*new DeprecatedCSSOMRGBColor(owner, color));
}
- DeprecatedCSSOMPrimitiveValue* red() { return m_red.get(); }
- DeprecatedCSSOMPrimitiveValue* green() { return m_green.get(); }
- DeprecatedCSSOMPrimitiveValue* blue() { return m_blue.get(); }
- DeprecatedCSSOMPrimitiveValue* alpha() { return m_alpha.get(); }
-
- Color color() const { return Color(m_rgbColor); }
+ DeprecatedCSSOMPrimitiveValue& red() { return m_red; }
+ DeprecatedCSSOMPrimitiveValue& green() { return m_green; }
+ DeprecatedCSSOMPrimitiveValue& blue() { return m_blue; }
+ DeprecatedCSSOMPrimitiveValue& alpha() { return m_alpha; }
+ Color color() const { return m_color; }
+
private:
- DeprecatedCSSOMRGBColor(const RGBColor& color, CSSStyleDeclaration& owner)
- : m_rgbColor(color.rgbColor())
+ template<typename NumberType> static Ref<DeprecatedCSSOMPrimitiveValue> createWrapper(CSSStyleDeclaration& owner, NumberType number)
{
- // Red
- unsigned value = (m_rgbColor >> 16) & 0xFF;
- auto result = CSSPrimitiveValue::create(value, CSSUnitType::CSS_NUMBER);
- m_red = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
-
- // Green
- value = (m_rgbColor >> 8) & 0xFF;
- result = CSSPrimitiveValue::create(value, CSSUnitType::CSS_NUMBER);
- m_green = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
+ return CSSPrimitiveValue::create(number, CSSUnitType::CSS_NUMBER)->createDeprecatedCSSOMPrimitiveWrapper(owner);
+ }
- // Blue
- value = m_rgbColor & 0xFF;
- result = CSSPrimitiveValue::create(value, CSSUnitType::CSS_NUMBER);
- m_blue = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
-
- // Alpha
- float alphaValue = static_cast<float>((m_rgbColor >> 24) & 0xFF) / 0xFF;
- result = CSSPrimitiveValue::create(alphaValue, CSSUnitType::CSS_NUMBER);
- m_alpha = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
+ DeprecatedCSSOMRGBColor(CSSStyleDeclaration& owner, const Color& color)
+ : m_color(color)
+ , m_red(createWrapper(owner, color.red()))
+ , m_green(createWrapper(owner, color.green()))
+ , m_blue(createWrapper(owner, color.blue()))
+ , m_alpha(createWrapper(owner, color.alphaAsFloat()))
+ {
}
-
- RGBA32 m_rgbColor;
- RefPtr<DeprecatedCSSOMPrimitiveValue> m_red;
- RefPtr<DeprecatedCSSOMPrimitiveValue> m_green;
- RefPtr<DeprecatedCSSOMPrimitiveValue> m_blue;
- RefPtr<DeprecatedCSSOMPrimitiveValue> m_alpha;
+
+ Color m_color;
+ Ref<DeprecatedCSSOMPrimitiveValue> m_red;
+ Ref<DeprecatedCSSOMPrimitiveValue> m_green;
+ Ref<DeprecatedCSSOMPrimitiveValue> m_blue;
+ Ref<DeprecatedCSSOMPrimitiveValue> m_alpha;
};
} // namespace WebCore
Deleted: trunk/Source/WebCore/css/RGBColor.cpp (255784 => 255785)
--- trunk/Source/WebCore/css/RGBColor.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/RGBColor.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2008, 2009 Google, Inc. All rights reserved.
- * Copyright (C) 2009 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. ``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
- * 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 "RGBColor.h"
-
-namespace WebCore {
-
-Ref<RGBColor> RGBColor::create(unsigned rgbColor)
-{
- return adoptRef(*new RGBColor(rgbColor));
-}
-
-} // namespace WebCore
-
Deleted: trunk/Source/WebCore/css/RGBColor.h (255784 => 255785)
--- trunk/Source/WebCore/css/RGBColor.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/RGBColor.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2006, 2007, 2008, 2009 Google, Inc. All rights reserved.
- * Copyright (C) 2009 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. ``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
- * 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
-
-#include "Color.h"
-#include <wtf/RefCounted.h>
-
-namespace WebCore {
-
-class CSSPrimitiveValue;
-
-class RGBColor final : public RefCounted<RGBColor> {
-public:
- static Ref<RGBColor> create(unsigned rgbColor);
-
- Color color() const { return Color(m_rgbColor); }
-
- RGBA32 rgbColor() const { return m_rgbColor; }
-
-private:
- RGBColor(unsigned rgbColor)
- : m_rgbColor(rgbColor)
- {
- }
-
- RGBA32 m_rgbColor;
-};
-
-} // namespace WebCore
Modified: trunk/Source/WebCore/css/StyleColor.cpp (255784 => 255785)
--- trunk/Source/WebCore/css/StyleColor.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/css/StyleColor.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -41,7 +41,7 @@
{
if (const char* valueName = getValueName(keyword)) {
if (const NamedColor* namedColor = findColor(valueName, strlen(valueName)))
- return Color(namedColor->ARGBValue);
+ return SimpleColor { namedColor->ARGBValue };
}
return RenderTheme::singleton().systemColor(keyword, options);
Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (255784 => 255785)
--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2020-02-05 03:47:15 UTC (rev 255785)
@@ -58,7 +58,6 @@
#import "HTMLTableCellElement.h"
#import "HTMLTextAreaElement.h"
#import "LoaderNSURLExtras.h"
-#import "RGBColor.h"
#import "RenderImage.h"
#import "RenderText.h"
#import "StyleProperties.h"
Modified: trunk/Source/WebCore/inspector/InspectorOverlay.cpp (255784 => 255785)
--- trunk/Source/WebCore/inspector/InspectorOverlay.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/inspector/InspectorOverlay.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -222,7 +222,7 @@
context.fillPath(quadToPath(quad, bounds));
context.setCompositeOperation(CompositeOperator::DestinationOut);
- context.setFillColor(Color::createUnchecked(255, 0, 0));
+ context.setFillColor(Color(255, 0, 0));
context.fillPath(quadToPath(clipQuad, bounds));
}
Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm (255784 => 255785)
--- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm 2020-02-05 03:47:15 UTC (rev 255785)
@@ -128,13 +128,13 @@
struct HistoricMemoryCategoryInfo {
HistoricMemoryCategoryInfo() { } // Needed for std::array.
- HistoricMemoryCategoryInfo(unsigned category, RGBA32 rgba, String name, bool subcategory = false)
+ HistoricMemoryCategoryInfo(unsigned category, uint32_t argb, String name, bool subcategory = false)
: name(WTFMove(name))
, isSubcategory(subcategory)
, type(category)
{
float r, g, b, a;
- Color(rgba).getRGBA(r, g, b, a);
+ Color { SimpleColor { argb } }.getRGBA(r, g, b, a);
color = adoptCF(createColor(r, g, b, a));
}
Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/Color.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-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
@@ -37,18 +37,9 @@
namespace WebCore {
-#if !COMPILER(MSVC)
-const RGBA32 Color::black;
-const RGBA32 Color::white;
-const RGBA32 Color::darkGray;
-const RGBA32 Color::gray;
-const RGBA32 Color::lightGray;
-const RGBA32 Color::transparent;
-#endif
+static constexpr SimpleColor lightenedBlack { 0xFF545454 };
+static constexpr SimpleColor darkenedWhite { 0xFFABABAB };
-static const RGBA32 lightenedBlack = 0xFF545454;
-static const RGBA32 darkenedWhite = 0xFFABABAB;
-
static inline unsigned premultipliedChannel(unsigned c, unsigned a, bool ceiling = true)
{
return fastDivideBy255(ceiling ? c * a + 254 : c * a);
@@ -61,12 +52,12 @@
RGBA32 makeRGB(int r, int g, int b)
{
- return 0xFF000000 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
+ return makeRGBA(r, g, b, 0xFF);
}
RGBA32 makeRGBA(int r, int g, int b, int a)
{
- return std::max(0, std::min(a, 255)) << 24 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
+ return { static_cast<unsigned>(std::max(0, std::min(a, 0xFF)) << 24 | std::max(0, std::min(r, 0xFF)) << 16 | std::max(0, std::min(g, 0xFF)) << 8 | std::max(0, std::min(b, 0xFF))) };
}
RGBA32 makePremultipliedRGBA(int r, int g, int b, int a, bool ceiling)
@@ -87,14 +78,12 @@
RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a)
{
- return colorFloatToRGBAByte(a) << 24 | colorFloatToRGBAByte(r) << 16 | colorFloatToRGBAByte(g) << 8 | colorFloatToRGBAByte(b);
+ return makeRGBA(colorFloatToRGBAByte(r), colorFloatToRGBAByte(g), colorFloatToRGBAByte(b), colorFloatToRGBAByte(a));
}
RGBA32 colorWithOverrideAlpha(RGBA32 color, float overrideAlpha)
{
- RGBA32 rgbOnly = color & 0x00FFFFFF;
- RGBA32 rgba = rgbOnly | colorFloatToRGBAByte(overrideAlpha) << 24;
- return rgba;
+ return { (color.value() & 0x00FFFFFF) | colorFloatToRGBAByte(overrideAlpha) << 24 };
}
RGBA32 makeRGBAFromHSLA(float hue, float saturation, float lightness, float alpha)
@@ -131,28 +120,28 @@
value |= toASCIIHexValue(name[i]);
}
if (length == 6) {
- rgb = 0xFF000000 | value;
+ rgb = { 0xFF000000 | value };
return true;
}
if (length == 8) {
// We parsed the values into RGBA order, but the RGBA32 type
// expects them to be in ARGB order, so we right rotate eight bits.
- rgb = value << 24 | value >> 8;
+ rgb = { value << 24 | value >> 8 };
return true;
}
if (length == 4) {
// #abcd converts to ddaabbcc in RGBA32.
- rgb = (value & 0xF) << 28 | (value & 0xF) << 24
+ rgb = { (value & 0xF) << 28 | (value & 0xF) << 24
| (value & 0xF000) << 8 | (value & 0xF000) << 4
| (value & 0xF00) << 4 | (value & 0xF00)
- | (value & 0xF0) | (value & 0xF0) >> 4;
+ | (value & 0xF0) | (value & 0xF0) >> 4 };
return true;
}
// #abc converts to #aabbcc
- rgb = 0xFF000000
+ rgb = { 0xFF000000
| (value & 0xF00) << 12 | (value & 0xF00) << 8
| (value & 0xF0) << 8 | (value & 0xF0) << 4
- | (value & 0xF) << 4 | (value & 0xF);
+ | (value & 0xF) << 4 | (value & 0xF) };
return true;
}
@@ -169,7 +158,6 @@
bool Color::parseHexColor(const String& name, RGBA32& rgb)
{
unsigned length = name.length();
-
if (!length)
return false;
if (name.is8Bit())
@@ -236,26 +224,18 @@
setRGB(color);
} else {
if (auto* foundColor = findNamedColor(name))
- setRGB(foundColor->ARGBValue);
- else
- m_colorData.rgbaAndFlags = invalidRGBAColor;
+ setRGB({ foundColor->ARGBValue });
}
}
Color::Color(const char* name)
{
- RGBA32 color;
- bool valid;
- if (name[0] == '#')
- valid = parseHexColor((String)&name[1], color);
- else {
- const NamedColor* foundColor = findColor(name, strlen(name));
- color = foundColor ? foundColor->ARGBValue : 0;
- valid = foundColor;
- }
-
- if (valid)
- setRGB(color);
+ if (name[0] == '#') {
+ SimpleColor color;
+ if (parseHexColor(reinterpret_cast<const LChar*>(&name[1]), std::strlen(&name[1]), color))
+ setRGB(color);
+ } else if (auto* foundColor = findColor(name, strlen(name)))
+ setRGB({ foundColor->ARGBValue });
}
Color::Color(const Color& other)
@@ -309,15 +289,18 @@
return *this;
}
+String SimpleColor::serializationForHTML() const
+{
+ if (isOpaque())
+ return makeString('#', hex(redComponent(), 2, Lowercase), hex(greenComponent(), 2, Lowercase), hex(blueComponent(), 2, Lowercase));
+ return serializationForCSS();
+}
+
String Color::serialized() const
{
if (isExtended())
return asExtended().cssText();
-
- if (isOpaque())
- return makeString('#', hex(red(), 2, Lowercase), hex(green(), 2, Lowercase), hex(blue(), 2, Lowercase));
-
- return cssText();
+ return rgb().serializationForHTML();
}
static char decimalDigit(unsigned number)
@@ -326,7 +309,7 @@
return '0' + number;
}
-static std::array<char, 4> serializedFractionDigitsForFractionalAlphaValue(uint8_t alpha)
+static std::array<char, 4> fractionDigitsForFractionalAlphaValue(uint8_t alpha)
{
ASSERT(alpha > 0);
ASSERT(alpha < 0xFF);
@@ -337,27 +320,36 @@
return { { decimalDigit((alpha * 10 + 0x7F) / 0xFF), '\0', '\0', '\0' } };
}
-String Color::cssText() const
+String SimpleColor::serializationForCSS() const
{
- if (isExtended())
- return asExtended().cssText();
- uint8_t alpha = this->alpha();
- switch (alpha) {
+ switch (alphaComponent()) {
case 0:
- return makeString("rgba(", red(), ", ", green(), ", ", blue(), ", 0)");
+ return makeString("rgba(", redComponent(), ", ", greenComponent(), ", ", blueComponent(), ", 0)");
case 0xFF:
- return makeString("rgb(", red(), ", ", green(), ", ", blue(), ')');
+ return makeString("rgb(", redComponent(), ", ", greenComponent(), ", ", blueComponent(), ')');
default:
- return makeString("rgba(", red(), ", ", green(), ", ", blue(), ", 0.", serializedFractionDigitsForFractionalAlphaValue(alpha).data(), ')');
+ return makeString("rgba(", redComponent(), ", ", greenComponent(), ", ", blueComponent(), ", 0.", fractionDigitsForFractionalAlphaValue(alphaComponent()).data(), ')');
}
}
+String Color::cssText() const
+{
+ if (isExtended())
+ return asExtended().cssText();
+ return rgb().serializationForCSS();
+}
+
+String RGBA32::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));
+}
+
String Color::nameForRenderTreeAsText() const
{
- // FIXME: Handle ExtendedColors.
- 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));
+ // FIXME: Handle extended colors.
+ return rgb().serializationForRenderTreeAsText();
}
Color Color::light() const
@@ -575,10 +567,9 @@
Color colorFromPremultipliedARGB(RGBA32 pixelColor)
{
- int alpha = alphaChannel(pixelColor);
- if (alpha && alpha < 255)
- pixelColor = makeUnPremultipliedRGBA(redChannel(pixelColor), greenChannel(pixelColor), blueChannel(pixelColor), alpha);
- return Color(pixelColor);
+ if (pixelColor.isVisible() && !pixelColor.isOpaque())
+ return makeUnPremultipliedRGBA(pixelColor.redComponent(), pixelColor.greenComponent(), pixelColor.blueComponent(), pixelColor.alphaComponent());
+ return pixelColor;
}
RGBA32 premultipliedARGBFromColor(const Color& color)
@@ -603,10 +594,9 @@
return Color();
if (blendPremultiplied) {
- // Contrary to the name, RGBA32 actually stores ARGB, so we can initialize Color directly from premultipliedARGBFromColor().
- // Also, premultipliedARGBFromColor() bails on zero alpha, so special-case that.
- Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : 0;
- Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : 0;
+ // Since premultipliedARGBFromColor() bails on zero alpha, special-case that.
+ Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : Color::transparent;
+ Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : Color::transparent;
Color premultBlended(blend(premultFrom.red(), premultTo.red(), progress),
blend(premultFrom.green(), premultTo.green(), progress),
Modified: trunk/Source/WebCore/platform/graphics/Color.h (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/Color.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/Color.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-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
@@ -52,14 +52,38 @@
typedef struct _GdkRGBA GdkRGBA;
#endif
-namespace WTF {
-class TextStream;
-}
-
namespace WebCore {
-typedef unsigned RGBA32; // Deprecated: Type for an RGBA quadruplet. Use RGBA class instead.
+// Color value with 8-bit components for red, green, blue, and alpha.
+// For historical reasons, stored as a 32-bit integer, with alpha in the high bits: ARGB.
+class SimpleColor {
+public:
+ constexpr SimpleColor(uint32_t value = 0) : m_value { value } { }
+ constexpr uint32_t value() const { return m_value; }
+
+ constexpr uint8_t redComponent() const { return m_value >> 16; }
+ constexpr uint8_t greenComponent() const { return m_value >> 8; }
+ constexpr uint8_t blueComponent() const { return m_value; }
+ constexpr uint8_t alphaComponent() const { return m_value >> 24; }
+
+ constexpr bool isOpaque() const { return alphaComponent() == 0xFF; }
+ constexpr bool isVisible() const { return alphaComponent(); }
+
+ String serializationForHTML() const;
+ String serializationForCSS() const;
+ String serializationForRenderTreeAsText() const;
+
+private:
+ uint32_t m_value { 0 };
+};
+
+bool operator==(SimpleColor, SimpleColor);
+bool operator!=(SimpleColor, SimpleColor);
+
+// FIXME: Remove this after migrating to the new name.
+using RGBA32 = SimpleColor;
+
WEBCORE_EXPORT RGBA32 makeRGB(int r, int g, int b);
WEBCORE_EXPORT RGBA32 makeRGBA(int r, int g, int b, int a);
@@ -73,36 +97,9 @@
RGBA32 makeRGBAFromHSLA(float h, float s, float l, float a);
RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a);
-inline int redChannel(RGBA32 color) { return (color >> 16) & 0xFF; }
-inline int greenChannel(RGBA32 color) { return (color >> 8) & 0xFF; }
-inline int blueChannel(RGBA32 color) { return color & 0xFF; }
-inline int alphaChannel(RGBA32 color) { return (color >> 24) & 0xFF; }
-
uint8_t roundAndClampColorChannel(int);
uint8_t roundAndClampColorChannel(float);
-class RGBA {
-public:
- RGBA(); // all channels zero, including alpha
- RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
- RGBA(uint8_t red, uint8_t green, uint8_t blue); // opaque, alpha of 1
-
- uint8_t red() const;
- uint8_t green() const;
- uint8_t blue() const;
- uint8_t alpha() const;
-
- bool hasAlpha() const;
-
-private:
- friend class Color;
-
- unsigned m_integer { 0 };
-};
-
-bool operator==(const RGBA&, const RGBA&);
-bool operator!=(const RGBA&, const RGBA&);
-
class Color {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -117,7 +114,6 @@
}
enum SemanticTag { Semantic };
-
Color(RGBA32 color, SemanticTag)
{
setRGB(color);
@@ -175,7 +171,6 @@
// 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&);
WEBCORE_EXPORT Color(Color&&);
@@ -185,17 +180,6 @@
m_colorData.extendedColor->deref();
}
- static Color createUnchecked(int r, int g, int b)
- {
- RGBA32 color = 0xFF000000 | r << 16 | g << 8 | b;
- return Color(color);
- }
- static Color createUnchecked(int r, int g, int b, int a)
- {
- RGBA32 color = a << 24 | r << 16 | g << 8 | b;
- return Color(color);
- }
-
// 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;
@@ -207,15 +191,15 @@
bool isValid() const { return isExtended() || (m_colorData.rgbaAndFlags & validRGBAColorBit); }
- bool isOpaque() const { return isValid() && (isExtended() ? asExtended().alpha() == 1.0 : alpha() == 255); }
- bool isVisible() const { return isValid() && (isExtended() ? asExtended().alpha() > 0.0 : alpha() > 0); }
+ bool isOpaque() const { return isExtended() ? asExtended().alpha() == 1.0 : rgb().isOpaque(); }
+ bool isVisible() const { return isExtended() ? asExtended().alpha() > 0.0 : rgb().isVisible(); }
- int red() const { return redChannel(rgb()); }
- int green() const { return greenChannel(rgb()); }
- int blue() const { return blueChannel(rgb()); }
- int alpha() const { return alphaChannel(rgb()); }
+ int red() const { return rgb().redComponent(); }
+ int green() const { return rgb().greenComponent(); }
+ int blue() const { return rgb().blueComponent(); }
+ int alpha() const { return rgb().alphaComponent(); }
- float alphaAsFloat() const { return isExtended() ? asExtended().alpha() : static_cast<float>(alphaChannel(rgb())) / 255; }
+ float alphaAsFloat() const { return isExtended() ? asExtended().alpha() : static_cast<float>(rgb().alphaComponent()) / 0xFF; }
RGBA32 rgb() const;
@@ -269,19 +253,19 @@
static bool parseHexColor(const LChar*, unsigned, RGBA32&);
static bool parseHexColor(const UChar*, unsigned, RGBA32&);
- static const RGBA32 black = 0xFF000000;
- WEBCORE_EXPORT static const RGBA32 white = 0xFFFFFFFF;
- static const RGBA32 darkGray = 0xFF808080;
- static const RGBA32 gray = 0xFFA0A0A0;
- static const RGBA32 lightGray = 0xFFC0C0C0;
- WEBCORE_EXPORT static const RGBA32 transparent = 0x00000000;
- static const RGBA32 cyan = 0xFF00FFFF;
- static const RGBA32 yellow = 0xFFFFFF00;
+ static constexpr SimpleColor black { 0xFF000000 };
+ static constexpr SimpleColor white { 0xFFFFFFFF };
+ static constexpr SimpleColor darkGray { 0xFF808080 };
+ static constexpr SimpleColor gray { 0xFFA0A0A0 };
+ static constexpr SimpleColor lightGray { 0xFFC0C0C0 };
+ static constexpr SimpleColor transparent { 0x00000000 };
+ static constexpr SimpleColor cyan { 0xFF00FFFF };
+ static constexpr SimpleColor yellow { 0xFFFFFF00 };
#if PLATFORM(IOS_FAMILY)
- static const RGBA32 compositionFill = 0x3CAFC0E3;
+ static constexpr SimpleColor compositionFill { 0x3CAFC0E3 };
#else
- static const RGBA32 compositionFill = 0xFFE1DD55;
+ static constexpr SimpleColor compositionFill { 0xFFE1DD55 };
#endif
bool isExtended() const
@@ -343,51 +327,19 @@
WEBCORE_EXPORT CGColorRef cachedCGColor(const Color&);
#endif
-inline RGBA::RGBA()
-{
-}
+WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const Color&);
+WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace);
-inline RGBA::RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
- : m_integer(alpha << 24 | red << 16 | green << 8 | blue)
+inline bool operator==(SimpleColor a, SimpleColor b)
{
+ return a.value() == b.value();
}
-inline RGBA::RGBA(uint8_t red, uint8_t green, uint8_t blue)
- : m_integer(0xFF000000 | red << 16 | green << 8 | blue)
+inline bool operator!=(SimpleColor a, SimpleColor b)
{
+ return !(a == b);
}
-inline uint8_t RGBA::red() const
-{
- return m_integer >> 16;
-}
-
-inline uint8_t RGBA::green() const
-{
- return m_integer >> 8;
-}
-
-inline uint8_t RGBA::blue() const
-{
- return m_integer;
-}
-
-inline uint8_t RGBA::alpha() const
-{
- return m_integer >> 24;
-}
-
-inline bool RGBA::hasAlpha() const
-{
- return (m_integer & 0xFF000000) != 0xFF000000;
-}
-
-inline Color::Color(RGBA color, ColorSpace space)
-{
- setRGB(color.m_integer);
- ASSERT_UNUSED(space, space == ColorSpace::SRGB);
-}
-
inline bool operator==(const Color& a, const Color& b)
{
return a.m_colorData.rgbaAndFlags == b.m_colorData.rgbaAndFlags;
@@ -437,12 +389,12 @@
// FIXME: We should ASSERT(!isExtended()) here, or produce
// an RGBA32 equivalent for an ExtendedColor. Ideally the former,
// so we can audit all the rgb() call sites to handle extended.
- return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32);
+ return { static_cast<uint32_t>(m_colorData.rgbaAndFlags >> 32) };
}
inline void Color::setRGB(RGBA32 rgb)
{
- m_colorData.rgbaAndFlags = static_cast<uint64_t>(rgb) << 32;
+ m_colorData.rgbaAndFlags = static_cast<uint64_t>(rgb.value()) << 32;
tagAsValid();
}
@@ -453,7 +405,7 @@
return !extendedColor.red() && !extendedColor.green() && !extendedColor.blue() && extendedColor.alpha() == 1;
}
- return color.isValid() && color.rgb() == Color::black;
+ return color.rgb() == Color::black;
}
inline bool Color::isWhiteColor(const Color& color)
@@ -463,12 +415,9 @@
return extendedColor.red() == 1 && extendedColor.green() == 1 && extendedColor.blue() == 1 && extendedColor.alpha() == 1;
}
- return color.isValid() && color.rgb() == Color::white;
+ return color.rgb() == Color::white;
}
-WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const Color&);
-WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace);
-
} // namespace WebCore
namespace WTF {
Modified: trunk/Source/WebCore/platform/graphics/ImageBackingStore.h (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/ImageBackingStore.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/ImageBackingStore.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -60,7 +60,7 @@
return false;
Vector<char> buffer;
- size_t bufferSize = size.area().unsafeGet() * sizeof(RGBA32);
+ size_t bufferSize = size.area().unsafeGet() * sizeof(uint32_t);
if (!buffer.tryReserveCapacity(bufferSize))
return false;
@@ -67,7 +67,7 @@
buffer.grow(bufferSize);
m_pixels = SharedBuffer::DataSegment::create(WTFMove(buffer));
- m_pixelsPtr = reinterpret_cast<RGBA32*>(const_cast<char*>(m_pixels->data()));
+ m_pixelsPtr = reinterpret_cast<uint32_t*>(const_cast<char*>(m_pixels->data()));
m_size = size;
m_frameRect = IntRect(IntPoint(), m_size);
clear();
@@ -86,7 +86,7 @@
void clear()
{
- memset(m_pixelsPtr, 0, (m_size.area() * sizeof(RGBA32)).unsafeGet());
+ memset(m_pixelsPtr, 0, (m_size.area() * sizeof(uint32_t)).unsafeGet());
}
void clearRect(const IntRect& rect)
@@ -94,8 +94,8 @@
if (rect.isEmpty() || !inBounds(rect))
return;
- size_t rowBytes = rect.width() * sizeof(RGBA32);
- RGBA32* start = pixelAt(rect.x(), rect.y());
+ size_t rowBytes = rect.width() * sizeof(uint32_t);
+ uint32_t* start = pixelAt(rect.x(), rect.y());
for (int i = 0; i < rect.height(); ++i) {
memset(start, 0, rowBytes);
start += m_size.width();
@@ -107,8 +107,8 @@
if (rect.isEmpty() || !inBounds(rect))
return;
- RGBA32* start = pixelAt(rect.x(), rect.y());
- RGBA32 pixelValue = this->pixelValue(r, g, b, a);
+ uint32_t* start = pixelAt(rect.x(), rect.y());
+ uint32_t pixelValue = this->pixelValue(r, g, b, a);
for (int i = 0; i < rect.height(); ++i) {
for (int j = 0; j < rect.width(); ++j)
start[j] = pixelValue;
@@ -121,9 +121,9 @@
if (rect.isEmpty() || !inBounds(rect))
return;
- size_t rowBytes = rect.width() * sizeof(RGBA32);
- RGBA32* src = "" rect.y());
- RGBA32* dest = src + m_size.width();
+ size_t rowBytes = rect.width() * sizeof(uint32_t);
+ uint32_t* src = "" rect.y());
+ uint32_t* dest = src + m_size.width();
for (int i = 1; i < rect.height(); ++i) {
memcpy(dest, src, rowBytes);
dest += m_size.width();
@@ -130,13 +130,13 @@
}
}
- RGBA32* pixelAt(int x, int y) const
+ uint32_t* pixelAt(int x, int y) const
{
ASSERT(inBounds(IntPoint(x, y)));
return m_pixelsPtr + y * m_size.width() + x;
}
- void setPixel(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
+ void setPixel(uint32_t* dest, unsigned r, unsigned g, unsigned b, unsigned a)
{
ASSERT(dest);
*dest = pixelValue(r, g, b, a);
@@ -147,30 +147,32 @@
setPixel(pixelAt(x, y), r, g, b, a);
}
- void blendPixel(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
+ void blendPixel(uint32_t* dest, unsigned r, unsigned g, unsigned b, unsigned a)
{
if (!a)
return;
- if (a >= 255 || !alphaChannel(*dest)) {
+ SimpleColor pixel { *dest };
+
+ if (a >= 255 || !pixel.isVisible()) {
setPixel(dest, r, g, b, a);
return;
}
if (!m_premultiplyAlpha)
- *dest = makePremultipliedRGBA(redChannel(*dest), greenChannel(*dest), blueChannel(*dest), alphaChannel(*dest), false);
+ pixel = makePremultipliedRGBA(pixel.redComponent(), pixel.greenComponent(), pixel.blueComponent(), pixel.alphaComponent(), false);
unsigned d = 255 - a;
- r = fastDivideBy255(r * a + redChannel(*dest) * d);
- g = fastDivideBy255(g * a + greenChannel(*dest) * d);
- b = fastDivideBy255(b * a + blueChannel(*dest) * d);
- a += fastDivideBy255(d * alphaChannel(*dest));
+ r = fastDivideBy255(r * a + pixel.redComponent() * d);
+ g = fastDivideBy255(g * a + pixel.greenComponent() * d);
+ b = fastDivideBy255(b * a + pixel.blueComponent() * d);
+ a += fastDivideBy255(d * pixel.alphaComponent());
if (m_premultiplyAlpha)
- *dest = makeRGBA(r, g, b, a);
+ *dest = makeRGBA(r, g, b, a).value();
else
- *dest = makeUnPremultipliedRGBA(r, g, b, a);
+ *dest = makeUnPremultipliedRGBA(r, g, b, a).value();
}
static bool isOverSize(const IntSize& size)
@@ -204,7 +206,7 @@
Vector<char> buffer;
buffer.append(other.m_pixels->data(), other.m_pixels->size());
m_pixels = SharedBuffer::DataSegment::create(WTFMove(buffer));
- m_pixelsPtr = reinterpret_cast<RGBA32*>(const_cast<char*>(m_pixels->data()));
+ m_pixelsPtr = reinterpret_cast<uint32_t*>(const_cast<char*>(m_pixels->data()));
}
bool inBounds(const IntPoint& point) const
@@ -217,19 +219,19 @@
return IntRect(IntPoint(), m_size).contains(rect);
}
- RGBA32 pixelValue(unsigned r, unsigned g, unsigned b, unsigned a) const
+ uint32_t pixelValue(unsigned r, unsigned g, unsigned b, unsigned a) const
{
if (m_premultiplyAlpha && !a)
return 0;
if (m_premultiplyAlpha && a < 255)
- return makePremultipliedRGBA(r, g, b, a, false);
+ return makePremultipliedRGBA(r, g, b, a, false).value();
- return makeRGBA(r, g, b, a);
+ return makeRGBA(r, g, b, a).value();
}
RefPtr<SharedBuffer::DataSegment> m_pixels;
- RGBA32* m_pixelsPtr { nullptr };
+ uint32_t* m_pixelsPtr { nullptr };
IntSize m_size;
IntRect m_frameRect; // This will always just be the entire buffer except for GIF and PNG frames
bool m_premultiplyAlpha { true };
Modified: trunk/Source/WebCore/platform/graphics/ImageFrame.h (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/ImageFrame.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/ImageFrame.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -27,7 +27,6 @@
#include "Color.h"
#include "DecodingOptions.h"
-#include "ImageBackingStore.h"
#include "ImageOrientation.h"
#include "ImageTypes.h"
#include "IntSize.h"
Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/ImageSource.h 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h 2020-02-05 03:47:15 UTC (rev 255785)
@@ -40,6 +40,7 @@
class BitmapImage;
class GraphicsContext;
class ImageDecoder;
+class SharedBuffer;
class ImageSource : public ThreadSafeRefCounted<ImageSource>, public CanMakeWeakPtr<ImageSource> {
friend class BitmapImage;
Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -398,7 +398,7 @@
lookUpTable[pixelColor.green()],
lookUpTable[pixelColor.blue()],
pixelColor.alpha());
- *pixel = premultipliedARGBFromColor(pixelColor);
+ *pixel = premultipliedARGBFromColor(pixelColor).value();
}
}
cairo_surface_mark_dirty_rectangle(m_data.m_surface.get(), 0, 0, m_logicalSize.width(), m_logicalSize.height());
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -128,16 +128,16 @@
CGColorRef cachedCGColor(const Color& color)
{
if (!color.isExtended()) {
- switch (color.rgb()) {
- case Color::transparent: {
+ switch (color.rgb().value()) {
+ case Color::transparent.value(): {
static CGColorRef transparentCGColor = leakCGColor(color);
return transparentCGColor;
}
- case Color::black: {
+ case Color::black.value(): {
static CGColorRef blackCGColor = leakCGColor(color);
return blackCGColor;
}
- case Color::white: {
+ case Color::white.value(): {
static CGColorRef whiteCGColor = leakCGColor(color);
return whiteCGColor;
}
@@ -144,7 +144,7 @@
}
}
- ASSERT(color.isExtended() || color.rgb());
+ ASSERT(color.isExtended() || color.rgb().value());
static NeverDestroyed<TinyLRUCache<Color, RetainPtr<CGColorRef>, 32>> cache;
return cache.get().get(color).get();
Modified: trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm 2020-02-05 03:47:15 UTC (rev 255785)
@@ -40,7 +40,7 @@
Color oldAquaFocusRingColor()
{
- return 0xFF7DADD9;
+ return SimpleColor { 0xFF7DADD9 };
}
void setUsesTestModeFocusRingColor(bool newValue)
Modified: trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -42,7 +42,7 @@
{
float colorAlpha = alpha() / 255.0f;
- return D2D1::ColorF(rgb(), colorAlpha);
+ return D2D1::ColorF(rgb().value(), colorAlpha);
}
Color::operator D2D1_VECTOR_4F() const
Modified: trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -511,7 +511,7 @@
}
} else {
for (int x = 0; x < width; ++x, pixel += 3, ++address)
- *address = makeRGB(pixel[0], pixel[1], pixel[2]);
+ *address = 0xFF000000 | pixel[0] << 16 | pixel[1] << 8 | pixel[2];
}
if (nonTrivialAlphaMask && !buffer.hasAlpha())
Modified: trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -83,8 +83,8 @@
MockMediaDevice { "SCREEN-1"_s, "Mock screen device 1"_s, MockDisplayProperties { CaptureDevice::DeviceType::Screen, Color::lightGray, { 3840, 2160 } } },
MockMediaDevice { "SCREEN-2"_s, "Mock screen device 2"_s, MockDisplayProperties { CaptureDevice::DeviceType::Screen, Color::yellow, { 1920, 1080 } } },
- MockMediaDevice { "WINDOW-2"_s, "Mock window 1"_s, MockDisplayProperties { CaptureDevice::DeviceType::Screen, 0xfff1b5, { 640, 480 } } },
- MockMediaDevice { "WINDOW-2"_s, "Mock window 2"_s, MockDisplayProperties { CaptureDevice::DeviceType::Screen, 0xffd0b5, { 1280, 600 } } },
+ MockMediaDevice { "WINDOW-2"_s, "Mock window 1"_s, MockDisplayProperties { CaptureDevice::DeviceType::Screen, SimpleColor { 0xfff1b5 }, { 640, 480 } } },
+ MockMediaDevice { "WINDOW-2"_s, "Mock window 2"_s, MockDisplayProperties { CaptureDevice::DeviceType::Screen, SimpleColor { 0xffd0b5 }, { 1280, 600 } } },
};
}
Modified: trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -262,12 +262,10 @@
void MockRealtimeVideoSource::drawBoxes(GraphicsContext& context)
{
- static const RGBA32 magenta = 0xffff00ff;
- static const RGBA32 yellow = 0xffffff00;
- static const RGBA32 blue = 0xff0000ff;
- static const RGBA32 red = 0xffff0000;
- static const RGBA32 green = 0xff008000;
- static const RGBA32 cyan = 0xFF00FFFF;
+ constexpr SimpleColor magenta { 0xffff00ff };
+ constexpr SimpleColor blue { 0xff0000ff };
+ constexpr SimpleColor red { 0xffff0000 };
+ constexpr SimpleColor darkGreen { 0xff008000 };
IntSize size = captureSize();
float boxSize = size.width() * .035;
@@ -317,9 +315,9 @@
boxTop += boxSize + 2;
boxLeft = boxSize;
- 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]);
+ constexpr SimpleColor boxColors[] = { Color::white, Color::yellow, Color::cyan, darkGreen, magenta, red, blue };
+ for (auto& boxColor : boxColors) {
+ context.fillRect(FloatRect(boxLeft, boxTop, boxSize + 1, boxSize + 1), boxColor);
boxLeft += boxSize + 1;
}
context.strokePath(m_path);
Modified: trunk/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp (255784 => 255785)
--- trunk/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -46,7 +46,7 @@
void ScrollbarThemeMock::paintTrackBackground(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& trackRect)
{
- context.fillRect(trackRect, scrollbar.enabled() ? Color::lightGray : Color(0xFFE0E0E0));
+ context.fillRect(trackRect, scrollbar.enabled() ? Color::lightGray : SimpleColor { 0xFFE0E0E0 });
}
void ScrollbarThemeMock::paintThumb(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& thumbRect)
Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (255784 => 255785)
--- trunk/Source/WebCore/rendering/RenderObject.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1837,9 +1837,11 @@
void RenderObject::calculateBorderStyleColor(const BorderStyle& style, const BoxSide& side, Color& color)
{
ASSERT(style == BorderStyle::Inset || style == BorderStyle::Outset);
+
// This values were derived empirically.
- const RGBA32 baseDarkColor = 0xFF202020;
- const RGBA32 baseLightColor = 0xFFEBEBEB;
+ constexpr SimpleColor baseDarkColor { 0xFF202020 };
+ constexpr SimpleColor baseLightColor { 0xFFEBEBEB };
+
enum Operation { Darken, Lighten };
Operation operation = (side == BSTop || side == BSLeft) == (style == BorderStyle::Inset) ? Darken : Lighten;
Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (255784 => 255785)
--- trunk/Source/WebCore/rendering/RenderTheme.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1285,73 +1285,72 @@
{
switch (cssValueId) {
case CSSValueWebkitLink:
- return options.contains(StyleColor::Options::ForVisitedLink) ? 0xFF551A8B : 0xFF0000EE;
+ return options.contains(StyleColor::Options::ForVisitedLink) ? SimpleColor { 0xFF551A8B } : SimpleColor { 0xFF0000EE };
case CSSValueWebkitActivelink:
- return 0xFFFF0000;
+ return SimpleColor { 0xFFFF0000 };
case CSSValueActiveborder:
- return 0xFFFFFFFF;
+ return Color::white;
case CSSValueActivebuttontext:
- return 0xFF000000;
+ return Color::black;
case CSSValueActivecaption:
- return 0xFFCCCCCC;
+ return SimpleColor { 0xFFCCCCCC };
case CSSValueAppworkspace:
- return 0xFFFFFFFF;
+ return Color::white;
case CSSValueBackground:
- return 0xFF6363CE;
+ return SimpleColor { 0xFF6363CE };
case CSSValueButtonface:
- return 0xFFC0C0C0;
+ return Color::lightGray;
case CSSValueButtonhighlight:
- return 0xFFDDDDDD;
+ return SimpleColor { 0xFFDDDDDD };
case CSSValueButtonshadow:
- return 0xFF888888;
+ return SimpleColor { 0xFF888888 };
case CSSValueButtontext:
- return 0xFF000000;
+ return Color::black;
case CSSValueCaptiontext:
- return 0xFF000000;
+ return Color::black;
case CSSValueGraytext:
- return 0xFF808080;
+ return SimpleColor { 0xFF808080 };
case CSSValueHighlight:
- return 0xFFB5D5FF;
+ return SimpleColor { 0xFFB5D5FF };
case CSSValueHighlighttext:
- return 0xFF000000;
+ return Color::black;
case CSSValueInactiveborder:
- return 0xFFFFFFFF;
+ return Color::white;
case CSSValueInactivecaption:
- return 0xFFFFFFFF;
+ return Color::white;
case CSSValueInactivecaptiontext:
- return 0xFF7F7F7F;
+ return SimpleColor { 0xFF7F7F7F };
case CSSValueInfobackground:
- return 0xFFFBFCC5;
+ return SimpleColor { 0xFFFBFCC5 };
case CSSValueInfotext:
- return 0xFF000000;
+ return Color::black;
case CSSValueMenu:
- return 0xFFC0C0C0;
+ return Color::lightGray;
case CSSValueMenutext:
- return 0xFF000000;
+ return Color::black;
case CSSValueScrollbar:
- return 0xFFFFFFFF;
+ return Color::white;
case CSSValueText:
- return 0xFF000000;
+ return Color::black;
case CSSValueThreeddarkshadow:
- return 0xFF666666;
+ return SimpleColor { 0xFF666666 };
case CSSValueThreedface:
- return 0xFFC0C0C0;
+ return Color::lightGray;
case CSSValueThreedhighlight:
- return 0xFFDDDDDD;
+ return SimpleColor { 0xFFDDDDDD };
case CSSValueThreedlightshadow:
- return 0xFFC0C0C0;
+ return Color::lightGray;
case CSSValueThreedshadow:
- return 0xFF888888;
+ return SimpleColor { 0xFF888888 };
case CSSValueWindow:
- return 0xFFFFFFFF;
+ return Color::white;
case CSSValueWindowframe:
- return 0xFFCCCCCC;
+ return SimpleColor { 0xFFCCCCCC };
case CSSValueWindowtext:
- return 0xFF000000;
+ return Color::black;
default:
- break;
+ return { };
}
- return Color();
}
Color RenderTheme::activeTextSearchHighlightColor(OptionSet<StyleColor::Options> options) const
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (255784 => 255785)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2020-02-05 03:47:15 UTC (rev 255785)
@@ -819,11 +819,11 @@
case CSSValueThreedface:
// We selected this value instead of [NSColor controlColor] to avoid website incompatibilities.
// We may want to consider changing to [NSColor controlColor] some day.
- return 0xFFC0C0C0;
+ return SimpleColor { 0xFFC0C0C0 };
case CSSValueInfobackground:
// No corresponding NSColor for this so we use a hard coded value.
- return 0xFFFBFCC5;
+ return SimpleColor { 0xFFFBFCC5 };
case CSSValueMenu:
return menuBackgroundColor();
@@ -832,30 +832,30 @@
case CSSValueActiveborder:
// Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
if (localAppearance.usingDarkAppearance())
- return Color(0xFF1AA9FF, Color::Semantic);
- return Color(0xFF0067F4, Color::Semantic);
+ return { SimpleColor { 0xFF1AA9FF }, Color::Semantic };
+ return { SimpleColor { 0xFF0067F4 }, Color::Semantic };
case CSSValueAppleSystemControlAccent:
// Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
// Same color in light and dark appearances.
- return Color(0xFF007AFF, Color::Semantic);
+ return { SimpleColor { 0xFF007AFF }, Color::Semantic };
case CSSValueAppleSystemSelectedContentBackground:
// Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
if (localAppearance.usingDarkAppearance())
- return Color(0xFF0058D0, Color::Semantic);
- return Color(0xFF0063E1, Color::Semantic);
+ return { SimpleColor { 0xFF0058D0 }, Color::Semantic };
+ return { SimpleColor { 0xFF0063E1 }, Color::Semantic };
case CSSValueHighlight:
case CSSValueAppleSystemSelectedTextBackground:
// Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
if (localAppearance.usingDarkAppearance())
- return Color(0xCC3F638B, Color::Semantic);
- return Color(0x9980BCFE, Color::Semantic);
+ return { SimpleColor { 0xCC3F638B }, Color::Semantic };
+ return { SimpleColor { 0x9980BCFE }, Color::Semantic };
#if !HAVE(OS_DARK_MODE_SUPPORT)
case CSSValueAppleSystemContainerBorder:
- return 0xFFC5C5C5;
+ return SimpleColor { 0xFFC5C5C5 };
#endif
case CSSValueAppleSystemEvenAlternatingContentBackground: {
Modified: trunk/Source/WebCore/rendering/RenderTreeAsText.cpp (255784 => 255785)
--- trunk/Source/WebCore/rendering/RenderTreeAsText.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebCore/rendering/RenderTreeAsText.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -244,17 +244,17 @@
// Do not dump invalid or transparent backgrounds, since that is the default.
Color backgroundColor = o.style().visitedDependentColor(CSSPropertyBackgroundColor);
if (o.parent()->style().visitedDependentColor(CSSPropertyBackgroundColor).rgb() != backgroundColor.rgb()
- && backgroundColor.isValid() && backgroundColor.rgb())
+ && backgroundColor.rgb() != Color::transparent)
ts << " [bgcolor=" << backgroundColor.nameForRenderTreeAsText() << "]";
Color textFillColor = o.style().visitedDependentColor(CSSPropertyWebkitTextFillColor);
if (o.parent()->style().visitedDependentColor(CSSPropertyWebkitTextFillColor).rgb() != textFillColor.rgb()
- && textFillColor.isValid() && textFillColor.rgb() != color.rgb() && textFillColor.rgb())
+ && textFillColor.rgb() != color.rgb() && textFillColor.rgb() != Color::transparent)
ts << " [textFillColor=" << textFillColor.nameForRenderTreeAsText() << "]";
Color textStrokeColor = o.style().visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
if (o.parent()->style().visitedDependentColor(CSSPropertyWebkitTextStrokeColor).rgb() != textStrokeColor.rgb()
- && textStrokeColor.isValid() && textStrokeColor.rgb() != color.rgb() && textStrokeColor.rgb())
+ && textStrokeColor.rgb() != color.rgb() && textStrokeColor.rgb() != Color::transparent)
ts << " [textStrokeColor=" << textStrokeColor.nameForRenderTreeAsText() << "]";
if (o.parent()->style().textStrokeWidth() != o.style().textStrokeWidth() && o.style().textStrokeWidth() > 0)
Modified: trunk/Source/WebKit/ChangeLog (255784 => 255785)
--- trunk/Source/WebKit/ChangeLog 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebKit/ChangeLog 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,3 +1,15 @@
+2020-02-01 Darin Adler <[email protected]>
+
+ Replace RGBA32 typedef with a class to improve type safety
+ https://bugs.webkit.org/show_bug.cgi?id=206862
+
+ Reviewed by Sam Weinig.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<Color>::encode): Use uint32_t explicitly to convert
+ the color value into a SimpleColor.
+ (IPC::ArgumentCoder<Color>::decode): Same thing, only the other direction.
+
2020-02-04 Darin Adler <[email protected]>
Remove NSKeyedArchiverSPI.h now that WebKit only uses API
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (255784 => 255785)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1489,8 +1489,10 @@
return;
}
+ uint32_t value = color.rgb().value();
+
encoder << true;
- encoder << color.rgb();
+ encoder << value;
}
bool ArgumentCoder<Color>::decode(Decoder& decoder, Color& color)
@@ -1528,11 +1530,11 @@
return true;
}
- RGBA32 rgba;
- if (!decoder.decode(rgba))
+ uint32_t value;
+ if (!decoder.decode(value))
return false;
- color = Color(rgba);
+ color = SimpleColor { value };
return true;
}
Modified: trunk/Tools/ChangeLog (255784 => 255785)
--- trunk/Tools/ChangeLog 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Tools/ChangeLog 2020-02-05 03:47:15 UTC (rev 255785)
@@ -1,3 +1,13 @@
+2020-02-01 Darin Adler <[email protected]>
+
+ Replace RGBA32 typedef with a class to improve type safety
+ https://bugs.webkit.org/show_bug.cgi?id=206862
+
+ Reviewed by Sam Weinig.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/PDFSnapshot.mm:
+ (TestWebKitAPI::TEST): Use the Color constructor instead of Color::createUnchecked.
+
2020-02-04 Darin Adler <[email protected]>
Remove NSKeyedArchiverSPI.h now that WebKit only uses API
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFSnapshot.mm (255784 => 255785)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFSnapshot.mm 2020-02-05 03:45:12 UTC (rev 255784)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFSnapshot.mm 2020-02-05 03:47:15 UTC (rev 255785)
@@ -60,7 +60,7 @@
EXPECT_EQ(page->text()[4], 'o');
// The entire page should be green. Pick a point in the middle to check.
- EXPECT_TRUE(page->colorAtPoint(400, 300) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(400, 300) == Color(0, 255, 0));
didTakeSnapshot = true;
}];
@@ -91,7 +91,7 @@
EXPECT_EQ(page->characterCount(), 0u);
// The entire page should be green. Pick a point in the middle to check.
- EXPECT_TRUE(page->colorAtPoint(200, 150) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(200, 150) == Color(0, 255, 0));
didTakeSnapshot = true;
}];
@@ -111,10 +111,10 @@
EXPECT_TRUE(CGRectEqualToRect(page->bounds(), CGRectMake(0, 0, 1200, 1200)));
// A pixel that was in the view should be green. Pick a point in the middle to check.
- EXPECT_TRUE(page->colorAtPoint(200, 150) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(200, 150) == Color(0, 255, 0));
// A pixel that was outside the view should also be green (we extend background color out). Pick a point in the middle to check.
- EXPECT_TRUE(page->colorAtPoint(900, 700) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(900, 700) == Color(0, 255, 0));
didTakeSnapshot = true;
}];
@@ -140,13 +140,13 @@
auto page = document->page(0);
EXPECT_NE(page, nullptr);
EXPECT_TRUE(CGRectEqualToRect(page->bounds(), CGRectMake(0, 0, 800, 14400)));
- EXPECT_TRUE(page->colorAtPoint(400, 300) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(400, 300) == Color(0, 255, 0));
EXPECT_EQ(page->characterCount(), 5u);
page = document->page(1);
EXPECT_NE(page, nullptr);
EXPECT_TRUE(CGRectEqualToRect(page->bounds(), CGRectMake(0, 0, 800, 14400)));
- EXPECT_TRUE(page->colorAtPoint(400, 300) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(400, 300) == Color(0, 255, 0));
EXPECT_EQ(page->characterCount(), 0u);
@@ -153,7 +153,7 @@
page = document->page(2);
EXPECT_NE(page, nullptr);
EXPECT_TRUE(CGRectEqualToRect(page->bounds(), CGRectMake(0, 0, 800, 600)));
- EXPECT_TRUE(page->colorAtPoint(400, 300) == Color::createUnchecked(0, 255, 0));
+ EXPECT_TRUE(page->colorAtPoint(400, 300) == Color(0, 255, 0));
EXPECT_EQ(page->characterCount(), 0u);
didTakeSnapshot = true;
@@ -178,7 +178,7 @@
EXPECT_NE(page, nullptr);
EXPECT_TRUE(CGRectEqualToRect(page->bounds(), CGRectMake(0, 0, 800, 14400)));
- EXPECT_TRUE(page->colorAtPoint(400, 300) == Color::createUnchecked(255, 255, 255));
+ EXPECT_TRUE(page->colorAtPoint(400, 300) == Color(255, 255, 255));
EXPECT_EQ(page->characterCount(), 8u);
EXPECT_EQ(page->text()[0], 'C');