OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. | 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. |
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2124 marginStart = std::max(LayoutUnit(), marginStartWidth); | 2124 marginStart = std::max(LayoutUnit(), marginStartWidth); |
2125 marginEnd = std::max(LayoutUnit(), marginEndWidth); | 2125 marginEnd = std::max(LayoutUnit(), marginEndWidth); |
2126 } | 2126 } |
2127 } | 2127 } |
2128 | 2128 |
2129 // CSS 2.1 (10.3.3): "If 'width' is not 'auto' and 'border-left-width' + 'pa dding-left' + 'width' + 'padding-right' + 'border-right-width' | 2129 // CSS 2.1 (10.3.3): "If 'width' is not 'auto' and 'border-left-width' + 'pa dding-left' + 'width' + 'padding-right' + 'border-right-width' |
2130 // (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larg er than the width of the containing block, then any 'auto' | 2130 // (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larg er than the width of the containing block, then any 'auto' |
2131 // values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero. | 2131 // values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero. |
2132 LayoutUnit marginBoxWidth = childWidth + (!style()->width().isAuto() ? margi nStartWidth + marginEndWidth : LayoutUnit()); | 2132 LayoutUnit marginBoxWidth = childWidth + (!style()->width().isAuto() ? margi nStartWidth + marginEndWidth : LayoutUnit()); |
2133 | 2133 |
2134 // CSS 2.1: "If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element | 2134 if (marginBoxWidth < availableWidth) { |
2135 // with respect to the edges of the containing block." | 2135 // CSS 2.1: "If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element |
2136 const RenderStyle* containingBlockStyle = containingBlock->style(); | 2136 // with respect to the edges of the containing block." |
2137 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && marginBoxWidt h < availableWidth) | 2137 const RenderStyle* containingBlockStyle = containingBlock->style(); |
2138 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containi ngBlockStyle->textAlign() == WEBKIT_CENTER)) { | 2138 if ((marginStartLength.isAuto() && marginEndLength.isAuto()) |
2139 // Other browsers center the margin box for align=center elements so we match them here. | 2139 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && cont ainingBlockStyle->textAlign() == WEBKIT_CENTER)) { |
2140 LayoutUnit centeredMarginBoxStart = std::max(LayoutUnit(), (availableWid th - childWidth - marginStartWidth - marginEndWidth) / 2); | 2140 // Other browsers center the margin box for align=center elements so we match them here. |
2141 marginStart = centeredMarginBoxStart + marginStartWidth; | 2141 LayoutUnit centeredMarginBoxStart = std::max(LayoutUnit(), (availabl eWidth - childWidth - marginStartWidth - marginEndWidth) / 2); |
2142 marginEnd = availableWidth - childWidth - marginStart + marginEndWidth; | 2142 marginStart = centeredMarginBoxStart + marginStartWidth; |
2143 return; | 2143 marginEnd = availableWidth - childWidth - marginStart + marginEndWid th; |
2144 } | 2144 return; |
2145 } | |
2145 | 2146 |
2146 // CSS 2.1: "If there is exactly one value specified as 'auto', its used val ue follows from the equality." | 2147 // Adjust margins from textAlign |
mstensho (USE GERRIT)
2014/12/11 09:01:02
Might as well say "Adjust margins for the align at
| |
2147 if (marginEndLength.isAuto() && marginBoxWidth < availableWidth) { | 2148 if ((!containingBlockStyle->isLeftToRightDirection() && containingBlockS tyle->textAlign() == WEBKIT_LEFT) |
2148 marginStart = marginStartWidth; | 2149 || (containingBlockStyle->isLeftToRightDirection() && containingBloc kStyle->textAlign() == WEBKIT_RIGHT)) { |
2149 marginEnd = availableWidth - childWidth - marginStart; | 2150 if (containingBlockStyle->isLeftToRightDirection() != style()->isLef tToRightDirection()) { |
2150 return; | 2151 if (!marginStartLength.isAuto()) |
2151 } | 2152 marginEndLength = Length(Auto); |
2153 } else { | |
2154 if (!marginEndLength.isAuto()) | |
2155 marginStartLength = Length(Auto); | |
2156 } | |
2157 } | |
2152 | 2158 |
2153 bool adjustFromTextAlign = !marginEndLength.isAuto() && ((!containingBlockSt yle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_LEF T) | 2159 // CSS 2.1: "If there is exactly one value specified as 'auto', its used value follows from the equality." |
2154 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT)); | 2160 if (marginEndLength.isAuto()) { |
2155 bool hasInvertedDirection = containingBlockStyle->isLeftToRightDirection() ! = style()->isLeftToRightDirection(); | 2161 marginStart = marginStartWidth; |
2162 marginEnd = availableWidth - childWidth - marginStart; | |
2163 return; | |
2164 } | |
2156 | 2165 |
2157 if ((marginStartLength.isAuto() && marginBoxWidth < availableWidth) || (adju stFromTextAlign && !hasInvertedDirection)) { | 2166 if (marginStartLength.isAuto()) { |
2158 marginEnd = marginEndWidth; | 2167 marginEnd = marginEndWidth; |
2159 marginStart = availableWidth - childWidth - marginEnd; | 2168 marginStart = availableWidth - childWidth - marginEnd; |
2160 return; | 2169 return; |
2161 } | 2170 } |
2162 | |
2163 if (adjustFromTextAlign && hasInvertedDirection) { | |
2164 marginStart = marginStartWidth; | |
2165 marginEnd = availableWidth - childWidth - marginStart; | |
2166 return; | |
2167 } | 2171 } |
2168 | 2172 |
2169 // Either no auto margins, or our margin box width is >= the container width , auto margins will just turn into 0. | 2173 // Either no auto margins, or our margin box width is >= the container width , auto margins will just turn into 0. |
2170 marginStart = marginStartWidth; | 2174 marginStart = marginStartWidth; |
2171 marginEnd = marginEndWidth; | 2175 marginEnd = marginEndWidth; |
2172 } | 2176 } |
2173 | 2177 |
2174 void RenderBox::updateLogicalHeight() | 2178 void RenderBox::updateLogicalHeight() |
2175 { | 2179 { |
2176 m_intrinsicContentLogicalHeight = contentLogicalHeight(); | 2180 m_intrinsicContentLogicalHeight = contentLogicalHeight(); |
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4492 computedValues.m_margins.m_end = marginEnd(); | 4496 computedValues.m_margins.m_end = marginEnd(); |
4493 | 4497 |
4494 setLogicalTop(oldLogicalTop); | 4498 setLogicalTop(oldLogicalTop); |
4495 setLogicalWidth(oldLogicalWidth); | 4499 setLogicalWidth(oldLogicalWidth); |
4496 setLogicalLeft(oldLogicalLeft); | 4500 setLogicalLeft(oldLogicalLeft); |
4497 setMarginLeft(oldMarginLeft); | 4501 setMarginLeft(oldMarginLeft); |
4498 setMarginRight(oldMarginRight); | 4502 setMarginRight(oldMarginRight); |
4499 } | 4503 } |
4500 | 4504 |
4501 } // namespace blink | 4505 } // namespace blink |
OLD | NEW |