| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 { | 193 { |
| 194 if (name[0] == '#') { | 194 if (name[0] == '#') { |
| 195 m_valid = parseHexColor(&name[1], m_color); | 195 m_valid = parseHexColor(&name[1], m_color); |
| 196 } else { | 196 } else { |
| 197 const NamedColor* foundColor = findColor(name, strlen(name)); | 197 const NamedColor* foundColor = findColor(name, strlen(name)); |
| 198 m_color = foundColor ? foundColor->ARGBValue : 0; | 198 m_color = foundColor ? foundColor->ARGBValue : 0; |
| 199 m_valid = foundColor; | 199 m_valid = foundColor; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 String Color::serializedAsCSSComponentValue() const |
| 204 { |
| 205 StringBuilder result; |
| 206 result.reserveCapacity(32); |
| 207 bool colorHasAlpha = hasAlpha(); |
| 208 if (colorHasAlpha) |
| 209 result.append("rgba(", 5); |
| 210 else |
| 211 result.append("rgb(", 4); |
| 212 |
| 213 result.appendNumber(static_cast<unsigned char>(red())); |
| 214 result.append(", ", 2); |
| 215 |
| 216 result.appendNumber(static_cast<unsigned char>(green())); |
| 217 result.append(", ", 2); |
| 218 |
| 219 result.appendNumber(static_cast<unsigned char>(blue())); |
| 220 if (colorHasAlpha) { |
| 221 result.append(", ", 2); |
| 222 |
| 223 NumberToStringBuffer buffer; |
| 224 const char* alphaString = numberToFixedPrecisionString(alpha() / 255.0f,
6, buffer, true); |
| 225 result.append(alphaString, strlen(alphaString)); |
| 226 } |
| 227 |
| 228 result.append(')'); |
| 229 return result.toString(); |
| 230 } |
| 231 |
| 203 String Color::serialized() const | 232 String Color::serialized() const |
| 204 { | 233 { |
| 205 if (!hasAlpha()) { | 234 if (!hasAlpha()) { |
| 206 StringBuilder builder; | 235 StringBuilder builder; |
| 207 builder.reserveCapacity(7); | 236 builder.reserveCapacity(7); |
| 208 builder.append('#'); | 237 builder.append('#'); |
| 209 appendByteAsHex(red(), builder, Lowercase); | 238 appendByteAsHex(red(), builder, Lowercase); |
| 210 appendByteAsHex(green(), builder, Lowercase); | 239 appendByteAsHex(green(), builder, Lowercase); |
| 211 appendByteAsHex(blue(), builder, Lowercase); | 240 appendByteAsHex(blue(), builder, Lowercase); |
| 212 return builder.toString(); | 241 return builder.toString(); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 (color.green() * alpha + 254) / 255, | 467 (color.green() * alpha + 254) / 255, |
| 439 (color.blue() * alpha + 254) / 255, | 468 (color.blue() * alpha + 254) / 255, |
| 440 alpha).rgb(); | 469 alpha).rgb(); |
| 441 } else | 470 } else |
| 442 pixelColor = color.rgb(); | 471 pixelColor = color.rgb(); |
| 443 | 472 |
| 444 return pixelColor; | 473 return pixelColor; |
| 445 } | 474 } |
| 446 | 475 |
| 447 } // namespace WebCore | 476 } // namespace WebCore |
| OLD | NEW |