Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1026)

Unified Diff: Source/core/html/HTMLOptGroupElement.cpp

Issue 347773002: Implement select listbox using shadow DOM (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLOptGroupElement.h ('k') | Source/core/html/HTMLOptionElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLOptGroupElement.cpp
diff --git a/Source/core/html/HTMLOptGroupElement.cpp b/Source/core/html/HTMLOptGroupElement.cpp
index eacf865b5af74cb5a31647d148e3d28faca2a330..5c867f161de4324e2ffa9ed77c7d667b4727c54e 100644
--- a/Source/core/html/HTMLOptGroupElement.cpp
+++ b/Source/core/html/HTMLOptGroupElement.cpp
@@ -27,8 +27,14 @@
#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 {
@@ -37,21 +43,19 @@ using namespace HTMLNames;
inline HTMLOptGroupElement::HTMLOptGroupElement(Document& document)
: HTMLElement(optgroupTag, document)
{
- setHasCustomStyleCallbacks();
ScriptWrappable::init(this);
}
-DEFINE_NODE_FACTORY(HTMLOptGroupElement)
-
-bool HTMLOptGroupElement::isDisabledFormControl() const
+PassRefPtrWillBeRawPtr<HTMLOptGroupElement> HTMLOptGroupElement::create(Document& document)
{
- return fastHasAttribute(disabledAttr);
+ RefPtrWillBeRawPtr<HTMLOptGroupElement> optGroupElement = adoptRefWillBeNoop(new HTMLOptGroupElement(document));
+ optGroupElement->ensureUserAgentShadowRoot();
+ return optGroupElement.release();
}
-bool HTMLOptGroupElement::rendererIsFocusable() const
+bool HTMLOptGroupElement::isDisabledFormControl() const
{
- // Optgroup elements do not have a renderer so we check the renderStyle instead.
- return renderStyle() && renderStyle()->display() != NONE;
+ return fastHasAttribute(disabledAttr);
}
void HTMLOptGroupElement::childrenChanged(const ChildrenChange& change)
@@ -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,34 @@ 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));
+ DEFINE_STATIC_LOCAL(AtomicString, labelMinHeight, ("1.2em", AtomicString::ConstructFromLiteral));
+ RefPtrWillBeRawPtr<HTMLDivElement> label = HTMLDivElement::create(document());
+ label->setAttribute(roleAttr, AtomicString("group", AtomicString::ConstructFromLiteral));
+ label->setAttribute(aria_labelAttr, AtomicString());
+ label->setInlineStyleProperty(CSSPropertyPadding, labelPadding);
+ label->setInlineStyleProperty(CSSPropertyMinHeight, labelMinHeight);
+ label->setIdAttribute(ShadowElementNames::optGroupLabel());
+ root.appendChild(label);
+
+ RefPtrWillBeRawPtr<HTMLContentElement> content = HTMLContentElement::create(document());
+ content->setAttribute(selectAttr, "option,optgroup");
+ root.appendChild(content);
+}
+
+void HTMLOptGroupElement::updateGroupLabel()
+{
+ const String& labelText = groupLabelText();
+ HTMLDivElement& label = optGroupLabelElement();
+ label.setTextContent(labelText);
+ label.setAttribute(aria_labelAttr, AtomicString(labelText));
+}
+
+HTMLDivElement& HTMLOptGroupElement::optGroupLabelElement() const
{
- RenderStyle* style = nonRendererStyle();
- return style && style->display() == NONE;
+ return *toHTMLDivElement(userAgentShadowRoot()->getElementById(ShadowElementNames::optGroupLabel()));
}
} // namespace
« no previous file with comments | « Source/core/html/HTMLOptGroupElement.h ('k') | Source/core/html/HTMLOptionElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698