Changeset 207442 in webkit
- Timestamp:
- Oct 17, 2016 5:12:00 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207438 r207442 1 2016-10-17 Dean Jackson <dino@apple.com> 2 3 Allow creation of ExtendedColors and make Color immutable 4 https://bugs.webkit.org/show_bug.cgi?id=163557 5 <rdar://problem/28805360> 6 7 Reviewed by Darin Adler and Dave Hyatt. 8 9 1. Support the creation of ExtendedColor objects via the 10 Color class. 11 12 2. Fix the remaining few places where a Color object is 13 modified after creation, instead creating a new Color. 14 Move all the mutation methods into the private section, 15 making Color now immutable. 16 17 Changes to Color are covered by existing tests. Changes 18 to ExtendedColor are covered by the ExtendedColor API test. 19 20 * css/parser/CSSParser.cpp: 21 (WebCore::CSSParser::fastParseColor): Return a new named Color. 22 23 * dom/Document.cpp: 24 (WebCore::Document::resetActiveLinkColor): Set to be the named "red" color. 25 26 * html/HTMLElement.cpp: 27 (WebCore::HTMLElement::addHTMLColorToStyle): Use the string-based constructor 28 where possible. 29 30 * page/CaptionUserPreferencesMediaAF.cpp: 31 (WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): No need to 32 use the string "black" here - we have a constant value. 33 34 * platform/graphics/cairo/GraphicsContextCairo.cpp: Don't use setRGB. 35 36 * platform/graphics/Color.cpp: 37 (WebCore::findNamedColor): Move this up in the file. 38 (WebCore::Color::Color): Copy in the code from setNamedColor. Also 39 add a constructor for ExtendedColor. 40 (WebCore::Color::serialized): Call ExtendedColor's serializer if necessary. 41 (WebCore::Color::cssText): Ditto. 42 (WebCore::Color::setNamedColor): Deleted. 43 (WebCore::Color::tagAsExtended): Deleted. 44 45 * platform/graphics/Color.h: Add a new constructor. 46 (WebCore::Color::setRGB): Move to private. 47 48 * platform/graphics/ExtendedColor.cpp: 49 (WebCore::ExtendedColor::cssText): Implement serializer. 50 * platform/graphics/ExtendedColor.h: 51 52 * rendering/style/RenderStyle.cpp: 53 (WebCore::RenderStyle::colorIncludingFallback): Construct a new Color rather than changing an existing object. 54 1 55 2016-10-17 Simon Fraser <simon.fraser@apple.com> 2 56 -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r207396 r207442 7551 7551 7552 7552 // Try named colors. 7553 color.setNamedColor(name); 7554 return color; 7553 return Color { name }; 7555 7554 } 7556 7555 -
trunk/Source/WebCore/dom/Document.cpp
r207372 r207442 821 821 void Document::resetActiveLinkColor() 822 822 { 823 m_activeLinkColor .setNamedColor("red");823 m_activeLinkColor = Color(255, 0, 0); 824 824 } 825 825 -
trunk/Source/WebCore/html/HTMLElement.cpp
r206944 r207442 1038 1038 return; 1039 1039 1040 // If the string is a named CSS color or a 3/6-digit hex color, use that.1041 // We can't use the default Color constructor because it accepts1040 Color color; 1041 // We can't always use the default Color constructor because it accepts 1042 1042 // 4/8-digit hex, which conflict with some legacy HTML content using attributes. 1043 1044 Color color; 1045 1046 if ((colorString.length() == 4 || colorString.length() == 7) && colorString[0] == '#') 1043 if ((colorString.length() != 5 && colorString.length() != 9) || colorString[0] != '#') 1047 1044 color = Color(colorString); 1048 1045 if (!color.isValid()) 1049 color.setNamedColor(colorString); 1050 if (!color.isValid()) 1051 color.setRGB(parseColorStringWithCrazyLegacyRules(colorString)); 1046 color = Color(parseColorStringWithCrazyLegacyRules(colorString)); 1052 1047 1053 1048 style.setProperty(propertyID, CSSValuePool::singleton().createColorValue(color.rgb())); -
trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
r206830 r207442 397 397 Color color = captionsTextColor(unused); 398 398 if (!color.isValid()) 399 color .setNamedColor("black");399 color = Color { Color::black }; 400 400 color = captionsEdgeColorForTextColor(color); 401 401 -
trunk/Source/WebCore/platform/graphics/Color.cpp
r207265 r207442 223 223 } 224 224 225 static inline const NamedColor* findNamedColor(const String& name) 226 { 227 char buffer[64]; // easily big enough for the longest color name 228 unsigned length = name.length(); 229 if (length > sizeof(buffer) - 1) 230 return nullptr; 231 for (unsigned i = 0; i < length; ++i) { 232 UChar c = name[i]; 233 if (!c || !WTF::isASCII(c)) 234 return nullptr; 235 buffer[i] = toASCIILower(static_cast<char>(c)); 236 } 237 buffer[length] = '\0'; 238 return findColor(buffer, length); 239 } 240 225 241 Color::Color(const String& name) 226 242 { … … 236 252 if (valid) 237 253 setRGB(color); 238 } else 239 setNamedColor(name); 254 } else { 255 if (auto* foundColor = findNamedColor(name)) 256 setRGB(foundColor->ARGBValue); 257 else 258 m_colorData.rgbaAndFlags = invalidRGBAColor; 259 } 240 260 } 241 261 … … 268 288 } 269 289 290 Color::Color(float r, float g, float b, float a, ColorSpace colorSpace) 291 { 292 auto extendedColorRef = ExtendedColor::create(r, g, b, a, colorSpace); 293 m_colorData.extendedColor = &extendedColorRef.leakRef(); 294 ASSERT(isExtended()); 295 } 296 270 297 Color::~Color() 271 298 { … … 302 329 String Color::serialized() const 303 330 { 331 if (isExtended()) 332 return asExtended().cssText(); 333 304 334 if (!hasAlpha()) { 305 335 StringBuilder builder; … … 317 347 String Color::cssText() const 318 348 { 349 if (isExtended()) 350 return asExtended().cssText(); 351 319 352 StringBuilder builder; 320 353 builder.reserveCapacity(28); … … 351 384 return String::format("#%02X%02X%02X%02X", red(), green(), blue(), alpha()); 352 385 return String::format("#%02X%02X%02X", red(), green(), blue()); 353 }354 355 static inline const NamedColor* findNamedColor(const String& name)356 {357 char buffer[64]; // easily big enough for the longest color name358 unsigned length = name.length();359 if (length > sizeof(buffer) - 1)360 return 0;361 for (unsigned i = 0; i < length; ++i) {362 UChar c = name[i];363 if (!c || c > 0x7F)364 return 0;365 buffer[i] = toASCIILower(static_cast<char>(c));366 }367 buffer[length] = '\0';368 return findColor(buffer, length);369 }370 371 void Color::setNamedColor(const String& name)372 {373 const NamedColor* foundColor = findNamedColor(name);374 if (foundColor)375 setRGB(foundColor->ARGBValue);376 else377 m_colorData.rgbaAndFlags = invalidRGBAColor;378 386 } 379 387 … … 625 633 } 626 634 627 void Color::tagAsExtended()628 {629 // FIXME: Is this method necessary? Will colors ever change from RGBA32 to Extended?630 // Valid colors should not change type.631 ASSERT(!isValid());632 m_colorData.rgbaAndFlags &= ~(invalidRGBAColor);633 }634 635 635 bool Color::isExtended() const 636 636 { … … 638 638 } 639 639 640 ExtendedColor *Color::asExtended() const640 ExtendedColor& Color::asExtended() const 641 641 { 642 642 ASSERT(isExtended()); 643 if (!isExtended()) 644 return nullptr; 645 return m_colorData.extendedColor; 643 return *m_colorData.extendedColor; 646 644 } 647 645 -
trunk/Source/WebCore/platform/graphics/Color.h
r207361 r207442 159 159 } 160 160 161 // FIXME: Add constructor for ExtendedColor type. 161 // This creates an ExtendedColor. 162 // FIXME: If the colorSpace is sRGB and the values can all be 163 // converted exactly to integers, we should make a normal Color. 164 WEBCORE_EXPORT Color(float r, float g, float b, float a, ColorSpace colorSpace); 162 165 163 166 Color(RGBA, ColorSpace); … … 182 185 WEBCORE_EXPORT String serialized() const; 183 186 184 String cssText() const;187 WEBCORE_EXPORT String cssText() const; 185 188 186 189 // Returns the color serialized as either #RRGGBB or #RRGGBBAA 187 190 // The latter format is not a valid CSS color, and should only be seen in DRT dumps. 188 191 String nameForRenderTreeAsText() const; 189 190 void setNamedColor(const String&);191 192 192 193 bool isValid() const { return m_colorData.rgbaAndFlags & validRGBAColorBit; } … … 200 201 201 202 RGBA32 rgb() const { ASSERT(!isExtended()); return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32); } 202 void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }203 void setRGB(RGBA32);204 203 uint64_t asUint64() const { return m_colorData.rgbaAndFlags; } 205 204 … … 257 256 258 257 WEBCORE_EXPORT bool isExtended() const; 259 WEBCORE_EXPORT ExtendedColor *asExtended() const;258 WEBCORE_EXPORT ExtendedColor& asExtended() const; 260 259 261 260 WEBCORE_EXPORT Color& operator=(const Color&); … … 265 264 266 265 private: 266 void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); } 267 void setRGB(RGBA32); 267 268 268 269 // 0x_______00 is an ExtendedColor pointer. … … 275 276 276 277 WEBCORE_EXPORT void tagAsValid(); 277 void tagAsExtended();278 278 279 279 union { -
trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp
r207265 r207442 28 28 29 29 #include "ColorSpace.h" 30 #include <wtf/MathExtras.h> 31 #include <wtf/dtoa.h> 32 #include <wtf/text/StringBuilder.h> 30 33 31 34 namespace WebCore { … … 36 39 } 37 40 41 String ExtendedColor::cssText() const 42 { 43 StringBuilder builder; 44 builder.reserveCapacity(40); 45 builder.appendLiteral("color("); 46 47 switch (m_colorSpace) { 48 case ColorSpaceSRGB: 49 builder.appendLiteral("srgb "); 50 break; 51 case ColorSpaceDisplayP3: 52 builder.appendLiteral("display-p3 "); 53 break; 54 default: 55 ASSERT_NOT_REACHED(); 56 return WTF::emptyString(); 57 } 58 59 NumberToStringBuffer buffer; 60 bool shouldTruncateTrailingZeros = true; 61 62 builder.append(numberToFixedPrecisionString(red(), 6, buffer, shouldTruncateTrailingZeros)); 63 builder.append(' '); 64 65 builder.append(numberToFixedPrecisionString(green(), 6, buffer, shouldTruncateTrailingZeros)); 66 builder.append(' '); 67 68 builder.append(numberToFixedPrecisionString(blue(), 6, buffer, shouldTruncateTrailingZeros)); 69 builder.appendLiteral(" / "); 70 71 builder.append(numberToFixedPrecisionString(alpha(), 6, buffer, shouldTruncateTrailingZeros)); 72 builder.append(')'); 73 74 return builder.toString(); 38 75 } 76 77 } -
trunk/Source/WebCore/platform/graphics/ExtendedColor.h
r207265 r207442 30 30 #include <wtf/Ref.h> 31 31 #include <wtf/RefCounted.h> 32 #include <wtf/text/WTFString.h> 32 33 33 34 namespace WebCore { … … 43 44 44 45 ColorSpace colorSpace() const { return m_colorSpace; } 46 47 WEBCORE_EXPORT String cssText() const; 45 48 46 49 private: -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
r207002 r207442 541 541 #if !PLATFORM(GTK) 542 542 // Force the alpha to 50%. This matches what the Mac does with outline rings. 543 color .setRGB(makeRGBA(color.red(), color.green(), color.blue(), 127));543 color = Color(makeRGBA(color.red(), color.green(), color.blue(), 127)); 544 544 #else 545 545 UNUSED_PARAM(color); -
trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
r205348 r207442 200 200 static const RGBA32 red = 0xffff0000; 201 201 static const RGBA32 green = 0xff008000; 202 static const RGBA32 cyan = 0xFF00FFFF; 202 203 203 204 IntSize size = this->size(); … … 249 250 boxTop += boxSize + 2; 250 251 boxLeft = boxSize; 251 Color boxColors[] = { Color::white, yellow, Color::cyan, green, magenta, red, blue };252 Color boxColors[] = { Color::white, yellow, cyan, green, magenta, red, blue }; 252 253 for (unsigned i = 0; i < sizeof(boxColors) / sizeof(boxColors[0]); i++) { 253 254 context.fillRect(FloatRect(boxLeft, boxTop, boxSize + 1, boxSize + 1), boxColors[i]); -
trunk/Source/WebCore/rendering/style/RenderStyle.cpp
r206839 r207442 1684 1684 if (!result.isValid()) { 1685 1685 if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE)) 1686 result .setRGB(238, 238, 238);1686 result = Color(238, 238, 238); 1687 1687 else 1688 1688 result = visitedLink ? visitedLinkColor() : color(); -
trunk/Tools/ChangeLog
r207432 r207442 1 2016-10-17 Dean Jackson <dino@apple.com> 2 3 Allow creation of ExtendedColors and make Color immutable 4 https://bugs.webkit.org/show_bug.cgi?id=163557 5 <rdar://problem/28805360> 6 7 Reviewed by Darin Adler and Dave Hyatt. 8 9 API tests for ExtendedColor. 10 11 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 12 * TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp: Added. 13 (TestWebKitAPI::TEST): 14 (TestWebKitAPI::makeColor): 15 1 16 2016-10-17 JF Bastien <jfbastien@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r207385 r207442 86 86 2EFF06D41D8AEDBB0004BB30 /* TestWKWebViewMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D31D8AEDBB0004BB30 /* TestWKWebViewMac.mm */; }; 87 87 2EFF06D71D8AF34A0004BB30 /* WKWebViewCandidateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */; }; 88 315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; }; 88 89 33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; }; 89 90 33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; }; … … 823 824 2EFF06D31D8AEDBB0004BB30 /* TestWKWebViewMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestWKWebViewMac.mm; sourceTree = "<group>"; }; 824 825 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCandidateTests.mm; sourceTree = "<group>"; }; 826 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; }; 825 827 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; }; 826 828 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; }; … … 1457 1459 260BA57A1B1D2EE2004FA07C /* DFAHelpers.h */, 1458 1460 26F6E1EF1ADC749B00DE696B /* DFAMinimizer.cpp */, 1461 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */, 1459 1462 41973B5A1AF2286A006C7B36 /* FileSystem.cpp */, 1460 1463 83B88A331C80056D00BB2418 /* HTMLParserIdioms.cpp */, … … 2432 2435 7CCE7EC61A411A7E00447C4C /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */, 2433 2436 7C83E0B71D0A64B800FEBCF3 /* MenuTypesForMouseEvents.cpp in Sources */, 2437 315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */, 2434 2438 51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */, 2435 2439 7C83E0B61D0A64B300FEBCF3 /* ModalAlertsSPI.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.