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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 2417853002: [css-grid] Implementing the grid's first line baseline. (Closed)
Patch Set: Patch rebased. Created 4 years, 1 month 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 | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | 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) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 2888 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 if (marginBefore.isAuto() && marginAfter.isAuto()) { 2899 if (marginBefore.isAuto() && marginAfter.isAuto()) {
2900 child.setMarginBefore(availableAlignmentSpace / 2, style()); 2900 child.setMarginBefore(availableAlignmentSpace / 2, style());
2901 child.setMarginAfter(availableAlignmentSpace / 2, style()); 2901 child.setMarginAfter(availableAlignmentSpace / 2, style());
2902 } else if (marginBefore.isAuto()) { 2902 } else if (marginBefore.isAuto()) {
2903 child.setMarginBefore(availableAlignmentSpace, style()); 2903 child.setMarginBefore(availableAlignmentSpace, style());
2904 } else if (marginAfter.isAuto()) { 2904 } else if (marginAfter.isAuto()) {
2905 child.setMarginAfter(availableAlignmentSpace, style()); 2905 child.setMarginAfter(availableAlignmentSpace, style());
2906 } 2906 }
2907 } 2907 }
2908 2908
2909 // TODO(lajava): This logic is shared by LayoutFlexibleBox, so it might be
2910 // refactored somehow.
2911 static int synthesizedBaselineFromContentBox(const LayoutBox& box,
2912 LineDirectionMode direction) {
2913 if (direction == HorizontalLine) {
2914 return (box.size().height() - box.borderBottom() - box.paddingBottom() -
2915 box.horizontalScrollbarHeight())
2916 .toInt();
2917 }
2918 return (box.size().width() - box.borderLeft() - box.paddingLeft() -
2919 box.verticalScrollbarWidth())
2920 .toInt();
2921 }
2922
2923 static int synthesizedBaselineFromBorderBox(const LayoutBox& box,
2924 LineDirectionMode direction) {
2925 return (direction == HorizontalLine ? box.size().height()
2926 : box.size().width())
2927 .toInt();
2928 }
2929
2930 // TODO(lajava): This logic is shared by LayoutFlexibleBox, so it might be
2931 // refactored somehow.
2932 int LayoutGrid::baselinePosition(FontBaseline,
2933 bool,
2934 LineDirectionMode direction,
2935 LinePositionMode mode) const {
2936 DCHECK_EQ(mode, PositionOnContainingLine);
2937 int baseline = firstLineBoxBaseline();
2938 // We take content-box's bottom if no valid baseline.
2939 if (baseline == -1)
2940 baseline = synthesizedBaselineFromContentBox(*this, direction);
2941
2942 return baseline + beforeMarginInLineDirection(direction);
2943 }
2944
2945 bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const {
2946 return alignSelfForChild(*child).position() == ItemPositionBaseline &&
2947 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child);
2948 }
2949
2950 int LayoutGrid::firstLineBoxBaseline() const {
2951 if (isWritingModeRoot() || m_grid.isEmpty())
2952 return -1;
2953 const LayoutBox* baselineChild = nullptr;
2954 const LayoutBox* firstChild = nullptr;
2955 bool isBaselineAligned = false;
2956 // Finding the first grid item in grid order.
2957 for (size_t column = 0; !isBaselineAligned && column < m_grid[0].size();
2958 column++) {
2959 for (size_t index = 0; index < m_grid[0][column].size(); index++) {
2960 const LayoutBox* child = m_grid[0][column][index];
2961 DCHECK(!child->isOutOfFlowPositioned());
2962 // If an item participates in baseline alignmen, we select such item.
2963 if (isInlineBaselineAlignedChild(child)) {
2964 // TODO (lajava): self-baseline and content-baseline alignment
2965 // still not implemented.
2966 baselineChild = child;
2967 isBaselineAligned = true;
2968 break;
2969 }
2970 if (!baselineChild) {
2971 // Use dom order for items in the same cell.
2972 if (!firstChild || (m_gridItemsIndexesMap.get(child) <
2973 m_gridItemsIndexesMap.get(firstChild)))
2974 firstChild = child;
2975 }
2976 }
2977 if (!baselineChild && firstChild)
2978 baselineChild = firstChild;
2979 }
2980
2981 if (!baselineChild)
2982 return -1;
2983
2984 int baseline = isOrthogonalChild(*baselineChild)
2985 ? -1
2986 : baselineChild->firstLineBoxBaseline();
2987 // We take border-box's bottom if no valid baseline.
2988 if (baseline == -1) {
2989 // TODO (lajava): We should pass |direction| into
2990 // firstLineBoxBaseline and stop bailing out if we're a writing
2991 // mode root. This would also fix some cases where the grid is
2992 // orthogonal to its container.
2993 LineDirectionMode direction =
2994 isHorizontalWritingMode() ? HorizontalLine : VerticalLine;
2995 return (synthesizedBaselineFromBorderBox(*baselineChild, direction) +
2996 baselineChild->logicalTop())
2997 .toInt();
2998 }
2999
3000 return (baseline + baselineChild->logicalTop()).toInt();
3001 }
3002
3003 int LayoutGrid::inlineBlockBaseline(LineDirectionMode direction) const {
3004 int baseline = firstLineBoxBaseline();
3005 if (baseline != -1)
3006 return baseline;
3007
3008 int marginHeight =
3009 (direction == HorizontalLine ? marginTop() : marginRight()).toInt();
3010 return synthesizedBaselineFromContentBox(*this, direction) + marginHeight;
3011 }
3012
2909 GridAxisPosition LayoutGrid::columnAxisPositionForChild( 3013 GridAxisPosition LayoutGrid::columnAxisPositionForChild(
2910 const LayoutBox& child) const { 3014 const LayoutBox& child) const {
2911 bool hasSameWritingMode = 3015 bool hasSameWritingMode =
2912 child.styleRef().getWritingMode() == styleRef().getWritingMode(); 3016 child.styleRef().getWritingMode() == styleRef().getWritingMode();
2913 bool childIsLTR = child.styleRef().isLeftToRightDirection(); 3017 bool childIsLTR = child.styleRef().isLeftToRightDirection();
2914 3018
2915 switch (alignSelfForChild(child).position()) { 3019 switch (alignSelfForChild(child).position()) {
2916 case ItemPositionSelfStart: 3020 case ItemPositionSelfStart:
2917 // TODO (lajava): Should we implement this logic in a generic utility 3021 // TODO (lajava): Should we implement this logic in a generic utility
2918 // function? 3022 // function?
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
3332 if (!m_gridItemArea.isEmpty()) 3436 if (!m_gridItemArea.isEmpty())
3333 GridPainter(*this).paintChildren(paintInfo, paintOffset); 3437 GridPainter(*this).paintChildren(paintInfo, paintOffset);
3334 } 3438 }
3335 3439
3336 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { 3440 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const {
3337 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); 3441 SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
3338 return m_hasDefiniteLogicalHeight.value(); 3442 return m_hasDefiniteLogicalHeight.value();
3339 } 3443 }
3340 3444
3341 } // namespace blink 3445 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698