HTMLOptGroupElement.cpp [plain text]
#include "config.h"
#include "HTMLOptGroupElement.h"
#include "Document.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));
setHasCustomStyleResolveCallbacks();
}
PassRefPtr<HTMLOptGroupElement> HTMLOptGroupElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(new HTMLOptGroupElement(tagName, document));
}
bool HTMLOptGroupElement::isDisabledFormControl() const
{
return fastHasAttribute(disabledAttr);
}
bool HTMLOptGroupElement::isFocusable() const
{
return supportsFocus() && renderStyle() && renderStyle()->display() != NONE;
}
const AtomicString& HTMLOptGroupElement::formControlType() const
{
DEPRECATED_DEFINE_STATIC_LOCAL(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)
didAffectSelector(AffectedSelectorDisabled | AffectedSelectorEnabled);
}
void HTMLOptGroupElement::recalcSelectOptions()
{
ContainerNode* select = parentNode();
while (select && !select->hasTagName(selectTag))
select = select->parentNode();
if (select)
toHTMLSelectElement(select)->setRecalcListItems();
}
void HTMLOptGroupElement::didAttachRenderers()
{
if (!m_style && parentNode()->renderStyle())
updateNonRenderStyle(*parentNode()->renderStyle());
}
void HTMLOptGroupElement::willDetachRenderers()
{
m_style.clear();
}
void HTMLOptGroupElement::updateNonRenderStyle(RenderStyle& parentStyle)
{
m_style = document().ensureStyleResolver().styleForElement(this, &parentStyle);
}
RenderStyle* HTMLOptGroupElement::nonRendererStyle() const
{
return m_style.get();
}
PassRefPtr<RenderStyle> HTMLOptGroupElement::customStyleForRenderer(RenderStyle& parentStyle)
{
updateNonRenderStyle(parentStyle);
return m_style;
}
String HTMLOptGroupElement::groupLabelText() const
{
String itemText = document().displayStringModifiedByEncoding(getAttribute(labelAttr));
itemText = itemText.stripWhiteSpace();
itemText = itemText.simplifyWhiteSpace();
return itemText;
}
HTMLSelectElement* HTMLOptGroupElement::ownerSelectElement() const
{
ContainerNode* select = parentNode();
while (select && !select->hasTagName(selectTag))
select = select->parentNode();
if (!select)
return 0;
return toHTMLSelectElement(select);
}
void HTMLOptGroupElement::accessKeyAction(bool)
{
HTMLSelectElement* select = ownerSelectElement();
if (select && !select->focused())
select->accessKeyAction(false);
}
}