OLD | NEW |
---|---|
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 2867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2878 if (marginBefore.isAuto() && marginAfter.isAuto()) { | 2878 if (marginBefore.isAuto() && marginAfter.isAuto()) { |
2879 child.setMarginBefore(availableAlignmentSpace / 2, style()); | 2879 child.setMarginBefore(availableAlignmentSpace / 2, style()); |
2880 child.setMarginAfter(availableAlignmentSpace / 2, style()); | 2880 child.setMarginAfter(availableAlignmentSpace / 2, style()); |
2881 } else if (marginBefore.isAuto()) { | 2881 } else if (marginBefore.isAuto()) { |
2882 child.setMarginBefore(availableAlignmentSpace, style()); | 2882 child.setMarginBefore(availableAlignmentSpace, style()); |
2883 } else if (marginAfter.isAuto()) { | 2883 } else if (marginAfter.isAuto()) { |
2884 child.setMarginAfter(availableAlignmentSpace, style()); | 2884 child.setMarginAfter(availableAlignmentSpace, style()); |
2885 } | 2885 } |
2886 } | 2886 } |
2887 | 2887 |
2888 LayoutUnit LayoutGrid::firstLineBoxBaselineForChild( | |
cbiesinger
2016/10/19 20:57:59
Are you calling this function anywhere...?
jfernandez
2016/10/20 09:07:14
Umm, you're right. This function will be used late
| |
2889 const LayoutBox& child) const { | |
2890 LayoutUnit baseline(child.firstLineBoxBaseline()); | |
2891 // We take content-box's bottom if no valid baseline. | |
cbiesinger
2016/10/19 20:57:59
But you're actually calculating the border-box bot
jfernandez
2016/10/20 09:07:14
umm, as far as I know, LayoutBlock::logicalHeightF
cbiesinger
2016/10/20 17:42:36
No, size().height() (and logicalHeight()) all refe
jfernandez
2016/10/20 22:13:23
Oh, I was so confused about this. I'll think about
| |
2892 if (baseline == -1) | |
2893 baseline = LayoutBlock::logicalHeightForChild(child); | |
2894 return baseline + marginBeforeForChild(child); | |
2895 } | |
2896 | |
2897 static int synthesizedBaselineFromContentBox(const LayoutBox& box, | |
2898 LineDirectionMode direction) { | |
2899 if (direction == HorizontalLine) { | |
2900 return (box.size().height() - box.borderBottom() - box.paddingBottom() - | |
2901 box.verticalScrollbarWidth()) | |
2902 .toInt(); | |
2903 } | |
2904 return (box.size().width() - box.borderLeft() - box.paddingLeft() - | |
2905 box.horizontalScrollbarHeight()) | |
2906 .toInt(); | |
2907 } | |
2908 | |
2909 int LayoutGrid::baselinePosition(FontBaseline, | |
2910 bool, | |
2911 LineDirectionMode direction, | |
2912 LinePositionMode mode) const { | |
2913 DCHECK(mode == PositionOnContainingLine); | |
cbiesinger
2016/10/19 20:57:59
DCHECK_EQ
jfernandez
2016/10/20 09:07:14
Done.
| |
2914 int baseline = firstLineBoxBaseline(); | |
2915 // We take content-box's bottom if no valid baseline. | |
2916 if (baseline == -1) | |
2917 baseline = synthesizedBaselineFromContentBox(*this, direction); | |
2918 | |
2919 return baseline + beforeMarginInLineDirection(direction); | |
2920 } | |
2921 | |
2922 int LayoutGrid::firstLineBoxBaseline() const { | |
2923 if (isWritingModeRoot()) | |
2924 return -1; | |
2925 const LayoutBox* baselineChild = nullptr; | |
2926 for (const LayoutBox* child = m_orderIterator.first(); child; | |
2927 child = m_orderIterator.next()) { | |
2928 if (child->isOutOfFlowPositioned()) | |
2929 continue; | |
2930 const GridSpan& rowsSpan = cachedGridSpan(*child, ForRows); | |
2931 // TODO (lajava): propertly identifying grid items whose areas | |
2932 // intersect the grid container's first row. | |
2933 if (rowsSpan.startLine() > 0) | |
2934 continue; | |
2935 ItemPosition align = alignSelfForChild(*child).position(); | |
2936 // Orthogonal children don't participate in baseline alignment. | |
2937 if (align == ItemPositionBaseline && !isOrthogonalChild(*child) && | |
2938 !hasAutoMarginsInColumnAxis(*child)) { | |
2939 // TODO (lajava): self-baseline and content-baseline alignment | |
2940 // still not implemented. | |
2941 baselineChild = child; | |
2942 break; | |
2943 } | |
2944 if (!baselineChild) | |
2945 baselineChild = child; | |
2946 } | |
2947 | |
2948 if (!baselineChild) | |
2949 return -1; | |
2950 | |
2951 if (isOrthogonalChild(*baselineChild)) { | |
2952 return ((isHorizontalWritingMode() ? baselineChild->size().height() | |
2953 : baselineChild->size().width()) + | |
2954 baselineChild->logicalTop()) | |
2955 .toInt(); | |
2956 } | |
2957 | |
2958 int baseline = baselineChild->firstLineBoxBaseline(); | |
2959 if (baseline == -1) { | |
2960 // TODO (lajava): We should pass |direction| into | |
2961 // firstLineBoxBaseline and stop bailing out if we're a writing | |
2962 // mode root. This would also fix some cases where the grid is | |
2963 // orthogonal to its container. | |
2964 LineDirectionMode direction = | |
2965 isHorizontalWritingMode() ? HorizontalLine : VerticalLine; | |
2966 return (synthesizedBaselineFromContentBox(*baselineChild, direction) + | |
2967 baselineChild->logicalTop()) | |
2968 .toInt(); | |
2969 } | |
2970 | |
2971 return (baseline + baselineChild->logicalTop()).toInt(); | |
2972 } | |
2973 | |
2974 int LayoutGrid::inlineBlockBaseline(LineDirectionMode direction) const { | |
2975 int baseline = firstLineBoxBaseline(); | |
2976 if (baseline != -1) | |
2977 return baseline; | |
2978 | |
2979 int marginHeight = | |
2980 (direction == HorizontalLine ? marginTop() : marginRight()).toInt(); | |
2981 return synthesizedBaselineFromContentBox(*this, direction) + marginHeight; | |
2982 } | |
2983 | |
2888 GridAxisPosition LayoutGrid::columnAxisPositionForChild( | 2984 GridAxisPosition LayoutGrid::columnAxisPositionForChild( |
2889 const LayoutBox& child) const { | 2985 const LayoutBox& child) const { |
2890 bool hasSameWritingMode = | 2986 bool hasSameWritingMode = |
2891 child.styleRef().getWritingMode() == styleRef().getWritingMode(); | 2987 child.styleRef().getWritingMode() == styleRef().getWritingMode(); |
2892 bool childIsLTR = child.styleRef().isLeftToRightDirection(); | 2988 bool childIsLTR = child.styleRef().isLeftToRightDirection(); |
2893 | 2989 |
2894 switch (alignSelfForChild(child).position()) { | 2990 switch (alignSelfForChild(child).position()) { |
2895 case ItemPositionSelfStart: | 2991 case ItemPositionSelfStart: |
2896 // TODO (lajava): Should we implement this logic in a generic utility | 2992 // TODO (lajava): Should we implement this logic in a generic utility |
2897 // function? | 2993 // function? |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3308 if (!m_gridItemArea.isEmpty()) | 3404 if (!m_gridItemArea.isEmpty()) |
3309 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 3405 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
3310 } | 3406 } |
3311 | 3407 |
3312 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { | 3408 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { |
3313 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); | 3409 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); |
3314 return m_hasDefiniteLogicalHeight.value(); | 3410 return m_hasDefiniteLogicalHeight.value(); |
3315 } | 3411 } |
3316 | 3412 |
3317 } // namespace blink | 3413 } // namespace blink |
OLD | NEW |