OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
6 | 6 |
7 #include "core/StylePropertyShorthand.h" | 7 #include "core/StylePropertyShorthand.h" |
8 #include "core/css/CSSBasicShapeValues.h" | 8 #include "core/css/CSSBasicShapeValues.h" |
9 #include "core/css/CSSBorderImage.h" | 9 #include "core/css/CSSBorderImage.h" |
10 #include "core/css/CSSCalculationValue.h" | 10 #include "core/css/CSSCalculationValue.h" |
(...skipping 4205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4216 addProperty(CSSPropertyBorderImageRepeat, repeat ? repeat : cssValue Pool().createImplicitInitialValue(), important); | 4216 addProperty(CSSPropertyBorderImageRepeat, repeat ? repeat : cssValue Pool().createImplicitInitialValue(), important); |
4217 return true; | 4217 return true; |
4218 default: | 4218 default: |
4219 ASSERT_NOT_REACHED(); | 4219 ASSERT_NOT_REACHED(); |
4220 return false; | 4220 return false; |
4221 } | 4221 } |
4222 } | 4222 } |
4223 return false; | 4223 return false; |
4224 } | 4224 } |
4225 | 4225 |
4226 static inline CSSValueID mapFromPageBreakBetween(CSSValueID value) | |
4227 { | |
4228 if (value == CSSValueAlways) | |
4229 return CSSValuePage; | |
4230 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-page", acc ording to the spec. | |
4231 if (value == CSSValueAvoid) | |
4232 return CSSValueAvoidPage; | |
4233 if (value == CSSValueAuto || value == CSSValueLeft || value == CSSValueRight ) | |
4234 return value; | |
4235 return CSSValueInvalid; | |
4236 } | |
4237 | |
4238 static inline CSSValueID mapFromColumnBreakBetween(CSSValueID value) | |
4239 { | |
4240 if (value == CSSValueAlways) | |
4241 return CSSValueColumn; | |
4242 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-column". | |
4243 if (value == CSSValueAvoid) | |
4244 return CSSValueAvoidColumn; | |
4245 // TODO(mstensho): column break properties shouldn't take 'left' and 'right' values (but | |
4246 // allowing it for now, since that's what we've always done). | |
4247 if (value == CSSValueAuto || value == CSSValueLeft || value == CSSValueRight ) | |
4248 return value; | |
4249 return CSSValueInvalid; | |
4250 } | |
4251 | |
4252 static inline CSSValueID mapFromPageBreakInside(CSSValueID value) | |
4253 { | |
4254 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-page", acc ording to the spec. | |
4255 if (value == CSSValueAvoid) | |
4256 return CSSValueAvoidPage; | |
4257 if (value == CSSValueAuto) | |
4258 return value; | |
4259 return CSSValueInvalid; | |
4260 } | |
4261 | |
4262 static inline CSSValueID mapFromColumnBreakInside(CSSValueID value) | |
4263 { | |
4264 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-column". | |
4265 if (value == CSSValueAvoid) | |
4266 return CSSValueAvoidColumn; | |
4267 if (value == CSSValueAuto) | |
4268 return value; | |
4269 return CSSValueInvalid; | |
4270 } | |
4271 | |
4272 static inline CSSPropertyID mapFromLegacyBreakProperty(CSSPropertyID property) | |
4273 { | |
4274 if (property == CSSPropertyPageBreakAfter || property == CSSPropertyWebkitCo lumnBreakAfter) | |
4275 return CSSPropertyBreakAfter; | |
4276 if (property == CSSPropertyPageBreakBefore || property == CSSPropertyWebkitC olumnBreakBefore) | |
4277 return CSSPropertyBreakBefore; | |
4278 if (property == CSSPropertyPageBreakInside || property == CSSPropertyWebkitC olumnBreakInside) | |
Timothy Loh
2016/02/18 06:25:45
I prefer the style of having the last if just be a
mstensho (USE GERRIT)
2016/02/18 09:05:26
I like it!
Done.
| |
4279 return CSSPropertyBreakInside; | |
4280 ASSERT_NOT_REACHED(); | |
4281 return property; | |
4282 } | |
4283 | |
4284 bool CSSPropertyParser::consumeLegacyBreakProperty(CSSPropertyID property, bool important) | |
4285 { | |
4286 // The fragmentation spec says that page-break-(after|before|inside) are to be treated as | |
4287 // shorthands for their break-(after|before|inside) counterparts. We'll do t he same for the | |
4288 // non-standard properties -webkit-column-break-(after|before|inside). | |
4289 RefPtrWillBeRawPtr<CSSPrimitiveValue> keyword = consumeIdent(m_range); | |
4290 if (!keyword) | |
4291 return false; | |
4292 if (!m_range.atEnd()) | |
4293 return false; | |
4294 CSSValueID value = keyword->getValueID(); | |
4295 switch (property) { | |
4296 case CSSPropertyPageBreakAfter: | |
4297 case CSSPropertyPageBreakBefore: | |
4298 value = mapFromPageBreakBetween(value); | |
4299 break; | |
4300 case CSSPropertyWebkitColumnBreakAfter: | |
4301 case CSSPropertyWebkitColumnBreakBefore: | |
4302 value = mapFromColumnBreakBetween(value); | |
4303 break; | |
4304 case CSSPropertyPageBreakInside: | |
4305 value = mapFromPageBreakInside(value); | |
4306 break; | |
4307 case CSSPropertyWebkitColumnBreakInside: | |
4308 value = mapFromColumnBreakInside(value); | |
4309 break; | |
4310 default: | |
4311 ASSERT_NOT_REACHED(); | |
4312 } | |
4313 if (value == CSSValueInvalid) | |
4314 return false; | |
4315 | |
4316 CSSPropertyID genericBreakProperty = mapFromLegacyBreakProperty(property); | |
4317 addProperty(genericBreakProperty, cssValuePool().createIdentifierValue(value ), important); | |
4318 return true; | |
4319 } | |
4320 | |
4226 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) | 4321 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) |
4227 { | 4322 { |
4228 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 4323 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
4229 | 4324 |
4230 CSSPropertyID oldShorthand = m_currentShorthand; | 4325 CSSPropertyID oldShorthand = m_currentShorthand; |
4231 // TODO(rob.buis): Remove this when the legacy property parser is gone | 4326 // TODO(rob.buis): Remove this when the legacy property parser is gone |
4232 m_currentShorthand = property; | 4327 m_currentShorthand = property; |
4233 switch (property) { | 4328 switch (property) { |
4234 case CSSPropertyWebkitMarginCollapse: { | 4329 case CSSPropertyWebkitMarginCollapse: { |
4235 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 4330 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4350 return consumeShorthandGreedily(borderRightShorthand(), important); | 4445 return consumeShorthandGreedily(borderRightShorthand(), important); |
4351 case CSSPropertyBorderBottom: | 4446 case CSSPropertyBorderBottom: |
4352 return consumeShorthandGreedily(borderBottomShorthand(), important); | 4447 return consumeShorthandGreedily(borderBottomShorthand(), important); |
4353 case CSSPropertyBorderLeft: | 4448 case CSSPropertyBorderLeft: |
4354 return consumeShorthandGreedily(borderLeftShorthand(), important); | 4449 return consumeShorthandGreedily(borderLeftShorthand(), important); |
4355 case CSSPropertyBorder: | 4450 case CSSPropertyBorder: |
4356 return consumeBorder(important); | 4451 return consumeBorder(important); |
4357 case CSSPropertyBorderImage: | 4452 case CSSPropertyBorderImage: |
4358 case CSSPropertyWebkitMaskBoxImage: | 4453 case CSSPropertyWebkitMaskBoxImage: |
4359 return consumeBorderImage(property, important); | 4454 return consumeBorderImage(property, important); |
4455 case CSSPropertyPageBreakAfter: | |
4456 case CSSPropertyPageBreakBefore: | |
4457 case CSSPropertyPageBreakInside: | |
4458 case CSSPropertyWebkitColumnBreakAfter: | |
4459 case CSSPropertyWebkitColumnBreakBefore: | |
4460 case CSSPropertyWebkitColumnBreakInside: | |
4461 return consumeLegacyBreakProperty(property, important); | |
4360 default: | 4462 default: |
4361 m_currentShorthand = oldShorthand; | 4463 m_currentShorthand = oldShorthand; |
4362 CSSParserValueList valueList(m_range); | 4464 CSSParserValueList valueList(m_range); |
4363 if (!valueList.size()) | 4465 if (!valueList.size()) |
4364 return false; | 4466 return false; |
4365 m_valueList = &valueList; | 4467 m_valueList = &valueList; |
4366 return legacyParseShorthand(unresolvedProperty, important); | 4468 return legacyParseShorthand(unresolvedProperty, important); |
4367 } | 4469 } |
4368 } | 4470 } |
4369 | 4471 |
4370 } // namespace blink | 4472 } // namespace blink |
OLD | NEW |