| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 5 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 6 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. |
| 7 * Copyright (C) 2010 Google Inc. All rights reserved. | 7 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 8 * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved. | 8 * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved. |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "core/style/ComputedStyle.h" | 43 #include "core/style/ComputedStyle.h" |
| 44 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 45 #include "wtf/text/StringBuilder.h" | 45 #include "wtf/text/StringBuilder.h" |
| 46 | 46 |
| 47 namespace blink { | 47 namespace blink { |
| 48 | 48 |
| 49 using namespace HTMLNames; | 49 using namespace HTMLNames; |
| 50 | 50 |
| 51 HTMLOptionElement::HTMLOptionElement(Document& document) | 51 HTMLOptionElement::HTMLOptionElement(Document& document) |
| 52 : HTMLElement(optionTag, document), m_isSelected(false) { | 52 : HTMLElement(optionTag, document), m_isSelected(false) { |
| 53 setHasCustomStyleCallbacks(); | |
| 54 } | 53 } |
| 55 | 54 |
| 56 // An explicit empty destructor should be in HTMLOptionElement.cpp, because | 55 // An explicit empty destructor should be in HTMLOptionElement.cpp, because |
| 57 // if an implicit destructor is used or an empty destructor is defined in | 56 // if an implicit destructor is used or an empty destructor is defined in |
| 58 // HTMLOptionElement.h, when including HTMLOptionElement.h, | 57 // HTMLOptionElement.h, when including HTMLOptionElement.h, |
| 59 // msvc tries to expand the destructor and causes | 58 // msvc tries to expand the destructor and causes |
| 60 // a compile error because of lack of ComputedStyle definition. | 59 // a compile error because of lack of ComputedStyle definition. |
| 61 HTMLOptionElement::~HTMLOptionElement() {} | 60 HTMLOptionElement::~HTMLOptionElement() {} |
| 62 | 61 |
| 63 HTMLOptionElement* HTMLOptionElement::create(Document& document) { | 62 HTMLOptionElement* HTMLOptionElement::create(Document& document) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 element->setValue(value); | 83 element->setValue(value); |
| 85 if (defaultSelected) | 84 if (defaultSelected) |
| 86 element->setAttribute(selectedAttr, emptyAtom); | 85 element->setAttribute(selectedAttr, emptyAtom); |
| 87 element->setSelected(selected); | 86 element->setSelected(selected); |
| 88 | 87 |
| 89 return element; | 88 return element; |
| 90 } | 89 } |
| 91 | 90 |
| 92 void HTMLOptionElement::attachLayoutTree(const AttachContext& context) { | 91 void HTMLOptionElement::attachLayoutTree(const AttachContext& context) { |
| 93 AttachContext optionContext(context); | 92 AttachContext optionContext(context); |
| 94 if (context.resolvedStyle) { | 93 RefPtr<ComputedStyle> resolvedStyle; |
| 95 DCHECK(!m_style || m_style == context.resolvedStyle); | 94 if (!context.resolvedStyle && parentComputedStyle()) { |
| 96 m_style = context.resolvedStyle; | 95 if (HTMLSelectElement* select = ownerSelectElement()) |
| 97 } else if (parentComputedStyle()) { | 96 select->updateListOnLayoutObject(); |
| 98 updateNonComputedStyle(); | 97 resolvedStyle = originalStyleForLayoutObject(); |
| 99 optionContext.resolvedStyle = m_style.get(); | 98 optionContext.resolvedStyle = resolvedStyle.get(); |
| 100 } | 99 } |
| 101 HTMLElement::attachLayoutTree(optionContext); | 100 HTMLElement::attachLayoutTree(optionContext); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void HTMLOptionElement::detachLayoutTree(const AttachContext& context) { | 103 void HTMLOptionElement::detachLayoutTree(const AttachContext& context) { |
| 105 m_style.clear(); | |
| 106 HTMLElement::detachLayoutTree(context); | 104 HTMLElement::detachLayoutTree(context); |
| 107 } | 105 } |
| 108 | 106 |
| 109 bool HTMLOptionElement::supportsFocus() const { | 107 bool HTMLOptionElement::supportsFocus() const { |
| 110 HTMLSelectElement* select = ownerSelectElement(); | 108 HTMLSelectElement* select = ownerSelectElement(); |
| 111 if (select && select->usesMenuList()) | 109 if (select && select->usesMenuList()) |
| 112 return false; | 110 return false; |
| 113 return HTMLElement::supportsFocus(); | 111 return HTMLElement::supportsFocus(); |
| 114 } | 112 } |
| 115 | 113 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return label; | 322 return label; |
| 325 return collectOptionInnerText() | 323 return collectOptionInnerText() |
| 326 .stripWhiteSpace(isHTMLSpace<UChar>) | 324 .stripWhiteSpace(isHTMLSpace<UChar>) |
| 327 .simplifyWhiteSpace(isHTMLSpace<UChar>); | 325 .simplifyWhiteSpace(isHTMLSpace<UChar>); |
| 328 } | 326 } |
| 329 | 327 |
| 330 void HTMLOptionElement::setLabel(const AtomicString& label) { | 328 void HTMLOptionElement::setLabel(const AtomicString& label) { |
| 331 setAttribute(labelAttr, label); | 329 setAttribute(labelAttr, label); |
| 332 } | 330 } |
| 333 | 331 |
| 334 void HTMLOptionElement::updateNonComputedStyle() { | |
| 335 m_style = originalStyleForLayoutObject(); | |
| 336 if (HTMLSelectElement* select = ownerSelectElement()) | |
| 337 select->updateListOnLayoutObject(); | |
| 338 } | |
| 339 | |
| 340 ComputedStyle* HTMLOptionElement::nonLayoutObjectComputedStyle() const { | |
| 341 return m_style.get(); | |
| 342 } | |
| 343 | |
| 344 PassRefPtr<ComputedStyle> HTMLOptionElement::customStyleForLayoutObject() { | |
| 345 updateNonComputedStyle(); | |
| 346 return m_style; | |
| 347 } | |
| 348 | |
| 349 String HTMLOptionElement::textIndentedToRespectGroupLabel() const { | 332 String HTMLOptionElement::textIndentedToRespectGroupLabel() const { |
| 350 ContainerNode* parent = parentNode(); | 333 ContainerNode* parent = parentNode(); |
| 351 if (parent && isHTMLOptGroupElement(*parent)) | 334 if (parent && isHTMLOptGroupElement(*parent)) |
| 352 return " " + displayLabel(); | 335 return " " + displayLabel(); |
| 353 return displayLabel(); | 336 return displayLabel(); |
| 354 } | 337 } |
| 355 | 338 |
| 356 bool HTMLOptionElement::ownElementDisabled() const { | 339 bool HTMLOptionElement::ownElementDisabled() const { |
| 357 return fastHasAttribute(disabledAttr); | 340 return fastHasAttribute(disabledAttr); |
| 358 } | 341 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 408 } |
| 426 | 409 |
| 427 bool HTMLOptionElement::spatialNavigationFocused() const { | 410 bool HTMLOptionElement::spatialNavigationFocused() const { |
| 428 HTMLSelectElement* select = ownerSelectElement(); | 411 HTMLSelectElement* select = ownerSelectElement(); |
| 429 if (!select || !select->isFocused()) | 412 if (!select || !select->isFocused()) |
| 430 return false; | 413 return false; |
| 431 return select->spatialNavigationFocusedOption() == this; | 414 return select->spatialNavigationFocusedOption() == this; |
| 432 } | 415 } |
| 433 | 416 |
| 434 bool HTMLOptionElement::isDisplayNone() const { | 417 bool HTMLOptionElement::isDisplayNone() const { |
| 435 // If m_style is not set, then the node is still unattached. | 418 // If the style is not set, then the node is still unattached. |
| 436 // We have to wait till it gets attached to read the display property. | 419 // We have to wait till it gets attached to read the display property. |
| 437 if (!m_style) | 420 const ComputedStyle* style = nonLayoutObjectComputedStyle(); |
| 421 if (!style) |
| 438 return false; | 422 return false; |
| 439 | 423 |
| 440 if (m_style->display() != EDisplay::None) { | 424 if (style->display() != EDisplay::None) { |
| 441 // We need to check the parent's display property. Parent's | 425 // We need to check the parent's display property. Parent's |
| 442 // display:none doesn't override children's display properties in | 426 // display:none doesn't override children's display properties in |
| 443 // ComputedStyle. | 427 // ComputedStyle. |
| 444 Element* parent = parentElement(); | 428 Element* parent = parentElement(); |
| 445 DCHECK(parent); | 429 DCHECK(parent); |
| 446 if (isHTMLOptGroupElement(*parent)) { | 430 if (isHTMLOptGroupElement(*parent)) { |
| 447 const ComputedStyle* parentStyle = parent->computedStyle() | 431 const ComputedStyle* parentStyle = parent->computedStyle() |
| 448 ? parent->computedStyle() | 432 ? parent->computedStyle() |
| 449 : parent->ensureComputedStyle(); | 433 : parent->ensureComputedStyle(); |
| 450 return !parentStyle || parentStyle->display() == EDisplay::None; | 434 return !parentStyle || parentStyle->display() == EDisplay::None; |
| 451 } | 435 } |
| 452 } | 436 } |
| 453 return m_style->display() == EDisplay::None; | 437 return style->display() == EDisplay::None; |
| 454 } | 438 } |
| 455 | 439 |
| 456 String HTMLOptionElement::innerText() { | 440 String HTMLOptionElement::innerText() { |
| 457 // A workaround for crbug.com/424578. We add ShadowRoot to an OPTION, but | 441 // A workaround for crbug.com/424578. We add ShadowRoot to an OPTION, but |
| 458 // innerText behavior for Shadow DOM is unclear. We just return the same | 442 // innerText behavior for Shadow DOM is unclear. We just return the same |
| 459 // string before adding ShadowRoot. | 443 // string before adding ShadowRoot. |
| 460 return textContent(); | 444 return textContent(); |
| 461 } | 445 } |
| 462 | 446 |
| 463 } // namespace blink | 447 } // namespace blink |
| OLD | NEW |