Index: Source/core/html/HTMLOptGroupElement.cpp |
diff --git a/Source/core/html/HTMLOptGroupElement.cpp b/Source/core/html/HTMLOptGroupElement.cpp |
index 47e6e701ef70f507eae8ca3fae491a6bbe373c45..5da4991ef9e75c55b543ab1fb6f7a2a57be8b353 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) |
+{ |
+ 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(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) |
{ |
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,28 @@ void HTMLOptGroupElement::accessKeyAction(bool) |
select->accessKeyAction(false); |
} |
-bool HTMLOptGroupElement::isDisplayNone() const |
+void HTMLOptGroupElement::didAddUserAgentShadowRoot(ShadowRoot& root) |
+{ |
+ RefPtrWillBeRawPtr<HTMLDivElement> label = HTMLDivElement::create(document()); |
+ label->setShadowPseudoId(AtomicString("-webkit-optgroup-label", AtomicString::ConstructFromLiteral)); |
tkent
2014/07/01 06:45:41
We can't add non-standard pseudo ID. Can we make
keishi
2014/07/02 04:27:22
I think it is hard to add pseudo ids that are only
|
+ 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 |
{ |
- RenderStyle* style = nonRendererStyle(); |
- return style && style->display() == NONE; |
+ return toHTMLDivElement(userAgentShadowRoot()->getElementById(ShadowElementNames::optGroupLabel())); |
} |
} // namespace |