Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutFieldset.cpp
blobd67632e5a97c2ab4fe423dc463d65aa4c4fbb8dc
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include "config.h"
25 #include "core/layout/LayoutFieldset.h"
27 #include "core/CSSPropertyNames.h"
28 #include "core/HTMLNames.h"
29 #include "core/html/HTMLLegendElement.h"
30 #include "core/paint/FieldsetPainter.h"
32 using namespace std;
34 namespace blink {
36 using namespace HTMLNames;
38 LayoutFieldset::LayoutFieldset(Element* element)
39 : LayoutBlockFlow(element)
43 void LayoutFieldset::computePreferredLogicalWidths()
45 LayoutBlockFlow::computePreferredLogicalWidths();
46 if (LayoutBox* legend = findInFlowLegend()) {
47 int legendMinWidth = legend->minPreferredLogicalWidth();
49 Length legendMarginLeft = legend->style()->marginLeft();
50 Length legendMarginRight = legend->style()->marginLeft();
52 if (legendMarginLeft.isFixed())
53 legendMinWidth += legendMarginLeft.value();
55 if (legendMarginRight.isFixed())
56 legendMinWidth += legendMarginRight.value();
58 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, legendMinWidth + borderAndPaddingWidth());
62 LayoutObject* LayoutFieldset::layoutSpecialExcludedChild(bool relayoutChildren, SubtreeLayoutScope&)
64 LayoutBox* legend = findInFlowLegend();
65 if (legend) {
66 LayoutRect oldLegendFrameRect = legend->frameRect();
68 if (relayoutChildren)
69 legend->setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::FieldsetChanged);
70 legend->layoutIfNeeded();
72 LayoutUnit logicalLeft;
73 if (style()->isLeftToRightDirection()) {
74 switch (legend->style()->textAlign()) {
75 case CENTER:
76 logicalLeft = (logicalWidth() - logicalWidthForChild(*legend)) / 2;
77 break;
78 case RIGHT:
79 logicalLeft = logicalWidth() - borderEnd() - paddingEnd() - logicalWidthForChild(*legend);
80 break;
81 default:
82 logicalLeft = borderStart() + paddingStart() + marginStartForChild(*legend);
83 break;
85 } else {
86 switch (legend->style()->textAlign()) {
87 case LEFT:
88 logicalLeft = borderStart() + paddingStart();
89 break;
90 case CENTER: {
91 // Make sure that the extra pixel goes to the end side in RTL (since it went to the end side
92 // in LTR).
93 LayoutUnit centeredWidth = logicalWidth() - logicalWidthForChild(*legend);
94 logicalLeft = centeredWidth - centeredWidth / 2;
95 break;
97 default:
98 logicalLeft = logicalWidth() - borderStart() - paddingStart() - marginStartForChild(*legend) - logicalWidthForChild(*legend);
99 break;
103 setLogicalLeftForChild(*legend, logicalLeft);
105 LayoutUnit fieldsetBorderBefore = borderBefore();
106 LayoutUnit legendLogicalHeight = logicalHeightForChild(*legend);
108 LayoutUnit legendLogicalTop;
109 LayoutUnit collapsedLegendExtent;
110 // FIXME: We need to account for the legend's margin before too.
111 if (fieldsetBorderBefore > legendLogicalHeight) {
112 // The <legend> is smaller than the associated fieldset before border
113 // so the latter determines positioning of the <legend>. The sizing depends
114 // on the legend's margins as we want to still follow the author's cues.
115 // Firefox completely ignores the margins in this case which seems wrong.
116 legendLogicalTop = (fieldsetBorderBefore - legendLogicalHeight) / 2;
117 collapsedLegendExtent = max<LayoutUnit>(fieldsetBorderBefore, legendLogicalTop + legendLogicalHeight + marginAfterForChild(*legend));
118 } else {
119 collapsedLegendExtent = legendLogicalHeight + marginAfterForChild(*legend);
122 setLogicalTopForChild(*legend, legendLogicalTop);
123 setLogicalHeight(paddingBefore() + collapsedLegendExtent);
125 if (legend->frameRect() != oldLegendFrameRect) {
126 // We need to invalidate the fieldset border if the legend's frame changed.
127 setShouldDoFullPaintInvalidation();
130 return legend;
133 LayoutBox* LayoutFieldset::findInFlowLegend() const
135 for (LayoutObject* legend = firstChild(); legend; legend = legend->nextSibling()) {
136 if (legend->isFloatingOrOutOfFlowPositioned())
137 continue;
139 if (isHTMLLegendElement(legend->node()))
140 return toLayoutBox(legend);
142 return nullptr;
145 void LayoutFieldset::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
147 FieldsetPainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset);
150 void LayoutFieldset::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
152 FieldsetPainter(*this).paintMask(paintInfo, paintOffset);
155 } // namespace blink