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

Side by Side Diff: sky/engine/core/css/StylePropertySet.cpp

Issue 860423004: Remove css !important (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « sky/engine/core/css/StylePropertySet.h ('k') | sky/engine/core/css/parser/BisonCSSParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 if (returnText) 169 if (returnText)
170 *returnText = propertyAt(foundPropertyIndex).value()->cssText(); 170 *returnText = propertyAt(foundPropertyIndex).value()->cssText();
171 171
172 // A more efficient removal strategy would involve marking entries as empty 172 // A more efficient removal strategy would involve marking entries as empty
173 // and sweeping them when the vector grows too big. 173 // and sweeping them when the vector grows too big.
174 m_propertyVector.remove(foundPropertyIndex); 174 m_propertyVector.remove(foundPropertyIndex);
175 175
176 return true; 176 return true;
177 } 177 }
178 178
179 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const
180 {
181 int foundPropertyIndex = findPropertyIndex(propertyID);
182 if (foundPropertyIndex != -1)
183 return propertyAt(foundPropertyIndex).isImportant();
184
185 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
186 if (!shorthand.length())
187 return false;
188
189 for (unsigned i = 0; i < shorthand.length(); ++i) {
190 if (!propertyIsImportant(shorthand.properties()[i]))
191 return false;
192 }
193 return true;
194 }
195
196 CSSPropertyID StylePropertySet::getPropertyShorthand(CSSPropertyID propertyID) c onst 179 CSSPropertyID StylePropertySet::getPropertyShorthand(CSSPropertyID propertyID) c onst
197 { 180 {
198 int foundPropertyIndex = findPropertyIndex(propertyID); 181 int foundPropertyIndex = findPropertyIndex(propertyID);
199 if (foundPropertyIndex == -1) 182 if (foundPropertyIndex == -1)
200 return CSSPropertyInvalid; 183 return CSSPropertyInvalid;
201 return propertyAt(foundPropertyIndex).shorthandID(); 184 return propertyAt(foundPropertyIndex).shorthandID();
202 } 185 }
203 186
204 bool StylePropertySet::isPropertyImplicit(CSSPropertyID propertyID) const 187 bool StylePropertySet::isPropertyImplicit(CSSPropertyID propertyID) const
205 { 188 {
206 int foundPropertyIndex = findPropertyIndex(propertyID); 189 int foundPropertyIndex = findPropertyIndex(propertyID);
207 if (foundPropertyIndex == -1) 190 if (foundPropertyIndex == -1)
208 return false; 191 return false;
209 return propertyAt(foundPropertyIndex).isImplicit(); 192 return propertyAt(foundPropertyIndex).isImplicit();
210 } 193 }
211 194
212 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, const String & value, bool important, StyleSheetContents* contextStyleSheet) 195 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, const String & value, StyleSheetContents* contextStyleSheet)
213 { 196 {
214 // Setting the value to an empty string just removes the property in both IE and Gecko. 197 // Setting the value to an empty string just removes the property in both IE and Gecko.
215 // Setting it to null seems to produce less consistent results, but we treat it just the same. 198 // Setting it to null seems to produce less consistent results, but we treat it just the same.
216 if (value.isEmpty()) 199 if (value.isEmpty())
217 return removeProperty(propertyID); 200 return removeProperty(propertyID);
218 201
219 // When replacing an existing property value, this moves the property to the end of the list. 202 // When replacing an existing property value, this moves the property to the end of the list.
220 // Firefox preserves the position, and MSIE moves the property to the beginn ing. 203 // Firefox preserves the position, and MSIE moves the property to the beginn ing.
221 return BisonCSSParser::parseValue(this, propertyID, value, important, cssPar serMode(), contextStyleSheet); 204 return BisonCSSParser::parseValue(this, propertyID, value, cssParserMode(), contextStyleSheet);
222 } 205 }
223 206
224 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtr<C SSValue> prpValue, bool important) 207 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtr<C SSValue> prpValue)
225 { 208 {
226 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 209 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
227 if (!shorthand.length()) { 210 if (!shorthand.length()) {
228 setProperty(CSSProperty(propertyID, prpValue, important)); 211 setProperty(CSSProperty(propertyID, prpValue));
229 return; 212 return;
230 } 213 }
231 214
232 removePropertiesInSet(shorthand.properties(), shorthand.length()); 215 removePropertiesInSet(shorthand.properties(), shorthand.length());
233 216
234 RefPtr<CSSValue> value = prpValue; 217 RefPtr<CSSValue> value = prpValue;
235 for (unsigned i = 0; i < shorthand.length(); ++i) 218 for (unsigned i = 0; i < shorthand.length(); ++i)
236 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant)); 219 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value));
237 } 220 }
238 221
239 void MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot) 222 void MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot)
240 { 223 {
241 if (!removeShorthandProperty(property.id())) { 224 if (!removeShorthandProperty(property.id())) {
242 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ()); 225 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ());
243 if (toReplace) { 226 if (toReplace) {
244 *toReplace = property; 227 *toReplace = property;
245 return; 228 return;
246 } 229 }
247 } 230 }
248 appendProperty(property); 231 appendProperty(property);
249 } 232 }
250 233
251 void MutableStylePropertySet::appendProperty(const CSSProperty& property) 234 void MutableStylePropertySet::appendProperty(const CSSProperty& property)
252 { 235 {
253 m_propertyVector.append(property); 236 m_propertyVector.append(property);
254 } 237 }
255 238
256 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValueID i dentifier, bool important) 239 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValueID i dentifier)
257 { 240 {
258 setProperty(CSSProperty(propertyID, cssValuePool().createIdentifierValue(ide ntifier), important)); 241 setProperty(CSSProperty(propertyID, cssValuePool().createIdentifierValue(ide ntifier)));
259 return true; 242 return true;
260 } 243 }
261 244
262 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSPropertyI D identifier, bool important) 245 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSPropertyI D identifier)
263 { 246 {
264 setProperty(CSSProperty(propertyID, cssValuePool().createIdentifierValue(ide ntifier), important)); 247 setProperty(CSSProperty(propertyID, cssValuePool().createIdentifierValue(ide ntifier)));
265 return true; 248 return true;
266 } 249 }
267 250
268 void MutableStylePropertySet::parseDeclaration(const String& styleDeclaration, S tyleSheetContents* contextStyleSheet) 251 void MutableStylePropertySet::parseDeclaration(const String& styleDeclaration, S tyleSheetContents* contextStyleSheet)
269 { 252 {
270 m_propertyVector.clear(); 253 m_propertyVector.clear();
271 254
272 CSSParserContext context(UseCounter::getFrom(contextStyleSheet)); 255 CSSParserContext context(UseCounter::getFrom(contextStyleSheet));
273 if (contextStyleSheet) { 256 if (contextStyleSheet) {
274 context = contextStyleSheet->parserContext(); 257 context = contextStyleSheet->parserContext();
275 } 258 }
276 259
277 BisonCSSParser parser(context); 260 BisonCSSParser parser(context);
278 parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet); 261 parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet);
279 } 262 }
280 263
281 void MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty, 256> & properties) 264 void MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty, 256> & properties)
282 { 265 {
283 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size() ); 266 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size() );
284 for (unsigned i = 0; i < properties.size(); ++i) 267 for (unsigned i = 0; i < properties.size(); ++i)
285 addParsedProperty(properties[i]); 268 addParsedProperty(properties[i]);
286 } 269 }
287 270
271 // TODO(esprehn): Remove this, it used to have !important logic before sky.
288 void MutableStylePropertySet::addParsedProperty(const CSSProperty& property) 272 void MutableStylePropertySet::addParsedProperty(const CSSProperty& property)
289 { 273 {
290 // Only add properties that have no !important counterpart present 274 setProperty(property);
291 if (!propertyIsImportant(property.id()) || property.isImportant())
292 setProperty(property);
293 } 275 }
294 276
295 String StylePropertySet::asText() const 277 String StylePropertySet::asText() const
296 { 278 {
297 return StylePropertySerializer(*this).asText(); 279 return StylePropertySerializer(*this).asText();
298 } 280 }
299 281
300 // This is the list of properties we want to copy in the copyBlockProperties() f unction. 282 // This is the list of properties we want to copy in the copyBlockProperties() f unction.
301 // It is the list of CSS properties that apply specially to block-level elements . 283 // It is the list of CSS properties that apply specially to block-level elements .
302 static const CSSPropertyID staticBlockProperties[] = { 284 static const CSSPropertyID staticBlockProperties[] = {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 if (m_propertyVector.isEmpty()) 332 if (m_propertyVector.isEmpty())
351 return false; 333 return false;
352 334
353 Vector<CSSProperty> newProperties; 335 Vector<CSSProperty> newProperties;
354 newProperties.reserveInitialCapacity(m_propertyVector.size()); 336 newProperties.reserveInitialCapacity(m_propertyVector.size());
355 337
356 unsigned initialSize = m_propertyVector.size(); 338 unsigned initialSize = m_propertyVector.size();
357 const CSSProperty* properties = m_propertyVector.data(); 339 const CSSProperty* properties = m_propertyVector.data();
358 for (unsigned n = 0; n < initialSize; ++n) { 340 for (unsigned n = 0; n < initialSize; ++n) {
359 const CSSProperty& property = properties[n]; 341 const CSSProperty& property = properties[n];
360 // Not quite sure if the isImportant test is needed but it matches the e xisting behavior. 342 if (containsId(set, length, property.id()))
361 if (!property.isImportant() && containsId(set, length, property.id()))
362 continue; 343 continue;
363 newProperties.append(property); 344 newProperties.append(property);
364 } 345 }
365 346
366 m_propertyVector = newProperties; 347 m_propertyVector = newProperties;
367 return initialSize != m_propertyVector.size(); 348 return initialSize != m_propertyVector.size();
368 } 349 }
369 350
370 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID) 351 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID)
371 { 352 {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 { 471 {
491 return getPropertyNameString(id()); 472 return getPropertyNameString(id());
492 } 473 }
493 474
494 String StylePropertySet::PropertyReference::cssText() const 475 String StylePropertySet::PropertyReference::cssText() const
495 { 476 {
496 StringBuilder result; 477 StringBuilder result;
497 result.append(cssName()); 478 result.append(cssName());
498 result.appendLiteral(": "); 479 result.appendLiteral(": ");
499 result.append(propertyValue()->cssText()); 480 result.append(propertyValue()->cssText());
500 if (isImportant())
501 result.appendLiteral(" !important");
502 result.append(';'); 481 result.append(';');
503 return result.toString(); 482 return result.toString();
504 } 483 }
505 484
506 485
507 } // namespace blink 486 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/StylePropertySet.h ('k') | sky/engine/core/css/parser/BisonCSSParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698