HTMLLegendElement.cpp [plain text]
#include "config.h"
#include "HTMLLegendElement.h"
#include "ElementIterator.h"
#include "HTMLFieldSetElement.h"
#include "HTMLNames.h"
namespace WebCore {
using namespace HTMLNames;
inline HTMLLegendElement::HTMLLegendElement(const QualifiedName& tagName, Document& document)
: HTMLElement(tagName, document)
{
ASSERT(hasTagName(legendTag));
}
Ref<HTMLLegendElement> HTMLLegendElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new HTMLLegendElement(tagName, document));
}
HTMLFormControlElement* HTMLLegendElement::associatedControl()
{
auto enclosingFieldset = ancestorsOfType<HTMLFieldSetElement>(*this).first();
if (!enclosingFieldset)
return nullptr;
return descendantsOfType<HTMLFormControlElement>(*enclosingFieldset).first();
}
void HTMLLegendElement::focus(bool restorePreviousSelection, FocusDirection direction)
{
if (document().haveStylesheetsLoaded()) {
document().updateLayoutIgnorePendingStylesheets();
if (isFocusable()) {
Element::focus(restorePreviousSelection, direction);
return;
}
}
if (auto* control = associatedControl())
control->focus(false, direction);
}
void HTMLLegendElement::accessKeyAction(bool sendMouseEvents)
{
if (HTMLFormControlElement* control = associatedControl())
control->accessKeyAction(sendMouseEvents);
}
HTMLFormElement* HTMLLegendElement::virtualForm() const
{
ContainerNode* fieldset = parentNode();
if (!is<HTMLFieldSetElement>(fieldset))
return nullptr;
return downcast<HTMLFieldSetElement>(*fieldset).form();
}
}