| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (C) 2005 Apple Computer, Inc. | 2 * Copyright (C) 2005 Apple Computer, Inc. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 * | 18 * |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "core/layout/LayoutButton.h" | 21 #include "core/layout/LayoutButton.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 using namespace HTMLNames; | 25 using namespace HTMLNames; |
| 26 | 26 |
| 27 LayoutButton::LayoutButton(Element* element) | 27 LayoutButton::LayoutButton(Element* element) |
| 28 : LayoutFlexibleBox(element) | 28 : LayoutBlockFlow(element) |
| 29 , m_inner(nullptr) | 29 , m_inner(nullptr) |
| 30 { | 30 { |
| 31 } | 31 } |
| 32 | 32 |
| 33 LayoutButton::~LayoutButton() | 33 LayoutButton::~LayoutButton() |
| 34 { | 34 { |
| 35 } | 35 } |
| 36 | 36 |
| 37 void LayoutButton::addChild(LayoutObject* newChild, LayoutObject* beforeChild) | 37 void LayoutButton::addChild(LayoutObject* newChild, LayoutObject* beforeChild) |
| 38 { | 38 { |
| 39 if (!m_inner) { | 39 if (!m_inner) { |
| 40 // Create an anonymous block. | 40 // Create an anonymous block. |
| 41 ASSERT(!firstChild()); | 41 ASSERT(!firstChild()); |
| 42 m_inner = createAnonymousBlock(style()->display()); | 42 m_inner = createAnonymousBlock(style()->display()); |
| 43 LayoutFlexibleBox::addChild(m_inner); | 43 LayoutBlockFlow::addChild(m_inner); |
| 44 } | 44 } |
| 45 | 45 |
| 46 m_inner->addChild(newChild, beforeChild); | 46 m_inner->addChild(newChild, beforeChild); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void LayoutButton::removeChild(LayoutObject* oldChild) | 49 void LayoutButton::removeChild(LayoutObject* oldChild) |
| 50 { | 50 { |
| 51 if (oldChild == m_inner || !m_inner) { | 51 if (oldChild == m_inner || !m_inner) { |
| 52 LayoutFlexibleBox::removeChild(oldChild); | 52 LayoutBlockFlow::removeChild(oldChild); |
| 53 m_inner = 0; | 53 m_inner = 0; |
| 54 | 54 |
| 55 } else if (oldChild->parent() == this) { | 55 } else if (oldChild->parent() == this) { |
| 56 // We aren't the inner node, but we're getting removed from the button,
this | 56 // We aren't the inner node, but we're getting removed from the button,
this |
| 57 // can happen with things like scrollable area resizer's. | 57 // can happen with things like scrollable area resizer's. |
| 58 LayoutFlexibleBox::removeChild(oldChild); | 58 LayoutBlockFlow::removeChild(oldChild); |
| 59 | 59 |
| 60 } else { | 60 } else { |
| 61 m_inner->removeChild(oldChild); | 61 m_inner->removeChild(oldChild); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void LayoutButton::updateAnonymousChildStyle(const LayoutObject& child, Computed
Style& childStyle) const | 65 void LayoutButton::updateAnonymousChildStyle(const LayoutObject& child, Computed
Style& childStyle) const |
| 66 { | 66 { |
| 67 ASSERT(!m_inner || &child == m_inner); | 67 ASSERT(!m_inner || &child == m_inner); |
| 68 | 68 |
| 69 childStyle.setFlexGrow(1.0f); | 69 childStyle.setFlexGrow(1.0f); |
| 70 childStyle.setHeight(Length(0, FillAvailable)); |
| 70 // min-width: 0; is needed for correct shrinking. | 71 // min-width: 0; is needed for correct shrinking. |
| 71 childStyle.setMinWidth(Length(0, Fixed)); | 72 childStyle.setMinWidth(Length(0, Fixed)); |
| 72 // Use margin:auto instead of align-items:center to get safe centering, i.e. | 73 // Use margin:auto instead of align-items:center to get safe centering, i.e. |
| 73 // when the content overflows, treat it the same as align-items: flex-start. | 74 // when the content overflows, treat it the same as align-items: flex-start. |
| 74 childStyle.setMarginTop(Length()); | 75 childStyle.setMarginTop(Length()); |
| 75 childStyle.setMarginBottom(Length()); | 76 childStyle.setMarginBottom(Length()); |
| 76 childStyle.setFlexDirection(style()->flexDirection()); | 77 childStyle.setFlexDirection(style()->flexDirection()); |
| 77 childStyle.setJustifyContent(style()->justifyContent()); | 78 childStyle.setJustifyContent(style()->justifyContent()); |
| 78 childStyle.setFlexWrap(style()->flexWrap()); | 79 childStyle.setFlexWrap(style()->flexWrap()); |
| 79 childStyle.setAlignItems(style()->alignItems()); | 80 childStyle.setAlignItems(style()->alignItems()); |
| 80 childStyle.setAlignContent(style()->alignContent()); | 81 childStyle.setAlignContent(style()->alignContent()); |
| 81 } | 82 } |
| 82 | 83 |
| 83 LayoutRect LayoutButton::controlClipRect(const LayoutPoint& additionalOffset) co
nst | 84 LayoutRect LayoutButton::controlClipRect(const LayoutPoint& additionalOffset) co
nst |
| 84 { | 85 { |
| 85 // Clip to the padding box to at least give content the extra padding space. | 86 // Clip to the padding box to at least give content the extra padding space. |
| 86 LayoutRect rect(additionalOffset, size()); | 87 LayoutRect rect(additionalOffset, size()); |
| 87 rect.expand(borderInsets()); | 88 rect.expand(borderInsets()); |
| 88 return rect; | 89 return rect; |
| 89 } | 90 } |
| 90 | 91 |
| 91 int LayoutButton::baselinePosition(FontBaseline baseline, bool firstLine, LineDi
rectionMode direction, LinePositionMode linePositionMode) const | 92 int LayoutButton::baselinePosition(FontBaseline baseline, bool firstLine, LineDi
rectionMode direction, LinePositionMode linePositionMode) const |
| 92 { | 93 { |
| 93 ASSERT(linePositionMode == PositionOnContainingLine); | 94 ASSERT(linePositionMode == PositionOnContainingLine); |
| 94 // We want to call the LayoutBlock version of firstLineBoxBaseline to | 95 // We want to call the LayoutBlock version of firstLineBoxBaseline to |
| 95 // avoid LayoutFlexibleBox synthesizing a baseline that we don't want. | 96 // avoid LayoutBlockFlow synthesizing a baseline that we don't want. |
| 96 // We use this check as a proxy for "are there any line boxes in this button
" | 97 // We use this check as a proxy for "are there any line boxes in this button
" |
| 97 if (!hasLineIfEmpty() && LayoutBlock::firstLineBoxBaseline() == -1) { | 98 if (!hasLineIfEmpty() && (!firstChild() || LayoutBlock::firstLineBoxBaseline
() == -1)) { |
| 98 // To ensure that we have a consistent baseline when we have no children
, | 99 // To ensure that we have a consistent baseline when we have no children
, |
| 99 // even when we have the anonymous LayoutBlock child, we calculate the | 100 // even when we have the anonymous LayoutBlock child, we calculate the |
| 100 // baseline for the empty case manually here. | 101 // baseline for the empty case manually here. |
| 101 if (direction == HorizontalLine) { | 102 if (direction == HorizontalLine) { |
| 102 return marginTop() + size().height() - borderBottom() - paddingBotto
m() - horizontalScrollbarHeight(); | 103 return marginTop() + size().height() - borderBottom() - paddingBotto
m() - horizontalScrollbarHeight(); |
| 103 } | 104 } |
| 104 return marginRight() + size().width() - borderLeft() - paddingLeft() - v
erticalScrollbarWidth(); | 105 return marginRight() + size().width() - borderLeft() - paddingLeft() - v
erticalScrollbarWidth(); |
| 105 } | 106 } |
| 106 return LayoutFlexibleBox::baselinePosition(baseline, firstLine, direction, l
inePositionMode); | 107 return LayoutBlockFlow::baselinePosition(baseline, firstLine, direction, lin
ePositionMode); |
| 107 } | 108 } |
| 108 | 109 |
| 109 | 110 |
| 110 // For compatibility with IE/FF we only clip overflow on input elements. | 111 // For compatibility with IE/FF we only clip overflow on input elements. |
| 111 bool LayoutButton::hasControlClip() const | 112 bool LayoutButton::hasControlClip() const |
| 112 { | 113 { |
| 113 return !isHTMLButtonElement(node()); | 114 return !isHTMLButtonElement(node()); |
| 114 } | 115 } |
| 115 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |