diff options
Diffstat (limited to 'Source/WebCore/html/HTMLOptGroupElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLOptGroupElement.cpp | 70 |
1 files changed, 20 insertions, 50 deletions
diff --git a/Source/WebCore/html/HTMLOptGroupElement.cpp b/Source/WebCore/html/HTMLOptGroupElement.cpp index 2927adac5..afb782108 100644 --- a/Source/WebCore/html/HTMLOptGroupElement.cpp +++ b/Source/WebCore/html/HTMLOptGroupElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2004-2016 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -26,6 +26,7 @@ #include "HTMLOptGroupElement.h" #include "Document.h" +#include "ElementAncestorIterator.h" #include "HTMLNames.h" #include "HTMLSelectElement.h" #include "RenderMenuList.h" @@ -41,28 +42,30 @@ inline HTMLOptGroupElement::HTMLOptGroupElement(const QualifiedName& tagName, Do : HTMLElement(tagName, document) { ASSERT(hasTagName(optgroupTag)); - setHasCustomStyleResolveCallbacks(); } -PassRefPtr<HTMLOptGroupElement> HTMLOptGroupElement::create(const QualifiedName& tagName, Document& document) +Ref<HTMLOptGroupElement> HTMLOptGroupElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLOptGroupElement(tagName, document)); + return adoptRef(*new HTMLOptGroupElement(tagName, document)); } bool HTMLOptGroupElement::isDisabledFormControl() const { - return fastHasAttribute(disabledAttr); + return hasAttributeWithoutSynchronization(disabledAttr); } bool HTMLOptGroupElement::isFocusable() const { - // Optgroup elements do not have a renderer so we check the renderStyle instead. - return supportsFocus() && renderStyle() && renderStyle()->display() != NONE; + if (!supportsFocus()) + return false; + // Optgroup elements do not have a renderer. + auto* style = const_cast<HTMLOptGroupElement&>(*this).computedStyle(); + return style && style->display() != NONE; } const AtomicString& HTMLOptGroupElement::formControlType() const { - DEFINE_STATIC_LOCAL(const AtomicString, optgroup, ("optgroup", AtomicString::ConstructFromLiteral)); + static NeverDestroyed<const AtomicString> optgroup("optgroup", AtomicString::ConstructFromLiteral); return optgroup; } @@ -78,53 +81,20 @@ void HTMLOptGroupElement::parseAttribute(const QualifiedName& name, const Atomic recalcSelectOptions(); if (name == disabledAttr) - didAffectSelector(AffectedSelectorDisabled | AffectedSelectorEnabled); + invalidateStyleForSubtree(); } void HTMLOptGroupElement::recalcSelectOptions() { - ContainerNode* select = parentNode(); - while (select && !select->hasTagName(selectTag)) - select = select->parentNode(); - if (select) - toHTMLSelectElement(select)->setRecalcListItems(); -} - -void HTMLOptGroupElement::didAttachRenderers() -{ - // If after attaching nothing called styleForRenderer() on this node we - // manually cache the value. This happens if our parent doesn't have a - // renderer like <optgroup> or if it doesn't allow children like <select>. - if (!m_style && parentNode()->renderStyle()) - updateNonRenderStyle(); -} - -void HTMLOptGroupElement::willDetachRenderers() -{ - m_style.clear(); -} - -void HTMLOptGroupElement::updateNonRenderStyle() -{ - m_style = document().ensureStyleResolver().styleForElement(this); -} - -RenderStyle* HTMLOptGroupElement::nonRendererStyle() const -{ - return m_style.get(); -} - -PassRefPtr<RenderStyle> HTMLOptGroupElement::customStyleForRenderer() -{ - // styleForRenderer is called whenever a new style should be associated - // with an Element so now is a good time to update our cached style. - updateNonRenderStyle(); - return m_style; + if (auto* selectElement = ancestorsOfType<HTMLSelectElement>(*this).first()) { + selectElement->setRecalcListItems(); + selectElement->updateValidity(); + } } String HTMLOptGroupElement::groupLabelText() const { - String itemText = document().displayStringModifiedByEncoding(getAttribute(labelAttr)); + String itemText = document().displayStringModifiedByEncoding(attributeWithoutSynchronization(labelAttr)); // In WinIE, leading and trailing whitespace is ignored in options and optgroups. We match this behavior. itemText = itemText.stripWhiteSpace(); @@ -137,13 +107,13 @@ String HTMLOptGroupElement::groupLabelText() const HTMLSelectElement* HTMLOptGroupElement::ownerSelectElement() const { ContainerNode* select = parentNode(); - while (select && !select->hasTagName(selectTag)) + while (select && !is<HTMLSelectElement>(*select)) select = select->parentNode(); if (!select) - return 0; + return nullptr; - return toHTMLSelectElement(select); + return downcast<HTMLSelectElement>(select); } void HTMLOptGroupElement::accessKeyAction(bool) |