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 "NodeRenderingContext.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));
setHasCustomStyleCallbacks();
}
PassRefPtr<HTMLOptGroupElement> HTMLOptGroupElement::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new HTMLOptGroupElement(tagName, document));
}
bool HTMLOptGroupElement::isDisabledFormControl() const
{
return fastHasAttribute(disabledAttr);
}
bool HTMLOptGroupElement::supportsFocus() const
{
return HTMLElement::supportsFocus();
}
bool HTMLOptGroupElement::isFocusable() const
{
return supportsFocus() && renderStyle() && renderStyle()->display() != NONE;
}
const AtomicString& HTMLOptGroupElement::formControlType() const
{
DEFINE_STATIC_LOCAL(const AtomicString, optgroup, ("optgroup", AtomicString::ConstructFromLiteral));
return optgroup;
}
void HTMLOptGroupElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
recalcSelectOptions();
HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
}
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::attach(const AttachContext& context)
{
HTMLElement::attach(context);
if (!m_style && parentNode()->renderStyle())
updateNonRenderStyle();
}
void HTMLOptGroupElement::detach(const AttachContext& context)
{
m_style.clear();
HTMLElement::detach(context);
}
void HTMLOptGroupElement::updateNonRenderStyle()
{
m_style = document()->ensureStyleResolver()->styleForElement(this);
}
RenderStyle* HTMLOptGroupElement::nonRendererStyle() const
{
return m_style.get();
}
PassRefPtr<RenderStyle> HTMLOptGroupElement::customStyleForRenderer()
{
updateNonRenderStyle();
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);
}
}