Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1068)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Color.cpp

Issue 2017053003: Remove StringBuilder::appendLiteral. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return parseHexColor(name.characters8() + 1, name.length() - 1, m_color) ; 191 return parseHexColor(name.characters8() + 1, name.length() - 1, m_color) ;
192 return parseHexColor(name.characters16() + 1, name.length() - 1, m_color); 192 return parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
193 } 193 }
194 194
195 String Color::serializedAsCSSComponentValue() const 195 String Color::serializedAsCSSComponentValue() const
196 { 196 {
197 StringBuilder result; 197 StringBuilder result;
198 result.reserveCapacity(32); 198 result.reserveCapacity(32);
199 bool colorHasAlpha = hasAlpha(); 199 bool colorHasAlpha = hasAlpha();
200 if (colorHasAlpha) 200 if (colorHasAlpha)
201 result.appendLiteral("rgba("); 201 result.append("rgba(");
202 else 202 else
203 result.appendLiteral("rgb("); 203 result.append("rgb(");
204 204
205 result.appendNumber(static_cast<unsigned char>(red())); 205 result.appendNumber(static_cast<unsigned char>(red()));
206 result.appendLiteral(", "); 206 result.append(", ");
207 207
208 result.appendNumber(static_cast<unsigned char>(green())); 208 result.appendNumber(static_cast<unsigned char>(green()));
209 result.appendLiteral(", "); 209 result.append(", ");
210 210
211 result.appendNumber(static_cast<unsigned char>(blue())); 211 result.appendNumber(static_cast<unsigned char>(blue()));
212 if (colorHasAlpha) { 212 if (colorHasAlpha) {
213 result.appendLiteral(", "); 213 result.append(", ");
214 214
215 NumberToStringBuffer buffer; 215 NumberToStringBuffer buffer;
216 const char* alphaString = numberToFixedPrecisionString(alpha() / 255.0f, 6, buffer, true); 216 const char* alphaString = numberToFixedPrecisionString(alpha() / 255.0f, 6, buffer, true);
217 result.append(alphaString, strlen(alphaString)); 217 result.append(alphaString, strlen(alphaString));
218 } 218 }
219 219
220 result.append(')'); 220 result.append(')');
221 return result.toString(); 221 return result.toString();
222 } 222 }
223 223
224 String Color::serialized() const 224 String Color::serialized() const
225 { 225 {
226 if (!hasAlpha()) { 226 if (!hasAlpha()) {
227 StringBuilder builder; 227 StringBuilder builder;
228 builder.reserveCapacity(7); 228 builder.reserveCapacity(7);
229 builder.append('#'); 229 builder.append('#');
230 appendByteAsHex(red(), builder, Lowercase); 230 appendByteAsHex(red(), builder, Lowercase);
231 appendByteAsHex(green(), builder, Lowercase); 231 appendByteAsHex(green(), builder, Lowercase);
232 appendByteAsHex(blue(), builder, Lowercase); 232 appendByteAsHex(blue(), builder, Lowercase);
233 return builder.toString(); 233 return builder.toString();
234 } 234 }
235 235
236 StringBuilder result; 236 StringBuilder result;
237 result.reserveCapacity(28); 237 result.reserveCapacity(28);
238 238
239 result.appendLiteral("rgba("); 239 result.append("rgba(");
240 result.appendNumber(red()); 240 result.appendNumber(red());
241 result.appendLiteral(", "); 241 result.append(", ");
242 result.appendNumber(green()); 242 result.appendNumber(green());
243 result.appendLiteral(", "); 243 result.append(", ");
244 result.appendNumber(blue()); 244 result.appendNumber(blue());
245 result.appendLiteral(", "); 245 result.append(", ");
246 246
247 if (!alpha()) 247 if (!alpha())
248 result.append('0'); 248 result.append('0');
249 else { 249 else {
250 result.append(Decimal::fromDouble(alpha() / 255.0).toString()); 250 result.append(Decimal::fromDouble(alpha() / 255.0).toString());
251 } 251 }
252 252
253 result.append(')'); 253 result.append(')');
254 return result.toString(); 254 return result.toString();
255 } 255 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 (color.green() * alpha + 254) / 255, 462 (color.green() * alpha + 254) / 255,
463 (color.blue() * alpha + 254) / 255, 463 (color.blue() * alpha + 254) / 255,
464 alpha).rgb(); 464 alpha).rgb();
465 } else 465 } else
466 pixelColor = color.rgb(); 466 pixelColor = color.rgb();
467 467
468 return pixelColor; 468 return pixelColor;
469 } 469 }
470 470
471 } // namespace blink 471 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698