Chromium Code Reviews| Index: Source/core/html/HTMLOptionElement.cpp |
| diff --git a/Source/core/html/HTMLOptionElement.cpp b/Source/core/html/HTMLOptionElement.cpp |
| index 42d0b436faf5fa5fe011e2ac9c2e1bd177f2d753..b344d223c77b0ec067630fdd21acb25df32b76bd 100644 |
| --- a/Source/core/html/HTMLOptionElement.cpp |
| +++ b/Source/core/html/HTMLOptionElement.cpp |
| @@ -34,7 +34,9 @@ |
| #include "core/dom/NodeTraversal.h" |
| #include "core/dom/ScriptLoader.h" |
| #include "core/dom/Text.h" |
| +#include "core/dom/shadow/ShadowRoot.h" |
| #include "core/html/HTMLDataListElement.h" |
| +#include "core/html/HTMLOptGroupElement.h" |
| #include "core/html/HTMLSelectElement.h" |
| #include "core/html/parser/HTMLParserIdioms.h" |
| #include "core/rendering/RenderTheme.h" |
| @@ -56,13 +58,16 @@ HTMLOptionElement::HTMLOptionElement(Document& document) |
| PassRefPtrWillBeRawPtr<HTMLOptionElement> HTMLOptionElement::create(Document& document) |
| { |
| - return adoptRefWillBeNoop(new HTMLOptionElement(document)); |
| + RefPtrWillBeRawPtr<HTMLOptionElement> option = adoptRefWillBeNoop(new HTMLOptionElement(document)); |
| + option->ensureUserAgentShadowRoot(); |
| + return option.release(); |
| } |
| PassRefPtrWillBeRawPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document& document, const String& data, const AtomicString& value, |
| bool defaultSelected, bool selected, ExceptionState& exceptionState) |
| { |
| RefPtrWillBeRawPtr<HTMLOptionElement> element = adoptRefWillBeNoop(new HTMLOptionElement(document)); |
| + element->ensureUserAgentShadowRoot(); |
| element->appendChild(Text::create(document, data.isNull() ? "" : data), exceptionState); |
| if (exceptionState.hadException()) |
| return nullptr; |
| @@ -95,12 +100,6 @@ void HTMLOptionElement::detach(const AttachContext& context) |
| HTMLElement::detach(context); |
| } |
| -bool HTMLOptionElement::rendererIsFocusable() const |
| -{ |
| - // Option elements do not have a renderer so we check the renderStyle instead. |
| - return renderStyle() && renderStyle()->display() != NONE; |
| -} |
| - |
| String HTMLOptionElement::text() const |
| { |
| Document& document = this->document(); |
| @@ -188,6 +187,8 @@ void HTMLOptionElement::parseAttribute(const QualifiedName& name, const AtomicSt |
| } else if (name == selectedAttr) { |
| if (bool willBeSelected = !value.isNull()) |
| setSelected(willBeSelected); |
| + } else if (name == labelAttr) { |
| + updateLabel(); |
| } else |
| HTMLElement::parseAttribute(name, value); |
| } |
| @@ -251,6 +252,7 @@ void HTMLOptionElement::childrenChanged(const ChildrenChange& change) |
| dataList->optionElementChildrenChanged(); |
| else if (HTMLSelectElement* select = ownerSelectElement()) |
| select->optionElementChildrenChanged(); |
| + updateLabel(); |
| HTMLElement::childrenChanged(change); |
| } |
| @@ -279,12 +281,9 @@ void HTMLOptionElement::setLabel(const AtomicString& label) |
| void HTMLOptionElement::updateNonRenderStyle() |
| { |
| - bool oldDisplayNoneStatus = isDisplayNone(); |
| m_style = originalStyleForRenderer(); |
| - if (oldDisplayNoneStatus != isDisplayNone()) { |
| - if (HTMLSelectElement* select = ownerSelectElement()) |
| - select->updateListOnRenderer(); |
| - } |
| + if (HTMLSelectElement* select = ownerSelectElement()) |
| + select->updateListOnRenderer(); |
| } |
| RenderStyle* HTMLOptionElement::nonRendererStyle() const |
| @@ -343,6 +342,14 @@ Node::InsertionNotificationRequest HTMLOptionElement::insertedInto(ContainerNode |
| return HTMLElement::insertedInto(insertionPoint); |
| } |
| +void HTMLOptionElement::removedFrom(ContainerNode* insertionPoint) |
| +{ |
| + HTMLSelectElement* select = Traversal<HTMLSelectElement>::firstAncestorOrSelf(*insertionPoint); |
|
tkent
2014/07/08 02:20:59
nit: You can write this as:
if (HTMLSelectElement*
keishi
2014/07/10 09:48:03
Done.
|
| + if (select) |
| + return select->optionRemoved(this); |
|
tkent
2014/07/08 02:20:59
This is weird for void function.
Also, should we c
keishi
2014/07/10 09:48:03
Done.
|
| + HTMLElement::removedFrom(insertionPoint); |
| +} |
| + |
| String HTMLOptionElement::collectOptionInnerText() const |
| { |
| StringBuilder text; |
| @@ -366,16 +373,25 @@ HTMLFormElement* HTMLOptionElement::form() const |
| return 0; |
| } |
| -bool HTMLOptionElement::isDisplayNone() const |
| +void HTMLOptionElement::didAddUserAgentShadowRoot(ShadowRoot& root) |
| { |
| - ContainerNode* parent = parentNode(); |
| - // Check for parent optgroup having display NONE |
| - if (parent && isHTMLOptGroupElement(*parent)) { |
| - if (toHTMLOptGroupElement(*parent).isDisplayNone()) |
| - return true; |
| - } |
| - RenderStyle* style = nonRendererStyle(); |
| - return style && style->display() == NONE; |
| + updateLabel(); |
| +} |
| + |
| +void HTMLOptionElement::updateLabel() |
| +{ |
| + ShadowRoot* root = userAgentShadowRoot(); |
|
tkent
2014/07/08 02:20:59
nit: You can write this as:
if (ShadowRoot* root =
keishi
2014/07/10 09:48:03
Done.
|
| + if (!root) |
| + return; |
| + root->setTextContent(textIndentedToRespectGroupLabel()); |
| +} |
| + |
| +bool HTMLOptionElement::spatialNavigationFocused() const |
| +{ |
| + HTMLSelectElement* select = ownerSelectElement(); |
| + if (!select || !select->focused()) |
| + return false; |
| + return select->spatialNavigationFocusedOption() == this; |
| } |
| } // namespace WebCore |