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

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 for landing. Created 4 years, 2 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 /* 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 2882 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 if (marginBefore.isAuto() && marginAfter.isAuto()) { 2893 if (marginBefore.isAuto() && marginAfter.isAuto()) {
2894 child.setMarginBefore(availableAlignmentSpace / 2, style()); 2894 child.setMarginBefore(availableAlignmentSpace / 2, style());
2895 child.setMarginAfter(availableAlignmentSpace / 2, style()); 2895 child.setMarginAfter(availableAlignmentSpace / 2, style());
2896 } else if (marginBefore.isAuto()) { 2896 } else if (marginBefore.isAuto()) {
2897 child.setMarginBefore(availableAlignmentSpace, style()); 2897 child.setMarginBefore(availableAlignmentSpace, style());
2898 } else if (marginAfter.isAuto()) { 2898 } else if (marginAfter.isAuto()) {
2899 child.setMarginAfter(availableAlignmentSpace, style()); 2899 child.setMarginAfter(availableAlignmentSpace, style());
2900 } 2900 }
2901 } 2901 }
2902 2902
2903 static int synthesizedBaselineFromContentBox(const LayoutBox& box,
2904 LineDirectionMode direction) {
2905 if (direction == HorizontalLine) {
2906 return (box.size().height() - box.borderBottom() - box.paddingBottom() -
2907 box.verticalScrollbarWidth())
svillar 2016/10/21 12:53:06 Why aren't you directly using contentHeight() ?
jfernandez 2016/10/26 14:22:31 Well, we don't want contentHeight, but the distanc
2908 .toInt();
2909 }
2910 return (box.size().width() - box.borderLeft() - box.paddingLeft() -
2911 box.horizontalScrollbarHeight())
svillar 2016/10/21 12:53:06 Why aren't you directly using contentWidth() ?
jfernandez 2016/10/26 14:22:31 Ditto.
2912 .toInt();
2913 }
2914
2915 int LayoutGrid::baselinePosition(FontBaseline,
2916 bool,
2917 LineDirectionMode direction,
2918 LinePositionMode mode) const {
Manuel Rego 2016/10/25 19:42:09 This is the same code than flexbox, probably it'd
jfernandez 2016/10/26 14:22:31 Acknowledged.
2919 DCHECK_EQ(mode, PositionOnContainingLine);
2920 int baseline = firstLineBoxBaseline();
2921 // We take content-box's bottom if no valid baseline.
2922 if (baseline == -1)
2923 baseline = synthesizedBaselineFromContentBox(*this, direction);
2924
2925 return baseline + beforeMarginInLineDirection(direction);
2926 }
2927
2928 int LayoutGrid::firstLineBoxBaseline() const {
2929 if (isWritingModeRoot())
2930 return -1;
2931 const LayoutBox* baselineChild = nullptr;
2932 for (const LayoutBox* child = m_orderIterator.first(); child;
svillar 2016/10/21 12:53:06 This is order-modified document order not grid-mod
Manuel Rego 2016/10/25 19:42:09 Yeah you should check the things in the first row
jfernandez 2016/10/26 14:22:31 Done.
2933 child = m_orderIterator.next()) {
2934 if (child->isOutOfFlowPositioned())
2935 continue;
2936 const GridSpan& rowsSpan = cachedGridSpan(*child, ForRows);
2937 // TODO (lajava): propertly identifying grid items whose areas
2938 // intersect the grid container's first row.
2939 if (rowsSpan.startLine() > 0)
2940 continue;
2941 ItemPosition align = alignSelfForChild(*child).position();
2942 // Orthogonal children don't participate in baseline alignment.
2943 if (align == ItemPositionBaseline && !isOrthogonalChild(*child) &&
2944 !hasAutoMarginsInColumnAxis(*child)) {
2945 // TODO (lajava): self-baseline and content-baseline alignment
2946 // still not implemented.
2947 baselineChild = child;
2948 break;
2949 }
2950 if (!baselineChild)
2951 baselineChild = child;
2952 }
2953
2954 if (!baselineChild)
2955 return -1;
2956
2957 if (isOrthogonalChild(*baselineChild)) {
2958 return ((isHorizontalWritingMode() ? baselineChild->size().height()
2959 : baselineChild->size().width()) +
2960 baselineChild->logicalTop())
2961 .toInt();
2962 }
2963
2964 int baseline = baselineChild->firstLineBoxBaseline();
2965 if (baseline == -1) {
2966 // TODO (lajava): We should pass |direction| into
2967 // firstLineBoxBaseline and stop bailing out if we're a writing
2968 // mode root. This would also fix some cases where the grid is
2969 // orthogonal to its container.
2970 LineDirectionMode direction =
2971 isHorizontalWritingMode() ? HorizontalLine : VerticalLine;
2972 return (synthesizedBaselineFromContentBox(*baselineChild, direction) +
2973 baselineChild->logicalTop())
2974 .toInt();
2975 }
2976
2977 return (baseline + baselineChild->logicalTop()).toInt();
2978 }
2979
2980 int LayoutGrid::inlineBlockBaseline(LineDirectionMode direction) const {
Manuel Rego 2016/10/25 19:42:09 Again same code than flexbox, please add a comment
jfernandez 2016/10/26 14:22:31 Acknowledged.
2981 int baseline = firstLineBoxBaseline();
2982 if (baseline != -1)
2983 return baseline;
2984
2985 int marginHeight =
2986 (direction == HorizontalLine ? marginTop() : marginRight()).toInt();
2987 return synthesizedBaselineFromContentBox(*this, direction) + marginHeight;
2988 }
2989
2903 GridAxisPosition LayoutGrid::columnAxisPositionForChild( 2990 GridAxisPosition LayoutGrid::columnAxisPositionForChild(
2904 const LayoutBox& child) const { 2991 const LayoutBox& child) const {
2905 bool hasSameWritingMode = 2992 bool hasSameWritingMode =
2906 child.styleRef().getWritingMode() == styleRef().getWritingMode(); 2993 child.styleRef().getWritingMode() == styleRef().getWritingMode();
2907 bool childIsLTR = child.styleRef().isLeftToRightDirection(); 2994 bool childIsLTR = child.styleRef().isLeftToRightDirection();
2908 2995
2909 switch (alignSelfForChild(child).position()) { 2996 switch (alignSelfForChild(child).position()) {
2910 case ItemPositionSelfStart: 2997 case ItemPositionSelfStart:
2911 // TODO (lajava): Should we implement this logic in a generic utility 2998 // TODO (lajava): Should we implement this logic in a generic utility
2912 // function? 2999 // function?
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 if (!m_gridItemArea.isEmpty()) 3410 if (!m_gridItemArea.isEmpty())
3324 GridPainter(*this).paintChildren(paintInfo, paintOffset); 3411 GridPainter(*this).paintChildren(paintInfo, paintOffset);
3325 } 3412 }
3326 3413
3327 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { 3414 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const {
3328 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); 3415 SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
3329 return m_hasDefiniteLogicalHeight.value(); 3416 return m_hasDefiniteLogicalHeight.value();
3330 } 3417 }
3331 3418
3332 } // namespace blink 3419 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698