HTMLOptGroupElement.cpp [plain text]
#include "config.h"
#include "HTMLOptGroupElement.h"
#include "Document.h"
#include "ElementAncestorIterator.h"
#include "HTMLNames.h"
#include "HTMLSelectElement.h"
#include "RenderMenuList.h"
#include "NodeRenderStyle.h"
#include "StyleResolver.h"
#include <wtf/StdLibExtras.h>
namespace WebCore {
using namespace HTMLNames;
inline HTMLOptGroupElement::HTMLOptGroupElement(const QualifiedName& tagName, Document& document)
: HTMLElement(tagName, document)
{
ASSERT(hasTagName(optgroupTag));
}
Ref<HTMLOptGroupElement> HTMLOptGroupElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new HTMLOptGroupElement(tagName, document));
}
bool HTMLOptGroupElement::isDisabledFormControl() const
{
return hasAttributeWithoutSynchronization(disabledAttr);
}
bool HTMLOptGroupElement::isFocusable() const
{
if (!supportsFocus())
return false;
auto* style = const_cast<HTMLOptGroupElement&>(*this).computedStyle();
return style && style->display() != NONE;
}
const AtomicString& HTMLOptGroupElement::formControlType() const
{
static NeverDestroyed<const AtomicString> optgroup("optgroup", AtomicString::ConstructFromLiteral);
return optgroup;
}
void HTMLOptGroupElement::childrenChanged(const ChildChange& change)
{
recalcSelectOptions();
HTMLElement::childrenChanged(change);
}
void HTMLOptGroupElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
HTMLElement::parseAttribute(name, value);
recalcSelectOptions();
if (name == disabledAttr)
invalidateStyleForSubtree();
}
void HTMLOptGroupElement::recalcSelectOptions()
{
if (auto* selectElement = ancestorsOfType<HTMLSelectElement>(*this).first()) {
selectElement->setRecalcListItems();
selectElement->updateValidity();
}
}
String HTMLOptGroupElement::groupLabelText() const
{
String itemText = document().displayStringModifiedByEncoding(attributeWithoutSynchronization(labelAttr));
itemText = itemText.stripWhiteSpace();
itemText = itemText.simplifyWhiteSpace();
return itemText;
}
HTMLSelectElement* HTMLOptGroupElement::ownerSelectElement() const
{
ContainerNode* select = parentNode();
while (select && !is<HTMLSelectElement>(*select))
select = select->parentNode();
if (!select)
return nullptr;
return downcast<HTMLSelectElement>(select);
}
void HTMLOptGroupElement::accessKeyAction(bool)
{
HTMLSelectElement* select = ownerSelectElement();
if (select && !select->focused())
select->accessKeyAction(false);
}
}