Chromium Code Reviews| Index: Source/core/html/HTMLOptGroupElement.cpp |
| diff --git a/Source/core/html/HTMLOptGroupElement.cpp b/Source/core/html/HTMLOptGroupElement.cpp |
| index eacf865b5af74cb5a31647d148e3d28faca2a330..848c64658b33ba9ee4182c18af74212eb5c09d06 100644 |
| --- a/Source/core/html/HTMLOptGroupElement.cpp |
| +++ b/Source/core/html/HTMLOptGroupElement.cpp |
| @@ -27,33 +27,37 @@ |
| #include "core/HTMLNames.h" |
| #include "core/dom/NodeRenderStyle.h" |
| +#include "core/dom/Text.h" |
| +#include "core/editing/htmlediting.h" |
| +#include "core/html/HTMLContentElement.h" |
| +#include "core/html/HTMLDivElement.h" |
| #include "core/html/HTMLSelectElement.h" |
| +#include "core/html/shadow/ShadowElementNames.h" |
| #include "wtf/StdLibExtras.h" |
| +#include "wtf/unicode/CharacterNames.h" |
| namespace WebCore { |
| using namespace HTMLNames; |
| +PassRefPtrWillBeRawPtr<HTMLOptGroupElement> HTMLOptGroupElement::create(Document& document) |
|
tkent
2014/07/08 02:20:59
nit: We had better put the factory function defini
keishi
2014/07/10 09:48:03
Done.
|
| +{ |
| + RefPtrWillBeRawPtr<HTMLOptGroupElement> optGroupElement = adoptRefWillBeNoop(new HTMLOptGroupElement(document)); |
| + optGroupElement->ensureUserAgentShadowRoot(); |
| + return optGroupElement.release(); |
| +} |
| + |
| inline HTMLOptGroupElement::HTMLOptGroupElement(Document& document) |
| : HTMLElement(optgroupTag, document) |
| { |
| - setHasCustomStyleCallbacks(); |
| ScriptWrappable::init(this); |
| } |
| -DEFINE_NODE_FACTORY(HTMLOptGroupElement) |
| - |
| bool HTMLOptGroupElement::isDisabledFormControl() const |
| { |
| return fastHasAttribute(disabledAttr); |
| } |
| -bool HTMLOptGroupElement::rendererIsFocusable() const |
| -{ |
| - // Optgroup elements do not have a renderer so we check the renderStyle instead. |
| - return renderStyle() && renderStyle()->display() != NONE; |
| -} |
| - |
| void HTMLOptGroupElement::childrenChanged(const ChildrenChange& change) |
| { |
| recalcSelectOptions(); |
| @@ -67,6 +71,8 @@ void HTMLOptGroupElement::parseAttribute(const QualifiedName& name, const Atomic |
| if (name == disabledAttr) |
| didAffectSelector(AffectedSelectorDisabled | AffectedSelectorEnabled); |
| + else if (name == labelAttr) |
| + updateGroupLabel(); |
| } |
| void HTMLOptGroupElement::recalcSelectOptions() |
| @@ -75,42 +81,6 @@ void HTMLOptGroupElement::recalcSelectOptions() |
| select->setRecalcListItems(); |
| } |
| -void HTMLOptGroupElement::attach(const AttachContext& context) |
| -{ |
| - if (context.resolvedStyle) { |
| - ASSERT(!m_style || m_style == context.resolvedStyle); |
| - m_style = context.resolvedStyle; |
| - } |
| - HTMLElement::attach(context); |
| -} |
| - |
| -void HTMLOptGroupElement::detach(const AttachContext& context) |
| -{ |
| - m_style.clear(); |
| - HTMLElement::detach(context); |
| -} |
| - |
| -void HTMLOptGroupElement::updateNonRenderStyle() |
| -{ |
| - bool oldDisplayNoneStatus = isDisplayNone(); |
| - m_style = originalStyleForRenderer(); |
| - if (oldDisplayNoneStatus != isDisplayNone()) { |
| - if (HTMLSelectElement* select = ownerSelectElement()) |
| - select->updateListOnRenderer(); |
| - } |
| -} |
| - |
| -RenderStyle* HTMLOptGroupElement::nonRendererStyle() const |
| -{ |
| - return m_style.get(); |
| -} |
| - |
| -PassRefPtr<RenderStyle> HTMLOptGroupElement::customStyleForRenderer() |
| -{ |
| - updateNonRenderStyle(); |
| - return m_style; |
| -} |
| - |
| String HTMLOptGroupElement::groupLabelText() const |
| { |
| String itemText = getAttribute(labelAttr); |
| @@ -136,10 +106,29 @@ void HTMLOptGroupElement::accessKeyAction(bool) |
| select->accessKeyAction(false); |
| } |
| -bool HTMLOptGroupElement::isDisplayNone() const |
| +void HTMLOptGroupElement::didAddUserAgentShadowRoot(ShadowRoot& root) |
| +{ |
| + DEFINE_STATIC_LOCAL(AtomicString, labelPadding, ("0 2px 1px 2px", AtomicString::ConstructFromLiteral)); |
| + RefPtrWillBeRawPtr<HTMLDivElement> label = HTMLDivElement::create(document()); |
| + label->setInlineStyleProperty(CSSPropertyPadding, labelPadding); |
| + label->setIdAttribute(ShadowElementNames::optGroupLabel()); |
| + label->setTextContent(nonBreakingSpaceString()); |
| + root.appendChild(label); |
| + |
| + RefPtrWillBeRawPtr<HTMLContentElement> content = HTMLContentElement::create(document()); |
| + content->setAttribute(selectAttr, "option,optgroup"); |
| + root.appendChild(content); |
| +} |
| + |
| +void HTMLOptGroupElement::updateGroupLabel() |
| +{ |
| + const String& labelText = groupLabelText(); |
| + optGroupLabelElement()->setTextContent(labelText.isEmpty() ? nonBreakingSpaceString() : labelText); |
| +} |
| + |
| +HTMLDivElement* HTMLOptGroupElement::optGroupLabelElement() const |
|
tkent
2014/07/08 04:43:45
The return value can't be null. We can make it HT
keishi
2014/07/10 09:48:03
Done.
|
| { |
| - RenderStyle* style = nonRendererStyle(); |
| - return style && style->display() == NONE; |
| + return toHTMLDivElement(userAgentShadowRoot()->getElementById(ShadowElementNames::optGroupLabel())); |
| } |
| } // namespace |