RenderFormElement.cpp [plain text]
#include "config.h"
#include "RenderFormElement.h"
#include "EventNames.h"
#include "HTMLGenericFormElement.h"
#include "PlatformMouseEvent.h"
namespace WebCore {
using namespace EventNames;
RenderFormElement::RenderFormElement(HTMLGenericFormElement* element)
: RenderWidget(element)
{
setInline(true);
}
RenderFormElement::~RenderFormElement()
{
}
short RenderFormElement::baselinePosition(bool f, bool isRootLineBox) const
{
return marginTop() + widget()->baselinePosition(m_height);
}
void RenderFormElement::setStyle(RenderStyle* s)
{
if (canHaveIntrinsicMargins())
addIntrinsicMarginsIfAllowed(s);
RenderWidget::setStyle(s);
setShouldPaintBackgroundOrBorder(false);
m_widget->setFont(style()->font());
}
void RenderFormElement::updateFromElement()
{
m_widget->setEnabled(!static_cast<HTMLGenericFormElement*>(node())->disabled());
}
void RenderFormElement::layout()
{
ASSERT(needsLayout());
ASSERT(minMaxKnown());
m_height = 0;
calcWidth();
calcHeight();
setNeedsLayout(false);
}
void RenderFormElement::clicked(Widget*)
{
RenderArena* arena = ref();
PlatformMouseEvent event(PlatformMouseEvent::currentEvent);
if (node())
static_cast<EventTargetNode*>(node())->dispatchMouseEvent(event, clickEvent, event.clickCount());
deref(arena);
}
HorizontalAlignment RenderFormElement::textAlignment() const
{
switch (style()->textAlign()) {
case LEFT:
case WEBKIT_LEFT:
return AlignLeft;
case RIGHT:
case WEBKIT_RIGHT:
return AlignRight;
case CENTER:
case WEBKIT_CENTER:
return AlignHCenter;
case JUSTIFY:
case TAAUTO:
return style()->direction() == RTL ? AlignRight : AlignLeft;
}
ASSERT(false); return AlignLeft;
}
void RenderFormElement::addIntrinsicMarginsIfAllowed(RenderStyle* _style)
{
if (_style->fontSize() < 11)
return;
int m = intrinsicMargin();
if (_style->width().isIntrinsicOrAuto()) {
if (_style->marginLeft().quirk())
_style->setMarginLeft(Length(m, Fixed));
if (_style->marginRight().quirk())
_style->setMarginRight(Length(m, Fixed));
}
if (_style->height().isAuto()) {
if (_style->marginTop().quirk())
_style->setMarginTop(Length(m, Fixed));
if (_style->marginBottom().quirk())
_style->setMarginBottom(Length(m, Fixed));
}
}
}