| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 setHasCustomStyleCallbacks(); | 54 setHasCustomStyleCallbacks(); |
| 55 ScriptWrappable::init(this); | 55 ScriptWrappable::init(this); |
| 56 } | 56 } |
| 57 | 57 |
| 58 PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(Document& document) | 58 PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(Document& document) |
| 59 { | 59 { |
| 60 return adoptRef(new HTMLOptionElement(document)); | 60 return adoptRef(new HTMLOptionElement(document)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 PassRefPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document
& document, const String& data, const String& value, | 63 PassRefPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document
& document, const String& data, const String& value, |
| 64 bool defaultSelected, bool selected, ExceptionState& es) | 64 bool defaultSelected, bool selected, ExceptionState& exceptionState) |
| 65 { | 65 { |
| 66 RefPtr<HTMLOptionElement> element = adoptRef(new HTMLOptionElement(document)
); | 66 RefPtr<HTMLOptionElement> element = adoptRef(new HTMLOptionElement(document)
); |
| 67 | 67 |
| 68 RefPtr<Text> text = Text::create(document, data.isNull() ? "" : data); | 68 RefPtr<Text> text = Text::create(document, data.isNull() ? "" : data); |
| 69 | 69 |
| 70 element->appendChild(text.release(), es); | 70 element->appendChild(text.release(), exceptionState); |
| 71 if (es.hadException()) | 71 if (exceptionState.hadException()) |
| 72 return 0; | 72 return 0; |
| 73 | 73 |
| 74 if (!value.isNull()) | 74 if (!value.isNull()) |
| 75 element->setValue(value); | 75 element->setValue(value); |
| 76 if (defaultSelected) | 76 if (defaultSelected) |
| 77 element->setAttribute(selectedAttr, emptyAtom); | 77 element->setAttribute(selectedAttr, emptyAtom); |
| 78 element->setSelected(selected); | 78 element->setSelected(selected); |
| 79 | 79 |
| 80 return element.release(); | 80 return element.release(); |
| 81 } | 81 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 // FIXME: The following treats an element with the label attribute set to | 114 // FIXME: The following treats an element with the label attribute set to |
| 115 // the empty string the same as an element with no label attribute at all. | 115 // the empty string the same as an element with no label attribute at all. |
| 116 // Is that correct? If it is, then should the label function work the same w
ay? | 116 // Is that correct? If it is, then should the label function work the same w
ay? |
| 117 if (text.isEmpty()) | 117 if (text.isEmpty()) |
| 118 text = collectOptionInnerText(); | 118 text = collectOptionInnerText(); |
| 119 | 119 |
| 120 return text.stripWhiteSpace(isHTMLSpace<UChar>).simplifyWhiteSpace(isHTMLSpa
ce<UChar>); | 120 return text.stripWhiteSpace(isHTMLSpace<UChar>).simplifyWhiteSpace(isHTMLSpa
ce<UChar>); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void HTMLOptionElement::setText(const String &text, ExceptionState& es) | 123 void HTMLOptionElement::setText(const String &text, ExceptionState& exceptionSta
te) |
| 124 { | 124 { |
| 125 RefPtr<Node> protectFromMutationEvents(this); | 125 RefPtr<Node> protectFromMutationEvents(this); |
| 126 | 126 |
| 127 // Changing the text causes a recalc of a select's items, which will reset t
he selected | 127 // Changing the text causes a recalc of a select's items, which will reset t
he selected |
| 128 // index to the first item if the select is single selection with a menu lis
t. We attempt to | 128 // index to the first item if the select is single selection with a menu lis
t. We attempt to |
| 129 // preserve the selected item. | 129 // preserve the selected item. |
| 130 RefPtr<HTMLSelectElement> select = ownerSelectElement(); | 130 RefPtr<HTMLSelectElement> select = ownerSelectElement(); |
| 131 bool selectIsMenuList = select && select->usesMenuList(); | 131 bool selectIsMenuList = select && select->usesMenuList(); |
| 132 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; | 132 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; |
| 133 | 133 |
| 134 // Handle the common special case where there's exactly 1 child node, and it
's a text node. | 134 // Handle the common special case where there's exactly 1 child node, and it
's a text node. |
| 135 Node* child = firstChild(); | 135 Node* child = firstChild(); |
| 136 if (child && child->isTextNode() && !child->nextSibling()) | 136 if (child && child->isTextNode() && !child->nextSibling()) |
| 137 toText(child)->setData(text); | 137 toText(child)->setData(text); |
| 138 else { | 138 else { |
| 139 removeChildren(); | 139 removeChildren(); |
| 140 appendChild(Text::create(document(), text), es); | 140 appendChild(Text::create(document(), text), exceptionState); |
| 141 } | 141 } |
| 142 | 142 |
| 143 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) | 143 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) |
| 144 select->setSelectedIndex(oldSelectedIndex); | 144 select->setSelectedIndex(oldSelectedIndex); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void HTMLOptionElement::accessKeyAction(bool) | 147 void HTMLOptionElement::accessKeyAction(bool) |
| 148 { | 148 { |
| 149 HTMLSelectElement* select = ownerSelectElement(); | 149 HTMLSelectElement* select = ownerSelectElement(); |
| 150 if (select) | 150 if (select) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // Text nodes inside script elements are not part of the option text. | 360 // Text nodes inside script elements are not part of the option text. |
| 361 if (node->isElementNode() && toScriptLoaderIfPossible(toElement(node))) | 361 if (node->isElementNode() && toScriptLoaderIfPossible(toElement(node))) |
| 362 node = NodeTraversal::nextSkippingChildren(*node, this); | 362 node = NodeTraversal::nextSkippingChildren(*node, this); |
| 363 else | 363 else |
| 364 node = NodeTraversal::next(*node, this); | 364 node = NodeTraversal::next(*node, this); |
| 365 } | 365 } |
| 366 return text.toString(); | 366 return text.toString(); |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace WebCore | 369 } // namespace WebCore |
| OLD | NEW |