This source file includes following definitions.
- m_inner
- addChild
- removeChild
- styleWillChange
- styleDidChange
- setupInnerStyle
- canHaveGeneratedChildren
- controlClipRect
- baselinePosition
#include "config.h"
#include "core/rendering/RenderButton.h"
#include "core/dom/Document.h"
namespace WebCore {
using namespace HTMLNames;
RenderButton::RenderButton(Element* element)
: RenderFlexibleBox(element)
, m_inner(0)
{
}
RenderButton::~RenderButton()
{
}
void RenderButton::addChild(RenderObject* newChild, RenderObject* beforeChild)
{
if (!m_inner) {
ASSERT(!firstChild());
m_inner = createAnonymousBlock(style()->display());
setupInnerStyle(m_inner->style());
RenderFlexibleBox::addChild(m_inner);
}
m_inner->addChild(newChild, beforeChild);
}
void RenderButton::removeChild(RenderObject* oldChild)
{
if (oldChild == m_inner || !m_inner || oldChild->parent() == this) {
ASSERT(oldChild == m_inner || !m_inner);
RenderFlexibleBox::removeChild(oldChild);
m_inner = 0;
} else
m_inner->removeChild(oldChild);
}
void RenderButton::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)
{
if (m_inner) {
m_inner->style()->setFlexGrow(newStyle.initialFlexGrow());
m_inner->style()->setMarginTop(newStyle.initialMargin());
m_inner->style()->setMarginBottom(newStyle.initialMargin());
}
RenderBlock::styleWillChange(diff, newStyle);
}
void RenderButton::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderBlock::styleDidChange(diff, oldStyle);
if (m_inner)
setupInnerStyle(m_inner->style());
}
void RenderButton::setupInnerStyle(RenderStyle* innerStyle)
{
ASSERT(innerStyle->refCount() == 1);
innerStyle->setFlexGrow(1.0f);
innerStyle->setMarginTop(Length());
innerStyle->setMarginBottom(Length());
innerStyle->setFlexDirection(style()->flexDirection());
}
bool RenderButton::canHaveGeneratedChildren() const
{
return !isHTMLInputElement(*node());
}
LayoutRect RenderButton::controlClipRect(const LayoutPoint& additionalOffset) const
{
return LayoutRect(additionalOffset.x() + borderLeft(), additionalOffset.y() + borderTop(), width() - borderLeft() - borderRight(), height() - borderTop() - borderBottom());
}
int RenderButton::baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
{
ASSERT(linePositionMode == PositionOnContainingLine);
if (!hasLineIfEmpty() && RenderBlock::firstLineBoxBaseline() == -1) {
if (direction == HorizontalLine)
return marginTop() + borderTop() + paddingTop() + contentHeight();
return marginRight() + borderRight() + paddingRight() + contentWidth();
}
return RenderFlexibleBox::baselinePosition(baseline, firstLine, direction, linePositionMode);
}
}