2 * Copyright (C) 2005 Apple Computer, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "core/layout/LayoutButton.h"
26 using namespace HTMLNames
;
28 LayoutButton::LayoutButton(Element
* element
)
29 : LayoutFlexibleBox(element
)
34 LayoutButton::~LayoutButton()
38 void LayoutButton::addChild(LayoutObject
* newChild
, LayoutObject
* beforeChild
)
41 // Create an anonymous block.
42 ASSERT(!firstChild());
43 m_inner
= createAnonymousBlock(style()->display());
44 LayoutFlexibleBox::addChild(m_inner
);
47 m_inner
->addChild(newChild
, beforeChild
);
50 void LayoutButton::removeChild(LayoutObject
* oldChild
)
52 if (oldChild
== m_inner
|| !m_inner
) {
53 LayoutFlexibleBox::removeChild(oldChild
);
56 } else if (oldChild
->parent() == this) {
57 // We aren't the inner node, but we're getting removed from the button, this
58 // can happen with things like scrollable area resizer's.
59 LayoutFlexibleBox::removeChild(oldChild
);
62 m_inner
->removeChild(oldChild
);
66 void LayoutButton::updateAnonymousChildStyle(const LayoutObject
& child
, ComputedStyle
& childStyle
) const
68 ASSERT(!m_inner
|| &child
== m_inner
);
70 childStyle
.setFlexGrow(1.0f
);
71 // min-width: 0; is needed for correct shrinking.
72 childStyle
.setMinWidth(Length(0, Fixed
));
73 // Use margin:auto instead of align-items:center to get safe centering, i.e.
74 // when the content overflows, treat it the same as align-items: flex-start.
75 childStyle
.setMarginTop(Length());
76 childStyle
.setMarginBottom(Length());
77 childStyle
.setFlexDirection(style()->flexDirection());
78 childStyle
.setJustifyContent(style()->justifyContent());
79 childStyle
.setFlexWrap(style()->flexWrap());
80 childStyle
.setAlignItems(style()->alignItems());
81 childStyle
.setAlignContent(style()->alignContent());
84 LayoutRect
LayoutButton::controlClipRect(const LayoutPoint
& additionalOffset
) const
86 // Clip to the padding box to at least give content the extra padding space.
87 LayoutRect
rect(additionalOffset
, size());
88 rect
.expand(borderInsets());
92 int LayoutButton::baselinePosition(FontBaseline baseline
, bool firstLine
, LineDirectionMode direction
, LinePositionMode linePositionMode
) const
94 ASSERT(linePositionMode
== PositionOnContainingLine
);
95 // We want to call the LayoutBlock version of firstLineBoxBaseline to
96 // avoid LayoutFlexibleBox synthesizing a baseline that we don't want.
97 // We use this check as a proxy for "are there any line boxes in this button"
98 if (!hasLineIfEmpty() && LayoutBlock::firstLineBoxBaseline() == -1) {
99 // To ensure that we have a consistent baseline when we have no children,
100 // even when we have the anonymous LayoutBlock child, we calculate the
101 // baseline for the empty case manually here.
102 if (direction
== HorizontalLine
) {
103 return marginTop() + size().height() - borderBottom() - paddingBottom() - horizontalScrollbarHeight();
105 return marginRight() + size().width() - borderLeft() - paddingLeft() - verticalScrollbarWidth();
107 return LayoutFlexibleBox::baselinePosition(baseline
, firstLine
, direction
, linePositionMode
);
111 // For compatibility with IE/FF we only clip overflow on input elements.
112 bool LayoutButton::hasControlClip() const
114 return !isHTMLButtonElement(node());