| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 String HTMLOptionElement::displayLabel() const { | 123 String HTMLOptionElement::displayLabel() const { |
| 124 Document& document = this->document(); | 124 Document& document = this->document(); |
| 125 String text; | 125 String text; |
| 126 | 126 |
| 127 // WinIE does not use the label attribute, so as a quirk, we ignore it. | 127 // WinIE does not use the label attribute, so as a quirk, we ignore it. |
| 128 if (!document.inQuirksMode()) | 128 if (!document.inQuirksMode()) |
| 129 text = fastGetAttribute(labelAttr); | 129 text = fastGetAttribute(labelAttr); |
| 130 | 130 |
| 131 // FIXME: The following treats an element with the label attribute set to | 131 // FIXME: The following treats an element with the label attribute set to |
| 132 // the empty string the same as an element with no label attribute at all. | 132 // the empty string the same as an element with no label attribute at all. |
| 133 // Is that correct? If it is, then should the label function work the same way
? | 133 // Is that correct? If it is, then should the label function work the same |
| 134 // way? |
| 134 if (text.isEmpty()) | 135 if (text.isEmpty()) |
| 135 text = collectOptionInnerText(); | 136 text = collectOptionInnerText(); |
| 136 | 137 |
| 137 return text.stripWhiteSpace(isHTMLSpace<UChar>) | 138 return text.stripWhiteSpace(isHTMLSpace<UChar>) |
| 138 .simplifyWhiteSpace(isHTMLSpace<UChar>); | 139 .simplifyWhiteSpace(isHTMLSpace<UChar>); |
| 139 } | 140 } |
| 140 | 141 |
| 141 String HTMLOptionElement::text() const { | 142 String HTMLOptionElement::text() const { |
| 142 return collectOptionInnerText() | 143 return collectOptionInnerText() |
| 143 .stripWhiteSpace(isHTMLSpace<UChar>) | 144 .stripWhiteSpace(isHTMLSpace<UChar>) |
| 144 .simplifyWhiteSpace(isHTMLSpace<UChar>); | 145 .simplifyWhiteSpace(isHTMLSpace<UChar>); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void HTMLOptionElement::setText(const String& text, | 148 void HTMLOptionElement::setText(const String& text, |
| 148 ExceptionState& exceptionState) { | 149 ExceptionState& exceptionState) { |
| 149 // Changing the text causes a recalc of a select's items, which will reset the
selected | 150 // Changing the text causes a recalc of a select's items, which will reset the |
| 150 // index to the first item if the select is single selection with a menu list.
We attempt to | 151 // selected index to the first item if the select is single selection with a |
| 151 // preserve the selected item. | 152 // menu list. We attempt to preserve the selected item. |
| 152 HTMLSelectElement* select = ownerSelectElement(); | 153 HTMLSelectElement* select = ownerSelectElement(); |
| 153 bool selectIsMenuList = select && select->usesMenuList(); | 154 bool selectIsMenuList = select && select->usesMenuList(); |
| 154 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; | 155 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; |
| 155 | 156 |
| 156 if (hasOneTextChild()) { | 157 if (hasOneTextChild()) { |
| 157 toText(firstChild())->setData(text); | 158 toText(firstChild())->setData(text); |
| 158 } else { | 159 } else { |
| 159 removeChildren(); | 160 removeChildren(); |
| 160 appendChild(Text::create(document(), text), exceptionState); | 161 appendChild(Text::create(document(), text), exceptionState); |
| 161 } | 162 } |
| 162 | 163 |
| 163 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) | 164 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) |
| 164 select->setSelectedIndex(oldSelectedIndex); | 165 select->setSelectedIndex(oldSelectedIndex); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void HTMLOptionElement::accessKeyAction(bool) { | 168 void HTMLOptionElement::accessKeyAction(bool) { |
| 168 if (HTMLSelectElement* select = ownerSelectElement()) | 169 if (HTMLSelectElement* select = ownerSelectElement()) |
| 169 select->selectOptionByAccessKey(this); | 170 select->selectOptionByAccessKey(this); |
| 170 } | 171 } |
| 171 | 172 |
| 172 int HTMLOptionElement::index() const { | 173 int HTMLOptionElement::index() const { |
| 173 // It would be faster to cache the index, but harder to get it right in all ca
ses. | 174 // It would be faster to cache the index, but harder to get it right in all |
| 175 // cases. |
| 174 | 176 |
| 175 HTMLSelectElement* selectElement = ownerSelectElement(); | 177 HTMLSelectElement* selectElement = ownerSelectElement(); |
| 176 if (!selectElement) | 178 if (!selectElement) |
| 177 return 0; | 179 return 0; |
| 178 | 180 |
| 179 int optionIndex = 0; | 181 int optionIndex = 0; |
| 180 for (const auto& option : selectElement->optionList()) { | 182 for (const auto& option : selectElement->optionList()) { |
| 181 if (option == this) | 183 if (option == this) |
| 182 return optionIndex; | 184 return optionIndex; |
| 183 ++optionIndex; | 185 ++optionIndex; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 if (m_isSelected == selected) | 269 if (m_isSelected == selected) |
| 268 return; | 270 return; |
| 269 | 271 |
| 270 m_isSelected = selected; | 272 m_isSelected = selected; |
| 271 pseudoStateChanged(CSSSelector::PseudoChecked); | 273 pseudoStateChanged(CSSSelector::PseudoChecked); |
| 272 | 274 |
| 273 if (HTMLSelectElement* select = ownerSelectElement()) { | 275 if (HTMLSelectElement* select = ownerSelectElement()) { |
| 274 select->invalidateSelectedItems(); | 276 select->invalidateSelectedItems(); |
| 275 | 277 |
| 276 if (AXObjectCache* cache = document().existingAXObjectCache()) { | 278 if (AXObjectCache* cache = document().existingAXObjectCache()) { |
| 277 // If there is a layoutObject (most common), fire accessibility notificati
ons | 279 // If there is a layoutObject (most common), fire accessibility |
| 278 // only when it's a listbox (and not a menu list). If there's no layoutObj
ect, | 280 // notifications only when it's a listbox (and not a menu list). If |
| 279 // fire them anyway just to be safe (to make sure the AX tree is in sync). | 281 // there's no layoutObject, fire them anyway just to be safe (to make sure |
| 282 // the AX tree is in sync). |
| 280 if (!select->layoutObject() || select->layoutObject()->isListBox()) { | 283 if (!select->layoutObject() || select->layoutObject()->isListBox()) { |
| 281 cache->listboxOptionStateChanged(this); | 284 cache->listboxOptionStateChanged(this); |
| 282 cache->listboxSelectedChildrenChanged(select); | 285 cache->listboxSelectedChildrenChanged(select); |
| 283 } | 286 } |
| 284 } | 287 } |
| 285 } | 288 } |
| 286 } | 289 } |
| 287 | 290 |
| 288 void HTMLOptionElement::setDirty(bool value) { | 291 void HTMLOptionElement::setDirty(bool value) { |
| 289 m_isDirty = true; | 292 m_isDirty = true; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 const ComputedStyle* parentStyle = parent->computedStyle() | 446 const ComputedStyle* parentStyle = parent->computedStyle() |
| 444 ? parent->computedStyle() | 447 ? parent->computedStyle() |
| 445 : parent->ensureComputedStyle(); | 448 : parent->ensureComputedStyle(); |
| 446 return !parentStyle || parentStyle->display() == EDisplay::None; | 449 return !parentStyle || parentStyle->display() == EDisplay::None; |
| 447 } | 450 } |
| 448 } | 451 } |
| 449 return m_style->display() == EDisplay::None; | 452 return m_style->display() == EDisplay::None; |
| 450 } | 453 } |
| 451 | 454 |
| 452 } // namespace blink | 455 } // namespace blink |
| OLD | NEW |