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

Side by Side Diff: third_party/WebKit/Source/core/style/GridPositionsResolver.cpp

Issue 2751653003: Replace ASSERT and ASSERT_NOT_REACHED in core/style/ (Closed)
Patch Set: Replace ASSERT and ASSERT_NOT_REACHED in core/style/ Created 3 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "GridPositionsResolver.h" 5 #include "GridPositionsResolver.h"
6 6
7 #include "core/layout/LayoutBox.h" 7 #include "core/layout/LayoutBox.h"
8 #include "core/style/GridArea.h" 8 #include "core/style/GridArea.h"
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 finalPosition.setSpanPosition(1, nullAtom); 197 finalPosition.setSpanPosition(1, nullAtom);
198 if (finalPosition.isAuto() && initialPosition.isSpan() && 198 if (finalPosition.isAuto() && initialPosition.isSpan() &&
199 !initialPosition.namedGridLine().isNull()) 199 !initialPosition.namedGridLine().isNull())
200 initialPosition.setSpanPosition(1, nullAtom); 200 initialPosition.setSpanPosition(1, nullAtom);
201 } 201 }
202 202
203 static size_t lookAheadForNamedGridLine(int start, 203 static size_t lookAheadForNamedGridLine(int start,
204 size_t numberOfLines, 204 size_t numberOfLines,
205 size_t gridLastLine, 205 size_t gridLastLine,
206 NamedLineCollection& linesCollection) { 206 NamedLineCollection& linesCollection) {
207 ASSERT(numberOfLines); 207 DCHECK(numberOfLines);
208 208
209 // Only implicit lines on the search direction are assumed to have the given 209 // Only implicit lines on the search direction are assumed to have the given
210 // name, so we can start to look from first line. 210 // name, so we can start to look from first line.
211 // See: https://drafts.csswg.org/css-grid/#grid-placement-span-int 211 // See: https://drafts.csswg.org/css-grid/#grid-placement-span-int
212 size_t end = std::max(start, 0); 212 size_t end = std::max(start, 0);
213 213
214 if (!linesCollection.hasNamedLines()) { 214 if (!linesCollection.hasNamedLines()) {
215 end = std::max(end, gridLastLine + 1); 215 end = std::max(end, gridLastLine + 1);
216 return end + numberOfLines - 1; 216 return end + numberOfLines - 1;
217 } 217 }
218 218
219 for (; numberOfLines; ++end) { 219 for (; numberOfLines; ++end) {
220 if (end > gridLastLine || linesCollection.contains(end)) 220 if (end > gridLastLine || linesCollection.contains(end))
221 numberOfLines--; 221 numberOfLines--;
222 } 222 }
223 223
224 ASSERT(end); 224 DCHECK(end);
225 return end - 1; 225 return end - 1;
226 } 226 }
227 227
228 static int lookBackForNamedGridLine(int end, 228 static int lookBackForNamedGridLine(int end,
229 size_t numberOfLines, 229 size_t numberOfLines,
230 int gridLastLine, 230 int gridLastLine,
231 NamedLineCollection& linesCollection) { 231 NamedLineCollection& linesCollection) {
232 ASSERT(numberOfLines); 232 DCHECK(numberOfLines);
233 233
234 // Only implicit lines on the search direction are assumed to have the given 234 // Only implicit lines on the search direction are assumed to have the given
235 // name, so we can start to look from last line. 235 // name, so we can start to look from last line.
236 // See: https://drafts.csswg.org/css-grid/#grid-placement-span-int 236 // See: https://drafts.csswg.org/css-grid/#grid-placement-span-int
237 int start = std::min(end, gridLastLine); 237 int start = std::min(end, gridLastLine);
238 238
239 if (!linesCollection.hasNamedLines()) { 239 if (!linesCollection.hasNamedLines()) {
240 start = std::min(start, -1); 240 start = std::min(start, -1);
241 return start - numberOfLines + 1; 241 return start - numberOfLines + 1;
242 } 242 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 : GridPositionsResolver::explicitGridRowCount( 298 : GridPositionsResolver::explicitGridRowCount(
299 gridContainerStyle, autoRepeatTracksCount); 299 gridContainerStyle, autoRepeatTracksCount);
300 } 300 }
301 301
302 static GridSpan resolveNamedGridLinePositionAgainstOppositePosition( 302 static GridSpan resolveNamedGridLinePositionAgainstOppositePosition(
303 const ComputedStyle& gridContainerStyle, 303 const ComputedStyle& gridContainerStyle,
304 int oppositeLine, 304 int oppositeLine,
305 const GridPosition& position, 305 const GridPosition& position,
306 size_t autoRepeatTracksCount, 306 size_t autoRepeatTracksCount,
307 GridPositionSide side) { 307 GridPositionSide side) {
308 ASSERT(position.isSpan()); 308 DCHECK(position.isSpan());
309 ASSERT(!position.namedGridLine().isNull()); 309 DCHECK(!position.namedGridLine().isNull());
310 // Negative positions are not allowed per the specification and should have 310 // Negative positions are not allowed per the specification and should have
311 // been handled during parsing. 311 // been handled during parsing.
312 ASSERT(position.spanPosition() > 0); 312 DCHECK_GT(position.spanPosition(), 0);
313 313
314 size_t lastLine = 314 size_t lastLine =
315 explicitGridSizeForSide(gridContainerStyle, side, autoRepeatTracksCount); 315 explicitGridSizeForSide(gridContainerStyle, side, autoRepeatTracksCount);
316 NamedLineCollection linesCollection( 316 NamedLineCollection linesCollection(
317 gridContainerStyle, position.namedGridLine(), directionFromSide(side), 317 gridContainerStyle, position.namedGridLine(), directionFromSide(side),
318 lastLine, autoRepeatTracksCount); 318 lastLine, autoRepeatTracksCount);
319 return definiteGridSpanWithNamedSpanAgainstOpposite( 319 return definiteGridSpanWithNamedSpanAgainstOpposite(
320 oppositeLine, position, side, lastLine, linesCollection); 320 oppositeLine, position, side, lastLine, linesCollection);
321 } 321 }
322 322
(...skipping 17 matching lines...) Expand all
340 GridPositionSide side, 340 GridPositionSide side,
341 size_t autoRepeatTracksCount) { 341 size_t autoRepeatTracksCount) {
342 if (position.isAuto()) { 342 if (position.isAuto()) {
343 if (side == ColumnStartSide || side == RowStartSide) 343 if (side == ColumnStartSide || side == RowStartSide)
344 return GridSpan::untranslatedDefiniteGridSpan(oppositeLine - 1, 344 return GridSpan::untranslatedDefiniteGridSpan(oppositeLine - 1,
345 oppositeLine); 345 oppositeLine);
346 return GridSpan::untranslatedDefiniteGridSpan(oppositeLine, 346 return GridSpan::untranslatedDefiniteGridSpan(oppositeLine,
347 oppositeLine + 1); 347 oppositeLine + 1);
348 } 348 }
349 349
350 ASSERT(position.isSpan()); 350 DCHECK(position.isSpan());
351 ASSERT(position.spanPosition() > 0); 351 DCHECK_GT(position.spanPosition(), 0);
352 352
353 if (!position.namedGridLine().isNull()) { 353 if (!position.namedGridLine().isNull()) {
354 // span 2 'c' -> we need to find the appropriate grid line before / after 354 // span 2 'c' -> we need to find the appropriate grid line before / after
355 // our opposite position. 355 // our opposite position.
356 return resolveNamedGridLinePositionAgainstOppositePosition( 356 return resolveNamedGridLinePositionAgainstOppositePosition(
357 gridContainerStyle, oppositeLine, position, autoRepeatTracksCount, 357 gridContainerStyle, oppositeLine, position, autoRepeatTracksCount,
358 side); 358 side);
359 } 359 }
360 360
361 return definiteGridSpanWithSpanAgainstOpposite(oppositeLine, position, side); 361 return definiteGridSpanWithSpanAgainstOpposite(oppositeLine, position, side);
362 } 362 }
363 363
364 size_t GridPositionsResolver::spanSizeForAutoPlacedItem( 364 size_t GridPositionsResolver::spanSizeForAutoPlacedItem(
365 const ComputedStyle& gridContainerStyle, 365 const ComputedStyle& gridContainerStyle,
366 const LayoutBox& gridItem, 366 const LayoutBox& gridItem,
367 GridTrackSizingDirection direction) { 367 GridTrackSizingDirection direction) {
368 GridPosition initialPosition, finalPosition; 368 GridPosition initialPosition, finalPosition;
369 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, 369 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction,
370 initialPosition, finalPosition); 370 initialPosition, finalPosition);
371 371
372 // This method will only be used when both positions need to be resolved 372 // This method will only be used when both positions need to be resolved
373 // against the opposite one. 373 // against the opposite one.
374 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && 374 DCHECK(initialPosition.shouldBeResolvedAgainstOppositePosition() &&
tkent 2017/03/15 05:02:20 Please split it to two DCHEKS. DCHECK(initialPos
375 finalPosition.shouldBeResolvedAgainstOppositePosition()); 375 finalPosition.shouldBeResolvedAgainstOppositePosition());
376 376
377 if (initialPosition.isAuto() && finalPosition.isAuto()) 377 if (initialPosition.isAuto() && finalPosition.isAuto())
378 return 1; 378 return 1;
379 379
380 GridPosition position = 380 GridPosition position =
381 initialPosition.isSpan() ? initialPosition : finalPosition; 381 initialPosition.isSpan() ? initialPosition : finalPosition;
382 ASSERT(position.isSpan()); 382 DCHECK(position.isSpan());
383 ASSERT(position.spanPosition()); 383 DCHECK(position.spanPosition());
384 return position.spanPosition(); 384 return position.spanPosition();
385 } 385 }
386 386
387 static int resolveNamedGridLinePositionFromStyle( 387 static int resolveNamedGridLinePositionFromStyle(
388 const ComputedStyle& gridContainerStyle, 388 const ComputedStyle& gridContainerStyle,
389 const GridPosition& position, 389 const GridPosition& position,
390 GridPositionSide side, 390 GridPositionSide side,
391 size_t autoRepeatTracksCount) { 391 size_t autoRepeatTracksCount) {
392 ASSERT(!position.namedGridLine().isNull()); 392 DCHECK(!position.namedGridLine().isNull());
393 393
394 size_t lastLine = 394 size_t lastLine =
395 explicitGridSizeForSide(gridContainerStyle, side, autoRepeatTracksCount); 395 explicitGridSizeForSide(gridContainerStyle, side, autoRepeatTracksCount);
396 NamedLineCollection linesCollection( 396 NamedLineCollection linesCollection(
397 gridContainerStyle, position.namedGridLine(), directionFromSide(side), 397 gridContainerStyle, position.namedGridLine(), directionFromSide(side),
398 lastLine, autoRepeatTracksCount); 398 lastLine, autoRepeatTracksCount);
399 399
400 if (position.isPositive()) 400 if (position.isPositive())
401 return lookAheadForNamedGridLine(0, abs(position.integerPosition()), 401 return lookAheadForNamedGridLine(0, abs(position.integerPosition()),
402 lastLine, linesCollection); 402 lastLine, linesCollection);
403 403
404 return lookBackForNamedGridLine(lastLine, abs(position.integerPosition()), 404 return lookBackForNamedGridLine(lastLine, abs(position.integerPosition()),
405 lastLine, linesCollection); 405 lastLine, linesCollection);
406 } 406 }
407 407
408 static int resolveGridPositionFromStyle(const ComputedStyle& gridContainerStyle, 408 static int resolveGridPositionFromStyle(const ComputedStyle& gridContainerStyle,
409 const GridPosition& position, 409 const GridPosition& position,
410 GridPositionSide side, 410 GridPositionSide side,
411 size_t autoRepeatTracksCount) { 411 size_t autoRepeatTracksCount) {
412 switch (position.type()) { 412 switch (position.type()) {
413 case ExplicitPosition: { 413 case ExplicitPosition: {
414 ASSERT(position.integerPosition()); 414 DCHECK(position.integerPosition());
415 415
416 if (!position.namedGridLine().isNull()) 416 if (!position.namedGridLine().isNull())
417 return resolveNamedGridLinePositionFromStyle( 417 return resolveNamedGridLinePositionFromStyle(
418 gridContainerStyle, position, side, autoRepeatTracksCount); 418 gridContainerStyle, position, side, autoRepeatTracksCount);
419 419
420 // Handle <integer> explicit position. 420 // Handle <integer> explicit position.
421 if (position.isPositive()) 421 if (position.isPositive())
422 return position.integerPosition() - 1; 422 return position.integerPosition() - 1;
423 423
424 size_t resolvedPosition = abs(position.integerPosition()) - 1; 424 size_t resolvedPosition = abs(position.integerPosition()) - 1;
425 size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, side, 425 size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, side,
426 autoRepeatTracksCount); 426 autoRepeatTracksCount);
427 427
428 return endOfTrack - resolvedPosition; 428 return endOfTrack - resolvedPosition;
429 } 429 }
430 case NamedGridAreaPosition: { 430 case NamedGridAreaPosition: {
431 // First attempt to match the grid area's edge to a named grid area: if 431 // First attempt to match the grid area's edge to a named grid area: if
432 // there is a named line with the name ''<custom-ident>-start (for 432 // there is a named line with the name ''<custom-ident>-start (for
433 // grid-*-start) / <custom-ident>-end'' (for grid-*-end), contributes the 433 // grid-*-start) / <custom-ident>-end'' (for grid-*-end), contributes the
434 // first such line to the grid item's placement. 434 // first such line to the grid item's placement.
435 String namedGridLine = position.namedGridLine(); 435 String namedGridLine = position.namedGridLine();
436 ASSERT(!position.namedGridLine().isNull()); 436 DCHECK(!position.namedGridLine().isNull());
437 437
438 size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side, 438 size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side,
439 autoRepeatTracksCount); 439 autoRepeatTracksCount);
440 NamedLineCollection implicitLines( 440 NamedLineCollection implicitLines(
441 gridContainerStyle, implicitNamedGridLineForSide(namedGridLine, side), 441 gridContainerStyle, implicitNamedGridLineForSide(namedGridLine, side),
442 directionFromSide(side), lastLine, autoRepeatTracksCount); 442 directionFromSide(side), lastLine, autoRepeatTracksCount);
443 if (implicitLines.hasNamedLines()) 443 if (implicitLines.hasNamedLines())
444 return implicitLines.firstPosition(); 444 return implicitLines.firstPosition();
445 445
446 // Otherwise, if there is a named line with the specified name, 446 // Otherwise, if there is a named line with the specified name,
447 // contributes the first such line to the grid item's placement. 447 // contributes the first such line to the grid item's placement.
448 NamedLineCollection explicitLines(gridContainerStyle, namedGridLine, 448 NamedLineCollection explicitLines(gridContainerStyle, namedGridLine,
449 directionFromSide(side), lastLine, 449 directionFromSide(side), lastLine,
450 autoRepeatTracksCount); 450 autoRepeatTracksCount);
451 if (explicitLines.hasNamedLines()) 451 if (explicitLines.hasNamedLines())
452 return explicitLines.firstPosition(); 452 return explicitLines.firstPosition();
453 453
454 ASSERT(!NamedLineCollection::isValidNamedLineOrArea( 454 DCHECK(!NamedLineCollection::isValidNamedLineOrArea(
455 namedGridLine, gridContainerStyle, side)); 455 namedGridLine, gridContainerStyle, side));
456 // If none of the above works specs mandate to assume that all the lines 456 // If none of the above works specs mandate to assume that all the lines
457 // in the implicit grid have this name. 457 // in the implicit grid have this name.
458 return lastLine + 1; 458 return lastLine + 1;
459 } 459 }
460 case AutoPosition: 460 case AutoPosition:
461 case SpanPosition: 461 case SpanPosition:
462 // 'auto' and span depend on the opposite position for resolution (e.g. 462 // 'auto' and span depend on the opposite position for resolution (e.g.
463 // grid-row: auto / 1 or grid-column: span 3 / "myHeader"). 463 // grid-row: auto / 1 or grid-column: span 3 / "myHeader").
464 ASSERT_NOT_REACHED(); 464 NOTREACHED();
465 return 0; 465 return 0;
466 } 466 }
467 ASSERT_NOT_REACHED(); 467 NOTREACHED();
468 return 0; 468 return 0;
469 } 469 }
470 470
471 GridSpan GridPositionsResolver::resolveGridPositionsFromStyle( 471 GridSpan GridPositionsResolver::resolveGridPositionsFromStyle(
472 const ComputedStyle& gridContainerStyle, 472 const ComputedStyle& gridContainerStyle,
473 const LayoutBox& gridItem, 473 const LayoutBox& gridItem,
474 GridTrackSizingDirection direction, 474 GridTrackSizingDirection direction,
475 size_t autoRepeatTracksCount) { 475 size_t autoRepeatTracksCount) {
476 GridPosition initialPosition, finalPosition; 476 GridPosition initialPosition, finalPosition;
477 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, 477 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 515
516 if (endLine < startLine) 516 if (endLine < startLine)
517 std::swap(endLine, startLine); 517 std::swap(endLine, startLine);
518 else if (endLine == startLine) 518 else if (endLine == startLine)
519 endLine = startLine + 1; 519 endLine = startLine + 1;
520 520
521 return GridSpan::untranslatedDefiniteGridSpan(startLine, endLine); 521 return GridSpan::untranslatedDefiniteGridSpan(startLine, endLine);
522 } 522 }
523 523
524 } // namespace blink 524 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698