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

Side by Side Diff: sky/engine/core/css/DOMWindowCSS.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/CSSStyleDeclaration.idl ('k') | sky/engine/core/css/FontFace.cpp » ('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 * Copyright (C) 2012 Motorola Mobility Inc. All rights reserved. 2 * Copyright (C) 2012 Motorola Mobility 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above 10 * 2. Redistributions in binary form must reproduce the above
(...skipping 24 matching lines...) Expand all
35 #include "sky/engine/core/css/parser/BisonCSSParser.h" 35 #include "sky/engine/core/css/parser/BisonCSSParser.h"
36 #include "sky/engine/wtf/text/WTFString.h" 36 #include "sky/engine/wtf/text/WTFString.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 PassRefPtr<DOMWindowCSS> DOMWindowCSS::create() 40 PassRefPtr<DOMWindowCSS> DOMWindowCSS::create()
41 { 41 {
42 return adoptRef(new DOMWindowCSS()); 42 return adoptRef(new DOMWindowCSS());
43 } 43 }
44 44
45 static String valueWithoutImportant(const String& value)
46 {
47 if (!value.endsWith("important", false))
48 return value;
49
50 String newValue = value;
51 int bangIndex = newValue.length() - 9 - 1;
52 if (newValue[bangIndex] == ' ')
53 bangIndex--;
54 newValue = newValue.left(bangIndex);
55
56 return newValue;
57 }
58
59 bool DOMWindowCSS::supports(const String& property, const String& value) const 45 bool DOMWindowCSS::supports(const String& property, const String& value) const
60 { 46 {
61 CSSPropertyID propertyID = cssPropertyID(property.stripWhiteSpace()); 47 CSSPropertyID propertyID = cssPropertyID(property.stripWhiteSpace());
62 if (propertyID == CSSPropertyInvalid) 48 if (propertyID == CSSPropertyInvalid)
63 return false; 49 return false;
64 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); 50 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
65 51
66 // BisonCSSParser::parseValue() won't work correctly if !important is presen t,
67 // so just get rid of it. It doesn't matter to supports() if it's actually
68 // there or not, provided how it's specified in the value is correct.
69 String normalizedValue = value.stripWhiteSpace().simplifyWhiteSpace(); 52 String normalizedValue = value.stripWhiteSpace().simplifyWhiteSpace();
70 normalizedValue = valueWithoutImportant(normalizedValue);
71 53
72 if (normalizedValue.isEmpty()) 54 if (normalizedValue.isEmpty())
73 return false; 55 return false;
74 56
75 RefPtr<MutableStylePropertySet> dummyStyle = MutableStylePropertySet::create (); 57 RefPtr<MutableStylePropertySet> dummyStyle = MutableStylePropertySet::create ();
76 return BisonCSSParser::parseValue(dummyStyle.get(), propertyID, normalizedVa lue, false, HTMLStandardMode, 0); 58 return BisonCSSParser::parseValue(dummyStyle.get(), propertyID, normalizedVa lue, HTMLStandardMode, 0);
77 } 59 }
78 60
79 bool DOMWindowCSS::supports(const String& conditionText) const 61 bool DOMWindowCSS::supports(const String& conditionText) const
80 { 62 {
81 CSSParserContext context(0); 63 CSSParserContext context(0);
82 BisonCSSParser parser(context); 64 BisonCSSParser parser(context);
83 return parser.parseSupportsCondition(conditionText); 65 return parser.parseSupportsCondition(conditionText);
84 } 66 }
85 67
86 } 68 }
OLDNEW
« no previous file with comments | « sky/engine/core/css/CSSStyleDeclaration.idl ('k') | sky/engine/core/css/FontFace.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698