| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool HTMLOptionElement::rendererIsFocusable() const | 105 bool HTMLOptionElement::rendererIsFocusable() const |
| 106 { | 106 { |
| 107 // Option elements do not have a renderer so we check the renderStyle instea
d. | 107 // Option elements do not have a renderer so we check the renderStyle instea
d. |
| 108 return renderStyle() && renderStyle()->display() != NONE; | 108 return renderStyle() && renderStyle()->display() != NONE; |
| 109 } | 109 } |
| 110 | 110 |
| 111 String HTMLOptionElement::text() const | 111 String HTMLOptionElement::text() const |
| 112 { | 112 { |
| 113 Document* document = this->document(); | 113 Document& document = this->document(); |
| 114 String text; | 114 String text; |
| 115 | 115 |
| 116 // WinIE does not use the label attribute, so as a quirk, we ignore it. | 116 // WinIE does not use the label attribute, so as a quirk, we ignore it. |
| 117 if (!document->inQuirksMode()) | 117 if (!document.inQuirksMode()) |
| 118 text = fastGetAttribute(labelAttr); | 118 text = fastGetAttribute(labelAttr); |
| 119 | 119 |
| 120 // FIXME: The following treats an element with the label attribute set to | 120 // FIXME: The following treats an element with the label attribute set to |
| 121 // the empty string the same as an element with no label attribute at all. | 121 // the empty string the same as an element with no label attribute at all. |
| 122 // Is that correct? If it is, then should the label function work the same w
ay? | 122 // Is that correct? If it is, then should the label function work the same w
ay? |
| 123 if (text.isEmpty()) | 123 if (text.isEmpty()) |
| 124 text = collectOptionInnerText(); | 124 text = collectOptionInnerText(); |
| 125 | 125 |
| 126 // FIXME: Is displayStringModifiedByEncoding helpful here? | 126 // FIXME: Is displayStringModifiedByEncoding helpful here? |
| 127 // If it's correct here, then isn't it needed in the value and label functio
ns too? | 127 // If it's correct here, then isn't it needed in the value and label functio
ns too? |
| 128 return document->displayStringModifiedByEncoding(text).stripWhiteSpace(isHTM
LSpace).simplifyWhiteSpace(isHTMLSpace); | 128 return document.displayStringModifiedByEncoding(text).stripWhiteSpace(isHTML
Space).simplifyWhiteSpace(isHTMLSpace); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void HTMLOptionElement::setText(const String &text, ExceptionState& es) | 131 void HTMLOptionElement::setText(const String &text, ExceptionState& es) |
| 132 { | 132 { |
| 133 RefPtr<Node> protectFromMutationEvents(this); | 133 RefPtr<Node> protectFromMutationEvents(this); |
| 134 | 134 |
| 135 // Changing the text causes a recalc of a select's items, which will reset t
he selected | 135 // Changing the text causes a recalc of a select's items, which will reset t
he selected |
| 136 // index to the first item if the select is single selection with a menu lis
t. We attempt to | 136 // index to the first item if the select is single selection with a menu lis
t. We attempt to |
| 137 // preserve the selected item. | 137 // preserve the selected item. |
| 138 RefPtr<HTMLSelectElement> select = ownerSelectElement(); | 138 RefPtr<HTMLSelectElement> select = ownerSelectElement(); |
| 139 bool selectIsMenuList = select && select->usesMenuList(); | 139 bool selectIsMenuList = select && select->usesMenuList(); |
| 140 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; | 140 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; |
| 141 | 141 |
| 142 // Handle the common special case where there's exactly 1 child node, and it
's a text node. | 142 // Handle the common special case where there's exactly 1 child node, and it
's a text node. |
| 143 Node* child = firstChild(); | 143 Node* child = firstChild(); |
| 144 if (child && child->isTextNode() && !child->nextSibling()) | 144 if (child && child->isTextNode() && !child->nextSibling()) |
| 145 toText(child)->setData(text); | 145 toText(child)->setData(text); |
| 146 else { | 146 else { |
| 147 removeChildren(); | 147 removeChildren(); |
| 148 appendChild(Text::create(document(), text), es); | 148 appendChild(Text::create(&document(), text), es); |
| 149 } | 149 } |
| 150 | 150 |
| 151 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) | 151 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) |
| 152 select->setSelectedIndex(oldSelectedIndex); | 152 select->setSelectedIndex(oldSelectedIndex); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void HTMLOptionElement::accessKeyAction(bool) | 155 void HTMLOptionElement::accessKeyAction(bool) |
| 156 { | 156 { |
| 157 HTMLSelectElement* select = ownerSelectElement(); | 157 HTMLSelectElement* select = ownerSelectElement(); |
| 158 if (select) | 158 if (select) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // Text nodes inside script elements are not part of the option text. | 368 // Text nodes inside script elements are not part of the option text. |
| 369 if (node->isElementNode() && toScriptLoaderIfPossible(toElement(node))) | 369 if (node->isElementNode() && toScriptLoaderIfPossible(toElement(node))) |
| 370 node = NodeTraversal::nextSkippingChildren(node, this); | 370 node = NodeTraversal::nextSkippingChildren(node, this); |
| 371 else | 371 else |
| 372 node = NodeTraversal::next(node, this); | 372 node = NodeTraversal::next(node, this); |
| 373 } | 373 } |
| 374 return text.toString(); | 374 return text.toString(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 } // namespace WebCore | 377 } // namespace WebCore |
| OLD | NEW |