Ignore:
Timestamp:
Dec 8, 2017, 9:26:58 AM (7 years ago)
Author:
Darin Adler
Message:

Simplify and streamline some Color-related code to prepare for some Color/ExtendedColor work
https://bugs.webkit.org/show_bug.cgi?id=180569

Reviewed by Sam Weinig.

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::colorValue const): Use valueAsColor instead of
having custom code here to parse the color string.

  • css/CSSGradientValue.cpp:

(WebCore::interpolate): Deleted.
(WebCore::CSSGradientValue::computeStops): Call blend instead of interpolate. The only
difference is that the interpolate function truncated when converting from floating point
to integer, and the blend function rounds instead.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::colorFromPrimitiveValue const): Removed unneeded special case
for identifier of 0, since StyleColor::colorFromKeyword already handles that correctly.
Also got rid of unneded local variable "state".

  • html/ColorInputType.cpp:

(WebCore::isValidSimpleColor): Rewrote to take a StringView instead of a String and
to stay with a single loop since this does not need the extra efficiency of a separate
8-bit and 16-bit character version. Renamed to more closely match what the specification
calls this algorithm.
(WebCore::parseSimpleColorValue): Added. To be used instead of relying on the behavior of
the Color constructor that takes a String, so we can remove that later.
(WebCore::ColorInputType::sanitizeValue const): Updated for name change.
(WebCore::ColorInputType::valueAsColor const): Use parseSimpleColorValue instead of the
Color constructor that takes a string.
(WebCore::ColorInputType::typeMismatchFor const): Updated for name change.
(WebCore::ColorInputType::selectColor): Updated to take a StringView instead of a Color.
Note that this function is used for testing only.

  • html/ColorInputType.h: Marked everything final instead of override. Updated the

selectColor function to take a StringView instead of a Color.

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::selectColor): Take a StringView instead of a Color.

  • html/HTMLInputElement.h: Ditto.
  • html/InputType.cpp:

(WebCore::InputType::selectColor): Take a StringView instead of a Color.

  • html/InputType.h: Ditto.
  • testing/Internals.cpp:

(WebCore::Internals::selectColorInColorChooser): Pass the string directly instead of
constructing a Color with it.
(WebCore::Internals::setViewBaseBackgroundColor): Instead of pasring the passed in string
with the Color constructor, implemented the two names that are actually used with this
function in tests: "transparent" and "white".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r225036 r225680  
    120120}
    121121
    122 static inline int interpolate(int min, int max, float position)
    123 {
    124     return min + static_cast<int>(position * (max - min));
    125 }
    126 
    127 static inline Color interpolate(const Color& color1, const Color& color2, float position)
    128 {
    129     // FIXME: ExtendedColor - Doesn't work with extended colors, and really should be a helper in Color.h, not here.
    130     int red = interpolate(color1.red(), color2.red(), position);
    131     int green = interpolate(color1.green(), color2.green(), position);
    132     int blue = interpolate(color1.blue(), color2.blue(), position);
    133     int alpha = interpolate(color1.alpha(), color2.alpha(), position);
    134 
    135     return Color(red, green, blue, alpha);
    136 }
    137 
    138122class LinearGradientAdapter {
    139123public:
     
    422406        for (size_t y = 0; y < 9; ++y) {
    423407            float relativeOffset = (newStops[y].offset - offset1) / (offset2 - offset1);
    424             float multiplier = powf(relativeOffset, logf(.5f) / logf(midpoint));
    425             newStops[y].color = interpolate(color1, color2, multiplier);
     408            float multiplier = std::pow(relativeOffset, std::log(.5f) / std::log(midpoint));
     409            // FIXME: Why not premultiply here?
     410            newStops[y].color = blend(color1, color2, multiplier, false /* do not premultiply */);
    426411        }
    427412
Note: See TracChangeset for help on using the changeset viewer.