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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSMarkup.cpp

Issue 1783693006: Use <string> serialization rules for computed value of reference filter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 4 years, 9 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 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 if (!length) 63 if (!length)
64 return false; 64 return false;
65 65
66 if (string.is8Bit()) 66 if (string.is8Bit())
67 return isCSSTokenizerIdentifier(string.characters8(), length); 67 return isCSSTokenizerIdentifier(string.characters8(), length);
68 return isCSSTokenizerIdentifier(string.characters16(), length); 68 return isCSSTokenizerIdentifier(string.characters16(), length);
69 } 69 }
70 70
71 template <typename CharacterType> 71 template <typename CharacterType>
72 static inline bool isCSSTokenizerURL(const CharacterType* characters, unsigned l ength)
73 {
74 const CharacterType* end = characters + length;
75
76 for (; characters != end; ++characters) {
77 CharacterType c = characters[0];
78 switch (c) {
79 case '!':
80 case '#':
81 case '$':
82 case '%':
83 case '&':
84 break;
85 default:
86 if (c < '*')
87 return false;
88 if (c <= '~')
89 break;
90 if (c < 128)
91 return false;
92 }
93 }
94
95 return true;
96 }
97
98 // "url" from the CSS tokenizer, minus backslash-escape sequences
99 static bool isCSSTokenizerURL(const String& string)
100 {
101 unsigned length = string.length();
102
103 if (!length)
104 return true;
105
106 if (string.is8Bit())
107 return isCSSTokenizerURL(string.characters8(), length);
108 return isCSSTokenizerURL(string.characters16(), length);
109 }
110
111 template <typename CharacterType>
112 static inline String quoteCSSStringInternal(const CharacterType* characters, uns igned length) 72 static inline String quoteCSSStringInternal(const CharacterType* characters, uns igned length)
113 { 73 {
114 // For efficiency, we first pre-calculate the length of the quoted string, t hen we build the actual one. 74 // For efficiency, we first pre-calculate the length of the quoted string, t hen we build the actual one.
115 // Please see below for the actual logic. 75 // Please see below for the actual logic.
116 unsigned quotedStringSize = 2; // Two quotes surrounding the entire string. 76 unsigned quotedStringSize = 2; // Two quotes surrounding the entire string.
117 bool afterEscape = false; 77 bool afterEscape = false;
118 for (unsigned i = 0; i < length; ++i) { 78 for (unsigned i = 0; i < length; ++i) {
119 CharacterType ch = characters[i]; 79 CharacterType ch = characters[i];
120 if (ch == '\\' || ch == '\'') { 80 if (ch == '\\' || ch == '\'') {
121 quotedStringSize += 2; 81 quotedStringSize += 2;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (string.is8Bit()) 134 if (string.is8Bit())
175 return quoteCSSStringInternal(string.characters8(), length); 135 return quoteCSSStringInternal(string.characters8(), length);
176 return quoteCSSStringInternal(string.characters16(), length); 136 return quoteCSSStringInternal(string.characters16(), length);
177 } 137 }
178 138
179 String quoteCSSStringIfNeeded(const String& string) 139 String quoteCSSStringIfNeeded(const String& string)
180 { 140 {
181 return isCSSTokenizerIdentifier(string) ? string : quoteCSSString(string); 141 return isCSSTokenizerIdentifier(string) ? string : quoteCSSString(string);
182 } 142 }
183 143
184 String quoteCSSURLIfNeeded(const String& string)
185 {
186 return isCSSTokenizerURL(string) ? string : quoteCSSString(string);
187 }
188
189 static void serializeCharacter(UChar32 c, StringBuilder& appendTo) 144 static void serializeCharacter(UChar32 c, StringBuilder& appendTo)
190 { 145 {
191 appendTo.append('\\'); 146 appendTo.append('\\');
192 appendTo.append(c); 147 appendTo.append(c);
193 } 148 }
194 149
195 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo) 150 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo)
196 { 151 {
197 appendTo.append('\\'); 152 appendTo.append('\\');
198 appendUnsignedAsHex(c, appendTo, Lowercase); 153 appendUnsignedAsHex(c, appendTo, Lowercase);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 serializeString(string, builder); 215 serializeString(string, builder);
261 return builder.toString(); 216 return builder.toString();
262 } 217 }
263 218
264 String serializeURI(const String& string) 219 String serializeURI(const String& string)
265 { 220 {
266 return "url(" + serializeString(string) + ")"; 221 return "url(" + serializeString(string) + ")";
267 } 222 }
268 223
269 } // namespace blink 224 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSMarkup.h ('k') | third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698