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

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

Issue 1681273003: Add CSS parser support for break-after, break-before and break-inside. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase master Created 4 years, 10 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 // 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 4255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 addProperty(CSSPropertyBorderImageRepeat, repeat ? repeat : cssValue Pool().createImplicitInitialValue(), important); 4266 addProperty(CSSPropertyBorderImageRepeat, repeat ? repeat : cssValue Pool().createImplicitInitialValue(), important);
4267 return true; 4267 return true;
4268 default: 4268 default:
4269 ASSERT_NOT_REACHED(); 4269 ASSERT_NOT_REACHED();
4270 return false; 4270 return false;
4271 } 4271 }
4272 } 4272 }
4273 return false; 4273 return false;
4274 } 4274 }
4275 4275
4276 static inline CSSValueID mapFromPageBreakBetween(CSSValueID value)
4277 {
4278 if (value == CSSValueAlways)
4279 return CSSValuePage;
4280 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-page", acc ording to the spec.
4281 if (value == CSSValueAvoid)
4282 return CSSValueAvoidPage;
4283 if (value == CSSValueAuto || value == CSSValueLeft || value == CSSValueRight )
4284 return value;
4285 return CSSValueInvalid;
4286 }
4287
4288 static inline CSSValueID mapFromColumnBreakBetween(CSSValueID value)
4289 {
4290 if (value == CSSValueAlways)
4291 return CSSValueColumn;
4292 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-column".
4293 if (value == CSSValueAvoid)
4294 return CSSValueAvoidColumn;
4295 // TODO(mstensho): column break properties shouldn't take 'left' and 'right' values (but
4296 // allowing it for now, since that's what we've always done).
4297 if (value == CSSValueAuto || value == CSSValueLeft || value == CSSValueRight )
4298 return value;
4299 return CSSValueInvalid;
4300 }
4301
4302 static inline CSSValueID mapFromPageBreakInside(CSSValueID value)
4303 {
4304 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-page", acc ording to the spec.
4305 if (value == CSSValueAvoid)
4306 return CSSValueAvoidPage;
4307 if (value == CSSValueAuto)
4308 return value;
4309 return CSSValueInvalid;
4310 }
4311
4312 static inline CSSValueID mapFromColumnBreakInside(CSSValueID value)
4313 {
4314 // TODO(mstensho): "avoid" should just return "avoid", not "avoid-column".
4315 if (value == CSSValueAvoid)
4316 return CSSValueAvoidColumn;
4317 if (value == CSSValueAuto)
4318 return value;
4319 return CSSValueInvalid;
4320 }
4321
4322 static inline CSSPropertyID mapFromLegacyBreakProperty(CSSPropertyID property)
4323 {
4324 if (property == CSSPropertyPageBreakAfter || property == CSSPropertyWebkitCo lumnBreakAfter)
4325 return CSSPropertyBreakAfter;
4326 if (property == CSSPropertyPageBreakBefore || property == CSSPropertyWebkitC olumnBreakBefore)
4327 return CSSPropertyBreakBefore;
4328 ASSERT(property == CSSPropertyPageBreakInside || property == CSSPropertyWebk itColumnBreakInside);
4329 return CSSPropertyBreakInside;
4330 }
4331
4332 bool CSSPropertyParser::consumeLegacyBreakProperty(CSSPropertyID property, bool important)
4333 {
4334 // The fragmentation spec says that page-break-(after|before|inside) are to be treated as
4335 // shorthands for their break-(after|before|inside) counterparts. We'll do t he same for the
4336 // non-standard properties -webkit-column-break-(after|before|inside).
4337 RefPtrWillBeRawPtr<CSSPrimitiveValue> keyword = consumeIdent(m_range);
4338 if (!keyword)
4339 return false;
4340 if (!m_range.atEnd())
4341 return false;
4342 CSSValueID value = keyword->getValueID();
4343 switch (property) {
4344 case CSSPropertyPageBreakAfter:
4345 case CSSPropertyPageBreakBefore:
4346 value = mapFromPageBreakBetween(value);
4347 break;
4348 case CSSPropertyWebkitColumnBreakAfter:
4349 case CSSPropertyWebkitColumnBreakBefore:
4350 value = mapFromColumnBreakBetween(value);
4351 break;
4352 case CSSPropertyPageBreakInside:
4353 value = mapFromPageBreakInside(value);
4354 break;
4355 case CSSPropertyWebkitColumnBreakInside:
4356 value = mapFromColumnBreakInside(value);
4357 break;
4358 default:
4359 ASSERT_NOT_REACHED();
4360 }
4361 if (value == CSSValueInvalid)
4362 return false;
4363
4364 CSSPropertyID genericBreakProperty = mapFromLegacyBreakProperty(property);
4365 addProperty(genericBreakProperty, cssValuePool().createIdentifierValue(value ), important);
4366 return true;
4367 }
4368
4276 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) 4369 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant)
4277 { 4370 {
4278 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 4371 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
4279 4372
4280 CSSPropertyID oldShorthand = m_currentShorthand; 4373 CSSPropertyID oldShorthand = m_currentShorthand;
4281 // TODO(rob.buis): Remove this when the legacy property parser is gone 4374 // TODO(rob.buis): Remove this when the legacy property parser is gone
4282 m_currentShorthand = property; 4375 m_currentShorthand = property;
4283 switch (property) { 4376 switch (property) {
4284 case CSSPropertyWebkitMarginCollapse: { 4377 case CSSPropertyWebkitMarginCollapse: {
4285 CSSValueID id = m_range.consumeIncludingWhitespace().id(); 4378 CSSValueID id = m_range.consumeIncludingWhitespace().id();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4400 return consumeShorthandGreedily(borderRightShorthand(), important); 4493 return consumeShorthandGreedily(borderRightShorthand(), important);
4401 case CSSPropertyBorderBottom: 4494 case CSSPropertyBorderBottom:
4402 return consumeShorthandGreedily(borderBottomShorthand(), important); 4495 return consumeShorthandGreedily(borderBottomShorthand(), important);
4403 case CSSPropertyBorderLeft: 4496 case CSSPropertyBorderLeft:
4404 return consumeShorthandGreedily(borderLeftShorthand(), important); 4497 return consumeShorthandGreedily(borderLeftShorthand(), important);
4405 case CSSPropertyBorder: 4498 case CSSPropertyBorder:
4406 return consumeBorder(important); 4499 return consumeBorder(important);
4407 case CSSPropertyBorderImage: 4500 case CSSPropertyBorderImage:
4408 case CSSPropertyWebkitMaskBoxImage: 4501 case CSSPropertyWebkitMaskBoxImage:
4409 return consumeBorderImage(property, important); 4502 return consumeBorderImage(property, important);
4503 case CSSPropertyPageBreakAfter:
4504 case CSSPropertyPageBreakBefore:
4505 case CSSPropertyPageBreakInside:
4506 case CSSPropertyWebkitColumnBreakAfter:
4507 case CSSPropertyWebkitColumnBreakBefore:
4508 case CSSPropertyWebkitColumnBreakInside:
4509 return consumeLegacyBreakProperty(property, important);
4410 default: 4510 default:
4411 m_currentShorthand = oldShorthand; 4511 m_currentShorthand = oldShorthand;
4412 CSSParserValueList valueList(m_range); 4512 CSSParserValueList valueList(m_range);
4413 if (!valueList.size()) 4513 if (!valueList.size())
4414 return false; 4514 return false;
4415 m_valueList = &valueList; 4515 m_valueList = &valueList;
4416 return legacyParseShorthand(unresolvedProperty, important); 4516 return legacyParseShorthand(unresolvedProperty, important);
4417 } 4517 }
4418 } 4518 }
4419 4519
4420 } // namespace blink 4520 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h ('k') | third_party/WebKit/Source/core/editing/EditingStyle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698