Refine and simplify some color-related code
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Sep 2015 01:25:35 +0000 (01:25 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Sep 2015 01:25:35 +0000 (01:25 +0000)
commite9231172fad0f8a88208e3ea5802717c0ee55a00
tree64e149620029086f4ea111d0ea09593c57159f37
parentea4094590bd934cafe9f87ec3672893865293702
Refine and simplify some color-related code
https://bugs.webkit.org/show_bug.cgi?id=148961

Reviewed by Anders Carlsson.

Refactoring code that seems to be covered by existing tests.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseColor): Handle the empty string efficiently so that
callers don't need to do that.

* platform/graphics/Color.h: Started adding comments about deprecation.
Added RGBA class for future use whenever we need an RGBA quadruplet rather than
a color with a color space. Added FIXME about future evoluation of the classes here.
Added OptionalColor so we can start removing the "invalid color" feature from Color.
Added roundAndClampColorChannel function.

* svg/ColorDistance.cpp: Removed.
* svg/ColorDistance.h: Removed.

* CMakeLists.txt: Removed ColorDistance.
* WebCore.vcxproj/WebCore.vcxproj: Ditto.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* svg/SVGAllInOne.cpp: Ditto.

* svg/SVGAnimatedColor.cpp:
(WebCore::SVGAnimatedColorAnimator::SVGAnimatedColorAnimator): Changed to take
a reference instead of a pointer.
(WebCore::SVGAnimatedColorAnimator::constructFromString): Simplified since the
SVGColor::colorFromRGBColorString will handle the empty string.
(WebCore::SVGAnimatedColorAnimator::addAnimatedTypes): Moved the code to add the
RGB channels of two colors here from ColorDistance::addColors since this is the
only place it was used.
(WebCore::currentColor): Refactored adjustForCurrentColor function into this.
Helper for the code below.
(WebCore::SVGAnimatedColorAnimator::calculateAnimatedValue): Refactored to use
the new currentColor function and replaced the use of the ColorDistance::clampColor
function here with a bit of code here in the one place it was used.
(WebCore::SVGAnimatedColorAnimator::calculateDistance): Moved the distance algorithm
here from ColorDistance::distance.

* svg/SVGAnimatedColor.h: Removed unneeded forward declaration, changed constructor
to take references instead of pointers, and made all class member functions private.

* svg/SVGAnimatedType.cpp:
(WebCore::SVGAnimatedType::setValueAsString): Removed special case for empty string,
since SVGColor::colorFromRGBColorString does the same thing.

* svg/SVGAnimatorFactory.h:
(WebCore::SVGAnimatorFactory::create): Pass references rather tha pointers to the
SVGAnimatedColorAnimator constructor.

* svg/SVGColor.cpp:
(WebCore::SVGColor::colorFromRGBColorString): Added more FIXMEs about the future of
this function.
(WebCore::SVGColor::setRGBColor): Fixed confusing verb tense.
(WebCore::SVGColor::customCSSText): Use ASCII literal for an ASCII literal.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190003 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSParser.cpp
Source/WebCore/platform/graphics/Color.h
Source/WebCore/svg/ColorDistance.cpp [deleted file]
Source/WebCore/svg/ColorDistance.h [deleted file]
Source/WebCore/svg/SVGAllInOne.cpp
Source/WebCore/svg/SVGAnimatedColor.cpp
Source/WebCore/svg/SVGAnimatedColor.h
Source/WebCore/svg/SVGAnimatedType.cpp
Source/WebCore/svg/SVGAnimatorFactory.h
Source/WebCore/svg/SVGColor.cpp