HTMLLabelElement.cpp [plain text]
#include "config.h"
#include "HTMLLabelElement.h"
#include "Document.h"
#include "Event.h"
#include "EventNames.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
namespace WebCore {
using namespace HTMLNames;
using namespace EventNames;
HTMLLabelElement::HTMLLabelElement(Document *doc)
: HTMLElement(labelTag, doc)
{
}
HTMLLabelElement::~HTMLLabelElement()
{
}
bool HTMLLabelElement::isFocusable() const
{
return false;
}
HTMLElement* HTMLLabelElement::correspondingControl()
{
const AtomicString& controlId = getAttribute(forAttr);
if (controlId.isNull()) {
Node* node = this;
while ((node = node->traverseNextNode(this))) {
if (node->isHTMLElement()) {
HTMLElement* element = static_cast<HTMLElement*>(node);
if (element->isGenericFormElement())
return element;
}
}
return 0;
}
Element* elt = document()->getElementById(controlId);
if (elt && elt->isHTMLElement())
return static_cast<HTMLElement*>(elt);
return 0;
}
void HTMLLabelElement::setActive(bool down, bool pause)
{
if (down == active())
return;
HTMLElement::setActive(down, pause);
if (HTMLElement* element = correspondingControl())
element->setActive(down, pause);
}
void HTMLLabelElement::setHovered(bool over)
{
if (over == hovered())
return;
HTMLElement::setHovered(over);
if (HTMLElement* element = correspondingControl())
element->setHovered(over);
}
void HTMLLabelElement::defaultEventHandler(Event* evt)
{
static bool processingClick = false;
if (evt->type() == clickEvent && !processingClick) {
RefPtr<HTMLElement> control = correspondingControl();
if (!control || (evt->target() && control->contains(evt->target()->toNode())))
return;
processingClick = true;
control->dispatchSimulatedClick(evt);
if (control->isMouseFocusable())
control->focus();
processingClick = false;
evt->setDefaultHandled();
}
HTMLElement::defaultEventHandler(evt);
}
void HTMLLabelElement::focus(bool)
{
if (HTMLElement* element = correspondingControl())
element->focus();
}
void HTMLLabelElement::accessKeyAction(bool sendToAnyElement)
{
if (HTMLElement* element = correspondingControl())
element->accessKeyAction(sendToAnyElement);
}
String HTMLLabelElement::accessKey() const
{
return getAttribute(accesskeyAttr);
}
void HTMLLabelElement::setAccessKey(const String &value)
{
setAttribute(accesskeyAttr, value);
}
String HTMLLabelElement::htmlFor() const
{
return getAttribute(forAttr);
}
void HTMLLabelElement::setHtmlFor(const String &value)
{
setAttribute(forAttr, value);
}
}